tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

params-dflt-ref-arguments.js (2088B)


      1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 description: Referencing the arguments object from a default parameter (function expression)
      5 esid: sec-function-definitions-runtime-semantics-evaluation
      6 es6id: 14.1.20
      7 features: [default-parameters]
      8 info: |
      9    FunctionExpression : function ( FormalParameters ) { FunctionBody }
     10 
     11        [...]
     12        3. Let closure be FunctionCreate(Normal, FormalParameters, FunctionBody,
     13           scope, strict).
     14        [...]
     15 
     16    9.2.1 [[Call]] ( thisArgument, argumentsList)
     17 
     18    [...]
     19    7. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
     20    [...]
     21 
     22    9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList )
     23 
     24    1. Let status be FunctionDeclarationInstantiation(F, argumentsList).
     25    [...]
     26 
     27    9.2.12 FunctionDeclarationInstantiation(func, argumentsList)
     28 
     29    [...]
     30    23. Let iteratorRecord be Record {[[iterator]]:
     31        CreateListIterator(argumentsList), [[done]]: false}.
     32    24. If hasDuplicates is true, then
     33        [...]
     34    25. Else,
     35        b. Let formalStatus be IteratorBindingInitialization for formals with
     36           iteratorRecord and env as arguments.
     37    [...]
     38 
     39    14.1.19 Runtime Semantics: IteratorBindingInitialization
     40 
     41    FormalsList : FormalsList , FormalParameter
     42 
     43    1. Let status be the result of performing IteratorBindingInitialization for
     44       FormalsList using iteratorRecord and environment as the arguments.
     45    2. ReturnIfAbrupt(status).
     46    3. Return the result of performing IteratorBindingInitialization for
     47       FormalParameter using iteratorRecord and environment as the arguments.
     48 ---*/
     49 
     50 var callCount = 0;
     51 var f;
     52 f = function(x = arguments[2], y = arguments[3], z) {
     53  assert.sameValue(x, 'third', 'first parameter');
     54  assert.sameValue(y, 'fourth', 'second parameter');
     55  assert.sameValue(z, 'third', 'third parameter');
     56  callCount = callCount + 1;
     57 };
     58 
     59 f(undefined, undefined, 'third', 'fourth');
     60 
     61 assert.sameValue(callCount, 1, 'function invoked exactly once');
     62 
     63 reportCompare(0, 0);