2022-08-11 15:41:37 +00:00
|
|
|
// 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)]);
|
2022-08-18 08:15:11 +00:00
|
|
|
builder.addFunction('createStruct', makeSig([kWasmI32], [kWasmEqRef]))
|
2022-08-11 15:41:37 +00:00
|
|
|
.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);
|
2022-09-20 13:41:23 +00:00
|
|
|
// The struct is opaque and doesn't have any observable properties.
|
|
|
|
assertFalse(obj instanceof Object);
|
2022-08-11 15:41:37 +00:00
|
|
|
assertEquals([], Object.getOwnPropertyNames(obj));
|
|
|
|
// It can be passed as externref without any observable change.
|
|
|
|
let passObj = instance.exports.passObj;
|
2022-09-20 13:41:23 +00:00
|
|
|
let obj2 = passObj(obj);
|
|
|
|
assertFalse(obj2 instanceof Object);
|
|
|
|
assertEquals([], Object.getOwnPropertyNames(obj2));
|
|
|
|
assertSame(obj, obj2);
|
2022-08-11 15:41:37 +00:00
|
|
|
// A JavaScript object can be passed as externref.
|
2022-09-20 13:41:23 +00:00
|
|
|
let jsObject = {"hello": "world"};
|
|
|
|
assertSame(jsObject, passObj(jsObject));
|