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:
André Bargull 2018-03-22 17:20:29 -07:00 committed by Leo Balter
parent 500e48e6ce
commit ea6c18c5e2
13 changed files with 42 additions and 42 deletions

View File

@ -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"),
];

View File

@ -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`
);
}
}

View File

@ -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`
);
}
}

View File

@ -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;

View File

@ -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)`
);
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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();

View File

@ -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);

View File

@ -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)`
);
}
}

View File

@ -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)`
);
}
}

View File

@ -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);
});

View File

@ -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);
}