summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/global-code/script-decl-func-err-non-configurable.js
blob: 449c596e7a3b37575c4be8e6d88f2baa52c73220 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// 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 function when there is a corresponding global property that is
  non-configurable but *not* a writable and configurable data property.
info: |
  [...]
  9. Let declaredFunctionNames be a new empty List.
  10. For each d in varDeclarations, in reverse list order do
      a. If d is neither a VariableDeclaration or a ForBinding, then
         i. Assert: d is either a FunctionDeclaration or a
            GeneratorDeclaration.
         ii. NOTE If there are multiple FunctionDeclarations for the same name,
             the last declaration is used.
         iii. Let fn be the sole element of the BoundNames of d.
         iv. If fn is not an element of declaredFunctionNames, then
             1. Let fnDefinable be ? envRec.CanDeclareGlobalFunction(fn).
             2. If fnDefinable is false, throw a TypeError exception.

  8.1.1.4.16 CanDeclareGlobalFunction

  [...]
  6. If existingProp.[[Configurable]] is true, return true.
  7. If IsDataDescriptor(existingProp) is true and existingProp has attribute
     values {[[Writable]]: true, [[Enumerable]]: true}, return true.
  8. Return false. 
---*/

Object.defineProperty(
  this,
  'data1',
  { configurable: false, value: 0, writable: true, enumerable: false }
);

Object.defineProperty(
  this,
  'data2',
  { configurable: false, value: 0, writable: false, enumerable: true }
);

Object.defineProperty(
  this,
  'data3',
  { configurable: false, value: 0, writable: false, enumerable: false }
);

Object.defineProperty(
  this,
  'accessor1',
  { 
    configurable: false,
    get: function() {},
    set: function() {},
    enumerable: true
  }
);

Object.defineProperty(
  this,
  'accessor2',
  { 
    configurable: false,
    get: function() {},
    set: function() {},
    enumerable: true
  }
);

assert.throws(TypeError, function() {
  $262.evalScript('var x; function data1() {}');
}, 'writable, non-enumerable data property');
assert.throws(ReferenceError, function() {
  x;
}, 'bindings not created for writable, non-enumerable data property');

assert.throws(TypeError, function() {
  $262.evalScript('var x; function data2() {}');
}, 'non-writable, enumerable data property');
assert.throws(ReferenceError, function() {
  x;
}, 'bindings not created for non-writable, enumerable data property');

assert.throws(TypeError, function() {
  $262.evalScript('var x; function data3() {}');
}, 'non-writable, non-enumerable data property');
assert.throws(ReferenceError, function() {
  x;
}, 'bindings not created for non-writable, non-enumerable data property');

assert.throws(TypeError, function() {
  $262.evalScript('var x; function accessor1() {}');
}, 'enumerable accessor property');
assert.throws(ReferenceError, function() {
  x;
}, 'bindings not created for enumerableaccessor property');

assert.throws(TypeError, function() {
  $262.evalScript('var x; function accessor2() {}');
}, 'non-enumerable accessor property');
assert.throws(ReferenceError, function() {
  x;
}, 'bindings not created for non-enumerableaccessor property');

reportCompare(0, 0);