[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: Jakob 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}
This commit is contained in:
Matthias Liedtke 2022-09-20 11:31:19 +02:00 committed by V8 LUCI CQ
parent 4c4549ee57
commit 7d00a97afb
5 changed files with 45 additions and 6 deletions

View File

@ -35,6 +35,7 @@
'regress/modules-skip*': [SKIP], 'regress/modules-skip*': [SKIP],
'wasm/exceptions-utils': [SKIP], 'wasm/exceptions-utils': [SKIP],
'wasm/gc-js-interop-helpers': [SKIP], 'wasm/gc-js-interop-helpers': [SKIP],
'wasm/gc-js-interop-export': [SKIP],
'wasm/wasm-module-builder': [SKIP], 'wasm/wasm-module-builder': [SKIP],
'compiler/fast-api-helpers': [SKIP], 'compiler/fast-api-helpers': [SKIP],
'typedarray-helpers': [SKIP], 'typedarray-helpers': [SKIP],

View File

@ -0,0 +1,6 @@
// 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();

View File

@ -8,6 +8,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
function CreateWasmObjects() { function CreateWasmObjects() {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.setSingletonRecGroups();
let struct_type = builder.addStruct([makeField(kWasmI32, true)]); let struct_type = builder.addStruct([makeField(kWasmI32, true)]);
let array_type = builder.addArray(kWasmI32, true); let array_type = builder.addArray(kWasmI32, true);
builder.addFunction('MakeStruct', makeSig([], [kWasmExternRef])) builder.addFunction('MakeStruct', makeSig([], [kWasmExternRef]))

View File

@ -0,0 +1,37 @@
// 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));

View File

@ -275,12 +275,6 @@ for (const wasm_obj of [struct, array]) {
assertThrows(() => gen().next(), TypeError); 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. // Ensure no statement re-assigned wasm_obj by accident.
assertTrue(wasm_obj == struct || wasm_obj == array); 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?)