forked from tc39/proposal-shadowrealm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.html
182 lines (165 loc) · 7.7 KB
/
spec.html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!doctype html>
<meta charset="utf8">
<pre class="metadata">
title: 'Realms API'
stage: 2
contributors: Dave Herman, Caridy Patiño, Mark Miller, Leo Balter
status: proposal
copyright: false
location: https://tc39.es/proposal-realms/
</pre>
<link href="ecmarkup.css" rel="stylesheet">
<script src="ecmarkup.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<emu-clause id="sec-well-known-intrinsic-objects">
<h1>Well-known intrinsic objects</h1>
<emu-table id="table-7" caption="Well-known Intrinsic Objects">
<table>
<tbody>
<tr>
<th>Intrinsic Name</th>
<th>Global Name</th>
<th>ECMAScript Language Association</th>
</tr>
<tr>
<td>%Realm%</td>
<td>`Realm`</td>
<td>The Realm constructor (<emu-xref href="#sec-realm-constructor"></emu-xref>)</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-realm-objects">
<h1>Realm Objects</h1>
<emu-clause id="sec-realm-constructor">
<h1>The Realm Constructor</h1>
<p>The Realm constructor:</p>
<ul>
<li>is the intrinsic object <dfn>%Realm%</dfn>.</li>
<li>is the initial value of the *"Realm"* property of the global object.</li>
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
<li>creates and initializes a new Realm object when called as a constructor.</li>
<li>is designed to be subclassable. It may be used as the value in an `extends` clause of a class definition. Subclass constructors that intend to inherit the specified `Realm` behaviour must include a `super` call to the `Realm` constructor to create and initialize the subclass instance with the internal state necessary to support the `Realm.prototype` built-in methods.</li>
</ul>
<emu-clause id="sec-realm">
<h1>Realm ()</h1>
<p>When the `Realm` function is called with no arguments, the following steps are taken:</p>
<emu-alg>
1. If NewTarget is *undefined*, throw a *TypeError* exception.
1. Let _O_ be ? OrdinaryCreateFromConstructor(NewTarget, "%Realm.prototype%", « [[Realm]], [[ExecutionContext]] »).
1. Let _realmRec_ be CreateRealm().
1. Set _O_.[[Realm]] to _realmRec_.
1. Let _context_ be a new execution context.
1. Set the Function of _context_ to *null*.
1. Set the Realm of _context_ to _realmRec_.
1. Set the ScriptOrModule of _context_ to *null*.
1. Set _O_.[[ExecutionContext]] to _context_.
1. Perform ? SetRealmGlobalObject(_realmRec_, *undefined*, *undefined*).
1. Perform ? SetDefaultGlobalBindings(_O_.[[Realm]]).
1. Perform ? HostInitializeUserRealm(_O_.[[Realm]]).
1. Return _O_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-realm-constructor">
<h1>Properties of the Realm Constructor</h1>
<p>The Realm constructor:</p>
<ul>
<li>as a [[Prototype]] internal slot whose value is %Function.prototype%.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-realm.prototype">
<h1>Realm.prototype</h1>
<p>The initial value of *Realm.prototype* is %Realm.prototype%.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-realm-prototype-object">
<h1>Properties of the Realm Prototype Object</h1>
<p>The Realm prototype object:</p>
<ul>
<li>is the intrinsic object <dfn>%Realm.prototype%</dfn>.</li>
<li>is the initial value of the "*prototype*" property of %Realm%.</li>
<li>is an ordinary object.</li>
<li>is not a Realm instance and does not have a [[Realm]] internal slot.</li>
</ul>
<emu-clause id="sec-realm.prototype.import">
<h1>Realm.prototype.import ( _specifier_ )</h1>
<p>The following steps are performed:</p>
<emu-alg>
1. Let _O_ be *this* value.
1. Perform ? RequireInternalSlot(_O_, [[Realm]]).
1. Let _referencingScriptOrModule_ be *null*.
1. Let _specifierString_ be ? ToString(_specifier_).
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
1. Let _callerContext_ be the running execution context.
1. Push _O_.[[ExecutionContext]] onto the execution context stack; _O_.[[ExecutionContext]] is now the running execution context.
1. Perform ! HostImportModuleDynamically(_referencingScriptOrModule_, _specifierString_, _promiseCapability_).
1. Remove _O_.[[ExecutionContext]] from the execution context stack and restore _callerContext_ as the running execution context.
1. Return _promiseCapability_.[[Promise]].
</emu-alg>
<emu-note>
Extensible web: This is equivalent to dynamic import without having to evaluate a script source, which might not be available (e.g.: when CSP is blocking source evaluation).
</emu-note>
<emu-note type=editor>
An extra execution context is created around the call to HostImportModuleDynamically in order to execute within the appropriate Realm--the host can reference the current Realm to figure out how the import should work. An alternative phrasing would be to pass the Realm as a parameter to HostImportModuleDynamically, which could be revisited when merging into the main specification.
</emu-note>
</emu-clause>
<emu-clause id="sec-realm.prototype.globalthis">
<h1>get Realm.prototype.globalThis</h1>
<p>Realm.prototype.globalThis is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps:</p>
<emu-alg>
1. Let _O_ be *this* value.
1. Perform ? RequireInternalSlot(_O_, [[Realm]]).
1. Return _O_.[[Realm]].[[GlobalEnv]].[[GlobalThisValue]].
</emu-alg>
</emu-clause>
<emu-clause id="sec-realm.prototype-@@tostringtag">
<h1>Realm.prototype [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the String value "Realm".</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-realm-instances">
<h1>Properties of Realm Instances</h1>
<p>Realm instances are ordinary objects that inherit properties from the Realm prototype object (the intrinsic, %Realm.prototype%). Realm instances are initially created with the internal slots described in <emu-xref href="#table-internal-slots-of-realm-instances"></emu-xref>.</p>
<emu-table id="table-internal-slots-of-realm-instances" caption="Internal Slots of Realm Instances">
<table>
<tbody>
<tr>
<th>Internal Slot</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>[[Realm]]</td>
<td>Realm Record</td>
<td>The Realm Record for the initial execution context.</td>
</tr>
<tr>
<td>[[ExecutionContext]]</td>
<td>Execution context</td>
<td>An execution context wherein the current Realm is this [[Realm]].</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-realm-host-operations">
<h1>Host operations</h1>
<emu-clause id="sec-host-initialize-user-realm" aoid="HostInitializeUserRealm">
<h1>Runtime Semantics: HostInitializeUserRealm ( _realm_ )</h1>
<p>
HostInitializerUserRealm is an implementation-defined abstract
operation used to inform the host of any newly created realms from
the Realm constructor. Its return value is not used, though it may
throw an exception. The idea of this hook is to initialize host
data structures related to the Realm, e.g., for module loading. It
is not expected that this hook would add properties to the Realm's
global object.
</p>
</emu-clause>
</emu-clause>
</emu-clause>