Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Object/defineProperty/15.2.3.6-4-8.js

raw
1 // Copyright (c) 2012 Ecma International. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 info: |
6 Step 4 of defineProperty calls the [[DefineOwnProperty]] internal method
7 of O to define the property. Step 7b of [[DefineOwnProperty]] rejects if
8 current.[[Enumerable]] and desc.[[Enumerable]] are the boolean negations
9 of each other.
10 es5id: 15.2.3.6-4-8
11 description: >
12 Object.defineProperty throws TypeError when changing
13 [[Enumerable]] from false to true on non-configurable data
14 properties
15 ---*/
16
17 var o = {};
18
19 // create a data valued property; all other attributes default to false.
20 var d1 = {
21 value: 101,
22 enumerable: false,
23 configurable: false
24 };
25 Object.defineProperty(o, "foo", d1);
26
27 // now, setting enumerable to true should fail, since [[Configurable]]
28 // on the original property will be false.
29 var desc = {
30 value: 101,
31 enumerable: true
32 };
33 assert.throws(TypeError, function() {
34 Object.defineProperty(o, "foo", desc);
35 });
36 // the property should remain unchanged.
37 var d2 = Object.getOwnPropertyDescriptor(o, "foo");
38 assert.sameValue(d2.value, 101, 'd2.value');
39 assert.sameValue(d2.enumerable, false, 'd2.enumerable');
40 assert.sameValue(d2.configurable, false, 'd2.configurable');