Bug 1290655 - Call GetMethod in String.prototype.{search,replace,split}. r=evilpie
authorTooru Fujisawa <arai_a@mac.com>
Sun, 31 Jul 2016 11:04:19 +0900
changeset 349597 d7cca89ce49723337bd50dd04fec86f43096560a
parent 349596 b46b071d48cf7d26edcd077970e1c3445248a171
child 349598 b7dc3515dc78bbb77c1191b4d5d5ee05668fd6cf
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1290655
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1290655 - Call GetMethod in String.prototype.{search,replace,split}. r=evilpie
js/src/builtin/String.js
js/src/tests/ecma_6/String/match-GetMethod.js
js/src/tests/ecma_6/String/replace-GetMethod.js
js/src/tests/ecma_6/String/search-GetMethod.js
js/src/tests/ecma_6/String/split-GetMethod.js
--- a/js/src/builtin/String.js
+++ b/js/src/builtin/String.js
@@ -135,17 +135,17 @@ function String_replace(searchValue, rep
     // Step 1.
     RequireObjectCoercible(this);
 
     // Step 2.
     if (!(typeof searchValue === "string" && StringProtoHasNoReplace()) &&
         searchValue !== undefined && searchValue !== null)
     {
         // Step 2.a.
-        var replacer = searchValue[std_replace];
+        var replacer = GetMethod(searchValue, std_replace);
 
         // Step 2.b.
         if (replacer !== undefined)
             return callContentFunction(replacer, searchValue, this, replaceValue);
     }
 
     // Step 3.
     var string = ToString(this);
@@ -218,17 +218,17 @@ function IsStringSearchOptimizable() {
 function String_search(regexp) {
     // Step 1.
     RequireObjectCoercible(this);
 
     // Step 2.
     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)
             return callContentFunction(searcher, regexp, this);
     }
 
     // Step 3.
     var string = ToString(this);
@@ -280,17 +280,17 @@ function String_split(separator, limit) 
         }
     }
 
     // Step 2.
     if (!(typeof separator == "string" && StringProtoHasNoSplit()) &&
         separator !== undefined && separator !== null)
     {
         // Step 2.a.
-        var splitter = separator[std_split];
+        var splitter = GetMethod(separator, std_split);
 
         // Step 2.b.
         if (splitter !== undefined)
             return callContentFunction(splitter, separator, this, limit);
     }
 
     // Step 3.
     var S = ToString(this);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/String/match-GetMethod.js
@@ -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);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/String/replace-GetMethod.js
@@ -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);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/String/search-GetMethod.js
@@ -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);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/String/split-GetMethod.js
@@ -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);