Last cases of convertToBigInt

This commit is contained in:
Leo Balter 2018-02-15 14:33:06 -05:00
parent 3325e2a516
commit c6cd535940
31 changed files with 54 additions and 88 deletions

View File

@ -18,10 +18,6 @@ var BigIntTypedArrayConstructors = [
*/
var TypedArray = Object.getPrototypeOf(Int8Array);
function convertToBigInt(x) {
return (Array.isArray(x)) ? x.map(convertToBigInt) : BigInt(x);
}
/**
* Callback for testing a typed array constructor.
*

View File

@ -12,10 +12,8 @@ includes: [testBigIntTypedArray.js, compareArray.js]
features: [BigInt, TypedArray]
---*/
var sample = [0, 42, 64];
testWithBigIntTypedArrayConstructors(function(TA) {
var typedArray = new TA(convertToBigInt(sample));
var typedArray = new TA([0n, 42n, 64n]);
var itor = typedArray.entries();
var next = itor.next();

View File

@ -27,12 +27,12 @@ features: [BigInt, Reflect.set, TypedArray]
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA([42n, 43n, 44n]);
var newVal = 0;
var newVal = 0n;
sample.every(function(val, i) {
if (i > 0) {
assert.sameValue(
sample[i - 1], convertToBigInt(newVal - 1),
sample[i - 1], newVal - 1n,
"get the changed value during the loop"
);
assert.sameValue(
@ -42,7 +42,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
);
}
assert.sameValue(
Reflect.set(sample, i, convertToBigInt(newVal)),
Reflect.set(sample, i, newVal),
true,
"set value during iteration"
);

View File

@ -17,10 +17,10 @@ features: [BigInt, TypedArray]
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(2);
var n = 1;
sample.fill({ valueOf() { return convertToBigInt(n++); } });
var n = 1n;
sample.fill({ valueOf() { return n++; } });
assert.sameValue(n, 2, "additional unexpected ToNumber() calls");
assert.sameValue(n, 2n, "additional unexpected ToNumber() calls");
assert.sameValue(sample[0], 1n, "incorrect ToNumber result in index 0");
assert.sameValue(sample[1], 1n, "incorrect ToNumber result in index 1");
});

View File

@ -18,12 +18,12 @@ features: [BigInt, Reflect.set, TypedArray]
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA([42n, 43n, 44n]);
var newVal = 0;
var newVal = 0n;
sample.filter(function(val, i) {
if (i > 0) {
assert.sameValue(
sample[i - 1], convertToBigInt(newVal - 1),
sample[i - 1], newVal - 1n,
"get the changed value during the loop"
);
assert.sameValue(
@ -33,7 +33,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
);
}
assert.sameValue(
Reflect.set(sample, i, convertToBigInt(newVal)),
Reflect.set(sample, i, newVal),
true,
"set value during interaction"
);

View File

@ -18,12 +18,12 @@ features: [BigInt, Reflect.set, TypedArray]
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA([42n, 43n, 44n]);
var newVal = 0;
var newVal = 0n;
sample.forEach(function(val, i) {
if (i > 0) {
assert.sameValue(
sample[i - 1], convertToBigInt(newVal - 1),
sample[i - 1], newVal - 1n,
"get the changed value during the loop"
);
assert.sameValue(
@ -33,7 +33,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
);
}
assert.sameValue(
Reflect.set(sample, i, convertToBigInt(newVal)),
Reflect.set(sample, i, newVal),
true,
"set value during iteration"
);

View File

@ -13,10 +13,10 @@ includes: [testBigIntTypedArray.js]
features: [BigInt, TypedArray]
---*/
var sample = [0, 42, 64];
var sample = [0n, 42n, 64n];
testWithBigIntTypedArrayConstructors(function(TA) {
var typedArray = new TA(convertToBigInt(sample));
var typedArray = new TA(sample);
var itor = typedArray.keys();
var next = itor.next();

View File

@ -13,12 +13,12 @@ features: [BigInt, Reflect.set, TypedArray]
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA([42n, 43n, 44n]);
var newVal = 0;
var newVal = 0n;
sample.map(function(val, i) {
if (i > 0) {
assert.sameValue(
sample[i - 1], convertToBigInt(newVal - 1),
sample[i - 1], newVal - 1n,
"get the changed value during the loop"
);
assert.sameValue(
@ -28,7 +28,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
);
}
assert.sameValue(
Reflect.set(sample, i, convertToBigInt(newVal)),
Reflect.set(sample, i, newVal),
true,
"set value during iteration"
);

View File

@ -20,12 +20,12 @@ features: [BigInt, Reflect.set, TypedArray]
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA([42n, 43n, 44n]);
var newVal = 0;
var newVal = 0n;
sample.reduce(function(acc, val, i) {
if (i > 0) {
assert.sameValue(
sample[i - 1], convertToBigInt(newVal - 1),
sample[i - 1], newVal - 1n,
"get the changed value during the loop"
);
assert.sameValue(
@ -35,7 +35,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
);
}
assert.sameValue(
Reflect.set(sample, i, convertToBigInt(newVal)),
Reflect.set(sample, i, newVal),
true,
"set value during iteration"
);

View File

@ -20,12 +20,12 @@ features: [BigInt, Reflect.set, TypedArray]
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA([42n, 43n, 44n]);
var newVal = 0;
var newVal = 0n;
sample.reduceRight(function(acc, val, i) {
if (i < sample.length - 1) {
assert.sameValue(
sample[i + 1], convertToBigInt(newVal - 1),
sample[i + 1], newVal - 1n,
"get the changed value during the loop"
);
assert.sameValue(
@ -35,7 +35,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
);
}
assert.sameValue(
Reflect.set(sample, i, convertToBigInt(newVal)),
Reflect.set(sample, i, newVal),
true,
"set value during iteration"
);

View File

@ -35,11 +35,10 @@ testWithBigIntTypedArrayConstructors(function(TA) {
}
};
// undefined and NaN covered on typedArrayConversions
var arr = ["1", "", false, true, nullish, obj1, obj2, [], [1]];
var arr = [false, true, obj1, [], [1]];
var sample = new TA(arr.length);
var expected = new TA(convertToBigInt([1, 0, 0, 1, 42, 42, 0, 1]));
var expected = new TA([0n, 1n, 42n, 0n, 1n]);
sample.set(arr);

View File

@ -30,10 +30,10 @@ includes: [testBigIntTypedArray.js, compareArray.js]
features: [BigInt, Symbol.species, TypedArray]
---*/
var arr = [42, 43, 44];
var arr = [42n 43n, 44n];
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(convertToBigInt(arr));
var sample = new TA(arr);
var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array;
sample.constructor = {};
@ -41,7 +41,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
var result = sample.slice();
assert(compareArray(result, convertToBigInt(arr)), "values are set");
assert(compareArray(result, arr), "values are set");
assert.notSameValue(result.buffer, sample.buffer, "creates a new buffer");
assert.sameValue(result.constructor, other, "used the custom ctor");
});

View File

@ -27,12 +27,12 @@ features: [BigInt, Reflect.set, TypedArray]
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA([42n, 43n, 44n]);
var newVal = 0;
var newVal = 0n;
sample.some(function(val, i) {
if (i > 0) {
assert.sameValue(
sample[i - 1], convertToBigInt(newVal - 1),
sample[i - 1], newVal - 1n,
"get the changed value during the loop"
);
assert.sameValue(
@ -42,7 +42,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
);
}
assert.sameValue(
Reflect.set(sample, i, convertToBigInt(newVal)),
Reflect.set(sample, i, newVal),
true,
"set value during iteration"
);

View File

@ -26,7 +26,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
sample = new TA([3n, 4n, 3n, 1n, 0n, 1n, 2n]).sort();
assert(compareArray(sample, [0n, 1n, 1n, 2n, 3n, 3n, 4n]), "repeating numbers");
sample = new TA(convertToBigInt([1, 0, -0, 2])).sort();
sample = new TA([1n, 0n, -0n, 2n]).sort();
assert(compareArray(sample, [0n, 0n, 1n, 2n]), "0s");
});

View File

@ -39,15 +39,14 @@ BigInt.prototype.toLocaleString = function() {
return "hacks" + calls.length;
};
var arr = [42, 0];
var expected = ["hacks1", "hacks2"].join(separator);
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(convertToBigInt(arr));
var sample = new TA([42n, 0n]);
calls = [];
assert.sameValue(sample.toLocaleString(), expected, "returns expected value");
assert(
compareArray(new TA(convertToBigInt(calls)), sample),
compareArray(new TA(calls), sample),
"toLocaleString called for each item"
);
});

View File

@ -47,11 +47,11 @@ BigInt.prototype.toLocaleString = function() {
};
};
var arr = [42, 0];
var arr = [42n, 0n];
var expected = ["hacks1", "hacks2"].join(separator);
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(convertToBigInt(arr));
var sample = new TA(arr);
calls = 0;
assert.sameValue(sample.toLocaleString(), expected, "returns expected value");
assert.sameValue(calls, 2, "toString called once for each item");

View File

@ -45,11 +45,10 @@ BigInt.prototype.toLocaleString = function() {
};
};
var arr = [42, 0];
var expected = ["hacks1", "hacks2"].join(separator);
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(convertToBigInt(arr));
var sample = new TA([42n, 0n]);
calls = 0;
assert.sameValue(sample.toLocaleString(), expected, "returns expected value");
assert.sameValue(calls, 2, "valueOf called once for each item");

View File

@ -31,11 +31,9 @@ BigInt.prototype.toLocaleString = function() {
throw new Test262Error();
};
var arr = [42, 0];
testWithBigIntTypedArrayConstructors(function(TA) {
calls = 0;
var sample = new TA(convertToBigInt(arr));
var sample = new TA([42n, 0n]);
assert.throws(Test262Error, function() {
sample.toLocaleString();
});

View File

@ -43,10 +43,8 @@ BigInt.prototype.toLocaleString = function() {
};
};
var arr = [42, 0];
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(convertToBigInt(arr));
var sample = new TA([42n, 0n]);
calls = 0;
assert.throws(Test262Error, function() {
sample.toLocaleString();

View File

@ -44,10 +44,8 @@ BigInt.prototype.toLocaleString = function() {
};
};
var arr = [42, 0];
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(convertToBigInt(arr));
var sample = new TA([42n, 0n]);
calls = 0;
assert.throws(Test262Error, function() {
sample.toLocaleString();

View File

@ -34,11 +34,9 @@ BigInt.prototype.toLocaleString = function() {
}
};
var arr = [42, 0];
testWithBigIntTypedArrayConstructors(function(TA) {
calls = 0;
var sample = new TA(convertToBigInt(arr));
var sample = new TA([42n, 0n]);
assert.throws(Test262Error, function() {
sample.toLocaleString();
});

View File

@ -45,10 +45,8 @@ BigInt.prototype.toLocaleString = function() {
};
};
var arr = [42, 0];
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(convertToBigInt(arr));
var sample = new TA([42n, 0n]);
calls = 0;
assert.throws(Test262Error, function() {
sample.toLocaleString();

View File

@ -46,10 +46,8 @@ BigInt.prototype.toLocaleString = function() {
};
};
var arr = [42, 0];
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(convertToBigInt(arr));
var sample = new TA([42n, 0n]);
calls = 0;
assert.throws(Test262Error, function() {
sample.toLocaleString();

View File

@ -33,10 +33,8 @@ features: [BigInt, TypedArray]
var separator = ["", ""].toLocaleString();
var arr = [42, 0, 43];
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(convertToBigInt(arr));
var sample = new TA([42n, 0n, 43n]);
var expected =
sample[0].toLocaleString().toString() +
separator +

View File

@ -13,10 +13,8 @@ includes: [testBigIntTypedArray.js]
features: [BigInt, TypedArray]
---*/
var sample = [0, 42, 64];
testWithBigIntTypedArrayConstructors(function(TA) {
var typedArray = new TA(convertToBigInt(sample));
var typedArray = new TA([0n, 42n, 64n]);
var itor = typedArray.values();
var next = itor.next();

View File

@ -16,10 +16,8 @@ includes: [testBigIntTypedArray.js]
features: [BigInt, TypedArray]
---*/
var obj = [7, 42];
testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA(convertToBigInt(obj));
var typedArray = new TA([7n, 42n]);
assert.sameValue(typedArray.length, 2);
assert.sameValue(typedArray[0], 7n);
assert.sameValue(typedArray[1], 42n);

View File

@ -20,17 +20,16 @@ flags: [noStrict]
features: [BigInt, TypedArray]
---*/
var source = [42, 43];
var global = this;
testWithBigIntTypedArrayConstructors(function(TA) {
var results = [];
var mapfn = function(x) {
results.push(this);
return convertToBigInt(x);
return x;
};
TA.from(convertToBigInt(source), mapfn);
TA.from([42n, 43n], mapfn);
assert.sameValue(results.length, 2);
assert.sameValue(results[0], global);

View File

@ -8,8 +8,6 @@ includes: [testBigIntTypedArray.js]
features: [BigInt, TypedArray]
---*/
var source = [42, 43, 42];
testWithBigIntTypedArrayConstructors(function(TA) {
var called = 0;
@ -19,7 +17,7 @@ testWithBigIntTypedArrayConstructors(function(TA) {
return new TA(len);
};
var result = TA.from.call(ctor, convertToBigInt(source));
var result = TA.from.call(ctor, [42n, 43n, 42n]);
assert.sameValue(result.length, 3);
assert.sameValue(result[0], 42n);
assert.sameValue(result[1], 43n);

View File

@ -8,14 +8,12 @@ includes: [testBigIntTypedArray.js]
features: [BigInt, TypedArray]
---*/
var source = [42, 43, 42];
testWithBigIntTypedArrayConstructors(function(TA) {
var mapfn = function(kValue) {
return convertToBigInt(kValue * 2);
return kValue * 2n;
};
var result = TA.from(source, mapfn);
var result = TA.from([42n, 43n, 42n], mapfn);
assert.sameValue(result.length, 3);
assert.sameValue(result[0], 84n);
assert.sameValue(result[1], 86n);

View File

@ -8,10 +8,8 @@ includes: [testBigIntTypedArray.js]
features: [BigInt, TypedArray]
---*/
var source = [42, 43, 42];
testWithBigIntTypedArrayConstructors(function(TA) {
var result = TA.from(convertToBigInt(source));
var result = TA.from([42n, 43n, 42n]);
assert.sameValue(result.length, 3);
assert.sameValue(result[0], 42n);
assert.sameValue(result[1], 43n);

View File

@ -24,7 +24,7 @@ features: [BigInt, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
var result = TA.of(42n, 43n, convertToBigInt(false));
var result = TA.of(42n, 43n, 0n);
assert.sameValue(result.length, 3);
assert.sameValue(result[0], 42n);
assert.sameValue(result[1], 43n);