Bug 1290655 - Call GetMethod in String.prototype.{search,replace,split}. r=evilpie

This commit is contained in:
Tooru Fujisawa 2016-07-31 11:04:19 +09:00
parent 696d9c1a76
commit 4e75fef821
5 changed files with 103 additions and 3 deletions

View File

@ -140,7 +140,7 @@ function String_replace(searchValue, replaceValue) {
searchValue !== undefined && searchValue !== null)
{
// Step 2.a.
var replacer = searchValue[std_replace];
var replacer = GetMethod(searchValue, std_replace);
// Step 2.b.
if (replacer !== undefined)
@ -223,7 +223,7 @@ function String_search(regexp) {
var isPatternString = (typeof regexp === "string");
if (!(isPatternString && StringProtoHasNoSearch()) && regexp !== undefined && regexp !== null) {
// Step 2.a.
var searcher = regexp[std_search];
var searcher = GetMethod(regexp, std_search);
// Step 2.b.
if (searcher !== undefined)
@ -285,7 +285,7 @@ function String_split(separator, limit) {
separator !== undefined && separator !== null)
{
// Step 2.a.
var splitter = separator[std_split];
var splitter = GetMethod(separator, std_split);
// Step 2.b.
if (splitter !== undefined)

View File

@ -0,0 +1,28 @@
var BUGNUMBER = 1290655;
var summary = "String.prototype.match should call GetMethod.";
print(BUGNUMBER + ": " + summary);
function create(value) {
return {
[Symbol.match]: value,
toString() {
return "-";
}
};
}
var expected = ["-"];
expected.index = 1;
expected.input = "a-a";
for (let v of [null, undefined]) {
assertDeepEq("a-a".match(create(v)), expected);
}
for (let v of [1, true, Symbol.iterator, "", {}, []]) {
assertThrowsInstanceOf(() => "a-a".match(create(v)), TypeError);
}
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -0,0 +1,24 @@
var BUGNUMBER = 1290655;
var summary = "String.prototype.replace should call GetMethod.";
print(BUGNUMBER + ": " + summary);
function create(value) {
return {
[Symbol.replace]: value,
toString() {
return "-";
}
};
}
for (let v of [null, undefined]) {
assertEq("a-a".replace(create(v), "+"), "a+a");
}
for (let v of [1, true, Symbol.iterator, "", {}, []]) {
assertThrowsInstanceOf(() => "a-a".replace(create(v)), TypeError);
}
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -0,0 +1,24 @@
var BUGNUMBER = 1290655;
var summary = "String.prototype.search should call GetMethod.";
print(BUGNUMBER + ": " + summary);
function create(value) {
return {
[Symbol.search]: value,
toString() {
return "-";
}
};
}
for (let v of [null, undefined]) {
assertEq("a-a".search(create(v)), 1);
}
for (let v of [1, true, Symbol.iterator, "", {}, []]) {
assertThrowsInstanceOf(() => "a-a".search(create(v)), TypeError);
}
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -0,0 +1,24 @@
var BUGNUMBER = 1290655;
var summary = "String.prototype.split should call GetMethod.";
print(BUGNUMBER + ": " + summary);
function create(value) {
return {
[Symbol.split]: value,
toString() {
return "-";
}
};
}
for (let v of [null, undefined]) {
assertDeepEq("a-a".split(create(v)), ["a", "a"]);
}
for (let v of [1, true, Symbol.iterator, "", {}, []]) {
assertThrowsInstanceOf(() => "a-a".split(create(v)), TypeError);
}
if (typeof reportCompare === "function")
reportCompare(true, true);