Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Object/defineProperty/15.2.3.6-4-20.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. For non-configurable properties, step 11.a.ii
8 of [[DefineOwnProperty]] rejects changing the getter if present.
9 es5id: 15.2.3.6-4-20
10 description: >
11 Object.defineProperty throws TypeError when changing getter (if
12 present) of non-configurable accessor properties(8.12.9 step
13 11.a.ii)
14 ---*/
15
16 var o = {};
17
18 // create an accessor property; all other attributes default to false.
19 // dummy getter/setter
20 var getter = function() {
21 return 1;
22 }
23 var d1 = {
24 get: getter,
25 configurable: false
26 };
27 Object.defineProperty(o, "foo", d1);
28
29 // now, trying to change the setter should fail, since [[Configurable]]
30 // on the original property will be false.
31 var desc = {
32 get: undefined
33 };
34 assert.throws(TypeError, function() {
35 Object.defineProperty(o, "foo", desc);
36 });
37 var d2 = Object.getOwnPropertyDescriptor(o, "foo");
38
39 assert.sameValue(d2.get, getter, 'd2.get');
40 assert.sameValue(d2.configurable, false, 'd2.configurable');
41 assert.sameValue(d2.enumerable, false, 'd2.enumerable');