| 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 |
description: > |
| 6 |
Replaces value field even if they pass in the SameValue algorithm, including |
| 7 |
distinct NaN values |
| 8 |
info: | |
| 9 |
This test does not compare the actual byte values, instead it simply checks that |
| 10 |
the value is some valid NaN encoding. |
| 11 |
|
| 12 |
--- |
| 13 |
|
| 14 |
Previously, this method compared the "value" field using the SameValue |
| 15 |
algorithm (thereby ignoring distinct NaN values) |
| 16 |
|
| 17 |
--- |
| 18 |
|
| 19 |
[[DefineOwnProperty]] (P, Desc) |
| 20 |
|
| 21 |
Return ? OrdinaryDefineOwnProperty(O, P, Desc). |
| 22 |
|
| 23 |
#sec-ordinarydefineownproperty |
| 24 |
OrdinaryDefineOwnProperty ( O, P, Desc ) |
| 25 |
|
| 26 |
1. Let current be ? O.[[GetOwnProperty]](P). |
| 27 |
2. Let extensible be O.[[Extensible]]. |
| 28 |
3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, |
| 29 |
current). |
| 30 |
|
| 31 |
#sec-validateandapplypropertydescriptor |
| 32 |
ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) |
| 33 |
|
| 34 |
... |
| 35 |
7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, |
| 36 |
then |
| 37 |
a. If current.[[Configurable]] is false and current.[[Writable]] is false, |
| 38 |
then |
| 39 |
... |
| 40 |
... |
| 41 |
9. If O is not undefined, then |
| 42 |
a. For each field of Desc that is present, set the corresponding attribute |
| 43 |
of the property named P of object O to the value of the field. |
| 44 |
10. Return true. |
| 45 |
|
| 46 |
#sec-isnan-number |
| 47 |
|
| 48 |
NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is |
| 49 |
an expression of the form X !== X. The result will be true if and only |
| 50 |
if X is a NaN. |
| 51 |
includes: [nans.js] |
| 52 |
---*/ |
| 53 |
|
| 54 |
var len = NaNs.length; |
| 55 |
|
| 56 |
for (var idx = 0; idx < len; ++idx) { |
| 57 |
for (var jdx = 0; jdx < len; ++jdx) { |
| 58 |
var a = {}; |
| 59 |
var b = {}; |
| 60 |
|
| 61 |
Object.defineProperty(a, "prop", { |
| 62 |
value: NaNs[idx], |
| 63 |
configurable: true, |
| 64 |
}); |
| 65 |
|
| 66 |
Object.defineProperty(a, "prop", { |
| 67 |
value: NaNs[jdx], |
| 68 |
}); |
| 69 |
|
| 70 |
assert( |
| 71 |
a.prop !== a.prop, |
| 72 |
`Object property value reconfigured to NaN produced by (index=${idx}) results in a valid NaN` |
| 73 |
); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
reportCompare(0, 0); |