Commit 937b5d40 authored by Matthias Liedtke's avatar Matthias Liedtke Committed by V8 LUCI CQ

[wasm-gc] Use non-generic-wrapper for anyref

This has been broken even prior to the any <-> extern split.
The code decided to use the generic wrapper for type any even though
the generic wrapper doesn't support wrapping the return value of functions
and unwrapping arguments passed to it.

Bug: v8:7748
Change-Id: I9dbb893cc4bc4f2bb789b3b3a9addd0208d526ae
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3826056Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Auto-Submit: Matthias Liedtke <mliedtke@chromium.org>
Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82424}
parent e99b43f8
......@@ -187,7 +187,7 @@ bool UseGenericWrapper(const FunctionSig* sig) {
ValueType ret = sig->GetReturn(0);
if (ret.kind() == kS128) return false;
if (ret.is_reference()) {
if (ret.heap_representation() != wasm::HeapType::kAny &&
if (ret.heap_representation() != wasm::HeapType::kExtern &&
ret.heap_representation() != wasm::HeapType::kFunc) {
return false;
}
......@@ -197,7 +197,7 @@ bool UseGenericWrapper(const FunctionSig* sig) {
if (type.kind() != kI32 && type.kind() != kI64 && type.kind() != kF32 &&
type.kind() != kF64 &&
!(type.is_reference() &&
type.heap_representation() == wasm::HeapType::kAny)) {
type.heap_representation() == wasm::HeapType::kExtern)) {
return false;
}
}
......
// 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], [kWasmAnyRef]))
.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 wrapped in the special wrapper.
// It doesn't have any observable properties.
assertTrue(obj instanceof Object);
assertEquals([], Object.getOwnPropertyNames(obj));
assertEquals("{}", JSON.stringify(obj));
// It can be passed as externref without any observable change.
let passObj = instance.exports.passObj;
obj = passObj(obj);
assertTrue(obj instanceof Object);
assertEquals([], Object.getOwnPropertyNames(obj));
assertEquals("{}", JSON.stringify(obj));
// A JavaScript object can be passed as externref.
// It will not be wrapped.
obj = passObj({"hello": "world"});
assertEquals({"hello": "world"}, obj);
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