tor-browser

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

non-definable-function-with-function.js (1917B)


      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 esid: sec-evaldeclarationinstantiation
      5 es6id: 18.2.1.2
      6 description: >
      7    Global functions are not created if conflicting function declarations were
      8    detected.
      9 info: |
     10  Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
     11 
     12  ...
     13  8. For each d in varDeclarations, in reverse list order do
     14    a. If d is neither a VariableDeclaration or a ForBinding, then
     15      i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration.
     16      ii. NOTE If there are multiple FunctionDeclarations for the same name,
     17          the last declaration is used.
     18      iii. Let fn be the sole element of the BoundNames of d.
     19      iv. If fn is not an element of declaredFunctionNames, then
     20        1. If varEnvRec is a global Environment Record, then
     21          a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn).
     22          b. ReturnIfAbrupt(fnDefinable).
     23          c. If fnDefinable is false, throw TypeError exception.
     24  ...
     25  14. For each production f in functionsToInitialize, do
     26    a. Let fn be the sole element of the BoundNames of f.
     27    b. Let fo be the result of performing InstantiateFunctionObject for f with argument lexEnv.
     28    c. If varEnvRec is a global Environment Record, then
     29      i. Let status be varEnvRec.CreateGlobalFunctionBinding(fn, fo, true).
     30      ii. ReturnIfAbrupt(status).
     31  ...
     32 ---*/
     33 
     34 try {
     35  (0,eval)("function shouldNotBeDefined1() {} function NaN() {} function shouldNotBeDefined2() {}");
     36 } catch (e) {
     37  // Ignore TypeError exception.
     38 }
     39 
     40 assert.sameValue(
     41  Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined1"),
     42  undefined,
     43  "declaration preceding"
     44 );
     45 assert.sameValue(
     46  Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined2"),
     47  undefined,
     48  "declaration following"
     49 );
     50 
     51 reportCompare(0, 0);