v8  7.9.317(node13.2.0)
V8 is Google's open source JavaScript engine
Module Class Reference

#include <v8.h>

Inheritance diagram for Module:
Collaboration diagram for Module:

Public Types

enum  Status {
  kUninstantiated, kInstantiating, kInstantiated, kEvaluating,
  kEvaluated, kErrored
}
 
typedef MaybeLocal< Module >(* ResolveCallback) (Local< Context > context, Local< String > specifier, Local< Module > referrer)
 
typedef MaybeLocal< Value >(* SyntheticModuleEvaluationSteps) (Local< Context > context, Local< Module > module)
 

Public Member Functions

Status GetStatus () const
 
Local< ValueGetException () const
 
int GetModuleRequestsLength () const
 
Local< StringGetModuleRequest (int i) const
 
Location GetModuleRequestLocation (int i) const
 
int GetIdentityHash () const
 
V8_WARN_UNUSED_RESULT Maybe< bool > InstantiateModule (Local< Context > context, ResolveCallback callback)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueEvaluate (Local< Context > context)
 
Local< ValueGetModuleNamespace ()
 
Local< UnboundModuleScriptGetUnboundModuleScript ()
 
void SetSyntheticModuleExport (Local< String > export_name, Local< Value > export_value)
 

Static Public Member Functions

static Local< ModuleCreateSyntheticModule (Isolate *isolate, Local< String > module_name, const std::vector< Local< String >> &export_names, SyntheticModuleEvaluationSteps evaluation_steps)
 

Detailed Description

A compiled JavaScript module.

Definition at line 1449 of file v8.h.

Member Typedef Documentation

◆ ResolveCallback

typedef MaybeLocal<Module>(* ResolveCallback) (Local< Context > context, Local< String > specifier, Local< Module > referrer)

Definition at line 1499 of file v8.h.

◆ SyntheticModuleEvaluationSteps

typedef MaybeLocal<Value>(* SyntheticModuleEvaluationSteps) (Local< Context > context, Local< Module > module)

Definition at line 1545 of file v8.h.

Member Enumeration Documentation

◆ Status

enum Status

The different states a module can be in.

This corresponds to the states used in ECMAScript except that "evaluated" is split into kEvaluated and kErrored, indicating success and failure, respectively.

Enumerator
kUninstantiated 
kInstantiating 
kInstantiated 
kEvaluating 
kEvaluated 
kErrored 

Definition at line 1458 of file v8.h.

Member Function Documentation

◆ CreateSyntheticModule()

static Local<Module> CreateSyntheticModule ( Isolate isolate,
Local< String module_name,
const std::vector< Local< String >> &  export_names,
SyntheticModuleEvaluationSteps  evaluation_steps 
)
static

Creates a new SyntheticModule with the specified export names, where evaluation_steps will be executed upon module evaluation. export_names must not contain duplicates. module_name is used solely for logging/debugging and doesn't affect module behavior.

◆ Evaluate()

V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate ( Local< Context context)

Evaluates the module and its dependencies.

If status is kInstantiated, run the module's code. On success, set status to kEvaluated and return the completion value; on failure, set status to kErrored and propagate the thrown exception (which is then also available via |GetException|).

◆ GetException()

Local<Value> GetException ( ) const

For a module in kErrored status, this returns the corresponding exception.

◆ GetIdentityHash()

int GetIdentityHash ( ) const

Returns the identity hash for this object.

◆ GetModuleNamespace()

Local<Value> GetModuleNamespace ( )

Returns the namespace object of this module.

The module's status must be at least kInstantiated.

◆ GetModuleRequest()

Local<String> GetModuleRequest ( int  i) const

Returns the ith module specifier in this module. i must be < GetModuleRequestsLength() and >= 0.

◆ GetModuleRequestLocation()

Location GetModuleRequestLocation ( int  i) const

Returns the source location (line number and column number) of the ith module specifier's first occurrence in this module.

◆ GetModuleRequestsLength()

int GetModuleRequestsLength ( ) const

Returns the number of modules requested by this module.

◆ GetStatus()

Status GetStatus ( ) const

Returns the module's current status.

◆ GetUnboundModuleScript()

Local<UnboundModuleScript> GetUnboundModuleScript ( )

Returns the corresponding context-unbound module script.

The module must be unevaluated, i.e. its status must not be kEvaluating, kEvaluated or kErrored.

◆ InstantiateModule()

V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule ( Local< Context context,
ResolveCallback  callback 
)

Instantiates the module and its dependencies.

Returns an empty Maybe<bool> if an exception occurred during instantiation. (In the case where the callback throws an exception, that exception is propagated.)

◆ SetSyntheticModuleExport()

void SetSyntheticModuleExport ( Local< String export_name,
Local< Value export_value 
)

Set this module's exported value for the name export_name to the specified export_value. This method must be called only on Modules created via CreateSyntheticModule. export_name must be one of the export_names that were passed in that CreateSyntheticModule call.


The documentation for this class was generated from the following file: