Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc
5 es6id: 9.1.6
6 description: >
7 Replaces value field even if they pass in the SameValue algorithm, including
8 distinct NaN values
9 info: |
10 Previously, this method compared the "value" field using the SameValue
11 algorithm (thereby ignoring distinct NaN values)
12
13 ---
14
15 [[DefineOwnProperty]] (P, Desc)
16
17 1. Return ? OrdinaryDefineOwnProperty(O, P, Desc).
18
19 9.1.6.1 OrdinaryDefineOwnProperty
20
21 1. Let current be ? O.[[GetOwnProperty]](P).
22 2. Let extensible be O.[[Extensible]].
23 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc,
24 current).
25
26 9.1.6.3 ValidateAndApplyPropertyDescriptor
27
28 [...]
29 7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true,
30 then
31 a. If current.[[Configurable]] is false and current.[[Writable]] is false,
32 then
33 [...]
34 [...]
35 9. If O is not undefined, then
36 a. For each field of Desc that is present, set the corresponding attribute
37 of the property named P of object O to the value of the field.
38 10. Return true.
39 features: [Float64Array, Uint8Array, Uint16Array]
40 includes: [nans.js]
41 ---*/
42
43 var isLittleEndian = new Uint8Array(new Uint16Array([1]).buffer)[0] !== 0;
44
45 var float = new Float64Array(1);
46 var ints = new Uint8Array(float.buffer);
47 var len = distinctNaNs.length;
48
49 function byteValue(value) {
50 float[0] = value;
51
52 var hex = "0123456789ABCDEF";
53 var s = "";
54 for (var i = 0; i < 8; ++i) {
55 var v = ints[isLittleEndian ? 7 - i : i];
56 s += hex[(v >> 4) & 0xf] + hex[v & 0xf];
57 }
58 return s;
59 }
60
61 /**
62 * Iterate over each pair of distinct NaN values (with replacement). If two or
63 * more suitable NaN values cannot be identified, the semantics under test
64 * cannot be verified and this test is expected to pass without evaluating any
65 * assertions.
66 */
67 for (var idx = 0; idx < len; ++idx) {
68 for (var jdx = 0; jdx < len; ++jdx) {
69 // NB: Don't store the distinct NaN values as global variables, because
70 // global variables are properties of the global object. And in this test
71 // we want to ensure NaN-valued properties in objects are properly handled,
72 // so storing NaN values in the (global) object defeats the purpose.
73 if (byteValue(distinctNaNs[idx]) === byteValue(distinctNaNs[jdx])) {
74 continue;
75 }
76
77 var subject = {};
78 subject.prop = distinctNaNs[idx];
79 subject.prop = distinctNaNs[jdx];
80
81 assert.sameValue(
82 byteValue(subject.prop),
83 byteValue(distinctNaNs[jdx]),
84 'Property value was re-set'
85 );
86 }
87 }