Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Object/defineProperty/15.2.3.6-4-9.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-9
11 description: >
12 Object.defineProperty throws TypeError when changing
13 [[Enumerable]] from true to false on non-configurable data
14 properties
15 ---*/
16
17 var o = {};
18
19 // create a data valued property with [[Enumerable]] explicitly set to true;
20 // all other attributes default to false.
21 var d1 = {
22 value: 101,
23 enumerable: true,
24 configurable: false
25 };
26 Object.defineProperty(o, "foo", d1);
27
28 // now, setting enumerable to false should fail, since [[Configurable]]
29 // on the original property will be false.
30 var desc = {
31 value: 101,
32 enumerable: false
33 };
34 assert.throws(TypeError, function() {
35 Object.defineProperty(o, "foo", desc);
36 });
37 // the property should remain unchanged.
38 var d2 = Object.getOwnPropertyDescriptor(o, "foo");
39 assert.sameValue(d2.value, 101, 'd2.value');
40 assert.sameValue(d2.enumerable, true, 'd2.enumerable');
41 assert.sameValue(d2.configurable, false, 'd2.configurable');