@@ -265,12 +265,16 @@ heap. Node.js exposes this ability through the [`vm` module][].
265265V8 refers to each of these global objects and their associated builtins as a
266266`Context`.
267267
268- Currently, in Node.js there is one main `Context` associated with a
269- [`Realm`][] instance, and most Node.js features will only work inside
270- that context. (The only exception at the time of writing are
271- [`MessagePort`][] objects.) This restriction is not inherent to the design of
272- Node.js, and a sufficiently committed person could restructure Node.js to
273- provide built-in modules inside of `vm.Context`s.
268+ Currently, in Node.js there is one main `Context` associated with the
269+ principal [`Realm`][] of an [`Environment`][] instance, and a number of
270+ subsidiary `Context`s that are created with `vm.Context` or associated with
271+ [`ShadowRealm`][].
272+
273+ Most Node.js features will only work inside a context associated with a
274+ `Realm`. The only exception at the time of writing are [`MessagePort`][]
275+ objects. This restriction is not inherent to the design of Node.js, and a
276+ sufficiently committed person could restructure Node.js to provide built-in
277+ modules inside of `vm.Context`s.
274278
275279Often, the `Context` is passed around for [exception handling][].
276280Typical ways of accessing the current `Context` in the Node.js code are:
@@ -310,7 +314,8 @@ Currently, every `Environment` class is associated with:
310314
311315The `Environment` class contains a large number of different fields for
312316different built-in modules that can be shared across different `Realm`
313- instances, for example a libuv timer for `setTimeout()`.
317+ instances, for example, the inspector agent, async hooks info, and the
318+ principal uncaught exception handlers.
314319
315320Typical ways of accessing the current `Environment` in the Node.js code are:
316321
@@ -329,20 +334,25 @@ Typical ways of accessing the current `Environment` in the Node.js code are:
329334### `Realm`
330335
331336The `Realm` class is a container for a set of JavaScript objects and functions
332- that are associated with a particular ECMAScript global environment .
337+ that are associated with a particular [ ECMAScript realm][] .
333338
334- Every `Realm` instance is associated with a [`Context`][].
339+ Each ECMAScript realm comes with a global object and a set of intrinsic
340+ objects. An ECMAScript realm has a `[[HostDefined]]` field, which represents
341+ the Node.js [`Realm`][] object.
335342
336- A `Realm` can be a principal realm or a synthetic realm. A principal realm is
337- created with an `Environment` as its principal global environment to evaluate
338- scripts. A synthetic realm is created with JS APIs like `ShadowRealm`.
343+ Every `Realm` instance is created for a particular [`Context`][]. A `Realm`
344+ can be a principal realm or a synthetic realm. A principal realm is created
345+ for each `Environment`'s main [`Context`][]. A synthetic realm is created
346+ for the [`Context`][] of each [`ShadowRealm`][] constructed from the JS API. No
347+ `Realm` is created for the [`Context`][] of a `vm.Context`.
339348
340349Native bindings and built-in modules can be evaluated in either a principal
341350realm or a synthetic realm.
342351
343352The `Realm` class contains a large number of different fields for
344- different built-in modules, for example the memory for a `Float64Array` that
345- the `fs` module uses for storing data returned from a `fs.stat()` call.
353+ different built-in modules, for example the memory for a `Uint32Array` that
354+ the `url` module uses for storing data returned from a
355+ `urlBinding.update()` call.
346356
347357It also provides [cleanup hooks][] and maintains a list of [`BaseObject`][]
348358instances.
@@ -356,7 +366,7 @@ Typical ways of accessing the current `Realm` in the Node.js code are:
356366 This requires that `context` has been associated with the `Realm`
357367 instance, e.g. is the principal `Realm` for the `Environment`.
358368* Given an [`Isolate`][], using `Realm::GetCurrent(isolate)`. This looks
359- up the current [`Context`][] and then uses that .
369+ up the current [`Context`][] and then uses its `Realm` .
360370
361371<a id="isolate-data"></a>
362372
@@ -1073,6 +1083,7 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
10731083
10741084[ C++ coding style ] : ../doc/contributing/cpp-style-guide.md
10751085[ Callback scopes ] : #callback-scopes
1086+ [ ECMAScript realm ] : https://tc39.es/ecma262/#sec-code-realms
10761087[ JavaScript value handles ] : #js-handles
10771088[ N-API ] : https://nodejs.org/api/n-api.html
10781089[ `BaseObject` ] : #baseobject
@@ -1087,6 +1098,7 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
10871098[ `MessagePort` ] : https://nodejs.org/api/worker_threads.html#worker_threads_class_messageport
10881099[ `Realm` ] : #realm
10891100[ `ReqWrap` ] : #reqwrap
1101+ [ `ShadowRealm` ] : https://github.com/tc39/proposal-shadowrealm
10901102[ `async_hooks` module ] : https://nodejs.org/api/async_hooks.html
10911103[ `async_wrap.h` ] : async_wrap.h
10921104[ `base_object.h` ] : base_object.h
0 commit comments