<!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>[214601] 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/214601">214601</a></dd>
<dt>Author</dt> <dd>jfbastien@apple.com</dd>
<dt>Date</dt> <dd>2017-03-30 00:16:27 -0700 (Thu, 30 Mar 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>WebAssembly: fix misc JS API implementation inconsistencies
https://bugs.webkit.org/show_bug.cgi?id=170187
Reviewed by Keith Miller.
JSTests:
Verify that WebAssembly function are on the object's __proto__.
* wasm/js-api/Module-compile.js:
* wasm/js-api/validate.js:
* wasm/js-api/web-assembly-instantiate.js:
Source/JavaScriptCore:
Auto-generate lookup tables.
Methods should be on prototype.
Exception returns should be idiomatic.
* wasm/JSWebAssembly.cpp: validate / compile / instantiate should
be on the prototype
(JSC::JSWebAssembly::create):
(JSC::JSWebAssembly::finishCreation):
(JSC::reject): Deleted.
(JSC::webAssemblyCompileFunc): Deleted.
(JSC::resolve): Deleted.
(JSC::instantiate): Deleted.
(JSC::compileAndInstantiate): Deleted.
(JSC::webAssemblyInstantiateFunc): Deleted.
(JSC::webAssemblyValidateFunc): Deleted.
* wasm/JSWebAssembly.h:
* wasm/js/WebAssemblyMemoryPrototype.cpp: move from JSWebAssembly.cpp
(JSC::webAssemblyMemoryProtoFuncBuffer):
(JSC::WebAssemblyMemoryPrototype::create):
(JSC::WebAssemblyMemoryPrototype::finishCreation):
* wasm/js/WebAssemblyMemoryPrototype.h:
* wasm/js/WebAssemblyPrototype.cpp:
(JSC::reject):
(JSC::webAssemblyCompileFunc):
(JSC::resolve):
(JSC::instantiate):
(JSC::compileAndInstantiate):
(JSC::webAssemblyInstantiateFunc):
(JSC::webAssemblyValidateFunc):
(JSC::webAssemblyFunctionValidate): Deleted.
(JSC::webAssemblyFunctionCompile): Deleted.
* wasm/js/WebAssemblyTablePrototype.cpp:
(JSC::webAssemblyTableProtoFuncGrow):
(JSC::webAssemblyTableProtoFuncGet):
(JSC::webAssemblyTableProtoFuncSet):
(JSC::WebAssemblyTablePrototype::create):
(JSC::WebAssemblyTablePrototype::finishCreation):
* wasm/js/WebAssemblyTablePrototype.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkJSTestsChangeLog">trunk/JSTests/ChangeLog</a></li>
<li><a href="#trunkJSTestswasmjsapiModulecompilejs">trunk/JSTests/wasm/js-api/Module-compile.js</a></li>
<li><a href="#trunkJSTestswasmjsapivalidatejs">trunk/JSTests/wasm/js-api/validate.js</a></li>
<li><a href="#trunkJSTestswasmjsapiwebassemblyinstantiatejs">trunk/JSTests/wasm/js-api/web-assembly-instantiate.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmJSWebAssemblycpp">trunk/Source/JavaScriptCore/wasm/JSWebAssembly.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmJSWebAssemblyh">trunk/Source/JavaScriptCore/wasm/JSWebAssembly.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyMemoryPrototypecpp">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyMemoryPrototypeh">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyPrototypecpp">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyTablePrototypecpp">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmjsWebAssemblyTablePrototypeh">trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/ChangeLog (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/ChangeLog        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/JSTests/ChangeLog        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2017-03-30 JF Bastien <jfbastien@apple.com>
+
+ WebAssembly: fix misc JS API implementation inconsistencies
+ https://bugs.webkit.org/show_bug.cgi?id=170187
+
+ Reviewed by Keith Miller.
+
+ Verify that WebAssembly function are on the object's __proto__.
+
+ * wasm/js-api/Module-compile.js:
+ * wasm/js-api/validate.js:
+ * wasm/js-api/web-assembly-instantiate.js:
+
</ins><span class="cx"> 2017-03-29 JF Bastien <jfbastien@apple.com>
</span><span class="cx">
</span><span class="cx"> WebAssembly: add shell-only Memory mode helper
</span></span></pre></div>
<a id="trunkJSTestswasmjsapiModulecompilejs"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/wasm/js-api/Module-compile.js (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/wasm/js-api/Module-compile.js        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/JSTests/wasm/js-api/Module-compile.js        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,6 +1,10 @@
</span><span class="cx"> import * as assert from '../assert.js';
</span><span class="cx"> import Builder from '../Builder.js';
</span><span class="cx">
</span><ins>+assert.isFunction(WebAssembly.compile);
+assert.isFunction(WebAssembly.__proto__.compile);
+assert.eq(WebAssembly.compile.length, 1);
+
</ins><span class="cx"> async function testPromiseAPI() {
</span><span class="cx"> {
</span><span class="cx"> // Can't declare more than one memory.
</span></span></pre></div>
<a id="trunkJSTestswasmjsapivalidatejs"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/wasm/js-api/validate.js (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/wasm/js-api/validate.js        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/JSTests/wasm/js-api/validate.js        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,6 +1,10 @@
</span><span class="cx"> import * as assert from '../assert.js';
</span><span class="cx"> import Builder from '../Builder.js';
</span><span class="cx">
</span><ins>+assert.isFunction(WebAssembly.validate);
+assert.isFunction(WebAssembly.__proto__.validate);
+assert.eq(WebAssembly.validate.length, 1);
+
</ins><span class="cx"> {
</span><span class="cx"> const builder = (new Builder())
</span><span class="cx"> .Type().End()
</span></span></pre></div>
<a id="trunkJSTestswasmjsapiwebassemblyinstantiatejs"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/wasm/js-api/web-assembly-instantiate.js (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/wasm/js-api/web-assembly-instantiate.js        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/JSTests/wasm/js-api/web-assembly-instantiate.js        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,7 +1,8 @@
</span><span class="cx"> import * as assert from '../assert.js';
</span><span class="cx"> import Builder from '../Builder.js';
</span><span class="cx">
</span><del>-assert.truthy(WebAssembly.instantiate instanceof Function);
</del><ins>+assert.isFunction(WebAssembly.instantiate);
+assert.isFunction(WebAssembly.__proto__.instantiate);
</ins><span class="cx"> assert.eq(WebAssembly.instantiate.length, 1);
</span><span class="cx">
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,3 +1,49 @@
</span><ins>+2017-03-30 JF Bastien <jfbastien@apple.com>
+
+ WebAssembly: fix misc JS API implementation inconsistencies
+ https://bugs.webkit.org/show_bug.cgi?id=170187
+
+ Reviewed by Keith Miller.
+
+ Auto-generate lookup tables.
+ Methods should be on prototype.
+ Exception returns should be idiomatic.
+
+ * wasm/JSWebAssembly.cpp: validate / compile / instantiate should
+ be on the prototype
+ (JSC::JSWebAssembly::create):
+ (JSC::JSWebAssembly::finishCreation):
+ (JSC::reject): Deleted.
+ (JSC::webAssemblyCompileFunc): Deleted.
+ (JSC::resolve): Deleted.
+ (JSC::instantiate): Deleted.
+ (JSC::compileAndInstantiate): Deleted.
+ (JSC::webAssemblyInstantiateFunc): Deleted.
+ (JSC::webAssemblyValidateFunc): Deleted.
+ * wasm/JSWebAssembly.h:
+ * wasm/js/WebAssemblyMemoryPrototype.cpp: move from JSWebAssembly.cpp
+ (JSC::webAssemblyMemoryProtoFuncBuffer):
+ (JSC::WebAssemblyMemoryPrototype::create):
+ (JSC::WebAssemblyMemoryPrototype::finishCreation):
+ * wasm/js/WebAssemblyMemoryPrototype.h:
+ * wasm/js/WebAssemblyPrototype.cpp:
+ (JSC::reject):
+ (JSC::webAssemblyCompileFunc):
+ (JSC::resolve):
+ (JSC::instantiate):
+ (JSC::compileAndInstantiate):
+ (JSC::webAssemblyInstantiateFunc):
+ (JSC::webAssemblyValidateFunc):
+ (JSC::webAssemblyFunctionValidate): Deleted.
+ (JSC::webAssemblyFunctionCompile): Deleted.
+ * wasm/js/WebAssemblyTablePrototype.cpp:
+ (JSC::webAssemblyTableProtoFuncGrow):
+ (JSC::webAssemblyTableProtoFuncGet):
+ (JSC::webAssemblyTableProtoFuncSet):
+ (JSC::WebAssemblyTablePrototype::create):
+ (JSC::WebAssemblyTablePrototype::finishCreation):
+ * wasm/js/WebAssemblyTablePrototype.h:
+
</ins><span class="cx"> 2017-03-29 Keith Miller <keith_miller@apple.com>
</span><span class="cx">
</span><span class="cx"> Unreviewed, fix the build, again. Hopefully for the last time, again!
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmJSWebAssemblycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/JSWebAssembly.cpp (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/JSWebAssembly.cpp        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/Source/JavaScriptCore/wasm/JSWebAssembly.cpp        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -28,223 +28,18 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(WEBASSEMBLY)
</span><span class="cx">
</span><del>-#include "Exception.h"
-#include "FunctionPrototype.h"
</del><span class="cx"> #include "JSCInlines.h"
</span><del>-#include "JSPromiseDeferred.h"
-#include "JSWebAssemblyHelpers.h"
-#include "JSWebAssemblyInstance.h"
-#include "JSWebAssemblyModule.h"
-#include "ObjectConstructor.h"
-#include "PromiseDeferredTimer.h"
-#include "StrongInlines.h"
-#include "WasmPlan.h"
-#include "WasmWorklist.h"
-#include "WebAssemblyModuleConstructor.h"
</del><span class="cx">
</span><del>-using JSC::Wasm::Plan;
-
</del><span class="cx"> namespace JSC {
</span><span class="cx">
</span><span class="cx"> STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSWebAssembly);
</span><span class="cx">
</span><del>-EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState*);
-EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState*);
-EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState*);
-
-static EncodedJSValue reject(ExecState* exec, CatchScope& catchScope, JSPromiseDeferred* promise)
-{
- Exception* exception = catchScope.exception();
- ASSERT(exception);
- catchScope.clearException();
- promise->reject(exec, exception->value());
- return JSValue::encode(promise->promise());
-}
-
-EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState* exec)
-{
- VM& vm = exec->vm();
- auto scope = DECLARE_CATCH_SCOPE(vm);
- auto* globalObject = exec->lexicalGlobalObject();
-
- JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, globalObject);
- RETURN_IF_EXCEPTION(scope, { });
-
- RefPtr<ArrayBuffer> source = createSourceBufferFromValue(vm, exec, exec->argument(0));
- RETURN_IF_EXCEPTION(scope, { });
-
- Vector<Strong<JSCell>> dependencies;
- dependencies.append(Strong<JSCell>(vm, globalObject));
- vm.promiseDeferredTimer->addPendingPromise(promise, WTFMove(dependencies));
-
- Ref<Plan> plan = adoptRef(*new Plan(vm, *source, Plan::Validation, [source, promise, globalObject] (Plan& p) mutable {
- RefPtr<Plan> plan = makeRef(p);
- plan->vm().promiseDeferredTimer->scheduleWorkSoon(promise, [source, promise, globalObject, plan = WTFMove(plan)] () mutable {
- VM& vm = plan->vm();
- auto scope = DECLARE_CATCH_SCOPE(vm);
- ExecState* exec = globalObject->globalExec();
- JSValue module = JSWebAssemblyModule::createStub(vm, exec, globalObject->WebAssemblyModuleStructure(), WTFMove(source), WTFMove(plan));
- if (scope.exception()) {
- reject(exec, scope, promise);
- return;
- }
-
- promise->resolve(exec, module);
- });
- }));
-
- Wasm::ensureWorklist().enqueue(WTFMove(plan));
- return JSValue::encode(promise->promise());
-}
-
-enum class Resolve { WithInstance, WithModuleAndInstance };
-static void resolve(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSWebAssemblyInstance* instance, JSWebAssemblyModule* module, Resolve entries)
-{
- auto scope = DECLARE_CATCH_SCOPE(vm);
- instance->finalizeCreation(vm, exec);
- if (scope.exception()) {
- reject(exec, scope, promise);
- return;
- }
-
- if (entries == Resolve::WithInstance)
- promise->resolve(exec, instance);
- else {
- JSObject* result = constructEmptyObject(exec);
- result->putDirect(vm, Identifier::fromString(&vm, ASCIILiteral("module")), module);
- result->putDirect(vm, Identifier::fromString(&vm, ASCIILiteral("instance")), instance);
- promise->resolve(exec, result);
- }
-}
-
-static void instantiate(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSWebAssemblyModule* module, JSObject* importObject, Resolve entries)
-{
- auto scope = DECLARE_CATCH_SCOPE(vm);
- // In order to avoid potentially recompiling a module. We first gather all the import/memory information prior to compiling code.
- JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, exec, module, importObject, exec->lexicalGlobalObject()->WebAssemblyInstanceStructure());
- if (scope.exception()) {
- reject(exec, scope, promise);
- return;
- }
-
- // There are three possible cases:
- // 1) The instance already has an initialized CodeBlock, so we have no more work to do.
- // 2) The instance has no CodeBlock, so we need to make one and compile the code for it.
- // 3) The instance already has an uninitialized CodeBlock, so someone else is compiling code and we just need to wait for them.
-
- if (instance->initialized()) {
- resolve(vm, exec, promise, instance, module, entries);
- return;
- }
-
- Vector<Strong<JSCell>> dependencies;
- // The instance keeps the module alive.
- dependencies.append(Strong<JSCell>(vm, instance));
- vm.promiseDeferredTimer->addPendingPromise(promise, WTFMove(dependencies));
-
- if (instance->codeBlock()) {
- vm.promiseDeferredTimer->scheduleBlockedTask(instance->codeBlock()->plan().pendingPromise(), [&vm, promise, instance, module, entries] () {
- auto* globalObject = instance->globalObject();
- ExecState* exec = globalObject->globalExec();
- resolve(vm, exec, promise, instance, module, entries);
- });
- return;
- }
- ASSERT(!instance->codeBlock());
-
- // FIXME: This re-parses the module header, which shouldn't be necessary.
- // https://bugs.webkit.org/show_bug.cgi?id=170205
- Ref<Plan> plan = adoptRef(*new Plan(vm, module->source(), Plan::FullCompile, [promise, instance, module, entries] (Plan& p) {
- RefPtr<Plan> plan = makeRef(p);
- plan->vm().promiseDeferredTimer->scheduleWorkSoon(promise, [promise, instance, module, entries, plan = WTFMove(plan)] () {
- VM& vm = plan->vm();
- ExecState* exec = instance->globalObject()->globalExec();
- resolve(vm, exec, promise, instance, module, entries);
- });
- }));
-
- instance->addUnitializedCodeBlock(vm, plan.copyRef());
- plan->setModeAndPromise(instance->memoryMode(), promise);
- Wasm::ensureWorklist().enqueue(WTFMove(plan));
-}
-
-static void compileAndInstantiate(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSValue buffer, JSObject* importObject)
-{
- auto scope = DECLARE_THROW_SCOPE(vm);
- RefPtr<ArrayBuffer> source = createSourceBufferFromValue(vm, exec, buffer);
- RETURN_IF_EXCEPTION(scope, void());
-
- auto* globalObject = exec->lexicalGlobalObject();
-
- Vector<Strong<JSCell>> dependencies;
- dependencies.append(Strong<JSCell>(vm, importObject));
- vm.promiseDeferredTimer->addPendingPromise(promise, WTFMove(dependencies));
-
- Ref<Plan> plan = adoptRef(*new Plan(vm, *source, Plan::Validation, [source, promise, importObject, globalObject] (Plan& p) mutable {
- RefPtr<Plan> plan = makeRef(p);
- plan->vm().promiseDeferredTimer->scheduleWorkSoon(promise, [source, promise, importObject, globalObject, plan = WTFMove(plan)] () mutable {
- VM& vm = plan->vm();
- auto scope = DECLARE_CATCH_SCOPE(vm);
- ExecState* exec = globalObject->globalExec();
- JSWebAssemblyModule* module = JSWebAssemblyModule::createStub(vm, exec, globalObject->WebAssemblyModuleStructure(), WTFMove(source), plan.copyRef());
- if (scope.exception()) {
- reject(exec, scope, promise);
- return;
- }
-
- instantiate(vm, exec, promise, module, importObject, Resolve::WithModuleAndInstance);
- });
- }));
-
- Wasm::ensureWorklist().enqueue(WTFMove(plan));
-}
-
-EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState* exec)
-{
- VM& vm = exec->vm();
- auto catchScope = DECLARE_CATCH_SCOPE(vm);
-
- JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, exec->lexicalGlobalObject());
- RETURN_IF_EXCEPTION(catchScope, encodedJSValue());
-
- JSValue importArgument = exec->argument(1);
- JSObject* importObject = importArgument.getObject();
- if (!importArgument.isUndefined() && !importObject) {
- promise->reject(exec, createTypeError(exec,
- ASCIILiteral("second argument to WebAssembly.instantiate must be undefined or an Object"), defaultSourceAppender, runtimeTypeForValue(importArgument)));
- return JSValue::encode(promise->promise());
- }
-
- JSValue firstArgument = exec->argument(0);
- if (auto* module = jsDynamicCast<JSWebAssemblyModule*>(vm, firstArgument))
- instantiate(vm, exec, promise, module, importObject, Resolve::WithInstance);
- else
- compileAndInstantiate(vm, exec, promise, firstArgument, importObject);
-
- 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, encodedJSValue());
- Wasm::Plan plan(vm, base + byteOffset, byteSize, Plan::Validation, Plan::dontFinalize);
- // 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()));
-}
-
</del><span class="cx"> const ClassInfo JSWebAssembly::s_info = { "WebAssembly", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssembly) };
</span><span class="cx">
</span><del>-JSWebAssembly* JSWebAssembly::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
</del><ins>+JSWebAssembly* JSWebAssembly::create(VM& vm, JSGlobalObject*, Structure* structure)
</ins><span class="cx"> {
</span><span class="cx"> auto* object = new (NotNull, allocateCell<JSWebAssembly>(vm.heap)) JSWebAssembly(vm, structure);
</span><del>- object->finishCreation(vm, globalObject);
</del><ins>+ object->finishCreation(vm);
</ins><span class="cx"> return object;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -253,13 +48,10 @@
</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* globalObject)
</del><ins>+void JSWebAssembly::finishCreation(VM& vm)
</ins><span class="cx"> {
</span><span class="cx"> Base::finishCreation(vm);
</span><span class="cx"> ASSERT(inherits(vm, info()));
</span><del>- JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("validate", webAssemblyValidateFunc, DontEnum, 1);
- JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("compile", webAssemblyCompileFunc, DontEnum, 1);
- JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("instantiate", webAssemblyInstantiateFunc, DontEnum, 1);
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> JSWebAssembly::JSWebAssembly(VM& vm, Structure* structure)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmJSWebAssemblyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/JSWebAssembly.h (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/JSWebAssembly.h        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/Source/JavaScriptCore/wasm/JSWebAssembly.h        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -67,7 +67,7 @@
</span><span class="cx"> DECLARE_INFO;
</span><span class="cx">
</span><span class="cx"> protected:
</span><del>- void finishCreation(VM&, JSGlobalObject*);
</del><ins>+ void finishCreation(VM&);
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> JSWebAssembly(VM&, Structure*);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyMemoryPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx">
</span><span class="cx"> namespace JSC {
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState*);
</span><ins>+static EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState*);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> #include "WebAssemblyMemoryPrototype.lut.h"
</span><span class="lines">@@ -47,12 +48,11 @@
</span><span class="cx">
</span><span class="cx"> /* Source for WebAssemblyMemoryPrototype.lut.h
</span><span class="cx"> @begin prototypeTableWebAssemblyMemory
</span><del>- grow webAssemblyMemoryProtoFuncGrow DontEnum|Function 1
</del><ins>+ grow webAssemblyMemoryProtoFuncGrow DontEnum|Function 1
+ buffer webAssemblyMemoryProtoFuncBuffer DontEnum|Accessor 0
</ins><span class="cx"> @end
</span><span class="cx"> */
</span><span class="cx">
</span><del>-EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState*);
-
</del><span class="cx"> ALWAYS_INLINE JSWebAssemblyMemory* getMemory(ExecState* exec, JSValue value)
</span><span class="cx"> {
</span><span class="cx"> VM& vm = exec->vm();
</span><span class="lines">@@ -67,16 +67,6 @@
</span><span class="cx"> return memory;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState* exec)
-{
- VM& vm = exec->vm();
- auto throwScope = DECLARE_THROW_SCOPE(vm);
-
- JSWebAssemblyMemory* memory = getMemory(exec, exec->thisValue());
- RETURN_IF_EXCEPTION(throwScope, { });
- return JSValue::encode(memory->buffer(exec->vm(), exec->lexicalGlobalObject()));
-}
-
</del><span class="cx"> EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> VM& vm = exec->vm();
</span><span class="lines">@@ -95,10 +85,20 @@
</span><span class="cx"> return JSValue::encode(jsNumber(result.pageCount()));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
</del><ins>+EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState* exec)
</ins><span class="cx"> {
</span><ins>+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSWebAssemblyMemory* memory = getMemory(exec, exec->thisValue());
+ RETURN_IF_EXCEPTION(throwScope, { });
+ return JSValue::encode(memory->buffer(exec->vm(), exec->lexicalGlobalObject()));
+}
+
+WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
+{
</ins><span class="cx"> auto* object = new (NotNull, allocateCell<WebAssemblyMemoryPrototype>(vm.heap)) WebAssemblyMemoryPrototype(vm, structure);
</span><del>- object->finishCreation(vm, globalObject);
</del><ins>+ object->finishCreation(vm);
</ins><span class="cx"> return object;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -107,10 +107,10 @@
</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 WebAssemblyMemoryPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
</del><ins>+void WebAssemblyMemoryPrototype::finishCreation(VM& vm)
</ins><span class="cx"> {
</span><span class="cx"> Base::finishCreation(vm);
</span><del>- JSC_NATIVE_GETTER("buffer", webAssemblyMemoryProtoFuncBuffer, DontEnum | Accessor);
</del><ins>+ ASSERT(inherits(vm, info()));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> WebAssemblyMemoryPrototype::WebAssemblyMemoryPrototype(VM& vm, Structure* structure)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyMemoryPrototypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -43,7 +43,7 @@
</span><span class="cx"> DECLARE_INFO;
</span><span class="cx">
</span><span class="cx"> protected:
</span><del>- void finishCreation(VM&, JSGlobalObject*);
</del><ins>+ void finishCreation(VM&);
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> WebAssemblyMemoryPrototype(VM&, Structure*);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -28,40 +28,230 @@
</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 "JSWebAssemblyInstance.h"
+#include "JSWebAssemblyModule.h"
+#include "ObjectConstructor.h"
+#include "PromiseDeferredTimer.h"
+#include "StrongInlines.h"
+#include "WasmPlan.h"
+#include "WasmWorklist.h"
+#include "WebAssemblyInstanceConstructor.h"
+#include "WebAssemblyModuleConstructor.h"
</ins><span class="cx">
</span><ins>+using JSC::Wasm::Plan;
+
</ins><span class="cx"> namespace JSC {
</span><ins>+static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState*);
+static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState*);
+static EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState*);
+}
</ins><span class="cx">
</span><del>-static EncodedJSValue JSC_HOST_CALL webAssemblyFunctionValidate(ExecState* exec)
</del><ins>+#include "WebAssemblyPrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyPrototype::s_info = { "WebAssembly.prototype", &Base::s_info, &prototypeTableWebAssembly, CREATE_METHOD_TABLE(WebAssemblyPrototype) };
+
+/* Source for WebAssemblyPrototype.lut.h
+ @begin prototypeTableWebAssembly
+ compile webAssemblyCompileFunc DontEnum|Function 1
+ instantiate webAssemblyInstantiateFunc DontEnum|Function 1
+ validate webAssemblyValidateFunc DontEnum|Function 1
+ @end
+ */
+
+static EncodedJSValue reject(ExecState* exec, CatchScope& catchScope, JSPromiseDeferred* promise)
</ins><span class="cx"> {
</span><del>- VM& vm = exec->vm();
- auto scope = DECLARE_THROW_SCOPE(vm);
- return JSValue::encode(throwException(exec, scope, createError(exec, ASCIILiteral("WebAssembly doesn't yet implement the validate function property"))));
</del><ins>+ Exception* exception = catchScope.exception();
+ ASSERT(exception);
+ catchScope.clearException();
+ promise->reject(exec, exception->value());
+ return JSValue::encode(promise->promise());
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-static EncodedJSValue JSC_HOST_CALL webAssemblyFunctionCompile(ExecState* exec)
</del><ins>+static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState* exec)
</ins><span class="cx"> {
</span><span class="cx"> VM& vm = exec->vm();
</span><del>- auto scope = DECLARE_THROW_SCOPE(vm);
- return JSValue::encode(throwException(exec, scope, createError(exec, ASCIILiteral("WebAssembly doesn't yet implement the compile function property"))));
</del><ins>+ auto scope = DECLARE_CATCH_SCOPE(vm);
+ auto* globalObject = exec->lexicalGlobalObject();
+
+ JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, globalObject);
+ RETURN_IF_EXCEPTION(scope, { });
+
+ RefPtr<ArrayBuffer> source = createSourceBufferFromValue(vm, exec, exec->argument(0));
+ RETURN_IF_EXCEPTION(scope, { });
+
+ Vector<Strong<JSCell>> dependencies;
+ dependencies.append(Strong<JSCell>(vm, globalObject));
+ vm.promiseDeferredTimer->addPendingPromise(promise, WTFMove(dependencies));
+
+ Ref<Plan> plan = adoptRef(*new Plan(vm, *source, Plan::Validation, [source, promise, globalObject] (Plan& p) mutable {
+ RefPtr<Plan> plan = makeRef(p);
+ plan->vm().promiseDeferredTimer->scheduleWorkSoon(promise, [source, promise, globalObject, plan = WTFMove(plan)] () mutable {
+ VM& vm = plan->vm();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+ ExecState* exec = globalObject->globalExec();
+ JSValue module = JSWebAssemblyModule::createStub(vm, exec, globalObject->WebAssemblyModuleStructure(), WTFMove(source), WTFMove(plan));
+ if (scope.exception()) {
+ reject(exec, scope, promise);
+ return;
+ }
+
+ promise->resolve(exec, module);
+ });
+ }));
+
+ Wasm::ensureWorklist().enqueue(WTFMove(plan));
+ return JSValue::encode(promise->promise());
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+enum class Resolve { WithInstance, WithModuleAndInstance };
+static void resolve(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSWebAssemblyInstance* instance, JSWebAssemblyModule* module, Resolve entries)
+{
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+ instance->finalizeCreation(vm, exec);
+ if (scope.exception()) {
+ reject(exec, scope, promise);
+ return;
+ }
+
+ if (entries == Resolve::WithInstance)
+ promise->resolve(exec, instance);
+ else {
+ JSObject* result = constructEmptyObject(exec);
+ result->putDirect(vm, Identifier::fromString(&vm, ASCIILiteral("module")), module);
+ result->putDirect(vm, Identifier::fromString(&vm, ASCIILiteral("instance")), instance);
+ promise->resolve(exec, result);
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-#include "WebAssemblyPrototype.lut.h"
</del><ins>+static void instantiate(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSWebAssemblyModule* module, JSObject* importObject, Resolve entries)
+{
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+ // In order to avoid potentially recompiling a module. We first gather all the import/memory information prior to compiling code.
+ JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, exec, module, importObject, exec->lexicalGlobalObject()->WebAssemblyInstanceStructure());
+ if (scope.exception()) {
+ reject(exec, scope, promise);
+ return;
+ }
</ins><span class="cx">
</span><del>-namespace JSC {
</del><ins>+ // There are three possible cases:
+ // 1) The instance already has an initialized CodeBlock, so we have no more work to do.
+ // 2) The instance has no CodeBlock, so we need to make one and compile the code for it.
+ // 3) The instance already has an uninitialized CodeBlock, so someone else is compiling code and we just need to wait for them.
</ins><span class="cx">
</span><del>-const ClassInfo WebAssemblyPrototype::s_info = { "WebAssembly.prototype", &Base::s_info, &prototypeTableWebAssembly, CREATE_METHOD_TABLE(WebAssemblyPrototype) };
</del><ins>+ if (instance->initialized()) {
+ resolve(vm, exec, promise, instance, module, entries);
+ return;
+ }
</ins><span class="cx">
</span><del>-/* Source for WebAssemblyPrototype.lut.h
- @begin prototypeTableWebAssembly
- validate webAssemblyFunctionValidate DontEnum|Function 1
- compile webAssemblyFunctionCompile DontEnum|Function 1
- @end
- */
</del><ins>+ Vector<Strong<JSCell>> dependencies;
+ // The instance keeps the module alive.
+ dependencies.append(Strong<JSCell>(vm, instance));
+ vm.promiseDeferredTimer->addPendingPromise(promise, WTFMove(dependencies));
</ins><span class="cx">
</span><ins>+ if (instance->codeBlock()) {
+ vm.promiseDeferredTimer->scheduleBlockedTask(instance->codeBlock()->plan().pendingPromise(), [&vm, promise, instance, module, entries] () {
+ auto* globalObject = instance->globalObject();
+ ExecState* exec = globalObject->globalExec();
+ resolve(vm, exec, promise, instance, module, entries);
+ });
+ return;
+ }
+ ASSERT(!instance->codeBlock());
+
+ // FIXME: This re-parses the module header, which shouldn't be necessary.
+ // https://bugs.webkit.org/show_bug.cgi?id=170205
+ Ref<Plan> plan = adoptRef(*new Plan(vm, module->source(), Plan::FullCompile, [promise, instance, module, entries] (Plan& p) {
+ RefPtr<Plan> plan = makeRef(p);
+ plan->vm().promiseDeferredTimer->scheduleWorkSoon(promise, [promise, instance, module, entries, plan = WTFMove(plan)] () {
+ VM& vm = plan->vm();
+ ExecState* exec = instance->globalObject()->globalExec();
+ resolve(vm, exec, promise, instance, module, entries);
+ });
+ }));
+
+ instance->addUnitializedCodeBlock(vm, plan.copyRef());
+ plan->setModeAndPromise(instance->memoryMode(), promise);
+ Wasm::ensureWorklist().enqueue(WTFMove(plan));
+}
+
+static void compileAndInstantiate(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSValue buffer, JSObject* importObject)
+{
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ RefPtr<ArrayBuffer> source = createSourceBufferFromValue(vm, exec, buffer);
+ RETURN_IF_EXCEPTION(scope, void());
+
+ auto* globalObject = exec->lexicalGlobalObject();
+
+ Vector<Strong<JSCell>> dependencies;
+ dependencies.append(Strong<JSCell>(vm, importObject));
+ vm.promiseDeferredTimer->addPendingPromise(promise, WTFMove(dependencies));
+
+ Ref<Plan> plan = adoptRef(*new Plan(vm, *source, Plan::Validation, [source, promise, importObject, globalObject] (Plan& p) mutable {
+ RefPtr<Plan> plan = makeRef(p);
+ plan->vm().promiseDeferredTimer->scheduleWorkSoon(promise, [source, promise, importObject, globalObject, plan = WTFMove(plan)] () mutable {
+ VM& vm = plan->vm();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+ ExecState* exec = globalObject->globalExec();
+ JSWebAssemblyModule* module = JSWebAssemblyModule::createStub(vm, exec, globalObject->WebAssemblyModuleStructure(), WTFMove(source), plan.copyRef());
+ if (scope.exception()) {
+ reject(exec, scope, promise);
+ return;
+ }
+
+ instantiate(vm, exec, promise, module, importObject, Resolve::WithModuleAndInstance);
+ });
+ }));
+
+ Wasm::ensureWorklist().enqueue(WTFMove(plan));
+}
+
+static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto catchScope = DECLARE_CATCH_SCOPE(vm);
+
+ JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, exec->lexicalGlobalObject());
+ RETURN_IF_EXCEPTION(catchScope, encodedJSValue());
+
+ JSValue importArgument = exec->argument(1);
+ JSObject* importObject = importArgument.getObject();
+ if (!importArgument.isUndefined() && !importObject) {
+ promise->reject(exec, createTypeError(exec,
+ ASCIILiteral("second argument to WebAssembly.instantiate must be undefined or an Object"), defaultSourceAppender, runtimeTypeForValue(importArgument)));
+ return JSValue::encode(promise->promise());
+ }
+
+ JSValue firstArgument = exec->argument(0);
+ if (auto* module = jsDynamicCast<JSWebAssemblyModule*>(vm, firstArgument))
+ instantiate(vm, exec, promise, module, importObject, Resolve::WithInstance);
+ else
+ compileAndInstantiate(vm, exec, promise, firstArgument, importObject);
+
+ return JSValue::encode(promise->promise());
+}
+
+static 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, encodedJSValue());
+ Wasm::Plan plan(vm, base + byteOffset, byteSize, Plan::Validation, Plan::dontFinalize);
+ // 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"> WebAssemblyPrototype* WebAssemblyPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
</span><span class="cx"> {
</span><span class="cx"> auto* object = new (NotNull, allocateCell<WebAssemblyPrototype>(vm.heap)) WebAssemblyPrototype(vm, structure);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyTablePrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -33,6 +33,13 @@
</span><span class="cx"> #include "JSWebAssemblyHelpers.h"
</span><span class="cx"> #include "JSWebAssemblyTable.h"
</span><span class="cx">
</span><ins>+namespace JSC {
+static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState*);
+static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState*);
+static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState*);
+static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState*);
+}
+
</ins><span class="cx"> #include "WebAssemblyTablePrototype.lut.h"
</span><span class="cx">
</span><span class="cx"> namespace JSC {
</span><span class="lines">@@ -41,6 +48,10 @@
</span><span class="cx">
</span><span class="cx"> /* Source for WebAssemblyTablePrototype.lut.h
</span><span class="cx"> @begin prototypeTableWebAssemblyTable
</span><ins>+ length webAssemblyTableProtoFuncLength DontEnum|Accessor 0
+ grow webAssemblyTableProtoFuncGrow DontEnum|Function 1
+ get webAssemblyTableProtoFuncGet DontEnum|Function 1
+ set webAssemblyTableProtoFuncSet DontEnum|Function 2
</ins><span class="cx"> @end
</span><span class="cx"> */
</span><span class="cx">
</span><span class="lines">@@ -56,11 +67,6 @@
</span><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState*);
-EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState*);
-EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState*);
-EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState*);
-
</del><span class="cx"> EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> VM& vm = exec->vm();
</span><span class="lines">@@ -81,11 +87,8 @@
</span><span class="cx">
</span><span class="cx"> uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
</span><span class="cx"> RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
</span><del>- if (!table->grow(index)) {
- throwException(exec, throwScope,
- createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.grow could not grow the table")));
- return { };
- }
</del><ins>+ if (!table->grow(index))
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.grow could not grow the table"))));
</ins><span class="cx">
</span><span class="cx"> return JSValue::encode(jsUndefined());
</span><span class="cx"> }
</span><span class="lines">@@ -100,11 +103,8 @@
</span><span class="cx">
</span><span class="cx"> uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
</span><span class="cx"> RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
</span><del>- if (index >= table->size()) {
- throwException(exec, throwScope,
- createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.get expects an integer less than the size of the table")));
- return { };
- }
</del><ins>+ if (index >= table->size())
+ return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.get expects an integer less than the size of the table"))));
</ins><span class="cx">
</span><span class="cx"> if (JSObject* result = table->getFunction(index))
</span><span class="cx"> return JSValue::encode(result);
</span><span class="lines">@@ -122,20 +122,14 @@
</span><span class="cx"> JSValue value = exec->argument(1);
</span><span class="cx"> WebAssemblyFunction* wasmFunction;
</span><span class="cx"> WebAssemblyWrapperFunction* wasmWrapperFunction;
</span><del>- if (!value.isNull() && !isWebAssemblyHostFunction(vm, value, wasmFunction, wasmWrapperFunction)) {
- throwException(exec, throwScope,
- createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects the second argument to be null or an instance of WebAssembly.Function")));
- return { };
- }
</del><ins>+ if (!value.isNull() && !isWebAssemblyHostFunction(vm, value, wasmFunction, wasmWrapperFunction))
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects the second argument to be null or an instance of WebAssembly.Function"))));
</ins><span class="cx">
</span><span class="cx"> uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
</span><span class="cx"> RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
</span><span class="cx">
</span><del>- if (index >= table->size()) {
- throwException(exec, throwScope,
- createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects an integer less than the size of the table")));
- return { };
- }
</del><ins>+ if (index >= table->size())
+ return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects an integer less than the size of the table"))));
</ins><span class="cx">
</span><span class="cx"> if (value.isNull())
</span><span class="cx"> table->clearFunction(index);
</span><span class="lines">@@ -151,10 +145,10 @@
</span><span class="cx"> return JSValue::encode(jsUndefined());
</span><span class="cx"> }
</span><span class="cx">
</span><del>-WebAssemblyTablePrototype* WebAssemblyTablePrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
</del><ins>+WebAssemblyTablePrototype* WebAssemblyTablePrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
</ins><span class="cx"> {
</span><span class="cx"> auto* object = new (NotNull, allocateCell<WebAssemblyTablePrototype>(vm.heap)) WebAssemblyTablePrototype(vm, structure);
</span><del>- object->finishCreation(vm, globalObject);
</del><ins>+ object->finishCreation(vm);
</ins><span class="cx"> return object;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -163,14 +157,10 @@
</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 WebAssemblyTablePrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
</del><ins>+void WebAssemblyTablePrototype::finishCreation(VM& vm)
</ins><span class="cx"> {
</span><span class="cx"> Base::finishCreation(vm);
</span><del>-
- JSC_NATIVE_GETTER("length", webAssemblyTableProtoFuncLength, DontEnum | Accessor);
- JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("grow", webAssemblyTableProtoFuncGrow, DontEnum, 1);
- JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("get", webAssemblyTableProtoFuncGet, DontEnum, 1);
- JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("set", webAssemblyTableProtoFuncSet, DontEnum, 2);
</del><ins>+ ASSERT(inherits(vm, info()));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> WebAssemblyTablePrototype::WebAssemblyTablePrototype(VM& vm, Structure* structure)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmjsWebAssemblyTablePrototypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h (214600 => 214601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h        2017-03-30 06:35:31 UTC (rev 214600)
+++ trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h        2017-03-30 07:16:27 UTC (rev 214601)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -43,7 +43,7 @@
</span><span class="cx"> DECLARE_INFO;
</span><span class="cx">
</span><span class="cx"> protected:
</span><del>- void finishCreation(VM&, JSGlobalObject*);
</del><ins>+ void finishCreation(VM&);
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> WebAssemblyTablePrototype(VM&, Structure*);
</span></span></pre>
</div>
</div>
</body>
</html>