Expand description
The module API’s remaining half: private values, names, namespaces, the loader hooks, and
JS_EvalThis/JS_DetectModule/JS_WriteObject2.
§What a JSModuleDef * can be
Two things, and they are different allocations:
- a C module’s definition, built by
crate::modules::JS_NewCModule— aJsModuleDefwith a name, declared exports and values; - an engine module’s record, for a
.jsfile the loader read — the engine owns that one and the C API only ever sees it as the pointer it recorded.
Every function here therefore has to decide which it has. The discriminator is the
module’s own table: a pointer the context’s module_table knows is a C module; anything
else is an engine module the context has no record of, and the operations that need a
name or a namespace go through the interpreter’s module map instead.
That split is why JS_GetModuleName on an engine module answers a new atom rather than
one from the C module’s name field, and why JS_SetModulePrivateValue on one is a
failure: an engine module has no place to keep a host’s pointer.
Functions§
- JS_
Detect ⚠Module JS_DetectModule: whetherinputparses as a module rather than a script.- JS_
Eval ⚠This JS_EvalThis: evaluate with an explicitthis.- JS_
GetImport ⚠Meta JS_GetImportMeta: theimport.metaobject of the module being evaluated.- JS_
GetModule ⚠Name JS_GetModuleName: the module’s specifier, as an atom.- JS_
GetModule ⚠Namespace JS_GetModuleNamespace: the module namespace object.- JS_
GetModule ⚠Private Value JS_GetModulePrivateValue: the valueJS_SetModulePrivateValuestored, orundefined.- JS_
GetScript ⚠OrModule Name JS_GetScriptOrModuleName: the file name of the code atn_stack_levelsup.- JS_
Load ⚠Module JS_LoadModule: load and evaluate the modulebasenamenames.- JS_
Resolve ⚠Module JS_ResolveModule: resolve a module’s imports, without evaluating them.- JS_
SetModule ⚠Loader Func JS_SetModuleLoaderFunc: install how a specifier becomes a module.- JS_
SetModule ⚠Loader Func2 JS_SetModuleLoaderFunc2: the same, plus the import-attribute check.- JS_
SetModule ⚠Private Value JS_SetModulePrivateValue: attach a value to a C module.- JS_
Write ⚠Object2 JS_WriteObject2:JS_WriteObjectplus the shared-ArrayBuffertable.