mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 05:35:31 +00:00
Bug 1290655 - Call GetMethod in String.prototype.{search,replace,split}. r=evilpie
This commit is contained in:
parent
696d9c1a76
commit
4e75fef821
@ -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)
|
||||
|
28
js/src/tests/ecma_6/String/match-GetMethod.js
Normal file
28
js/src/tests/ecma_6/String/match-GetMethod.js
Normal 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);
|
24
js/src/tests/ecma_6/String/replace-GetMethod.js
Normal file
24
js/src/tests/ecma_6/String/replace-GetMethod.js
Normal 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);
|
24
js/src/tests/ecma_6/String/search-GetMethod.js
Normal file
24
js/src/tests/ecma_6/String/search-GetMethod.js
Normal 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);
|
24
js/src/tests/ecma_6/String/split-GetMethod.js
Normal file
24
js/src/tests/ecma_6/String/split-GetMethod.js
Normal 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);
|
Loading…
Reference in New Issue
Block a user