From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../indexOf/position-tointeger-wrapped-values.js | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js (limited to 'js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js') diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js new file mode 100644 index 0000000000..ea8e721eaa --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js @@ -0,0 +1,111 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: String.prototype.indexOf type coercion for position parameter +esid: sec-string.prototype.indexof +info: | + String.prototype.indexOf ( searchString [ , position ] ) + + 4. Let pos be ? ToInteger(position). +features: [Symbol.toPrimitive, computed-property-names] +---*/ + +assert.sameValue("aaaa".indexOf("aa", Object(0)), 0, "ToPrimitive: unbox object with internal slot"); +assert.sameValue("aaaa".indexOf("aa", { + [Symbol.toPrimitive]: function() { + return 0; + } +}), 0, "ToPrimitive: @@toPrimitive"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: function() { + return 0; + } +}), 0, "ToPrimitive: valueOf"); +assert.sameValue("aaaa".indexOf("aa", { + toString: function() { + return 0; + } +}), 0, "ToPrimitive: toString"); +assert.sameValue("aaaa".indexOf("aa", Object(NaN)), 0, + "ToInteger: unbox object with internal slot => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", { + [Symbol.toPrimitive]: function() { + return NaN; + } +}), 0, "ToInteger: @@toPrimitive => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: function() { + return NaN; + } +}), 0, "ToInteger: valueOf => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", { + toString: function() { + return NaN; + } +}), 0, "ToInteger: toString => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", { + [Symbol.toPrimitive]: function() { + return undefined; + } +}), 0, "ToInteger: @@toPrimitive => undefined => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: function() { + return undefined; + } +}), 0, "ToInteger: valueOf => undefined => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", { + toString: function() { + return undefined; + } +}), 0, "ToInteger: toString => undefined => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", { + [Symbol.toPrimitive]: function() { + return null; + } +}), 0, "ToInteger: @@toPrimitive => null => 0"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: function() { + return null; + } +}), 0, "ToInteger: valueOf => null => 0"); +assert.sameValue("aaaa".indexOf("aa", { + toString: function() { + return null; + } +}), 0, "ToInteger: toString => null => 0"); +assert.sameValue("aaaa".indexOf("aa", Object(true)), 1, + "ToInteger: unbox object with internal slot => true => 1"); +assert.sameValue("aaaa".indexOf("aa", { + [Symbol.toPrimitive]: function() { + return true; + } +}), 1, "ToInteger: @@toPrimitive => true => 1"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: function() { + return true; + } +}), 1, "ToInteger: valueOf => true => 1"); +assert.sameValue("aaaa".indexOf("aa", { + toString: function() { + return true; + } +}), 1, "ToInteger: toString => true => 1"); +assert.sameValue("aaaa".indexOf("aa", Object("1.9")), 1, + "ToInteger: unbox object with internal slot => parse Number => 1.9 => 1"); +assert.sameValue("aaaa".indexOf("aa", { + [Symbol.toPrimitive]: function() { + return "1.9"; + } +}), 1, "ToInteger: @@toPrimitive => parse Number => 1.9 => 1"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: function() { + return "1.9"; + } +}), 1, "ToInteger: valueOf => parse Number => 1.9 => 1"); +assert.sameValue("aaaa".indexOf("aa", { + toString: function() { + return "1.9"; + } +}), 1, "ToInteger: toString => parse Number => 1.9 => 1"); + +reportCompare(0, 0); -- cgit v1.2.3