Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Object/defineProperty/15.2.3.6-4-6.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 6 of [[DefineOwnProperty]] returns if
8 every field of desc also occurs in current and every field in desc has
9 the same value as current.
10 es5id: 15.2.3.6-4-6
11 description: >
12 Object.defineProperty is no-op if current and desc are the same
13 accessor desc
14 ---*/
15
16 function sameAccessorDescriptorValues(d1, d2) {
17 return (d1.get == d2.get &&
18 d1.enumerable == d2.enumerable &&
19 d1.configurable == d2.configurable);
20 }
21
22 var o = {};
23
24 // create an accessor property with the following attributes:
25 // enumerable: true, configurable: true
26 var desc = {
27 get: function() {},
28 enumerable: true,
29 configurable: true
30 };
31
32 Object.defineProperty(o, "foo", desc);
33
34 // query for, and save, the desc. A subsequent call to defineProperty
35 // with the same desc should not disturb the property definition.
36 var d1 = Object.getOwnPropertyDescriptor(o, "foo");
37
38 // now, redefine the property with the same descriptor
39 // the property defintion should not get disturbed.
40 Object.defineProperty(o, "foo", desc);
41
42 var d2 = Object.getOwnPropertyDescriptor(o, "foo");
43
44 assert.sameValue(sameAccessorDescriptorValues(d1, d2), true, 'sameAccessorDescriptorValues(d1, d2)');