Skip to content

Commit da34edf

Browse files
authored
Type check in AsyncContext.wrap (#32)
1 parent 8c3343f commit da34edf

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

spec.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,29 @@ <h1>Properties of the AsyncContext Constructor</h1>
392392
</ul>
393393

394394
<emu-clause id="sec-asynccontext-wrap">
395-
<h1>AsyncContext.wrap ( _func_ )</h1>
395+
<h1>AsyncContext.wrap ( _target_ )</h1>
396396
<p>This function returns a new function which opaquely captures the current value of all AsyncContexts and restores the captured value when being invoked.</p>
397397

398398
<emu-alg>
399399
1. Let _snapshot_ be AsyncContextSnapshot().
400-
1. Return ? AsyncContextWrappedFunctionCreate(_func_, _snapshot_).
400+
1. If IsCallable(_target_) is false, throw a TypeError exception.
401+
1. Let _F_ be ? AsyncContextWrappedFunctionCreate(_target_, _snapshot_).
402+
1. Let _L_ be 0.
403+
1. Let _targetHasLength_ be ? HasOwnProperty(_target_, *"length"*).
404+
1. If _targetHasLength_ is *true*, then
405+
1. Let _targetLen_ be ? Get(_target_, *"length"*).
406+
1. If _targetLen_ is a Number, then
407+
1. If _targetLen_ is *+∞*<sub>𝔽</sub>, set _L_ to +∞.
408+
1. Else if _targetLen_ is *-∞*<sub>𝔽</sub>, set _L_ to 0.
409+
1. Else,
410+
1. Let _targetLenAsInt_ be ! ToIntegerOrInfinity(_targetLen_).
411+
1. Assert: _targetLenAsInt_ is finite.
412+
1. Set _L_ to _targetLenAsInt_.
413+
1. Perform SetFunctionLength(_F_, _L_).
414+
1. Let _targetName_ be ? Get(_target_, *"name"*).
415+
1. If _targetName_ is not a String, set _targetName_ to the empty String.
416+
1. Perform SetFunctionName(_F_, _targetName_, *"wrapped"*).
417+
1. Return _F_.
401418
</emu-alg>
402419
</emu-clause>
403420
</emu-clause>

0 commit comments

Comments
 (0)