tor-browser

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

script-decl-lex.js (1658B)


      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-globaldeclarationinstantiation
      5 es6id: 15.1.8
      6 description: Declaration of lexical bindings
      7 info: |
      8  [...]
      9  16. For each element d in lexDeclarations do
     10      a. NOTE Lexically declared names are only instantiated here but not
     11         initialized.
     12      b. For each element dn of the BoundNames of d do
     13         i. If IsConstantDeclaration of d is true, then
     14            1. Perform ? envRec.CreateImmutableBinding(dn, true).
     15         ii. Else,
     16             1. Perform ? envRec.CreateMutableBinding(dn, false).
     17  [...]
     18 ---*/
     19 
     20 // Extensibility of the global object should have no bearing on lexical
     21 // declarations.
     22 Object.preventExtensions(this);
     23 
     24 $262.evalScript('let test262let = 1;');
     25 
     26 test262let = 2;
     27 
     28 assert.sameValue(test262let, 2, '`let` binding is mutable');
     29 assert.sameValue(
     30  this.hasOwnProperty('test262let'),
     31  false,
     32  'property not created on the global object (let)'
     33 );
     34 
     35 $262.evalScript('const test262const = 3;');
     36 
     37 assert.throws(TypeError, function() {
     38  test262const = 4;
     39 }, '`const` binding is strictly immutable');
     40 assert.sameValue(test262const, 3, '`const` binding cannot be modified');
     41 assert.sameValue(
     42  this.hasOwnProperty('test262const'),
     43  false,
     44  'property not created on the global object (const)'
     45 );
     46 
     47 $262.evalScript('class test262class {}');
     48 
     49 test262class = 5;
     50 
     51 assert.sameValue(test262class, 5, '`class` binding is mutable');
     52 assert.sameValue(
     53  this.hasOwnProperty('test262class'),
     54  false,
     55  'property not created on the global object (class)'
     56 );
     57 
     58 reportCompare(0, 0);