-
Notifications
You must be signed in to change notification settings - Fork 28.3k
/
shadow_realm.js
47 lines (42 loc) · 1.01 KB
/
shadow_realm.js
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
'use strict';
// In ShadowRealm.
const {
prepareShadowRealmExecution,
} = require('internal/process/pre_execution');
const {
BuiltinModule,
} = require('internal/bootstrap/realm');
const { setDefaultImportModuleDynamically } = require('internal/modules/esm/utils');
BuiltinModule.setRealmAllowRequireByUsers([
'assert',
'assert/strict',
'buffer',
'console',
'constants',
'cypto',
'diagnostics_channel',
'events',
'module',
'path',
'path/posix',
'path/win32',
'readline',
'readline/promises',
'repl',
'stream',
'stream/consumers',
'stream/promises',
'stream/web',
'string_decoder',
'url',
'util',
'util/types',
'zlib',
]);
prepareShadowRealmExecution();
// The handler for `ShadowRealm.prototype.importValue`.
setDefaultImportModuleDynamically((specifier, assertions) => {
const { esmLoader } = require('internal/process/esm_loader');
// `parentUrl` is not set in the case of a ShadowRealm top-level import.
return esmLoader.import(specifier, undefined, assertions);
});