diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/indexOf')
49 files changed, 1760 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A10.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A10.js new file mode 100644 index 0000000000..e8470aa105 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A10.js @@ -0,0 +1,35 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The String.prototype.indexOf.length property has the attribute ReadOnly +es5id: 15.5.4.7_A10 +description: > + Checking if varying the String.prototype.indexOf.length property + fails +includes: [propertyHelper.js] +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (!(String.prototype.indexOf.hasOwnProperty('length'))) { + throw new Test262Error('#1: String.prototype.indexOf.hasOwnProperty(\'length\') return true. Actual: ' + String.prototype.indexOf.hasOwnProperty('length')); +} +// +////////////////////////////////////////////////////////////////////////////// + +var __obj = String.prototype.indexOf.length; + +verifyNotWritable(String.prototype.indexOf, "length", null, function() { + return "shifted"; +}); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (String.prototype.indexOf.length !== __obj) { + throw new Test262Error('#2: __obj = String.prototype.indexOf.length; String.prototype.indexOf.length = function(){return "shifted";}; String.prototype.indexOf.length === __obj. Actual: ' + String.prototype.indexOf.length); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A11.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A11.js new file mode 100644 index 0000000000..9154c4ee74 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A11.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The length property of the indexOf method is 1 +es5id: 15.5.4.7_A11 +description: Checking String.prototype.indexOf.length +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (!(String.prototype.indexOf.hasOwnProperty("length"))) { + throw new Test262Error('#1: String.prototype.indexOf.hasOwnProperty("length") return true. Actual: ' + String.prototype.indexOf.hasOwnProperty("length")); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (String.prototype.indexOf.length !== 1) { + throw new Test262Error('#2: String.prototype.indexOf.length === 1. Actual: ' + String.prototype.indexOf.length); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T1.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T1.js new file mode 100644 index 0000000000..5e5f2b4e77 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T1.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T1 +description: Arguments are false and true, and instance is object +---*/ + +var __instance = new Object(true); + +__instance.indexOf = String.prototype.indexOf; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__instance.indexOf(true, false) !== 0) { + throw new Test262Error('#1: __instance = new Object(true); __instance.indexOf = String.prototype.indexOf; __instance.indexOf(true, false) === 0. Actual: ' + __instance.indexOf(true, false)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T10.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T10.js new file mode 100644 index 0000000000..7a4a6940ad --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T10.js @@ -0,0 +1,32 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T10 +description: Call indexOf(searchString, position) function with object arguments +---*/ + +var __obj = { + toString: function() { + return "\u0041B"; + } +} +var __obj2 = { + valueOf: function() { + return true; + } +} +var __str = "ABB\u0041BABAB"; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.indexOf(__obj, __obj2) !== 3) { + throw new Test262Error('#1: var x; var __obj = {toString:function(){return "\u0041B";}}; var __obj2 = {valueOf:function(){return true;}}; var __str = "ABB\u0041BABAB"; __str.indexOf(__obj, __obj2) === 3. Actual: ' + __str.indexOf(__obj, __obj2)); +} +// +////////////////////////////////////////////////////////////////////////////// + +var x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T12.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T12.js new file mode 100644 index 0000000000..ae01758ac0 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T12.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T12 +description: Argument is string, and instance is array of strings +---*/ + +var __instance = new Array('new', 'zoo', 'revue'); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__instance.indexOf('new') !== 0) { + throw new Test262Error('#1: __instance = new Array(\'new\',\'zoo\',\'revue\'); __instance.indexOf(\'new\') === 0. Actual: ' + __instance.indexOf('new')); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (__instance.indexOf('zoo') !== 1) { + throw new Test262Error('#2: __instance = new Array(\'new\',\'zoo\',\'revue\'); __instance.indexOf(\'zoo\') === 1. Actual: ' + __instance.indexOf('zoo')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T2.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T2.js new file mode 100644 index 0000000000..84559cf6bf --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T2.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T2 +description: > + Arguments are boolean equation, function and null, and instance is + Boolean object +---*/ + +var __instance = new Boolean; + +__instance.indexOf = String.prototype.indexOf; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__instance.indexOf("A" !== "\u0041", function() { + return 0; + }(), null) !== 0) { + throw new Test262Error('#1: __instance = new Boolean; __instance.indexOf = String.prototype.indexOf; __instance.indexOf("A"!=="\\u0041", function(){return 0;}(),null) === 0. Actual: ' + __instance.indexOf("A" !== "\u0041", function() { + return 0; + }(), null)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T4.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T4.js new file mode 100644 index 0000000000..f569552206 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T4.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T4 +description: > + Call indexOf(searchString, position) function without arguments of + string +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +//since ToString() evaluates to "" indexOf() evaluates to indexOf("",0) +if ("".indexOf() !== -1) { + throw new Test262Error('#1: "".indexOf() === -1. Actual: ' + ("".indexOf())); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T5.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T5.js new file mode 100644 index 0000000000..062eb4a5bf --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T5.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T5 +description: > + Call indexOf(searchString, position) function with null argument + of function object +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +//since ToString(null) evaluates to "null" indexOf(null) evaluates to indexOf("",0) +if (function() { + return "gnulluna" + }().indexOf(null) !== 1) { + throw new Test262Error('#1: function(){return "gnulluna"}().indexOf(null) === 1. Actual: ' + function() { + return "gnulluna" + }().indexOf(null)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T6.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T6.js new file mode 100644 index 0000000000..220003e0b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T6.js @@ -0,0 +1,23 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T6 +description: > + Call indexOf(searchString, position) function with x argument of + new String object, where x is undefined variable +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +//since ToString(undefined) evaluates to "" indexOf(undefined) evaluates to indexOf("",0) +if (new String("undefined").indexOf(x) !== 0) { + throw new Test262Error('#1: var x; new String("undefined").indexOf(x) === 0. Actual: ' + new String("undefined").indexOf(x)); +} +// +////////////////////////////////////////////////////////////////////////////// + +var x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T7.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T7.js new file mode 100644 index 0000000000..7a617eff3a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T7.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T7 +description: > + Call indexOf(searchString, position) function with undefined + argument of string object +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +//since ToString(undefined) evaluates to "undefined" indexOf(undefined) evaluates to indexOf("undefined",0) +if (String("undefined").indexOf(undefined) !== 0) { + throw new Test262Error('#1: String("undefined").indexOf(undefined) === 0. Actual: ' + String("undefined").indexOf(undefined)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T8.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T8.js new file mode 100644 index 0000000000..ecc0cfb088 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T8.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T8 +description: > + Call indexOf(searchString, position) function with void 0 argument + of string object +---*/ + +var __obj = { + toString: function() {} +}; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +//since ToString(void 0) evaluates to "undefined" indexOf(void 0) evaluates to indexOf("undefined") +if (String(__obj).indexOf(void 0) !== 0) { + throw new Test262Error('#1: __obj = {toString:function(){}}; String(__obj).indexOf(void 0) === 0. Actual: ' + String(__obj).indexOf(void 0)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T9.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T9.js new file mode 100644 index 0000000000..e21a055b41 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A1_T9.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf(searchString, position) +es5id: 15.5.4.7_A1_T9 +description: > + Call indexOf(searchString, position) function with function(){}() + argument of string object +---*/ + +var __obj = { + valueOf: function() {}, + toString: void 0 +}; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +//since ToString(undefined) evaluates to "undefined" indexOf(undefined) evaluates to indexOf("undefined") +if (new String(__obj).indexOf(function() {}()) !== 0) { + throw new Test262Error('#1: __obj = {valueOf:function(){}, toString:void 0}; new String(__obj).indexOf(function(){}()) === 0. Actual: ' + new String(__obj).indexOf(function() {}())); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T1.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T1.js new file mode 100644 index 0000000000..e338160a18 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T1.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: When length of searchString less than length of ToString(this) -1 returns +es5id: 15.5.4.7_A2_T1 +description: Call "abcd".indexOf("abcdab") and check result +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ("abcd".indexOf("abcdab") !== -1) { + throw new Test262Error('#1: "abcd".indexOf("abcdab")===-1. Actual: ' + ("abcd".indexOf("abcdab"))); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T2.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T2.js new file mode 100644 index 0000000000..ad29d78703 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T2.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: When length of searchString less than length of ToString(this) -1 returns +es5id: 15.5.4.7_A2_T2 +description: Call "abcd".indexOf("abcdab",0) and check result +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ("abcd".indexOf("abcdab", 0) !== -1) { + throw new Test262Error('#1: "abcd".indexOf("abcdab",0)===-1. Actual: ' + ("abcd".indexOf("abcdab", 0))); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T3.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T3.js new file mode 100644 index 0000000000..0c21d307ce --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T3.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: When length of searchString less than length of ToString(this) -1 returns +es5id: 15.5.4.7_A2_T3 +description: Call "abcd".indexOf("abcdab",99) and check result +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ("abcd".indexOf("abcdab", 99) !== -1) { + throw new Test262Error('#1: "abcd".indexOf("abcdab",99)===-1. Actual: ' + ("abcd".indexOf("abcdab", 99))); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T4.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T4.js new file mode 100644 index 0000000000..8f9b2be63a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T4.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: When length of searchString less than length of ToString(this) -1 returns +es5id: 15.5.4.7_A2_T4 +description: Call "abcd".indexOf("abcdab",NaN) and check result +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ("abcd".indexOf("abcdab", NaN) !== -1) { + throw new Test262Error('#1: "abcd".indexOf("abcdab",NaN)===-1. Actual: ' + ("abcd".indexOf("abcdab", NaN))); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T1.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T1.js new file mode 100644 index 0000000000..47941f97e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T1.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Since we deal with max(ToInteger(pos), 0) if ToInteger(pos) less than 0 + indexOf(searchString,0) returns +es5id: 15.5.4.7_A3_T1 +description: Call "$$abcdabcd".indexOf("ab",NaN) and check result +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ("$$abcdabcd".indexOf("ab", NaN) !== 2) { + throw new Test262Error('#1: "$$abcdabcd".indexOf("ab",NaN)===2. Actual: ' + ("$$abcdabcd".indexOf("ab", NaN))); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T2.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T2.js new file mode 100644 index 0000000000..79264306b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T2.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Since we deal with max(ToInteger(pos), 0) if ToInteger(pos) less than 0 + indexOf(searchString,0) returns +es5id: 15.5.4.7_A3_T2 +description: Call "$$abcdabcd".indexOf("ab",eval("\"-99\"")) and check result +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ("$$abcdabcd".indexOf("ab", eval("\"-99\"")) !== 2) { + throw new Test262Error('#1: "$$abcdabcd".indexOf("ab",eval("\\"-99\\""))===2. Actual: ' + ("$$abcdabcd".indexOf("ab", eval("\"-99\"")))); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T3.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T3.js new file mode 100644 index 0000000000..efcfdd118e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T3.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Since we deal with max(ToInteger(pos), 0) if ToInteger(pos) less than 0 + indexOf(searchString,0) returns +es5id: 15.5.4.7_A3_T3 +description: > + Call "$$abcdabcd".indexOf("ab",function(){return -Infinity;}()) + and check result +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ("$$abcdabcd".indexOf("ab", function() { + return -Infinity; + }()) !== 2) { + throw new Test262Error('#1: "$$abcdabcd".indexOf("ab", function(){return -Infinity;}())===2. Actual: ' + ("$$abcdabcd".indexOf("ab", function() { + return -Infinity; + }()))); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T1.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T1.js new file mode 100644 index 0000000000..28b1e8b909 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T1.js @@ -0,0 +1,37 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + when String.prototype.indexOf(searchString, position) is called first Call ToString, giving it the this value as its argument. + Then Call ToString(searchString) and Call ToNumber(position) +es5id: 15.5.4.7_A4_T1 +description: Override toString and valueOf functions, valueOf throw exception +---*/ + +var __obj = { + toString: function() { + return "\u0041B"; + } +} +var __obj2 = { + valueOf: function() { + throw "intointeger"; + } +} +var __str = "ABB\u0041BABAB"; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + var x = __str.indexOf(__obj, __obj2); + throw new Test262Error('#1: "var x = __str.indexOf(__obj, __obj2)" lead to throwing exception'); +} catch (e) { + if (e !== "intointeger") { + throw new Test262Error('#1.1: Exception === "intointeger". Actual: ' + e); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T2.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T2.js new file mode 100644 index 0000000000..45cc620488 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T2.js @@ -0,0 +1,42 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + when String.prototype.indexOf(searchString, position) is called first Call ToString, giving it the this value as its argument. + Then Call ToString(searchString) and Call ToNumber(position) +es5id: 15.5.4.7_A4_T2 +description: > + Override toString and valueOf functions, second toString throw + exception +---*/ + +var __obj = { + toString: function() { + return "\u0041B"; + } +} +var __obj2 = { + valueOf: function() { + return {}; + }, + toString: function() { + throw "intointeger"; + } +} +var __str = new String("ABB\u0041BABAB"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + var x = __str.indexOf(__obj, __obj2); + throw new Test262Error('#1: "var x = __str.indexOf(__obj, __obj2)" lead to throwing exception'); +} catch (e) { + if (e !== "intointeger") { + throw new Test262Error('#1.1: Exception === "intointeger". Actual: ' + e); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T3.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T3.js new file mode 100644 index 0000000000..fc96919f8b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T3.js @@ -0,0 +1,34 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + when String.prototype.indexOf(searchString, position) is called first Call ToString, giving it the this value as its argument. + Then Call ToString(searchString) and Call ToNumber(position) +es5id: 15.5.4.7_A4_T3 +description: Override toString and valueOf functions +---*/ + +var __obj = { + toString: function() { + return "\u0041B"; + } +} +var __obj2 = { + valueOf: function() { + return {}; + }, + toString: function() { + return "1"; + } +} + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ("ABB\u0041BABAB".indexOf(__obj, __obj2) !== 3) { + throw new Test262Error('#1: var __obj = {toString:function(){return "\u0041B";}}; var __obj2 = {valueOf:function(){return {};},toString:function(){return "1";}}; "ABB\\u0041BABAB".indexOf(__obj, __obj2)===3. Actual: ' + ("ABB\u0041BABAB".indexOf(__obj, __obj2))); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T4.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T4.js new file mode 100644 index 0000000000..1701373f5a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T4.js @@ -0,0 +1,38 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + when String.prototype.indexOf(searchString, position) is called first Call ToString, giving it the this value as its argument. + Then Call ToString(searchString) and Call ToNumber(position) +es5id: 15.5.4.7_A4_T4 +description: Override toString and valueOf functions, and they throw exceptions +---*/ + +var __obj = { + toString: function() { + throw "intostr"; + } +}; +var __obj2 = { + valueOf: function() { + throw "intoint"; + } +}; +var __instance = new Number(10001.10001); +Number.prototype.indexOf = String.prototype.indexOf; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + var x = __instance.indexOf(__obj, __obj2); + throw new Test262Error('#1: "var x = __instance.indexOf(__obj, __obj2)" lead to throwing exception'); +} catch (e) { + if (e !== "intostr") { + throw new Test262Error('#1.1: Exception === "intostr". Actual: ' + e); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T5.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T5.js new file mode 100644 index 0000000000..59bd7c409c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A4_T5.js @@ -0,0 +1,56 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + when String.prototype.indexOf(searchString, position) is called first Call ToString, giving it the this value as its argument. + Then Call ToString(searchString) and Call ToNumber(position) +es5id: 15.5.4.7_A4_T5 +description: > + Override toString and valueOf functions, first and second valueOf + throw exception +---*/ + +var __obj = { + toString: function() { + return {}; + }, + valueOf: function() { + throw "intostr"; + } +}; + +var __obj2 = { + valueOf: function() { + throw "intointeger"; + } +}; + +__FACTORY.prototype.indexOf = String.prototype.indexOf; + +var __instance = new __FACTORY(void 0); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + var x = __instance.indexOf(__obj, __obj2); + throw new Test262Error('#1: "var x = __instance.indexOf(__obj, __obj2)" lead to throwing exception'); +} catch (e) { + if (e !== "intostr") { + throw new Test262Error('#1.1: Exception === "intostr". Actual: ' + e); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +function __FACTORY(value) { + this.value = value; + this.toString = function() { + return new Number; + }; + this.valueOf = function() { + return this.value + "" + }; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T1.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T1.js new file mode 100644 index 0000000000..dfb17a474d --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T1.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf works properly +es5id: 15.5.4.7_A5_T1 +description: Search one symbol from begin of string +---*/ + +var TEST_STRING = new String(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +for (var k = 0, i = 0x0020; i < 0x007e; i++, k++) { + if (TEST_STRING.indexOf(String.fromCharCode(i), 0) !== k) { + throw new Test262Error('#' + (i - 0x0020) + ': TEST_STRING.indexOf( String.fromCharCode(' + i + '), 0 )===' + k + '. Actual: ' + TEST_STRING.indexOf(String.fromCharCode(i), 0)); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T2.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T2.js new file mode 100644 index 0000000000..017a91506c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T2.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf works properly +es5id: 15.5.4.7_A5_T2 +description: Search one symbol from its position in the string +---*/ + +var TEST_STRING = new String(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +for (var k = 0, i = 0x0020; i < 0x007e; i++, k++) { + if (TEST_STRING.indexOf(String.fromCharCode(i), k) !== k) { + throw new Test262Error('#' + (i - 0x0020) + ': TEST_STRING.indexOf( String.fromCharCode(' + i + '), ' + k + ' )===' + k + '. Actual: ' + TEST_STRING.indexOf(String.fromCharCode(i), k)); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T3.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T3.js new file mode 100644 index 0000000000..22f9b8328c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T3.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf works properly +es5id: 15.5.4.7_A5_T3 +description: Search one symbol from its position+1 in the string +---*/ + +var TEST_STRING = new String(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +for (var k = 0, i = 0x0020; i < 0x007e; i++, k++) { + if (TEST_STRING.indexOf(String.fromCharCode(i), k + 1) !== -1) { + throw new Test262Error('#' + (i - 0x0020) + ': TEST_STRING.indexOf( String.fromCharCode(' + i + '), ' + (k + 1) + ' )===-1. Actual: ' + TEST_STRING.indexOf(String.fromCharCode(i), k + 1)); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T4.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T4.js new file mode 100644 index 0000000000..b257a00bb7 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T4.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf works properly +es5id: 15.5.4.7_A5_T4 +description: Search substring from begin of string +---*/ + +var TEST_STRING = new String(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +for (var k = 0, i = 0x0020; i < 0x007d; i++, k++) { + if (TEST_STRING.indexOf((String.fromCharCode(i) + String.fromCharCode(i + 1) + String.fromCharCode(i + 2)), 0) !== k) { + throw new Test262Error('#' + (i - 0x0020) + ': TEST_STRING.indexOf( (String.fromCharCode(' + i + ')+ String.fromCharCode(' + (i + 1) + ') + String.fromCharCode(' + (i + 2) + ')), 0 )===' + k + '. Actual: ' + TEST_STRING.indexOf((String.fromCharCode(i) + String.fromCharCode(i + 1) + String.fromCharCode(i + 2)), 0)); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T5.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T5.js new file mode 100644 index 0000000000..2b96e84170 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T5.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf works properly +es5id: 15.5.4.7_A5_T5 +description: Search substring from its position in the string +---*/ + +var TEST_STRING = new String(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +for (var k = 0, i = 0x0020; i < 0x007d; i++, k++) { + if (TEST_STRING.indexOf((String.fromCharCode(i) + String.fromCharCode(i + 1) + String.fromCharCode(i + 2)), k) !== k) { + throw new Test262Error('#' + (i - 0x0020) + ': TEST_STRING.indexOf( (String.fromCharCode(' + i + ')+ String.fromCharCode(' + (i + 1) + ') + String.fromCharCode(' + (i + 2) + ')), ' + k + ' )===' + k + '. Actual: ' + TEST_STRING.indexOf((String.fromCharCode(i) + String.fromCharCode(i + 1) + String.fromCharCode(i + 2)), k)); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T6.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T6.js new file mode 100644 index 0000000000..2120268f71 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A5_T6.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf works properly +es5id: 15.5.4.7_A5_T6 +description: Search substring from its position+1 in the string +---*/ + +var TEST_STRING = new String(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +for (var k = 0, i = 0x0020; i < 0x007d; i++, k++) { + if (TEST_STRING.indexOf((String.fromCharCode(i) + String.fromCharCode(i + 1) + String.fromCharCode(i + 2)), k + 1) !== -1) { + throw new Test262Error('#' + (i - 0x0020) + ': TEST_STRING.indexOf( (String.fromCharCode(' + i + ')+ String.fromCharCode(' + (i + 1) + ') + String.fromCharCode(' + (i + 2) + ')), ' + (k + 1) + ' )=== -1. Actual: ' + TEST_STRING.indexOf((String.fromCharCode(i) + String.fromCharCode(i + 1) + String.fromCharCode(i + 2)), k + 1)); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A6.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A6.js new file mode 100644 index 0000000000..2989c9b54c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A6.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf has not prototype property +es5id: 15.5.4.7_A6 +description: Checking String.prototype.indexOf.prototype +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (String.prototype.indexOf.prototype !== undefined) { + throw new Test262Error('#1: String.prototype.indexOf.prototype === undefined. Actual: ' + String.prototype.indexOf.prototype); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A7.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A7.js new file mode 100644 index 0000000000..aca8033023 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A7.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.indexOf can't be used as constructor +es5id: 15.5.4.7_A7 +description: Checking if creating the String.prototype.indexOf object fails +---*/ + +var __FACTORY = String.prototype.indexOf; + +try { + var __instance = new __FACTORY; + throw new Test262Error('#1: var __FACTORY = String.prototype.indexOf; "__instance = new __FACTORY" lead to throwing exception'); +} catch (e) { + if ((e instanceof TypeError) !== true) { + throw new Test262Error('#1.2: var __FACTORY = String.prototype.indexOf; "__instance = new __FACTORY" throw a TypeError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A8.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A8.js new file mode 100644 index 0000000000..7b64601072 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A8.js @@ -0,0 +1,43 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The String.prototype.indexOf.length property has the attribute DontEnum +es5id: 15.5.4.7_A8 +description: > + Checking if enumerating the String.prototype.indexOf.length + property fails +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#0 +if (!(String.prototype.indexOf.hasOwnProperty('length'))) { + throw new Test262Error('#0: String.prototype.indexOf.hasOwnProperty(\'length\') return true. Actual: ' + String.prototype.indexOf.hasOwnProperty('length')); +} +// +////////////////////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////////////////////// +// CHECK#1 +if (String.prototype.indexOf.propertyIsEnumerable('length')) { + throw new Test262Error('#1: String.prototype.indexOf.propertyIsEnumerable(\'length\') return false'); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +// CHECK#2 +var count = 0; + +for (var p in String.prototype.indexOf) { + if (p === "length") count++; +} + +if (count !== 0) { + throw new Test262Error('#2: count=0; for (p in String.prototype.indexOf){if (p==="length") count++;}; count === 0. Actual: ' + count); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A9.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A9.js new file mode 100644 index 0000000000..310d9116fc --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/S15.5.4.7_A9.js @@ -0,0 +1,38 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The String.prototype.indexOf.length property does not have the attribute + DontDelete +es5id: 15.5.4.7_A9 +description: > + Checking if deleting the String.prototype.indexOf.length property + fails +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#0 +if (!(String.prototype.indexOf.hasOwnProperty('length'))) { + throw new Test262Error('#0: String.prototype.indexOf.hasOwnProperty(\'length\') return true. Actual: ' + String.prototype.indexOf.hasOwnProperty('length')); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (!delete String.prototype.indexOf.length) { + throw new Test262Error('#1: delete String.prototype.indexOf.length raturn true'); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (String.prototype.indexOf.hasOwnProperty('length')) { + throw new Test262Error('#2: delete String.prototype.indexOf.length; String.prototype.indexOf.hasOwnProperty(\'length\') return false. Actual: ' + String.prototype.indexOf.hasOwnProperty('length')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/browser.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/name.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/name.js new file mode 100644 index 0000000000..ff0064a42f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.1.3.8 +description: > + String.prototype.indexOf.name is "indexOf". +info: | + String.prototype.indexOf ( searchString [ , position ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(String.prototype.indexOf.name, "indexOf"); + +verifyNotEnumerable(String.prototype.indexOf, "name"); +verifyNotWritable(String.prototype.indexOf, "name"); +verifyConfigurable(String.prototype.indexOf, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/not-a-constructor.js new file mode 100644 index 0000000000..6cc8bc2efb --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.indexOf does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.indexOf), + false, + 'isConstructor(String.prototype.indexOf) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.indexOf(); +}, '`new String.prototype.indexOf()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-bigint.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-bigint.js new file mode 100644 index 0000000000..a7be5890ff --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-bigint.js @@ -0,0 +1,41 @@ +// 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: [BigInt, Symbol.toPrimitive, computed-property-names] +---*/ + +assert.throws(TypeError, function() { + "".indexOf("", 0n); +}, "ToInteger: BigInt => TypeError"); +assert.throws(TypeError, function() { + "".indexOf("", Object(0n)); +}, "ToInteger: unbox object with internal slot => BigInt => TypeError"); +assert.throws(TypeError, function() { + "".indexOf("", { + [Symbol.toPrimitive]: function() { + return 0n; + } + }); +}, "ToInteger: @@toPrimitive => BigInt => TypeError"); +assert.throws(TypeError, function() { + "".indexOf("", { + valueOf: function() { + return 0n; + } + }); +}, "ToInteger: valueOf => BigInt => TypeError"); +assert.throws(TypeError, function() { + "".indexOf("", { + toString: function() { + return 0n; + } + }); +}, "ToInteger: toString => BigInt => TypeError"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-errors.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-errors.js new file mode 100644 index 0000000000..f21a3d0144 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-errors.js @@ -0,0 +1,41 @@ +// 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, Symbol.toPrimitive, computed-property-names] +---*/ + +assert.throws(TypeError, function() { + "".indexOf("", Symbol("1")); +}, "ToInteger: Symbol => TypeError"); +assert.throws(TypeError, function() { + "".indexOf("", Object(Symbol("1"))); +}, "ToInteger: unbox object with internal slot => Symbol => TypeError"); +assert.throws(TypeError, function() { + "".indexOf("", { + [Symbol.toPrimitive]: function() { + return Symbol("1"); + } + }); +}, "ToInteger: @@toPrimitive => Symbol => TypeError"); +assert.throws(TypeError, function() { + "".indexOf("", { + valueOf: function() { + return Symbol("1"); + } + }); +}, "ToInteger: valueOf => Symbol => TypeError"); +assert.throws(TypeError, function() { + "".indexOf("", { + toString: function() { + return Symbol("1"); + } + }); +}, "ToInteger: toString => Symbol => TypeError"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-toprimitive.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-toprimitive.js new file mode 100644 index 0000000000..68a89ae176 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger-toprimitive.js @@ -0,0 +1,167 @@ +// 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] +---*/ + +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue("aaaa".indexOf("aa", { + [Symbol.toPrimitive]: function() { + return 1; + }, + valueOf: err, + toString: err +}), 1, "ToPrimitive: @@toPrimitive takes precedence"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: function() { + return 1; + }, + toString: err +}), 1, "ToPrimitive: valueOf takes precedence over toString"); +assert.sameValue("aaaa".indexOf("aa", { + toString: function() { + return 1; + } +}), 1, "ToPrimitive: toString with no valueOf"); +assert.sameValue("aaaa".indexOf("aa", { + [Symbol.toPrimitive]: undefined, + valueOf: function() { + return 1; + } +}), 1, "ToPrimitive: skip @@toPrimitive when it's undefined"); +assert.sameValue("aaaa".indexOf("aa", { + [Symbol.toPrimitive]: null, + valueOf: function() { + return 1; + } +}), 1, "ToPrimitive: skip @@toPrimitive when it's null"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: null, + toString: function() { + return 1; + } +}), 1, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: 1, + toString: function() { + return 1; + } +}), 1, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: {}, + toString: function() { + return 1; + } +}), 1, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: function() { + return {}; + }, + toString: function() { + return 1; + } +}), 1, "ToPrimitive: skip valueOf when it returns an object"); +assert.sameValue("aaaa".indexOf("aa", { + valueOf: function() { + return Object(12345); + }, + toString: function() { + return 1; + } +}), 1, "ToPrimitive: skip valueOf when it returns an object"); +assert.throws(TypeError, function() { + "".indexOf("", { + [Symbol.toPrimitive]: 1 + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + "".indexOf("", { + [Symbol.toPrimitive]: {} + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + "".indexOf("", { + [Symbol.toPrimitive]: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(TypeError, function() { + "".indexOf("", { + [Symbol.toPrimitive]: function() { + return {}; + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(MyError, function() { + "".indexOf("", { + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from @@toPrimitive"); +assert.throws(MyError, function() { + "".indexOf("", { + valueOf: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from valueOf"); +assert.throws(MyError, function() { + "".indexOf("", { + toString: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from toString"); +assert.throws(TypeError, function() { + "".indexOf("", { + valueOf: null, + toString: null + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + "".indexOf("", { + valueOf: 1, + toString: 1 + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + "".indexOf("", { + valueOf: {}, + toString: {} + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + "".indexOf("", { + valueOf: function() { + return Object(1); + }, + toString: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + "".indexOf("", { + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); + +reportCompare(0, 0); 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); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger.js new file mode 100644 index 0000000000..46f49616c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/position-tointeger.js @@ -0,0 +1,39 @@ +// 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). +---*/ + +assert.sameValue("aaaa".indexOf("aa", 0), 0); +assert.sameValue("aaaa".indexOf("aa", 1), 1); +assert.sameValue("aaaa".indexOf("aa", -0.9), 0, "ToInteger: truncate towards 0"); +assert.sameValue("aaaa".indexOf("aa", 0.9), 0, "ToInteger: truncate towards 0"); +assert.sameValue("aaaa".indexOf("aa", 1.9), 1, "ToInteger: truncate towards 0"); +assert.sameValue("aaaa".indexOf("aa", NaN), 0, "ToInteger: NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", Infinity), -1); +assert.sameValue("aaaa".indexOf("aa", undefined), 0, "ToInteger: undefined => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", null), 0, "ToInteger: null => 0"); +assert.sameValue("aaaa".indexOf("aa", false), 0, "ToInteger: false => 0"); +assert.sameValue("aaaa".indexOf("aa", true), 1, "ToInteger: true => 1"); +assert.sameValue("aaaa".indexOf("aa", "0"), 0, "ToInteger: parse Number"); +assert.sameValue("aaaa".indexOf("aa", "1.9"), 1, "ToInteger: parse Number => 1.9 => 1"); +assert.sameValue("aaaa".indexOf("aa", "Infinity"), -1, "ToInteger: parse Number"); +assert.sameValue("aaaa".indexOf("aa", ""), 0, "ToInteger: unparseable string => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", "foo"), 0, "ToInteger: unparseable string => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", "true"), 0, "ToInteger: unparseable string => NaN => 0"); +assert.sameValue("aaaa".indexOf("aa", 2), 2); +assert.sameValue("aaaa".indexOf("aa", "2"), 2, "ToInteger: parse Number"); +assert.sameValue("aaaa".indexOf("aa", 2.9), 2, "ToInteger: truncate towards 0"); +assert.sameValue("aaaa".indexOf("aa", "2.9"), 2, "ToInteger: parse Number => truncate towards 0"); +assert.sameValue("aaaa".indexOf("aa", [0]), 0, 'ToInteger: [0].toString() => "0" => 0'); +assert.sameValue("aaaa".indexOf("aa", ["1"]), 1, 'ToInteger: ["1"].toString() => "1" => 1'); +assert.sameValue("aaaa".indexOf("aa", {}), 0, + 'ToInteger: ({}).toString() => "[object Object]" => NaN => 0'); +assert.sameValue("aaaa".indexOf("aa", []), 0, 'ToInteger: [].toString() => "" => NaN => 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-bigint.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-bigint.js new file mode 100644 index 0000000000..42b59ffef2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-bigint.js @@ -0,0 +1,33 @@ +// 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 searchString parameter +esid: sec-string.prototype.indexof +info: | + String.prototype.indexOf ( searchString [ , position ] ) + + 3. Let searchStr be ? ToString(searchString). +features: [BigInt, Symbol.toPrimitive, computed-property-names] +---*/ + +assert.sameValue("__0__".indexOf(0n), 2, "ToString: BigInt to String"); +assert.sameValue("__0__".indexOf(Object(0n)), 2, + "ToString: unbox object with internal slot => BigInt to String"); +assert.sameValue("__0__".indexOf({ + [Symbol.toPrimitive]: function() { + return 0n; + } +}), 2, "ToString: @@toPrimitive => BigInt to String"); +assert.sameValue("__0__".indexOf({ + valueOf: function() { + return 0n; + }, + toString: null +}), 2, "ToString: valueOf => BigInt to String"); +assert.sameValue("__0__".indexOf({ + toString: function() { + return 0n; + } +}), 2, "ToString: toString => BigInt to String"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-errors.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-errors.js new file mode 100644 index 0000000000..9f2802c291 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-errors.js @@ -0,0 +1,42 @@ +// 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 searchString parameter +esid: sec-string.prototype.indexof +info: | + String.prototype.indexOf ( searchString [ , position ] ) + + 3. Let searchStr be ? ToString(searchString). +features: [Symbol, Symbol.toPrimitive, computed-property-names] +---*/ + +assert.throws(TypeError, function() { + "".indexOf(Symbol("1")); +}, "ToString: Symbol => TypeError"); +assert.throws(TypeError, function() { + "".indexOf(Object(Symbol("1"))); +}, "ToString: unbox object with internal slot => Symbol => TypeError"); +assert.throws(TypeError, function() { + "".indexOf({ + [Symbol.toPrimitive]: function() { + return Symbol("1"); + } + }); +}, "ToString: @@toPrimitive => Symbol => TypeError"); +assert.throws(TypeError, function() { + "".indexOf({ + valueOf: function() { + return Symbol("1"); + }, + toString: null + }); +}, "ToString: valueOf => Symbol => TypeError"); +assert.throws(TypeError, function() { + "".indexOf({ + toString: function() { + return Symbol("1"); + } + }); +}, "ToString: toString => Symbol => TypeError"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-toprimitive.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-toprimitive.js new file mode 100644 index 0000000000..6c45bd6965 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-toprimitive.js @@ -0,0 +1,163 @@ +// 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 searchString parameter +esid: sec-string.prototype.indexof +info: | + String.prototype.indexOf ( searchString [ , position ] ) + + 3. Let searchStr be ? ToString(searchString). +features: [Symbol.toPrimitive, computed-property-names] +---*/ + +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue("__foo__".indexOf({ + [Symbol.toPrimitive]: function() { + return "foo"; + }, + toString: err, + valueOf: err +}), 2, "ToPrimitive: @@toPrimitive takes precedence"); +assert.sameValue("__foo__".indexOf({ + toString: function() { + return "foo"; + }, + valueOf: err +}), 2, "ToPrimitive: toString takes precedence over valueOf"); +assert.sameValue("__foo__".indexOf({ + [Symbol.toPrimitive]: undefined, + toString: function() { + return "foo"; + } +}), 2, "ToPrimitive: skip @@toPrimitive when it's undefined"); +assert.sameValue("__foo__".indexOf({ + [Symbol.toPrimitive]: null, + toString: function() { + return "foo"; + } +}), 2, "ToPrimitive: skip @@toPrimitive when it's null"); +assert.sameValue("__foo__".indexOf({ + toString: null, + valueOf: function() { + return "foo"; + } +}), 2, "ToPrimitive: skip toString when it's not callable"); +assert.sameValue("__foo__".indexOf({ + toString: 1, + valueOf: function() { + return "foo"; + } +}), 2, "ToPrimitive: skip toString when it's not callable"); +assert.sameValue("__foo__".indexOf({ + toString: {}, + valueOf: function() { + return "foo"; + } +}), 2, "ToPrimitive: skip toString when it's not callable"); +assert.sameValue("__foo__".indexOf({ + toString: function() { + return {}; + }, + valueOf: function() { + return "foo"; + } +}), 2, "ToPrimitive: skip toString when it returns an object"); +assert.sameValue("__foo__".indexOf({ + toString: function() { + return Object(12345); + }, + valueOf: function() { + return "foo"; + } +}), 2, "ToPrimitive: skip toString when it returns an object"); +assert.throws(TypeError, function() { + "".indexOf({ + [Symbol.toPrimitive]: 1 + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + "".indexOf({ + [Symbol.toPrimitive]: {} + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + "".indexOf({ + [Symbol.toPrimitive]: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(TypeError, function() { + "".indexOf({ + [Symbol.toPrimitive]: function() { + return {}; + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(MyError, function() { + "".indexOf({ + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from @@toPrimitive"); +assert.throws(MyError, function() { + "".indexOf({ + valueOf: function() { + throw new MyError(); + }, + toString: null + }); +}, "ToPrimitive: propagate errors from valueOf"); +assert.throws(MyError, function() { + "".indexOf({ + toString: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from toString"); +assert.throws(TypeError, function() { + "".indexOf({ + valueOf: null, + toString: null + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + "".indexOf({ + valueOf: 1, + toString: 1 + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + "".indexOf({ + valueOf: {}, + toString: {} + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + "".indexOf({ + valueOf: function() { + return Object(1); + }, + toString: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + "".indexOf({ + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-wrapped-values.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-wrapped-values.js new file mode 100644 index 0000000000..af0c8a76c8 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring-wrapped-values.js @@ -0,0 +1,100 @@ +// 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 searchString parameter +esid: sec-string.prototype.indexof +info: | + String.prototype.indexOf ( searchString [ , position ] ) + + 3. Let searchStr be ? ToString(searchString). +features: [Symbol.toPrimitive, computed-property-names] +---*/ + +assert.sameValue("__foo__".indexOf(Object("foo")), 2, + "ToPrimitive: unbox object with internal slot"); +assert.sameValue("__foo__".indexOf({ + [Symbol.toPrimitive]: function() { + return "foo"; + } +}), 2, "ToPrimitive: @@toPrimitive"); +assert.sameValue("__foo__".indexOf({ + valueOf: function() { + return "foo"; + }, + toString: null +}), 2, "ToPrimitive: valueOf"); +assert.sameValue("__foo__".indexOf({ + toString: function() { + return "foo"; + } +}), 2, "ToPrimitive: toString"); +assert.sameValue("__undefined__".indexOf({ + [Symbol.toPrimitive]: function() { + return undefined; + } +}), 2, 'ToString: @@toPrimitive => undefined => "undefined"'); +assert.sameValue("__undefined__".indexOf({ + valueOf: function() { + return undefined; + }, + toString: null +}), 2, 'ToString: valueOf => undefined => "undefined"'); +assert.sameValue("__undefined__".indexOf({ + toString: function() { + return undefined; + } +}), 2, 'ToString: toString => undefined => "undefined"'); +assert.sameValue("__null__".indexOf({ + [Symbol.toPrimitive]: function() { + return null; + } +}), 2, 'ToString: @@toPrimitive => null => "null"'); +assert.sameValue("__null__".indexOf({ + valueOf: function() { + return null; + }, + toString: null +}), 2, 'ToString: valueOf => null => "null"'); +assert.sameValue("__null__".indexOf({ + toString: function() { + return null; + } +}), 2, 'ToString: toString => null => "null"'); +assert.sameValue("__false__".indexOf(Object(false)), 2, + 'ToString: unbox object with internal slot => false => "false"'); +assert.sameValue("__false__".indexOf({ + [Symbol.toPrimitive]: function() { + return false; + } +}), 2, 'ToString: @@toPrimitive => false => "false"'); +assert.sameValue("__false__".indexOf({ + valueOf: function() { + return false; + }, + toString: null +}), 2, 'ToString: valueOf => false => "false"'); +assert.sameValue("__false__".indexOf({ + toString: function() { + return false; + } +}), 2, 'ToString: toString => false => "false"'); +assert.sameValue("__0__".indexOf(Object(0)), 2, + "ToString: unbox object with internal slot => Number to String"); +assert.sameValue("__0__".indexOf({ + [Symbol.toPrimitive]: function() { + return 0; + } +}), 2, "ToString: @@toPrimitive => Number to String"); +assert.sameValue("__0__".indexOf({ + valueOf: function() { + return 0; + }, + toString: null +}), 2, "ToString: valueOf => Number to String"); +assert.sameValue("__0__".indexOf({ + toString: function() { + return 0; + } +}), 2, "ToString: toString => Number to String"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring.js new file mode 100644 index 0000000000..fb49889399 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/searchstring-tostring.js @@ -0,0 +1,29 @@ +// 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 searchString parameter +esid: sec-string.prototype.indexof +info: | + String.prototype.indexOf ( searchString [ , position ] ) + + 3. Let searchStr be ? ToString(searchString). +---*/ + +assert.sameValue("foo".indexOf(""), 0); +assert.sameValue("__foo__".indexOf("foo"), 2); +assert.sameValue("__undefined__".indexOf(undefined), 2, 'ToString: undefined => "undefined"'); +assert.sameValue("__null__".indexOf(null), 2, 'ToString: null => "null"'); +assert.sameValue("__true__".indexOf(true), 2, 'ToString: true => "true"'); +assert.sameValue("__false__".indexOf(false), 2, 'ToString: false => "false"'); +assert.sameValue("__0__".indexOf(0), 2, "ToString: Number to String"); +assert.sameValue("__0__".indexOf(-0), 2, 'ToString: -0 => "0"'); +assert.sameValue("__Infinity__".indexOf(Infinity), 2, 'ToString: Infinity => "Infinity"'); +assert.sameValue("__-Infinity__".indexOf(-Infinity), 2, 'ToString: -Infinity => "-Infinity"'); +assert.sameValue("__NaN__".indexOf(NaN), 2, 'ToString: NaN => "NaN"'); +assert.sameValue("__123.456__".indexOf(123.456), 2, "ToString: Number to String"); +assert.sameValue("__-123.456__".indexOf(-123.456), 2, "ToString: Number to String"); +assert.sameValue("foo".indexOf([]), 0, "ToString: .toString()"); +assert.sameValue("__foo,bar__".indexOf(["foo", "bar"]), 2, "ToString: .toString()"); +assert.sameValue("__[object Object]__".indexOf({}), 2, "ToString: .toString()"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/shell.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/shell.js diff --git a/js/src/tests/test262/built-ins/String/prototype/indexOf/this-value-not-obj-coercible.js b/js/src/tests/test262/built-ins/String/prototype/indexOf/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..46ab36f345 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/indexOf/this-value-not-obj-coercible.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.indexof +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var indexOf = String.prototype.indexOf; + +assert.sameValue(typeof indexOf, 'function'); + +assert.throws(TypeError, function() { + indexOf.call(undefined, ''); +}, 'undefined'); + +assert.throws(TypeError, function() { + indexOf.call(null, ''); +}, 'null'); + +reportCompare(0, 0); |