Diff
Modified: trunk/LayoutTests/ChangeLog (199747 => 199748)
--- trunk/LayoutTests/ChangeLog 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/LayoutTests/ChangeLog 2016-04-20 00:02:07 UTC (rev 199748)
@@ -1,3 +1,32 @@
+2016-04-19 Mark Lam <[email protected]>
+
+ Re-landing: 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-19 Alex Christensen <[email protected]>
Rebase test after r199738
Added: trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects-expected.txt (0 => 199748)
--- trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects-expected.txt (rev 0)
+++ trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects-expected.txt 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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
+
Added: trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects.html (0 => 199748)
--- trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects.html (rev 0)
+++ trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects.html 2016-04-20 00:02:07 UTC (rev 199748)
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</body>
+</html>
+
Added: trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2-expected.txt (0 => 199748)
--- trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2-expected.txt (rev 0)
+++ trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2-expected.txt 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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
+
Added: trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2.html (0 => 199748)
--- trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2.html (rev 0)
+++ trunk/LayoutTests/js/regress/regexp-prototype-search-observable-side-effects2.html 2016-04-20 00:02:07 UTC (rev 199748)
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</body>
+</html>
+
Added: trunk/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects.js (0 => 199748)
--- trunk/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects.js (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects.js 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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");
+})();
Added: trunk/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects2.js (0 => 199748)
--- trunk/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects2.js (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/regexp-prototype-search-observable-side-effects2.js 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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");
+})();
+
Added: trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects.js (0 => 199748)
--- trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects.js (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects.js 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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");
+})();
Added: trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects2.js (0 => 199748)
--- trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects2.js (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects2.js 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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 });
+})();
Added: trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects3.js (0 => 199748)
--- trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects3.js (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects3.js 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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 });
+})();
Added: trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects4.js (0 => 199748)
--- trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects4.js (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/string-prototype-search-observable-side-effects4.js 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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");
+})();
Added: trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects-expected.txt (0 => 199748)
--- trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects-expected.txt (rev 0)
+++ trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects-expected.txt 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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
+
Added: trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects.html (0 => 199748)
--- trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects.html (rev 0)
+++ trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects.html 2016-04-20 00:02:07 UTC (rev 199748)
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</body>
+</html>
+
Added: trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects2-expected.txt (0 => 199748)
--- trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects2-expected.txt (rev 0)
+++ trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects2-expected.txt 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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
+
Added: trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects2.html (0 => 199748)
--- trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects2.html (rev 0)
+++ trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects2.html 2016-04-20 00:02:07 UTC (rev 199748)
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</body>
+</html>
+
Added: trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects3-expected.txt (0 => 199748)
--- trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects3-expected.txt (rev 0)
+++ trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects3-expected.txt 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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
+
Added: trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects3.html (0 => 199748)
--- trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects3.html (rev 0)
+++ trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects3.html 2016-04-20 00:02:07 UTC (rev 199748)
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</body>
+</html>
+
Added: trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects4-expected.txt (0 => 199748)
--- trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects4-expected.txt (rev 0)
+++ trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects4-expected.txt 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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
+
Added: trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects4.html (0 => 199748)
--- trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects4.html (rev 0)
+++ trunk/LayoutTests/js/regress/string-prototype-search-observable-side-effects4.html 2016-04-20 00:02:07 UTC (rev 199748)
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</body>
+</html>
+
Modified: trunk/Source/_javascript_Core/ChangeLog (199747 => 199748)
--- trunk/Source/_javascript_Core/ChangeLog 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-04-20 00:02:07 UTC (rev 199748)
@@ -1,5 +1,88 @@
2016-04-19 Mark Lam <[email protected]>
+ Re-landing: 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-19 Mark Lam <[email protected]>
+
Replace $vm.printValue() with $vm.value().
https://bugs.webkit.org/show_bug.cgi?id=156767
Modified: trunk/Source/_javascript_Core/builtins/RegExpPrototype.js (199747 => 199748)
--- trunk/Source/_javascript_Core/builtins/RegExpPrototype.js 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/builtins/RegExpPrototype.js 2016-04-20 00:02:07 UTC (rev 199748)
@@ -108,6 +108,40 @@
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 @@
if (regexpSource !== @regExpProtoSourceGetter)
return true;
- return !@isRegExp(regexp);
+ return !@isRegExpObject(regexp);
}
// ES 21.2.5.11 RegExp.prototype[@@split](string, limit)
Modified: trunk/Source/_javascript_Core/builtins/StringPrototype.js (199747 => 199748)
--- trunk/Source/_javascript_Core/builtins/StringPrototype.js 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/builtins/StringPrototype.js 2016-04-20 00:02:07 UTC (rev 199748)
@@ -57,8 +57,8 @@
}
if (regexp != null) {
- var searcher = regexp[@symbolSearch];
- if (searcher != @undefined)
+ var searcher = regexp[@symbolSearch];
+ if (searcher != @undefined)
return searcher.@call(regexp, this);
}
Modified: trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h 2016-04-20 00:02:07 UTC (rev 199748)
@@ -988,7 +988,8 @@
case IsString:
case IsObject:
case IsObjectOrNull:
- case IsFunction: {
+ case IsFunction:
+ case IsRegExpObject: {
AbstractValue child = forNode(node->child1());
if (child.value()) {
bool constantWasSet = true;
@@ -1063,6 +1064,9 @@
} else
setConstant(node, jsBoolean(false));
break;
+ case IsRegExpObject:
+ setConstant(node, jsBoolean(child.value().isObject() && child.value().getObject()->type() == RegExpObjectType));
+ break;
default:
constantWasSet = false;
break;
@@ -1205,6 +1209,21 @@
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;
}
Modified: trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -2244,6 +2244,15 @@
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;
Modified: trunk/Source/_javascript_Core/dfg/DFGClobberize.h (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGClobberize.h 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGClobberize.h 2016-04-20 00:02:07 UTC (rev 199748)
@@ -160,6 +160,7 @@
case IsNumber:
case IsString:
case IsObject:
+ case IsRegExpObject:
case LogicalNot:
case CheckInBounds:
case DoubleRep:
Modified: trunk/Source/_javascript_Core/dfg/DFGDoesGC.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGDoesGC.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGDoesGC.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -163,6 +163,7 @@
case IsObject:
case IsObjectOrNull:
case IsFunction:
+ case IsRegExpObject:
case TypeOf:
case LogicalNot:
case ToPrimitive:
Modified: trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -1530,6 +1530,7 @@
case IsNumber:
case IsObjectOrNull:
case IsFunction:
+ case IsRegExpObject:
case CreateDirectArguments:
case CreateClonedArguments:
case Jump:
Modified: trunk/Source/_javascript_Core/dfg/DFGNodeType.h (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGNodeType.h 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGNodeType.h 2016-04-20 00:02:07 UTC (rev 199748)
@@ -313,6 +313,7 @@
macro(IsObject, NodeResultBoolean) \
macro(IsObjectOrNull, NodeResultBoolean) \
macro(IsFunction, NodeResultBoolean) \
+ macro(IsRegExpObject, NodeResultBoolean) \
macro(TypeOf, NodeResultJS) \
macro(LogicalNot, NodeResultBoolean) \
macro(ToPrimitive, NodeResultJS | NodeMustGenerate) \
Modified: trunk/Source/_javascript_Core/dfg/DFGPredictionPropagationPhase.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGPredictionPropagationPhase.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGPredictionPropagationPhase.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -437,7 +437,8 @@
case IsString:
case IsObject:
case IsObjectOrNull:
- case IsFunction: {
+ case IsFunction:
+ case IsRegExpObject: {
changed |= setPrediction(SpecBoolean);
break;
}
Modified: trunk/Source/_javascript_Core/dfg/DFGSafeToExecute.h (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGSafeToExecute.h 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGSafeToExecute.h 2016-04-20 00:02:07 UTC (rev 199748)
@@ -263,6 +263,7 @@
case IsObject:
case IsObjectOrNull:
case IsFunction:
+ case IsRegExpObject:
case TypeOf:
case LogicalNot:
case CallObjectConstructor:
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -3442,6 +3442,30 @@
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);
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h 2016-04-20 00:02:07 UTC (rev 199748)
@@ -738,6 +738,7 @@
void compileIsJSArray(Node*);
void compileIsArrayConstructor(Node*);
void compileIsArrayObject(Node*);
+ void compileIsRegExpObject(Node*);
void emitCall(Node*);
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -4535,6 +4535,12 @@
compileIsFunction(node);
break;
}
+
+ case IsRegExpObject: {
+ compileIsRegExpObject(node);
+ break;
+ }
+
case TypeOf: {
compileTypeOf(node);
break;
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -4563,6 +4563,11 @@
break;
}
+ case IsRegExpObject: {
+ compileIsRegExpObject(node);
+ break;
+ }
+
case TypeOf: {
compileTypeOf(node);
break;
Modified: trunk/Source/_javascript_Core/ftl/FTLCapabilities.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/ftl/FTLCapabilities.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/ftl/FTLCapabilities.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -186,6 +186,7 @@
case IsObject:
case IsObjectOrNull:
case IsFunction:
+ case IsRegExpObject:
case CheckTypeInfoFlags:
case OverridesHasInstance:
case InstanceOf:
Modified: trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -870,6 +870,9 @@
case IsFunction:
compileIsFunction();
break;
+ case IsRegExpObject:
+ compileIsRegExpObject();
+ break;
case TypeOf:
compileTypeOf();
break;
@@ -5925,7 +5928,26 @@
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();
@@ -9998,7 +10020,16 @@
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(
Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h (199747 => 199748)
--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2016-04-20 00:02:07 UTC (rev 199748)
@@ -415,7 +415,7 @@
macro(isJSArray) \
macro(isArrayConstructor) \
macro(isConstructor) \
- macro(isRegExp) \
+ macro(isRegExpObject) \
macro(concatMemcpy) \
macro(appendMemcpy) \
macro(predictFinalLengthFromArgumunts) \
@@ -434,6 +434,7 @@
macro(regExpProtoSourceGetter) \
macro(regExpProtoStickyGetter) \
macro(regExpProtoUnicodeGetter) \
+ macro(regExpSearchFast) \
macro(regExpSplitFast) \
macro(stringIncludesInternal) \
macro(stringSplitFast) \
Modified: trunk/Source/_javascript_Core/runtime/ECMAScriptSpecInternalFunctions.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/runtime/ECMAScriptSpecInternalFunctions.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/runtime/ECMAScriptSpecInternalFunctions.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -29,21 +29,22 @@
#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
Modified: trunk/Source/_javascript_Core/runtime/ECMAScriptSpecInternalFunctions.h (199747 => 199748)
--- trunk/Source/_javascript_Core/runtime/ECMAScriptSpecInternalFunctions.h 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/runtime/ECMAScriptSpecInternalFunctions.h 2016-04-20 00:02:07 UTC (rev 199748)
@@ -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
Modified: trunk/Source/_javascript_Core/runtime/Intrinsic.h (199747 => 199748)
--- trunk/Source/_javascript_Core/runtime/Intrinsic.h 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/runtime/Intrinsic.h 2016-04-20 00:02:07 UTC (rev 199748)
@@ -60,6 +60,7 @@
IsArrayIntrinsic,
IsArrayConstructorIntrinsic,
IsJSArrayIntrinsic,
+ IsRegExpObjectIntrinsic,
// Getter intrinsics.
TypedArrayLengthIntrinsic,
Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -634,7 +634,7 @@
#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),
@@ -650,6 +650,7 @@
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.
Modified: trunk/Source/_javascript_Core/runtime/RegExpPrototype.cpp (199747 => 199748)
--- trunk/Source/_javascript_Core/runtime/RegExpPrototype.cpp 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/runtime/RegExpPrototype.cpp 2016-04-20 00:02:07 UTC (rev 199748)
@@ -49,7 +49,6 @@
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 @@
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);
@@ -437,20 +436,19 @@
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));
}
Modified: trunk/Source/_javascript_Core/runtime/RegExpPrototype.h (199747 => 199748)
--- trunk/Source/_javascript_Core/runtime/RegExpPrototype.h 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/runtime/RegExpPrototype.h 2016-04-20 00:02:07 UTC (rev 199748)
@@ -58,6 +58,7 @@
WriteBarrier<RegExp> m_emptyRegExp;
};
+EncodedJSValue JSC_HOST_CALL regExpProtoFuncSearchFast(ExecState*);
EncodedJSValue JSC_HOST_CALL regExpProtoFuncSplitFast(ExecState*);
} // namespace JSC
Modified: trunk/Source/_javascript_Core/tests/es6.yaml (199747 => 199748)
--- trunk/Source/_javascript_Core/tests/es6.yaml 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/tests/es6.yaml 2016-04-20 00:02:07 UTC (rev 199748)
@@ -1005,7 +1005,7 @@
- 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
Modified: trunk/Source/_javascript_Core/tests/stress/regexp-search.js (199747 => 199748)
--- trunk/Source/_javascript_Core/tests/stress/regexp-search.js 2016-04-19 23:41:25 UTC (rev 199747)
+++ trunk/Source/_javascript_Core/tests/stress/regexp-search.js 2016-04-20 00:02:07 UTC (rev 199748)
@@ -59,7 +59,7 @@
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 () {