diff --git a/test/built-ins/String/prototype/match/cstm-matcher-on-bigint-primitive.js b/test/built-ins/String/prototype/match/cstm-matcher-on-bigint-primitive.js new file mode 100644 index 0000000000..7eaa742116 --- /dev/null +++ b/test/built-ins/String/prototype/match/cstm-matcher-on-bigint-primitive.js @@ -0,0 +1,31 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.match +description: > + If a regexp property is a bigint primitive, its Symbol.match property is not accessed. +info: | + String.prototype.match ( regexp ) + + [...] + 2. If regexp is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.match] +---*/ + +Object.defineProperty(BigInt.prototype, Symbol.match, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var separator = 1n; + +const matched = "a1b1c".match(separator); +assert.sameValue(matched.index, 1); +assert.sameValue(matched.input, "a1b1c"); +assert.compareArray(matched, ["1"]); diff --git a/test/built-ins/String/prototype/match/cstm-matcher-on-boolean-primitive.js b/test/built-ins/String/prototype/match/cstm-matcher-on-boolean-primitive.js new file mode 100644 index 0000000000..98cf07a379 --- /dev/null +++ b/test/built-ins/String/prototype/match/cstm-matcher-on-boolean-primitive.js @@ -0,0 +1,31 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.match +description: > + If a regexp property is a boolean primitive, its Symbol.match property is not accessed. +info: | + String.prototype.match ( regexp ) + + [...] + 2. If regexp is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.match] +---*/ + +Object.defineProperty(Boolean.prototype, Symbol.match, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var separator = true; + +const matched = "atruebtruec".match(separator); +assert.sameValue(matched.index, 1); +assert.sameValue(matched.input, "atruebtruec"); +assert.compareArray(matched, ["true"]); diff --git a/test/built-ins/String/prototype/match/cstm-matcher-on-number-primitive.js b/test/built-ins/String/prototype/match/cstm-matcher-on-number-primitive.js new file mode 100644 index 0000000000..0cdd72f6bb --- /dev/null +++ b/test/built-ins/String/prototype/match/cstm-matcher-on-number-primitive.js @@ -0,0 +1,31 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.match +description: > + If a regexp property is a number primitive, its Symbol.match property is not accessed. +info: | + String.prototype.match ( regexp ) + + [...] + 2. If regexp is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.match] +---*/ + +Object.defineProperty(Number.prototype, Symbol.match, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var separator = 1; + +const matched = "a1b1c".match(separator); +assert.sameValue(matched.index, 1); +assert.sameValue(matched.input, "a1b1c"); +assert.compareArray(matched, ["1"]); diff --git a/test/built-ins/String/prototype/match/cstm-matcher-on-string-primitive.js b/test/built-ins/String/prototype/match/cstm-matcher-on-string-primitive.js new file mode 100644 index 0000000000..9cfb2b97e4 --- /dev/null +++ b/test/built-ins/String/prototype/match/cstm-matcher-on-string-primitive.js @@ -0,0 +1,31 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.match +description: > + If a regexp property is a string primitive, its Symbol.match property is not accessed. +info: | + String.prototype.match ( regexp ) + + [...] + 2. If regexp is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.match] +---*/ + +Object.defineProperty(String.prototype, Symbol.match, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var separator = ","; + +const matched = "a,b,c".match(separator); +assert.sameValue(matched.index, 1); +assert.sameValue(matched.input, "a,b,c"); +assert.compareArray(matched, [","]); diff --git a/test/built-ins/String/prototype/matchAll/cstm-matchall-on-bigint-primitive.js b/test/built-ins/String/prototype/matchAll/cstm-matchall-on-bigint-primitive.js new file mode 100644 index 0000000000..d573a0bf90 --- /dev/null +++ b/test/built-ins/String/prototype/matchAll/cstm-matchall-on-bigint-primitive.js @@ -0,0 +1,36 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.matchall +description: > + If a regexp property is a bigint primitive, its Symbol.matchAll property is not accessed. +info: | + String.prototype.matchAll ( regexp ) + + [...] + 2. If regexp is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.matchAll] +---*/ + +Object.defineProperty(BigInt.prototype, Symbol.matchAll, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var matcher = 1n; + +const matched = "a1b1c".matchAll(matcher); +const matchesArray = Array.from(matched); +assert.sameValue(matchesArray[0].index, 1); +assert.sameValue(matchesArray[0].input, "a1b1c"); +assert.compareArray(matchesArray[0], ["1"]); +assert.sameValue(matchesArray[1].index, 3); +assert.sameValue(matchesArray[1].input, "a1b1c"); +assert.compareArray(matchesArray[1], ["1"]); +assert.sameValue(matchesArray.length, 2); diff --git a/test/built-ins/String/prototype/matchAll/cstm-matchall-on-boolean-primitive.js b/test/built-ins/String/prototype/matchAll/cstm-matchall-on-boolean-primitive.js new file mode 100644 index 0000000000..6756f5df7d --- /dev/null +++ b/test/built-ins/String/prototype/matchAll/cstm-matchall-on-boolean-primitive.js @@ -0,0 +1,36 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.matchall +description: > + If a regexp property is a boolean primitive, its Symbol.matchAll property is not accessed. +info: | + String.prototype.matchAll ( regexp ) + + [...] + 2. If regexp is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.matchAll] +---*/ + +Object.defineProperty(Boolean.prototype, Symbol.match, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var matcher = true; + +const matched = "atruebtruec".matchAll(matcher); +const matchesArray = Array.from(matched); +assert.sameValue(matchesArray[0].index, 1); +assert.sameValue(matchesArray[0].input, "atruebtruec"); +assert.compareArray(matchesArray[0], ["true"]); +assert.sameValue(matchesArray[1].index, 6); +assert.sameValue(matchesArray[1].input, "atruebtruec"); +assert.compareArray(matchesArray[1], ["true"]); +assert.sameValue(matchesArray.length, 2); diff --git a/test/built-ins/String/prototype/matchAll/cstm-matchall-on-number-primitive.js b/test/built-ins/String/prototype/matchAll/cstm-matchall-on-number-primitive.js new file mode 100644 index 0000000000..38d31ef49e --- /dev/null +++ b/test/built-ins/String/prototype/matchAll/cstm-matchall-on-number-primitive.js @@ -0,0 +1,36 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.matchall +description: > + If a regexp property is a number primitive, its Symbol.matchAll property is not accessed. +info: | + String.prototype.matchAll ( regexp ) + + [...] + 2. If regexp is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.matchAll] +---*/ + +Object.defineProperty(Number.prototype, Symbol.matchAll, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var matcher = 1; + +const matched = "a1b1c".matchAll(matcher); +const matchesArray = Array.from(matched); +assert.sameValue(matchesArray[0].index, 1); +assert.sameValue(matchesArray[0].input, "a1b1c"); +assert.compareArray(matchesArray[0], ["1"]); +assert.sameValue(matchesArray[1].index, 3); +assert.sameValue(matchesArray[1].input, "a1b1c"); +assert.compareArray(matchesArray[1], ["1"]); +assert.sameValue(matchesArray.length, 2); diff --git a/test/built-ins/String/prototype/matchAll/cstm-matchall-on-string-primitive.js b/test/built-ins/String/prototype/matchAll/cstm-matchall-on-string-primitive.js new file mode 100644 index 0000000000..52c02724cf --- /dev/null +++ b/test/built-ins/String/prototype/matchAll/cstm-matchall-on-string-primitive.js @@ -0,0 +1,36 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.matchall +description: > + If a regexp property is a string primitive, its Symbol.matchAll property is not accessed. +info: | + String.prototype.matchAll ( regexp ) + + [...] + 2. If regexp is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.matchAll] +---*/ + +Object.defineProperty(String.prototype, Symbol.matchAll, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var matcher = ","; + +const matched = "a,b,c".matchAll(matcher); +const matchesArray = Array.from(matched); +assert.sameValue(matchesArray[0].index, 1); +assert.sameValue(matchesArray[0].input, "a,b,c"); +assert.compareArray(matchesArray[0], [","]); +assert.sameValue(matchesArray[1].index, 3); +assert.sameValue(matchesArray[1].input, "a,b,c"); +assert.compareArray(matchesArray[1], [","]); +assert.sameValue(matchesArray.length, 2); diff --git a/test/built-ins/String/prototype/replace/cstm-replace-on-bigint-primitive.js b/test/built-ins/String/prototype/replace/cstm-replace-on-bigint-primitive.js new file mode 100644 index 0000000000..b309e75fca --- /dev/null +++ b/test/built-ins/String/prototype/replace/cstm-replace-on-bigint-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replace +description: > + If a searchValue is a bigint primitive, its Symbol.replace property is not accessed. +info: | + String.prototype.replace ( searchValue, replaceValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.replace] +---*/ + +Object.defineProperty(BigInt.prototype, Symbol.replace, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = 1n; + +const replaced = "a1b1c".replace(searchValue, "X"); +assert.sameValue(replaced, "aXb1c"); diff --git a/test/built-ins/String/prototype/replace/cstm-replace-on-boolean-primitive.js b/test/built-ins/String/prototype/replace/cstm-replace-on-boolean-primitive.js new file mode 100644 index 0000000000..ae1ea4b6f2 --- /dev/null +++ b/test/built-ins/String/prototype/replace/cstm-replace-on-boolean-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replace +description: > + If a searchValue is a boolean primitive, its Symbol.replace property is not accessed. +info: | + String.prototype.replace ( searchValue, replaceValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.replace] +---*/ + +Object.defineProperty(Boolean.prototype, Symbol.replace, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = true; + +const replaced = "atruebtruec".replace(searchValue, "X"); +assert.sameValue(replaced, "aXbtruec"); diff --git a/test/built-ins/String/prototype/replace/cstm-replace-on-number-primitive.js b/test/built-ins/String/prototype/replace/cstm-replace-on-number-primitive.js new file mode 100644 index 0000000000..03446c0441 --- /dev/null +++ b/test/built-ins/String/prototype/replace/cstm-replace-on-number-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replace +description: > + If a searchValue is a number primitive, its Symbol.replace property is not accessed. +info: | + String.prototype.replace ( searchValue, replaceValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.replace] +---*/ + +Object.defineProperty(Number.prototype, Symbol.replace, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = 1; + +const replaced = "a1b1c".replace(searchValue, "X"); +assert.sameValue(replaced, "aXb1c"); diff --git a/test/built-ins/String/prototype/replace/cstm-replace-on-string-primitive.js b/test/built-ins/String/prototype/replace/cstm-replace-on-string-primitive.js new file mode 100644 index 0000000000..53e1512f7a --- /dev/null +++ b/test/built-ins/String/prototype/replace/cstm-replace-on-string-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replace +description: > + If a searchValue is a string primitive, its Symbol.replace property is not accessed. +info: | + String.prototype.replace ( searchValue, replaceValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.replace] +---*/ + +Object.defineProperty(String.prototype, Symbol.replace, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = ","; + +const replaced = "a,b,c".replace(searchValue, "X"); +assert.sameValue(replaced, "aXb,c"); diff --git a/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-bigint-primitive.js b/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-bigint-primitive.js new file mode 100644 index 0000000000..2399931a42 --- /dev/null +++ b/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-bigint-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replaceall +description: > + If a searchValue is a bigint primitive, its Symbol.replace property is not accessed. +info: | + String.prototype.replaceAll ( searchValue, replaceValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.replace] +---*/ + +Object.defineProperty(BigInt.prototype, Symbol.replace, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = 1n; + +const replaced = "a1b1c".replaceAll(searchValue, "X"); +assert.sameValue(replaced, "aXbXc"); diff --git a/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-boolean-primitive.js b/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-boolean-primitive.js new file mode 100644 index 0000000000..b69369840b --- /dev/null +++ b/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-boolean-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replaceall +description: > + If a searchValue is a boolean primitive, its Symbol.replace property is not accessed. +info: | + String.prototype.replaceAll ( searchValue, replaceValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.replace] +---*/ + +Object.defineProperty(Boolean.prototype, Symbol.replace, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = true; + +const replaced = "atruebtruec".replaceAll(searchValue, "X"); +assert.sameValue(replaced, "aXbXc"); diff --git a/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-number-primitive.js b/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-number-primitive.js new file mode 100644 index 0000000000..7b152c2532 --- /dev/null +++ b/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-number-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replaceall +description: > + If a searchValue is a number primitive, its Symbol.replace property is not accessed. +info: | + String.prototype.replaceAll ( searchValue, replaceValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.replace] +---*/ + +Object.defineProperty(Number.prototype, Symbol.replace, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = 1; + +const replaced = "a1b1c".replaceAll(searchValue, "X"); +assert.sameValue(replaced, "aXbXc"); diff --git a/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-string-primitive.js b/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-string-primitive.js new file mode 100644 index 0000000000..236df5a9d8 --- /dev/null +++ b/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-string-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.replaceall +description: > + If a searchValue is a string primitive, its Symbol.replace property is not accessed. +info: | + String.prototype.replaceAll ( searchValue, replaceValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.replace] +---*/ + +Object.defineProperty(String.prototype, Symbol.replace, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = ","; + +const replaced = "a,b,c".replaceAll(searchValue, "X"); +assert.sameValue(replaced, "aXbXc"); diff --git a/test/built-ins/String/prototype/search/cstm-search-on-bigint-primitive.js b/test/built-ins/String/prototype/search/cstm-search-on-bigint-primitive.js new file mode 100644 index 0000000000..a9b920378b --- /dev/null +++ b/test/built-ins/String/prototype/search/cstm-search-on-bigint-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.search +description: > + If a searchValue is a bigint primitive, its Symbol.search property is not accessed. +info: | + String.prototype.search ( searchValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.search] +---*/ + +Object.defineProperty(BigInt.prototype, Symbol.search, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = 1n; + +const searched = "a1b1c".search(searchValue); +assert.sameValue(searched, 1); diff --git a/test/built-ins/String/prototype/search/cstm-search-on-boolean-primitive.js b/test/built-ins/String/prototype/search/cstm-search-on-boolean-primitive.js new file mode 100644 index 0000000000..be2eb07d60 --- /dev/null +++ b/test/built-ins/String/prototype/search/cstm-search-on-boolean-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.search +description: > + If a searchValue is a boolean primitive, its Symbol.search property is not accessed. +info: | + String.prototype.search ( searchValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.search] +---*/ + +Object.defineProperty(Boolean.prototype, Symbol.search, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = true; + +const searched = "atruebtruec".search(searchValue); +assert.sameValue(searched, 1); diff --git a/test/built-ins/String/prototype/search/cstm-search-on-number-primitive.js b/test/built-ins/String/prototype/search/cstm-search-on-number-primitive.js new file mode 100644 index 0000000000..bd3d017d2e --- /dev/null +++ b/test/built-ins/String/prototype/search/cstm-search-on-number-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.search +description: > + If a searchValue is a number primitive, its Symbol.search property is not accessed. +info: | + String.prototype.search ( searchValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.search] +---*/ + +Object.defineProperty(Number.prototype, Symbol.search, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = 1; + +const searched = "a1b1c".search(searchValue); +assert.sameValue(searched, 1); diff --git a/test/built-ins/String/prototype/search/cstm-search-on-string-primitive.js b/test/built-ins/String/prototype/search/cstm-search-on-string-primitive.js new file mode 100644 index 0000000000..1db9223f20 --- /dev/null +++ b/test/built-ins/String/prototype/search/cstm-search-on-string-primitive.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.search +description: > + If a searchValue is a string primitive, its Symbol.search property is not accessed. +info: | + String.prototype.search ( searchValue ) + + [...] + 2. If searchValue is not Object, then + [...] + [...] + +features: [Symbol.search] +---*/ + +Object.defineProperty(String.prototype, Symbol.search, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var searchValue = ","; + +const searched = "a,b,c".search(searchValue); +assert.sameValue(searched, 1); diff --git a/test/built-ins/String/prototype/split/cstm-split-on-bigint-primitive.js b/test/built-ins/String/prototype/split/cstm-split-on-bigint-primitive.js new file mode 100644 index 0000000000..54099121a3 --- /dev/null +++ b/test/built-ins/String/prototype/split/cstm-split-on-bigint-primitive.js @@ -0,0 +1,29 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.split +description: > + If a separator is a bigint primitive, its Symbol.split property is not accessed. +info: | + String.prototype.split ( separator, limit ) + + [...] + 2. If separator is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.split] +---*/ + +Object.defineProperty(BigInt.prototype, Symbol.split, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var separator = 1n; + +assert.compareArray("a1b1c".split(separator), ["a", "b", "c"]); +assert.compareArray("a1b1c".split(separator, 1), ["a"]); diff --git a/test/built-ins/String/prototype/split/cstm-split-on-boolean-primitive.js b/test/built-ins/String/prototype/split/cstm-split-on-boolean-primitive.js new file mode 100644 index 0000000000..2e5671d22a --- /dev/null +++ b/test/built-ins/String/prototype/split/cstm-split-on-boolean-primitive.js @@ -0,0 +1,29 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.split +description: > + If a separator is a boolean primitive, its Symbol.split property is not accessed. +info: | + String.prototype.split ( separator, limit ) + + [...] + 2. If separator is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.split] +---*/ + +Object.defineProperty(Boolean.prototype, Symbol.split, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var separator = true; + +assert.compareArray("atruebtruec".split(separator), ["a", "b", "c"]); +assert.compareArray("atruebtruec".split(separator, 1), ["a"]); diff --git a/test/built-ins/String/prototype/split/cstm-split-on-number-primitive.js b/test/built-ins/String/prototype/split/cstm-split-on-number-primitive.js new file mode 100644 index 0000000000..09559d230c --- /dev/null +++ b/test/built-ins/String/prototype/split/cstm-split-on-number-primitive.js @@ -0,0 +1,29 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.split +description: > + If a separator is a number primitive, its Symbol.split property is not accessed. +info: | + String.prototype.split ( separator, limit ) + + [...] + 2. If separator is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.split] +---*/ + +Object.defineProperty(Number.prototype, Symbol.split, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var separator = 1; + +assert.compareArray("a1b1c".split(separator), ["a", "b", "c"]); +assert.compareArray("a1b1c".split(separator, 1), ["a"]); diff --git a/test/built-ins/String/prototype/split/cstm-split-on-string-primitive.js b/test/built-ins/String/prototype/split/cstm-split-on-string-primitive.js new file mode 100644 index 0000000000..021e6d0c9f --- /dev/null +++ b/test/built-ins/String/prototype/split/cstm-split-on-string-primitive.js @@ -0,0 +1,29 @@ +// Copyright (C) 2025 Luca Casonato. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.split +description: > + If a separator is a string primitive, its Symbol.split property is not accessed. +info: | + String.prototype.split ( separator, limit ) + + [...] + 2. If separator is not Object, then + [...] + [...] + +includes: [compareArray.js] +features: [Symbol.split] +---*/ + +Object.defineProperty(String.prototype, Symbol.split, { + get: function() { + throw new Test262Error("should not be called"); + }, +}); + +var separator = ","; + +assert.compareArray("a,b,c".split(separator), ["a", "b", "c"]); +assert.compareArray("a,b,c".split(separator, 1), ["a"]);