summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-wrapped-values.js
diff options
context:
space:
mode:
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.js111
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);