From 5628e995667922d58d2d7966249c1c815e0ce338 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Wed, 15 Apr 2020 04:10:43 +0300 Subject: [PATCH] Add default parameters test --- .../default-parameters-emulates-undefined.js | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 test/annexB/language/statements/function/default-parameters-emulates-undefined.js diff --git a/test/annexB/language/statements/function/default-parameters-emulates-undefined.js b/test/annexB/language/statements/function/default-parameters-emulates-undefined.js new file mode 100644 index 0000000000..2b40b8d99e --- /dev/null +++ b/test/annexB/language/statements/function/default-parameters-emulates-undefined.js @@ -0,0 +1,72 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject +description: > + Initializer is not evaluated when argument is an object with + [[IsHTMLDDA]] internal slot. +info: | + FunctionDeclaration : + function BindingIdentifier ( FormalParameters ) { FunctionBody } + + [...] + 3. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody, + scope, strict). + [...] + + [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + [...] + 23. Let iteratorRecord be Record {[[Iterator]]: + CreateListIterator(argumentsList), [[Done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + a. Perform ? IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +features: [default-parameters, IsHTMLDDA] +---*/ + +let initCount = 0; +const counter = function() { + initCount += 1; +}; + +const arrow = (x = counter()) => x; +const IsHTMLDDA = $262.IsHTMLDDA; + +assert.sameValue(arrow(IsHTMLDDA), IsHTMLDDA); +assert.sameValue(initCount, 0); + +function fn(x, y = counter()) { + return y; +} + +assert.sameValue(fn(1, IsHTMLDDA), IsHTMLDDA); +assert.sameValue(initCount, 0);