e2b7092f52
This is an unmodified reland of commit67106ff494
The issue causing the revert should be addressed by commit8598d77023
Original change's description: > [wasm-gc] JS interop: Do not wrap structs/arrays by default > > Bug: v8:7748 > Change-Id: I441fd294bc0f31c0396217bc55c27159abacdbd1 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3905725 > Reviewed-by: Manos Koukoutos <manoskouk@chromium.org> > Commit-Queue: Manos Koukoutos <manoskouk@chromium.org> > Auto-Submit: Matthias Liedtke <mliedtke@chromium.org> > Commit-Queue: Matthias Liedtke <mliedtke@chromium.org> > Cr-Commit-Position: refs/heads/main@{#83338} Bug: v8:7748 Change-Id: I3e6a0a33bed4dbc7dd7c311465b25de4f8184894 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3912763 Reviewed-by: Manos Koukoutos <manoskouk@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Matthias Liedtke <mliedtke@chromium.org> Cr-Commit-Position: refs/heads/main@{#83382}
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
// 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
|
|
"use strict";
|
|
|
|
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
let instance = (() => {
|
|
let builder = new WasmModuleBuilder();
|
|
let struct = builder.addStruct([makeField(kWasmI32, true)]);
|
|
builder.addFunction('createStruct', makeSig([kWasmI32], [kWasmEqRef]))
|
|
.addBody([
|
|
kExprLocalGet, 0,
|
|
kGCPrefix, kExprStructNew, struct])
|
|
.exportFunc();
|
|
builder.addFunction('passObj', makeSig([kWasmExternRef], [kWasmExternRef]))
|
|
.addBody([kExprLocalGet, 0])
|
|
.exportFunc();
|
|
return builder.instantiate({});
|
|
})();
|
|
|
|
let obj = instance.exports.createStruct(123);
|
|
// The struct is opaque and doesn't have any observable properties.
|
|
assertFalse(obj instanceof Object);
|
|
assertEquals([], Object.getOwnPropertyNames(obj));
|
|
// It can be passed as externref without any observable change.
|
|
let passObj = instance.exports.passObj;
|
|
let obj2 = passObj(obj);
|
|
assertFalse(obj2 instanceof Object);
|
|
assertEquals([], Object.getOwnPropertyNames(obj2));
|
|
assertSame(obj, obj2);
|
|
// A JavaScript object can be passed as externref.
|
|
let jsObject = {"hello": "world"};
|
|
assertSame(jsObject, passObj(jsObject));
|