diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/replace')
49 files changed, 1250 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/15.5.4.11-1.js b/js/src/tests/test262/built-ins/String/prototype/replace/15.5.4.11-1.js new file mode 100644 index 0000000000..e7a7818938 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/15.5.4.11-1.js @@ -0,0 +1,24 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 15.5.4.11-1 +description: > + 'this' object used by the replaceValue function of a + String.prototype.replace invocation +flags: [noStrict] +---*/ + +var global = this; +var retVal = 'x'.replace(/x/, + function() { + if (this === global) { + return 'y'; + } else { + return 'z'; + } + }); + +assert.sameValue(retVal, 'y', 'retVal'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A12.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A12.js new file mode 100644 index 0000000000..de508e784f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A12.js @@ -0,0 +1,25 @@ +// Copyright 2011 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Call replaceValue passing undefined as the this value +es5id: 15.5.4.11_A12 +description: replaceValue tests that its this value is undefined +flags: [noStrict] +---*/ + +var global = this; +'x'.replace(/x/, function() { + "use strict"; + + if (this === global) { + throw new Test262Error('#1: String replace leaks global'); + } + if (this !== undefined) { + throw new Test262Error('#2: replaceValue should be called with this===undefined. ' + + 'Actual: ' + this); + } + return 'y'; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T1.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T1.js new file mode 100644 index 0000000000..7d915749b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_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.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T1 +description: Arguments are true and 1, and instance is object +---*/ + +var __instance = new Object(true); + +__instance.replace = String.prototype.replace; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__instance.replace(true, 1) !== "1") { + throw new Test262Error('#1: __instance = new Object(true); __instance.replace = String.prototype.replace; __instance.replace(true, 1) === "1". Actual: ' + __instance.replace(true, 1)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T10.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T10.js new file mode 100644 index 0000000000..0b021fa5f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T10.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: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T10 +description: > + Call replace (searchValue, replaceValue) function with object and + function arguments of string. Object have overrided toString + function +---*/ + +var __obj = { + toString: function() { + return "\u0041B"; + } +}; + +var __str = "ABB\u0041BABAB"; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__obj, function() { + return x; + }) !== "undefinedBABABAB") { + throw new Test262Error('#1: var x; var __obj = {toString:function(){return "\u0041B";}}; var __str = "ABB\u0041BABAB"; replace(__obj, function(){return x;}) === "undefinedBABABAB". Actual: ' + __str.replace(__obj, function() { + return x; + })); +} +// +////////////////////////////////////////////////////////////////////////////// + +var x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T11.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T11.js new file mode 100644 index 0000000000..0ec448e985 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T11.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: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T11 +description: > + Call replace (searchValue, replaceValue) function with objects + arguments of string object. Objects have overrided toString + function, that throw exception +---*/ + +var __obj = { + toString: function() { + throw "insearchValue"; + } +}; +var __obj2 = { + toString: function() { + throw "inreplaceValue"; + } +}; +var __str = "ABB\u0041BABAB"; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + var x = __str.replace(__obj, __obj2); + throw new Test262Error('#1: "var x = __str.replace(__obj,__obj2)" lead to throwing exception'); +} catch (e) { + if (e !== "insearchValue") { + throw new Test262Error('#1.1: Exception === "insearchValue". Actual: ' + e); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T12.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T12.js new file mode 100644 index 0000000000..43cd91885f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T12.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: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T12 +description: > + Call replace (searchValue, replaceValue) function with objects + arguments of String object. First objects have overrided toString + and valueOf functions, valueOf throw exception. Second objects + have overrided toString function, that throw exception +---*/ + +var __obj = { + toString: function() { + return {}; + }, + valueOf: function() { + throw "insearchValue"; + } +}; +var __obj2 = { + toString: function() { + throw "inreplaceValue"; + } +}; +var __str = new String("ABB\u0041BABAB"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + var x = __str.replace(__obj, __obj2); + throw new Test262Error('#1: "var x = __str.replace(__obj,__obj2)" lead to throwing exception'); +} catch (e) { + if (e !== "insearchValue") { + throw new Test262Error('#1.1: Exception === "insearchValue". Actual: ' + e); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T13.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T13.js new file mode 100644 index 0000000000..1a98a4191a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T13.js @@ -0,0 +1,41 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T13 +description: > + Call replace (searchValue, replaceValue) function with objects + arguments of string. First objects have overrided toString and + valueOf functions. Second objects have overrided toString + function, that throw exception +---*/ + +var __obj = { + toString: function() { + return {}; + }, + valueOf: function() { + return 1; + } +}; +var __obj2 = { + toString: function() { + throw "inreplaceValue"; + } +}; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + var x = "ABB\u0041BABAB\u0031BBAA".replace(__obj, __obj2); + throw new Test262Error('#1: var x = "ABB\\u0041BABAB\\u0031BBAA".replace(__obj,__obj2) lead to throwing exception'); +} catch (e) { + if (e !== "inreplaceValue") { + throw new Test262Error('#1.1: Exception === "inreplaceValue". Actual: ' + e); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T14.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T14.js new file mode 100644 index 0000000000..e34b2fe7e8 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T14.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: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T14 +description: Instance is string, searchValue is regular expression +---*/ + +var __reg = new RegExp("77"); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if ("ABB\u0041BABAB\u0037\u0037BBAA".replace(__reg, 1) !== "ABBABABAB\u0031BBAA") { + throw new Test262Error('#1: var __reg = new RegExp("77"); "ABB\\u0041BABAB\\u0037\\u0037BBAA".replace(__reg, 1) === "ABBABABAB\\u0031BBAA". Actual: ' + ("ABB\u0041BABAB\u0037\u0037BBAA".replace(__reg, 1))); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T15.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T15.js new file mode 100644 index 0000000000..7f1f20a554 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T15.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T15 +description: Instance is Object, searchValue is regular expression +---*/ + +var __obj = { + toString: function() { + return /77/ + } +}; + +var __instance = new Object(1100.00777001); + +Object.prototype.replace = String.prototype.replace; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + var x = __instance.replace(__obj, 1) === "1100.0017001"; + throw new Test262Error('#1.0: x = __instance.replace(__obj, 1) === "1100.0017001" lead to throwing exception'); +} catch (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error('#1.1: Exception is instance of TypeError. Actual: ' + e); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T16.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T16.js new file mode 100644 index 0000000000..f38a86b388 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T16.js @@ -0,0 +1,39 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T16 +description: Instance is Number, searchValue is regular expression +---*/ + +var __re = /77/; + +var __instance = new Number(1100.00777001); + +Number.prototype.replace = String.prototype.replace; + +var __obj = { + toString: function() { + return function(a1, a2, a3) { + return a2 + "z" + }; + } +} +//__obj = function(a1,a2,a3){return a2+"z"}; + + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +try { + var x = __instance.replace(__re, __obj) === "1100.007z7001"; + throw new Test262Error('#1.0: x = __instance.replace(__obj, 1) === "1100.007z7001" lead to throwing exception'); +} catch (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error('#1.1: Exception is instance of TypeError. Actual: ' + e); + } +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T17.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T17.js new file mode 100644 index 0000000000..2a74db7349 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T17.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.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T17 +description: Instance is String object, searchValue is regular expression +---*/ + +var __re = new RegExp(x, "g"); + +var __instance = String("asdf"); + +var __str = "1"; +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__instance.replace(__re, __str) !== "1a1s1d1f1") { + throw new Test262Error('#1: var x; var __re = new RegExp(x,"g"); __instance = String("asdf"); __str = "1"; __instance.replace(__re, __str) === "1a1s1d1f1". Actual: ' + __instance.replace(__re, __str)); +} +// +////////////////////////////////////////////////////////////////////////////// + +var x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T2.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T2.js new file mode 100644 index 0000000000..7273ab9c74 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T2.js @@ -0,0 +1,30 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T2 +description: > + Argument is function that return boolean, and instance is Boolean + object +---*/ + +var __instance = new Boolean; + +__instance.replace = String.prototype.replace; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__instance.replace(function() { + return false; + }(), x) !== "undefined") { + throw new Test262Error('#1: var x; __instance = new Boolean; __instance.replace = String.prototype.replace; __instance.replace(function(){return false;}(),x) === "undefined". Actual: ' + __instance.replace(function() { + return false; + }(), x)); +} +// +////////////////////////////////////////////////////////////////////////////// + +var x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T4.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T4.js new file mode 100644 index 0000000000..e21689c161 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T4.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.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T4 +description: > + Call replace (searchValue, replaceValue) function with null and + function(a1,a2,a3){return a2+"";} arguments of function object +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (function() { + return "gnulluna" + }().replace(null, function(a1, a2, a3) { + return a2 + ""; + }) !== "g1una") { + throw new Test262Error('#1: function(){return "gnulluna"}().replace(null,function(a1,a2,a3){return a2+"";}) === "g1una". Actual: ' + function() { + return "gnulluna" + }().replace(null, function(a1, a2, a3) { + return a2 + ""; + })); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T5.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T5.js new file mode 100644 index 0000000000..4d7aa0f7ef --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T5.js @@ -0,0 +1,24 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T5 +description: > + Call replace (searchValue, replaceValue) function with null and + Function() arguments of function object +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (function() { + return "gnulluna" + }().replace(null, Function()) !== "gundefineduna") { + throw new Test262Error('#1: function(){return "gnulluna"}().replace(null, Function()) === "gundefineduna". Actual: ' + function() { + return "gnulluna" + }().replace(null, Function())); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T6.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T6.js new file mode 100644 index 0000000000..d5ce769257 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_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.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T6 +description: > + Call replace (searchValue, replaceValue) function with x and + Function("return arguments[1]+42;") arguments of new String + object. x is undefined variable +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (new String("undefined").replace(x, Function("return arguments[1]+42;")) !== "42") { + throw new Test262Error('#1: var x; new String("undefined").replace(x,Function("return arguments[1]+42;")) === "42". Actual: ' + new String("undefined").replace(x, Function("return arguments[1]+42;"))); +} +// +////////////////////////////////////////////////////////////////////////////// + +var x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T7.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T7.js new file mode 100644 index 0000000000..a5071d2fdf --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T7.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: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T7 +description: > + Call replace (searchValue, replaceValue) function with string and + undefined arguments of String object +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (String(void 0).replace("e", undefined) !== "undundefinedfined") { + throw new Test262Error('#1: String(void 0).replace("e",undefined) === "undundefinedfined". Actual: ' + String(void 0).replace("e", undefined)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T8.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T8.js new file mode 100644 index 0000000000..c8749a3d73 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T8.js @@ -0,0 +1,24 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T8 +description: > + Call replace (searchValue, replaceValue) function with regular + expression and void 0 arguments of String object +---*/ + +var __obj = { + toString: function() {} +}; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (String(__obj).replace(/e/g, void 0) !== "undundefinedfinundefinedd") { + throw new Test262Error('#1: __obj = {toString:function(){}}; String(__obj).replace(/e/g,void 0) === "undundefinedfinundefinedd". Actual: ' + String(__obj).replace(/e/g, void 0)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T9.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T9.js new file mode 100644 index 0000000000..cfa8895ebe --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A1_T9.js @@ -0,0 +1,29 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.replace (searchValue, replaceValue) +es5id: 15.5.4.11_A1_T9 +description: > + Call replace (searchValue, replaceValue) function with functions + arguments of new String object +---*/ + +var __obj = { + valueOf: function() {}, + toString: void 0 +}; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (new String(__obj).replace(function() {}(), __func) !== "undefined0undefined") { + throw new Test262Error('#1: __obj = {valueOf:function(){}, toString:void 0}; function __func(a1,a2,a3){return a1+a2+a3;}; new String(__obj).replace(function(){}(),__func) === "undefined0undefined". Actual: ' + new String(__obj).replace(function() {}(), __func)); +} +// +////////////////////////////////////////////////////////////////////////////// + +function __func(a1, a2, a3) { + return a1 + a2 + a3; +}; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T1.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T1.js new file mode 100644 index 0000000000..4e617aa030 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T1.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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T1 +description: > + Don`t use $ in replaceValue, searchValue is regular expression + /sh/g +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/g; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, 'sch') !== 'She sells seaschells by the seaschore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/g; __str.replace(__re,\'sch\')===\'She sells seaschells by the seaschore.\'. Actual: ' + __str.replace(__re, 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T10.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T10.js new file mode 100644 index 0000000000..c1edeff76c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T10.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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T10 +description: Use $' in replaceValue, searchValue is regular expression /sh/ +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$'" + 'sch') !== 'She sells seaells by the seashore.schells by the seashore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/; __str.replace(__re, "$\'" + \'sch\')===\'She sells seaells by the seashore.schells by the seashore.\'. Actual: ' + __str.replace(__re, "$'" + 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T2.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T2.js new file mode 100644 index 0000000000..276487a71e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T2.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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T2 +description: Use $$ in replaceValue, searchValue is regular expression /sh/g +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/g; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$$" + 'sch') !== 'She sells sea$schells by the sea$schore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/g; __str.replace(__re,"$$" + \'sch\')===\'She sells sea$schells by the sea$schore.\'. Actual: ' + __str.replace(__re, "$$" + 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T3.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T3.js new file mode 100644 index 0000000000..89c8a6a111 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T3.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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T3 +description: Use $& in replaceValue, searchValue is regular expression /sh/g +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/g; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$&" + 'sch') !== 'She sells seashschells by the seashschore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/g; __str.replace(__re,"$&" + \'sch\')===\'She sells seashschells by the seashschore.\'. Actual: ' + __str.replace(__re, "$&" + 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T4.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T4.js new file mode 100644 index 0000000000..b019004f21 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T4.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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T4 +description: Use $` in replaceValue, searchValue is regular expression /sh/g +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/g; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$`" + 'sch') !== 'She sells seaShe sells seaschells by the seaShe sells seashells by the seaschore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/g; __str.replace(__re, "$`" + \'sch\')===\'She sells seaShe sells seaschells by the seaShe sells seashells by the seaschore.\'. Actual: ' + __str.replace(__re, "$`" + 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T5.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T5.js new file mode 100644 index 0000000000..2c4cf32b97 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T5.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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T5 +description: Use $' in replaceValue, searchValue is regular expression /sh/g +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/g; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$'" + 'sch') !== 'She sells seaells by the seashore.schells by the seaore.schore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/g; __str.replace(__re, "$\'" + \'sch\')===\'She sells seaells by the seashore.schells by the seaore.schore.\'. Actual: ' + __str.replace(__re, "$'" + 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T6.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T6.js new file mode 100644 index 0000000000..668ae4a876 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T6 +description: Don`t use $ in replaceValue, searchValue is regular expression /sh/ +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, 'sch') !== 'She sells seaschells by the seashore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/; __str.replace(__re, \'sch\')===\'She sells seaschells by the seashore.\'. Actual: ' + __str.replace(__re, 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T7.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T7.js new file mode 100644 index 0000000000..7d50ab0f8b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T7.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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T7 +description: Use $$ in replaceValue, searchValue is regular expression /sh/ +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$$" + 'sch') !== 'She sells sea$schells by the seashore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/; __str.replace(__re, "$$" + \'sch\')===\'She sells sea$schells by the seashore.\'. Actual: ' + __str.replace(__re, "$$" + 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T8.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T8.js new file mode 100644 index 0000000000..f2611147b1 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T8.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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T8 +description: Use $& in replaceValue, searchValue is regular expression /sh/ +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$&" + 'sch') !== 'She sells seashschells by the seashore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/; __str.replace(__re, "$&" + \'sch\')===\'She sells seashschells by the seashore.\'. Actual: ' + __str.replace(__re, "$&" + 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T9.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T9.js new file mode 100644 index 0000000000..839d8f02fe --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A2_T9.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: | + The $ replacements are done left-to-right, and, once such are placement is performed, the new + replacement text is not subject to further replacements +es5id: 15.5.4.11_A2_T9 +description: Use $` in replaceValue, searchValue is regular expression /sh/ +---*/ + +var __str = 'She sells seashells by the seashore.'; +var __re = /sh/; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$`" + 'sch') !== 'She sells seaShe sells seaschells by the seashore.') { + throw new Test262Error('#1: var __str = \'She sells seashells by the seashore.\'; var __re = /sh/; __str.replace(__re, "$`" + \'sch\')===\'She sells seaShe sells seaschells by the seashore.\'. Actual: ' + __str.replace(__re, "$`" + 'sch')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A3_T1.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A3_T1.js new file mode 100644 index 0000000000..56a378494c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A3_T1.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: replace with regexp /(uid=)(\d+)/ returns +es5id: 15.5.4.11_A3_T1 +description: replaceValue is "$11" + 15 +---*/ + +var __str = 'uid=31'; +var __re = /(uid=)(\d+)/; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$11" + 15) !== 'uid=115') { + throw new Test262Error('#1: var __str = \'uid=31\'; var __re = /(uid=)(\d+)/; __str.replace(__re, "$11" + 15)===\'uid=115\'. Actual: ' + __str.replace(__re, "$11" + 15)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A3_T2.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A3_T2.js new file mode 100644 index 0000000000..0eb7fd3d83 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A3_T2.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: replace with regexp /(uid=)(\d+)/ returns +es5id: 15.5.4.11_A3_T2 +description: replaceValue is "$11" + '15' +---*/ + +var __str = 'uid=31'; +var __re = /(uid=)(\d+)/; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$11" + '15') !== 'uid=115') { + throw new Test262Error('#1: var __str = \'uid=31\'; var __re = /(uid=)(\d+)/; __str.replace(__re, "$11" + \'15\')===\'uid=115\'. Actual: ' + __str.replace(__re, "$11" + '15')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A3_T3.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A3_T3.js new file mode 100644 index 0000000000..d8abc13544 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A3_T3.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: replace with regexp /(uid=)(\d+)/ returns +es5id: 15.5.4.11_A3_T3 +description: replaceValue is "$11" + 'A15' +---*/ + +var __str = 'uid=31'; +var __re = /(uid=)(\d+)/; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__re, "$11" + 'A15') !== 'uid=1A15') { + throw new Test262Error('#1: var __str = \'uid=31\'; var __re = /(uid=)(\d+)/; __str.replace(__re, "$11" + \'A15\')===\'uid=1A15\' . Actual: ' + __str.replace(__re, "$11" + 'A15')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T1.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T1.js new file mode 100644 index 0000000000..968f54808e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T1.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: replace with regexp /([a-z]+)([0-9]+)/ and replace function returns +es5id: 15.5.4.11_A4_T1 +description: searchValue is /([a-z]+)([0-9]+)/ +---*/ + +var __str = "abc12 def34"; +var __pattern = /([a-z]+)([0-9]+)/; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__pattern, __replFN) !== '12abc def34') { + throw new Test262Error('#1: var __str = "abc12 def34"; var __pattern = /([a-z]+)([0-9]+)/; function __replFN() {return arguments[2] + arguments[1];}; __str.replace(__pattern, __replFN)===\'12abc def34\'. Actual: ' + __str.replace(__pattern, __replFN)); +} +// +////////////////////////////////////////////////////////////////////////////// + +function __replFN() { + return arguments[2] + arguments[1]; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T2.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T2.js new file mode 100644 index 0000000000..35e33a7158 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T2.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: replace with regexp /([a-z]+)([0-9]+)/ and replace function returns +es5id: 15.5.4.11_A4_T2 +description: searchValue is /([a-z]+)([0-9]+)/g +---*/ + +var __str = "abc12 def34"; +var __pattern = /([a-z]+)([0-9]+)/g; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__pattern, __replFN) !== '12abc 34def') { + throw new Test262Error('#1: var __str = "abc12 def34"; var __pattern = /([a-z]+)([0-9]+)/g; function __replFN() {return arguments[2] + arguments[1];}; __str.replace(__pattern, __replFN)===\'12abc 34def\'. Actual: ' + __str.replace(__pattern, __replFN)); +} +// +////////////////////////////////////////////////////////////////////////////// + +function __replFN() { + return arguments[2] + arguments[1]; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T3.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T3.js new file mode 100644 index 0000000000..8dbcb0a9e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T3.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: replace with regexp /([a-z]+)([0-9]+)/ and replace function returns +es5id: 15.5.4.11_A4_T3 +description: searchValue is /([a-z]+)([0-9]+)/i +---*/ + +var __str = "aBc12 def34"; +var __pattern = /([a-z]+)([0-9]+)/i; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__pattern, __replFN) !== '12aBc def34') { + throw new Test262Error('#1: var __str = "aBc12 def34"; var __pattern = /([a-z]+)([0-9]+)/i; function __replFN() {return arguments[2] + arguments[1];}; __str.replace(__pattern, __replFN)===\'12aBc def34\'. Actual: ' + __str.replace(__pattern, __replFN)); +} +// +////////////////////////////////////////////////////////////////////////////// + +function __replFN() { + return arguments[2] + arguments[1]; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T4.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T4.js new file mode 100644 index 0000000000..c6527a9bad --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A4_T4.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: replace with regexp /([a-z]+)([0-9]+)/ and replace function returns +es5id: 15.5.4.11_A4_T4 +description: searchValue is /([a-z]+)([0-9]+)/ig +---*/ + +var __str = "aBc12 dEf34"; +var __pattern = /([a-z]+)([0-9]+)/ig; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__pattern, __replFN) !== '12aBc 34dEf') { + throw new Test262Error('#1: var __str = "aBc12 dEf34"; var __pattern = /([a-z]+)([0-9]+)/ig; function __replFN() {return arguments[2] + arguments[1];}; __str.replace(__pattern, __replFN)===\'12aBc 34dEf\'. Actual: ' + __str.replace(__pattern, __replFN)); +} +// +////////////////////////////////////////////////////////////////////////////// + +function __replFN() { + return arguments[2] + arguments[1]; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A5_T1.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A5_T1.js new file mode 100644 index 0000000000..491d0ae818 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_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: Use replace with regexp as searchValue and use $ in replaceValue +es5id: 15.5.4.11_A5_T1 +description: searchValue is regexp /^(a+)\1*,\1+$/ and replaceValue is "$1" +---*/ + +var __str = "aaaaaaaaaa,aaaaaaaaaaaaaaa"; +var __pattern = /^(a+)\1*,\1+$/; +var __repl = "$1"; + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (__str.replace(__pattern, __repl) !== 'aaaaa') { + throw new Test262Error('#1: var __str = "aaaaaaaaaa,aaaaaaaaaaaaaaa"; var __pattern = /^(a+)\\1*,\\1+$/; var __repl = "$1"; __str.replace(__pattern, __repl)===\'aaaaa\'. Actual: ' + __str.replace(__pattern, __repl)); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A6.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A6.js new file mode 100644 index 0000000000..f5f167a1fb --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_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.replace has not prototype property +es5id: 15.5.4.11_A6 +description: Checking String.prototype.replace.prototype; +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (String.prototype.replace.prototype !== undefined) { + throw new Test262Error('#1: String.prototype.replace.prototype === undefined. Actual: ' + String.prototype.replace.prototype); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A7.js b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A7.js new file mode 100644 index 0000000000..af06d225d7 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/S15.5.4.11_A7.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.replace can't be used as constructor +es5id: 15.5.4.11_A7 +description: Checking if creating the String.prototype.replace object fails +---*/ + +var __FACTORY = String.prototype.replace; + +try { + var __instance = new __FACTORY; + throw new Test262Error('#1: __FACTORY = String.prototype.replace; "__instance = new __FACTORY" lead to throwing exception'); +} catch (e) { + if (e instanceof Test262Error) throw e; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/browser.js b/js/src/tests/test262/built-ins/String/prototype/replace/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/cstm-replace-get-err.js b/js/src/tests/test262/built-ins/String/prototype/replace/cstm-replace-get-err.js new file mode 100644 index 0000000000..bad72b1bbc --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/cstm-replace-get-err.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Behavior when error is thrown accessing @@replace property +es6id: 21.1.3.14 +info: | + [...] + 3. If searchValue is neither undefined nor null, then + a. Let replacer be GetMethod(searchValue, @@replace). + b. ReturnIfAbrupt(replacer). +features: [Symbol.replace] +---*/ + +var poisonedReplace = {}; +Object.defineProperty(poisonedReplace, Symbol.replace, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + ''.replace(poisonedReplace); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/cstm-replace-invocation.js b/js/src/tests/test262/built-ins/String/prototype/replace/cstm-replace-invocation.js new file mode 100644 index 0000000000..bde2b7ee0b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/cstm-replace-invocation.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Invocation of @@replace property of user-supplied objects +es6id: 21.1.3.14 +info: | + [...] + 3. If searchValue is neither undefined nor null, then + a. Let replacer be GetMethod(searchValue, @@replace). + b. ReturnIfAbrupt(replacer). + c. If replacer is not undefined, then + i. Return Call(replacer, searchValue, «O, replaceValue»). +features: [Symbol.replace] +---*/ + +var searchValue = {}; +var returnVal = {}; +var callCount = 0; +var thisVal, args; + +searchValue[Symbol.replace] = function() { + callCount += 1; + thisVal = this; + args = arguments; + return returnVal; +}; + +assert.sameValue(''.replace(searchValue, 'replace value'), returnVal); +assert.sameValue(thisVal, searchValue); +assert.notSameValue(args, undefined); +assert.sameValue(args.length, 2); +assert.sameValue(args[0], ''); +assert.sameValue(args[1], 'replace value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/cstm-replace-is-null.js b/js/src/tests/test262/built-ins/String/prototype/replace/cstm-replace-is-null.js new file mode 100644 index 0000000000..2654ed83bf --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/cstm-replace-is-null.js @@ -0,0 +1,36 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replace +description: > + If searchValue's Symbol.replace property is null, no error is thrown. +info: | + String.prototype.replace ( searchValue, replaceValue ) + + [...] + 2. If searchValue is neither undefined nor null, then + a. Let replacer be ? GetMethod(searchValue, @@replace). + b. If replacer is not undefined, then + [...] + [...] + 12. Return newString. + + GetMethod ( V, P ) + + [...] + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. +features: [Symbol.replace] +---*/ + +var searchValue = {}; +searchValue[Symbol.replace] = null; +searchValue.toString = function() { return "3"; }; +searchValue.valueOf = function() { throw new Test262Error("should not be called"); }; + +var replacer = function() { return "<foo>"; }; +assert.sameValue("ab3c".replace(searchValue, replacer), "ab<foo>c"); +assert.sameValue("ab3c".replace(searchValue, "<foo>"), "ab<foo>c"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/length.js b/js/src/tests/test262/built-ins/String/prototype/replace/length.js new file mode 100644 index 0000000000..9146fd1fcb --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replace +description: > + String.prototype.replace.length is 2. +info: | + String.prototype.replace ( searchValue, replaceValue ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype.replace, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/name.js b/js/src/tests/test262/built-ins/String/prototype/replace/name.js new file mode 100644 index 0000000000..7e783a3585 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/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.14 +description: > + String.prototype.replace.name is "replace". +info: | + String.prototype.replace (searchValue, replaceValue ) + + 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.replace.name, "replace"); + +verifyNotEnumerable(String.prototype.replace, "name"); +verifyNotWritable(String.prototype.replace, "name"); +verifyConfigurable(String.prototype.replace, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/replace/not-a-constructor.js new file mode 100644 index 0000000000..c28df5ae80 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/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.replace 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.replace), + false, + 'isConstructor(String.prototype.replace) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.replace(); +}, '`new String.prototype.replace()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/replaceValue-evaluation-order-regexp-object.js b/js/src/tests/test262/built-ins/String/prototype/replace/replaceValue-evaluation-order-regexp-object.js new file mode 100644 index 0000000000..1eb0d40aab --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/replaceValue-evaluation-order-regexp-object.js @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replace +description: > + Non-callable replaceValue is evaluated via toString +info: | + String.prototype.replace ( searchValue, replaceValue ) + + If functionalReplace is false, then + Set replaceValue to ? ToString(replaceValue). +---*/ + +let calls = 0; +let replaceValue = /$/; +let oldToString = replaceValue.toString.bind(replaceValue); + +replaceValue.toString = () => { + calls += 1; + return oldToString(); +}; + +let newString = "".replace("a", replaceValue); +assert.sameValue(newString, ""); +assert.sameValue(calls, 1); +assert.sameValue("dollar".replace("dollar", /$/), "/$/"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/replaceValue-evaluation-order.js b/js/src/tests/test262/built-ins/String/prototype/replace/replaceValue-evaluation-order.js new file mode 100644 index 0000000000..aeb45287ba --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/replaceValue-evaluation-order.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replace +description: > + Non-callable replaceValue is evaluated before searching the string. +info: | + String.prototype.replace ( searchValue, replaceValue ) + + ... + 6. If functionalReplace is false, then + a. Set replaceValue to ? ToString(replaceValue). + 7. Search string for the first occurrence of searchString and let pos be the + index within string of the first code unit of the matched substring and let + matched be searchString. If no occurrences of searchString were found, return string. +---*/ + +var calls = 0; +var replaceValue = { + toString: function() { + calls += 1; + return "b"; + }, +}; + +var newString = "".replace("a", replaceValue); +assert.sameValue(newString, ""); +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/shell.js b/js/src/tests/test262/built-ins/String/prototype/replace/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/shell.js diff --git a/js/src/tests/test262/built-ins/String/prototype/replace/this-value-not-obj-coercible.js b/js/src/tests/test262/built-ins/String/prototype/replace/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..50e7dd8457 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/replace/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.replace +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var replace = String.prototype.replace; + +assert.sameValue(typeof replace, 'function'); + +assert.throws(TypeError, function() { + replace.call(undefined, '', ''); +}, 'undefined'); + +assert.throws(TypeError, function() { + replace.call(null, '', ''); +}, 'null'); + +reportCompare(0, 0); |