Title: [198625] trunk/Source/_javascript_Core
Revision
198625
Author
[email protected]
Date
2016-03-24 09:13:46 -0700 (Thu, 24 Mar 2016)

Log Message

[ES6] Add Proxy based tests for RegExp.prototype[@@match]
https://bugs.webkit.org/show_bug.cgi?id=155807

Reviewed by Saam Barati.

Added new test that uses Proxy to verify RegExp.prototype[@@match] processing
conforms to the ES6 standard

Modified builtin RegExp.prototype[@@match] to be ES6 spec conformant.

Updated es6.yaml as Proxy_internal_get_calls_RegExp.prototype[Symbol.match].js now passes.

* builtins/RegExpPrototype.js:
(match):
* tests/es6.yaml: Updated.
* tests/stress/regexp-match-proxy.js: Added.
(assert):
(let.getProxyNullExec.new.Proxy):
(let.getSetProxyNullExec.new.Proxy):
(get resetTracking):
(let.getSetProxyMatches_s.new.Proxy):
(set get getSetProxyNullExec):
(let.getSetProxyMatches_tx_Greedy.new.Proxy):
(set get getSetProxyMatches_s):
(let.getSetProxyMatchesUnicode_digit_nonGreedy.new.Proxy):
(set get getSetProxyMatches_tx_Greedy):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (198624 => 198625)


--- trunk/Source/_javascript_Core/ChangeLog	2016-03-24 14:19:37 UTC (rev 198624)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-03-24 16:13:46 UTC (rev 198625)
@@ -1,5 +1,34 @@
 2016-03-24  Michael Saboff  <[email protected]>
 
+        [ES6] Add Proxy based tests for RegExp.prototype[@@match]
+        https://bugs.webkit.org/show_bug.cgi?id=155807
+
+        Reviewed by Saam Barati.
+
+        Added new test that uses Proxy to verify RegExp.prototype[@@match] processing
+        conforms to the ES6 standard
+
+        Modified builtin RegExp.prototype[@@match] to be ES6 spec conformant.
+
+        Updated es6.yaml as Proxy_internal_get_calls_RegExp.prototype[Symbol.match].js now passes.
+
+        * builtins/RegExpPrototype.js:
+        (match):
+        * tests/es6.yaml: Updated.
+        * tests/stress/regexp-match-proxy.js: Added.
+        (assert):
+        (let.getProxyNullExec.new.Proxy):
+        (let.getSetProxyNullExec.new.Proxy):
+        (get resetTracking):
+        (let.getSetProxyMatches_s.new.Proxy):
+        (set get getSetProxyNullExec):
+        (let.getSetProxyMatches_tx_Greedy.new.Proxy):
+        (set get getSetProxyMatches_s):
+        (let.getSetProxyMatchesUnicode_digit_nonGreedy.new.Proxy):
+        (set get getSetProxyMatches_tx_Greedy):
+
+2016-03-24  Michael Saboff  <[email protected]>
+
         [ES6] Greedy unicode RegExp's don't properly backtrack past non BMP characters
         https://bugs.webkit.org/show_bug.cgi?id=155829
 

Modified: trunk/Source/_javascript_Core/builtins/RegExpPrototype.js (198624 => 198625)


--- trunk/Source/_javascript_Core/builtins/RegExpPrototype.js	2016-03-24 14:19:37 UTC (rev 198624)
+++ trunk/Source/_javascript_Core/builtins/RegExpPrototype.js	2016-03-24 16:13:46 UTC (rev 198625)
@@ -52,17 +52,17 @@
     if (!regexp.global)
         return regexp.exec(stringArg);
 
+    let unicode = regexp.unicode;
     regexp.lastIndex = 0;
-
     let resultList = [];
+    let execFunc = regexp.exec;
 
