-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathNsBuiltinModules.h
More file actions
54 lines (42 loc) · 2.32 KB
/
Copy pathNsBuiltinModules.h
File metadata and controls
54 lines (42 loc) · 2.32 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
#ifndef NsBuiltinModules_h
#define NsBuiltinModules_h
#include <string>
#include "Common.h"
namespace tns {
// The `ns:` builtin modules and their `node:` compatibility shims, as
// specified by docs/ns-builtin-modules.md. Every module is a per-realm
// singleton built from a RuntimeBuiltins source, so a specifier always yields
// the same frozen exports object and the same synthetic ES module.
class NsBuiltinModules {
public:
// Any `ns:`/`node:` specifier, registered or not. The CommonJS resolver
// claims all of them so a prefixed name can never reach the filesystem;
// bare specifiers (`util`) keep resolving through npm untouched.
static bool IsBuiltinScheme(const std::string& specifier);
// The `ns:` half of the scheme, whose unknown names must fail rather than
// fall through to any legacy handling.
static bool IsNsScheme(const std::string& specifier);
// Whether a module of that name exists.
// Whether the specifier names a registered builtin module. Internal-tier
// rows (see kRegistry) only count when includeInternal is set, which is the
// builtin require's privilege; every app-facing caller keeps the default.
static bool IsRegistered(const std::string& specifier,
bool includeInternal = false);
// Frozen exports object of a registered specifier. Empty when the specifier
// is not registered (nothing thrown) or when the module failed to build (an
// exception is pending).
static v8::MaybeLocal<v8::Object> GetExports(v8::Local<v8::Context> context,
const std::string& specifier);
// Evaluated synthetic module exporting the same values as GetExports under
// their own names plus `default` (the exports object itself).
static v8::MaybeLocal<v8::Module> GetModule(v8::Local<v8::Context> context,
const std::string& specifier);
// What every resolver reports for a specifier in the scheme that names no
// module.
static std::string NotFoundMessage(const std::string& specifier);
// `ns:util`'s format, used by console.* for %-substitution. Empty when the
// module could not be built; callers degrade instead of failing the log.
static v8::Local<v8::Function> GetFormatFunc(v8::Local<v8::Context> context);
};
} // namespace tns
#endif /* NsBuiltinModules_h */