Commit d9e44b2d authored by Thibaud Michaud's avatar Thibaud Michaud Committed by V8 LUCI CQ

[wasm] Suspend on other JS import kinds

The stack-switching variant of the wasm-to-js wrapper was only generated
for js functions with matching arity. Also suspend for js functions with
mismatching arity and unknown callables.

R=ahaas@chromium.org

Bug: v8:12191
Change-Id: Iab3e2d85210c86a814ae1defab9cd57bf74d80d2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3749578Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81605}
parent 7ea0412e
...@@ -7041,7 +7041,9 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7041,7 +7041,9 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
auto call_descriptor = Linkage::GetJSCallDescriptor( auto call_descriptor = Linkage::GetJSCallDescriptor(
graph()->zone(), false, pushed_count + 1, CallDescriptor::kNoFlags); graph()->zone(), false, pushed_count + 1, CallDescriptor::kNoFlags);
call = gasm_->Call(call_descriptor, pos, args.begin()); call = gasm_->Call(call_descriptor, pos, args.begin());
// TODO(12191): Handle suspending wrapper. if (suspend == wasm::kSuspend) {
call = BuildSuspend(call, Param(0));
}
break; break;
} }
// ======================================================================= // =======================================================================
...@@ -7077,7 +7079,9 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7077,7 +7079,9 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
DCHECK_EQ(pos, args.size()); DCHECK_EQ(pos, args.size());
call = gasm_->Call(call_descriptor, pos, args.begin()); call = gasm_->Call(call_descriptor, pos, args.begin());
// TODO(12191): Handle suspending wrapper. if (suspend == wasm::kSuspend) {
call = BuildSuspend(call, Param(0));
}
break; break;
} }
default: default:
......
...@@ -93,18 +93,36 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -93,18 +93,36 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
kExprCallFunction, import_index, // suspend kExprCallFunction, import_index, // suspend
]).exportFunc(); ]).exportFunc();
let suspender = new WebAssembly.Suspender(); let suspender = new WebAssembly.Suspender();
function js_import() { let js_import = suspender.suspendOnReturnedPromise(
return Promise.resolve(42); new WebAssembly.Function(
}; {parameters: [], results: ['externref']},
let wasm_js_import = new WebAssembly.Function( () => Promise.resolve(42)));
{parameters: [], results: ['externref']}, js_import); let instance = builder.instantiate({m: {import: js_import}});
let suspending_wasm_js_import =
suspender.suspendOnReturnedPromise(wasm_js_import);
let instance = builder.instantiate({m: {import: suspending_wasm_js_import}});
let wrapped_export = suspender.returnPromiseOnSuspend(instance.exports.test); let wrapped_export = suspender.returnPromiseOnSuspend(instance.exports.test);
let combined_promise = wrapped_export(); let combined_promise = wrapped_export();
combined_promise.then(v => assertEquals(42, v)); combined_promise.then(v => assertEquals(42, v));
// Also try with a JS function with a mismatching arity.
suspender = new WebAssembly.Suspender();
js_import = suspender.suspendOnReturnedPromise(
new WebAssembly.Function(
{parameters: [], results: ['externref']},
(unused) => Promise.resolve(42)));
instance = builder.instantiate({m: {import: js_import}});
wrapped_export = suspender.returnPromiseOnSuspend(instance.exports.test);
combined_promise = wrapped_export();
combined_promise.then(v => assertEquals(42, v));
// Also try with a proxy.
suspender = new WebAssembly.Suspender();
js_import = suspender.suspendOnReturnedPromise(
new WebAssembly.Function(
{parameters: [], results: ['externref']},
new Proxy(() => Promise.resolve(42), {})));
instance = builder.instantiate({m: {import: js_import}});
wrapped_export = suspender.returnPromiseOnSuspend(instance.exports.test);
combined_promise = wrapped_export();
combined_promise.then(v => assertEquals(42, v));
})(); })();
// Check that we can suspend back out of a resumed computation. // Check that we can suspend back out of a resumed computation.
......
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