diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js')
-rw-r--r-- | js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js | 111 |
1 files changed, 111 insertions, 0 deletions
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); |