diff --git a/test/mjsunit/mjsunit.status b/test/mjsunit/mjsunit.status index 3bf39e2528..600eb61fbf 100644 --- a/test/mjsunit/mjsunit.status +++ b/test/mjsunit/mjsunit.status @@ -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], diff --git a/test/mjsunit/wasm/gc-js-interop-export.mjs b/test/mjsunit/wasm/gc-js-interop-export.mjs new file mode 100644 index 0000000000..ee5e4a23bc --- /dev/null +++ b/test/mjsunit/wasm/gc-js-interop-export.mjs @@ -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(); diff --git a/test/mjsunit/wasm/gc-js-interop-helpers.js b/test/mjsunit/wasm/gc-js-interop-helpers.js index 3c39fc13bc..2047862d16 100644 --- a/test/mjsunit/wasm/gc-js-interop-helpers.js +++ b/test/mjsunit/wasm/gc-js-interop-helpers.js @@ -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])) diff --git a/test/mjsunit/wasm/gc-js-interop-import.mjs b/test/mjsunit/wasm/gc-js-interop-import.mjs new file mode 100644 index 0000000000..ce4d5f9633 --- /dev/null +++ b/test/mjsunit/wasm/gc-js-interop-import.mjs @@ -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)); diff --git a/test/mjsunit/wasm/gc-js-interop.js b/test/mjsunit/wasm/gc-js-interop.js index ed92056661..d05144d13a 100644 --- a/test/mjsunit/wasm/gc-js-interop.js +++ b/test/mjsunit/wasm/gc-js-interop.js @@ -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?)