v8  9.0.257(node16.0.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
}
 
using ResolveModuleCallback = MaybeLocal< Module >(*)(Local< Context > context, Local< String > specifier, Local< Module > referrer)
 
using ResolveModuleCallback = MaybeLocal< Module >(*)(Local< Context > context, Local< String > specifier, Local< FixedArray > import_assertions, Local< Module > referrer)
 
using SyntheticModuleEvaluationSteps = MaybeLocal< Value >(*)(Local< Context > context, Local< Module > module)
 

Public Member Functions

Status GetStatus () const
 
Local< ValueGetException () const
 
 V8_DEPRECATE_SOON ("Use Module::GetModuleRequests() and FixedArray::Length().") int GetModuleRequestsLength() const
 
 V8_DEPRECATE_SOON ("Use Module::GetModuleRequests() and ModuleRequest::GetSpecifier().") Local< String > GetModuleRequest(int i) const
 
 V8_DEPRECATE_SOON ("Use Module::GetModuleRequests(), ModuleRequest::GetSourceOffset(), and " "Module::SourceOffsetToLocation().") Location GetModuleRequestLocation(int i) const
 
Local< FixedArrayGetModuleRequests () const
 
Location SourceOffsetToLocation (int offset) const
 
int GetIdentityHash () const
 
 V8_DEPRECATE_SOON ("Use the version of InstantiateModule that takes a ResolveModuleCallback " "parameter") V8_WARN_UNUSED_RESULT Maybe< bool > InstantiateModule(Local< Context > context
 
V8_WARN_UNUSED_RESULT Maybe< bool > InstantiateModule (Local< Context > context, ResolveModuleCallback callback)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueEvaluate (Local< Context > context)
 
Local< ValueGetModuleNamespace ()
 
Local< UnboundModuleScriptGetUnboundModuleScript ()
 
int ScriptId ()
 
bool IsGraphAsync () const
 
bool IsSourceTextModule () const
 
bool IsSyntheticModule () const
 
V8_WARN_UNUSED_RESULT Maybe< bool > SetSyntheticModuleExport (Isolate *isolate, Local< String > export_name, Local< Value > export_value)
 
 V8_DEPRECATED ("Use the preceding SetSyntheticModuleExport with an Isolate parameter, " "instead of the one that follows. The former will throw a runtime " "error if called for an export that doesn't exist (as per spec); " "the latter will crash with a failed CHECK().") void SetSyntheticModuleExport(Local< String > export_name
 
- Public Member Functions inherited from Data
bool IsValue () const
 
bool IsModule () const
 
bool IsPrivate () const
 
bool IsObjectTemplate () const
 
bool IsFunctionTemplate () const
 
bool IsContext () const
 

Static Public Member Functions

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

Data Fields

ResolveCallback callback
 
Local< Valueexport_value
 

Detailed Description

A compiled JavaScript module.

Definition at line 1585 of file v8.h.

Member Typedef Documentation

◆ ResolveModuleCallback [1/2]

using ResolveModuleCallback = MaybeLocal<Module> (*)(Local<Context> context, Local<String> specifier, Local<Module> referrer)

Definition at line 1654 of file v8.h.

◆ ResolveModuleCallback [2/2]

using ResolveModuleCallback = MaybeLocal<Module> (*)( Local<Context> context, Local<String> specifier, Local<FixedArray> import_assertions, Local<Module> referrer)

Definition at line 1657 of file v8.h.

◆ SyntheticModuleEvaluationSteps

Definition at line 1732 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 1594 of file v8.h.

Member Function Documentation

◆ Cast()

Module * Cast ( Data data)
static

Definition at line 11979 of file v8.h.

◆ 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.

◆ GetModuleRequests()

Local<FixedArray> GetModuleRequests ( ) const

Returns the ModuleRequests for 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,
ResolveModuleCallback  callback 
)

◆ IsGraphAsync()

bool IsGraphAsync ( ) const

Returns whether this module or any of its requested modules is async, i.e. contains top-level await.

The module's status must be at least kInstantiated.

◆ IsSourceTextModule()

bool IsSourceTextModule ( ) const

Returns whether the module is a SourceTextModule.

◆ IsSyntheticModule()

bool IsSyntheticModule ( ) const

Returns whether the module is a SyntheticModule.

◆ ScriptId()

int ScriptId ( )

Returns the underlying script's id.

The module must be a SourceTextModule and must not have a kErrored status.

◆ SetSyntheticModuleExport()

V8_WARN_UNUSED_RESULT Maybe<bool> SetSyntheticModuleExport ( Isolate isolate,
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. An error will be thrown if export_name is not one of the export_names that were passed in that CreateSyntheticModule call. Returns Just(true) on success, Nothing<bool>() if an error was thrown.

◆ SourceOffsetToLocation()

Location SourceOffsetToLocation ( int  offset) const

For the given source text offset in this module, returns the corresponding Location with line and column numbers.

◆ V8_DEPRECATE_SOON() [1/4]

V8_DEPRECATE_SOON ( "Use Module::GetModuleRequests() and FixedArray::Length()."  ) const

Returns the number of modules requested by this module.

◆ V8_DEPRECATE_SOON() [2/4]

V8_DEPRECATE_SOON ( "Use Module::GetModuleRequests() and ModuleRequest::GetSpecifier()."  ) const

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

◆ V8_DEPRECATE_SOON() [3/4]

V8_DEPRECATE_SOON ( "Use   Module::GetModuleRequests(),
ModuleRequest::GetSourceOffset()  ,
and " "Module::SourceOffsetToLocation()."   
) const

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

◆ V8_DEPRECATE_SOON() [4/4]

V8_DEPRECATE_SOON ( "Use the version of InstantiateModule that takes a ResolveModuleCallback " "parameter"  )

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.)

◆ V8_DEPRECATED()

V8_DEPRECATED ( "Use the preceding SetSyntheticModuleExport with an Isolate  parameter,
" "instead of the one that follows. The former will throw a runtime " "error if called for an export that doesn 't exist(as per spec);" "the latter will crash with a failed CHECK()."   
)

Field Documentation

◆ callback

ResolveCallback callback

Definition at line 1670 of file v8.h.

◆ export_value

Local<Value> export_value

Definition at line 1761 of file v8.h.


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