summaryrefslogtreecommitdiff
path: root/harness
diff options
context:
space:
mode:
authorJosh Wolfe <jwolfe@igalia.com>2017-09-12 18:38:29 -0700
committerJosh Wolfe <jwolfe@igalia.com>2017-09-12 18:38:29 -0700
commitdafde72971845dc6f2da7549f0688ff2d2fe3d01 (patch)
treed19955bce78a5960768070fc3d1a109fd824c371 /harness
parent765f273ac41ea2927cf00ae1812795683015117a (diff)
downloadqtdeclarative-testsuites-dafde72971845dc6f2da7549f0688ff2d2fe3d01.tar.gz
BigInt.asUintN tests
* typeCoercion.js supports ToIndex * typeCoercion.js supports ToBigInt * updated BigInt.asIntN type coercion tests to use typeCoercion.js
Diffstat (limited to 'harness')
-rw-r--r--harness/typeCoercion.js126
1 files changed, 125 insertions, 1 deletions
diff --git a/harness/typeCoercion.js b/harness/typeCoercion.js
index 296694fcf..7cd6a9de3 100644
--- a/harness/typeCoercion.js
+++ b/harness/typeCoercion.js
@@ -6,6 +6,20 @@ description: |
operations like ToNumber.
---*/
+function testCoercibleToIndexZero(test) {
+ testCoercibleToIntegerZero(test);
+}
+
+function testCoercibleToIndexOne(test) {
+ testCoercibleToIntegerOne(test);
+}
+
+function testCoercibleToIndexFromIndex(nominalIndex, test) {
+ assert(Number.isInteger(nominalIndex));
+ assert(0 <= nominalIndex && nominalIndex <= 2**53 - 1);
+ testCoercibleToIntegerFromInteger(nominalIndex, test);
+}
+
function testCoercibleToIntegerZero(test) {
testCoercibleToNumberZero(test);
@@ -176,10 +190,35 @@ function testCoercibleToPrimitiveWithMethod(hint, method, test) {
});
}
+function testNotCoercibleToIndex(test) {
+ function testPrimitiveValue(value) {
+ test(RangeError, value);
+ // ToPrimitive
+ testPrimitiveWrappers(value, "number", function(value) {
+ test(RangeError, value);
+ });
+ }
+
+ // Let integerIndex be ? ToInteger(value).
+ testNotCoercibleToInteger(test);
+
+ // If integerIndex < 0, throw a RangeError exception.
+ testPrimitiveValue(-1);
+ testPrimitiveValue(-2.5);
+ testPrimitiveValue("-2.5");
+ testPrimitiveValue(-Infinity);
+
+ // Let index be ! ToLength(integerIndex).
+ // If SameValueZero(integerIndex, index) is false, throw a RangeError exception.
+ testPrimitiveValue(2 ** 53);
+ testPrimitiveValue(Infinity);
+}
+
function testNotCoercibleToInteger(test) {
// ToInteger only throws from ToNumber.
- return testNotCoercibleToNumber(test);
+ testNotCoercibleToNumber(test);
}
+
function testNotCoercibleToNumber(test) {
function testPrimitiveValue(value) {
test(TypeError, value);
@@ -283,3 +322,88 @@ function testNotCoercibleToString(test) {
// ToPrimitive
testNotCoercibleToPrimitive("string", test);
}
+
+function testCoercibleToBigIntZero(test) {
+ function testPrimitiveValue(value) {
+ test(value);
+ // ToPrimitive
+ testPrimitiveWrappers(value, "number", test);
+ }
+
+ testCoercibleToBigIntFromBigInt(0n, test);
+ testPrimitiveValue(-0n);
+ testPrimitiveValue("-0");
+ testPrimitiveValue(false);
+ testPrimitiveValue("");
+ testPrimitiveValue(" ");
+
+ // toString() returns ""
+ test([]);
+
+ // toString() returns "0"
+ test([0]);
+}
+
+function testCoercibleToBigIntOne(test) {
+ function testPrimitiveValue(value) {
+ test(value);
+ // ToPrimitive
+ testPrimitiveWrappers(value, "number", test);
+ }
+
+ testCoercibleToBigIntFromBigInt(1n, test);
+ testPrimitiveValue(true);
+
+ // toString() returns "1"
+ test([1]);
+}
+
+function testCoercibleToBigIntFromBigInt(nominalBigInt, test) {
+ function testPrimitiveValue(value) {
+ test(value);
+ // ToPrimitive
+ testPrimitiveWrappers(value, "number", test);
+ }
+
+ testPrimitiveValue(nominalBigInt);
+ testPrimitiveValue(nominalBigInt.toString());
+ testPrimitiveValue("0b" + nominalBigInt.toString(2));
+ testPrimitiveValue("0o" + nominalBigInt.toString(8));
+ testPrimitiveValue("0x" + nominalBigInt.toString(16));
+ testPrimitiveValue(" " + nominalBigInt.toString() + " ");
+
+ // toString() returns the decimal string representation
+ test([nominalBigInt]);
+ test([nominalBigInt.toString()]);
+}
+
+function testNotCoercibleToBigInt(test) {
+ function testPrimitiveValue(error, value) {
+ test(error, value);
+ // ToPrimitive
+ testPrimitiveWrappers(value, "number", function(value) {
+ test(error, value);
+ });
+ }
+
+ // Undefined, Null, Number, Symbol -> TypeError
+ testPrimitiveValue(TypeError, undefined);
+ testPrimitiveValue(TypeError, null);
+ testPrimitiveValue(TypeError, 0);
+ testPrimitiveValue(TypeError, NaN);
+ testPrimitiveValue(TypeError, Infinity);
+ testPrimitiveValue(TypeError, Symbol("1"));
+
+ // when a String parses to NaN -> SyntaxError
+ function testStringValue(string) {
+ testPrimitiveValue(SyntaxError, string);
+ testPrimitiveValue(SyntaxError, " " + string);
+ testPrimitiveValue(SyntaxError, string + " ");
+ testPrimitiveValue(SyntaxError, " " + string + " ");
+ }
+ testStringValue("a");
+ testStringValue("0b2");
+ testStringValue("0o8");
+ testStringValue("0xg");
+ testStringValue("1n");
+}