ES6: Implement RegExp.prototype[@@search].
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2016 20:00:31 +0000 (20:00 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2016 20:00:31 +0000 (20:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156331

Reviewed by Keith Miller.

Source/JavaScriptCore:

What changed?
1. Implemented search builtin in RegExpPrototype.js.
   The native path is now used as a fast path.
2. Added DFG support for an IsRegExpObjectIntrinsic (modelled after the
   IsJSArrayIntrinsic).
3. Renamed @isRegExp to @isRegExpObject to match the new IsRegExpObjectIntrinsic.
4. Change the esSpecIsRegExpObject() implementation to check if the object's
   JSType is RegExpObjectType instead of walking the classinfo chain.

* builtins/RegExpPrototype.js:
(search):
* builtins/StringPrototype.js:
(search):
- fixed some indentation.

* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleIntrinsicCall):
* dfg/DFGClobberize.h:
(JSC::DFG::clobberize):
* dfg/DFGDoesGC.cpp:
(JSC::DFG::doesGC):
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
* dfg/DFGNodeType.h:
* dfg/DFGPredictionPropagationPhase.cpp:
(JSC::DFG::PredictionPropagationPhase::propagate):
* dfg/DFGSafeToExecute.h:
(JSC::DFG::safeToExecute):
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileIsArrayConstructor):
(JSC::DFG::SpeculativeJIT::compileIsRegExpObject):
(JSC::DFG::SpeculativeJIT::compileCallObjectConstructor):
* dfg/DFGSpeculativeJIT.h:
* dfg/DFGSpeculativeJIT32_64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* ftl/FTLCapabilities.cpp:
(JSC::FTL::canCompile):
* ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileNode):
(JSC::FTL::DFG::LowerDFGToB3::compileIsFunction):
(JSC::FTL::DFG::LowerDFGToB3::compileIsRegExpObject):
(JSC::FTL::DFG::LowerDFGToB3::compileTypeOf):
(JSC::FTL::DFG::LowerDFGToB3::isExoticForTypeof):
(JSC::FTL::DFG::LowerDFGToB3::isRegExpObject):
(JSC::FTL::DFG::LowerDFGToB3::isType):
* runtime/Intrinsic.h:
- Added IsRegExpObjectIntrinsic.

* runtime/CommonIdentifiers.h:

* runtime/ECMAScriptSpecInternalFunctions.cpp:
(JSC::esSpecIsConstructor):
- Changed to use uncheckedArgument since this is only called from internal code.
(JSC::esSpecIsRegExpObject):
(JSC::esSpecIsRegExp): Deleted.
* runtime/ECMAScriptSpecInternalFunctions.h:
- Changed to check the object for a JSType of RegExpObjectType.

* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
- Added split fast path.

* runtime/RegExpPrototype.cpp:
(JSC::RegExpPrototype::finishCreation):
(JSC::regExpProtoFuncSearchFast):
(JSC::regExpProtoFuncSearch): Deleted.
* runtime/RegExpPrototype.h:

* tests/es6.yaml:
* tests/stress/regexp-search.js:
- Rebased test.

LayoutTests:

* js/regress/regexp-prototype-search-observable-side-effects-expected.txt: Added.
* js/regress/regexp-prototype-search-observable-side-effects.html: Added.
* js/regress/regexp-prototype-search-observable-side-effects2-expected.txt: Added.
* js/regress/regexp-prototype-search-observable-side-effects2.html: Added.

* js/regress/script-tests/regexp-prototype-search-observable-side-effects.js: Added.
* js/regress/script-tests/regexp-prototype-search-observable-side-effects2.js: Added.

* js/regress/script-tests/string-prototype-search-observable-side-effects.js: Added.
* js/regress/script-tests/string-prototype-search-observable-side-effects2.js: Added.
* js/regress/script-tests/string-prototype-search-observable-side-effects3.js: Added.
* js/regress/script-tests/string-prototype-search-observable-side-effects4.js: Added.

* js/regress/string-prototype-search-observable-side-effects-expected.txt: Added.
* js/regress/string-prototype-search-observable-side-effects.html: Added.
* js/regress/string-prototype-search-observable-side-effects2-expected.txt: Added.
* js/regress/string-prototype-search-observable-side-effects2.html: Added.
* js/regress/string-prototype-search-observable-side-effects3-expected.txt: Added.
* js/regress/string-prototype-search-observable-side-effects3.html: Added.
* js/regress/string-prototype-search-observable-side-effects4-expected.txt: Added.
* js/regress/string-prototype-search-observable-side-effects4.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199511 268f45cc-cd09-0410-ab3c-d52691b4dbfc

45 files changed:
LayoutTests/ChangeLog
LayoutTests/js/regress/regexp-prototype-search-observable-side-effects-expected.txt [new file with mode: 0644]
LayoutTests/js/regress/regexp-prototype-search-observable-side-effects.html [new file with mode: 0644]
LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2-expected.txt [new file with mode: 0644]
LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2.html [new file with mode: 0644]
LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects.js [new file with mode: 0644]
LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects2.js [new file with mode: 0644]
LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects.js [new file with mode: 0644]
LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects2.js [new file with mode: 0644]
LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects3.js [new file with mode: 0644]
LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects4.js [new file with mode: 0644]
LayoutTests/js/regress/string-prototype-search-observable-side-effects-expected.txt [new file with mode: 0644]
LayoutTests/js/regress/string-prototype-search-observable-side-effects.html [new file with mode: 0644]
LayoutTests/js/regress/string-prototype-search-observable-side-effects2-expected.txt [new file with mode: 0644]
LayoutTests/js/regress/string-prototype-search-observable-side-effects2.html [new file with mode: 0644]
LayoutTests/js/regress/string-prototype-search-observable-side-effects3-expected.txt [new file with mode: 0644]
LayoutTests/js/regress/string-prototype-search-observable-side-effects3.html [new file with mode: 0644]
LayoutTests/js/regress/string-prototype-search-observable-side-effects4-expected.txt [new file with mode: 0644]
LayoutTests/js/regress/string-prototype-search-observable-side-effects4.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/builtins/RegExpPrototype.js
Source/JavaScriptCore/builtins/StringPrototype.js
Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h
Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
Source/JavaScriptCore/dfg/DFGClobberize.h
Source/JavaScriptCore/dfg/DFGDoesGC.cpp
Source/JavaScriptCore/dfg/DFGFixupPhase.cpp
Source/JavaScriptCore/dfg/DFGNodeType.h
Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp
Source/JavaScriptCore/dfg/DFGSafeToExecute.h
Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp
Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h
Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp
Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp
Source/JavaScriptCore/ftl/FTLCapabilities.cpp
Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/ECMAScriptSpecInternalFunctions.cpp
Source/JavaScriptCore/runtime/ECMAScriptSpecInternalFunctions.h
Source/JavaScriptCore/runtime/Intrinsic.h
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/RegExpPrototype.cpp
Source/JavaScriptCore/runtime/RegExpPrototype.h
Source/JavaScriptCore/tests/es6.yaml
Source/JavaScriptCore/tests/stress/regexp-search.js

