v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8::Module Class Reference

#include <v8-script.h>

Inheritance diagram for v8::Module:
Collaboration diagram for v8::Module:

Public Types

enum  Status {
  kUninstantiated , kInstantiating , kInstantiated , kEvaluating ,
  kEvaluated , kErrored
}
 
using ResolveModuleCallback
 
using ResolveSourceCallback
 
using SyntheticModuleEvaluationSteps
 

Public Member Functions

Status GetStatus () const
 
Local< ValueGetException () const
 
Local< FixedArrayGetModuleRequests () const
 
Location SourceOffsetToLocation (int offset) const
 
int GetIdentityHash () const
 
V8_WARN_UNUSED_RESULT Maybe< bool > InstantiateModule (Local< Context > context, ResolveModuleCallback module_callback, ResolveSourceCallback source_callback=nullptr)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueEvaluate (Local< Context > context)
 
Local< ValueGetModuleNamespace ()
 
Local< UnboundModuleScriptGetUnboundModuleScript ()
 
int ScriptId () const
 
bool IsGraphAsync () const
 
bool HasTopLevelAwait () const
 
bool IsSourceTextModule () const
 
bool IsSyntheticModule () const
 
V8_WARN_UNUSED_RESULT Maybe< bool > SetSyntheticModuleExport (Isolate *isolate, Local< String > export_name, Local< Value > export_value)
 
std::pair< LocalVector< Module >, LocalVector< Message > > GetStalledTopLevelAwaitMessages (Isolate *isolate)
 
- Public Member Functions inherited from v8::Data
bool IsValue () const
 
bool IsModule () const
 
bool IsModuleRequest () const
 
bool IsFixedArray () 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 MemorySpan< const Local< String > > &export_names, SyntheticModuleEvaluationSteps evaluation_steps)
 
static V8_INLINE ModuleCast (Data *data)
 

Static Private Member Functions

static void CheckCast (Data *obj)
 

Detailed Description

A compiled JavaScript module.

Definition at line 172 of file v8-script.h.

Member Typedef Documentation

◆ ResolveModuleCallback

Initial value:
MaybeLocal<Module> (*)(
Local<Context> context, Local<String> specifier,
Local<FixedArray> import_attributes, Local<Module> referrer)
TNode< Context > context

Definition at line 216 of file v8-script.h.

◆ ResolveSourceCallback

Initial value:
MaybeLocal<Object> (*)(
Local<Context> context, Local<String> specifier,
Local<FixedArray> import_attributes, Local<Module> referrer)

Definition at line 219 of file v8-script.h.

◆ SyntheticModuleEvaluationSteps

Initial value:
MaybeLocal<Value> (*)(Local<Context> context, Local<Module> module)

Definition at line 300 of file v8-script.h.

Member Enumeration Documentation

◆ 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 181 of file v8-script.h.

Member Function Documentation

◆ Cast()

Module * v8::Module::Cast ( Data * data)
static

Definition at line 943 of file v8-script.h.

◆ CheckCast()

void v8::Module::CheckCast ( v8::Data * that)
staticprivate

Definition at line 3906 of file api.cc.

Here is the call graph for this function:

◆ CreateSyntheticModule()

Local< Module > v8::Module::CreateSyntheticModule ( Isolate * isolate,
Local< String > module_name,
const MemorySpan< const 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.

Definition at line 2271 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Evaluate()

MaybeLocal< Value > v8::Module::Evaluate ( Local< Context > context)

Evaluates the module and its dependencies.

If status is kInstantiated, run the module's code and return a Promise object. On success, set status to kEvaluated and resolve the Promise with the completion value; on failure, set status to kErrored and reject the Promise with the error.

If IsGraphAsync() is false, the returned Promise is settled.

Definition at line 2251 of file api.cc.

Here is the call graph for this function:

◆ GetException()

Local< Value > v8::Module::GetException ( ) const

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

Definition at line 2135 of file api.cc.

Here is the call graph for this function:

◆ GetIdentityHash()

int v8::Module::GetIdentityHash ( ) const

Returns the identity hash for this object.

Definition at line 2233 of file api.cc.

Here is the call graph for this function:

◆ GetModuleNamespace()

Local< Value > v8::Module::GetModuleNamespace ( )

Returns the namespace object of this module.

The module's status must be at least kInstantiated.

Definition at line 2174 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetModuleRequests()

Local< FixedArray > v8::Module::GetModuleRequests ( ) const

Returns the ModuleRequests for this module.

Definition at line 2144 of file api.cc.

Here is the call graph for this function:

◆ GetStalledTopLevelAwaitMessages()

std::pair< LocalVector< Module >, LocalVector< Message > > v8::Module::GetStalledTopLevelAwaitMessages ( Isolate * isolate)

Search the modules requested directly or indirectly by the module for any top-level await that has not yet resolved. If there is any, the returned pair of vectors (of equal size) contain the unresolved module and corresponding message with the pending top-level await. An embedder may call this before exiting to improve error messages.

Definition at line 2313 of file api.cc.

Here is the call graph for this function:

◆ GetStatus()

Module::Status v8::Module::GetStatus ( ) const

Returns the module's current status.

Definition at line 2113 of file api.cc.

Here is the call graph for this function:

◆ GetUnboundModuleScript()

Local< UnboundModuleScript > v8::Module::GetUnboundModuleScript ( )

Returns the corresponding context-unbound module script.

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

Definition at line 2186 of file api.cc.

Here is the call graph for this function:

◆ HasTopLevelAwait()

bool v8::Module::HasTopLevelAwait ( ) const

Returns whether this module is individually asynchronous (for example, if it's a Source Text Module Record containing a top-level await). See [[HasTLA]] in https://tc39.es/ecma262/#sec-cyclic-module-records

Definition at line 2205 of file api.cc.

Here is the call graph for this function:

◆ InstantiateModule()

Maybe< bool > v8::Module::InstantiateModule ( Local< Context > context,
ResolveModuleCallback module_callback,
ResolveSourceCallback source_callback = nullptr )

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

Definition at line 2239 of file api.cc.

Here is the call graph for this function:

◆ IsGraphAsync()

bool v8::Module::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.

Definition at line 2211 of file api.cc.

Here is the call graph for this function:

◆ IsSourceTextModule()

bool v8::Module::IsSourceTextModule ( ) const

Returns whether the module is a SourceTextModule.

Definition at line 2221 of file api.cc.

Here is the call graph for this function:

◆ IsSyntheticModule()

bool v8::Module::IsSyntheticModule ( ) const

Returns whether the module is a SyntheticModule.

Definition at line 2227 of file api.cc.

Here is the call graph for this function:

◆ ScriptId()

int v8::Module::ScriptId ( ) const

Returns the underlying script's id.

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

Definition at line 2197 of file api.cc.

Here is the call graph for this function:

◆ SetSyntheticModuleExport()

Maybe< bool > v8::Module::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.

Definition at line 2291 of file api.cc.

Here is the call graph for this function:

◆ SourceOffsetToLocation()

Location v8::Module::SourceOffsetToLocation ( int offset) const

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

Definition at line 2159 of file api.cc.

Here is the call graph for this function:

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