<!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>[172717] trunk/Source/JavaScriptCore</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/172717">172717</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-08-18 12:11:41 -0700 (Mon, 18 Aug 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>The parser should generate AST nodes the var declarations with no initializers
https://bugs.webkit.org/show_bug.cgi?id=135545

Patch by Saam Barati &lt;sbarati@apple.com&gt; on 2014-08-18
Reviewed by Geoffrey Garen.

Currently, JSC's parser ignores variable declarations
that have no assignment initializer value because all
variables are implicitly assigned to undefined. But,
type profiling needs an AST node to be generated for these
empty variable declarations because it needs to be able to
profile their text locations and to see that their type
is undefined.

* bytecompiler/NodesCodegen.cpp:
(JSC::EmptyVarExpression::emitBytecode):
* parser/ASTBuilder.h:
(JSC::ASTBuilder::createVarStatement):
(JSC::ASTBuilder::createEmptyVarExpression):
* parser/NodeConstructors.h:
(JSC::EmptyVarExpression::EmptyVarExpression):
* parser/Nodes.h:
* parser/Parser.cpp:
(JSC::Parser&lt;LexerType&gt;::parseVarDeclarationList):
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::createEmptyVarExpression):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerNodesCodegencpp">trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserASTBuilderh">trunk/Source/JavaScriptCore/parser/ASTBuilder.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserNodeConstructorsh">trunk/Source/JavaScriptCore/parser/NodeConstructors.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserNodesh">trunk/Source/JavaScriptCore/parser/Nodes.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserParsercpp">trunk/Source/JavaScriptCore/parser/Parser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreparserSyntaxCheckerh">trunk/Source/JavaScriptCore/parser/SyntaxChecker.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (172716 => 172717)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-08-18 19:07:17 UTC (rev 172716)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-08-18 19:11:41 UTC (rev 172717)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2014-08-18  Saam Barati  &lt;sbarati@apple.com&gt;
+
+        The parser should generate AST nodes the var declarations with no initializers
+        https://bugs.webkit.org/show_bug.cgi?id=135545
+
+        Reviewed by Geoffrey Garen.
+
+        Currently, JSC's parser ignores variable declarations
+        that have no assignment initializer value because all 
+        variables are implicitly assigned to undefined. But, 
+        type profiling needs an AST node to be generated for these 
+        empty variable declarations because it needs to be able to 
+        profile their text locations and to see that their type 
+        is undefined.
+
+        * bytecompiler/NodesCodegen.cpp:
+        (JSC::EmptyVarExpression::emitBytecode):
+        * parser/ASTBuilder.h:
+        (JSC::ASTBuilder::createVarStatement):
+        (JSC::ASTBuilder::createEmptyVarExpression):
+        * parser/NodeConstructors.h:
+        (JSC::EmptyVarExpression::EmptyVarExpression):
+        * parser/Nodes.h:
+        * parser/Parser.cpp:
+        (JSC::Parser&lt;LexerType&gt;::parseVarDeclarationList):
+        * parser/SyntaxChecker.h:
+        (JSC::SyntaxChecker::createEmptyVarExpression):
+
</ins><span class="cx"> 2014-08-18  Diego Pino Garcia  &lt;dpino@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Completed iterator can be revived by adding more than one new entry to the target object
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerNodesCodegencpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp (172716 => 172717)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2014-08-18 19:07:17 UTC (rev 172716)
+++ trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2014-08-18 19:11:41 UTC (rev 172717)
</span><span class="lines">@@ -1782,6 +1782,27 @@
</span><span class="cx">     generator.emitNode(m_expr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// ------------------------------ EmptyVarExpression ----------------------------
+
+RegisterID* EmptyVarExpression::emitBytecode(BytecodeGenerator&amp; generator, RegisterID*)
+{
+    if (!generator.isProfilingTypesWithHighFidelity())
+        return nullptr;
+
+    if (Local local = generator.local(m_ident))
+        generator.emitProfileTypesWithHighFidelity(local.get(), ProfileTypesBytecodeHasGlobalID, nullptr);
+    else {
+        RefPtr&lt;RegisterID&gt; scope = generator.emitResolveScope(generator.newTemporary(), m_ident);
+        RefPtr&lt;RegisterID&gt; value = generator.emitGetFromScope(generator.newTemporary(), scope.get(), m_ident, DoNotThrowIfNotFound);
+        generator.emitProfileTypesWithHighFidelity(value.get(), ProfileTypesBytecodeGetFromScope, &amp;m_ident);
+    }
+
+    generator.emitHighFidelityTypeProfilingExpressionInfo(position(), JSTextPosition(-1, position().offset + m_ident.length(), -1));
+
+    // It's safe to return null here because this node will always be a child node of VarStatementNode which ignores our return value.
+    return nullptr;
+}
+
</ins><span class="cx"> // ------------------------------ IfElseNode ---------------------------------------
</span><span class="cx"> 
</span><span class="cx"> static inline StatementNode* singleStatement(StatementNode* statementNode)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserASTBuilderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/ASTBuilder.h (172716 => 172717)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/ASTBuilder.h        2014-08-18 19:07:17 UTC (rev 172716)
+++ trunk/Source/JavaScriptCore/parser/ASTBuilder.h        2014-08-18 19:11:41 UTC (rev 172717)
</span><span class="lines">@@ -416,14 +416,16 @@
</span><span class="cx">     StatementNode* createVarStatement(const JSTokenLocation&amp; location, ExpressionNode* expr, int start, int end)
</span><span class="cx">     {
</span><span class="cx">         StatementNode* result;
</span><del>-        if (!expr)
-            result = new (m_vm) EmptyStatementNode(location);
-        else
-            result = new (m_vm) VarStatementNode(location, expr);
</del><ins>+        result = new (m_vm) VarStatementNode(location, expr);
</ins><span class="cx">         result-&gt;setLoc(start, end, location.startOffset, location.lineStartOffset);
</span><span class="cx">         return result;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    ExpressionNode* createEmptyVarExpression(const JSTokenLocation&amp; location, const Identifier&amp; identifier)
+    {
+        return new (m_vm) EmptyVarExpression(location, identifier);
+    }
+
</ins><span class="cx">     StatementNode* createReturnStatement(const JSTokenLocation&amp; location, ExpressionNode* expression, const JSTextPosition&amp; start, const JSTextPosition&amp; end)
</span><span class="cx">     {
</span><span class="cx">         ReturnNode* result = new (m_vm) ReturnNode(location, expression);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserNodeConstructorsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/NodeConstructors.h (172716 => 172717)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/NodeConstructors.h        2014-08-18 19:07:17 UTC (rev 172716)
+++ trunk/Source/JavaScriptCore/parser/NodeConstructors.h        2014-08-18 19:11:41 UTC (rev 172717)
</span><span class="lines">@@ -655,6 +655,12 @@
</span><span class="cx">         , m_expr(expr)
</span><span class="cx">     {
</span><span class="cx">     }
</span><ins>+
+    inline EmptyVarExpression::EmptyVarExpression(const JSTokenLocation&amp; location, const Identifier&amp; ident)
+        : ExpressionNode(location)
+        , m_ident(ident)
+    {
+    }
</ins><span class="cx">     
</span><span class="cx">     inline IfElseNode::IfElseNode(const JSTokenLocation&amp; location, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock)
</span><span class="cx">         : StatementNode(location)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserNodesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Nodes.h (172716 => 172717)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Nodes.h        2014-08-18 19:07:17 UTC (rev 172716)
+++ trunk/Source/JavaScriptCore/parser/Nodes.h        2014-08-18 19:11:41 UTC (rev 172717)
</span><span class="lines">@@ -1212,6 +1212,17 @@
</span><span class="cx">         ExpressionNode* m_expr;
</span><span class="cx">     };
</span><span class="cx"> 
</span><ins>+    class EmptyVarExpression : public ExpressionNode {
+    public:
+        EmptyVarExpression(const JSTokenLocation&amp;, const Identifier&amp;);
+
+    private:
+        virtual RegisterID* emitBytecode(BytecodeGenerator&amp;, RegisterID* = 0) override;
+
+        const Identifier&amp; m_ident;
+    };
+
+
</ins><span class="cx">     class IfElseNode : public StatementNode {
</span><span class="cx">     public:
</span><span class="cx">         IfElseNode(const JSTokenLocation&amp;, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/Parser.cpp (172716 => 172717)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/Parser.cpp        2014-08-18 19:07:17 UTC (rev 172716)
+++ trunk/Source/JavaScriptCore/parser/Parser.cpp        2014-08-18 19:11:41 UTC (rev 172717)
</span><span class="lines">@@ -458,6 +458,7 @@
</span><span class="cx">         bool hasInitializer = false;
</span><span class="cx">         if (match(IDENT)) {
</span><span class="cx">             JSTextPosition varStart = tokenStartPosition();
</span><ins>+            JSTokenLocation varStartLocation(tokenLocation());
</ins><span class="cx">             identStart = varStart;
</span><span class="cx">             const Identifier* name = m_token.m_data.ident;
</span><span class="cx">             lastIdent = name;
</span><span class="lines">@@ -475,7 +476,8 @@
</span><span class="cx">                 failIfFalse(initializer, &quot;Expected expression as the intializer for the variable '&quot;, name-&gt;impl(), &quot;'&quot;);
</span><span class="cx">                 
</span><span class="cx">                 node = context.createAssignResolve(location, *name, initializer, varStart, varDivot, lastTokenEndPosition());
</span><del>-            }
</del><ins>+            } else
+                node = context.createEmptyVarExpression(varStartLocation, *name);
</ins><span class="cx">         } else {
</span><span class="cx">             lastIdent = 0;
</span><span class="cx">             auto pattern = parseDeconstructionPattern(context, DeconstructToVariables);
</span><span class="lines">@@ -490,12 +492,10 @@
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">         
</span><del>-        if (hasInitializer) {
-            if (!varDecls)
-                varDecls = node;
-            else
-                varDecls = context.combineCommaNodes(location, varDecls, node);
-        }
</del><ins>+        if (!varDecls)
+            varDecls = node;
+        else
+            varDecls = context.combineCommaNodes(location, varDecls, node);
</ins><span class="cx">     } while (match(COMMA));
</span><span class="cx">     if (lastIdent)
</span><span class="cx">         lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreparserSyntaxCheckerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/parser/SyntaxChecker.h (172716 => 172717)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/parser/SyntaxChecker.h        2014-08-18 19:07:17 UTC (rev 172716)
+++ trunk/Source/JavaScriptCore/parser/SyntaxChecker.h        2014-08-18 19:11:41 UTC (rev 172717)
</span><span class="lines">@@ -158,6 +158,7 @@
</span><span class="cx">     ExpressionType createNewExpr(const JSTokenLocation&amp;, ExpressionType, int, int) { return NewExpr; }
</span><span class="cx">     ExpressionType createConditionalExpr(const JSTokenLocation&amp;, ExpressionType, ExpressionType, ExpressionType) { return ConditionalExpr; }
</span><span class="cx">     ExpressionType createAssignResolve(const JSTokenLocation&amp;, const Identifier&amp;, ExpressionType, int, int, int) { return AssignmentExpr; }
</span><ins>+    ExpressionType createEmptyVarExpression(const JSTokenLocation&amp;, const Identifier&amp;) { return AssignmentExpr; }
</ins><span class="cx">     ExpressionType createFunctionExpr(const JSTokenLocation&amp;, const Identifier*, int, int, int, int, int, int, int) { return FunctionExpr; }
</span><span class="cx">     int createFunctionBody(const JSTokenLocation&amp;, const JSTokenLocation&amp;, int, int, bool) { return FunctionBodyResult; }
</span><span class="cx">     void setFunctionNameStart(int, int) { }
</span></span></pre>
</div>
</div>

</body>
</html>