Commit ef555d08 authored by rossberg's avatar rossberg Committed by Commit bot

Delay all exceptions in WebAssembly.instantiate

R=titzer@chromium.org
BUG=v8:5818

Review-Url: https://codereview.chromium.org/2637703004
Cr-Commit-Position: refs/heads/master@{#42372}
parent 69465f73
......@@ -321,32 +321,35 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
HandleScope scope(isolate);
ErrorThrower thrower(i_isolate, "WebAssembly.compile()");
Local<Context> context = isolate->GetCurrentContext();
v8::Local<v8::Promise::Resolver> resolver;
if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return;
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
return_value.Set(resolver->GetPromise());
if (args.Length() < 1) {
thrower.TypeError("Argument 0 must be a buffer source");
resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
return;
}
i::MaybeHandle<i::WasmModuleObject> module_obj =
CreateModuleObject(isolate, args[0], &thrower);
Local<Context> context = isolate->GetCurrentContext();
v8::Local<v8::Promise::Resolver> resolver;
if (!v8::Promise::Resolver::New(context).ToLocal(&resolver)) return;
if (module_obj.is_null()) {
DCHECK(thrower.error());
resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
return;
}
MaybeLocal<Value> instance = InstantiateModuleImpl(
i_isolate, module_obj.ToHandleChecked(), args, &thrower);
if (instance.IsEmpty()) {
DCHECK(thrower.error());
resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
} else {
MaybeLocal<Value> instance = InstantiateModuleImpl(
i_isolate, module_obj.ToHandleChecked(), args, &thrower);
if (instance.IsEmpty()) {
DCHECK(thrower.error());
resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
} else {
DCHECK(!thrower.error());
resolver->Resolve(context, instance.ToLocalChecked());
}
DCHECK(!thrower.error());
resolver->Resolve(context, instance.ToLocalChecked());
}
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
return_value.Set(resolver->GetPromise());
}
bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower,
......
......@@ -587,15 +587,11 @@ assertEq(instantiate.length, 1);
assertEq(instantiate.name, "instantiate");
function assertInstantiateError(args, err, msg) {
var error = null;
try {
instantiate(...args).catch(e => error = e);
} catch(e) {
error = e;
}
instantiate(...args).catch(e => error = e);
drainJobQueue();
assertEq(error instanceof err, true);
assertEq(Boolean(error.stack.match("js-api.js")), true);
//TOassertEq(Boolean(error.message.match(msg)), true);
//TODO assertEq(Boolean(error.message.match(msg)), true);
}
var scratch_memory = new WebAssembly.Memory(new ArrayBuffer(10));
assertInstantiateError([], TypeError, /requires more than 0 arguments/);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment