Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1419,16 +1419,6 @@ Use this flag to generate a blob that can be injected into the Node.js
binary to produce a [single executable application][]. See the documentation
about [this configuration][`--experimental-sea-config`] for details.

### `--experimental-shadow-realm`

<!-- YAML
added:
- v19.0.0
- v18.13.0
-->

Use this flag to enable [ShadowRealm][] support.

### `--experimental-storage-inspection`

<!-- YAML
Expand Down Expand Up @@ -3914,7 +3904,6 @@ one is included in the list below.
* `--experimental-quic`
* `--experimental-repl-await`
* `--experimental-require-module`
* `--experimental-shadow-realm`
* `--experimental-specifier-resolution`
* `--experimental-stream-iter`
* `--experimental-test-isolation`
Expand Down Expand Up @@ -4419,8 +4408,6 @@ documented here:

### `--expose-gc`

### `--harmony-shadow-realm`

### `--heap-snapshot-on-oom`

### `--interpreted-frames-native-stack`
Expand Down Expand Up @@ -4526,7 +4513,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[Permission Model]: permissions.md#permission-model
[REPL]: repl.md
[ScriptCoverage]: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ScriptCoverage
[ShadowRealm]: https://github.com/tc39/proposal-shadowrealm
[Source Map]: https://tc39.es/ecma426/
[Test tags]: test.md#test-tags
[TypeScript type-stripping]: typescript.md#type-stripping
Expand Down
4 changes: 0 additions & 4 deletions doc/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@
"type": "boolean",
"description": "Legacy alias for --require-module"
},
"experimental-shadow-realm": {
"type": "boolean",
"description": ""
},
"experimental-sqlite": {
"type": "boolean",
"description": "experimental node:sqlite module"
Expand Down
5 changes: 0 additions & 5 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,6 @@ Use this flag to generate a blob that can be injected into the Node.js
binary to produce a single executable application. See the documentation
about this configuration for details.
.
.It Fl -experimental-shadow-realm
Use this flag to enable ShadowRealm support.
.
.It Fl -experimental-storage-inspection
Enable experimental support for storage inspection
.
Expand Down Expand Up @@ -2016,8 +2013,6 @@ one is included in the list below.
.It
\fB--experimental-require-module\fR
.It
\fB--experimental-shadow-realm\fR
.It
\fB--experimental-specifier-resolution\fR
.It
\fB--experimental-stream-iter\fR
Expand Down
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export default [
ReadableStreamDefaultReader: 'readonly',
Response: 'readonly',
sessionStorage: 'readonly',
ShadowRealm: 'readonly',
Storage: 'readonly',
SubtleCrypto: 'readonly',
TextDecoderStream: 'readonly',
Expand Down
6 changes: 0 additions & 6 deletions lib/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@ export default [
name: 'Response',
message: "Use `const { Response } = require('internal/deps/undici/undici');` instead of the global.",
},
// ShadowRealm is not available in primordials because it can be
// disabled with --no-harmony-shadow-realm CLI flag.
{
name: 'ShadowRealm',
message: 'Use `const { ShadowRealm } = globalThis;` instead of the global.',
},
// SharedArrayBuffer is not available in primordials because it can be
// disabled with --enable-sharedarraybuffer-per-context CLI flag.
{
Expand Down
13 changes: 3 additions & 10 deletions lib/internal/bootstrap/realm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is executed in every realm that is created by Node.js, including
// the context of main thread, worker threads, and ShadowRealms.
// the context of the main thread and worker threads.
// Only per-realm internal states and bindings should be bootstrapped in this
// file and no globals should be exposed to the user code.
//
Expand Down Expand Up @@ -226,8 +226,8 @@ const internalBuiltinIds = builtinIds
.filter((id) => StringPrototypeStartsWith(id, 'internal/') && id !== selfId);

// When --expose-internals is on we'll add the internal builtin ids to these.
let canBeRequiredByUsersList = new SafeSet(publicBuiltinIds);
let canBeRequiredByUsersWithoutSchemeList =
const canBeRequiredByUsersList = new SafeSet(publicBuiltinIds);
const canBeRequiredByUsersWithoutSchemeList =
new SafeSet(publicBuiltinIds.filter((id) => !schemelessBlockList.has(id)));

/**
Expand Down Expand Up @@ -280,13 +280,6 @@ class BuiltinModule {
}
}

static setRealmAllowRequireByUsers(ids) {
canBeRequiredByUsersList =
new SafeSet(ArrayPrototypeFilter(ids, (id) => ArrayPrototypeIncludes(publicBuiltinIds, id)));
canBeRequiredByUsersWithoutSchemeList =
new SafeSet(ArrayPrototypeFilter(ids, (id) => !schemelessBlockList.has(id)));
}

// To be called during pre-execution when --expose-internals is on.
// Enables the user-land module loader to access internal modules.
static exposeInternals() {
Expand Down
21 changes: 0 additions & 21 deletions lib/internal/bootstrap/shadow_realm.js

This file was deleted.

8 changes: 3 additions & 5 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ function isPermissionModelError(err) {

/**
* Every realm has its own prepareStackTraceCallback. When `error.stack` is
* accessed, if the error is created in a shadow realm, the shadow realm's
* prepareStackTraceCallback is invoked. Otherwise, the principal realm's
* prepareStackTraceCallback is invoked. Note that accessing `error.stack`
* of error objects created in a VM Context will always invoke the
* prepareStackTraceCallback of the principal realm.
* accessed, the principal realm's prepareStackTraceCallback is invoked.
* Note that accessing `error.stack` of error objects created in a VM Context
* will always invoke the prepareStackTraceCallback of the principal realm.
* @param {object} globalThis The global object of the realm that the error was
* created in. When the error object is created in a VM Context, this is the
* global object of that VM Context.
Expand Down
30 changes: 0 additions & 30 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,6 @@ function prepareWorkerThreadExecution() {
});
}

function prepareShadowRealmExecution() {
// Patch the process object with legacy properties and normalizations.
// Do not expand argv1 as it is not available in ShadowRealm.
patchProcessObject(false);
setupDebugEnv();

// Disable custom loaders in ShadowRealm.
initializeModuleLoaders({ shouldSpawnLoaderHookWorker: false, shouldPreloadModules: false });
const {
privateSymbols: {
host_defined_option_symbol,
},
} = internalBinding('util');
const {
vm_dynamic_import_default_internal,
} = internalBinding('symbols');

// For ShadowRealm.prototype.importValue(), the referrer name is
// always null, so the native ImportModuleDynamically() callback would
// always fallback to look up the host-defined option from the
// global object using host_defined_option_symbol. Using
// vm_dynamic_import_default_internal as the host-defined option
// instructs the JS-land importModuleDynamicallyCallback() to
// proxy the request to defaultImportModuleDynamically().
globalThis[host_defined_option_symbol] =
vm_dynamic_import_default_internal;
}

function prepareExecution(options) {
const { expandArgv1, initializeModules, isMainThread, shouldSpawnLoaderHookWorker, shouldPreloadModules } = options;

Expand Down Expand Up @@ -247,7 +219,6 @@ function initializeModuleLoaders(options) {
}
// Do not enable preload modules if custom loaders are disabled.
// For example, loader workers are responsible for doing this themselves.
// And preload modules are not supported in ShadowRealm as well.
if (shouldPreloadModules) {
loadPreloadModules();
}
Expand Down Expand Up @@ -830,7 +801,6 @@ module.exports = {
initializeModuleLoaders,
prepareMainThreadExecution,
prepareWorkerThreadExecution,
prepareShadowRealmExecution,
prepareTestRunnerMainExecution,
markBootstrapComplete,
loadPreloadModules,
Expand Down
2 changes: 0 additions & 2 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
'src/node_sea.cc',
'src/node_sea_bin.cc',
'src/node_serdes.cc',
'src/node_shadow_realm.cc',
'src/node_snapshotable.cc',
'src/node_sockaddr.cc',
'src/node_stat_watcher.cc',
Expand Down Expand Up @@ -289,7 +288,6 @@
'src/node_revert.h',
'src/node_root_certs.h',
'src/node_sea.h',
'src/node_shadow_realm.h',
'src/node_snapshotable.h',
'src/node_snapshot_builder.h',
'src/node_sockaddr.h',
Expand Down
21 changes: 7 additions & 14 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ V8 refers to each of these global objects and their associated builtins as a

Currently, in Node.js there is one main `Context` associated with the
principal [`Realm`][] of an [`Environment`][] instance, and a number of
subsidiary `Context`s that are created with `vm.Context` or associated with
[`ShadowRealm`][].
subsidiary `Context`s that are created with `vm.Context`.

Most Node.js features will only work inside a context associated with a
`Realm`. The only exception at the time of writing are [`MessagePort`][]
Expand Down Expand Up @@ -358,14 +357,11 @@ Each ECMAScript realm comes with a global object and a set of intrinsic
objects. An ECMAScript realm has a `[[HostDefined]]` field, which represents
the Node.js [`Realm`][] object.

Every `Realm` instance is created for a particular [`Context`][]. A `Realm`
can be a principal realm or a synthetic realm. A principal realm is created
for each `Environment`'s main [`Context`][]. A synthetic realm is created
for the [`Context`][] of each [`ShadowRealm`][] constructed from the JS API. No
`Realm` is created for the [`Context`][] of a `vm.Context`.
Every `Realm` instance is created for a particular [`Context`][]. A principal
realm is created for each `Environment`'s main [`Context`][]. No `Realm` is
created for the [`Context`][] of a `vm.Context`.

Native bindings and built-in modules can be evaluated in either a principal
realm or a synthetic realm.
Native bindings and built-in modules are evaluated in the principal realm.

The `Realm` class contains a large number of different fields for
different built-in modules, for example the memory for a `Uint32Array` that
Expand Down Expand Up @@ -861,10 +857,8 @@ and requests are cancelled if possible.

#### Cleanup realms and BaseObjects

Realm cleanup depends on the realm types. All realms are destroyed when the
[`Environment`][] is destroyed with the cleanup hook. A [`ShadowRealm`][] can
also be destroyed by the garbage collection when there is no strong reference
to it.
All realms are destroyed when the [`Environment`][] is destroyed with the
cleanup hook.

Every [`BaseObject`][] is tracked with its creation realm and will be destroyed
when the realm is tearing down.
Expand Down Expand Up @@ -1493,7 +1487,6 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
[`MessagePort`]: https://nodejs.org/api/worker_threads.html#worker_threads_class_messageport
[`Realm`]: #realm
[`ReqWrap`]: #reqwrap
[`ShadowRealm`]: https://github.com/tc39/proposal-shadowrealm
[`async_hooks` module]: https://nodejs.org/api/async_hooks.html
[`async_wrap.h`]: async_wrap.h
[`base_object.h`]: base_object.h
Expand Down
8 changes: 0 additions & 8 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "node_options-inl.h"
#include "node_platform.h"
#include "node_realm-inl.h"
#include "node_shadow_realm.h"
#include "node_snapshot_builder.h"
#include "node_v8_platform-inl.h"
#include "node_wasm_web_api.h"
Expand Down Expand Up @@ -270,13 +269,6 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {

isolate->SetWasmStreamingCallback(wasm_web_api::StartStreamingCompilation);

Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
if (per_process::cli_options->get_per_isolate_options()
->experimental_shadow_realm) {
isolate->SetHostCreateShadowRealmContextCallback(
shadow_realm::HostCreateShadowRealmContextCallback);
}

if ((s.flags & SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK) == 0) {
auto* promise_reject_cb = s.promise_reject_callback ?
s.promise_reject_callback : PromiseRejectCallback;
Expand Down
2 changes: 0 additions & 2 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,6 @@ void AsyncWrap::CreatePerContextProperties(Local<Object> target,
#undef FORCE_SET_TARGET_FIELD

// TODO(legendecas): async hook functions are not realm-aware yet.
// This simply avoid overriding principal realm's functions when a
// ShadowRealm initializes the binding.
realm->set_async_hooks_init_function(Local<Function>());
realm->set_async_hooks_before_function(Local<Function>());
realm->set_async_hooks_after_function(Local<Function>());
Expand Down
12 changes: 0 additions & 12 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "node_internals.h"
#include "node_options-inl.h"
#include "node_process-inl.h"
#include "node_shadow_realm.h"
#include "node_snapshotable.h"
#include "node_v8_platform-inl.h"
#include "node_worker.h"
Expand Down Expand Up @@ -264,14 +263,6 @@ void Environment::UntrackContext(Local<Context> context) {
}
}

void Environment::TrackShadowRealm(shadow_realm::ShadowRealm* realm) {
shadow_realms_.insert(realm);
}

void Environment::UntrackShadowRealm(shadow_realm::ShadowRealm* realm) {
shadow_realms_.erase(realm);
}

AsyncHooks::DefaultTriggerAsyncIdScope::DefaultTriggerAsyncIdScope(
Environment* env, double default_trigger_async_id)
: async_hooks_(env->async_hooks()) {
Expand Down Expand Up @@ -1122,8 +1113,6 @@ Environment::~Environment() {
inspector_agent_.reset();
#endif

// Sub-realms should have been cleared with Environment's cleanup.
DCHECK_EQ(shadow_realms_.size(), 0);
principal_realm_.reset();

if (trace_state_observer_) {
Expand Down Expand Up @@ -2337,7 +2326,6 @@ void Environment::MemoryInfo(MemoryTracker* tracker) const {
tracker->TrackField("timeout_info", timeout_info_);
tracker->TrackField("tick_info", tick_info_);
tracker->TrackField("principal_realm", principal_realm_);
tracker->TrackField("shadow_realms", shadow_realms_);

// FIXME(joyeecheung): track other fields in Environment.
// Currently MemoryTracker is unable to track these
Expand Down
9 changes: 1 addition & 8 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class MacCache;

namespace node {

namespace shadow_realm {
class ShadowRealm;
}
namespace contextify {
class ContextifyScript;
class CompiledFnEntry;
Expand Down Expand Up @@ -620,8 +617,7 @@ class Cleanable {

/**
* Environment is a per-isolate data structure that represents an execution
* environment. Each environment has a principal realm. An environment can
* create multiple subsidiary synthetic realms.
* environment. Each environment has a principal realm.
*/
class Environment final : public MemoryRetainer {
public:
Expand Down Expand Up @@ -707,8 +703,6 @@ class Environment final : public MemoryRetainer {
Realm* realm,
const ContextInfo& info);
void UnassignFromContext(v8::Local<v8::Context> context);
void TrackShadowRealm(shadow_realm::ShadowRealm* realm);
void UntrackShadowRealm(shadow_realm::ShadowRealm* realm);

void StartProfilerIdleNotifier();

Expand Down Expand Up @@ -1148,7 +1142,6 @@ class Environment final : public MemoryRetainer {

size_t async_callback_scope_depth_ = 0;
std::vector<double> destroy_async_id_list_;
std::unordered_set<shadow_realm::ShadowRealm*> shadow_realms_;

#if HAVE_INSPECTOR
std::unique_ptr<profiler::V8CoverageConnection> coverage_connection_;
Expand Down
Loading
Loading