<!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>[185528] 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/185528">185528</a></dd>
<dt>Author</dt> <dd>darin@apple.com</dd>
<dt>Date</dt> <dd>2015-06-12 18:35:08 -0700 (Fri, 12 Jun 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix minor ES6 compliance issue in RegExp.prototype.toString and optimize performance a little
https://bugs.webkit.org/show_bug.cgi?id=145935
Reviewed by Anders Carlsson.
Source/JavaScriptCore:
Test: js/regexp-toString.html
* runtime/RegExpPrototype.cpp:
(JSC::getFlags): Avoid memory allocation for the flags string by returning it in a character
buffer instead of constructing a WTF::String for it.
(JSC::regExpProtoFuncToString): Require only that the this value be an object; don't require
that it is actually a regular expression object. This is covered in the ES6 specification.
Also removed comment about the "/(?:)/" trick since that is now the repsonsibility of the
getter for the "source" property. Updated to use getFlags so we do one less memory allocation.
(JSC::regExpProtoGetterFlags): Chagned to use getFlags instead of the old flagsString.
LayoutTests:
* js/regexp-toString-expected.txt: Added.
* js/regexp-toString.html: Added.
* js/script-tests/regexp-toString.js: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeRegExpPrototypecpp">trunk/Source/JavaScriptCore/runtime/RegExpPrototype.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsregexptoStringexpectedtxt">trunk/LayoutTests/js/regexp-toString-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsregexptoStringhtml">trunk/LayoutTests/js/regexp-toString.html</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsregexptoStringjs">trunk/LayoutTests/js/script-tests/regexp-toString.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (185527 => 185528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-06-13 00:30:30 UTC (rev 185527)
+++ trunk/LayoutTests/ChangeLog        2015-06-13 01:35:08 UTC (rev 185528)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2015-06-12 Darin Adler <darin@apple.com>
+
+ Fix minor ES6 compliance issue in RegExp.prototype.toString and optimize performance a little
+ https://bugs.webkit.org/show_bug.cgi?id=145935
+
+ Reviewed by Anders Carlsson.
+
+ * js/regexp-toString-expected.txt: Added.
+ * js/regexp-toString.html: Added.
+ * js/script-tests/regexp-toString.js: Added.
+
</ins><span class="cx"> 2015-06-12 Manuel Rego Casasnovas <rego@igalia.com>
</span><span class="cx">
</span><span class="cx"> [CSS Grid Layout] Fix grid-template-areas parsing to avoid spaces
</span></span></pre></div>
<a id="trunkLayoutTestsjsregexptoStringexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regexp-toString-expected.txt (0 => 185528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regexp-toString-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/regexp-toString-expected.txt        2015-06-13 01:35:08 UTC (rev 185528)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+Test RegExp#toString
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').configurable is true
+PASS Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').enumerable is false
+PASS Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').get is undefined
+PASS Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').set is undefined
+PASS typeof Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').value is 'function'
+PASS RegExp.prototype.toString.call(new RegExp) is '/(?:)/'
+PASS RegExp.prototype.toString.call(new RegExp('a')) is '/a/'
+PASS RegExp.prototype.toString.call(new RegExp('\\\\')) is '/\\\\/'
+PASS RegExp.prototype.toString.call({}) is '/undefined/'
+PASS RegExp.prototype.toString.call({source: 'hi'}) is '/hi/'
+PASS RegExp.prototype.toString.call({ __proto__: { source: 'yo' } }) is '/yo/'
+PASS RegExp.prototype.toString.call({source: ''}) is '//'
+PASS RegExp.prototype.toString.call({source: '/'}) is '///'
+PASS RegExp.prototype.toString.call(undefined) threw exception TypeError: Type error.
+PASS RegExp.prototype.toString.call(null) threw exception TypeError: Type error.
+PASS RegExp.prototype.toString.call(false) threw exception TypeError: Type error.
+PASS RegExp.prototype.toString.call(true) threw exception TypeError: Type error.
+PASS RegExp.prototype.toString.call(0) threw exception TypeError: Type error.
+PASS RegExp.prototype.toString.call(0.5) threw exception TypeError: Type error.
+PASS RegExp.prototype.toString.call('x') threw exception TypeError: Type error.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins><span class="cx">Property changes on: trunk/LayoutTests/js/regexp-toString-expected.txt
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsjsregexptoStringhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regexp-toString.html (0 => 185528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regexp-toString.html         (rev 0)
+++ trunk/LayoutTests/js/regexp-toString.html        2015-06-13 01:35:08 UTC (rev 185528)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="script-tests/regexp-toString.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
</ins><span class="cx">Property changes on: trunk/LayoutTests/js/regexp-toString.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsjsscripttestsregexptoStringjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/script-tests/regexp-toString.js (0 => 185528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/regexp-toString.js         (rev 0)
+++ trunk/LayoutTests/js/script-tests/regexp-toString.js        2015-06-13 01:35:08 UTC (rev 185528)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+description('Test RegExp#toString');
+
+shouldBe("Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').configurable", "true");
+shouldBe("Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').enumerable", "false");
+shouldBe("Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').get", "undefined");
+shouldBe("Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').set", "undefined");
+shouldBe("typeof Object.getOwnPropertyDescriptor(RegExp.prototype, 'toString').value", "'function'");
+
+shouldBe("RegExp.prototype.toString.call(new RegExp)", "'/(?:)/'");
+shouldBe("RegExp.prototype.toString.call(new RegExp('a'))", "'/a/'");
+shouldBe("RegExp.prototype.toString.call(new RegExp('\\\\\\\\'))", "'/\\\\\\\\/'");
+
+shouldBe("RegExp.prototype.toString.call({})", "'/undefined/'");
+shouldBe("RegExp.prototype.toString.call({source: 'hi'})", "'/hi/'");
+shouldBe("RegExp.prototype.toString.call({ __proto__: { source: 'yo' } })", "'/yo/'");
+shouldBe("RegExp.prototype.toString.call({source: ''})", "'//'");
+shouldBe("RegExp.prototype.toString.call({source: '/'})", "'///'");
+
+shouldThrow("RegExp.prototype.toString.call(undefined)");
+shouldThrow("RegExp.prototype.toString.call(null)");
+shouldThrow("RegExp.prototype.toString.call(false)");
+shouldThrow("RegExp.prototype.toString.call(true)");
+shouldThrow("RegExp.prototype.toString.call(0)");
+shouldThrow("RegExp.prototype.toString.call(0.5)");
+shouldThrow("RegExp.prototype.toString.call('x')");
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (185527 => 185528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-06-13 00:30:30 UTC (rev 185527)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-06-13 01:35:08 UTC (rev 185528)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2015-06-12 Darin Adler <darin@apple.com>
+
+ Fix minor ES6 compliance issue in RegExp.prototype.toString and optimize performance a little
+ https://bugs.webkit.org/show_bug.cgi?id=145935
+
+ Reviewed by Anders Carlsson.
+
+ Test: js/regexp-toString.html
+
+ * runtime/RegExpPrototype.cpp:
+ (JSC::getFlags): Avoid memory allocation for the flags string by returning it in a character
+ buffer instead of constructing a WTF::String for it.
+ (JSC::regExpProtoFuncToString): Require only that the this value be an object; don't require
+ that it is actually a regular expression object. This is covered in the ES6 specification.
+ Also removed comment about the "/(?:)/" trick since that is now the repsonsibility of the
+ getter for the "source" property. Updated to use getFlags so we do one less memory allocation.
+ (JSC::regExpProtoGetterFlags): Chagned to use getFlags instead of the old flagsString.
+
</ins><span class="cx"> 2015-06-12 Basile Clement <basile_clement@apple.com>
</span><span class="cx">
</span><span class="cx"> DFG Object Allocation Sinking should not consider GetClosureVar as escapes
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeRegExpPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/RegExpPrototype.cpp (185527 => 185528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/RegExpPrototype.cpp        2015-06-13 00:30:30 UTC (rev 185527)
+++ trunk/Source/JavaScriptCore/runtime/RegExpPrototype.cpp        2015-06-13 01:35:08 UTC (rev 185528)
</span><span class="lines">@@ -137,37 +137,39 @@
</span><span class="cx"> return JSValue::encode(jsUndefined());
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static inline String flagsString(ExecState *exec, JSObject* regexp)
</del><ins>+typedef std::array<char, 3 + 1> FlagsString; // 3 different flags and a null character terminator.
+
+static inline FlagsString flagsString(ExecState* exec, JSObject* regexp)
</ins><span class="cx"> {
</span><del>- char flags[4] = { 0, 0, 0, 0 };
- int index = 0;
</del><ins>+ FlagsString string;
</ins><span class="cx">
</span><span class="cx"> JSValue globalValue = regexp->get(exec, exec->propertyNames().global);
</span><span class="cx"> if (exec->hadException())
</span><del>- return String();
</del><ins>+ return string;
</ins><span class="cx"> JSValue ignoreCaseValue = regexp->get(exec, exec->propertyNames().ignoreCase);
</span><span class="cx"> if (exec->hadException())
</span><del>- return String();
</del><ins>+ return string;
</ins><span class="cx"> JSValue multilineValue = regexp->get(exec, exec->propertyNames().multiline);
</span><del>- if (exec->hadException())
- return String();
</del><span class="cx">
</span><ins>+ unsigned index = 0;
</ins><span class="cx"> if (globalValue.toBoolean(exec))
</span><del>- flags[index++] = 'g';
</del><ins>+ string[index++] = 'g';
</ins><span class="cx"> if (ignoreCaseValue.toBoolean(exec))
</span><del>- flags[index++] = 'i';
</del><ins>+ string[index++] = 'i';
</ins><span class="cx"> if (multilineValue.toBoolean(exec))
</span><del>- flags[index] = 'm';
- return String(flags);
</del><ins>+ string[index++] = 'm';
+ ASSERT(index < string.size());
+ string[index] = 0;
+ return string;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> JSValue thisValue = exec->thisValue();
</span><del>- if (!thisValue.inherits(RegExpObject::info()))
</del><ins>+ if (!thisValue.isObject())
</ins><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- RegExpObject* thisObject = asRegExpObject(thisValue);
</del><ins>+ JSObject* thisObject = asObject(thisValue);
</ins><span class="cx">
</span><span class="cx"> StringRecursionChecker checker(exec, thisObject);
</span><span class="cx"> if (JSValue earlyReturnValue = checker.earlyReturnValue())
</span><span class="lines">@@ -180,12 +182,11 @@
</span><span class="cx"> if (exec->hadException())
</span><span class="cx"> return JSValue::encode(jsUndefined());
</span><span class="cx">
</span><del>- String flags = flagsString(exec, thisObject);
</del><ins>+ auto flags = flagsString(exec, thisObject);
</ins><span class="cx"> if (exec->hadException())
</span><span class="cx"> return JSValue::encode(jsUndefined());
</span><span class="cx">
</span><del>- // If source is empty, use "/(?:)/" to avoid colliding with comment syntax
- return JSValue::encode(jsMakeNontrivialString(exec, "/", source, "/", flags));
</del><ins>+ return JSValue::encode(jsMakeNontrivialString(exec, '/', source, '/', flags.data()));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL regExpProtoGetterGlobal(ExecState* exec)
</span><span class="lines">@@ -219,16 +220,15 @@
</span><span class="cx"> {
</span><span class="cx"> JSValue thisValue = exec->thisValue();
</span><span class="cx"> if (!thisValue.isObject())
</span><del>- return JSValue::encode(throwTypeError(exec));
</del><ins>+ return throwVMTypeError(exec);
</ins><span class="cx">
</span><del>- String flags = flagsString(exec, asObject(thisValue));
</del><ins>+ auto flags = flagsString(exec, asObject(thisValue));
</ins><span class="cx"> if (exec->hadException())
</span><span class="cx"> return JSValue::encode(jsUndefined());
</span><span class="cx">
</span><del>- return JSValue::encode(jsString(exec, flags));
</del><ins>+ return JSValue::encode(jsString(exec, flags.data()));
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-
</del><span class="cx"> template <typename CharacterType>
</span><span class="cx"> static inline void appendLineTerminatorEscape(StringBuilder&, CharacterType);
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>