Skip to main content

Module module_api

Module module_api 

Source
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 — a JsModuleDef with a name, declared exports and values;
  • an engine module’s record, for a .js file 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_DetectModule⚠
JS_DetectModule: whether input parses as a module rather than a script.
JS_EvalThis⚠
JS_EvalThis: evaluate with an explicit this.
JS_GetImportMeta⚠
JS_GetImportMeta: the import.meta object of the module being evaluated.
JS_GetModuleName⚠
JS_GetModuleName: the module’s specifier, as an atom.
JS_GetModuleNamespace⚠
JS_GetModuleNamespace: the module namespace object.
JS_GetModulePrivateValue⚠
JS_GetModulePrivateValue: the value JS_SetModulePrivateValue stored, or undefined.
JS_GetScriptOrModuleName⚠
JS_GetScriptOrModuleName: the file name of the code at n_stack_levels up.
JS_LoadModule⚠
JS_LoadModule: load and evaluate the module basename names.
JS_ResolveModule⚠
JS_ResolveModule: resolve a module’s imports, without evaluating them.
JS_SetModuleLoaderFunc⚠
JS_SetModuleLoaderFunc: install how a specifier becomes a module.
JS_SetModuleLoaderFunc2⚠
JS_SetModuleLoaderFunc2: the same, plus the import-attribute check.
JS_SetModulePrivateValue⚠
JS_SetModulePrivateValue: attach a value to a C module.
JS_WriteObject2⚠
JS_WriteObject2: JS_WriteObject plus the shared-ArrayBuffer table.