Repository navigation
Expand file tree
/
Copy pathModuleImport.h
More file actions
64 lines (56 loc) · 3.38 KB
/
Copy pathModuleImport.h
File metadata and controls
64 lines (56 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef NATIVESCRIPT_COMMON_LOADER_MODULE_IMPORT_H_
#define NATIVESCRIPT_COMMON_LOADER_MODULE_IMPORT_H_
#include <v8.h>
// Static import and import(): the two host callbacks V8 calls, which every
// runtime installs (SetHostImportModuleDynamicallyCallback) or passes to
// Module::InstantiateModule.
//
// Both resolve a specifier once, through ResolveModuleSpecifier, and load what
// the resolution names:
// - a builtin, from platform::BuiltinModule;
// - a file, compiled and registered (a .json file as a JSON module);
// - an http(s) URL, through the graph walk (import()) or the registry entry
// the walk made (static import);
// - a blob: URL, for import() only, from the blob store behind
// URL.createObjectURL (URL.InternalAccessor.getData).
// A module is JSON because its path ends in .json or its response is served
// as JSON, never because of an import attribute. The `type` attribute is then
// checked against it (LoaderConfig::enforceImportAttributes): a JSON module
// imported without `type: "json"`, `type: "json"` on any other module, or
// another `type` value (`"javascript"` included), or any key other than
// `type`, rejects the import with a TypeError, or, while enforcement is off,
// is let through and logged once per module by a debug build.
//
// Isolate thread, under the Locker.
namespace nativescript::common::loader {
// The module `specifier` names from `referrer`, compiled and registered but
// never instantiated or evaluated: V8 is linking the importer and evaluates
// the graph in order itself. A registered module that has not errored is
// returned as it is, which is how import cycles end. Empty, with an exception
// pending, when it cannot be loaded, and after loader::Quiesce.
v8::MaybeLocal<v8::Module> ResolveModuleCallback(
v8::Local<v8::Context> context, v8::Local<v8::String> specifier,
v8::Local<v8::FixedArray> importAttributes, v8::Local<v8::Module> referrer);
// The promise of import(specifier) from the script or module named
// `resourceName`. It settles with the module's namespace once the module has
// evaluated, top-level await included, or rejects with why it could not be
// loaded, linked or evaluated. Concurrent imports of one http(s) or blob: URL
// share one load. After loader::Quiesce it returns a promise that never
// settles, as the imports in flight at teardown never do, and runs nothing.
v8::MaybeLocal<v8::Promise> ImportModuleDynamicallyCallback(
v8::Local<v8::Context> context, v8::Local<v8::Data> hostDefinedOptions,
v8::Local<v8::Value> resourceName, v8::Local<v8::String> specifier,
v8::Local<v8::FixedArray> importAttributes);
// Fills import.meta of `module` from ImportMetaFor: `url` for every module;
// `dirname` for a module read from a file; `filename` too outside
// legacyOrigins. A module the registry does not know gets the app root's
// strings. Leaves `meta` empty once the isolate's loader state is gone.
void InitializeImportMetaObject(v8::Local<v8::Context> context,
v8::Local<v8::Module> module,
v8::Local<v8::Object> meta);
// Installs ImportModuleDynamicallyCallback and InitializeImportMetaObject on
// `isolate`. ResolveModuleCallback is not an isolate callback: pass it to
// every Module::InstantiateModule.
void InstallHostCallbacks(v8::Isolate* isolate);
} // namespace nativescript::common::loader
#endif // NATIVESCRIPT_COMMON_LOADER_MODULE_IMPORT_H_