forked from tc39/proposal-shadowrealm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.html
547 lines (513 loc) · 24.2 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
<!doctype html>
<html lang="en-GB-oxendict">
<head>
<meta charset="utf8">
<link href="ecmarkup.css" rel="stylesheet">
<script src="ecmarkup.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/solarized-light.min.css">
</head>
<body>
<pre class="metadata">
title: 'ShadowRealm API'
stage: 3
contributors: Dave Herman, Caridy Patiño, Mark Miller, Leo Balter
status: proposal
copyright: false
location: https://tc39.es/proposal-shadowrealm/
</pre>
<emu-biblio href="./biblio.json"></emu-biblio>
<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>%ShadowRealm%</td>
<td>`ShadowRealm`</td>
<td>The ShadowRealm constructor (<emu-xref href="#sec-shadowrealm-constructor"></emu-xref>)</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-wrapped-function-exotic-objects">
<h1>Wrapped Function Exotic Objects</h1>
<p>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.</p>
<p>An object is a <dfn id="wrapped-function-exotic-object">wrapped function exotic object</dfn> if its [[Call]] internal method uses the following implementation, and its other essential internal methods use the definitions found in <emu-xref href="#sec-ordinary-object-internal-methods-and-internal-slots"></emu-xref>. These methods are installed in WrappedFunctionCreate.</p>
<p>Wrapped function exotic objects do not have the internal slots of ECMAScript function objects listed in <emu-xref aoid="Internal Slots of ECMAScript Function Objects"></emu-xref>. Instead they have the internal slots listed in <emu-xref href="#table-internal-slots-of-wrapped-function-exotic-objects"></emu-xref>, in addition to [[Prototype]] and [[Extensible]].</p>
<emu-table id="table-internal-slots-of-wrapped-function-exotic-objects" caption="Internal Slots of Wrapped Function Exotic Objects">
<table>
<tbody>
<tr>
<th>
Internal Slot
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
<tr>
<td>
[[WrappedTargetFunction]]
</td>
<td>
Callable Object
</td>
<td>
Stores the callable object.
</td>
</tr>
<tr>
<td>
[[Call]]
</td>
<td>
The [[Call]] internal method
</td>
<td>
Executes code associated with this object's [[WrappedTargetFunction]].
</td>
</tr>
<tr>
<td>
[[Realm]]
</td>
<td>
Realm Record
</td>
<td>
The realm in which the function was created.
</td>
</tr>
</tbody>
</table>
</emu-table>
<emu-clause id="sec-wrapped-function-exotic-objects-call-thisargument-argumentslist" type="internal method">
<h1>
[[Call]] (
_thisArgument_: an ECMAScript language value,
_argumentsList_: a List of ECMAScript language values,
)
</h1>
<dl class="header">
<dt>for</dt>
<dd>a wrapped function exotic object _F_</dd>
</dl>
<emu-alg>
1. Let _callerContext_ be the running execution context.
1. Let _calleeContext_ be PrepareForWrappedFunctionCall(_F_).
1. Assert: _calleeContext_ is now the running execution context.
1. Let result be OrdinaryWrappedFunctionCall(_F_, _thisArgument_, _argumentsList_).
1. Remove _calleeContext_ from the execution context stack and restore _callerContext_ as the running execution context.
1. If result.[[Type]] is return, return result.[[Value]].
1. ReturnIfAbrupt(result).
1. Return *undefined*.
</emu-alg>
<emu-note type=editor>
In the case of an abrupt ~throw~ completion, the type of error to be created should match the type of the abrupt throw completion record. This could be revisited when merging into the main specification. Additionally, in the case of a ~break~ or ~continue~ completion, since those are not supported, a TypeError is expected.
</emu-note>
</emu-clause>
<emu-clause id="sec-ordinary-wrapped-function-call" type="abstract operation">
<h1>
OrdinaryWrappedFunctionCall (
_F_: a wrapped function exotic object,
_thisArgument_: an ECMAScript language value,
_argumentsList_: a List of ECMAScript language values,
)
</h1>
<emu-alg>
1. Let _target_ be _F_.[[WrappedTargetFunction]].
1. Assert: IsCallable(_target_) is *true*.
1. Let _callerRealm_ be _F_.[[Realm]].
1. NOTE: Any exception objects produced after this point are associated with _callerRealm_.
1. Let _targetRealm_ be ? GetFunctionRealm(_target_).
1. Let _wrappedArgs_ be a new empty List.
1. For each element _arg_ of _argumentsList_, do
1. Let _wrappedValue_ be ? GetWrappedValue(_targetRealm_, _arg_).
1. Append _wrappedValue_ to _wrappedArgs_.
1. Let _wrappedThisArgument_ to ? GetWrappedValue(_targetRealm_, _thisArgument_).
1. Let _result_ be the Completion Record of Call(_target_, _wrappedThisArgument_, _wrappedArgs_).
1. If _result_.[[Type]] is ~normal~ or _result_.[[Type]] is ~return~, then
1. Return ? GetWrappedValue(_callerRealm_, _result_.[[Value]]).
1. Else,
1. Throw a *TypeError* exception.
</emu-alg>
</emu-clause>
<emu-clause id="sec-prepare-for-wrapped-function-call" type="abstract operation">
<h1>
PrepareForWrappedFunctionCall (
_F_: a wrapped function exotic object,
)
</h1>
<emu-alg>
1. Let callerContext be the running execution context.
1. Let calleeContext be a new execution context.
1. Set the Function of calleeContext to F.
1. Let calleeRealm be F.[[Realm]].
1. Set the Realm of calleeContext to calleeRealm.
1. Set the ScriptOrModule of calleeContext to *null*.
1. If callerContext is not already suspended, suspend callerContext.
1. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
1. NOTE: Any exception objects produced after this point are associated with calleeRealm.
1. Return calleeContext.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-shadowrealm-objects">
<h1>ShadowRealm Objects</h1>
<emu-clause id="sec-shadowrealm-abstracts">
<h1>ShadowRealm Abstract Operations</h1>
<emu-clause id="sec-wrappedfunctioncreate" aoid="WrappedFunctionCreate" type="abstract operation">
<h1>
WrappedFunctionCreate (
_callerRealm_: a Realm Record,
_Target_: a function object,
)
</h1>
<p>The abstract operation WrappedFunctionCreate takes arguments _callerRealm_ and _Target_. It is used to specify the creation of new wrapped function exotic objects. It performs the following steps when called:</p>
<emu-alg>
1. Let _internalSlotsList_ be the internal slots listed in <emu-xref href="#table-internal-slots-of-wrapped-function-exotic-objects"></emu-xref>, plus [[Prototype]] and [[Extensible]].
1. Let _wrapped_ be MakeBasicObject(_internalSlotsList_).
1. Set _wrapped_.[[Prototype]] to _callerRealm_.[[Intrinsics]].[[%Function.prototype%]].
1. Set _wrapped_.[[Call]] as described in <emu-xref href="#sec-wrapped-function-exotic-objects-call-thisargument-argumentslist"></emu-xref>.
1. Set _wrapped_.[[WrappedTargetFunction]] to _Target_.
1. Set _wrapped_.[[Realm]] to _callerRealm_.
1. Let _result_ be CopyNameAndLength(_wrapped_, _Target_).
1. If _result_ is an Abrupt Completion, throw a TypeError exception.
1. Return _wrapped_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-copynameandlength" aoid="CopyNameAndLength" type="abstract operation">
<h1>
CopyNameAndLength (
_F_: a function object,
_Target_: a function object,
optional _prefix_: a String,
optional _argCount_: a Number,
)
</h1>
<emu-alg>
1. If _argCount_ is *undefined*, then set _argCount_ to 0.
1. Let _L_ be 0.
1. Let _targetHasLength_ be ? HasOwnProperty(_Target_, *"length"*).
1. If _targetHasLength_ is *true*, then
1. Let _targetLen_ be ? Get(_Target_, *"length"*).
1. If Type(_targetLen_) is Number, then
1. If _targetLen_ is *+∞*<sub>𝔽</sub>, set _L_ to +∞.
1. Else if _targetLen_ is *-∞*<sub>𝔽</sub>, set _L_ to 0.
1. Else,
1. Let _targetLenAsInt_ be ! ToIntegerOrInfinity(_targetLen_).
1. Assert: _targetLenAsInt_ is finite.
1. Set _L_ to max(_targetLenAsInt_ - _argCount_, 0).
1. Perform SetFunctionLength(_F_, _L_).
1. Let _targetName_ be ? Get(_Target_, *"name"*).
1. If Type(_targetName_) is not String, set _targetName_ to the empty String.
1. Perform SetFunctionName(_F_, _targetName_, _prefix_).
</emu-alg>
<emu-note type=editor>
Function.prototype.bind can replace steps 4 to 10 with this abstraction.
</emu-note>
<emu-clause id="sec-function.prototype.bind">
<h1>Function.prototype.bind ( _thisArg_, ..._args_ )</h1>
<p>When the `bind` method is called with argument _thisArg_ and zero or more _args_, it performs the following steps:</p>
<emu-alg>
1. Let _Target_ be the *this* value.
1. If IsCallable(_Target_) is *false*, throw a *TypeError* exception.
1. Let _F_ be ? BoundFunctionCreate(_Target_, _thisArg_, _args_).
1. <ins>Let _argCount_ be the number of elements in _args_.
1. <ins>Perform ? CopyNameAndLength(_F_, _Target_, *"bound"*, _argCount_).
1. <del>Let _L_ be 0.
1. <del>Let _targetHasLength_ be ? HasOwnProperty(_Target_, *"length"*).
1. <del>If _targetHasLength_ is *true*, then
1. <del>Let _targetLen_ be ? Get(_Target_, *"length"*).
1. <del>If Type(_targetLen_) is Number, then
1. <del>If _targetLen_ is *+∞*<sub>𝔽</sub>, set _L_ to +∞.
1. <del>Else if _targetLen_ is *-∞*<sub>𝔽</sub>, set _L_ to 0.
1. <del>Else,
1. <del>Let _targetLenAsInt_ be ! ToIntegerOrInfinity(_targetLen_).
1. <del>Assert: _targetLenAsInt_ is finite.
1. <del>Let _argCount_ be the number of elements in _args_.
1. <del>Set _L_ to max(_targetLenAsInt_ - _argCount_, 0).
1. <del>Perform SetFunctionLength(_F_, _L_).
1. <del>Let _targetName_ be ? Get(_Target_, *"name"*).
1. <del>If Type(_targetName_) is not String, set _targetName_ to the empty String.
1. <del>Perform SetFunctionName(_F_, _targetName_, *"bound"*).</del>
1. Return _F_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-performshadowrealmeval" aoid="PerformShadowRealmEval" type="abstract operation">
<h1>
PerformShadowRealmEval (
_sourceText_: a String,
_callerRealm_: a Realm Record,
_evalRealm_: a Realm Record,
)
</h1>
<emu-alg>
1. Perform ? HostEnsureCanCompileStrings(_callerRealm_, _evalRealm_).
1. Perform the following substeps in an implementation-defined order, possibly interleaving parsing and error detection:
1. Let _script_ be ParseText(StringToCodePoints(_sourceText_), |Script|).
1. If _script_ is a List of errors, throw a *SyntaxError* exception.
1. If _script_ Contains |ScriptBody| is *false*, return *undefined*.
1. Let _body_ be the |ScriptBody| of _script_.
1. If _body_ Contains |NewTarget| is *true*, throw a *SyntaxError* exception.
1. If _body_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception.
1. If _body_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
1. Let _strictEval_ be IsStrict of _script_.
1. Let _runningContext_ be the running execution context.
1. Let _lexEnv_ be NewDeclarativeEnvironment(_evalRealm_.[[GlobalEnv]]).
1. Let _varEnv_ be _evalRealm_.[[GlobalEnv]].
1. If _strictEval_ is *true*, set _varEnv_ to _lexEnv_.
1. If _runningContext_ is not already suspended, suspend _runningContext_.
1. Let _evalContext_ be a new ECMAScript code execution context.
1. Set _evalContext_'s Function to *null*.
1. Set _evalContext_'s Realm to _evalRealm_.
1. Set _evalContext_'s ScriptOrModule to *null*.
1. Set _evalContext_'s VariableEnvironment to _varEnv_.
1. Set _evalContext_'s LexicalEnvironment to _lexEnv_.
1. Push _evalContext_ onto the execution context stack; _evalContext_ is now the running execution context.
1. Let _result_ be Completion(EvalDeclarationInstantiation(_body_, _varEnv_, _lexEnv_, *null*, _strictEval_)).
1. If _result_.[[Type]] is ~normal~, then
1. Set _result_ to the result of evaluating _body_.
1. If _result_.[[Type]] is ~normal~ and _result_.[[Value]] is ~empty~, then
1. Set result to NormalCompletion(*undefined*).
1. Suspend _evalContext_ and remove it from the execution context stack.
1. Resume the context that is now on the top of the execution context stack as the running execution context.
1. If _result_.[[Type]] is not ~normal~, throw a *TypeError* exception.
1. Return ? GetWrappedValue(_callerRealm_, _result_.[[Value]]).
</emu-alg>
<emu-note type=editor>
In the case of an abrupt ~throw~ completion, the type of error to be created should match the type of the abrupt throw completion record. This could be revisited when merging into the main specification. Additionally, in the case of a ~break~ or ~continue~ completion, since those are not supported, a TypeError is expected. There should be no ~return~ completion because this is a top level script evaluation, in which case a return |Statement| must result in a parsing error.
</emu-note>
<emu-note type=editor>
Some steps from PerformShadowRealmEval are shared with |eval| and |Function| and should result into a shared abstraction when merged to ECMA-262.
</emu-note>
<emu-note>
This abstraction requires the performed evaluation to result into a normal completion. Otherwise, if the result is not a normal completion, the abstraction will throw a TypeError exception associated to its original running execution context.
</emu-note>
</emu-clause>
<emu-clause id="sec-shadowrealmimportvalue" aoid="ShadowRealmImportValue" type="abstract operation">
<h1>
ShadowRealmImportValue (
_specifierString_: a String,
_exportNameString_: a String,
_callerRealm_: a Realm Record,
_evalRealm_: a Realm Record,
_evalContext_: an execution context,
)
</h1>
<emu-alg>
1. Assert: _evalContext_ is an execution context associated to a ShadowRealm instance's [[ExecutionContext]].
1. Let _innerCapability_ be ! NewPromiseCapability(%Promise%).
1. Let _runningContext_ be the running execution context.
1. If _runningContext_ is not already suspended, suspend _runningContext_.
1. Push _evalContext_ onto the execution context stack; _evalContext_ is now the running execution context.
1. Perform HostImportModuleDynamically(*null*, _specifierString_, _innerCapability_).
1. Suspend _evalContext_ and remove it from the execution context stack.
1. Resume the context that is now on the top of the execution context stack as the running execution context.
1. Let _steps_ be the steps of an ExportGetter function as described below.
1. Let _onFulfilled_ be CreateBuiltinFunction(_steps_, 1, *""*, « [[ExportNameString]] », _callerRealm_).
1. Set _onFulfilled_.[[ExportNameString]] to _exportNameString_.
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. Return PerformPromiseThen(_innerCapability_.[[Promise]], _onFulfilled_, _callerRealm_.[[Intrinsics]].[[%ThrowTypeError%]], _promiseCapability_).
</emu-alg>
<p>An ExportGetter function is an anonymous built-in function with a [[ExportNameString]] internal slot. When an ExportGetter function is called with argument _exports_, it performs the following steps:</p>
<emu-alg>
1. Assert: _exports_ is a module namespace exotic object.
1. Let _f_ be the active function object.
1. Let _string_ be _f_.[[ExportNameString]].
1. Assert: Type(_string_) is String.
1. Let _hasOwn_ be ? HasOwnProperty(_exports_, _string_).
1. If _hasOwn_ is *false*, throw a *TypeError* exception.
1. Let _value_ be ? Get(_exports_, _string_).
1. Let _realm_ be _f_.[[Realm]].
1. Return ? GetWrappedValue(_realm_, _value_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-getwrappedvalue" aoid="GetWrappedValue" type="abstract operation">
<h1>
GetWrappedValue (
_callerRealm_: a Realm Record,
_value_: unknown,
)
</h1>
<emu-alg>
1. If Type(_value_) is Object, then
1. If IsCallable(_value_) is *false*, throw a TypeError exception.
1. Return ? WrappedFunctionCreate(_callerRealm_, _value_).
1. Return _value_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-validateshadowrealmobject" aoid="ValidateShadowRealmObject" type="abstract operation">
<h1>
ValidateShadowRealmObject (
_O_: unknown
)
</h1>
<emu-alg>
1. Perform ? RequireInternalSlot(_O_, [[ShadowRealm]]).
1. Perform ? RequireInternalSlot(_O_, [[ExecutionContext]]).
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-shadowrealm-constructor">
<h1>The ShadowRealm Constructor</h1>
<p>The ShadowRealm constructor:</p>
<ul>
<li>is the intrinsic object <dfn>%ShadowRealm%</dfn>.</li>
<li>is the initial value of the *"ShadowRealm"* 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 ShadowRealm 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 `ShadowRealm` behaviour must include a `super` call to the `ShadowRealm` constructor to create and initialize the subclass instance with the internal state necessary to support the `ShadowRealm.prototype` built-in methods.</li>
</ul>
<emu-clause id="sec-shadowrealm">
<h1>ShadowRealm ( )</h1>
<p>When the `ShadowRealm` function is called, the following steps are taken:</p>
<emu-alg>
1. If NewTarget is *undefined*, throw a *TypeError* exception.
1. Let _O_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%ShadowRealm.prototype%"*, « [[ShadowRealm]], [[ExecutionContext]] »).
1. Let _realmRec_ be CreateRealm().
1. Set _O_.[[ShadowRealm]] 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_.[[ShadowRealm]]).
1. Perform ? HostInitializeShadowRealm(_O_.[[ShadowRealm]]).
1. Return _O_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-shadowRealm-constructor">
<h1>Properties of the ShadowRealm Constructor</h1>
<p>The ShadowRealm constructor:</p>
<ul>
<li>has a [[Prototype]] internal slot whose value is %Function.prototype%.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-shadowrealm.prototype">
<h1>ShadowRealm.prototype</h1>
<p>The initial value of *ShadowRealm.prototype* is %ShadowRealm.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-shadowrealm-prototype-object">
<h1>Properties of the ShadowRealm Prototype Object</h1>
<p>The ShadowRealm prototype object:</p>
<ul>
<li>has a [[Prototype]] internal slot whose value is <dfn>%Object.prototype%</dfn>.</li>
<li>is %ShadowRealm.prototype%.</li>
<li>is an ordinary object.</li>
<li>does not have a [[ShadowRealm]] or any other of the internal slots that are specific to _Realm_ instance objects.</li>
</ul>
<emu-clause id="sec-shadowrealm.prototype.evaluate">
<h1>ShadowRealm.prototype.evaluate ( _sourceText_ )</h1>
<p>Synchronously execute a top-level script. The _sourceText_ is interpreted as a Script and evaluated with this bound to the shadowrealm's global object.</p>
<emu-alg>
1. Let _O_ be *this* value.
1. Perform ? ValidateShadowRealmObject(_O_).
1. If Type(_sourceText_) is not String, throw a *TypeError* exception.
1. Let _callerRealm_ be the current Realm Record.
1. Let _evalRealm_ be _O_.[[ShadowRealm]].
1. Return ? PerformShadowRealmEval(_sourceText_, _callerRealm_, _evalRealm_).
</emu-alg>
<emu-note type=editor>
Extensible web: This is the dynamic equivalent of a <script> in HTML.
</emu-note>
</emu-clause>
<emu-clause id="sec-shadowrealm.prototype.importvalue">
<h1>ShadowRealm.prototype.importValue ( _specifier_, _exportName_ )</h1>
<p>The following steps are performed:</p>
<emu-alg>
1. Let _O_ be *this* value.
1. Perform ? ValidateShadowRealmObject(_O_).
1. Let _specifierString_ be ? ToString(_specifier_).
1. If Type(_exportName_) is not String, throw a *TypeError* exception.
1. Let _callerRealm_ be the current Realm Record.
1. Let _evalRealm_ be _O_.[[ShadowRealm]].
1. Let _evalContext_ be _O_.[[ExecutionContext]].
1. Return ? ShadowRealmImportValue(_specifierString_, _exportName_, _callerRealm_, _evalRealm_, _evalContext_).
</emu-alg>
<emu-note type=editor>
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-clause>
<emu-clause id="sec-shadowrealm.prototype-@@tostringtag">
<h1>ShadowRealm.prototype [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the String value *"ShadowRealm"*.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-shadowrealm-instances">
<h1>Properties of ShadowRealm Instances</h1>
<p>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 <emu-xref href="#table-internal-slots-of-shadowrealm-instances"></emu-xref>.</p>
<emu-table id="table-internal-slots-of-shadowrealm-instances" caption="Internal Slots of ShadowRealm Instances">
<table>
<tbody>
<tr>
<th>Internal Slot</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>[[ShadowRealm]]</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 [[ShadowRealm]].</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-shadowrealm-host-operations">
<h1>Host operations</h1>
<emu-clause id="sec-host-initialize-shadow-shadowrealm" aoid="HostInitializeShadowRealm">
<h1>Runtime Semantics: HostInitializeShadowRealm ( _realm_ )</h1>
<p>
HostInitializeShadowRealm is an implementation-defined abstract
operation used to inform the host of any newly created realms from
the ShadowRealm 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 ShadowRealm, e.g., for module loading.
</p>
<p>
The host may use this hook to add properties to the ShadowRealm's global
object. Those properties must be configurable.
</p>
<emu-note>
<p>
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`, `console`, `localStorage`, `fetch`, etc..
</p>
</emu-note>
<emu-note type=editor>
<p>
The ShadowRealm constructor (<emu-xref href="#sec-shadowrealm"></emu-xref>
creates a new global object as an ordinary object. This
means all properties from the global object are deletable.
</p>
</emu-note>
</emu-clause>
</emu-clause>
</emu-clause>
</body>
</html>