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

[wasm-gc] Support non-function ref globals with non-global init value

This change adds support for defining globals whose value is imported
and not defined inline. This was already possible for importing globals
from other modules, now it is also supported for non-global values, e.g.
values created by a wasm function and exported to JS.

Bug: v8:7748
Change-Id: I4fe22a7ab33b431cb731458900c0f332dff8b8f7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3865554Reviewed-by: 's avatarManos Koukoutos <manoskouk@chromium.org>
Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82934}
parent 076e832c
......@@ -1542,6 +1542,14 @@ bool InstanceBuilder::ProcessImportedGlobal(Handle<WasmInstanceObject> instance,
if (IsSubtypeOf(global.type, kWasmFuncRef, module_) && !value->IsNull()) {
value =
WasmInternalFunction::FromExternal(value, isolate_).ToHandleChecked();
} else if (!v8_flags.wasm_gc_js_interop &&
global.type.heap_representation() != HeapType::kExtern &&
!value->IsNull()) {
bool unpacked = TryUnpackObjectWrapper(isolate_, value);
// Excluding SMIs and stringrefs, every value received here, must have
// been wrapped. This is ensured by TypeCheckJSObject().
DCHECK_EQ(unpacked, !value->IsSmi() && !value->IsString());
USE(unpacked); // Prevent nused warning if DCHECKs disabled.
}
WriteGlobalValue(global, WasmValue(value, global.type));
return true;
......
......@@ -2413,6 +2413,7 @@ bool TypecheckJSObject(Isolate* isolate, const WasmModule* module,
if (!(((repr == HeapType::kEq || repr == HeapType::kAny) &&
value->IsSmi()) ||
(repr == HeapType::kAny && value->IsString()) ||
(repr != HeapType::kArray && value->IsWasmStruct()) ||
value->IsWasmArray())) {
*error_message = "object incompatible with wasm type";
......
......@@ -219,10 +219,12 @@ V8_NOINLINE V8_EXPORT_PRIVATE bool IsHeapSubtypeOfImpl(
return super_heap == HeapType::kArray || super_heap == HeapType::kData ||
super_heap == HeapType::kEq || super_heap == HeapType::kAny;
case HeapType::kString:
// TODO(7748): Remove views from any subtype hierarchy as views can't be
// externalized as of now.
case HeapType::kStringViewWtf8:
case HeapType::kStringViewWtf16:
case HeapType::kStringViewIter:
// stringref is a subtype of anyref (aka externref) under wasm-gc.
// stringref is a subtype of anyref under wasm-gc.
return sub_heap == super_heap ||
(v8_flags.experimental_wasm_gc && super_heap == HeapType::kAny);
case HeapType::kBottom:
......
This diff is collapsed.
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