<!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>[183790] 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/183790">183790</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-05-04 20:35:13 -0700 (Mon, 04 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Unreviewed, rolling out <a href="http://trac.webkit.org/projects/webkit/changeset/183789">r183789</a>.
https://bugs.webkit.org/show_bug.cgi?id=144620

Causing flakiness on exceptionFuzz tests locally on 32-bit
build (Requested by saamyjoon on #webkit).

Reverted changeset:

&quot;Global functions should be initialized as JSFunctions in byte
code&quot;
https://bugs.webkit.org/show_bug.cgi?id=144178
http://trac.webkit.org/changeset/183789</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeUnlinkedCodeBlockcpp">trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeUnlinkedCodeBlockh">trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp">trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorh">trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeExecutablecpp">trunk/Source/JavaScriptCore/runtime/Executable.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjecth">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (183789 => 183790)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-05-05 03:27:09 UTC (rev 183789)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-05-05 03:35:13 UTC (rev 183790)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2015-05-04  Commit Queue  &lt;commit-queue@webkit.org&gt;
+
+        Unreviewed, rolling out r183789.
+        https://bugs.webkit.org/show_bug.cgi?id=144620
+
+        Causing flakiness on exceptionFuzz tests locally on 32-bit
+        build (Requested by saamyjoon on #webkit).
+
+        Reverted changeset:
+
+        &quot;Global functions should be initialized as JSFunctions in byte
+        code&quot;
+        https://bugs.webkit.org/show_bug.cgi?id=144178
+        http://trac.webkit.org/changeset/183789
+
</ins><span class="cx"> 2015-05-04  Saam Barati  &lt;saambarati1@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Global functions should be initialized as JSFunctions in byte code
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeUnlinkedCodeBlockcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp (183789 => 183790)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp        2015-05-05 03:27:09 UTC (rev 183789)
+++ trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp        2015-05-05 03:35:13 UTC (rev 183790)
</span><span class="lines">@@ -471,6 +471,8 @@
</span><span class="cx">     UnlinkedProgramCodeBlock* thisObject = jsCast&lt;UnlinkedProgramCodeBlock*&gt;(cell);
</span><span class="cx">     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
</span><span class="cx">     Base::visitChildren(thisObject, visitor);
</span><ins>+    for (size_t i = 0, end = thisObject-&gt;m_functionDeclarations.size(); i != end; i++)
+        visitor.append(&amp;thisObject-&gt;m_functionDeclarations[i].second);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> UnlinkedCodeBlock::~UnlinkedCodeBlock()
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeUnlinkedCodeBlockh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h (183789 => 183790)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h        2015-05-05 03:27:09 UTC (rev 183789)
+++ trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h        2015-05-05 03:35:13 UTC (rev 183790)
</span><span class="lines">@@ -654,14 +654,21 @@
</span><span class="cx"> 
</span><span class="cx">     static void destroy(JSCell*);
</span><span class="cx"> 
</span><ins>+    void addFunctionDeclaration(VM&amp; vm, const Identifier&amp; name, UnlinkedFunctionExecutable* functionExecutable)
+    {
+        m_functionDeclarations.append(std::make_pair(name, WriteBarrier&lt;UnlinkedFunctionExecutable&gt;(vm, this, functionExecutable)));
+    }
+
</ins><span class="cx">     void addVariableDeclaration(const Identifier&amp; name, bool isConstant)
</span><span class="cx">     {
</span><span class="cx">         m_varDeclarations.append(std::make_pair(name, isConstant));
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     typedef Vector&lt;std::pair&lt;Identifier, bool&gt;&gt; VariableDeclations;
</span><ins>+    typedef Vector&lt;std::pair&lt;Identifier, WriteBarrier&lt;UnlinkedFunctionExecutable&gt;&gt; &gt; FunctionDeclations;
</ins><span class="cx"> 
</span><span class="cx">     const VariableDeclations&amp; variableDeclarations() const { return m_varDeclarations; }
</span><ins>+    const FunctionDeclations&amp; functionDeclarations() const { return m_functionDeclarations; }
</ins><span class="cx"> 
</span><span class="cx">     static void visitChildren(JSCell*, SlotVisitor&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -672,6 +679,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     VariableDeclations m_varDeclarations;
</span><ins>+    FunctionDeclations m_functionDeclarations;
</ins><span class="cx"> 
</span><span class="cx"> public:
</span><span class="cx">     static Structure* createStructure(VM&amp; vm, JSGlobalObject* globalObject, JSValue proto)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp (183789 => 183790)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp        2015-05-05 03:27:09 UTC (rev 183789)
+++ trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp        2015-05-05 03:35:13 UTC (rev 183790)
</span><span class="lines">@@ -77,17 +77,9 @@
</span><span class="cx"> 
</span><span class="cx">     {
</span><span class="cx">         RefPtr&lt;RegisterID&gt; temp = newTemporary();
</span><del>-        RefPtr&lt;RegisterID&gt; globalScope = scopeRegister(); // FIXME: With lexical scoping, this won't always be the global object: https://bugs.webkit.org/show_bug.cgi?id=142944 
-        for (auto functionPair : m_functionsToInitialize) {
-            FunctionBodyNode* functionBody = functionPair.first;
-            FunctionVariableType functionType = functionPair.second;
</del><ins>+        for (FunctionBodyNode* functionBody : m_functionsToInitialize) {
</ins><span class="cx">             emitNewFunction(temp.get(), functionBody);
</span><del>-            if (functionType == NormalFunctionVariable)
-                initializeVariable(variable(functionBody-&gt;ident()) , temp.get());
-            else if (functionType == GlobalFunctionVariable)
-                emitPutToScope(globalScope.get(), Variable(functionBody-&gt;ident()), temp.get(), ThrowIfNotFound);
-            else
-                RELEASE_ASSERT_NOT_REACHED();
</del><ins>+            initializeVariable(variable(functionBody-&gt;ident()), temp.get());
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     
</span><span class="lines">@@ -171,7 +163,8 @@
</span><span class="cx"> 
</span><span class="cx">     for (size_t i = 0; i &lt; functionStack.size(); ++i) {
</span><span class="cx">         FunctionBodyNode* function = functionStack[i];
</span><del>-        m_functionsToInitialize.append(std::make_pair(function, GlobalFunctionVariable));
</del><ins>+        UnlinkedFunctionExecutable* unlinkedFunction = makeFunction(function);
+        codeBlock-&gt;addFunctionDeclaration(*m_vm, function-&gt;ident(), unlinkedFunction);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (size_t i = 0; i &lt; varStack.size(); ++i)
</span><span class="lines">@@ -391,7 +384,7 @@
</span><span class="cx">     for (FunctionBodyNode* function : functionNode-&gt;functionStack()) {
</span><span class="cx">         const Identifier&amp; ident = function-&gt;ident();
</span><span class="cx">         createVariable(ident, varKind(ident.impl()), IsVariable);
</span><del>-        m_functionsToInitialize.append(std::make_pair(function, NormalFunctionVariable));
</del><ins>+        m_functionsToInitialize.append(function);
</ins><span class="cx">     }
</span><span class="cx">     for (auto&amp; entry : functionNode-&gt;varStack()) {
</span><span class="cx">         ConstantMode constantMode = modeForIsConstant(entry.second &amp; DeclarationStacks::IsConstant);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h (183789 => 183790)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h        2015-05-05 03:27:09 UTC (rev 183789)
+++ trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h        2015-05-05 03:35:13 UTC (rev 183790)
</span><span class="lines">@@ -744,8 +744,7 @@
</span><span class="cx">         Vector&lt;std::unique_ptr&lt;ForInContext&gt;&gt; m_forInContextStack;
</span><span class="cx">         Vector&lt;TryContext&gt; m_tryContextStack;
</span><span class="cx">         Vector&lt;std::pair&lt;RefPtr&lt;RegisterID&gt;, const DeconstructionPatternNode*&gt;&gt; m_deconstructedParameters;
</span><del>-        enum FunctionVariableType : uint8_t { NormalFunctionVariable, GlobalFunctionVariable };
-        Vector&lt;std::pair&lt;FunctionBodyNode*, FunctionVariableType&gt;&gt; m_functionsToInitialize;
</del><ins>+        Vector&lt;FunctionBodyNode*&gt; m_functionsToInitialize;
</ins><span class="cx">         bool m_needToInitializeArguments { false };
</span><span class="cx">         
</span><span class="cx">         Vector&lt;TryRange&gt; m_tryRanges;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeExecutablecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Executable.cpp (183789 => 183790)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Executable.cpp        2015-05-05 03:27:09 UTC (rev 183789)
+++ trunk/Source/JavaScriptCore/runtime/Executable.cpp        2015-05-05 03:35:13 UTC (rev 183790)
</span><span class="lines">@@ -510,11 +510,12 @@
</span><span class="cx">     BatchedTransitionOptimizer optimizer(vm, globalObject);
</span><span class="cx"> 
</span><span class="cx">     const UnlinkedProgramCodeBlock::VariableDeclations&amp; variableDeclarations = unlinkedCodeBlock-&gt;variableDeclarations();
</span><ins>+    const UnlinkedProgramCodeBlock::FunctionDeclations&amp; functionDeclarations = unlinkedCodeBlock-&gt;functionDeclarations();
</ins><span class="cx"> 
</span><del>-    for (size_t i = 0, numberOfFunctions = unlinkedCodeBlock-&gt;numberOfFunctionDecls(); i &lt; numberOfFunctions; ++i) {
-        UnlinkedFunctionExecutable* unlinkedFunctionExecutable = unlinkedCodeBlock-&gt;functionDecl(i);
-        ASSERT(!unlinkedFunctionExecutable-&gt;name().isEmpty());
-        globalObject-&gt;addFunction(callFrame, unlinkedFunctionExecutable-&gt;name());
</del><ins>+    for (size_t i = 0; i &lt; functionDeclarations.size(); ++i) {
+        UnlinkedFunctionExecutable* unlinkedFunctionExecutable = functionDeclarations[i].second.get();
+        JSValue value = JSFunction::create(vm, unlinkedFunctionExecutable-&gt;link(vm, m_source), scope);
+        globalObject-&gt;addFunction(callFrame, functionDeclarations[i].first, value);
</ins><span class="cx">         if (vm.typeProfiler() || vm.controlFlowProfiler()) {
</span><span class="cx">             vm.functionHasExecutedCache()-&gt;insertUnexecutedRange(sourceID(), 
</span><span class="cx">                 unlinkedFunctionExecutable-&gt;typeProfilingStartOffset(), 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp (183789 => 183790)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2015-05-05 03:27:09 UTC (rev 183789)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2015-05-05 03:35:13 UTC (rev 183790)
</span><span class="lines">@@ -502,12 +502,16 @@
</span><span class="cx">     return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSGlobalObject::addGlobalVar(const Identifier&amp; ident, ConstantMode constantMode)
</del><ins>+JSGlobalObject::NewGlobalVar JSGlobalObject::addGlobalVar(const Identifier&amp; ident, ConstantMode constantMode)
</ins><span class="cx"> {
</span><span class="cx">     ConcurrentJITLocker locker(symbolTable()-&gt;m_lock);
</span><span class="cx">     SymbolTableEntry entry = symbolTable()-&gt;get(locker, ident.impl());
</span><del>-    if (!entry.isNull())
-        return;
</del><ins>+    if (!entry.isNull()) {
+        NewGlobalVar result;
+        result.offset = entry.scopeOffset();
+        result.set = entry.watchpointSet();
+        return result;
+    }
</ins><span class="cx">     
</span><span class="cx">     ScopeOffset offset = symbolTable()-&gt;takeNextScopeOffset(locker);
</span><span class="cx">     SymbolTableEntry newEntry(VarOffset(offset), (constantMode == IsConstant) ? ReadOnly : 0);
</span><span class="lines">@@ -519,13 +523,21 @@
</span><span class="cx">     
</span><span class="cx">     ScopeOffset offsetForAssert = addVariables(1);
</span><span class="cx">     RELEASE_ASSERT(offsetForAssert == offset);
</span><ins>+
+    NewGlobalVar var;
+    var.offset = offset;
+    var.set = newEntry.watchpointSet();
+    return var;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSGlobalObject::addFunction(ExecState* exec, const Identifier&amp; propertyName)
</del><ins>+void JSGlobalObject::addFunction(ExecState* exec, const Identifier&amp; propertyName, JSValue value)
</ins><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><span class="cx">     removeDirect(vm, propertyName); // Newly declared functions overwrite existing properties.
</span><del>-    addGlobalVar(propertyName, IsVariable);
</del><ins>+    NewGlobalVar var = addGlobalVar(propertyName, IsVariable);
+    variableAt(var.offset).set(exec-&gt;vm(), this, value);
+    if (var.set)
+        var.set-&gt;touch(VariableWriteFireDetail(this, propertyName));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static inline JSObject* lastInPrototypeChain(JSObject* object)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h (183789 => 183790)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2015-05-05 03:27:09 UTC (rev 183789)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2015-05-05 03:35:13 UTC (rev 183790)
</span><span class="lines">@@ -338,7 +338,11 @@
</span><span class="cx">         setGlobalThis(vm, thisValue);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void addGlobalVar(const Identifier&amp;, ConstantMode);
</del><ins>+    struct NewGlobalVar {
+        ScopeOffset offset;
+        WatchpointSet* set;
+    };
+    NewGlobalVar addGlobalVar(const Identifier&amp;, ConstantMode);
</ins><span class="cx"> 
</span><span class="cx"> public:
</span><span class="cx">     JS_EXPORT_PRIVATE ~JSGlobalObject();
</span><span class="lines">@@ -370,7 +374,7 @@
</span><span class="cx">         if (!hasProperty(exec, propertyName))
</span><span class="cx">             addGlobalVar(propertyName, IsConstant);
</span><span class="cx">     }
</span><del>-    void addFunction(ExecState*, const Identifier&amp;);
</del><ins>+    void addFunction(ExecState*, const Identifier&amp;, JSValue);
</ins><span class="cx"> 
</span><span class="cx">     // The following accessors return pristine values, even if a script 
</span><span class="cx">     // replaces the global object's associated property.
</span></span></pre>
</div>
</div>

</body>
</html>