<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[199106] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/199106">199106</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2016-04-06 11:26:11 -0700 (Wed, 06 Apr 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>RegExp constructor should use Symbol.match and other properties
https://bugs.webkit.org/show_bug.cgi?id=155873
Reviewed by Michael Saboff.
Source/JavaScriptCore:
This patch updates the behavior of the RegExp constructor. Now the constructor
should get the Symbol.match property and check if it exists to decide if something
should be constructed like a regexp object.
* runtime/RegExpConstructor.cpp:
(JSC::toFlags):
(JSC::constructRegExp):
(JSC::constructWithRegExpConstructor):
(JSC::callRegExpConstructor):
* runtime/RegExpConstructor.h:
* tests/stress/regexp-constructor.js: Added.
(assert):
(throw.new.Error.get let):
(throw.new.Error.):
(throw.new.Error.get re):
LayoutTests:
Fix test for new behavior.
* fast/regex/constructor-expected.txt:
* fast/regex/script-tests/constructor.js:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastregexconstructorexpectedtxt">trunk/LayoutTests/fast/regex/constructor-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastregexscripttestsconstructorjs">trunk/LayoutTests/fast/regex/script-tests/constructor.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeRegExpConstructorcpp">trunk/Source/JavaScriptCore/runtime/RegExpConstructor.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeRegExpConstructorh">trunk/Source/JavaScriptCore/runtime/RegExpConstructor.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (199105 => 199106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-04-06 17:44:42 UTC (rev 199105)
+++ trunk/LayoutTests/ChangeLog        2016-04-06 18:26:11 UTC (rev 199106)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-04-06 Keith Miller <keith_miller@apple.com>
+
+ RegExp constructor should use Symbol.match and other properties
+ https://bugs.webkit.org/show_bug.cgi?id=155873
+
+ Reviewed by Michael Saboff.
+
+ Fix test for new behavior.
+
+ * fast/regex/constructor-expected.txt:
+ * fast/regex/script-tests/constructor.js:
+
</ins><span class="cx"> 2016-04-06 Zalan Bujtas <zalan@apple.com>
</span><span class="cx">
</span><span class="cx"> ASSERTION FAILED: !floatingObject->originatingLine() in WebCore::RenderBlockFlow::linkToEndLineIfNeeded
</span></span></pre></div>
<a id="trunkLayoutTestsfastregexconstructorexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/regex/constructor-expected.txt (199105 => 199106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/regex/constructor-expected.txt        2016-04-06 17:44:42 UTC (rev 199105)
+++ trunk/LayoutTests/fast/regex/constructor-expected.txt        2016-04-06 18:26:11 UTC (rev 199106)
</span><span class="lines">@@ -5,7 +5,7 @@
</span><span class="cx">
</span><span class="cx"> PASS re === RegExp(re) is true
</span><span class="cx"> PASS re !== new RegExp(re) is true
</span><del>-PASS re === RegExp(re,'i') is true
</del><ins>+PASS re !== RegExp(re,'i') is true
</ins><span class="cx"> PASS re !== new RegExp(re,'i') is true
</span><span class="cx"> PASS successfullyParsed is true
</span><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsfastregexscripttestsconstructorjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/regex/script-tests/constructor.js (199105 => 199106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/regex/script-tests/constructor.js        2016-04-06 17:44:42 UTC (rev 199105)
+++ trunk/LayoutTests/fast/regex/script-tests/constructor.js        2016-04-06 18:26:11 UTC (rev 199106)
</span><span class="lines">@@ -4,6 +4,6 @@
</span><span class="cx">
</span><span class="cx"> shouldBeTrue("re === RegExp(re)");
</span><span class="cx"> shouldBeTrue("re !== new RegExp(re)");
</span><del>-shouldBeTrue("re === RegExp(re,'i')");
</del><ins>+shouldBeTrue("re !== RegExp(re,'i')");
</ins><span class="cx"> shouldBeTrue("re !== new RegExp(re,'i')");
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (199105 => 199106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-04-06 17:44:42 UTC (rev 199105)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-04-06 18:26:11 UTC (rev 199106)
</span><span class="lines">@@ -1,5 +1,28 @@
</span><span class="cx"> 2016-04-06 Keith Miller <keith_miller@apple.com>
</span><span class="cx">
</span><ins>+ RegExp constructor should use Symbol.match and other properties
+ https://bugs.webkit.org/show_bug.cgi?id=155873
+
+ Reviewed by Michael Saboff.
+
+ This patch updates the behavior of the RegExp constructor. Now the constructor
+ should get the Symbol.match property and check if it exists to decide if something
+ should be constructed like a regexp object.
+
+ * runtime/RegExpConstructor.cpp:
+ (JSC::toFlags):
+ (JSC::constructRegExp):
+ (JSC::constructWithRegExpConstructor):
+ (JSC::callRegExpConstructor):
+ * runtime/RegExpConstructor.h:
+ * tests/stress/regexp-constructor.js: Added.
+ (assert):
+ (throw.new.Error.get let):
+ (throw.new.Error.):
+ (throw.new.Error.get re):
+
+2016-04-06 Keith Miller <keith_miller@apple.com>
+
</ins><span class="cx"> We should support the ability to do a non-effectful getById
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=156116
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeRegExpConstructorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/RegExpConstructor.cpp (199105 => 199106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/RegExpConstructor.cpp        2016-04-06 17:44:42 UTC (rev 199105)
+++ trunk/Source/JavaScriptCore/runtime/RegExpConstructor.cpp        2016-04-06 18:26:11 UTC (rev 199106)
</span><span class="lines">@@ -96,7 +96,6 @@
</span><span class="cx"> Base::finishCreation(vm, ASCIILiteral("RegExp"));
</span><span class="cx"> ASSERT(inherits(info()));
</span><span class="cx">
</span><del>- // ECMA 15.10.5.1 RegExp.prototype
</del><span class="cx"> putDirectWithoutTransition(vm, vm.propertyNames->prototype, regExpPrototype, DontEnum | DontDelete | ReadOnly);
</span><span class="cx">
</span><span class="cx"> // no. of arguments for constructor
</span><span class="lines">@@ -260,47 +259,74 @@
</span><span class="cx"> return structure;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-// ECMA 15.10.4
-JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, JSValue newTarget)
</del><ins>+inline RegExpFlags toFlags(ExecState* exec, JSValue flags)
</ins><span class="cx"> {
</span><del>- JSValue arg0 = args.at(0);
- JSValue arg1 = args.at(1);
</del><ins>+ if (flags.isUndefined())
+ return NoFlags;
+ JSString* flagsString = flags.toString(exec);
+ if (!flagsString) {
+ ASSERT(exec->hadException());
+ return InvalidFlags;
+ }
</ins><span class="cx">
</span><ins>+ RegExpFlags result = regExpFlags(flagsString->value(exec));
+ if (exec->hadException())
+ return InvalidFlags;
+ if (result == InvalidFlags)
+ throwSyntaxError(exec, ASCIILiteral("Invalid flags supplied to RegExp constructor."));
+ return result;
+}
+
+JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, JSObject* callee, JSValue newTarget)
+{
</ins><span class="cx"> VM& vm = exec->vm();
</span><del>- RegExpFlags flags = NoFlags;
- bool haveFlags = false;
- if (!arg1.isUndefined()) {
- flags = regExpFlags(arg1.toString(exec)->value(exec));
</del><ins>+ JSValue patternArg = args.at(0);
+ JSValue flagsArg = args.at(1);
+
+ bool isPatternRegExp = patternArg.inherits(RegExpObject::info());
+ bool constructAsRegexp = isRegExp(vm, exec, patternArg);
+
+ if (newTarget.isUndefined() && constructAsRegexp && flagsArg.isUndefined()) {
+ JSValue constructor = patternArg.get(exec, vm.propertyNames->constructor);
</ins><span class="cx"> if (vm.exception())
</span><del>- return 0;
- if (flags == InvalidFlags)
- return vm.throwException(exec, createSyntaxError(exec, ASCIILiteral("Invalid flags supplied to RegExp constructor.")));
- haveFlags = true;
</del><ins>+ return nullptr;
+ if (callee == constructor) {
+ // We know that patternArg is a object otherwise constructAsRegexp would be false.
+ return patternArg.getObject();
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- if (arg0.inherits(RegExpObject::info())) {
- // If called as a function, this just returns the first argument (see 15.10.3.1).
- if (newTarget != jsUndefined()) {
- RegExp* regExp = static_cast<RegExpObject*>(asObject(arg0))->regExp();
- Structure* structure = getRegExpStructure(exec, globalObject, newTarget);
- if (vm.exception())
</del><ins>+ if (isPatternRegExp) {
+ RegExp* regExp = jsCast<RegExpObject*>(patternArg)->regExp();
+ Structure* structure = getRegExpStructure(exec, globalObject, newTarget);
+ if (exec->hadException())
+ return nullptr;
+
+ if (!flagsArg.isUndefined()) {
+ RegExpFlags flags = toFlags(exec, flagsArg);
+ if (flags == InvalidFlags)
</ins><span class="cx"> return nullptr;
</span><ins>+ regExp = RegExp::create(vm, regExp->pattern(), flags);
+ }
</ins><span class="cx">
</span><del>- if (haveFlags) {
- regExp = RegExp::create(vm, regExp->pattern(), flags);
- if (vm.exception())
- return nullptr;
- }
</del><ins>+ return RegExpObject::create(exec->vm(), structure, regExp);
+ }
</ins><span class="cx">
</span><del>- return RegExpObject::create(vm, structure, regExp);
- }
- return asObject(arg0);
</del><ins>+ if (constructAsRegexp) {
+ JSValue pattern = patternArg.get(exec, vm.propertyNames->source);
+ if (flagsArg.isUndefined())
+ flagsArg = patternArg.get(exec, vm.propertyNames->flags);
+ patternArg = pattern;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- String pattern = arg0.isUndefined() ? emptyString() : arg0.toString(exec)->value(exec);
- if (vm.exception())
- return 0;
</del><ins>+ String pattern = patternArg.isUndefined() ? emptyString() : patternArg.toString(exec)->value(exec);
+ if (exec->hadException())
+ return nullptr;
</ins><span class="cx">
</span><ins>+ RegExpFlags flags = toFlags(exec, flagsArg);
+ if (flags == InvalidFlags)
+ return nullptr;
+
</ins><span class="cx"> RegExp* regExp = RegExp::create(vm, pattern, flags);
</span><span class="cx"> if (!regExp->isValid())
</span><span class="cx"> return vm.throwException(exec, createSyntaxError(exec, regExp->errorMessage()));
</span><span class="lines">@@ -314,7 +340,7 @@
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> ArgList args(exec);
</span><del>- return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, exec->newTarget()));
</del><ins>+ return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, exec->callee(), exec->newTarget()));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> ConstructType RegExpConstructor::getConstructData(JSCell*, ConstructData& constructData)
</span><span class="lines">@@ -323,11 +349,10 @@
</span><span class="cx"> return ConstructType::Host;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-// ECMA 15.10.3
</del><span class="cx"> static EncodedJSValue JSC_HOST_CALL callRegExpConstructor(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> ArgList args(exec);
</span><del>- return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args));
</del><ins>+ return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, exec->callee()));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> CallType RegExpConstructor::getCallData(JSCell*, CallData& callData)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeRegExpConstructorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/RegExpConstructor.h (199105 => 199106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/RegExpConstructor.h        2016-04-06 17:44:42 UTC (rev 199105)
+++ trunk/Source/JavaScriptCore/runtime/RegExpConstructor.h        2016-04-06 18:26:11 UTC (rev 199106)
</span><span class="lines">@@ -87,7 +87,7 @@
</span><span class="cx">
</span><span class="cx"> RegExpConstructor* asRegExpConstructor(JSValue);
</span><span class="cx">
</span><del>-JSObject* constructRegExp(ExecState*, JSGlobalObject*, const ArgList&, JSValue newTarget = jsUndefined());
</del><ins>+JSObject* constructRegExp(ExecState*, JSGlobalObject*, const ArgList&, JSObject* callee = nullptr, JSValue newTarget = jsUndefined());
</ins><span class="cx">
</span><span class="cx"> inline RegExpConstructor* asRegExpConstructor(JSValue value)
</span><span class="cx"> {
</span></span></pre>
</div>
</div>
</body>
</html>