summaryrefslogtreecommitdiff
path: root/test/language/global-code/script-decl-lex.js
blob: e10e7b039428d4a9d841927adc0ee7f95d826127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-globaldeclarationinstantiation
es6id: 15.1.8
description: Declaration of lexical bindings
info: |
  [...]
  16. For each element d in lexDeclarations do
      a. NOTE Lexically declared names are only instantiated here but not
         initialized.
      b. For each element dn of the BoundNames of d do
         i. If IsConstantDeclaration of d is true, then
            1. Perform ? envRec.CreateImmutableBinding(dn, true).
         ii. Else,
             1. Perform ? envRec.CreateMutableBinding(dn, false).
  [...]
---*/

// Extensibility of the global object should have no bearing on lexical
// declarations.
Object.preventExtensions(this);

$.evalScript('let test262let = 1;');

test262let = 2;

assert.sameValue(test262let, 2, '`let` binding is mutable');
assert.sameValue(
  this.hasOwnProperty('test262let'),
  false,
  'property not created on the global object (let)'
);

$.evalScript('const test262const = 3;');

assert.throws(TypeError, function() {
  test262const = 4;
}, '`const` binding is strictly immutable');
assert.sameValue(test262const, 3, '`const` binding cannot be modified');
assert.sameValue(
  this.hasOwnProperty('test262const'),
  false,
  'property not created on the global object (const)'
);

$.evalScript('class test262class {}');

test262class = 5;

assert.sameValue(test262class, 5, '`class` binding is mutable');
assert.sameValue(
  this.hasOwnProperty('test262class'),
  false,
  'property not created on the global object (class)'
);