<!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>[192034] 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/192034">192034</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2015-11-04 13:46:10 -0800 (Wed, 04 Nov 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix endless OSR exits when creating a rope that contains an object that ToPrimitive's to a number.
https://bugs.webkit.org/show_bug.cgi?id=150583
Reviewed by Benjamin Poulain.
Source/JavaScriptCore:
Before we assumed that the result of ToPrimitive on any object was a string.
This had a couple of negative effects. First, the result ToPrimitive on an
object can be overridden to be any primitive type. In fact, as of ES6, ToPrimitive,
when part of a addition expression, will type hint a number value. Second, even after
repeatedly exiting with a bad type we would continue to think that the result
of ToPrimitive would be a string so we continue to convert StrCats into MakeRope.
The fix is to make Prediction Propagation match the behavior of Fixup and move
canOptimizeStringObjectAccess to DFGGraph.
* bytecode/SpeculatedType.h:
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::attemptToForceStringArrayModeByToStringConversion):
(JSC::DFG::FixupPhase::fixupToPrimitive):
(JSC::DFG::FixupPhase::fixupToStringOrCallStringConstructor):
(JSC::DFG::FixupPhase::attemptToMakeFastStringAdd):
(JSC::DFG::FixupPhase::isStringPrototypeMethodSane): Deleted.
(JSC::DFG::FixupPhase::canOptimizeStringObjectAccess): Deleted.
* dfg/DFGGraph.cpp:
(JSC::DFG::Graph::isStringPrototypeMethodSane):
(JSC::DFG::Graph::canOptimizeStringObjectAccess):
* dfg/DFGGraph.h:
* dfg/DFGPredictionPropagationPhase.cpp:
(JSC::DFG::PredictionPropagationPhase::resultOfToPrimitive):
(JSC::DFG::resultOfToPrimitive): Deleted.
* bytecode/SpeculatedType.h:
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::attemptToForceStringArrayModeByToStringConversion):
(JSC::DFG::FixupPhase::fixupToPrimitive):
(JSC::DFG::FixupPhase::fixupToStringOrCallStringConstructor):
(JSC::DFG::FixupPhase::attemptToMakeFastStringAdd):
(JSC::DFG::FixupPhase::isStringPrototypeMethodSane): Deleted.
(JSC::DFG::FixupPhase::canOptimizeStringObjectAccess): Deleted.
* dfg/DFGGraph.cpp:
(JSC::DFG::Graph::isStringPrototypeMethodSane):
(JSC::DFG::Graph::canOptimizeStringObjectAccess):
* dfg/DFGGraph.h:
* dfg/DFGPredictionPropagationPhase.cpp:
(JSC::DFG::PredictionPropagationPhase::resultOfToPrimitive):
(JSC::DFG::resultOfToPrimitive): Deleted.
* tests/stress/string-rope-with-custom-valueof.js: Added.
(catNumber):
(number.valueOf):
(catBool):
(bool.valueOf):
(catUndefined):
(undef.valueOf):
(catRandom):
(random.valueOf):
LayoutTests:
Created a regression test to look for OSRing in string concatenation when
valueOf returns a non-string primitive.
* js/regress/script-tests/string-rope-with-object.js: Added.
(body.f):
(body.String.prototype.valueOf):
(body.bar.valueOf):
(body):
* js/regress/string-rope-with-object-expected.txt: Added.
* js/regress/string-rope-with-object.html: 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="#trunkSourceJavaScriptCorebytecodeSpeculatedTypeh">trunk/Source/JavaScriptCore/bytecode/SpeculatedType.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGFixupPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGGraphcpp">trunk/Source/JavaScriptCore/dfg/DFGGraph.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGGraphh">trunk/Source/JavaScriptCore/dfg/DFGGraph.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGPredictionPropagationPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsregressscripttestsstringropewithobjectjs">trunk/LayoutTests/js/regress/script-tests/string-rope-with-object.js</a></li>
<li><a href="#trunkLayoutTestsjsregressstringropewithobjectexpectedtxt">trunk/LayoutTests/js/regress/string-rope-with-object-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsregressstringropewithobjecthtml">trunk/LayoutTests/js/regress/string-rope-with-object.html</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressstringropewithcustomvalueofjs">trunk/Source/JavaScriptCore/tests/stress/string-rope-with-custom-valueof.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (192033 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-11-04 21:28:14 UTC (rev 192033)
+++ trunk/LayoutTests/ChangeLog        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2015-10-30 Keith Miller <keith_miller@apple.com>
+
+ Fix endless OSR exits when creating a rope that contains an object that ToPrimitive's to a number.
+ https://bugs.webkit.org/show_bug.cgi?id=150583
+
+ Reviewed by Benjamin Poulain.
+
+ Created a regression test to look for OSRing in string concatenation when
+ valueOf returns a non-string primitive.
+
+ * js/regress/script-tests/string-rope-with-object.js: Added.
+ (body.f):
+ (body.String.prototype.valueOf):
+ (body.bar.valueOf):
+ (body):
+ * js/regress/string-rope-with-object-expected.txt: Added.
+ * js/regress/string-rope-with-object.html: Added.
+
</ins><span class="cx"> 2015-11-04 Ryan Haddad <ryanhaddad@apple.com>
</span><span class="cx">
</span><span class="cx"> Rebaselining LayoutTest fast/text/international/thai-baht-space.html on win
</span></span></pre></div>
<a id="trunkLayoutTestsjsregressscripttestsstringropewithobjectjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/script-tests/string-rope-with-object.js (0 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/script-tests/string-rope-with-object.js         (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/string-rope-with-object.js        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -0,0 +1,24 @@
</span><ins>+function body() {
+ function f(s,t) {
+ let total = 0;
+ for (let i = 0; i < 2000; i++) {
+ total += i;
+ }
+ return "a" + "b" + s + t;
+ }
+ noInline(f);
+
+ var foo = new String(10);
+ String.prototype.valueOf = function() { return 1; };
+
+ var count = 0;
+ var bar = { valueOf: function() { return count++; } };
+ (function wrapper() {
+ for (var i = 0; i < 10000; i++) {
+ if (f(foo,bar) !== "ab1" + i)
+ throw "bad";
+ }
+ })();
+
+}
+body();
</ins></span></pre></div>
<a id="trunkLayoutTestsjsregressstringropewithobjectexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/string-rope-with-object-expected.txt (0 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/string-rope-with-object-expected.txt         (rev 0)
+++ trunk/LayoutTests/js/regress/string-rope-with-object-expected.txt        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+JSRegress/string-rope-with-object
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsregressstringropewithobjecthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/string-rope-with-object.html (0 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/string-rope-with-object.html         (rev 0)
+++ trunk/LayoutTests/js/regress/string-rope-with-object.html        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/string-rope-with-object.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (192033 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-11-04 21:28:14 UTC (rev 192033)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -1,3 +1,61 @@
</span><ins>+2015-10-30 Keith Miller <keith_miller@apple.com>
+
+ Fix endless OSR exits when creating a rope that contains an object that ToPrimitive's to a number.
+ https://bugs.webkit.org/show_bug.cgi?id=150583
+
+ Reviewed by Benjamin Poulain.
+
+ Before we assumed that the result of ToPrimitive on any object was a string.
+ This had a couple of negative effects. First, the result ToPrimitive on an
+ object can be overridden to be any primitive type. In fact, as of ES6, ToPrimitive,
+ when part of a addition expression, will type hint a number value. Second, even after
+ repeatedly exiting with a bad type we would continue to think that the result
+ of ToPrimitive would be a string so we continue to convert StrCats into MakeRope.
+
+ The fix is to make Prediction Propagation match the behavior of Fixup and move
+ canOptimizeStringObjectAccess to DFGGraph.
+
+ * bytecode/SpeculatedType.h:
+ * dfg/DFGFixupPhase.cpp:
+ (JSC::DFG::FixupPhase::attemptToForceStringArrayModeByToStringConversion):
+ (JSC::DFG::FixupPhase::fixupToPrimitive):
+ (JSC::DFG::FixupPhase::fixupToStringOrCallStringConstructor):
+ (JSC::DFG::FixupPhase::attemptToMakeFastStringAdd):
+ (JSC::DFG::FixupPhase::isStringPrototypeMethodSane): Deleted.
+ (JSC::DFG::FixupPhase::canOptimizeStringObjectAccess): Deleted.
+ * dfg/DFGGraph.cpp:
+ (JSC::DFG::Graph::isStringPrototypeMethodSane):
+ (JSC::DFG::Graph::canOptimizeStringObjectAccess):
+ * dfg/DFGGraph.h:
+ * dfg/DFGPredictionPropagationPhase.cpp:
+ (JSC::DFG::PredictionPropagationPhase::resultOfToPrimitive):
+ (JSC::DFG::resultOfToPrimitive): Deleted.
+
+ * bytecode/SpeculatedType.h:
+ * dfg/DFGFixupPhase.cpp:
+ (JSC::DFG::FixupPhase::attemptToForceStringArrayModeByToStringConversion):
+ (JSC::DFG::FixupPhase::fixupToPrimitive):
+ (JSC::DFG::FixupPhase::fixupToStringOrCallStringConstructor):
+ (JSC::DFG::FixupPhase::attemptToMakeFastStringAdd):
+ (JSC::DFG::FixupPhase::isStringPrototypeMethodSane): Deleted.
+ (JSC::DFG::FixupPhase::canOptimizeStringObjectAccess): Deleted.
+ * dfg/DFGGraph.cpp:
+ (JSC::DFG::Graph::isStringPrototypeMethodSane):
+ (JSC::DFG::Graph::canOptimizeStringObjectAccess):
+ * dfg/DFGGraph.h:
+ * dfg/DFGPredictionPropagationPhase.cpp:
+ (JSC::DFG::PredictionPropagationPhase::resultOfToPrimitive):
+ (JSC::DFG::resultOfToPrimitive): Deleted.
+ * tests/stress/string-rope-with-custom-valueof.js: Added.
+ (catNumber):
+ (number.valueOf):
+ (catBool):
+ (bool.valueOf):
+ (catUndefined):
+ (undef.valueOf):
+ (catRandom):
+ (random.valueOf):
+
</ins><span class="cx"> 2015-11-04 Xabier Rodriguez Calvar <calvaris@igalia.com>
</span><span class="cx">
</span><span class="cx"> Remove bogus global internal functions for properties and prototype retrieval
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeSpeculatedTypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/SpeculatedType.h (192033 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/SpeculatedType.h        2015-11-04 21:28:14 UTC (rev 192033)
+++ trunk/Source/JavaScriptCore/bytecode/SpeculatedType.h        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -85,6 +85,7 @@
</span><span class="cx"> static const SpeculatedType SpecOther = 0x20000000; // It's definitely either Null or Undefined.
</span><span class="cx"> static const SpeculatedType SpecMisc = 0x30000000; // It's definitely either a boolean, Null, or Undefined.
</span><span class="cx"> static const SpeculatedType SpecHeapTop = 0x3bbfffff; // It can be any of the above, except for SpecInt52 and SpecDoubleImpureNaN.
</span><ins>+static const SpeculatedType SpecPrimitive = 0x3bbf0000; // It's any non-Object JSValue. This is (~SpecObject & SpecHeapTop)
</ins><span class="cx"> static const SpeculatedType SpecEmpty = 0x40000000; // It's definitely an empty value marker.
</span><span class="cx"> static const SpeculatedType SpecBytecodeTop = 0x7bbfffff; // It can be any of the above, except for SpecInt52 and SpecDoubleImpureNaN. This is (SpecHeapTop | SpecEmpty).
</span><span class="cx"> static const SpeculatedType SpecFullTop = 0x7fffffff; // It can be any of the above plus anything the DFG chooses.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGFixupPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp (192033 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp        2015-11-04 21:28:14 UTC (rev 192033)
+++ trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -1447,7 +1447,7 @@
</span><span class="cx"> {
</span><span class="cx"> ASSERT(arrayMode == ArrayMode(Array::Generic));
</span><span class="cx">
</span><del>- if (!canOptimizeStringObjectAccess(node->origin.semantic))
</del><ins>+ if (!m_graph.canOptimizeStringObjectAccess(node->origin.semantic))
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> createToString<useKind>(node, node->child1());
</span><span class="lines">@@ -1529,14 +1529,14 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (node->child1()->shouldSpeculateStringObject()
</span><del>- && canOptimizeStringObjectAccess(node->origin.semantic)) {
</del><ins>+ && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
</ins><span class="cx"> fixEdge<StringObjectUse>(node->child1());
</span><span class="cx"> node->convertToToString();
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (node->child1()->shouldSpeculateStringOrStringObject()
</span><del>- && canOptimizeStringObjectAccess(node->origin.semantic)) {
</del><ins>+ && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
</ins><span class="cx"> fixEdge<StringOrStringObjectUse>(node->child1());
</span><span class="cx"> node->convertToToString();
</span><span class="cx"> return;
</span><span class="lines">@@ -1552,13 +1552,13 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (node->child1()->shouldSpeculateStringObject()
</span><del>- && canOptimizeStringObjectAccess(node->origin.semantic)) {
</del><ins>+ && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
</ins><span class="cx"> fixEdge<StringObjectUse>(node->child1());
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (node->child1()->shouldSpeculateStringOrStringObject()
</span><del>- && canOptimizeStringObjectAccess(node->origin.semantic)) {
</del><ins>+ && m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
</ins><span class="cx"> fixEdge<StringOrStringObjectUse>(node->child1());
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="lines">@@ -1577,7 +1577,7 @@
</span><span class="cx"> [&] (Edge& edge) {
</span><span class="cx"> if (edge->shouldSpeculateString())
</span><span class="cx"> return;
</span><del>- if (canOptimizeStringObjectAccess(node->origin.semantic)) {
</del><ins>+ if (m_graph.canOptimizeStringObjectAccess(node->origin.semantic)) {
</ins><span class="cx"> if (edge->shouldSpeculateStringObject())
</span><span class="cx"> return;
</span><span class="cx"> if (edge->shouldSpeculateStringOrStringObject())
</span><span class="lines">@@ -1595,7 +1595,7 @@
</span><span class="cx"> convertStringAddUse<StringUse>(node, edge);
</span><span class="cx"> return;
</span><span class="cx"> }
</span><del>- ASSERT(canOptimizeStringObjectAccess(node->origin.semantic));
</del><ins>+ ASSERT(m_graph.canOptimizeStringObjectAccess(node->origin.semantic));
</ins><span class="cx"> if (edge->shouldSpeculateStringObject()) {
</span><span class="cx"> convertStringAddUse<StringObjectUse>(node, edge);
</span><span class="cx"> return;
</span><span class="lines">@@ -1610,65 +1610,7 @@
</span><span class="cx"> convertToMakeRope(node);
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><del>-
- bool isStringPrototypeMethodSane(
- JSObject* stringPrototype, Structure* stringPrototypeStructure, UniquedStringImpl* uid)
- {
- unsigned attributesUnused;
- PropertyOffset offset =
- stringPrototypeStructure->getConcurrently(uid, attributesUnused);
- if (!isValidOffset(offset))
- return false;
-
- JSValue value = m_graph.tryGetConstantProperty(
- stringPrototype, stringPrototypeStructure, offset);
- if (!value)
- return false;
-
- JSFunction* function = jsDynamicCast<JSFunction*>(value);
- if (!function)
- return false;
-
- if (function->executable()->intrinsicFor(CodeForCall) != StringPrototypeValueOfIntrinsic)
- return false;
-
- return true;
- }
-
- bool canOptimizeStringObjectAccess(const CodeOrigin& codeOrigin)
- {
- if (m_graph.hasExitSite(codeOrigin, NotStringObject))
- return false;
-
- Structure* stringObjectStructure = m_graph.globalObjectFor(codeOrigin)->stringObjectStructure();
- m_graph.registerStructure(stringObjectStructure);
- ASSERT(stringObjectStructure->storedPrototype().isObject());
- ASSERT(stringObjectStructure->storedPrototype().asCell()->classInfo() == StringPrototype::info());
</del><span class="cx">
</span><del>- FrozenValue* stringPrototypeObjectValue =
- m_graph.freeze(stringObjectStructure->storedPrototype());
- StringPrototype* stringPrototypeObject =
- stringPrototypeObjectValue->dynamicCast<StringPrototype*>();
- Structure* stringPrototypeStructure = stringPrototypeObjectValue->structure();
- if (m_graph.registerStructure(stringPrototypeStructure) != StructureRegisteredAndWatched)
- return false;
-
- if (stringPrototypeStructure->isDictionary())
- return false;
-
- // We're being conservative here. We want DFG's ToString on StringObject to be
- // used in both numeric contexts (that would call valueOf()) and string contexts
- // (that would call toString()). We don't want the DFG to have to distinguish
- // between the two, just because that seems like it would get confusing. So we
- // just require both methods to be sane.
- if (!isStringPrototypeMethodSane(stringPrototypeObject, stringPrototypeStructure, vm().propertyNames->valueOf.impl()))
- return false;
- if (!isStringPrototypeMethodSane(stringPrototypeObject, stringPrototypeStructure, vm().propertyNames->toString.impl()))
- return false;
-
- return true;
- }
-
</del><span class="cx"> void fixupGetAndSetLocalsInBlock(BasicBlock* block)
</span><span class="cx"> {
</span><span class="cx"> if (!block)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGGraphcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGGraph.cpp (192033 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGGraph.cpp        2015-11-04 21:28:14 UTC (rev 192033)
+++ trunk/Source/JavaScriptCore/dfg/DFGGraph.cpp        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -1479,6 +1479,59 @@
</span><span class="cx"> return MethodOfGettingAValueProfile();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+bool Graph::isStringPrototypeMethodSane(JSObject* stringPrototype, Structure* stringPrototypeStructure, UniquedStringImpl* uid)
+{
+ unsigned attributesUnused;
+ PropertyOffset offset = stringPrototypeStructure->getConcurrently(uid, attributesUnused);
+ if (!isValidOffset(offset))
+ return false;
+
+ JSValue value = tryGetConstantProperty(stringPrototype, stringPrototypeStructure, offset);
+ if (!value)
+ return false;
+
+ JSFunction* function = jsDynamicCast<JSFunction*>(value);
+ if (!function)
+ return false;
+
+ if (function->executable()->intrinsicFor(CodeForCall) != StringPrototypeValueOfIntrinsic)
+ return false;
+
+ return true;
+}
+
+bool Graph::canOptimizeStringObjectAccess(const CodeOrigin& codeOrigin)
+{
+ if (hasExitSite(codeOrigin, NotStringObject))
+ return false;
+
+ Structure* stringObjectStructure = globalObjectFor(codeOrigin)->stringObjectStructure();
+ registerStructure(stringObjectStructure);
+ ASSERT(stringObjectStructure->storedPrototype().isObject());
+ ASSERT(stringObjectStructure->storedPrototype().asCell()->classInfo() == StringPrototype::info());
+
+ FrozenValue* stringPrototypeObjectValue = freeze(stringObjectStructure->storedPrototype());
+ StringPrototype* stringPrototypeObject = stringPrototypeObjectValue->dynamicCast<StringPrototype*>();
+ Structure* stringPrototypeStructure = stringPrototypeObjectValue->structure();
+ if (registerStructure(stringPrototypeStructure) != StructureRegisteredAndWatched)
+ return false;
+
+ if (stringPrototypeStructure->isDictionary())
+ return false;
+
+ // We're being conservative here. We want DFG's ToString on StringObject to be
+ // used in both numeric contexts (that would call valueOf()) and string contexts
+ // (that would call toString()). We don't want the DFG to have to distinguish
+ // between the two, just because that seems like it would get confusing. So we
+ // just require both methods to be sane.
+ if (!isStringPrototypeMethodSane(stringPrototypeObject, stringPrototypeStructure, m_vm.propertyNames->valueOf.impl()))
+ return false;
+ if (!isStringPrototypeMethodSane(stringPrototypeObject, stringPrototypeStructure, m_vm.propertyNames->toString.impl()))
+ return false;
+
+ return true;
+}
+
</ins><span class="cx"> } } // namespace JSC::DFG
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(DFG_JIT)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGGraphh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGGraph.h (192033 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGGraph.h        2015-11-04 21:28:14 UTC (rev 192033)
+++ trunk/Source/JavaScriptCore/dfg/DFGGraph.h        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -318,6 +318,8 @@
</span><span class="cx"> && negate->canSpeculateInt52(pass);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ bool canOptimizeStringObjectAccess(const CodeOrigin&);
+
</ins><span class="cx"> bool roundShouldSpeculateInt32(Node* arithRound, PredictionPass pass)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(arithRound->op() == ArithRound);
</span><span class="lines">@@ -913,7 +915,9 @@
</span><span class="cx"> bool m_hasDebuggerEnabled;
</span><span class="cx"> bool m_hasExceptionHandlers { false };
</span><span class="cx"> private:
</span><del>-
</del><ins>+
+ bool isStringPrototypeMethodSane(JSObject* stringPrototype, Structure* stringPrototypeStructure, UniquedStringImpl*);
+
</ins><span class="cx"> void handleSuccessor(Vector<BasicBlock*, 16>& worklist, BasicBlock*, BasicBlock* successor);
</span><span class="cx">
</span><span class="cx"> AddSpeculationMode addImmediateShouldSpeculateInt32(Node* add, bool variableShouldSpeculateInt32, Node* operand, Node*immediate, RareCaseProfilingSource source)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGPredictionPropagationPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp (192033 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp        2015-11-04 21:28:14 UTC (rev 192033)
+++ trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -34,17 +34,6 @@
</span><span class="cx">
</span><span class="cx"> namespace JSC { namespace DFG {
</span><span class="cx">
</span><del>-SpeculatedType resultOfToPrimitive(SpeculatedType type)
-{
- if (type & SpecObject) {
- // Objects get turned into strings. So if the input has hints of objectness,
- // the output will have hinsts of stringiness.
- return mergeSpeculations(type & ~SpecObject, SpecString);
- }
-
- return type;
-}
-
</del><span class="cx"> class PredictionPropagationPhase : public Phase {
</span><span class="cx"> public:
</span><span class="cx"> PredictionPropagationPhase(Graph& graph)
</span><span class="lines">@@ -908,6 +897,20 @@
</span><span class="cx"> for (unsigned i = 0; i < m_graph.m_argumentPositions.size(); ++i)
</span><span class="cx"> m_changed |= m_graph.m_argumentPositions[i].mergeArgumentPredictionAwareness();
</span><span class="cx"> }
</span><ins>+
+ SpeculatedType resultOfToPrimitive(SpeculatedType type)
+ {
+ if (type & SpecObject) {
+ // We try to be optimistic here about StringObjects since it's unlikely that
+ // someone overrides the valueOf or toString methods.
+ if (type & SpecStringObject && m_graph.canOptimizeStringObjectAccess(m_currentNode->origin.semantic))
+ return mergeSpeculations(type & ~SpecObject, SpecString);
+
+ return mergeSpeculations(type & ~SpecObject, SpecPrimitive);
+ }
+
+ return type;
+ }
</ins><span class="cx">
</span><span class="cx"> Node* m_currentNode;
</span><span class="cx"> bool m_changed;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressstringropewithcustomvalueofjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/string-rope-with-custom-valueof.js (0 => 192034)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/string-rope-with-custom-valueof.js         (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/string-rope-with-custom-valueof.js        2015-11-04 21:46:10 UTC (rev 192034)
</span><span class="lines">@@ -0,0 +1,61 @@
</span><ins>+// This file tests the concatenating of known strings with different objects with overridden valueOf functions.
+// Note: we intentionally do not test Symbols since they cannot be appended to strings...
+
+function catNumber(obj) {
+ return "test" + "things" + obj;
+}
+noInline(catNumber);
+
+number = { valueOf: function() { return 1; } };
+
+function catBool(obj) {
+ return "test" + "things" + obj;
+}
+noInline(catBool);
+
+bool = { valueOf: function() { return true; } };
+
+function catUndefined(obj) {
+ return "test" + "things" + obj;
+}
+noInline(catUndefined);
+
+undef = { valueOf: function() { return undefined; } };
+
+function catRandom(obj) {
+ return "test" + "things" + obj;
+}
+noInline(catRandom);
+
+i = 0;
+random = { valueOf: function() {
+ switch (i % 3) {
+ case 0:
+ return number.valueOf();
+ case 1:
+ return bool.valueOf();
+ case 2:
+ return undef.valueOf();
+ }
+} };
+
+for (i = 0; i < 100000; i++) {
+ if (catNumber(number) !== "testthings1")
+ throw "bad number";
+ if (catBool(bool) !== "testthingstrue")
+ throw "bad bool";
+ if (catUndefined(undef) !== "testthingsundefined")
+ throw "bad undefined";
+ if (catRandom(random) !== "testthings" + random.valueOf())
+ throw "bad random";
+}
+
+// Try passing new types to each of the other functions.
+for (i = 0; i < 100000; i++) {
+ if (catUndefined(number) !== "testthings1")
+ throw "bad number";
+ if (catNumber(bool) !== "testthingstrue")
+ throw "bad bool";
+ if (catBool(undef) !== "testthingsundefined")
+ throw "bad undefined";
+}
</ins></span></pre>
</div>
</div>
</body>
</html>