Add tests for not calling well-known symbols on primitives for string methods (#4404)

* Add tests for not calling WK symbols on primitives for string methods

* clean up tests

* fix info in test files
This commit is contained in:
Luca Casonato 2025-03-12 01:54:04 +01:00 committed by GitHub
parent f250da9bf4
commit abc22b515e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 720 additions and 0 deletions

View File

@ -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"]);

View File

@ -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"]);

View File

@ -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"]);

View File

@ -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, [","]);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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"]);

View File

@ -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"]);

View File

@ -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"]);

View File

@ -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"]);