<!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>[209171] 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/209171">209171</a></dd>
<dt>Author</dt> <dd>utatane.tea@gmail.com</dd>
<dt>Date</dt> <dd>2016-11-30 19:54:24 -0800 (Wed, 30 Nov 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebAssembly JS API: export a module namespace object instead of a module environment
https://bugs.webkit.org/show_bug.cgi?id=165121

Reviewed by Saam Barati.

This patch setup AbstractModuleRecord further for WebAssemblyModuleRecord.
For exported entries in a wasm instance, we set up exported entries for
AbstractModuleRecord. This allows us to export WASM exported functions in
the module handling code.

Since the exported entries in the abstract module record are correctly
instantiated, the module namespace object for WASM module also starts
working correctly. So we start exposing the module namespace object
as `instance.exports` instead of the module environment object.

And we move SourceCode, lexicalVariables, and declaredVariables fields to
JSModuleRecord since they are related to JS source code (in the spec words,
they are related to the source text module record).

* runtime/AbstractModuleRecord.cpp:
(JSC::AbstractModuleRecord::AbstractModuleRecord):
* runtime/AbstractModuleRecord.h:
(JSC::AbstractModuleRecord::sourceCode): Deleted.
(JSC::AbstractModuleRecord::declaredVariables): Deleted.
(JSC::AbstractModuleRecord::lexicalVariables): Deleted.
* runtime/JSModuleRecord.cpp:
(JSC::JSModuleRecord::JSModuleRecord):
* runtime/JSModuleRecord.h:
(JSC::JSModuleRecord::sourceCode):
(JSC::JSModuleRecord::declaredVariables):
(JSC::JSModuleRecord::lexicalVariables):
* wasm/WasmFormat.cpp:
* wasm/js/JSWebAssemblyInstance.cpp:
(JSC::JSWebAssemblyInstance::finishCreation):
* wasm/js/WebAssemblyFunction.cpp:
* wasm/js/WebAssemblyInstanceConstructor.cpp:
(JSC::constructJSWebAssemblyInstance):
* wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::create):
(JSC::WebAssemblyModuleRecord::WebAssemblyModuleRecord):
(JSC::WebAssemblyModuleRecord::finishCreation):
WebAssemblyModuleRecord::link should perform linking things.
So allocating exported entries should be done here.
(JSC::WebAssemblyModuleRecord::link):
* wasm/js/WebAssemblyModuleRecord.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeAbstractModuleRecordcpp">trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeAbstractModuleRecordh">trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSModuleRecordcpp">trunk/Source/JavaScriptCore/runtime/JSModuleRecord.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSModuleRecordh">trunk/Source/JavaScriptCore/runtime/JSModuleRecord.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmFormatcpp">trunk/Source/JavaScriptCore/wasm/WasmFormat.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsJSWebAssemblyInstancecpp">trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyFunctioncpp">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyInstanceConstructorcpp">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyModuleRecordcpp">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyModuleRecordh">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2016-11-30  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
+
+        WebAssembly JS API: export a module namespace object instead of a module environment
+        https://bugs.webkit.org/show_bug.cgi?id=165121
+
+        Reviewed by Saam Barati.
+
+        This patch setup AbstractModuleRecord further for WebAssemblyModuleRecord.
+        For exported entries in a wasm instance, we set up exported entries for
+        AbstractModuleRecord. This allows us to export WASM exported functions in
+        the module handling code.
+
+        Since the exported entries in the abstract module record are correctly
+        instantiated, the module namespace object for WASM module also starts
+        working correctly. So we start exposing the module namespace object
+        as `instance.exports` instead of the module environment object.
+
+        And we move SourceCode, lexicalVariables, and declaredVariables fields to
+        JSModuleRecord since they are related to JS source code (in the spec words,
+        they are related to the source text module record).
+
+        * runtime/AbstractModuleRecord.cpp:
+        (JSC::AbstractModuleRecord::AbstractModuleRecord):
+        * runtime/AbstractModuleRecord.h:
+        (JSC::AbstractModuleRecord::sourceCode): Deleted.
+        (JSC::AbstractModuleRecord::declaredVariables): Deleted.
+        (JSC::AbstractModuleRecord::lexicalVariables): Deleted.
+        * runtime/JSModuleRecord.cpp:
+        (JSC::JSModuleRecord::JSModuleRecord):
+        * runtime/JSModuleRecord.h:
+        (JSC::JSModuleRecord::sourceCode):
+        (JSC::JSModuleRecord::declaredVariables):
+        (JSC::JSModuleRecord::lexicalVariables):
+        * wasm/WasmFormat.cpp:
+        * wasm/js/JSWebAssemblyInstance.cpp:
+        (JSC::JSWebAssemblyInstance::finishCreation):
+        * wasm/js/WebAssemblyFunction.cpp:
+        * wasm/js/WebAssemblyInstanceConstructor.cpp:
+        (JSC::constructJSWebAssemblyInstance):
+        * wasm/js/WebAssemblyModuleRecord.cpp:
+        (JSC::WebAssemblyModuleRecord::create):
+        (JSC::WebAssemblyModuleRecord::WebAssemblyModuleRecord):
+        (JSC::WebAssemblyModuleRecord::finishCreation):
+        WebAssemblyModuleRecord::link should perform linking things.
+        So allocating exported entries should be done here.
+        (JSC::WebAssemblyModuleRecord::link):
+        * wasm/js/WebAssemblyModuleRecord.h:
+
</ins><span class="cx"> 2016-11-30  Mark Lam  &lt;mark.lam@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         TypeInfo::OutOfLineTypeFlags should be 16 bits in size.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeAbstractModuleRecordcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -38,12 +38,9 @@
</span><span class="cx"> 
</span><span class="cx"> const ClassInfo AbstractModuleRecord::s_info = { &quot;AbstractModuleRecord&quot;, &amp;Base::s_info, 0, CREATE_METHOD_TABLE(AbstractModuleRecord) };
</span><span class="cx"> 
</span><del>-AbstractModuleRecord::AbstractModuleRecord(VM&amp; vm, Structure* structure, const Identifier&amp; moduleKey, const SourceCode&amp; sourceCode, const VariableEnvironment&amp; declaredVariables, const VariableEnvironment&amp; lexicalVariables)
</del><ins>+AbstractModuleRecord::AbstractModuleRecord(VM&amp; vm, Structure* structure, const Identifier&amp; moduleKey)
</ins><span class="cx">     : Base(vm, structure)
</span><span class="cx">     , m_moduleKey(moduleKey)
</span><del>-    , m_sourceCode(sourceCode)
-    , m_declaredVariables(declaredVariables)
-    , m_lexicalVariables(lexicalVariables)
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeAbstractModuleRecordh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.h (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.h        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/runtime/AbstractModuleRecord.h        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -88,7 +88,6 @@
</span><span class="cx">     std::optional&lt;ImportEntry&gt; tryGetImportEntry(UniquedStringImpl* localName);
</span><span class="cx">     std::optional&lt;ExportEntry&gt; tryGetExportEntry(UniquedStringImpl* exportName);
</span><span class="cx"> 
</span><del>-    const SourceCode&amp; sourceCode() const { return m_sourceCode; }
</del><span class="cx">     const Identifier&amp; moduleKey() const { return m_moduleKey; }
</span><span class="cx">     const OrderedIdentifierSet&amp; requestedModules() const { return m_requestedModules; }
</span><span class="cx">     const ExportEntries&amp; exportEntries() const { return m_exportEntries; }
</span><span class="lines">@@ -95,9 +94,6 @@
</span><span class="cx">     const ImportEntries&amp; importEntries() const { return m_importEntries; }
</span><span class="cx">     const OrderedIdentifierSet&amp; starExportEntries() const { return m_starExportEntries; }
</span><span class="cx"> 
</span><del>-    const VariableEnvironment&amp; declaredVariables() const { return m_declaredVariables; }
-    const VariableEnvironment&amp; lexicalVariables() const { return m_lexicalVariables; }
-
</del><span class="cx">     void dump();
</span><span class="cx"> 
</span><span class="cx">     struct Resolution {
</span><span class="lines">@@ -126,7 +122,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> protected:
</span><del>-    AbstractModuleRecord(VM&amp;, Structure*, const Identifier&amp;, const SourceCode&amp;, const VariableEnvironment&amp;, const VariableEnvironment&amp;);
</del><ins>+    AbstractModuleRecord(VM&amp;, Structure*, const Identifier&amp;);
</ins><span class="cx">     void finishCreation(ExecState*, VM&amp;);
</span><span class="cx"> 
</span><span class="cx">     static void visitChildren(JSCell*, SlotVisitor&amp;);
</span><span class="lines">@@ -143,11 +139,6 @@
</span><span class="cx">     // The loader resolves the given module name to the module key. The module key is the unique value to represent this module.
</span><span class="cx">     Identifier m_moduleKey;
</span><span class="cx"> 
</span><del>-    SourceCode m_sourceCode;
-
-    VariableEnvironment m_declaredVariables;
-    VariableEnvironment m_lexicalVariables;
-
</del><span class="cx">     // Currently, we don't keep the occurrence order of the import / export entries.
</span><span class="cx">     // So, we does not guarantee the order of the errors.
</span><span class="cx">     // e.g. The import declaration that occurr later than the another import declaration may
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSModuleRecordcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSModuleRecord.cpp (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSModuleRecord.cpp        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/runtime/JSModuleRecord.cpp        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -50,7 +50,10 @@
</span><span class="cx">     return instance;
</span><span class="cx"> }
</span><span class="cx"> JSModuleRecord::JSModuleRecord(VM&amp; vm, Structure* structure, const Identifier&amp; moduleKey, const SourceCode&amp; sourceCode, const VariableEnvironment&amp; declaredVariables, const VariableEnvironment&amp; lexicalVariables)
</span><del>-    : Base(vm, structure, moduleKey, sourceCode, declaredVariables, lexicalVariables)
</del><ins>+    : Base(vm, structure, moduleKey)
+    , m_sourceCode(sourceCode)
+    , m_declaredVariables(declaredVariables)
+    , m_lexicalVariables(lexicalVariables)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSModuleRecordh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSModuleRecord.h (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSModuleRecord.h        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/runtime/JSModuleRecord.h        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -51,6 +51,10 @@
</span><span class="cx">     void link(ExecState*);
</span><span class="cx">     JS_EXPORT_PRIVATE JSValue evaluate(ExecState*);
</span><span class="cx"> 
</span><ins>+    const SourceCode&amp; sourceCode() const { return m_sourceCode; }
+    const VariableEnvironment&amp; declaredVariables() const { return m_declaredVariables; }
+    const VariableEnvironment&amp; lexicalVariables() const { return m_lexicalVariables; }
+
</ins><span class="cx">     ModuleProgramExecutable* moduleProgramExecutable() const { return m_moduleProgramExecutable.get(); }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="lines">@@ -63,6 +67,9 @@
</span><span class="cx"> 
</span><span class="cx">     void instantiateDeclarations(ExecState*, ModuleProgramExecutable*);
</span><span class="cx"> 
</span><ins>+    SourceCode m_sourceCode;
+    VariableEnvironment m_declaredVariables;
+    VariableEnvironment m_lexicalVariables;
</ins><span class="cx">     WriteBarrier&lt;ModuleProgramExecutable&gt; m_moduleProgramExecutable;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmFormatcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmFormat.cpp (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmFormat.cpp        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/wasm/WasmFormat.cpp        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -31,6 +31,11 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;WasmMemory.h&quot;
</span><span class="cx"> 
</span><ins>+#if COMPILER(GCC) &amp;&amp; ASSERT_DISABLED
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored &quot;-Wreturn-type&quot;
+#endif // COMPILER(GCC) &amp;&amp; ASSERT_DISABLED
+
</ins><span class="cx"> namespace JSC { namespace Wasm {
</span><span class="cx"> 
</span><span class="cx"> const char* toString(Type type)
</span><span class="lines">@@ -53,4 +58,8 @@
</span><span class="cx"> 
</span><span class="cx"> } } // namespace JSC::Wasm
</span><span class="cx"> 
</span><ins>+#if COMPILER(GCC) &amp;&amp; ASSERT_DISABLED
+#pragma GCC diagnostic pop
+#endif // COMPILER(GCC) &amp;&amp; ASSERT_DISABLED
+
</ins><span class="cx"> #endif // ENABLE(WEBASSEMBLY)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsJSWebAssemblyInstancecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -56,10 +56,10 @@
</span><span class="cx"> void JSWebAssemblyInstance::finishCreation(VM&amp; vm, JSWebAssemblyModule* module, JSModuleNamespaceObject* moduleNamespaceObject)
</span><span class="cx"> {
</span><span class="cx">     Base::finishCreation(vm);
</span><ins>+    ASSERT(inherits(info()));
</ins><span class="cx">     m_module.set(vm, this, module);
</span><span class="cx">     m_moduleNamespaceObject.set(vm, this, moduleNamespaceObject);
</span><del>-    // FIXME this should put the module namespace object onto the exports object, instead of moduleEnvironment in WebAssemblyInstanceConstructor. https://bugs.webkit.org/show_bug.cgi?id=165121
-    ASSERT(inherits(info()));
</del><ins>+    putDirect(vm, Identifier::fromString(&amp;vm, &quot;exports&quot;), moduleNamespaceObject, None);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void JSWebAssemblyInstance::destroy(JSCell* cell)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyFunctioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -33,7 +33,7 @@
</span><span class="cx"> #include &quot;JSFunctionInlines.h&quot;
</span><span class="cx"> #include &quot;JSObject.h&quot;
</span><span class="cx"> #include &quot;JSWebAssemblyInstance.h&quot;
</span><del>-#include &quot;LLintThunks.h&quot;
</del><ins>+#include &quot;LLIntThunks.h&quot;
</ins><span class="cx"> #include &quot;ProtoCallFrame.h&quot;
</span><span class="cx"> #include &quot;VM.h&quot;
</span><span class="cx"> #include &quot;WasmFormat.h&quot;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyInstanceConstructorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -72,10 +72,7 @@
</span><span class="cx">         return JSValue::encode(throwException(state, scope, createTypeError(state, ASCIILiteral(&quot;second argument to WebAssembly.Instance must be Object because the WebAssembly.Module has imports&quot;), defaultSourceAppender, runtimeTypeForValue(importArgument))));
</span><span class="cx"> 
</span><span class="cx">     Identifier moduleKey = Identifier::fromUid(PrivateName(PrivateName::Description, &quot;WebAssemblyInstance&quot;));
</span><del>-    SourceCode sourceCode;
-    VariableEnvironment declaredVariables;
-    VariableEnvironment lexicalVariables;
-    WebAssemblyModuleRecord* moduleRecord = WebAssemblyModuleRecord::create(state, vm, globalObject-&gt;webAssemblyModuleRecordStructure(), moduleKey, sourceCode, declaredVariables, lexicalVariables);
</del><ins>+    WebAssemblyModuleRecord* moduleRecord = WebAssemblyModuleRecord::create(state, vm, globalObject-&gt;webAssemblyModuleRecordStructure(), moduleKey, moduleInformation);
</ins><span class="cx">     RETURN_IF_EXCEPTION(scope, encodedJSValue());
</span><span class="cx"> 
</span><span class="cx">     Structure* instanceStructure = InternalFunction::createSubclassStructure(state, state-&gt;newTarget(), globalObject-&gt;WebAssemblyInstanceStructure());
</span><span class="lines">@@ -88,8 +85,6 @@
</span><span class="cx">     RETURN_IF_EXCEPTION(scope, encodedJSValue());
</span><span class="cx">     if (verbose)
</span><span class="cx">         moduleRecord-&gt;dump();
</span><del>-    // FIXME the following should be in JSWebAssemblyInstance instead of here. https://bugs.webkit.org/show_bug.cgi?id=165121
-    instance-&gt;putDirect(vm, Identifier::fromString(&amp;vm, &quot;exports&quot;), JSValue(moduleRecord-&gt;moduleEnvironment()), None);
</del><span class="cx">     JSValue startResult = moduleRecord-&gt;evaluate(state);
</span><span class="cx">     UNUSED_PARAM(startResult);
</span><span class="cx">     RETURN_IF_EXCEPTION(scope, encodedJSValue());
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyModuleRecordcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -46,15 +46,15 @@
</span><span class="cx">     return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebAssemblyModuleRecord* WebAssemblyModuleRecord::create(ExecState* exec, VM&amp; vm, Structure* structure, const Identifier&amp; moduleKey, const SourceCode&amp; sourceCode, const VariableEnvironment&amp; declaredVariables, const VariableEnvironment&amp; lexicalVariables)
</del><ins>+WebAssemblyModuleRecord* WebAssemblyModuleRecord::create(ExecState* exec, VM&amp; vm, Structure* structure, const Identifier&amp; moduleKey, const Wasm::ModuleInformation&amp; moduleInformation)
</ins><span class="cx"> {
</span><del>-    WebAssemblyModuleRecord* instance = new (NotNull, allocateCell&lt;WebAssemblyModuleRecord&gt;(vm.heap)) WebAssemblyModuleRecord(vm, structure, moduleKey, sourceCode, declaredVariables, lexicalVariables);
-    instance-&gt;finishCreation(exec, vm);
</del><ins>+    WebAssemblyModuleRecord* instance = new (NotNull, allocateCell&lt;WebAssemblyModuleRecord&gt;(vm.heap)) WebAssemblyModuleRecord(vm, structure, moduleKey);
+    instance-&gt;finishCreation(exec, vm, moduleInformation);
</ins><span class="cx">     return instance;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebAssemblyModuleRecord::WebAssemblyModuleRecord(VM&amp; vm, Structure* structure, const Identifier&amp; moduleKey, const SourceCode&amp; sourceCode, const VariableEnvironment&amp; declaredVariables, const VariableEnvironment&amp; lexicalVariables)
-    : Base(vm, structure, moduleKey, sourceCode, declaredVariables, lexicalVariables)
</del><ins>+WebAssemblyModuleRecord::WebAssemblyModuleRecord(VM&amp; vm, Structure* structure, const Identifier&amp; moduleKey)
+    : Base(vm, structure, moduleKey)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -64,10 +64,31 @@
</span><span class="cx">     thisObject-&gt;WebAssemblyModuleRecord::~WebAssemblyModuleRecord();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebAssemblyModuleRecord::finishCreation(ExecState* exec, VM&amp; vm)
</del><ins>+void WebAssemblyModuleRecord::finishCreation(ExecState* exec, VM&amp; vm, const Wasm::ModuleInformation&amp; moduleInformation)
</ins><span class="cx"> {
</span><span class="cx">     Base::finishCreation(exec, vm);
</span><span class="cx">     ASSERT(inherits(info()));
</span><ins>+    for (const auto&amp; exp : moduleInformation.exports) {
+        switch (exp.kind) {
+        case Wasm::External::Function: {
+            addExportEntry(ExportEntry::createLocal(exp.field, exp.field));
+            break;
+        }
+        case Wasm::External::Table: {
+            // FIXME https://bugs.webkit.org/show_bug.cgi?id=164135
+            break;
+        }
+        case Wasm::External::Memory: {
+            // FIXME https://bugs.webkit.org/show_bug.cgi?id=164134
+            break;
+        }
+        case Wasm::External::Global: {
+            // FIXME https://bugs.webkit.org/show_bug.cgi?id=164133
+            // In the MVP, only immutable global variables can be exported.
+            break;
+        }
+        }
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebAssemblyModuleRecord::visitChildren(JSCell* cell, SlotVisitor&amp; visitor)
</span><span class="lines">@@ -92,11 +113,8 @@
</span><span class="cx"> 
</span><span class="cx">     // Let exports be a list of (string, JS value) pairs that is mapped from each external value e in instance.exports as follows:
</span><span class="cx">     JSModuleEnvironment* moduleEnvironment = JSModuleEnvironment::create(vm, globalObject, nullptr, exportSymbolTable, JSValue(), this);
</span><del>-    unsigned offset = 0;
</del><span class="cx">     for (const auto&amp; exp : moduleInformation.exports) {
</span><span class="cx">         JSValue exportedValue;
</span><del>-        PutPropertySlot slot(this);
-        slot.setNewProperty(this, offset++);
</del><span class="cx">         switch (exp.kind) {
</span><span class="cx">         case Wasm::External::Function: {
</span><span class="cx">             // 1. If e is a closure c:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyModuleRecordh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h (209170 => 209171)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h        2016-12-01 03:20:30 UTC (rev 209170)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h        2016-12-01 03:54:24 UTC (rev 209171)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #if ENABLE(WEBASSEMBLY)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;AbstractModuleRecord.h&quot;
</span><ins>+#include &quot;WasmFormat.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><span class="lines">@@ -43,15 +44,15 @@
</span><span class="cx">     DECLARE_EXPORT_INFO;
</span><span class="cx"> 
</span><span class="cx">     static Structure* createStructure(VM&amp;, JSGlobalObject*, JSValue);
</span><del>-    static WebAssemblyModuleRecord* create(ExecState*, VM&amp;, Structure*, const Identifier&amp;, const SourceCode&amp;, const VariableEnvironment&amp;, const VariableEnvironment&amp;);
</del><ins>+    static WebAssemblyModuleRecord* create(ExecState*, VM&amp;, Structure*, const Identifier&amp;, const Wasm::ModuleInformation&amp;);
</ins><span class="cx"> 
</span><span class="cx">     void link(ExecState*, JSWebAssemblyInstance*);
</span><span class="cx">     JS_EXPORT_PRIVATE JSValue evaluate(ExecState*);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    WebAssemblyModuleRecord(VM&amp;, Structure*, const Identifier&amp;, const SourceCode&amp;, const VariableEnvironment&amp;, const VariableEnvironment&amp;);
</del><ins>+    WebAssemblyModuleRecord(VM&amp;, Structure*, const Identifier&amp;);
</ins><span class="cx"> 
</span><del>-    void finishCreation(ExecState*, VM&amp;);
</del><ins>+    void finishCreation(ExecState*, VM&amp;, const Wasm::ModuleInformation&amp;);
</ins><span class="cx">     static void destroy(JSCell*);
</span><span class="cx"> 
</span><span class="cx">     static void visitChildren(JSCell*, SlotVisitor&amp;);
</span></span></pre>
</div>
</div>

</body>
</html>