Diff
Modified: trunk/LayoutTests/ChangeLog (89945 => 89946)
--- trunk/LayoutTests/ChangeLog 2011-06-28 18:31:19 UTC (rev 89945)
+++ trunk/LayoutTests/ChangeLog 2011-06-28 18:35:37 UTC (rev 89946)
@@ -1,3 +1,17 @@
+2011-06-28 Gavin Barraclough <[email protected]>
+
+ Reviewed by Oliver Hunt.
+
+ https://bugs.webkit.org/show_bug.cgi?id=55040
+ RegExp constructor returns the argument regexp instead of a new object
+
+ Per 15.10.3.1, our current behaviour is correct if called as a function,
+ but incorrect when called as a constructor.
+
+ * fast/regex/constructor-expected.txt: Added.
+ * fast/regex/constructor.html: Added.
+ * fast/regex/script-tests/constructor.js: Added.
+
2011-06-28 Jessie Berlin <[email protected]>
Better Windows rebaseline for the changes in r89864, with pixel results, to get the bots
Added: trunk/LayoutTests/fast/regex/constructor-expected.txt (0 => 89946)
--- trunk/LayoutTests/fast/regex/constructor-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/regex/constructor-expected.txt 2011-06-28 18:35:37 UTC (rev 89946)
@@ -0,0 +1,13 @@
+This test checks use of the regexp constructor.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS re === RegExp(re) is true
+PASS re !== new RegExp(re) is true
+PASS re === RegExp(re,'i') threw exception TypeError: Cannot supply flags when constructing one RegExp from another..
+PASS re !== new RegExp(re,'i') threw exception TypeError: Cannot supply flags when constructing one RegExp from another..
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/regex/constructor.html (0 => 89946)
--- trunk/LayoutTests/fast/regex/constructor.html (rev 0)
+++ trunk/LayoutTests/fast/regex/constructor.html 2011-06-28 18:35:37 UTC (rev 89946)
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src=""
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/fast/regex/script-tests/constructor.js (0 => 89946)
--- trunk/LayoutTests/fast/regex/script-tests/constructor.js (rev 0)
+++ trunk/LayoutTests/fast/regex/script-tests/constructor.js 2011-06-28 18:35:37 UTC (rev 89946)
@@ -0,0 +1,11 @@
+description("This test checks use of the regexp constructor.");
+
+var re = /abc/;
+
+shouldBeTrue("re === RegExp(re)");
+shouldBeTrue("re !== new RegExp(re)");
+shouldThrow("re === RegExp(re,'i')");
+shouldThrow("re !== new RegExp(re,'i')");
+
+var successfullyParsed = true;
+
Modified: trunk/Source/_javascript_Core/ChangeLog (89945 => 89946)
--- trunk/Source/_javascript_Core/ChangeLog 2011-06-28 18:31:19 UTC (rev 89945)
+++ trunk/Source/_javascript_Core/ChangeLog 2011-06-28 18:35:37 UTC (rev 89946)
@@ -1,3 +1,18 @@
+2011-06-28 Gavin Barraclough <[email protected]>
+
+ Reviewed by Oliver Hunt.
+
+ https://bugs.webkit.org/show_bug.cgi?id=55040
+ RegExp constructor returns the argument regexp instead of a new object
+
+ Per 15.10.3.1, our current behaviour is correct if called as a function,
+ but incorrect when called as a constructor.
+
+ * runtime/RegExpConstructor.cpp:
+ (JSC::constructRegExp):
+ (JSC::constructWithRegExpConstructor):
+ * runtime/RegExpConstructor.h:
+
2011-06-28 Luke Macpherson <[email protected]>
Reviewed by Darin Adler.
Modified: trunk/Source/_javascript_Core/runtime/RegExpConstructor.cpp (89945 => 89946)
--- trunk/Source/_javascript_Core/runtime/RegExpConstructor.cpp 2011-06-28 18:31:19 UTC (rev 89945)
+++ trunk/Source/_javascript_Core/runtime/RegExpConstructor.cpp 2011-06-28 18:35:37 UTC (rev 89946)
@@ -293,7 +293,7 @@
}
// ECMA 15.10.4
-JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args)
+JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, bool callAsConstructor)
{
JSValue arg0 = args.at(0);
JSValue arg1 = args.at(1);
@@ -301,6 +301,11 @@
if (arg0.inherits(&RegExpObject::s_info)) {
if (!arg1.isUndefined())
return throwError(exec, createTypeError(exec, "Cannot supply flags when constructing one RegExp from another."));
+ // If called as a function, this just returns the first argument (see 15.10.3.1).
+ if (callAsConstructor) {
+ RegExp* regExp = static_cast<RegExpObject*>(asObject(arg0))->regExp();
+ return new (exec) RegExpObject(globalObject, globalObject->regExpStructure(), regExp);
+ }
return asObject(arg0);
}
@@ -326,7 +331,7 @@
static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)
{
ArgList args(exec);
- return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args));
+ return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, true));
}
ConstructType RegExpConstructor::getConstructData(ConstructData& constructData)
Modified: trunk/Source/_javascript_Core/runtime/RegExpConstructor.h (89945 => 89946)
--- trunk/Source/_javascript_Core/runtime/RegExpConstructor.h 2011-06-28 18:31:19 UTC (rev 89945)
+++ trunk/Source/_javascript_Core/runtime/RegExpConstructor.h 2011-06-28 18:35:37 UTC (rev 89946)
@@ -96,7 +96,7 @@
RegExpConstructor* asRegExpConstructor(JSValue);
- JSObject* constructRegExp(ExecState*, JSGlobalObject*, const ArgList&);
+ JSObject* constructRegExp(ExecState*, JSGlobalObject*, const ArgList&, bool callAsConstructor = false);
inline RegExpConstructor* asRegExpConstructor(JSValue value)
{