Commit 7d00a97a authored by Matthias Liedtke's avatar Matthias Liedtke Committed by V8 LUCI CQ

[wasm-gc] JS interop: Test import/export of wasm objects

Bug: v8:7748
Change-Id: I1d4d951b67546e0403854b96b04b681ce101deaf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3902053
Auto-Submit: Matthias Liedtke <mliedtke@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83321}
parent 4c4549ee
......@@ -35,6 +35,7 @@
'regress/modules-skip*': [SKIP],
'wasm/exceptions-utils': [SKIP],
'wasm/gc-js-interop-helpers': [SKIP],
'wasm/gc-js-interop-export': [SKIP],
'wasm/wasm-module-builder': [SKIP],
'compiler/fast-api-helpers': [SKIP],
'typedarray-helpers': [SKIP],
......
// Copyright 2022 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.
d8.file.execute('test/mjsunit/wasm/gc-js-interop-helpers.js');
export let {struct, array} = CreateWasmObjects();
......@@ -8,6 +8,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
function CreateWasmObjects() {
let builder = new WasmModuleBuilder();
builder.setSingletonRecGroups();
let struct_type = builder.addStruct([makeField(kWasmI32, true)]);
let array_type = builder.addArray(kWasmI32, true);
builder.addFunction('MakeStruct', makeSig([], [kWasmExternRef]))
......
// Copyright 2022 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.
// Flags: --experimental-wasm-gc --wasm-gc-js-interop --allow-natives-syntax
import {struct, array} from 'gc-js-interop-export.mjs';
// Read struct and array with new wasm module.
let builder = new WasmModuleBuilder();
builder.setSingletonRecGroups();
let struct_type = builder.addStruct([makeField(kWasmI32, true)]);
let array_type = builder.addArray(kWasmI32, true);
builder.addFunction('readStruct', makeSig([kWasmExternRef], [kWasmI32]))
.exportFunc()
.addBody([
kExprLocalGet, 0, // --
kGCPrefix, kExprExternInternalize, // --
kGCPrefix, kExprRefAsData, // --
kGCPrefix, kExprRefCast, struct_type, // --
kGCPrefix, kExprStructGet, struct_type, 0, // --
]);
builder.addFunction('readArrayLength', makeSig([kWasmExternRef], [kWasmI32]))
.exportFunc()
.addBody([
kExprLocalGet, 0, // --
kGCPrefix, kExprExternInternalize, // --
kGCPrefix, kExprRefAsArray, // --
kGCPrefix, kExprArrayLen,
]);
let instance = builder.instantiate();
let wasm = instance.exports;
assertEquals(42, wasm.readStruct(struct));
assertEquals(2, wasm.readArrayLength(array));
assertTraps(kTrapIllegalCast, () => wasm.readStruct(array));
assertTraps(kTrapIllegalCast, () => wasm.readArrayLength(struct));
......@@ -275,12 +275,6 @@ for (const wasm_obj of [struct, array]) {
assertThrows(() => gen().next(), TypeError);
});
// FIXME(mliedtke): Should we repeat the same testing for async generator
// functions as for the synchronous ones?
// Ensure no statement re-assigned wasm_obj by accident.
assertTrue(wasm_obj == struct || wasm_obj == array);
}
// TODO(mliedtke): What about `export {struct, array}`?
// d8 doesn't seem to accept exports (as the file isn't a module?)
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