-    if (regexp.exec !== @RegExp.prototype.@exec && typeof(regexp.exec) === "function") {
+    if (execFunc !== @RegExp.prototype.@exec && typeof execFunc === "function") {
         // Match using the overridden exec.
-        let unicode = regexp.unicode;
-        let stringLength = str.length;
+        let stringLength = stringArg.length;
 
         while (true) {
-            let result = regexp.exec(stringArg);
+            let result = execFunc(stringArg);
             
             if (result === null) {
                 if (resultList.length === 0)
@@ -81,6 +81,8 @@
             }
 
             resultList.@push(resultString);
+
+            execFunc = regexp.exec;
         }
     }
 

Modified: trunk/Source/_javascript_Core/tests/es6.yaml (198624 => 198625)


--- trunk/Source/_javascript_Core/tests/es6.yaml	2016-03-24 14:19:37 UTC (rev 198624)
+++ trunk/Source/_javascript_Core/tests/es6.yaml	2016-03-24 16:13:46 UTC (rev 198625)
@@ -997,7 +997,7 @@
 - path: es6/Proxy_internal_get_calls_RegExp.prototype.toString.js
   cmd: runES6 :normal
 - path: es6/Proxy_internal_get_calls_RegExp.prototype[Symbol.match].js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_internal_get_calls_RegExp.prototype[Symbol.replace].js
   cmd: runES6 :fail
 - path: es6/Proxy_internal_get_calls_RegExp.prototype[Symbol.search].js

Added: trunk/Source/_javascript_Core/tests/stress/regexp-match-proxy.js (0 => 198625)


--- trunk/Source/_javascript_Core/tests/stress/regexp-match-proxy.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/regexp-match-proxy.js	2016-03-24 16:13:46 UTC (rev 198625)
@@ -0,0 +1,166 @@
+function assert(assertion) {
+    if (typeof assertion != "string")
+        throw new Error("Invalid assertion.");
+
+    let result = eval(assertion);
+
+    if (!result)
+        throw new Error("Bad assertion: " + assertion);
+}
+
+let get = [];
+let set = [];
+let getSet = [];
+
+function resetTracking()
+{
+    get = [];
+    set = [];
+    getSet = [];
+}
+
+let getProxyNullExec = new Proxy({
+        exec: function()
+        {
+            return null;
+        }
+    }, {
+        get: function(o, k)
+        {
+            get.push(k); return o[k];
+        }
+    });
+
+resetTracking();
+RegExp.prototype[Symbol.match].call(getProxyNullExec);
+assert('get == "global,exec"');
+
+let getSetProxyNullExec = new Proxy(
+    {
+        exec: function()
+        {
+            return null;
+        }
+    }, {
+        get: function(o, k)
+        {
+            get.push(k);
+            getSet.push(k);
+            return o[k];
+        },
+        set: function(o, k, v)
+        {
+            set.push(k);
+            getSet.push(k);
+            o[k] = v;
+        }
+    });
+
+getSetProxyNullExec.global = true;
+
+resetTracking();
+RegExp.prototype[Symbol.match].call(getSetProxyNullExec);
+assert('get == "global,unicode,exec"');
+assert('set == "lastIndex"');
+assert('getSet == "global,unicode,lastIndex,exec"');
+
+let regExpGlobal_s = new RegExp("s", "g");
+let getSetProxyMatches_s = new Proxy(
+    {
+        exec: function(string)
+        {
+            return regExpGlobal_s.exec(string);
+        }
+    }, {
+        get: function(o, k)
+        {
+            get.push(k);
+            getSet.push(k);
+            return o[k];
+        },
+        set: function(o, k, v)
+        {
+            set.push(k);
+            getSet.push(k);
+            o[k] = v;
+        }
+    });
+
+getSetProxyMatches_s.global = true;
+resetTracking();
+let matchResult = RegExp.prototype[Symbol.match].call(getSetProxyMatches_s, "This is a test");
+assert('matchResult == "s,s,s"');
+assert('get == "global,unicode,exec,exec,exec,exec"');
+assert('set == "lastIndex"');
+assert('getSet == "global,unicode,lastIndex,exec,exec,exec,exec"');
+
+let regExpGlobal_tx_Greedy = new RegExp("[tx]*", "g");
+let getSetProxyMatches_tx_Greedy = new Proxy(
+    {
+        exec: function(string)
+        {
+            return regExpGlobal_tx_Greedy.exec(string);
+        }
+    }, {
+        get: function(o, k)
+        {
+            get.push(k);
+            getSet.push(k);
+            if (k.toString() == "lastIndex")
+                return regExpGlobal_tx_Greedy.lastIndex;
+            return o[k];
+        },
+        set: function(o, k, v)
+        {
+            set.push(k);
+            getSet.push(k);
+            if (k.toString() == "lastIndex")
+                regExpGlobal_tx_Greedy.lastIndex = v;
+            o[k] = v;
+        }
+    });
+
+getSetProxyMatches_tx_Greedy.global = true;
+
+resetTracking();
+matchResult = RegExp.prototype[Symbol.match].call(getSetProxyMatches_tx_Greedy, "testing");
+assert('matchResult == "t,,,t,,,,"');
+assert('get == "global,unicode,exec,exec,lastIndex,exec,lastIndex,exec,exec,lastIndex,exec,lastIndex,exec,lastIndex,exec,lastIndex,exec"');
+assert('set == "lastIndex,lastIndex,lastIndex,lastIndex,lastIndex,lastIndex,lastIndex"');
+assert('getSet == "global,unicode,lastIndex,exec,exec,lastIndex,lastIndex,exec,lastIndex,lastIndex,exec,exec,lastIndex,lastIndex,exec,lastIndex,lastIndex,exec,lastIndex,lastIndex,exec,lastIndex,lastIndex,exec"');
+
+let regExpGlobalUnicode_digit_nonGreedy = new RegExp("\\d{0,1}", "gu");
+let getSetProxyMatchesUnicode_digit_nonGreedy = new Proxy(
+    {
+        exec: function(string)
+        {
+            return regExpGlobalUnicode_digit_nonGreedy.exec(string);
+        }
+    }, {
+        get: function(o, k)
+        {
+            get.push(k);
+            getSet.push(k);
+            if (k.toString() == "lastIndex")
+                return regExpGlobalUnicode_digit_nonGreedy.lastIndex;
+            return o[k];
+        },
+        set: function(o, k, v)
+        {
+            set.push(k);
+            getSet.push(k);
+            if (k.toString() == "lastIndex")
+                regExpGlobalUnicode_digit_nonGreedy.lastIndex = v;
+            o[k] = v;
+        }
+    });
+
+getSetProxyMatchesUnicode_digit_nonGreedy.global = true;
+getSetProxyMatchesUnicode_digit_nonGreedy.unicode = true;
+
+resetTracking();
+matchResult = RegExp.prototype[Symbol.match].call(getSetProxyMatchesUnicode_digit_nonGreedy, "12X3\u{10400}4");
+assert('matchResult == "1,2,,3,,4,"');
+assert('get == "global,unicode,exec,exec,exec,lastIndex,exec,exec,lastIndex,exec,exec,lastIndex,exec"');
+assert('set == "lastIndex,lastIndex,lastIndex,lastIndex"');
+assert('getSet == "global,unicode,lastIndex,exec,exec,exec,lastIndex,lastIndex,exec,exec,lastIndex,lastIndex,exec,exec,lastIndex,lastIndex,exec"');
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to