title: 'ShadowRealm API' stage: 2.7 contributors: Dave Herman, Caridy Patiño, Mark Miller, Leo Balter status: proposal copyright: false location: https://tc39.es/proposal-shadowrealm/
| Intrinsic Name | Global Name | ECMAScript Language Association |
|---|---|---|
| %ShadowRealm% | `ShadowRealm` | The ShadowRealm constructor ( |
A wrapped function exotic object is an exotic object that wraps a callable object. A wrapped function exotic object is callable (it has a [[Call]] internal method). Calling a wrapped function exotic object generally results in a call of its wrapped function.
An object is a wrapped function exotic object if its [[Call]] internal method uses the following implementation, and its other essential internal methods use the definitions found in
Wrapped function exotic objects do not have the internal slots of ECMAScript function objects listed in
| Internal Slot | Type | Description |
|---|---|---|
| [[WrappedTargetFunction]] | Callable Object | Stores the callable object. |
| [[Call]] | The [[Call]] internal method | Executes code associated with this object's [[WrappedTargetFunction]]. |
| [[Realm]] | Realm Record | The realm in which the function was created. |
If an execution in a ShadowRealm _R1_ oblivious of host or implementation-defined APIs can observe the identity of an object _O1_, a host or implementation-defined API must not allow an execution in any other realm than _R1_ to also observe the identity of _O1_. Similarly if an execution in a realm _R2_ can observe the identity of an object _O2_, a host or implementation-defined API must not allow execution in any other realm than _R2_ that is a ShadowRealm to also observe the identity of _O2_.
Host environments may provide implementation-specific message value. CreateTypeErrorCopy abstract operation must not cause any ECMAScript code execution. The implementation may store additional information on _originalError_ to produce the _newError_'s message.
This method performs the following steps when called:
An ExportGetter function is an anonymous built-in function that has an [[ExportNameString]] internal slot.
When an ExportGetter function is called with argument _exports_, it performs the following steps:
An ImportValueError function is an anonymous built-in function.
When an ImportValueError function is called with argument _error_, it performs the following steps:
The ShadowRealm constructor:
This function performs the following steps when called:
The ShadowRealm constructor:
The initial value of *ShadowRealm.prototype* is %ShadowRealm.prototype%.
This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.
The ShadowRealm prototype object:
Synchronously execute a top-level script. The _sourceText_ is interpreted as a Script and evaluated with this bound to the ShadowRealm's global object.
The following steps are performed:
The initial value of the @@toStringTag property is the String value *"ShadowRealm"*.
This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.
ShadowRealm instances are ordinary objects that inherit properties from the ShadowRealm prototype object (the intrinsic %ShadowRealm.prototype%). ShadowRealm instances are initially created with the internal slots described in
| Internal Slot | Type | Description |
|---|---|---|
| [[ShadowRealm]] | Realm Record | The Realm Record for the initial execution context. |
This specification does not recommend any specific addition. In the Web embedding, HTML and WebIDL will specify which interfaces are included. The Web Platform and Web-like environments may decide to include `EventTarget`, `atob`, `TextEncoder`, `URL`, etc. while at the same time not including `HTMLElement`, `localStorage`, `fetch`, etc.
If a host defines that a specific global object is to be used for a ShadowRealm, that object must be an extensible ordinary object, and any properties on it must be configurable.