<!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>[213453] 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/213453">213453</a></dd>
<dt>Author</dt> <dd>utatane.tea@gmail.com</dd>
<dt>Date</dt> <dd>2017-03-06 09:26:35 -0800 (Mon, 06 Mar 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[JSC] Allow indexed module namespace object fields
https://bugs.webkit.org/show_bug.cgi?id=168870

Reviewed by Saam Barati.

JSTests:

* wasm/spec-tests/names.wast.js:

Source/JavaScriptCore:

While JS modules cannot expose any indexed bindings,
Wasm modules can expose them. However, module namespace
object currently does not support indexed properties.
This patch allows module namespace objects to offer
indexed binding accesses.

* runtime/JSModuleNamespaceObject.cpp:
(JSC::JSModuleNamespaceObject::getOwnPropertySlotCommon):
(JSC::JSModuleNamespaceObject::getOwnPropertySlot):
(JSC::JSModuleNamespaceObject::getOwnPropertySlotByIndex):
* runtime/JSModuleNamespaceObject.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkJSTestsChangeLog">trunk/JSTests/ChangeLog</a></li>
<li><a href="#trunkJSTestswasmspectestsnameswastjs">trunk/JSTests/wasm/spec-tests/names.wast.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSModuleNamespaceObjectcpp">trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSModuleNamespaceObjecth">trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/ChangeLog (213452 => 213453)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/ChangeLog        2017-03-06 16:57:11 UTC (rev 213452)
+++ trunk/JSTests/ChangeLog        2017-03-06 17:26:35 UTC (rev 213453)
</span><span class="lines">@@ -1,5 +1,14 @@
</span><span class="cx"> 2017-03-06  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><ins>+        [JSC] Allow indexed module namespace object fields
+        https://bugs.webkit.org/show_bug.cgi?id=168870
+
+        Reviewed by Saam Barati.
+
+        * wasm/spec-tests/names.wast.js:
+
+2017-03-06  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
+
</ins><span class="cx">         Null pointer crash when loading module with unresolved import also as a script file
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=168971
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkJSTestswasmspectestsnameswastjs"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/wasm/spec-tests/names.wast.js (213452 => 213453)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/wasm/spec-tests/names.wast.js        2017-03-06 16:57:11 UTC (rev 213452)
+++ trunk/JSTests/wasm/spec-tests/names.wast.js        2017-03-06 17:26:35 UTC (rev 213453)
</span><span class="lines">@@ -102,8 +102,7 @@
</span><span class="cx"> assert_return(() =&gt; $$.exports[&quot;_malloc&quot;](), f32(6.296875));
</span><span class="cx"> assert_return(() =&gt; $$.exports[&quot;__malloc&quot;](), f32(6.3125));
</span><span class="cx"> assert_return(() =&gt; $$.exports[&quot;~!@#$%^&amp;*()_+`-={}|[]\x5c:\x22;'&lt;&gt;?,./ &quot;](), f32(6.34375));
</span><del>-// FIXME exporting a property with a name that's a number doesn't work https://bugs.webkit.org/show_bug.cgi?id=168857
-//assert_return(() =&gt; $$.exports[&quot;0&quot;](), f32(6.359375));
</del><ins>+assert_return(() =&gt; $$.exports[&quot;0&quot;](), f32(6.359375));
</ins><span class="cx"> assert_return(() =&gt; $$.exports[&quot;_&quot;](), f32(6.375));
</span><span class="cx"> assert_return(() =&gt; $$.exports[&quot;$&quot;](), f32(6.390625));
</span><span class="cx"> assert_return(() =&gt; $$.exports[&quot;@&quot;](), f32(8.0));
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (213452 => 213453)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-03-06 16:57:11 UTC (rev 213452)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-03-06 17:26:35 UTC (rev 213453)
</span><span class="lines">@@ -1,5 +1,24 @@
</span><span class="cx"> 2017-03-06  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><ins>+        [JSC] Allow indexed module namespace object fields
+        https://bugs.webkit.org/show_bug.cgi?id=168870
+
+        Reviewed by Saam Barati.
+
+        While JS modules cannot expose any indexed bindings,
+        Wasm modules can expose them. However, module namespace
+        object currently does not support indexed properties.
+        This patch allows module namespace objects to offer
+        indexed binding accesses.
+
+        * runtime/JSModuleNamespaceObject.cpp:
+        (JSC::JSModuleNamespaceObject::getOwnPropertySlotCommon):
+        (JSC::JSModuleNamespaceObject::getOwnPropertySlot):
+        (JSC::JSModuleNamespaceObject::getOwnPropertySlotByIndex):
+        * runtime/JSModuleNamespaceObject.h:
+
+2017-03-06  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
+
</ins><span class="cx">         Null pointer crash when loading module with unresolved import also as a script file
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=168971
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSModuleNamespaceObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp (213452 => 213453)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp        2017-03-06 16:57:11 UTC (rev 213452)
+++ trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp        2017-03-06 17:26:35 UTC (rev 213453)
</span><span class="lines">@@ -113,7 +113,7 @@
</span><span class="cx">     return environment-&gt;variableAt(scopeOffset).get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool JSModuleNamespaceObject::getOwnPropertySlot(JSObject* cell, ExecState* exec, PropertyName propertyName, PropertySlot&amp; slot)
</del><ins>+bool JSModuleNamespaceObject::getOwnPropertySlotCommon(ExecState* exec, PropertyName propertyName, PropertySlot&amp; slot)
</ins><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><span class="cx">     auto scope = DECLARE_THROW_SCOPE(vm);
</span><span class="lines">@@ -120,18 +120,16 @@
</span><span class="cx"> 
</span><span class="cx">     // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-getownproperty-p
</span><span class="cx"> 
</span><del>-    JSModuleNamespaceObject* thisObject = jsCast&lt;JSModuleNamespaceObject*&gt;(cell);
-
</del><span class="cx">     // step 1.
</span><span class="cx">     // If the property name is a symbol, we don't look into the imported bindings.
</span><span class="cx">     // It may return the descriptor with writable: true, but namespace objects does not allow it in [[Set]] / [[DefineOwnProperty]] side.
</span><span class="cx">     if (propertyName.isSymbol())
</span><del>-        return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot);
</del><ins>+        return JSObject::getOwnPropertySlot(this, exec, propertyName, slot);
</ins><span class="cx"> 
</span><span class="cx">     slot.setIsTaintedByOpaqueObject();
</span><span class="cx"> 
</span><del>-    auto iterator = thisObject-&gt;m_exports.find(propertyName.uid());
-    if (iterator == thisObject-&gt;m_exports.end())
</del><ins>+    auto iterator = m_exports.find(propertyName.uid());
+    if (iterator == m_exports.end())
</ins><span class="cx">         return false;
</span><span class="cx">     ExportEntry&amp; exportEntry = iterator-&gt;value;
</span><span class="cx"> 
</span><span class="lines">@@ -138,7 +136,7 @@
</span><span class="cx">     switch (slot.internalMethodType()) {
</span><span class="cx">     case PropertySlot::InternalMethodType::GetOwnProperty:
</span><span class="cx">     case PropertySlot::InternalMethodType::Get: {
</span><del>-        JSModuleEnvironment* environment = thisObject-&gt;moduleRecordAt(exportEntry.moduleRecordOffset)-&gt;moduleEnvironment();
</del><ins>+        JSModuleEnvironment* environment = moduleRecordAt(exportEntry.moduleRecordOffset)-&gt;moduleEnvironment();
</ins><span class="cx">         ScopeOffset scopeOffset;
</span><span class="cx">         JSValue value = getValue(environment, exportEntry.localName, scopeOffset);
</span><span class="cx">         // If the value is filled with TDZ value, throw a reference error.
</span><span class="lines">@@ -147,7 +145,7 @@
</span><span class="cx">             return false;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        slot.setValueModuleNamespace(thisObject, DontDelete, value, environment, scopeOffset);
</del><ins>+        slot.setValueModuleNamespace(this, DontDelete, value, environment, scopeOffset);
</ins><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -155,7 +153,7 @@
</span><span class="cx">         // Do not perform [[Get]] for [[HasProperty]].
</span><span class="cx">         // [[Get]] / [[GetOwnProperty]] onto namespace object could throw an error while [[HasProperty]] just returns true here.
</span><span class="cx">         // https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects-hasproperty-p
</span><del>-        slot.setValue(thisObject, DontDelete, jsUndefined());
</del><ins>+        slot.setValue(this, DontDelete, jsUndefined());
</ins><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -167,6 +165,18 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool JSModuleNamespaceObject::getOwnPropertySlot(JSObject* cell, ExecState* exec, PropertyName propertyName, PropertySlot&amp; slot)
+{
+    JSModuleNamespaceObject* thisObject = jsCast&lt;JSModuleNamespaceObject*&gt;(cell);
+    return thisObject-&gt;getOwnPropertySlotCommon(exec, propertyName, slot);
+}
+
+bool JSModuleNamespaceObject::getOwnPropertySlotByIndex(JSObject* cell, ExecState* exec, unsigned propertyName, PropertySlot&amp; slot)
+{
+    JSModuleNamespaceObject* thisObject = jsCast&lt;JSModuleNamespaceObject*&gt;(cell);
+    return thisObject-&gt;getOwnPropertySlotCommon(exec, Identifier::from(exec, propertyName), slot);
+}
+
</ins><span class="cx"> bool JSModuleNamespaceObject::put(JSCell*, ExecState* exec, PropertyName, JSValue, PutPropertySlot&amp; slot)
</span><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSModuleNamespaceObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.h (213452 => 213453)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.h        2017-03-06 16:57:11 UTC (rev 213452)
+++ trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.h        2017-03-06 17:26:35 UTC (rev 213453)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&amp;);
</span><ins>+    JS_EXPORT_PRIVATE static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&amp;);
</ins><span class="cx">     JS_EXPORT_PRIVATE static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&amp;);
</span><span class="cx">     JS_EXPORT_PRIVATE static bool putByIndex(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
</span><span class="cx">     JS_EXPORT_PRIVATE static bool deleteProperty(JSCell*, ExecState*, PropertyName);
</span><span class="lines">@@ -70,6 +71,7 @@
</span><span class="cx"> private:
</span><span class="cx">     static void destroy(JSCell*);
</span><span class="cx">     static void visitChildren(JSCell*, SlotVisitor&amp;);
</span><ins>+    bool getOwnPropertySlotCommon(ExecState*, PropertyName, PropertySlot&amp;);
</ins><span class="cx"> 
</span><span class="cx">     WriteBarrierBase&lt;AbstractModuleRecord&gt;&amp; moduleRecordAt(unsigned offset)
</span><span class="cx">     {
</span></span></pre>
</div>
</div>

</body>
</html>