<!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>[210401] branches/safari-603-branch</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/210401">210401</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2017-01-05 17:47:16 -0800 (Thu, 05 Jan 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/209979">r209979</a>. rdar://problem/29735737</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari603branchJSTestsChangeLog">branches/safari-603-branch/JSTests/ChangeLog</a></li>
<li><a href="#branchessafari603branchJSTestswasmjsapitest_basic_apijs">branches/safari-603-branch/JSTests/wasm/js-api/test_basic_api.js</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCoreChangeLog">branches/safari-603-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCorewasmJSWebAssemblycpp">branches/safari-603-branch/Source/JavaScriptCore/wasm/JSWebAssembly.cpp</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCorewasmWasmPlancpp">branches/safari-603-branch/Source/JavaScriptCore/wasm/WasmPlan.cpp</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCorewasmWasmPlanh">branches/safari-603-branch/Source/JavaScriptCore/wasm/WasmPlan.h</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCorewasmjsJSWebAssemblyHelpersh">branches/safari-603-branch/Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCorewasmjsWebAssemblyModuleConstructorcpp">branches/safari-603-branch/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp</a></li>
<li><a href="#branchessafari603branchSourceJavaScriptCorewasmjsWebAssemblyModuleConstructorh">branches/safari-603-branch/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari603branchJSTestswasmjsapiModulecompilejs">branches/safari-603-branch/JSTests/wasm/js-api/Module-compile.js</a></li>
<li><a href="#branchessafari603branchJSTestswasmjsapivalidatejs">branches/safari-603-branch/JSTests/wasm/js-api/validate.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari603branchJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/JSTests/ChangeLog (210400 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/JSTests/ChangeLog        2017-01-06 01:06:15 UTC (rev 210400)
+++ branches/safari-603-branch/JSTests/ChangeLog        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -1,5 +1,23 @@
</span><span class="cx"> 2017-01-05 Matthew Hanson <matthew_hanson@apple.com>
</span><span class="cx">
</span><ins>+ Merge r209979. rdar://problem/29735737
+
+ 2016-12-18 Saam Barati <sbarati@apple.com>
+
+ WebAssembly: Implement the WebAssembly.compile and WebAssembly.validate
+ https://bugs.webkit.org/show_bug.cgi?id=165936
+
+ Reviewed by Mark Lam.
+
+ * wasm/js-api/Module-compile.js: Added.
+ (async.testPromiseAPI):
+ * wasm/js-api/test_basic_api.js:
+ (const.c.in.constructorProperties.switch):
+ * wasm/js-api/validate.js: Added.
+ (assert.truthy.WebAssembly.validate.builder.WebAssembly):
+
+2017-01-05 Matthew Hanson <matthew_hanson@apple.com>
+
</ins><span class="cx"> Merge r210312. rdar://problem/29876342
</span><span class="cx">
</span><span class="cx"> 2017-01-04 JF Bastien <jfbastien@apple.com>
</span></span></pre></div>
<a id="branchessafari603branchJSTestswasmjsapiModulecompilejs"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/JSTests/wasm/js-api/Module-compile.js (0 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/JSTests/wasm/js-api/Module-compile.js         (rev 0)
+++ branches/safari-603-branch/JSTests/wasm/js-api/Module-compile.js        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -0,0 +1,58 @@
</span><ins>+import * as assert from '../assert.js';
+import Builder from '../Builder.js';
+
+let done = false;
+async function testPromiseAPI() {
+ {
+ // Can't declare more than one memory.
+ const builder = (new Builder())
+ .Type().End()
+ .Import().Memory("imp", "memory", {initial: 20}).End()
+ .Function().End()
+ .Memory().InitialMaxPages(1, 1).End()
+ .Export().End()
+ .Code()
+ .End();
+
+ let threw = false;
+ try {
+ await WebAssembly.compile(builder.WebAssembly().get());
+ } catch(e) {
+ threw = true;
+ assert.truthy(e instanceof WebAssembly.CompileError);
+ assert.truthy(e.message === "WebAssembly.Module doesn't parse at byte 34 / 43: Memory section cannot exist if an Import has a memory (evaluating 'WebAssembly.compile(builder.WebAssembly().get())')");
+ }
+ assert.truthy(threw);
+ }
+
+ {
+ let threw = false;
+ try {
+ await WebAssembly.compile(20);
+ } catch(e) {
+ threw = true;
+ assert.truthy(e instanceof TypeError);
+ assert.eq(e.message, "first argument must be an ArrayBufferView or an ArrayBuffer (evaluating 'WebAssembly.compile(20)')");
+ }
+ assert.truthy(threw);
+ }
+
+ {
+ const builder = (new Builder())
+ .Type().End()
+ .Import().Memory("imp", "memory", {initial: 20}).End()
+ .Function().End()
+ .Export().End()
+ .Code()
+ .End();
+
+ let module = await WebAssembly.compile(builder.WebAssembly().get());
+ assert.truthy(module instanceof WebAssembly.Module);
+ }
+
+ done = true;
+}
+
+testPromiseAPI();
+drainMicrotasks();
+assert.truthy(done);
</ins></span></pre></div>
<a id="branchessafari603branchJSTestswasmjsapitest_basic_apijs"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/JSTests/wasm/js-api/test_basic_api.js (210400 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/JSTests/wasm/js-api/test_basic_api.js        2017-01-06 01:06:15 UTC (rev 210400)
+++ branches/safari-603-branch/JSTests/wasm/js-api/test_basic_api.js        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -53,7 +53,7 @@
</span><span class="cx"> switch (c) {
</span><span class="cx"> case "Module":
</span><span class="cx"> for (const invalid of invalidConstructorInputs)
</span><del>- assert.throws(() => new WebAssembly[c](invalid), TypeError, `first argument to WebAssembly.Module must be an ArrayBufferView or an ArrayBuffer (evaluating 'new WebAssembly[c](invalid)')`);
</del><ins>+ assert.throws(() => new WebAssembly[c](invalid), TypeError, `first argument must be an ArrayBufferView or an ArrayBuffer (evaluating 'new WebAssembly[c](invalid)')`);
</ins><span class="cx"> for (const buffer of [new ArrayBuffer(), new DataView(new ArrayBuffer()), new Int8Array(), new Uint8Array(), new Uint8ClampedArray(), new Int16Array(), new Uint16Array(), new Int32Array(), new Uint32Array(), new Float32Array(), new Float64Array()])
</span><span class="cx"> // FIXME the following should be WebAssembly.CompileError. https://bugs.webkit.org/show_bug.cgi?id=163768
</span><span class="cx"> assert.throws(() => new WebAssembly[c](buffer), Error, `WebAssembly.Module doesn't parse at byte 0 / 0: expected a module of at least 8 bytes (evaluating 'new WebAssembly[c](buffer)')`);
</span><span class="lines">@@ -99,8 +99,3 @@
</span><span class="cx"> default: throw new Error(`Implementation error: unexpected constructor property "${c}"`);
</span><span class="cx"> }
</span><span class="cx"> }
</span><del>-
-// FIXME Implement and test these APIs further. For now they just throw. https://bugs.webkit.org/show_bug.cgi?id=159775
-for (const f in functionProperties) {
- assert.throws(() => WebAssembly[f](), Error, `WebAssembly doesn't yet implement the ${f} function property`);
-}
</del></span></pre></div>
<a id="branchessafari603branchJSTestswasmjsapivalidatejs"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/JSTests/wasm/js-api/validate.js (0 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/JSTests/wasm/js-api/validate.js         (rev 0)
+++ branches/safari-603-branch/JSTests/wasm/js-api/validate.js        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -0,0 +1,27 @@
</span><ins>+import * as assert from '../assert.js';
+import Builder from '../Builder.js';
+
+{
+ const builder = (new Builder())
+ .Type().End()
+ .Import().Memory("imp", "memory", {initial: 20}).End()
+ .Function().End()
+ .Memory().InitialMaxPages(1, 1).End()
+ .Export().End()
+ .Code()
+ .End();
+
+ assert.truthy(!WebAssembly.validate(builder.WebAssembly().get()));
+}
+
+{
+ const builder = (new Builder())
+ .Type().End()
+ .Import().Memory("imp", "memory", {initial: 20}).End()
+ .Function().End()
+ .Export().End()
+ .Code()
+ .End();
+
+ assert.truthy(WebAssembly.validate(builder.WebAssembly().get()));
+}
</ins></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/ChangeLog (210400 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/ChangeLog        2017-01-06 01:06:15 UTC (rev 210400)
+++ branches/safari-603-branch/Source/JavaScriptCore/ChangeLog        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -1,5 +1,36 @@
</span><span class="cx"> 2017-01-05 Matthew Hanson <matthew_hanson@apple.com>
</span><span class="cx">
</span><ins>+ Merge r209979. rdar://problem/29735737
+
+ 2016-12-18 Saam Barati <sbarati@apple.com>
+
+ WebAssembly: Implement the WebAssembly.compile and WebAssembly.validate
+ https://bugs.webkit.org/show_bug.cgi?id=165936
+
+ Reviewed by Mark Lam.
+
+ The APIs are documented here:
+ - https://github.com/WebAssembly/design/blob/master/JS.md#webassemblycompile
+ - https://github.com/WebAssembly/design/blob/master/JS.md#webassemblyvalidate
+
+ * wasm/JSWebAssembly.cpp:
+ (JSC::webAssemblyCompileFunc):
+ (JSC::webAssemblyValidateFunc):
+ (JSC::JSWebAssembly::finishCreation):
+ * wasm/WasmPlan.cpp:
+ (JSC::Wasm::Plan::parseAndValidateModule):
+ (JSC::Wasm::Plan::run):
+ * wasm/WasmPlan.h:
+ * wasm/js/JSWebAssemblyHelpers.h:
+ (JSC::getWasmBufferFromValue):
+ * wasm/js/WebAssemblyModuleConstructor.cpp:
+ (JSC::constructJSWebAssemblyModule):
+ (JSC::callJSWebAssemblyModule):
+ (JSC::WebAssemblyModuleConstructor::createModule):
+ * wasm/js/WebAssemblyModuleConstructor.h:
+
+2017-01-05 Matthew Hanson <matthew_hanson@apple.com>
+
</ins><span class="cx"> Merge r210359. rdar://problem/29882478
</span><span class="cx">
</span><span class="cx"> 2017-01-05 Per Arne Vollan <pvollan@apple.com>
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCorewasmJSWebAssemblycpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/wasm/JSWebAssembly.cpp (210400 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/wasm/JSWebAssembly.cpp        2017-01-06 01:06:15 UTC (rev 210400)
+++ branches/safari-603-branch/Source/JavaScriptCore/wasm/JSWebAssembly.cpp        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -28,13 +28,57 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(WEBASSEMBLY)
</span><span class="cx">
</span><ins>+#include "Exception.h"
</ins><span class="cx"> #include "FunctionPrototype.h"
</span><span class="cx"> #include "JSCInlines.h"
</span><ins>+#include "JSPromiseDeferred.h"
+#include "JSWebAssemblyHelpers.h"
+#include "WasmPlan.h"
+#include "WebAssemblyModuleConstructor.h"
</ins><span class="cx">
</span><span class="cx"> namespace JSC {
</span><span class="cx">
</span><span class="cx"> STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSWebAssembly);
</span><span class="cx">
</span><ins>+EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState*);
+EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState*);
+
+EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto catchScope = DECLARE_CATCH_SCOPE(vm);
+
+ JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, exec->lexicalGlobalObject());
+ RETURN_IF_EXCEPTION(catchScope, { });
+
+ // FIXME: Make this truly asynchronous:
+ // https://bugs.webkit.org/show_bug.cgi?id=166016
+ JSValue module = WebAssemblyModuleConstructor::createModule(exec, exec->lexicalGlobalObject()->WebAssemblyModuleStructure());
+ if (Exception* exception = catchScope.exception()) {
+ catchScope.clearException();
+ promise->reject(exec, exception);
+ return JSValue::encode(promise->promise());
+ }
+
+ promise->resolve(exec, module);
+ return JSValue::encode(promise->promise());
+}
+
+EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ size_t byteOffset;
+ size_t byteSize;
+ uint8_t* base = getWasmBufferFromValue(exec, exec->argument(0), byteOffset, byteSize);
+ RETURN_IF_EXCEPTION(scope, { });
+ Wasm::Plan plan(&vm, base + byteOffset, byteSize);
+ // FIXME: We might want to throw an OOM exception here if we detect that something will OOM.
+ // https://bugs.webkit.org/show_bug.cgi?id=166015
+ return JSValue::encode(jsBoolean(plan.parseAndValidateModule()));
+}
+
</ins><span class="cx"> const ClassInfo JSWebAssembly::s_info = { "WebAssembly", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssembly) };
</span><span class="cx">
</span><span class="cx"> JSWebAssembly* JSWebAssembly::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
</span><span class="lines">@@ -49,10 +93,12 @@
</span><span class="cx"> return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void JSWebAssembly::finishCreation(VM& vm, JSGlobalObject*)
</del><ins>+void JSWebAssembly::finishCreation(VM& vm, JSGlobalObject* globalObject)
</ins><span class="cx"> {
</span><span class="cx"> Base::finishCreation(vm);
</span><span class="cx"> ASSERT(inherits(info()));
</span><ins>+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("validate", webAssemblyValidateFunc, DontEnum, 1);
+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("compile", webAssemblyCompileFunc, DontEnum, 1);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> JSWebAssembly::JSWebAssembly(VM& vm, Structure* structure)
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCorewasmWasmPlancpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/wasm/WasmPlan.cpp (210400 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/wasm/WasmPlan.cpp        2017-01-06 01:06:15 UTC (rev 210400)
+++ branches/safari-603-branch/Source/JavaScriptCore/wasm/WasmPlan.cpp        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -58,7 +58,7 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void Plan::run()
</del><ins>+bool Plan::parseAndValidateModule()
</ins><span class="cx"> {
</span><span class="cx"> {
</span><span class="cx"> ModuleParser moduleParser(m_vm, m_source, m_sourceLength);
</span><span class="lines">@@ -65,7 +65,7 @@
</span><span class="cx"> auto parseResult = moduleParser.parse();
</span><span class="cx"> if (!parseResult) {
</span><span class="cx"> m_errorMessage = parseResult.error();
</span><del>- return; // FIXME return an Expected.
</del><ins>+ return false;
</ins><span class="cx"> }
</span><span class="cx"> m_moduleInformation = WTFMove(parseResult->module);
</span><span class="cx"> m_functionLocationInBinary = WTFMove(parseResult->functionLocationInBinary);
</span><span class="lines">@@ -73,6 +73,34 @@
</span><span class="cx"> m_functionIndexSpace.buffer = parseResult->functionIndexSpace.releaseBuffer();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ for (unsigned functionIndex = 0; functionIndex < m_functionLocationInBinary.size(); ++functionIndex) {
+ if (verbose)
+ dataLogLn("Processing function starting at: ", m_functionLocationInBinary[functionIndex].start, " and ending at: ", m_functionLocationInBinary[functionIndex].end);
+ const uint8_t* functionStart = m_source + m_functionLocationInBinary[functionIndex].start;
+ size_t functionLength = m_functionLocationInBinary[functionIndex].end - m_functionLocationInBinary[functionIndex].start;
+ ASSERT(Checked<uintptr_t>(bitwise_cast<uintptr_t>(functionStart)) + functionLength <= Checked<uintptr_t>(bitwise_cast<uintptr_t>(m_source)) + m_sourceLength);
+ Signature* signature = m_moduleInformation->internalFunctionSignatures[functionIndex];
+
+ auto validationResult = validateFunction(functionStart, functionLength, signature, m_functionIndexSpace, *m_moduleInformation);
+ if (!validationResult) {
+ if (verbose) {
+ for (unsigned i = 0; i < functionLength; ++i)
+ dataLog(RawPointer(reinterpret_cast<void*>(functionStart[i])), ", ");
+ dataLogLn();
+ }
+ m_errorMessage = validationResult.error(); // FIXME make this an Expected.
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void Plan::run()
+{
+ if (!parseAndValidateModule())
+ return;
+
</ins><span class="cx"> auto tryReserveCapacity = [this] (auto& vector, size_t size, const char* what) {
</span><span class="cx"> if (UNLIKELY(!vector.tryReserveCapacity(size))) {
</span><span class="cx"> StringBuilder builder;
</span><span class="lines">@@ -84,6 +112,7 @@
</span><span class="cx"> }
</span><span class="cx"> return true;
</span><span class="cx"> };
</span><ins>+
</ins><span class="cx"> Vector<Vector<UnlinkedWasmToWasmCall>> unlinkedWasmToWasmCalls;
</span><span class="cx"> if (!tryReserveCapacity(m_wasmToJSStubs, m_moduleInformation->importFunctions.size(), " WebAssembly to JavaScript stubs")
</span><span class="cx"> || !tryReserveCapacity(unlinkedWasmToWasmCalls, m_functionLocationInBinary.size(), " unlinked WebAssembly to WebAssembly calls")
</span><span class="lines">@@ -112,16 +141,7 @@
</span><span class="cx"> unsigned functionIndexSpace = m_wasmToJSStubs.size() + functionIndex;
</span><span class="cx"> ASSERT(m_functionIndexSpace.buffer.get()[functionIndexSpace].signature == signature);
</span><span class="cx">
</span><del>- auto validateResult = validateFunction(functionStart, functionLength, signature, m_functionIndexSpace, *m_moduleInformation);
- if (!validateResult) {
- if (verbose) {
- for (unsigned i = 0; i < functionLength; ++i)
- dataLog(RawPointer(reinterpret_cast<void*>(functionStart[i])), ", ");
- dataLogLn();
- }
- m_errorMessage = validateResult.error(); // FIXME make this an Expected.
- return;
- }
</del><ins>+ ASSERT(validateFunction(functionStart, functionLength, signature, m_functionIndexSpace, *m_moduleInformation));
</ins><span class="cx">
</span><span class="cx"> unlinkedWasmToWasmCalls.uncheckedAppend(Vector<UnlinkedWasmToWasmCall>());
</span><span class="cx"> auto parseAndCompileResult = parseAndCompile(*m_vm, functionStart, functionLength, signature, unlinkedWasmToWasmCalls.at(functionIndex), m_functionIndexSpace, *m_moduleInformation);
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCorewasmWasmPlanh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/wasm/WasmPlan.h (210400 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/wasm/WasmPlan.h        2017-01-06 01:06:15 UTC (rev 210400)
+++ branches/safari-603-branch/Source/JavaScriptCore/wasm/WasmPlan.h        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -48,6 +48,8 @@
</span><span class="cx"> JS_EXPORT_PRIVATE Plan(VM*, const uint8_t*, size_t);
</span><span class="cx"> JS_EXPORT_PRIVATE ~Plan();
</span><span class="cx">
</span><ins>+ bool parseAndValidateModule();
+
</ins><span class="cx"> JS_EXPORT_PRIVATE void run();
</span><span class="cx">
</span><span class="cx"> JS_EXPORT_PRIVATE void initializeCallees(JSGlobalObject*, std::function<void(unsigned, JSWebAssemblyCallee*, JSWebAssemblyCallee*)>);
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCorewasmjsJSWebAssemblyHelpersh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h (210400 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h        2017-01-06 01:06:15 UTC (rev 210400)
+++ branches/safari-603-branch/Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(WEBASSEMBLY)
</span><span class="cx">
</span><ins>+#include "JSArrayBuffer.h"
</ins><span class="cx"> #include "JSCJSValue.h"
</span><span class="cx">
</span><span class="cx"> namespace JSC {
</span><span class="lines">@@ -46,6 +47,30 @@
</span><span class="cx"> return static_cast<uint32_t>(doubleValue);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ALWAYS_INLINE uint8_t* getWasmBufferFromValue(ExecState* exec, JSValue value, size_t& byteOffset, size_t& byteSize)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ // If the given bytes argument is not a BufferSource, a TypeError exception is thrown.
+ JSArrayBuffer* arrayBuffer = value.getObject() ? jsDynamicCast<JSArrayBuffer*>(value.getObject()) : nullptr;
+ JSArrayBufferView* arrayBufferView = value.getObject() ? jsDynamicCast<JSArrayBufferView*>(value.getObject()) : nullptr;
+ if (!(arrayBuffer || arrayBufferView)) {
+ throwException(exec, throwScope, createTypeError(exec,
+ ASCIILiteral("first argument must be an ArrayBufferView or an ArrayBuffer"), defaultSourceAppender, runtimeTypeForValue(value)));
+ return nullptr;
+ }
+
+ if (arrayBufferView ? arrayBufferView->isNeutered() : arrayBuffer->impl()->isNeutered()) {
+ throwException(exec, throwScope, createTypeError(exec,
+ ASCIILiteral("underlying TypedArray has been detatched from the ArrayBuffer"), defaultSourceAppender, runtimeTypeForValue(value)));
+ return nullptr;
+ }
+
+ byteOffset = arrayBufferView ? arrayBufferView->byteOffset() : 0;
+ byteSize = arrayBufferView ? arrayBufferView->length() : arrayBuffer->impl()->byteLength();
+ return arrayBufferView ? static_cast<uint8_t*>(arrayBufferView->vector()) : static_cast<uint8_t*>(arrayBuffer->impl()->data());
+}
+
</ins><span class="cx"> } // namespace JSC
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(WEBASSEMBLY)
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCorewasmjsWebAssemblyModuleConstructorcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp (210400 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp        2017-01-06 01:06:15 UTC (rev 210400)
+++ branches/safari-603-branch/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include "JSTypedArrays.h"
</span><span class="cx"> #include "JSWebAssemblyCallee.h"
</span><span class="cx"> #include "JSWebAssemblyCompileError.h"
</span><ins>+#include "JSWebAssemblyHelpers.h"
</ins><span class="cx"> #include "JSWebAssemblyModule.h"
</span><span class="cx"> #include "SymbolTable.h"
</span><span class="cx"> #include "WasmPlan.h"
</span><span class="lines">@@ -52,34 +53,40 @@
</span><span class="cx"> @end
</span><span class="cx"> */
</span><span class="cx">
</span><del>-static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyModule(ExecState* state)
</del><ins>+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyModule(ExecState* exec)
</ins><span class="cx"> {
</span><ins>+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* structure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), exec->lexicalGlobalObject()->WebAssemblyModuleStructure());
+ RETURN_IF_EXCEPTION(throwScope, { });
+ throwScope.release();
+ return JSValue::encode(WebAssemblyModuleConstructor::createModule(exec, structure));
+}
+
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyModule(ExecState* state)
+{
</ins><span class="cx"> VM& vm = state->vm();
</span><span class="cx"> auto scope = DECLARE_THROW_SCOPE(vm);
</span><del>- JSValue val = state->argument(0);
</del><ins>+ return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.Module"));
+}
</ins><span class="cx">
</span><del>- // If the given bytes argument is not a BufferSource, a TypeError exception is thrown.
- JSArrayBuffer* arrayBuffer = val.getObject() ? jsDynamicCast<JSArrayBuffer*>(val.getObject()) : nullptr;
- JSArrayBufferView* arrayBufferView = val.getObject() ? jsDynamicCast<JSArrayBufferView*>(val.getObject()) : nullptr;
- if (!(arrayBuffer || arrayBufferView))
- return JSValue::encode(throwException(state, scope, createTypeError(state, ASCIILiteral("first argument to WebAssembly.Module must be an ArrayBufferView or an ArrayBuffer"), defaultSourceAppender, runtimeTypeForValue(val))));
</del><ins>+JSValue WebAssemblyModuleConstructor::createModule(ExecState* state, Structure* structure)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
</ins><span class="cx">
</span><del>- if (arrayBufferView ? arrayBufferView->isNeutered() : arrayBuffer->impl()->isNeutered())
- return JSValue::encode(throwException(state, scope, createTypeError(state, ASCIILiteral("underlying TypedArray has been detatched from the ArrayBuffer"), defaultSourceAppender, runtimeTypeForValue(val))));
</del><ins>+ size_t byteOffset;
+ size_t byteSize;
+ uint8_t* base = getWasmBufferFromValue(state, state->argument(0), byteOffset, byteSize);
+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx">
</span><del>- size_t byteOffset = arrayBufferView ? arrayBufferView->byteOffset() : 0;
- size_t byteSize = arrayBufferView ? arrayBufferView->length() : arrayBuffer->impl()->byteLength();
- const auto* base = arrayBufferView ? static_cast<uint8_t*>(arrayBufferView->vector()) : static_cast<uint8_t*>(arrayBuffer->impl()->data());
-
</del><span class="cx"> Wasm::Plan plan(&vm, base + byteOffset, byteSize);
</span><span class="cx"> // On failure, a new WebAssembly.CompileError is thrown.
</span><span class="cx"> plan.run();
</span><span class="cx"> if (plan.failed())
</span><del>- return JSValue::encode(throwException(state, scope, createWebAssemblyCompileError(state, plan.errorMessage())));
</del><ins>+ return throwException(state, scope, createWebAssemblyCompileError(state, plan.errorMessage()));
</ins><span class="cx">
</span><span class="cx"> // On success, a new WebAssembly.Module object is returned with [[Module]] set to the validated Ast.module.
</span><del>- auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyModuleStructure());
- RETURN_IF_EXCEPTION(scope, { });
</del><span class="cx">
</span><span class="cx"> // The export symbol table is the same for all Instances of a Module.
</span><span class="cx"> SymbolTable* exportSymbolTable = SymbolTable::create(vm);
</span><span class="lines">@@ -96,14 +103,8 @@
</span><span class="cx"> result->setJSEntrypointCallee(vm, calleeIndex, jsEntrypointCallee);
</span><span class="cx"> result->setWasmEntrypointCallee(vm, calleeIndex, wasmEntrypointCallee);
</span><span class="cx"> });
</span><del>- return JSValue::encode(result);
-}
</del><span class="cx">
</span><del>-static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyModule(ExecState* state)
-{
- VM& vm = state->vm();
- auto scope = DECLARE_THROW_SCOPE(vm);
- return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.Module"));
</del><ins>+ return result;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> WebAssemblyModuleConstructor* WebAssemblyModuleConstructor::create(VM& vm, Structure* structure, WebAssemblyModulePrototype* thisPrototype)
</span></span></pre></div>
<a id="branchessafari603branchSourceJavaScriptCorewasmjsWebAssemblyModuleConstructorh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.h (210400 => 210401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.h        2017-01-06 01:06:15 UTC (rev 210400)
+++ branches/safari-603-branch/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.h        2017-01-06 01:47:16 UTC (rev 210401)
</span><span class="lines">@@ -44,6 +44,8 @@
</span><span class="cx">
</span><span class="cx"> DECLARE_INFO;
</span><span class="cx">
</span><ins>+ static JSValue createModule(ExecState*, Structure*);
+
</ins><span class="cx"> protected:
</span><span class="cx"> void finishCreation(VM&, WebAssemblyModulePrototype*);
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>