Commit 2e3447bb authored by mtrofin's avatar mtrofin Committed by Commit bot

[wasm] WebAssembly.compile: pass errors through promise resolver

BUG=v8:5876

Review-Url: https://codereview.chromium.org/2644893004
Cr-Commit-Position: refs/heads/master@{#42568}
parent dc93bb47
......@@ -125,23 +125,25 @@ void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) {
ErrorThrower thrower(reinterpret_cast<i::Isolate*>(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::JSObject> 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 (thrower.error()) {
resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
} else {
resolver->Resolve(context, Utils::ToLocal(module_obj.ToHandleChecked()));
}
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
return_value.Set(resolver->GetPromise());
}
void WebAssemblyValidate(const v8::FunctionCallbackInfo<v8::Value>& args) {
......
......@@ -547,12 +547,7 @@ assertEq(compile.length, 1);
assertEq(compile.name, "compile");
function assertCompileError(args, err, msg) {
var error = null;
try {
compile(...args).catch(e => error = e);
} catch (e) {
// TODO: error shouldn't be thrown, but should be globbed onto the promise.
error = e;
}
compile(...args).catch(e => error = e);
drainJobQueue();
assertEq(error instanceof err, true);
assertEq(Boolean(error.stack.match("js-api.js")), true);
......
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