tor-browser

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

params-dflt-args-unmapped.js (2512B)


      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 declaration)
      5 esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject
      6 es6id: 14.1.19
      7 features: [default-parameters]
      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    9.2.1 [[Call]] ( thisArgument, argumentsList)
     18 
     19    [...]
     20    7. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
     21    [...]
     22 
     23    9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList )
     24 
     25    1. Let status be FunctionDeclarationInstantiation(F, argumentsList).
     26    [...]
     27 
     28    9.2.12 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    14.1.19 Runtime Semantics: IteratorBindingInitialization
     41 
     42    FormalsList : FormalsList , FormalParameter
     43 
     44    1. Let status be the result of performing IteratorBindingInitialization for
     45       FormalsList using iteratorRecord and environment as the arguments.
     46    2. ReturnIfAbrupt(status).
     47    3. Return the result of performing IteratorBindingInitialization for
     48       FormalParameter using iteratorRecord and environment as the arguments. 
     49 ---*/
     50 
     51 var callCount = 0;
     52 function f(x, _ = 0) {
     53  assert.sameValue(x, undefined, 'parameter binding value (initial)');
     54  assert.sameValue(
     55    arguments[0], undefined, 'arguments property value (initial)'
     56  );
     57 
     58  arguments[0] = 1;
     59 
     60  assert.sameValue(
     61    x, undefined, 'parameter binding value (after arguments modification)'
     62  );
     63  assert.sameValue(
     64    arguments[0], 1, 'arguments property value (after arguments modification)'
     65  );
     66 
     67  x = 2;
     68 
     69  assert.sameValue(
     70    x, 2, 'parameter binding value (after parameter binding modification)'
     71  );
     72  assert.sameValue(
     73    arguments[0],
     74    1,
     75    'arguments property value (after parameter binding modification)'
     76  );
     77  callCount = callCount + 1;
     78 }
     79 
     80 f();
     81 
     82 assert.sameValue(callCount, 1, 'function invoked exactly once');
     83 
     84 reportCompare(0, 0);