mirror of
https://github.com/tc39/test262.git
synced 2025-07-28 08:24:23 +02:00
Don't compute NaN values in functions (#1503)
`function nan() { return /* expression to compute NaN */ }` may not return the same implementation-distinguishable NaN value before and after JIT compilation.
This commit is contained in:
parent
500e48e6ce
commit
ea6c18c5e2
@ -9,13 +9,13 @@ description: |
|
||||
---*/
|
||||
|
||||
var NaNs = [
|
||||
() => NaN,
|
||||
() => Number.NaN,
|
||||
() => NaN * 0,
|
||||
() => 0/0,
|
||||
() => Infinity/Infinity,
|
||||
() => -(0/0),
|
||||
() => Math.pow(-1, 0.5),
|
||||
() => -Math.pow(-1, 0.5),
|
||||
() => Number("Not-a-Number"),
|
||||
NaN,
|
||||
Number.NaN,
|
||||
NaN * 0,
|
||||
0/0,
|
||||
Infinity/Infinity,
|
||||
-(0/0),
|
||||
Math.pow(-1, 0.5),
|
||||
-Math.pow(-1, 0.5),
|
||||
Number("Not-a-Number"),
|
||||
];
|
||||
|
@ -57,12 +57,12 @@ for (var idx = 0; idx < len; ++idx) {
|
||||
for (var jdx = 0; jdx < len; ++jdx) {
|
||||
var a = {};
|
||||
|
||||
a.prop = NaNs[idx]();
|
||||
a.prop = NaNs[jdx]();
|
||||
a.prop = NaNs[idx];
|
||||
a.prop = NaNs[jdx];
|
||||
|
||||
assert(
|
||||
a.prop !== a.prop,
|
||||
`Object property value reassigned to NaN produced by (${NaNs[idx].toString()}) results in a valid NaN`
|
||||
`Object property value reassigned to NaN produced by (index=${idx}) results in a valid NaN`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -59,17 +59,17 @@ for (var idx = 0; idx < len; ++idx) {
|
||||
var b = {};
|
||||
|
||||
Object.defineProperty(a, "prop", {
|
||||
value: NaNs[idx](),
|
||||
value: NaNs[idx],
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
Object.defineProperty(a, "prop", {
|
||||
value: NaNs[jdx](),
|
||||
value: NaNs[jdx],
|
||||
});
|
||||
|
||||
assert(
|
||||
a.prop !== a.prop,
|
||||
`Object property value reconfigured to NaN produced by (${NaNs[idx].toString()}) results in a valid NaN`
|
||||
`Object property value reconfigured to NaN produced by (index=${idx}) results in a valid NaN`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ function body(FloatArray) {
|
||||
var subject = new FloatArray(NaNs.length * 2);
|
||||
|
||||
NaNs.forEach(function(v, i) {
|
||||
subject[i] = v();
|
||||
subject[i] = v;
|
||||
});
|
||||
|
||||
var originalBytes, copiedBytes;
|
||||
|
@ -78,7 +78,7 @@ testWithTypedArrayConstructors(function(FA) {
|
||||
var controls, idx, aNaN;
|
||||
|
||||
for (idx = 0; idx < NaNs.length; ++idx) {
|
||||
aNaN = NaNs[idx]();
|
||||
aNaN = NaNs[idx];
|
||||
controls = new Float32Array([aNaN, aNaN, aNaN]);
|
||||
|
||||
samples.fill(aNaN);
|
||||
@ -89,12 +89,12 @@ testWithTypedArrayConstructors(function(FA) {
|
||||
|
||||
assert(
|
||||
samples[i] !== samples[i],
|
||||
`samples (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)`
|
||||
`samples (index=${idx}) produces a valid NaN (${precision} precision)`
|
||||
);
|
||||
|
||||
assert(
|
||||
controls[i] !== controls[i],
|
||||
`controls (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)`
|
||||
`controls (index=${idx}) produces a valid NaN (${precision} precision)`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -45,12 +45,12 @@ features: [TypedArray]
|
||||
---*/
|
||||
|
||||
function body(FloatArray) {
|
||||
var sample = new FloatArray(NaNs.map(n => n()));
|
||||
var sample = new FloatArray(NaNs);
|
||||
var sampleBytes, resultBytes;
|
||||
var i = 0;
|
||||
|
||||
var result = sample.map(function() {
|
||||
return NaNs[i++]();
|
||||
return NaNs[i++];
|
||||
});
|
||||
|
||||
sampleBytes = new Uint8Array(sample.buffer);
|
||||
|
@ -20,7 +20,7 @@ features: [TypedArray]
|
||||
---*/
|
||||
|
||||
function body(FA) {
|
||||
var source = new FA(NaNs.map(n => n()));
|
||||
var source = new FA(NaNs);
|
||||
var target = new FA(NaNs.length);
|
||||
var sourceBytes, targetBytes;
|
||||
|
||||
|
@ -25,7 +25,7 @@ features: [TypedArray]
|
||||
---*/
|
||||
|
||||
function body(FloatArray) {
|
||||
var subject = new FloatArray(NaNs.map(n => n()));
|
||||
var subject = new FloatArray(NaNs);
|
||||
var sliced, subjectBytes, slicedBytes;
|
||||
|
||||
sliced = subject.slice();
|
||||
|
@ -50,8 +50,8 @@ features: [TypedArray]
|
||||
---*/
|
||||
|
||||
function body(FloatArray) {
|
||||
var first = new FloatArray(NaNs.map(n => n()));
|
||||
var second = new FloatArray(NaNs.map(n => n()));
|
||||
var first = new FloatArray(NaNs);
|
||||
var second = new FloatArray(NaNs);
|
||||
var firstBytes = new Uint8Array(first.buffer);
|
||||
var secondBytes = new Uint8Array(second.buffer);
|
||||
|
||||
|
@ -74,7 +74,7 @@ testWithTypedArrayConstructors(function(FA) {
|
||||
var controls, idx, aNaN;
|
||||
|
||||
for (idx = 0; idx < NaNs.length; ++idx) {
|
||||
aNaN = NaNs[idx]();
|
||||
aNaN = NaNs[idx];
|
||||
controls = new FA([aNaN, aNaN, aNaN]);
|
||||
|
||||
Object.defineProperty(samples, "0", { value: aNaN });
|
||||
@ -85,12 +85,12 @@ testWithTypedArrayConstructors(function(FA) {
|
||||
|
||||
assert(
|
||||
samples[i] !== samples[i],
|
||||
`samples (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)`
|
||||
`samples (index=${idx}) produces a valid NaN (${precision} precision)`
|
||||
);
|
||||
|
||||
assert(
|
||||
controls[i] !== controls[i],
|
||||
`controls (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)`
|
||||
`controls (index=${idx}) produces a valid NaN (${precision} precision)`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ testWithTypedArrayConstructors(function(FA) {
|
||||
var controls, idx, aNaN;
|
||||
|
||||
for (idx = 0; idx < NaNs.length; ++idx) {
|
||||
aNaN = NaNs[idx]();
|
||||
aNaN = NaNs[idx];
|
||||
controls = new FA([aNaN, aNaN, aNaN]);
|
||||
|
||||
samples[0] = aNaN;
|
||||
@ -83,12 +83,12 @@ testWithTypedArrayConstructors(function(FA) {
|
||||
|
||||
assert(
|
||||
samples[i] !== samples[i],
|
||||
`samples (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)`
|
||||
`samples (index=${idx}) produces a valid NaN (${precision} precision)`
|
||||
);
|
||||
|
||||
assert(
|
||||
controls[i] !== controls[i],
|
||||
`controls (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)`
|
||||
`controls (index=${idx}) produces a valid NaN (${precision} precision)`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -15,5 +15,5 @@ includes: [nans.js]
|
||||
---*/
|
||||
|
||||
NaNs.forEach(function(v, i) {
|
||||
assert.sameValue(isNaN(v()), true, "value on position: " + i);
|
||||
assert.sameValue(isNaN(v), true, "value on position: " + i);
|
||||
});
|
||||
|
@ -5,20 +5,20 @@ description: >
|
||||
Including nans.js will expose:
|
||||
|
||||
var NaNs = [
|
||||
() => NaN,
|
||||
() => Number.NaN,
|
||||
() => NaN * 0,
|
||||
() => 0/0,
|
||||
() => Infinity/Infinity,
|
||||
() => -(0/0),
|
||||
() => Math.pow(-1, 0.5),
|
||||
() => -Math.pow(-1, 0.5),
|
||||
() => Number("Not-a-Number"),
|
||||
NaN,
|
||||
Number.NaN,
|
||||
NaN * 0,
|
||||
0/0,
|
||||
Infinity/Infinity,
|
||||
-(0/0),
|
||||
Math.pow(-1, 0.5),
|
||||
-Math.pow(-1, 0.5),
|
||||
Number("Not-a-Number"),
|
||||
];
|
||||
|
||||
includes: [nans.js]
|
||||
---*/
|
||||
|
||||
for (var i = 0; i < NaNs.length; i++) {
|
||||
assert.sameValue(Number.isNaN(NaNs[i]()), true, NaNs[i].toString());
|
||||
assert.sameValue(Number.isNaN(NaNs[i]), true, "index: " + i);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user