2021-10-26 10:27:07 +00:00
|
|
|
// Copyright 2021 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-12-08 10:50:38 +00:00
|
|
|
// Flags: --allow-natives-syntax --experimental-wasm-stack-switching --expose-gc
|
2021-10-26 10:27:07 +00:00
|
|
|
|
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
|
2021-11-05 14:02:33 +00:00
|
|
|
(function TestSuspender() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let suspender = new WebAssembly.Suspender();
|
|
|
|
assertTrue(suspender.toString() == "[object WebAssembly.Suspender]");
|
|
|
|
assertThrows(() => WebAssembly.Suspender(), TypeError,
|
|
|
|
/WebAssembly.Suspender must be invoked with 'new'/);
|
|
|
|
})();
|
|
|
|
|
2021-10-26 10:27:07 +00:00
|
|
|
(function TestStackSwitchNoSuspend() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addGlobal(kWasmI32, true).exportAs('g');
|
|
|
|
builder.addFunction("test", kSig_v_v)
|
|
|
|
.addBody([kExprI32Const, 42, kExprGlobalSet, 0]).exportFunc();
|
|
|
|
let instance = builder.instantiate();
|
2021-11-05 16:52:18 +00:00
|
|
|
let suspender = new WebAssembly.Suspender();
|
|
|
|
let wrapper = suspender.returnPromiseOnSuspend(instance.exports.test);
|
2021-10-26 10:27:07 +00:00
|
|
|
wrapper();
|
|
|
|
assertEquals(42, instance.exports.g.value);
|
|
|
|
})();
|
2021-12-08 10:50:38 +00:00
|
|
|
|
|
|
|
(function TestStackSwitchGC() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
let gc_index = builder.addImport('m', 'gc', kSig_v_v);
|
|
|
|
builder.addFunction("test", kSig_v_v)
|
|
|
|
.addBody([kExprCallFunction, gc_index]).exportFunc();
|
|
|
|
let instance = builder.instantiate({'m': {'gc': gc}});
|
|
|
|
let suspender = new WebAssembly.Suspender();
|
|
|
|
let wrapper = suspender.returnPromiseOnSuspend(instance.exports.test);
|
|
|
|
wrapper();
|
|
|
|
})();
|