index 25856d1..ca92b3e 100644 (file)
@@ -1,3 +1,32 @@
+2016-04-13  Mark Lam  <mark.lam@apple.com>
+
+        ES6: Implement RegExp.prototype[@@search].
+        https://bugs.webkit.org/show_bug.cgi?id=156331
+
+        Reviewed by Keith Miller.
+
+        * js/regress/regexp-prototype-search-observable-side-effects-expected.txt: Added.
+        * js/regress/regexp-prototype-search-observable-side-effects.html: Added.
+        * js/regress/regexp-prototype-search-observable-side-effects2-expected.txt: Added.
+        * js/regress/regexp-prototype-search-observable-side-effects2.html: Added.
+
+        * js/regress/script-tests/regexp-prototype-search-observable-side-effects.js: Added.
+        * js/regress/script-tests/regexp-prototype-search-observable-side-effects2.js: Added.
+
+        * js/regress/script-tests/string-prototype-search-observable-side-effects.js: Added.
+        * js/regress/script-tests/string-prototype-search-observable-side-effects2.js: Added.
+        * js/regress/script-tests/string-prototype-search-observable-side-effects3.js: Added.
+        * js/regress/script-tests/string-prototype-search-observable-side-effects4.js: Added.
+
+        * js/regress/string-prototype-search-observable-side-effects-expected.txt: Added.
+        * js/regress/string-prototype-search-observable-side-effects.html: Added.
+        * js/regress/string-prototype-search-observable-side-effects2-expected.txt: Added.
+        * js/regress/string-prototype-search-observable-side-effects2.html: Added.
+        * js/regress/string-prototype-search-observable-side-effects3-expected.txt: Added.
+        * js/regress/string-prototype-search-observable-side-effects3.html: Added.
+        * js/regress/string-prototype-search-observable-side-effects4-expected.txt: Added.
+        * js/regress/string-prototype-search-observable-side-effects4.html: Added.
+
 2016-04-13  Jiewen Tan  <jiewen_tan@apple.com>
 
         Mark fast/canvas/webgl/gl-teximage.html as flaky on Macs
