Repository navigation
Expand file tree
/
Copy pathModuleRegistry.h
More file actions
77 lines (60 loc) · 3.58 KB
/
Copy pathModuleRegistry.h
File metadata and controls
77 lines (60 loc) · 3.58 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
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef NATIVESCRIPT_COMMON_LOADER_MODULE_REGISTRY_H_
#define NATIVESCRIPT_COMMON_LOADER_MODULE_REGISTRY_H_
#include <v8.h>
#include <cstddef>
#include <string>
#include <vector>
// One isolate's module registry: canonical key -> module (keys as
// ns/loader/ModuleIdentity.h describes them). Every function runs on the
// isolate's thread and reads the isolate's loader state, which stays readable
// through teardown; once the runtime has closed its state, reads find nothing
// and writes do nothing.
namespace nativescript::common::loader {
// The module registered under `key`; empty when there is none.
v8::Local<v8::Module> FindRegisteredModule(v8::Isolate* isolate,
const std::string& key);
bool IsModuleRegistered(v8::Isolate* isolate, const std::string& key);
size_t RegisteredModuleCount(v8::Isolate* isolate);
// The only way to register a module. The module that held `key` before leaves
// the module -> key index under `key`, and loses its require(esm) facades
// unless another key still holds it, even when it is `module` itself.
// `filePath` is the file a file module was read from: a key is that path plus a
// query, and the path may itself contain '?'. Empty for any other module.
void SetRegisteredModule(v8::Isolate* isolate, const std::string& key,
v8::Local<v8::Module> module,
std::string filePath = std::string());
// The registry key `keyOrUrl` names: CanonicalizeModuleKey under the
// isolate's LoaderConfig and canonicalization vocabulary, except that a
// registered file module's key is kept as it is, and under legacyOrigins a
// file: URL that reads back verbatim (OriginToPath) as a registered key names
// that key.
std::string RegistryKeyFor(v8::Isolate* isolate, const std::string& keyOrUrl);
// Drops the module RegistryKeyFor(keyOrUrl) names, with its index entry, and
// its facades when no other key holds it. Returns that key, whether or not a
// module was registered there.
std::string RemoveModuleFromRegistry(v8::Isolate* isolate,
const std::string& keyOrUrl);
// The key `module` is registered under; empty when it is not registered.
std::string FindKeyForModule(v8::Isolate* isolate,
v8::Local<v8::Module> module);
// The file the module registered under `key` was read from. For a key the
// registry recorded no file for: the key up to its first '?' when it is a
// path, empty when it has a URL scheme.
std::string ModuleFilePathForKey(v8::Isolate* isolate, const std::string& key);
// The registered keys that are blob: URLs or URLs with an authority, sorted.
// Dev tooling only.
std::vector<std::string> GetLoadedModuleUrls(v8::Isolate* isolate);
// Removes the modules `urls` name, each key once. An import() still loading
// one rejects, in `context`, with "Module invalidated during dev reload:
// <key>".
void InvalidateModules(v8::Isolate* isolate, v8::Local<v8::Context> context,
const std::vector<std::string>& urls);
// The require(esm) facade cached for `target`; empty when there is none.
v8::Local<v8::Module> FindRequireFacade(v8::Isolate* isolate,
v8::Local<v8::Module> target);
// Caches `facade` for `target` until a key that holds `target` is removed
// or registered again (even with `target`) while no other key holds it.
void AddRequireFacade(v8::Isolate* isolate, v8::Local<v8::Module> target,
v8::Local<v8::Module> facade);
} // namespace nativescript::common::loader
#endif // NATIVESCRIPT_COMMON_LOADER_MODULE_REGISTRY_H_