summaryrefslogtreecommitdiff
path: root/harness
diff options
context:
space:
mode:
authorJosh Wolfe <jwolfe@igalia.com>2017-08-29 18:06:37 -0700
committerRick Waldron <waldron.rick@gmail.com>2017-09-08 10:15:19 -0400
commitf83adad4bd1e2005401fb7791fa86f8cf749908e (patch)
tree5460d7e6400abc202b18dad2f81388a2813de0c1 /harness
parent0d9ef34510cc7851b0ac67a7cf7200eb2a97a7a8 (diff)
downloadqtdeclarative-testsuites-f83adad4bd1e2005401fb7791fa86f8cf749908e.tar.gz
test for String.prototype.indexOf first parameter type coercion
Diffstat (limited to 'harness')
-rw-r--r--harness/typeCoercion.js61
1 files changed, 58 insertions, 3 deletions
diff --git a/harness/typeCoercion.js b/harness/typeCoercion.js
index 7c32a2c8d..296694fcf 100644
--- a/harness/typeCoercion.js
+++ b/harness/typeCoercion.js
@@ -129,9 +129,15 @@ function testCoercibleToPrimitiveWithMethod(hint, method, test) {
[methodNames[0]]: method,
[methodNames[1]]: function() { throw new Test262Error(); },
});
- test({
- [methodNames[1]]: method,
- });
+ if (hint === "number") {
+ // The default valueOf returns an object, which is unsuitable.
+ // The default toString returns a String, which is suitable.
+ // Therefore this test only works for valueOf falling back to toString.
+ test({
+ // this is toString:
+ [methodNames[1]]: method,
+ });
+ }
// GetMethod: if func is undefined or null, return undefined.
test({
@@ -228,3 +234,52 @@ function testNotCoercibleToPrimitive(hint, test) {
testUnsuitableMethod(function() { return Object(1); });
testUnsuitableMethod(function() { return {}; });
}
+
+function testCoercibleToString(test) {
+ function testPrimitiveValue(value, expectedString) {
+ test(value, expectedString);
+ // ToPrimitive
+ testPrimitiveWrappers(value, "string", function(value) {
+ test(value, expectedString);
+ });
+ }
+
+ testPrimitiveValue(undefined, "undefined");
+ testPrimitiveValue(null, "null");
+ testPrimitiveValue(true, "true");
+ testPrimitiveValue(false, "false");
+ testPrimitiveValue(0, "0");
+ testPrimitiveValue(-0, "0");
+ testPrimitiveValue(Infinity, "Infinity");
+ testPrimitiveValue(-Infinity, "-Infinity");
+ testPrimitiveValue(123.456, "123.456");
+ testPrimitiveValue(-123.456, "-123.456");
+ testPrimitiveValue("", "");
+ testPrimitiveValue("foo", "foo");
+
+ if (typeof BigInt !== "undefined") {
+ // BigInt -> TypeError
+ testPrimitiveValue(BigInt(0), "0");
+ }
+
+ // toString of a few objects
+ test([], "");
+ test(["foo", "bar"], "foo,bar");
+ test({}, "[object Object]");
+}
+
+function testNotCoercibleToString(test) {
+ function testPrimitiveValue(value) {
+ test(TypeError, value);
+ // ToPrimitive
+ testPrimitiveWrappers(value, "string", function(value) {
+ test(TypeError, value);
+ });
+ }
+
+ // Symbol -> TypeError
+ testPrimitiveValue(Symbol("1"));
+
+ // ToPrimitive
+ testNotCoercibleToPrimitive("string", test);
+}