diff --git a/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects-expected.txt b/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects-expected.txt
new file mode 100644 (file)
index 0000000..67cd66c
--- /dev/null
@@ -0,0 +1,10 @@
+JSRegress/regexp-prototype-search-observable-side-effects
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects.html b/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects.html
new file mode 100644 (file)
index 0000000..123b578
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/regexp-prototype-search-observable-side-effects.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
+
diff --git a/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2-expected.txt b/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2-expected.txt
new file mode 100644 (file)
index 0000000..ef88f31
--- /dev/null
@@ -0,0 +1,10 @@
+JSRegress/regexp-prototype-search-observable-side-effects2
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2.html b/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2.html
new file mode 100644 (file)
index 0000000..ab52b64
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/regexp-prototype-search-observable-side-effects2.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
+
diff --git a/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects.js b/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects.js
new file mode 100644 (file)
index 0000000..991f628
--- /dev/null
@@ -0,0 +1,281 @@
+//@ runDefault
+
+function assert(testedValue, msg) {
+    if (!testedValue)
+        throw Error(msg);
+}
+
+// RegExp subclass should not be able to override lastIndex.
+(function () {
+    let accesses = [];
+    class SubRegExp extends RegExp {
+        get lastIndex() {
+            accesses.push("getLastIndex");
+            return super.lastIndex;
+        }
+        set lastIndex(newIndex) {
+            accesses.push("setLastIndex");
+            super.lastIndex = newIndex;
+        }
+    }
+
+    let obj = new SubRegExp(/rch/);
+
+    assert(accesses == "", "Should not be able to override lastIndex");
+    let result = RegExp.prototype[Symbol.search].call(obj, "searchme");
+    assert(accesses == "", "Should not be able to override lastIndex");
+    assert(result === 3, "Unexpected result");
+})();
+
+// RegExp subclass overriding exec.
+(function () {
+    let accesses = [];
+    class SubRegExp extends RegExp {
+        exec(str) {
+            accesses.push("exec");
+            return super.exec(str);
+        }
+    }
+
+    let obj = new SubRegExp(/rch/);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = RegExp.prototype[Symbol.search].call(obj, "searchme");
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+// Any object with custom prototype overriding lastIndex.
+(function () {
+    let accesses = [];
+    let TestRegExpProto = {
+        get lastIndex() {
+            accesses.push("getLastIndex");
+            return this._regex.lastIndex;
+        },
+        set lastIndex(newIndex) {
+            accesses.push("setLastIndex");
+            this._regex.lastIndex = newIndex;
+        },
+    }
+    TestRegExpProto.__proto__ = RegExp.prototype;
+
+    let TestRegExp = function(regex) {
+        this._regex = new RegExp(regex);
+    }
+    TestRegExp.prototype = TestRegExpProto;
+    TestRegExpProto.constructor = TestRegExp;
+
+    let obj = new TestRegExp(/rch/);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    try {
+        RegExp.prototype[Symbol.search].call(obj, "searchme");
+        assert(false, "Error not thrown");
+    } catch (e) {
+        assert(e.toString() == "TypeError: Builtin RegExp exec can only be called on a RegExp object",
+            "Unexpected error message");
+    }
+    assert(accesses == "getLastIndex,setLastIndex", "Property accesses do not match expectation");
+})();
+
+// Any object with custom prototype overriding exec.
+(function () {
+    let accesses = [];
+    let TestRegExpProto = {
+        exec(str) {
+            accesses.push("exec");
+            return this._regex.exec(str);
+        }
+    }
+    TestRegExpProto.__proto__ = RegExp.prototype;
+
+    let TestRegExp = function(regex) {
+        this._regex = new RegExp(regex);
+    }
+    TestRegExp.prototype = TestRegExpProto;
+    TestRegExpProto.constructor = TestRegExp;
+
+    let obj = new TestRegExp(/rch/);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = RegExp.prototype[Symbol.search].call(obj, "searchme");
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// 2 levels of RegExp subclasses with the middle parent overriding exec.
+(function () {
+    let accesses = [];
+    class RegExpB extends RegExp {
+        exec(str) {
+            accesses.push("exec");
+            return super.exec(str);
+        }
+    }
+    class RegExpC extends RegExpB { }
+
+    assert(RegExpB.__proto__ == RegExp);
+    assert(RegExpC.__proto__ == RegExpB);
+
+    let obj = new RegExpC(/rch/);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = RegExp.prototype[Symbol.search].call(obj, "searchme");
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// 2 levels of RegExp subclasses with substituted prototype before instantiation.
+(function () {
+    let accesses = [];
+
+    class B extends RegExp { }
+    class C extends B { }
+
+    assert(B.__proto__ === RegExp);
+    assert(C.__proto__ === B);
+    assert(B.prototype.__proto__ === RegExp.prototype);
+    assert(C.prototype.__proto__ === B.prototype);
+
+    let X = function () {}
+    Object.defineProperty(X.prototype, "exec", {
+        value: function(str) {
+            accesses.push("exec");
+            return /rch/.exec(str);
+        }
+    });
+    Object.defineProperty(X.prototype, "lastIndex", {
+        get: function() {
+            accesses.push("getLastIndex");
+            return 0;
+        },
+        set: function(value) {
+            accesses.push("setLastIndex");
+        }
+    });
+
+    // Monkey with the prototype chain before instantiating C.
+    X.__proto__ = RegExp;
+    X.prototype.__proto__ = RegExp.prototype;
+    C.__proto__ = X;
+    C.prototype.__proto__ = X.prototype;
+
+    assert(X.__proto__ === RegExp);
+    assert(C.__proto__ === X);
+    assert(X.prototype.__proto__ === RegExp.prototype);
+    assert(C.prototype.__proto__ === X.prototype);
+
+    let obj = new C();
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = RegExp.prototype[Symbol.search].call(obj, "searchme");
+    assert(accesses == "getLastIndex,setLastIndex,exec,setLastIndex", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// 2 levels of RegExp subclasses with substituted prototype after instantiation.
+(function () {
+    let accesses = [];
+
+    class B extends RegExp { }
+    class C extends B { }
+
+    assert(B.__proto__ === RegExp);
+    assert(C.__proto__ === B);
+    assert(B.prototype.__proto__ === RegExp.prototype);
+    assert(C.prototype.__proto__ === B.prototype);
+
+    let obj = new C();
+
+    let X = function () {}
+    Object.defineProperty(X.prototype, "exec", {
+        value: function(str) {
+            accesses.push("exec");
+            return /rch/.exec(str);
+        }
+    });
+    Object.defineProperty(X.prototype, "lastIndex", {
+        get: function() {
+            accesses.push("getLastIndex");
+            return 0;
+        },
+        set: function(value) {
+            accesses.push("setLastIndex");
+        }
+    });
+
+    // Monkey with the prototype chain after instantiating C.
+    X.__proto__ = RegExp;
+    X.prototype.__proto__ = RegExp.prototype;
+    C.__proto__ = X;
+    C.prototype.__proto__ = X.prototype;
+
+    assert(X.__proto__ === RegExp);
+    assert(C.__proto__ === X);
+    assert(X.prototype.__proto__ === RegExp.prototype);
+    assert(C.prototype.__proto__ === X.prototype);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = RegExp.prototype[Symbol.search].call(obj, "searchme");
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// 2 levels of RegExp subclasses with proxied prototype.
+(function () {
+    let accesses = [];
+
+    class B extends RegExp { };
+
+    assert(B.__proto__ === RegExp);
+    assert(B.prototype.__proto__ === RegExp.prototype);
+
+    let proxy = new Proxy(RegExp.prototype, {
+        get: function(obj, prop) {
+            accesses.push("get_" + prop.toString());
+
+            function proxyExec(str) {
+                accesses.push("exec");
+                return /rch/.exec(str);
+            }
+
+            if (prop === "exec")
+                return proxyExec;
+            return obj[prop];
+        },
+        set: function(obj, prop, value) {
+            accesses.push("set_" + prop.toString());
+        }
+    });
+    B.prototype.__proto__ = proxy;
+
+    let obj = new B();
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = RegExp.prototype[Symbol.search].call(obj, "searchme");
+    assert(accesses == "get_exec,exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// Proxied RegExp observing every get.
+(function () {
+    let accesses = [];
+    let regexp = new RegExp(/rch/);
+    let proxy = new Proxy(regexp, {
+        get(obj, prop) {
+            accesses.push(prop.toString());
+            if (prop == "exec") {
+                return function(str) {
+                    return obj.exec(str);
+                }
+            }
+            return obj[prop];
+        }
+    });
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = RegExp.prototype[Symbol.search].call(proxy, "searchme");
+    assert(accesses.toString() == "lastIndex,exec", "Proxy not able to observe some gets");
+    assert(result === 3, "Unexpected result");
+})();
diff --git a/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects2.js b/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects2.js
new file mode 100644 (file)
index 0000000..d2cbeb0
--- /dev/null
@@ -0,0 +1,26 @@
+//@ runDefault
+
+function assert(testedValue, msg) {
+    if (!testedValue)
+        throw Error(msg);
+}
+
+// RegExp.prototype with overridden exec.
+(function () {
+    let accesses = [];
+    let origExec = RegExp.prototype.exec;
+
+    let obj = /rch/;
+    Object.defineProperty(RegExp.prototype, "exec", {
+        value: function(str) {
+            accesses.push("exec");
+            return origExec.call(this, str);
+        }
+    });
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = RegExp.prototype[Symbol.search].call(obj, "searchme");
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
diff --git a/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects.js b/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects.js
new file mode 100644 (file)
index 0000000..b5da8f3
--- /dev/null
@@ -0,0 +1,379 @@
+//@ runDefault
+
+function assert(testedValue, msg) {
+    if (!testedValue)
+        throw Error(msg);
+}
+
+//======================================================================================
+// Testing the string that we're calling search on.
+
+// Proxied String subclass.
+(function () {
+    let accesses = [];
+    class ExtString extends String { }
+    var obj = new ExtString("searchme");
+    var proxy = new Proxy(obj, {
+        get(obj, prop) {
+            accesses.push(prop.toString());
+            if (prop === "toString") {
+                return function() {
+                    accesses.push("in_toString");
+                    return obj.toString();
+                }
+            }
+            return obj[prop];
+        }
+    });
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = String.prototype.search.call(proxy, "rch");    
+    assert(accesses == "Symbol(Symbol.toPrimitive),toString,in_toString", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// Object that looks like a string.
+(function () {
+    let accesses = [];
+    var obj = {
+        [Symbol.toPrimitive]() {
+            accesses.push(Symbol.toPrimitive.toString());
+            return "searchme";
+        }
+    }
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = String.prototype.search.call(obj, "rch");    
+    assert(accesses == "Symbol(Symbol.toPrimitive)", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// Object that looks like a string.
+(function () {
+    let accesses = [];
+    var obj = {
+        toString() {
+            accesses.push("toString");
+            return "searchme";
+        }
+    }
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = String.prototype.search.call(obj, "rch");    
+    assert(accesses == "toString", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// String subclass with overridden @@search.
+(function () {
+    let accesses = [];
+    class ExtString extends String {
+        [Symbol.search] (str) {
+            accesses.push("Symbol(Symbol.search)");
+            return /rch/[Symbol.search](str);
+        }
+    };
+
+    var obj = new ExtString;
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);    
+    assert(accesses == "Symbol(Symbol.search)", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+
+// Object with overridden @@search.
+(function () {
+    let accesses = [];
+    var obj = {
+        [Symbol.search] (str) {
+            accesses.push("Symbol(Symbol.search)");
+            return /rch/[Symbol.search](str);
+        },
+    }
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "Symbol(Symbol.search)", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+
+//======================================================================================
+// Testing the regexp object that we're calling search with.
+
+// RegExp subclass should not be able to override lastIndex.
+(function () {
+    let accesses = [];
+    class SubRegExp extends RegExp {
+        get lastIndex() {
+            accesses.push("getLastIndex");
+            return super.lastIndex;
+        }
+        set lastIndex(newIndex) {
+            accesses.push("setLastIndex");
+            super.lastIndex = newIndex;
+        }
+    }
+
+    let obj = new SubRegExp(/rch/);
+
+    assert(accesses == "", "Should not be able to override lastIndex");
+    let result = "searchme".search(obj);
+    assert(accesses == "", "Should not be able to override lastIndex");
+    assert(result === 3, "Unexpected result");
+})();
+
+// RegExp subclass overriding exec.
+(function () {
+    let accesses = [];
+    class SubRegExp extends RegExp {
+        exec(str) {
+            accesses.push("exec");
+            return super.exec(str);
+        }
+    }
+
+    let obj = new SubRegExp(/rch/);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+// Any object with custom prototype overriding lastIndex.
+(function () {
+    let accesses = [];
+    let TestRegExpProto = {
+        get lastIndex() {
+            accesses.push("getLastIndex");
+            return this._regex.lastIndex;
+        },
+        set lastIndex(newIndex) {
+            accesses.push("setLastIndex");
+            this._regex.lastIndex = newIndex;
+        },
+    }
+    TestRegExpProto.__proto__ = RegExp.prototype;
+
+    let TestRegExp = function(regex) {
+        this._regex = new RegExp(regex);
+    }
+    TestRegExp.prototype = TestRegExpProto;
+    TestRegExpProto.constructor = TestRegExp;
+
+    let obj = new TestRegExp(/rch/);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    try {
+        let result = "searchme".search(obj);
+        assert(false, "Error not thrown");
+    } catch (e) {
+        assert(e.toString() == "TypeError: Builtin RegExp exec can only be called on a RegExp object",
+            "Unexpected error message");
+    }
+    assert(accesses == "getLastIndex,setLastIndex", "Property accesses do not match expectation");
+})();
+
+// Any object with custom prototype overriding exec.
+(function () {
+    let accesses = [];
+    let TestRegExpProto = {
+        exec(str) {
+            accesses.push("exec");
+            return this._regex.exec(str);
+        }
+    }
+    TestRegExpProto.__proto__ = RegExp.prototype;
+
+    let TestRegExp = function(regex) {
+        this._regex = new RegExp(regex);
+    }
+    TestRegExp.prototype = TestRegExpProto;
+    TestRegExpProto.constructor = TestRegExp;
+
+    let obj = new TestRegExp(/rch/);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// 2 levels of RegExp subclasses with the middle parent overriding exec.
+(function () {
+    let accesses = [];
+    class RegExpB extends RegExp {
+        exec(str) {
+            accesses.push("exec");
+            return super.exec(str);
+        }
+    }
+    class RegExpC extends RegExpB { }
+
+    assert(RegExpB.__proto__ == RegExp);
+    assert(RegExpC.__proto__ == RegExpB);
+
+    let obj = new RegExpC(/rch/);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// 2 levels of RegExp subclasses with substituted prototype before instantiation.
+(function () {
+    let accesses = [];
+
+    class B extends RegExp { }
+    class C extends B { }
+
+    assert(B.__proto__ === RegExp);
+    assert(C.__proto__ === B);
+    assert(B.prototype.__proto__ === RegExp.prototype);
+    assert(C.prototype.__proto__ === B.prototype);
+
+    let X = function () {}
+    Object.defineProperty(X.prototype, "exec", {
+        value: function(str) {
+            accesses.push("exec");
+            return /rch/.exec(str);
+        }
+    });
+    Object.defineProperty(X.prototype, "lastIndex", {
+        get: function() {
+            accesses.push("getLastIndex");
+            return 0;
+        },
+        set: function(value) {
+            accesses.push("setLastIndex");
+        }
+    });
+
+    // Monkey with the prototype chain before instantiating C.
+    X.__proto__ = RegExp;
+    X.prototype.__proto__ = RegExp.prototype;
+    C.__proto__ = X;
+    C.prototype.__proto__ = X.prototype;
+
+    assert(X.__proto__ === RegExp);
+    assert(C.__proto__ === X);
+    assert(X.prototype.__proto__ === RegExp.prototype);
+    assert(C.prototype.__proto__ === X.prototype);
+
+    let obj = new C();
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "getLastIndex,setLastIndex,exec,setLastIndex", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// 2 levels of RegExp subclasses with substituted prototype after instantiation.
+(function () {
+    let accesses = [];
+
+    class B extends RegExp { }
+    class C extends B { }
+
+    assert(B.__proto__ === RegExp);
+    assert(C.__proto__ === B);
+    assert(B.prototype.__proto__ === RegExp.prototype);
+    assert(C.prototype.__proto__ === B.prototype);
+
+    let obj = new C();
+
+    let X = function () {}
+    Object.defineProperty(X.prototype, "exec", {
+        value: function(str) {
+            accesses.push("exec");
+            return /rch/.exec(str);
+        }
+    });
+    Object.defineProperty(X.prototype, "lastIndex", {
+        get: function() {
+            accesses.push("getLastIndex");
+            return 0;
+        },
+        set: function(value) {
+            accesses.push("setLastIndex");
+        }
+    });
+
+    // Monkey with the prototype chain after instantiating C.
+    X.__proto__ = RegExp;
+    X.prototype.__proto__ = RegExp.prototype;
+    C.__proto__ = X;
+    C.prototype.__proto__ = X.prototype;
+
+    assert(X.__proto__ === RegExp);
+    assert(C.__proto__ === X);
+    assert(X.prototype.__proto__ === RegExp.prototype);
+    assert(C.prototype.__proto__ === X.prototype);
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// 2 levels of RegExp subclasses with proxied prototype.
+(function () {
+    let accesses = [];
+
+    class B extends RegExp { };
+
+    assert(B.__proto__ === RegExp);
+    assert(B.prototype.__proto__ === RegExp.prototype);
+
+    let proxy = new Proxy(RegExp.prototype, {
+        get: function(obj, prop) {
+            accesses.push("get_" + prop.toString());
+
+            function proxyExec(str) {
+                accesses.push("exec");
+                return /rch/.exec(str);
+            }
+
+            if (prop === "exec")
+                return proxyExec;
+            return obj[prop];
+        },
+        set: function(obj, prop, value) {
+            accesses.push("set_" + prop.toString());
+        }
+    });
+    B.prototype.__proto__ = proxy;
+
+    let obj = new B();
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "get_Symbol(Symbol.search),get_exec,exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
+
+// Proxied RegExp observing every get.
+(function () {
+    let accesses = [];
+    let regexp = new RegExp(/rch/);
+    let proxy = new Proxy(regexp, {
+        get(obj, prop) {
+            accesses.push(prop.toString());
+            if (prop == "exec") {
+                return function(str) {
+                    return obj.exec(str);
+                }
+            }
+            return obj[prop];
+        }
+    });
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(proxy);
+    assert(accesses.toString() == "Symbol(Symbol.search),lastIndex,exec", "Proxy not able to observe some gets");
+    assert(result === 3, "Unexpected result");
+})();
diff --git a/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects2.js b/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects2.js
new file mode 100644 (file)
index 0000000..ce8f385
--- /dev/null
@@ -0,0 +1,27 @@
+//@ runDefault
+
+function assert(testedValue, msg) {
+    if (!testedValue)
+        throw Error(msg);
+}
+
+// String prototype with overridden @@search.
+(function () {
+    let accesses = [];
+    var obj = String("");
+    Object.defineProperty(String.prototype, Symbol.search, {
+        value: function (str) {
+            accesses.push("Symbol(Symbol.search)");
+            return /rch/[Symbol.search](str);
+        },
+        writable: true,
+        configurable: true,
+    });
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "Symbol(Symbol.search)", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+
+    Object.defineProperty(String.prototype, Symbol.search, { value: undefined, writable: false, configurable: true });
+})();
diff --git a/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects3.js b/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects3.js
new file mode 100644 (file)
index 0000000..d628689
--- /dev/null
@@ -0,0 +1,27 @@
+//@ runDefault
+
+function assert(testedValue, msg) {
+    if (!testedValue)
+        throw Error(msg);
+}
+
+// String prototype with overridden @@search: test with string literal.
+(function () {
+    let accesses = [];
+    var obj = "";
+    Object.defineProperty(String.prototype, Symbol.search, {
+        value: function (str) {
+            accesses.push("Symbol(Symbol.search)");
+            return /rch/[Symbol.search](str);
+        },
+        writable: true,
+        configurable: true,
+    });
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "Symbol(Symbol.search)", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+
+    Object.defineProperty(String.prototype, Symbol.search, { value: undefined, writable: false, configurable: true });
+})();
diff --git a/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects4.js b/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects4.js
new file mode 100644 (file)
index 0000000..7cfe19f
--- /dev/null
@@ -0,0 +1,25 @@
+//@ runDefault
+
+function assert(testedValue, msg) {
+    if (!testedValue)
+        throw Error(msg);
+}
+
+// RegExp.prototype with overridden exec.
+(function () {
+    let accesses = [];
+    let origExec = RegExp.prototype.exec;
+
+    let obj = /rch/;
+    Object.defineProperty(RegExp.prototype, "exec", {
+        value: function(str) {
+            accesses.push("exec");
+            return origExec.call(this, str);
+        }
+    });
+
+    assert(accesses == "", "unexpected call to overridden props");
+    let result = "searchme".search(obj);
+    assert(accesses == "exec", "Property accesses do not match expectation");
+    assert(result === 3, "Unexpected result");
+})();
diff --git a/LayoutTests/js/regress/string-prototype-search-observable-side-effects-expected.txt b/LayoutTests/js/regress/string-prototype-search-observable-side-effects-expected.txt
new file mode 100644 (file)
index 0000000..0401e01
--- /dev/null
@@ -0,0 +1,10 @@
+JSRegress/string-prototype-search-observable-side-effects
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/regress/string-prototype-search-observable-side-effects.html b/LayoutTests/js/regress/string-prototype-search-observable-side-effects.html
new file mode 100644 (file)
index 0000000..c014b99
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/string-prototype-search-observable-side-effects.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
+
diff --git a/LayoutTests/js/regress/string-prototype-search-observable-side-effects2-expected.txt b/LayoutTests/js/regress/string-prototype-search-observable-side-effects2-expected.txt
new file mode 100644 (file)
index 0000000..766b529
--- /dev/null
@@ -0,0 +1,10 @@
+JSRegress/string-prototype-search-observable-side-effects2
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/regress/string-prototype-search-observable-side-effects2.html b/LayoutTests/js/regress/string-prototype-search-observable-side-effects2.html
new file mode 100644 (file)
index 0000000..2cda724
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/string-prototype-search-observable-side-effects2.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
+
diff --git a/LayoutTests/js/regress/string-prototype-search-observable-side-effects3-expected.txt b/LayoutTests/js/regress/string-prototype-search-observable-side-effects3-expected.txt
new file mode 100644 (file)
index 0000000..8ede2d5
--- /dev/null
@@ -0,0 +1,10 @@
+JSRegress/string-prototype-search-observable-side-effects3
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/regress/string-prototype-search-observable-side-effects3.html b/LayoutTests/js/regress/string-prototype-search-observable-side-effects3.html
new file mode 100644 (file)
index 0000000..7329a82
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/string-prototype-search-observable-side-effects3.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
+
diff --git a/LayoutTests/js/regress/string-prototype-search-observable-side-effects4-expected.txt b/LayoutTests/js/regress/string-prototype-search-observable-side-effects4-expected.txt
new file mode 100644 (file)
index 0000000..03df289
--- /dev/null
@@ -0,0 +1,10 @@
+JSRegress/string-prototype-search-observable-side-effects4
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/regress/string-prototype-search-observable-side-effects4.html b/LayoutTests/js/regress/string-prototype-search-observable-side-effects4.html
new file mode 100644 (file)
index 0000000..7d6fba8
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/string-prototype-search-observable-side-effects4.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
+
index fda02e5..f9823ec 100644 (file)
@@ -1,3 +1,86 @@
+2016-04-13  Mark Lam  <mark.lam@apple.com>
+
+        ES6: Implement RegExp.prototype[@@search].
+        https://bugs.webkit.org/show_bug.cgi?id=156331
+
+        Reviewed by Keith Miller.
+
+        What changed?
+        1. Implemented search builtin in RegExpPrototype.js.
+           The native path is now used as a fast path.
+        2. Added DFG support for an IsRegExpObjectIntrinsic (modelled after the
+           IsJSArrayIntrinsic).
+        3. Renamed @isRegExp to @isRegExpObject to match the new IsRegExpObjectIntrinsic.
+        4. Change the esSpecIsRegExpObject() implementation to check if the object's
+           JSType is RegExpObjectType instead of walking the classinfo chain.
+
+        * builtins/RegExpPrototype.js:
+        (search):
+        * builtins/StringPrototype.js:
+        (search):
+        - fixed some indentation.
+
+        * dfg/DFGAbstractInterpreterInlines.h:
+        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::handleIntrinsicCall):
+        * dfg/DFGClobberize.h:
+        (JSC::DFG::clobberize):
+        * dfg/DFGDoesGC.cpp:
+        (JSC::DFG::doesGC):
+        * dfg/DFGFixupPhase.cpp:
+        (JSC::DFG::FixupPhase::fixupNode):
+        * dfg/DFGNodeType.h:
+        * dfg/DFGPredictionPropagationPhase.cpp:
+        (JSC::DFG::PredictionPropagationPhase::propagate):
+        * dfg/DFGSafeToExecute.h:
+        (JSC::DFG::safeToExecute):
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::compileIsArrayConstructor):
+        (JSC::DFG::SpeculativeJIT::compileIsRegExpObject):
+        (JSC::DFG::SpeculativeJIT::compileCallObjectConstructor):
+        * dfg/DFGSpeculativeJIT.h:
+        * dfg/DFGSpeculativeJIT32_64.cpp:
+        (JSC::DFG::SpeculativeJIT::compile):
+        * dfg/DFGSpeculativeJIT64.cpp:
+        (JSC::DFG::SpeculativeJIT::compile):
+        * ftl/FTLCapabilities.cpp:
+        (JSC::FTL::canCompile):
+        * ftl/FTLLowerDFGToB3.cpp:
+        (JSC::FTL::DFG::LowerDFGToB3::compileNode):
+        (JSC::FTL::DFG::LowerDFGToB3::compileIsFunction):
+        (JSC::FTL::DFG::LowerDFGToB3::compileIsRegExpObject):
+        (JSC::FTL::DFG::LowerDFGToB3::compileTypeOf):
+        (JSC::FTL::DFG::LowerDFGToB3::isExoticForTypeof):
+        (JSC::FTL::DFG::LowerDFGToB3::isRegExpObject):
+        (JSC::FTL::DFG::LowerDFGToB3::isType):
+        * runtime/Intrinsic.h:
+        - Added IsRegExpObjectIntrinsic.
+
+        * runtime/CommonIdentifiers.h:
+
+        * runtime/ECMAScriptSpecInternalFunctions.cpp:
+        (JSC::esSpecIsConstructor):
+        - Changed to use uncheckedArgument since this is only called from internal code.
+        (JSC::esSpecIsRegExpObject):
+        (JSC::esSpecIsRegExp): Deleted.
+        * runtime/ECMAScriptSpecInternalFunctions.h:
+        - Changed to check the object for a JSType of RegExpObjectType.
+
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        - Added split fast path.
+
+        * runtime/RegExpPrototype.cpp:
+        (JSC::RegExpPrototype::finishCreation):
+        (JSC::regExpProtoFuncSearchFast):
+        (JSC::regExpProtoFuncSearch): Deleted.
+        * runtime/RegExpPrototype.h:
+
+        * tests/es6.yaml:
+        * tests/stress/regexp-search.js:
+        - Rebased test.
+
 2016-04-12  Filip Pizlo  <fpizlo@apple.com>
 
         PolymorphicAccess::regenerate() shouldn't have to clone non-generated AccessCases
index 5743b6c..61c70dc 100644 (file)
@@ -108,6 +108,40 @@ function regExpExec(regexp, str)
     return builtinExec.@call(regexp, str);
 }
 
+// 21.2.5.9 RegExp.prototype[@@search] (string)
+function search(strArg)
+{
+    "use strict";
+
+    let regexp = this;
+
+    // Check for observable side effects and call the fast path if there aren't any.
+    if (@isRegExpObject(regexp) && @tryGetById(regexp, "exec") === @RegExp.prototype.@exec)
+        return @regExpSearchFast.@call(regexp, strArg);
+
+    // 1. Let rx be the this value.
+    // 2. If Type(rx) is not Object, throw a TypeError exception.
+    if (!@isObject(this))
+        throw new @TypeError("RegExp.prototype.@@search requires that |this| be an Object");
+
+    // 3. Let S be ? ToString(string).
+    let str = @toString(strArg)
+
+    // 4. Let previousLastIndex be ? Get(rx, "lastIndex").
+    let previousLastIndex = regexp.lastIndex;
+    // 5. Perform ? Set(rx, "lastIndex", 0, true).
+    regexp.lastIndex = 0;
+    // 6. Let result be ? RegExpExec(rx, S).
+    let result = @regExpExec(regexp, str);
+    // 7. Perform ? Set(rx, "lastIndex", previousLastIndex, true).
+    regexp.lastIndex = previousLastIndex;
+    // 8. If result is null, return -1.
+    if (result === null)
+        return -1;
+    // 9. Return ? Get(result, "index").
+    return result.index;
+}
+
 function hasObservableSideEffectsForRegExpSplit(regexp) {
     // This is accessed by the RegExpExec internal function.
     let regexpExec = @tryGetById(regexp, "exec");
@@ -141,7 +175,7 @@ function hasObservableSideEffectsForRegExpSplit(regexp) {
     if (regexpSource !== @regExpProtoSourceGetter)
         return true;
     
-    return !@isRegExp(regexp);
+    return !@isRegExpObject(regexp);
 }
 
 // ES 21.2.5.11 RegExp.prototype[@@split](string, limit)
index dbd6300..807805e 100644 (file)
@@ -57,8 +57,8 @@ function search(regexp)
     }
 
     if (regexp != null) {
-         var searcher = regexp[@symbolSearch];
-         if (searcher != @undefined)
+        var searcher = regexp[@symbolSearch];
+        if (searcher != @undefined)
             return searcher.@call(regexp, this);
     }
 
index fb544fc..47989f6 100644 (file)
@@ -974,7 +974,8 @@ bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned clobberLimi
     case IsString:
     case IsObject:
     case IsObjectOrNull:
-    case IsFunction: {
+    case IsFunction:
+    case IsRegExpObject: {
         AbstractValue child = forNode(node->child1());
         if (child.value()) {
             bool constantWasSet = true;
@@ -1049,6 +1050,9 @@ bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned clobberLimi
                 } else
                     setConstant(node, jsBoolean(false));
                 break;
+            case IsRegExpObject:
+                setConstant(node, jsBoolean(child.value().isObject() && child.value().getObject()->type() == RegExpObjectType));
+                break;
             default:
                 constantWasSet = false;
                 break;
@@ -1191,6 +1195,21 @@ bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned clobberLimi
                 break;
             }
             break;
+
+        case IsRegExpObject:
+            // We don't have a SpeculatedType for Proxies yet so we can't do better at proving false.
+            if (!(child.m_type & ~SpecRegExpObject)) {
+                setConstant(node, jsBoolean(true));
+                constantWasSet = true;
+                break;
+            }
+            if (!(child.m_type & SpecObject)) {
+                setConstant(node, jsBoolean(false));
+                constantWasSet = true;
+                break;
+            }
+            break;
+
         default:
             break;
         }
index 1aa1d2c..f1014c8 100644 (file)
@@ -2242,6 +2242,15 @@ bool ByteCodeParser::handleIntrinsicCall(Node* callee, int resultOperand, Intrin
         return true;
     }
 
+    case IsRegExpObjectIntrinsic: {
+        ASSERT(argumentCountIncludingThis == 2);
+
+        insertChecks();
+        Node* isRegExpObject = addToGraph(IsRegExpObject, OpInfo(prediction), get(virtualRegisterForArgument(1, registerOffset)));
+        set(VirtualRegister(resultOperand), isRegExpObject);
+        return true;
+    }
+
     case StringPrototypeReplaceIntrinsic: {
         if (argumentCountIncludingThis != 3)
             return false;
index ad105c4..f1faa53 100644 (file)
@@ -160,6 +160,7 @@ void clobberize(Graph& graph, Node* node, const ReadFunctor& read, const WriteFu
     case IsNumber:
     case IsString:
     case IsObject:
+    case IsRegExpObject:
     case LogicalNot:
     case CheckInBounds:
     case DoubleRep:
index 6a64647..d2eed1b 100644 (file)
@@ -162,6 +162,7 @@ bool doesGC(Graph& graph, Node* node)
     case IsObject:
     case IsObjectOrNull:
     case IsFunction:
+    case IsRegExpObject:
     case TypeOf:
     case LogicalNot:
     case ToPrimitive:
index 20dcd0d..2d1cb0f 100644 (file)
@@ -1510,6 +1510,7 @@ private:
         case IsNumber:
         case IsObjectOrNull:
         case IsFunction:
+        case IsRegExpObject:
         case CreateDirectArguments:
         case CreateClonedArguments:
         case Jump:
index bcbfe1b..39c5273 100644 (file)
@@ -309,6 +309,7 @@ namespace JSC { namespace DFG {
     macro(IsObject, NodeResultBoolean) \
     macro(IsObjectOrNull, NodeResultBoolean) \
     macro(IsFunction, NodeResultBoolean) \
+    macro(IsRegExpObject, NodeResultBoolean) \
     macro(TypeOf, NodeResultJS) \
     macro(LogicalNot, NodeResultBoolean) \
     macro(ToPrimitive, NodeResultJS | NodeMustGenerate) \
index 844c749..758aed1 100644 (file)
@@ -431,7 +431,8 @@ private:
         case IsString:
         case IsObject:
         case IsObjectOrNull:
-        case IsFunction: {
+        case IsFunction:
+        case IsRegExpObject: {
             changed |= setPrediction(SpecBoolean);
             break;
         }
index 2204849..49a1d23 100644 (file)
@@ -262,6 +262,7 @@ bool safeToExecute(AbstractStateType& state, Graph& graph, Node* node)
     case IsObject:
     case IsObjectOrNull:
     case IsFunction:
+    case IsRegExpObject:
     case TypeOf:
     case LogicalNot:
     case CallObjectConstructor:
index 954be07..7f7d0e7 100644 (file)
@@ -3425,6 +3425,30 @@ void SpeculativeJIT::compileIsArrayConstructor(Node* node)
     unblessedBooleanResult(resultGPR, node);
 }
 
+void SpeculativeJIT::compileIsRegExpObject(Node* node)
+{
+    JSValueOperand value(this, node->child1());
+    GPRFlushedCallResult result(this);
+
+    JSValueRegs valueRegs = value.jsValueRegs();
+    GPRReg resultGPR = result.gpr();
+
+    JITCompiler::Jump isNotCell = m_jit.branchIfNotCell(valueRegs);
+
+    m_jit.compare8(JITCompiler::Equal,
+        JITCompiler::Address(valueRegs.payloadGPR(), JSCell::typeInfoTypeOffset()),
+        TrustedImm32(RegExpObjectType),
+        resultGPR);
+    blessBoolean(resultGPR);
+    JITCompiler::Jump done = m_jit.jump();
+
+    isNotCell.link(&m_jit);
+    moveFalseTo(resultGPR);
+
+    done.link(&m_jit);
+    blessedBooleanResult(resultGPR, node);
+}
+
 void SpeculativeJIT::compileCallObjectConstructor(Node* node)
 {
     RELEASE_ASSERT(node->child1().useKind() == UntypedUse);
index 1a5fdb0..67d8c7c 100644 (file)
@@ -737,6 +737,7 @@ public:
     void compileIsJSArray(Node*);
     void compileIsArrayConstructor(Node*);
     void compileIsArrayObject(Node*);
+    void compileIsRegExpObject(Node*);
     
     void emitCall(Node*);
     
index 6a70a68..f89928f 100644 (file)
@@ -4529,6 +4529,12 @@ void SpeculativeJIT::compile(Node* node)
         compileIsFunction(node);
         break;
     }
+
+    case IsRegExpObject: {
+        compileIsRegExpObject(node);
+        break;
+    }
+
     case TypeOf: {
         compileTypeOf(node);
         break;
index 2be27da..6f01fa3 100644 (file)
@@ -4542,6 +4542,11 @@ void SpeculativeJIT::compile(Node* node)
         break;
     }
 
+    case IsRegExpObject: {
+        compileIsRegExpObject(node);
+        break;
+    }
+
     case TypeOf: {
         compileTypeOf(node);
         break;
index 3a8a7d3..3ec50d5 100644 (file)
@@ -186,6 +186,7 @@ inline CapabilityLevel canCompile(Node* node)
     case IsObject:
     case IsObjectOrNull:
     case IsFunction:
+    case IsRegExpObject:
     case CheckTypeInfoFlags:
     case OverridesHasInstance:
     case InstanceOf:
index 31aff66..28b7902 100644 (file)
@@ -870,6 +870,9 @@ private:
         case IsFunction:
             compileIsFunction();
             break;
+        case IsRegExpObject:
+            compileIsRegExpObject();
+            break;
         case TypeOf:
             compileTypeOf();
             break;
@@ -5902,7 +5905,26 @@ private:
             m_out.boolean, notCellResult, functionResult, objectResult, slowResult);
         setBoolean(result);
     }
-    
+
+    void compileIsRegExpObject()
+    {
+        LValue value = lowJSValue(m_node->child1());
+
+        LBasicBlock isCellCase = m_out.newBlock();
+        LBasicBlock continuation = m_out.newBlock();
+
+        ValueFromBlock notCellResult = m_out.anchor(m_out.booleanFalse);
+        m_out.branch(
+            isCell(value, provenType(m_node->child1())), unsure(isCellCase), unsure(continuation));
+
+        LBasicBlock lastNext = m_out.appendTo(isCellCase, continuation);
+        ValueFromBlock cellResult = m_out.anchor(isRegExpObject(value, provenType(m_node->child1())));
+        m_out.jump(continuation);
+
+        m_out.appendTo(continuation, lastNext);
+        setBoolean(m_out.phi(m_out.boolean, notCellResult, cellResult));
+    }
+
     void compileTypeOf()
     {
         Edge child = m_node->child1();
@@ -9950,7 +9972,16 @@ private:
             m_out.load8ZeroExt32(cell, m_heaps.JSCell_typeInfoFlags),
             m_out.constInt32(MasqueradesAsUndefined | TypeOfShouldCallGetCallData));
     }
-    
+
+    LValue isRegExpObject(LValue cell, SpeculatedType type = SpecFullTop)
+    {
+        if (LValue proven = isProvenValue(type & SpecCell, SpecRegExpObject))
+            return proven;
+        return m_out.equal(
+            m_out.load8ZeroExt32(cell, m_heaps.JSCell_typeInfoType),
+            m_out.constInt32(RegExpObjectType));
+    }
+
     LValue isType(LValue cell, JSType type)
     {
         return m_out.equal(
index 4eccbee..1ec7963 100644 (file)
     macro(isJSArray) \
     macro(isArrayConstructor) \
     macro(isConstructor) \
-    macro(isRegExp) \
+    macro(isRegExpObject) \
     macro(concatMemcpy) \
     macro(appendMemcpy) \
     macro(predictFinalLengthFromArgumunts) \
     macro(regExpProtoSourceGetter) \
     macro(regExpProtoStickyGetter) \
     macro(regExpProtoUnicodeGetter) \
+    macro(regExpSearchFast) \
     macro(regExpSplitFast) \
     macro(stringIncludesInternal) \
     macro(stringSplitFast) \
index 47780d7..0aab6c7 100644 (file)
 #include "CallFrame.h"
 #include "ConstructData.h"
 #include "JSCJSValueInlines.h"
-#include "ProxyObject.h"
 #include "RegExpObject.h"
 
 namespace JSC {
 
 EncodedJSValue JSC_HOST_CALL esSpecIsConstructor(ExecState* exec)
 {
-    bool isConstructor = exec->argument(0).isConstructor();
+    bool isConstructor = exec->uncheckedArgument(0).isConstructor();
     return JSValue::encode(jsBoolean(isConstructor));
 }
 
-EncodedJSValue JSC_HOST_CALL esSpecIsRegExp(ExecState* exec)
+EncodedJSValue JSC_HOST_CALL esSpecIsRegExpObject(ExecState* exec)
 {
-    bool isRegExp = exec->argument(0).inherits(RegExpObject::info());
-    return JSValue::encode(jsBoolean(isRegExp));
+    JSValue value = exec->uncheckedArgument(0);
+    if (value.isObject())
+        return JSValue::encode(jsBoolean(value.getObject()->type() == RegExpObjectType));
+    return JSValue::encode(jsBoolean(false));
 }
 
 } // namespace JSC
index f6ea59c..ce1e070 100644 (file)
@@ -31,7 +31,7 @@
 namespace JSC {
 
 EncodedJSValue JSC_HOST_CALL esSpecIsConstructor(ExecState*);
-EncodedJSValue JSC_HOST_CALL esSpecIsRegExp(ExecState*);
+EncodedJSValue JSC_HOST_CALL esSpecIsRegExpObject(ExecState*);
 
 } // namespace JSC
 
index b8e6623..9194df9 100644 (file)
@@ -60,6 +60,7 @@ enum JS_EXPORT_PRIVATE Intrinsic {
     IsArrayIntrinsic,
     IsArrayConstructorIntrinsic,
     IsJSArrayIntrinsic,
+    IsRegExpObjectIntrinsic,
 
     // Getter intrinsics.
     TypedArrayLengthIntrinsic,
index e4a3572..3e3f7c7 100644 (file)
@@ -632,7 +632,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
 #endif // ENABLE(INTL)
 
         GlobalPropertyInfo(vm.propertyNames->isConstructorPrivateName, JSFunction::create(vm, this, 1, String(), esSpecIsConstructor, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
-        GlobalPropertyInfo(vm.propertyNames->isRegExpPrivateName, JSFunction::create(vm, this, 1, String(), esSpecIsRegExp, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames->isRegExpObjectPrivateName, JSFunction::create(vm, this, 1, String(), esSpecIsRegExpObject, IsRegExpObjectIntrinsic), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().speciesConstructorPrivateName(), JSFunction::createBuiltinFunction(vm, globalObjectSpeciesConstructorCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
 
         GlobalPropertyInfo(vm.propertyNames->regExpProtoFlagsGetterPrivateName, regExpProtoFlagsGetterObject, DontEnum | DontDelete | ReadOnly),
@@ -648,6 +648,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
         GlobalPropertyInfo(vm.propertyNames->builtinNames().hasObservableSideEffectsForRegExpSplitPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeHasObservableSideEffectsForRegExpSplitCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().advanceStringIndexPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeAdvanceStringIndexCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().regExpExecPrivateName(), JSFunction::createBuiltinFunction(vm, regExpPrototypeRegExpExecCodeGenerator(vm), this), DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames->regExpSearchFastPrivateName, JSFunction::create(vm, this, 2, String(), regExpProtoFuncSearchFast), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->regExpSplitFastPrivateName, JSFunction::create(vm, this, 2, String(), regExpProtoFuncSplitFast), DontEnum | DontDelete | ReadOnly),
 
         // String.prototype helpers.
index 4baa633..d796fba 100644 (file)
@@ -49,7 +49,6 @@ static EncodedJSValue JSC_HOST_CALL regExpProtoFuncExec(ExecState*);
 static EncodedJSValue JSC_HOST_CALL regExpProtoFuncMatchPrivate(ExecState*);
 static EncodedJSValue JSC_HOST_CALL regExpProtoFuncCompile(ExecState*);
 static EncodedJSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState*);
-static EncodedJSValue JSC_HOST_CALL regExpProtoFuncSearch(ExecState*);
 static EncodedJSValue JSC_HOST_CALL regExpProtoGetterGlobal(ExecState*);
 static EncodedJSValue JSC_HOST_CALL regExpProtoGetterIgnoreCase(ExecState*);
 static EncodedJSValue JSC_HOST_CALL regExpProtoGetterMultiline(ExecState*);
@@ -81,7 +80,7 @@ void RegExpPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
     JSC_NATIVE_GETTER(vm.propertyNames->flags, regExpProtoGetterFlags, DontEnum | Accessor);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().matchPrivateName(), regExpProtoFuncMatchPrivate, DontEnum | DontDelete | ReadOnly, 1);
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->matchSymbol, regExpPrototypeMatchCodeGenerator, DontEnum);
-    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->searchSymbol, regExpProtoFuncSearch, DontEnum, 1);
+    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->searchSymbol, regExpPrototypeSearchCodeGenerator, DontEnum);
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->splitSymbol, regExpPrototypeSplitCodeGenerator, DontEnum);
 
     JSFunction* execFunction = JSFunction::create(vm, globalObject, 1, vm.propertyNames->exec.string(), regExpProtoFuncExec, RegExpExecIntrinsic);
@@ -419,20 +418,19 @@ EncodedJSValue JSC_HOST_CALL regExpProtoGetterSource(ExecState* exec)
     return JSValue::encode(regExpProtoGetterSourceInternal(exec, pattern, pattern.characters16(), pattern.length()));
 }
 
-EncodedJSValue JSC_HOST_CALL regExpProtoFuncSearch(ExecState* exec)
+EncodedJSValue JSC_HOST_CALL regExpProtoFuncSearchFast(ExecState* exec)
 {
+    VM& vm = exec->vm();
     JSValue thisValue = exec->thisValue();
-    if (!thisValue.inherits(RegExpObject::info()))
-        return throwVMTypeError(exec);
     RegExp* regExp = asRegExpObject(thisValue)->regExp();
 
-    JSString* string = exec->argument(0).toString(exec);
+    JSString* string = exec->uncheckedArgument(0).toString(exec);
     String s = string->value(exec);
-    if (exec->hadException())
+    if (vm.exception())
         return JSValue::encode(jsUndefined());
 
     RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
-    MatchResult result = regExpConstructor->performMatch(exec->vm(), regExp, string, s, 0);
+    MatchResult result = regExpConstructor->performMatch(vm, regExp, string, s, 0);
     return JSValue::encode(result ? jsNumber(result.start) : jsNumber(-1));
 }
 
index cc68126..d73eea3 100644 (file)
@@ -58,6 +58,7 @@ private:
     WriteBarrier<RegExp> m_emptyRegExp;
 };
 
+EncodedJSValue JSC_HOST_CALL regExpProtoFuncSearchFast(ExecState*);
 EncodedJSValue JSC_HOST_CALL regExpProtoFuncSplitFast(ExecState*);
 
 } // namespace JSC
index 4ef9855..2b68cb8 100644 (file)
 - 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
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_internal_get_calls_RegExp.prototype[Symbol.split].js
   cmd: runES6 :normal
 - path: es6/Proxy_internal_get_calls_RegExp_constructor.js
index 2fd34ac..0c3936b 100644 (file)
@@ -59,7 +59,7 @@ var primitives = [
 for (var primitive of primitives) {
     shouldThrow(function () {
         RegExp.prototype[Symbol.search].call(primitive)
-    }, 'TypeError: Type error');
+    }, 'TypeError: RegExp.prototype.@@search requires that |this| be an Object');
 }
 
 shouldThrow(function () {