GeezerVison is showing github.com — src: add initial shadow realm support · nodejs/node@e86a638
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -337,6 +337,7 @@ module.exports = { | 337 | 337 | TextEncoderStream: 'readable', | 338 | 338 | TransformStream: 'readable', | 339 | 339 | TransformStreamDefaultController: 'readable', | | 340 | + ShadowRealm: 'readable', | 340 | 341 | SubtleCrypto: 'readable', | 341 | 342 | WritableStream: 'readable', | 342 | 343 | WritableStreamDefaultWriter: 'readable', | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +11-1Lines changed: 11 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -346,10 +346,18 @@ Disable experimental support for the [Fetch API][]. | 346 | 346 |
| 347 | 347 | <!-- YAML | 348 | 348 | added: v16.6.0 | 349 | | - --> | | 349 | +--> | 350 | 350 |
| 351 | 351 | Use this flag to disable top-level await in REPL. | 352 | 352 |
| | 353 | +### `--experimental-shadow-realm` | | 354 | + | | 355 | +<!-- YAML | | 356 | +added: REPLACEME | | 357 | +--> | | 358 | + | | 359 | +Use this flag to enable [ShadowRealm][] support. | | 360 | + | 353 | 361 | ### `--experimental-specifier-resolution=mode` | 354 | 362 |
| 355 | 363 | <!-- YAML | @@ -1622,6 +1630,7 @@ Node.js options that are allowed are: | 1622 | 1630 | * `--experimental-modules` | 1623 | 1631 | * `--experimental-network-imports` | 1624 | 1632 | * `--experimental-policy` | | 1633 | +* `--experimental-shadow-realm` | 1625 | 1634 | * `--experimental-specifier-resolution` | 1626 | 1635 | * `--experimental-top-level-await` | 1627 | 1636 | * `--experimental-vm-modules` | @@ -2017,6 +2026,7 @@ $ node --max-old-space-size=1536 index.js | 2017 | 2026 | [OSSL_PROVIDER-legacy]: https://www.openssl.org/docs/man3.0/man7/OSSL_PROVIDER-legacy.html | 2018 | 2027 | [REPL]: repl.md | 2019 | 2028 | [ScriptCoverage]: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ScriptCoverage | | 2029 | +[ShadowRealm]: https://github.com/tc39/proposal-shadowrealm | 2020 | 2030 | [Source Map]: https://sourcemaps.info/spec.html | 2021 | 2031 | [Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity | 2022 | 2032 | [V8 JavaScript code coverage]: https://v8project.blogspot.com/2017/12/javascript-code-coverage.html | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -156,6 +156,9 @@ Enable experimental support for loading modules using `import` over `https:`. | 156 | 156 | .It Fl -experimental-policy | 157 | 157 | Use the specified file as a security policy. | 158 | 158 | . | | 159 | +.It Fl -experimental-shadow-realm | | 160 | +Use this flag to enable ShadowRealm support. | | 161 | +. | 159 | 162 | .It Fl -no-experimental-fetch | 160 | 163 | Disable experimental support for the Fetch API. | 161 | 164 | . | |
Collapse file Copy file name to clipboardExpand all lines: lib/.eslintrc.yaml +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,6 +87,10 @@ rules: | 87 | 87 | message: Use `const { Request } = require('internal/deps/undici/undici');` instead of the global. | 88 | 88 | - name: Response | 89 | 89 | message: Use `const { Response } = require('internal/deps/undici/undici');` instead of the global. | | 90 | + # ShadowRealm is not available in primordials because it can be | | 91 | + # disabled with --no-harmony-shadow-realm CLI flag. | | 92 | + - name: ShadowRealm | | 93 | + message: Use `const { ShadowRealm } = globalThis;` instead of the global. | 90 | 94 | # SharedArrayBuffer is not available in primordials because it can be | 91 | 95 | # disabled with --no-harmony-sharedarraybuffer CLI flag. | 92 | 96 | - name: SharedArrayBuffer | |
Collapse file Copy file name to clipboardExpand all lines: node.gyp +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 531 | 531 | 'src/node_report_module.cc', | 532 | 532 | 'src/node_report_utils.cc', | 533 | 533 | 'src/node_serdes.cc', | | 534 | + 'src/node_shadow_realm.cc', | 534 | 535 | 'src/node_snapshotable.cc', | 535 | 536 | 'src/node_sockaddr.cc', | 536 | 537 | 'src/node_stat_watcher.cc', | | 637 | 638 | 'src/node_report.h', | 638 | 639 | 'src/node_revert.h', | 639 | 640 | 'src/node_root_certs.h', | | 641 | + 'src/node_shadow_realm.h', | 640 | 642 | 'src/node_snapshotable.h', | 641 | 643 | 'src/node_snapshot_builder.h', | 642 | 644 | 'src/node_sockaddr.h', | |
Collapse file Copy file name to clipboardExpand all lines: src/api/environment.cc +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | #include "node_native_module_env.h" | 6 | 6 | #include "node_options-inl.h" | 7 | 7 | #include "node_platform.h" | | 8 | +#include "node_shadow_realm.h" | 8 | 9 | #include "node_v8_platform-inl.h" | 9 | 10 | #include "node_wasm_web_api.h" | 10 | 11 | #include "uv.h" | @@ -261,6 +262,12 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) { | 261 | 262 | isolate->SetWasmStreamingCallback(wasm_web_api::StartStreamingCompilation); | 262 | 263 | } | 263 | 264 |
| | 265 | + if (per_process::cli_options->get_per_isolate_options() | | 266 | + ->experimental_shadow_realm) { | | 267 | + isolate->SetHostCreateShadowRealmContextCallback( | | 268 | + shadow_realm::HostCreateShadowRealmContextCallback); | | 269 | + } | | 270 | + | 264 | 271 | if ((s.flags & SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK) == 0) { | 265 | 272 | auto* promise_reject_cb = s.promise_reject_callback ? | 266 | 273 | s.promise_reject_callback : PromiseRejectCallback; | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -703,6 +703,15 @@ PerIsolateOptionsParser::PerIsolateOptionsParser( | 703 | 703 | AddOption( | 704 | 704 | "--experimental-top-level-await", "", NoOp{}, kAllowedInEnvironment); | 705 | 705 |
| | 706 | + AddOption("--experimental-shadow-realm", | | 707 | + "", | | 708 | + &PerIsolateOptions::experimental_shadow_realm, | | 709 | + kAllowedInEnvironment); | | 710 | + AddOption("--harmony-shadow-realm", "", V8Option{}); | | 711 | + Implies("--experimental-shadow-realm", "--harmony-shadow-realm"); | | 712 | + Implies("--harmony-shadow-realm", "--experimental-shadow-realm"); | | 713 | + ImpliesNot("--no-harmony-shadow-realm", "--experimental-shadow-realm"); | | 714 | + | 706 | 715 | Insert(eop, &PerIsolateOptions::get_per_env_options); | 707 | 716 | } | 708 | 717 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -205,6 +205,7 @@ class PerIsolateOptions : public Options { | 205 | 205 | bool track_heap_objects = false; | 206 | 206 | bool report_uncaught_exception = false; | 207 | 207 | bool report_on_signal = false; | | 208 | + bool experimental_shadow_realm = false; | 208 | 209 | std::string report_signal = "SIGUSR2"; | 209 | 210 | inline EnvironmentOptions* get_per_env_options(); | 210 | 211 | void CheckOptions(std::vector<std::string>* errors) override; | |
Collapse file Copy file name to clipboard +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#include "node_shadow_realm.h" | | 2 | + | | 3 | +namespace node { | | 4 | +namespace shadow_realm { | | 5 | +using v8::Context; | | 6 | +using v8::Local; | | 7 | +using v8::MaybeLocal; | | 8 | + | | 9 | +// static | | 10 | +MaybeLocal<Context> HostCreateShadowRealmContextCallback( | | 11 | + Local<Context> initiator_context) { | | 12 | + return Context::New(initiator_context->GetIsolate()); | | 13 | +} | | 14 | + | | 15 | +} // namespace shadow_realm | | 16 | +} // namespace node |
Collapse file Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#ifndef SRC_NODE_SHADOW_REALM_H_ | | 2 | +#define SRC_NODE_SHADOW_REALM_H_ | | 3 | + | | 4 | +#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | | 5 | + | | 6 | +#include "v8.h" | | 7 | + | | 8 | +namespace node { | | 9 | +namespace shadow_realm { | | 10 | + | | 11 | +v8::MaybeLocal<v8::Context> HostCreateShadowRealmContextCallback( | | 12 | + v8::Local<v8::Context> initiator_context); | | 13 | + | | 14 | +} // namespace shadow_realm | | 15 | +} // namespace node | | 16 | + | | 17 | +#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | | 18 | + | | 19 | +#endif // SRC_NODE_SHADOW_REALM_H_ |
|