Debian Codegraph @

js/src/tests/test262/annexB/language/statements/function/default-parameters-emulates-undefined.js

raw
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject
5 description: >
6 Initializer is not evaluated when argument is an object with
7 [[IsHTMLDDA]] internal slot.
8 info: |
9 FunctionDeclaration :
10 function BindingIdentifier ( FormalParameters ) { FunctionBody }
11
12 [...]
13 3. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody,
14 scope, strict).
15 [...]
16
17 [[Call]] ( thisArgument, argumentsList)
18
19 [...]
20 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
21 [...]
22
23 OrdinaryCallEvaluateBody ( F, argumentsList )
24
25 1. Let status be FunctionDeclarationInstantiation(F, argumentsList).
26 [...]
27
28 FunctionDeclarationInstantiation(func, argumentsList)
29
30 [...]
31 23. Let iteratorRecord be Record {[[iterator]]:
32 CreateListIterator(argumentsList), [[done]]: false}.
33 24. If hasDuplicates is true, then
34 [...]
35 25. Else,
36 b. Let formalStatus be IteratorBindingInitialization for formals with
37 iteratorRecord and env as arguments.
38 [...]
39
40 Runtime Semantics: IteratorBindingInitialization
41
42 FormalsList : FormalsList , FormalParameter
43
44 [...]
45 23. Let iteratorRecord be Record {[[Iterator]]:
46 CreateListIterator(argumentsList), [[Done]]: false}.
47 24. If hasDuplicates is true, then
48 [...]
49 25. Else,
50 a. Perform ? IteratorBindingInitialization for formals with
51 iteratorRecord and env as arguments.
52 [...]
53 features: [default-parameters, IsHTMLDDA]
54 ---*/
55
56 let initCount = 0;
57 const counter = function() {
58 initCount += 1;
59 };
60
61 const arrow = (x = counter()) => x;
62 const IsHTMLDDA = $262.IsHTMLDDA;
63
64 assert.sameValue(arrow(IsHTMLDDA), IsHTMLDDA);
65 assert.sameValue(initCount, 0);
66
67 function fn(x, y = counter()) {
68 return y;
69 }
70
71 assert.sameValue(fn(1, IsHTMLDDA), IsHTMLDDA);
72 assert.sameValue(initCount, 0);
73
74 reportCompare(0, 0);