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

[wasm-gc] Split any and extern type

Bug: v8:7748
Change-Id: Ifd4caec2015894f736dd94356298f6ee35ac852b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3779911Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Auto-Submit: Matthias Liedtke <mliedtke@chromium.org>
Reviewed-by: 's avatarPhilip Pfaffe <pfaffe@chromium.org>
Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82035}
parent ef2fd8aa
......@@ -6341,6 +6341,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
// wasm::kRefNull, it's the null object. Either way it's good to go
// already to JS.
return node;
case wasm::HeapType::kExtern:
case wasm::HeapType::kAny: {
if (!enabled_features_.has_gc()) return node;
// Wrap {node} in object wrapper if it is an array/struct.
......@@ -6543,6 +6544,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
case wasm::kRef:
case wasm::kRefNull: {
switch (type.heap_representation()) {
case wasm::HeapType::kExtern:
case wasm::HeapType::kAny:
if (!enabled_features_.has_gc()) return input;
// If this is a wrapper for arrays/structs/i31s, unpack it.
......
......@@ -905,6 +905,7 @@ Handle<WasmValueObject> WasmValueObject::New(
}
case wasm::kRefNull:
case wasm::kRef: {
// TODO(12868): Support stringrefs.
t = GetRefTypeName(isolate, value.type(), module_object->native_module());
Handle<Object> ref = value.to_ref();
if (ref->IsWasmStruct()) {
......@@ -915,7 +916,7 @@ Handle<WasmValueObject> WasmValueObject::New(
v = handle(Handle<WasmInternalFunction>::cast(ref)->external(),
isolate);
} else if (ref->IsJSFunction() || ref->IsSmi() || ref->IsNull() ||
value.type().is_reference_to(wasm::HeapType::kAny)) {
value.type().is_reference_to(wasm::HeapType::kExtern)) {
v = ref;
} else {
// Fail gracefully.
......
......@@ -84,7 +84,7 @@ ValKind V8ValueTypeToWasm(i::wasm::ValueType v8_valtype) {
switch (v8_valtype.heap_representation()) {
case i::wasm::HeapType::kFunc:
return FUNCREF;
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kExtern:
return ANYREF;
default:
// TODO(wasm+): support new value types
......@@ -109,7 +109,7 @@ i::wasm::ValueType WasmValKindToV8(ValKind kind) {
case FUNCREF:
return i::wasm::kWasmFuncRef;
case ANYREF:
return i::wasm::kWasmAnyRef;
return i::wasm::kWasmExternRef;
default:
// TODO(wasm+): support new value types
UNREACHABLE();
......@@ -1930,7 +1930,7 @@ auto Table::make(Store* store_abs, const TableType* type, const Ref* ref)
break;
case ANYREF:
// See Engine::make().
i_type = i::wasm::kWasmAnyRef;
i_type = i::wasm::kWasmExternRef;
break;
default:
UNREACHABLE();
......@@ -1976,7 +1976,7 @@ auto Table::type() const -> own<TableType> {
case i::wasm::HeapType::kFunc:
kind = FUNCREF;
break;
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kExtern:
kind = ANYREF;
break;
default:
......
......@@ -237,7 +237,7 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc,
case kI31RefCode:
case kDataRefCode:
case kArrayRefCode:
case kAnyRefCodeAlias:
case kAnyRefCode:
case kNoneCode:
if (!VALIDATE(enabled.has_gc())) {
DecodeError<validate>(
......@@ -247,7 +247,7 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc,
return HeapType(HeapType::kBottom);
}
V8_FALLTHROUGH;
case kAnyRefCode:
case kExternRefCode:
case kFuncRefCode:
return HeapType::from_code(code);
case kStringRefCode:
......@@ -314,7 +314,7 @@ ValueType read_value_type(Decoder* decoder, const byte* pc,
case kI31RefCode:
case kDataRefCode:
case kArrayRefCode:
case kAnyRefCodeAlias:
case kAnyRefCode:
case kNoneCode:
if (!VALIDATE(enabled.has_gc())) {
DecodeError<validate>(
......@@ -324,7 +324,7 @@ ValueType read_value_type(Decoder* decoder, const byte* pc,
return kWasmBottom;
}
V8_FALLTHROUGH;
case kAnyRefCode:
case kExternRefCode:
case kFuncRefCode: {
HeapType heap_type = HeapType::from_code(code);
Nullability nullability =
......
......@@ -64,7 +64,8 @@ class HeapType {
kI31, // shorthand: j
kData, // shorthand: o
kArray, // shorthand: g
kAny, // shorthand: a. Aka kExtern.
kAny, //
kExtern, // shorthand: a.
kString, // shorthand: w.
kStringViewWtf8, // shorthand: x.
kStringViewWtf16, // shorthand: y.
......@@ -84,8 +85,9 @@ class HeapType {
case ValueTypeCode::kI31RefCode:
return HeapType(kI31);
case ValueTypeCode::kAnyRefCode:
case ValueTypeCode::kAnyRefCodeAlias:
return HeapType(kAny);
case ValueTypeCode::kExternRefCode:
return HeapType(kExtern);
case ValueTypeCode::kDataRefCode:
return HeapType(kData);
case ValueTypeCode::kArrayRefCode:
......@@ -152,8 +154,10 @@ class HeapType {
return std::string("data");
case kArray:
return std::string("array");
case kExtern:
return std::string("extern");
case kAny:
return std::string(FLAG_experimental_wasm_gc ? "any" : "extern");
return std::string("any");
case kString:
return std::string("string");
case kStringViewWtf8:
......@@ -185,6 +189,8 @@ class HeapType {
return mask | kDataRefCode;
case kArray:
return mask | kArrayRefCode;
case kExtern:
return mask | kExternRefCode;
case kAny:
return mask | kAnyRefCode;
case kString:
......@@ -522,6 +528,8 @@ class ValueType {
return kFuncRefCode;
case HeapType::kEq:
return kEqRefCode;
case HeapType::kExtern:
return kExternRefCode;
case HeapType::kAny:
return kAnyRefCode;
case HeapType::kString:
......@@ -575,6 +583,7 @@ class ValueType {
return heap_representation() != HeapType::kFunc &&
heap_representation() != HeapType::kEq &&
heap_representation() != HeapType::kAny &&
heap_representation() != HeapType::kExtern &&
heap_representation() != HeapType::kString &&
heap_representation() != HeapType::kStringViewWtf8 &&
heap_representation() != HeapType::kStringViewWtf16 &&
......@@ -683,6 +692,7 @@ constexpr ValueType kWasmBottom = ValueType::Primitive(kBottom);
// Established reference-type and wasm-gc proposal shorthands.
constexpr ValueType kWasmFuncRef = ValueType::RefNull(HeapType::kFunc);
constexpr ValueType kWasmAnyRef = ValueType::RefNull(HeapType::kAny);
constexpr ValueType kWasmExternRef = ValueType::RefNull(HeapType::kExtern);
constexpr ValueType kWasmEqRef = ValueType::RefNull(HeapType::kEq);
constexpr ValueType kWasmI31Ref = ValueType::Ref(HeapType::kI31);
constexpr ValueType kWasmDataRef = ValueType::Ref(HeapType::kData);
......
......@@ -37,10 +37,9 @@ enum ValueTypeCode : uint8_t {
kI16Code = 0x79,
// Current reference types
kFuncRefCode = 0x70,
kAnyRefCode = 0x6f, // aka externref
kExternRefCode = 0x6f,
// typed-funcref and GC proposal types
// TODO(7748): For backwards compatibility only, remove when able.
kAnyRefCodeAlias = 0x6e,
kAnyRefCode = 0x6e,
kEqRefCode = 0x6d,
kRefNullCode = 0x6c,
kRefCode = 0x6b,
......
......@@ -1188,8 +1188,7 @@ void WebAssemblyTable(const v8::FunctionCallbackInfo<v8::Value>& args) {
// and anyfunc just becomes an alias for "funcref".
type = i::wasm::kWasmFuncRef;
} else if (string->StringEquals(v8_str(isolate, "externref"))) {
// externref is known as anyref as of wasm-gc.
type = i::wasm::kWasmAnyRef;
type = i::wasm::kWasmExternRef;
} else if (enabled_features.has_stringref() &&
string->StringEquals(v8_str(isolate, "stringref"))) {
type = i::wasm::kWasmStringRef;
......@@ -1385,7 +1384,7 @@ bool GetValueType(Isolate* isolate, MaybeLocal<Value> maybe,
} else if (string->StringEquals(v8_str(isolate, "f64"))) {
*type = i::wasm::kWasmF64;
} else if (string->StringEquals(v8_str(isolate, "externref"))) {
*type = i::wasm::kWasmAnyRef;
*type = i::wasm::kWasmExternRef;
} else if (enabled_features.has_type_reflection() &&
string->StringEquals(v8_str(isolate, "funcref"))) {
// The type reflection proposal renames "anyfunc" to "funcref", and makes
......@@ -1400,6 +1399,9 @@ bool GetValueType(Isolate* isolate, MaybeLocal<Value> maybe,
} else if (enabled_features.has_stringref() &&
string->StringEquals(v8_str(isolate, "stringref"))) {
*type = i::wasm::kWasmStringRef;
} else if (enabled_features.has_gc() &&
string->StringEquals(v8_str(isolate, "anyref"))) {
*type = i::wasm::kWasmAnyRef;
} else {
// Unrecognized type.
*type = i::wasm::kWasmVoid;
......@@ -1551,7 +1553,7 @@ void WebAssemblyGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
case i::wasm::kRef:
case i::wasm::kRefNull: {
switch (type.heap_representation()) {
case i::wasm::HeapType::kAny: {
case i::wasm::HeapType::kExtern: {
if (args.Length() < 2) {
// When no initial value is provided, we have to use the WebAssembly
// default value 'null', and not the JS default value 'undefined'.
......@@ -1599,6 +1601,7 @@ void WebAssemblyGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
case internal::wasm::HeapType::kI31:
case internal::wasm::HeapType::kData:
case internal::wasm::HeapType::kArray:
case internal::wasm::HeapType::kAny:
case internal::wasm::HeapType::kStringViewWtf8:
case internal::wasm::HeapType::kStringViewWtf16:
case internal::wasm::HeapType::kStringViewIter:
......@@ -1789,6 +1792,7 @@ void EncodeExceptionValues(v8::Isolate* isolate,
case i::wasm::kRefNull:
switch (type.heap_representation()) {
case i::wasm::HeapType::kFunc:
case i::wasm::HeapType::kExtern:
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq:
case i::wasm::HeapType::kI31:
......@@ -2032,12 +2036,12 @@ void WebAssemblyFunctionType(const v8::FunctionCallbackInfo<v8::Value>& args) {
// promise as an externref instead of the original return type.
size_t param_count = sig->parameter_count();
DCHECK_GE(param_count, 1);
DCHECK_EQ(sig->GetParam(0), i::wasm::kWasmAnyRef);
DCHECK_EQ(sig->GetParam(0), i::wasm::kWasmExternRef);
i::wasm::FunctionSig::Builder builder(&zone, 1, param_count - 1);
for (size_t i = 1; i < param_count; ++i) {
builder.AddParam(sig->GetParam(i));
}
builder.AddReturn(i::wasm::kWasmAnyRef);
builder.AddReturn(i::wasm::kWasmExternRef);
sig = builder.Build();
}
} else if (i::WasmJSFunction::IsWasmJSFunction(*arg0)) {
......@@ -2049,13 +2053,13 @@ void WebAssemblyFunctionType(const v8::FunctionCallbackInfo<v8::Value>& args) {
// parameter which will be consumed by the wasm-to-JS wrapper.
size_t param_count = sig->parameter_count();
i::wasm::FunctionSig::Builder builder(&zone, 1, param_count + 1);
builder.AddParam(internal::wasm::kWasmAnyRef);
builder.AddParam(internal::wasm::kWasmExternRef);
for (size_t i = 0; i < param_count; ++i) {
builder.AddParam(sig->GetParam(i));
}
DCHECK_EQ(1, sig->return_count());
DCHECK_EQ(i::wasm::kWasmAnyRef, sig->GetReturn(0));
builder.AddReturn(i::wasm::kWasmAnyRef);
DCHECK_EQ(i::wasm::kWasmExternRef, sig->GetReturn(0));
builder.AddReturn(i::wasm::kWasmExternRef);
sig = builder.Build();
}
} else {
......@@ -2226,7 +2230,9 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
i::Handle<i::Object> external_element;
bool is_external = i::WasmInternalFunction::FromExternal(element, i_isolate)
// TODO(7748): Make sure externref tables don't convert any values.
bool is_external = table_object->type() != i::wasm::kWasmExternRef &&
i::WasmInternalFunction::FromExternal(element, i_isolate)
.ToHandle(&external_element);
i::WasmTableObject::Set(i_isolate, table_object, index,
......@@ -2411,6 +2417,7 @@ void WebAssemblyExceptionGetArg(
case i::wasm::kRefNull:
switch (signature.get(i).heap_representation()) {
case i::wasm::HeapType::kFunc:
case i::wasm::HeapType::kExtern:
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq:
case i::wasm::HeapType::kI31:
......@@ -2473,6 +2480,7 @@ void WebAssemblyExceptionGetArg(
case i::wasm::kRefNull:
switch (signature.get(index).heap_representation()) {
case i::wasm::HeapType::kFunc:
case i::wasm::HeapType::kExtern:
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq:
case i::wasm::HeapType::kI31:
......@@ -2555,7 +2563,7 @@ void WebAssemblyGlobalGetValueCommon(
case i::wasm::kRef:
case i::wasm::kRefNull:
switch (receiver->type().heap_representation()) {
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kExtern:
case i::wasm::HeapType::kString:
return_value.Set(Utils::ToLocal(receiver->GetRef()));
break;
......@@ -2583,6 +2591,7 @@ void WebAssemblyGlobalGetValueCommon(
case i::wasm::HeapType::kI31:
case i::wasm::HeapType::kData:
case i::wasm::HeapType::kArray:
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq:
default:
// TODO(7748): Implement these.
......@@ -2660,7 +2669,7 @@ void WebAssemblyGlobalSetValue(
case i::wasm::kRef:
case i::wasm::kRefNull:
switch (receiver->type().heap_representation()) {
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kExtern:
receiver->SetExternRef(Utils::OpenHandle(*args[0]));
break;
case i::wasm::HeapType::kFunc: {
......@@ -2704,6 +2713,7 @@ void WebAssemblyGlobalSetValue(
case i::wasm::HeapType::kI31:
case i::wasm::HeapType::kData:
case i::wasm::HeapType::kArray:
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq:
default:
// TODO(7748): Implement these.
......@@ -2760,9 +2770,9 @@ void WebAssemblyReturnPromiseOnSuspend(
"Expected a WebAssembly.Function with exactly one return type");
}
if (data.sig()->parameter_count() == 0 ||
data.sig()->GetParam(0) != internal::wasm::kWasmAnyRef) {
data.sig()->GetParam(0) != internal::wasm::kWasmExternRef) {
thrower.TypeError("Expected at least one parameter of type %s",
i::wasm::kWasmAnyRef.name().c_str());
i::wasm::kWasmExternRef.name().c_str());
}
if (thrower.error()) return;
int index = data.function_index();
......@@ -2803,9 +2813,10 @@ void WebAssemblySuspendOnReturnedPromise(
return;
}
sig = i::Handle<i::WasmJSFunction>::cast(arg0)->GetSignature(&zone);
if (sig->return_count() != 1 || sig->GetReturn(0) != i::wasm::kWasmAnyRef) {
if (sig->return_count() != 1 ||
sig->GetReturn(0) != i::wasm::kWasmExternRef) {
thrower.TypeError("Expected a WebAssembly.Function with return type %s",
i::wasm::kWasmAnyRef.name().c_str());
i::wasm::kWasmExternRef.name().c_str());
return;
}
......
......@@ -607,7 +607,7 @@ struct WasmTable {
static bool IsValidTableType(ValueType type, const WasmModule* module) {
if (!type.is_object_reference()) return false;
HeapType heap_type = type.heap_type();
return heap_type == HeapType::kFunc || heap_type == HeapType::kAny ||
return heap_type == HeapType::kFunc || heap_type == HeapType::kExtern ||
heap_type == HeapType::kString ||
heap_type == HeapType::kStringViewWtf8 ||
heap_type == HeapType::kStringViewWtf16 ||
......
......@@ -167,7 +167,7 @@ void WasmGlobalObject::SetF64(double value) {
}
void WasmGlobalObject::SetExternRef(Handle<Object> value) {
DCHECK(type().is_reference_to(wasm::HeapType::kAny));
DCHECK(type().is_reference_to(wasm::HeapType::kExtern));
tagged_buffer().set(offset(), *value);
}
......
......@@ -377,7 +377,7 @@ void WasmTableObject::Set(Isolate* isolate, Handle<WasmTableObject> table,
int entry_index = static_cast<int>(index);
switch (table->type().heap_representation()) {
case wasm::HeapType::kAny:
case wasm::HeapType::kExtern:
case wasm::HeapType::kString:
case wasm::HeapType::kStringViewWtf8:
case wasm::HeapType::kStringViewWtf16:
......@@ -390,6 +390,7 @@ void WasmTableObject::Set(Isolate* isolate, Handle<WasmTableObject> table,
case wasm::HeapType::kEq:
case wasm::HeapType::kData:
case wasm::HeapType::kArray:
case wasm::HeapType::kAny:
case wasm::HeapType::kI31:
// TODO(7748): Implement once we have struct/arrays/i31ref/string tables.
UNREACHABLE();
......@@ -423,7 +424,7 @@ Handle<Object> WasmTableObject::Get(Isolate* isolate,
}
switch (table->type().heap_representation()) {
case wasm::HeapType::kAny:
case wasm::HeapType::kExtern:
case wasm::HeapType::kString:
case wasm::HeapType::kStringViewWtf8:
case wasm::HeapType::kStringViewWtf16:
......@@ -436,6 +437,7 @@ Handle<Object> WasmTableObject::Get(Isolate* isolate,
case wasm::HeapType::kI31:
case wasm::HeapType::kData:
case wasm::HeapType::kArray:
case wasm::HeapType::kAny:
// TODO(7748): Implement once we have a story for struct/arrays/i31ref in
// JS.
UNIMPLEMENTED();
......@@ -2188,7 +2190,7 @@ bool WasmJSFunction::MatchesSignatureForSuspend(const wasm::FunctionSig* sig) {
// WebAssembly.suspendOnReturnedPromise, so the return type has to be
// externref.
CHECK_EQ(function_data.serialized_return_count(), 1);
CHECK_EQ(function_data.serialized_signature().get(0), wasm::kWasmAnyRef);
CHECK_EQ(function_data.serialized_signature().get(0), wasm::kWasmExternRef);
const wasm::ValueType* expected = sig->parameters().begin() + 1;
return function_data.serialized_signature().matches(1, expected,
parameter_count - 1);
......@@ -2312,10 +2314,11 @@ bool TypecheckJSObject(Isolate* isolate, const WasmModule* module,
}
return true;
}
case HeapType::kAny:
case HeapType::kExtern:
return true;
case HeapType::kData:
case HeapType::kArray:
case HeapType::kAny:
case HeapType::kEq:
case HeapType::kI31: {
// TODO(7748): Change this when we have a decision on the JS API for
......
......@@ -174,6 +174,8 @@ V8_NOINLINE V8_EXPORT_PRIVATE bool IsHeapSubtypeOfImpl(
return sub_heap == super_heap || super_heap == HeapType::kAny;
case HeapType::kAny:
return super_heap == HeapType::kAny;
case HeapType::kExtern:
return super_heap == HeapType::kExtern;
case HeapType::kI31:
case HeapType::kData:
return super_heap == sub_heap || super_heap == HeapType::kEq ||
......@@ -213,6 +215,8 @@ V8_NOINLINE V8_EXPORT_PRIVATE bool IsHeapSubtypeOfImpl(
return false;
case HeapType::kAny:
return true;
case HeapType::kExtern:
return false;
case HeapType::kString:
case HeapType::kStringViewWtf8:
case HeapType::kStringViewWtf16:
......@@ -340,6 +344,8 @@ HeapType::Representation CommonAncestorWithGeneric(HeapType heap1,
case HeapType::kAny:
case HeapType::kFunc:
return HeapType::kAny;
case HeapType::kExtern:
UNREACHABLE();
default:
return module2->has_signature(heap2.ref_index()) ? HeapType::kAny
: HeapType::kEq;
......@@ -356,6 +362,8 @@ HeapType::Representation CommonAncestorWithGeneric(HeapType heap1,
case HeapType::kAny:
case HeapType::kFunc:
return HeapType::kAny;
case HeapType::kExtern:
UNREACHABLE();
default:
return module2->has_signature(heap2.ref_index()) ? HeapType::kAny
: HeapType::kData;
......@@ -373,6 +381,8 @@ HeapType::Representation CommonAncestorWithGeneric(HeapType heap1,
case HeapType::kAny:
case HeapType::kFunc:
return HeapType::kAny;
case HeapType::kExtern:
UNREACHABLE();
default:
return module2->has_array(heap2.ref_index()) ? HeapType::kArray
: module2->has_struct(heap2.ref_index()) ? HeapType::kData
......
......@@ -25,8 +25,8 @@ class TestSignatures {
sig_i_ff(1, 2, kIntFloatTypes4),
sig_i_d(1, 1, kIntDoubleTypes4),
sig_i_dd(1, 2, kIntDoubleTypes4),
sig_i_a(1, 1, kIntAnyRefTypes4),
sig_i_aa(1, 2, kIntAnyRefTypes4),
sig_i_a(1, 1, kIntExternRefTypes4),
sig_i_aa(1, 2, kIntExternRefTypes4),
sig_i_c(1, 1, kIntFuncRefTypes4),
sig_i_s(1, 1, kIntSimd128Types4),
sig_l_v(1, 0, kLongTypes4),
......@@ -37,15 +37,15 @@ class TestSignatures {
sig_f_ff(1, 2, kFloatTypes4),
sig_d_d(1, 1, kDoubleTypes4),
sig_d_dd(1, 2, kDoubleTypes4),
sig_a_v(1, 0, kAnyRefTypes4),
sig_a_v(1, 0, kExternRefTypes4),
sig_c_v(1, 0, kFuncTypes4),
sig_a_a(1, 1, kAnyRefTypes4),
sig_a_a(1, 1, kExternRefTypes4),
sig_c_c(1, 1, kFuncTypes4),
sig_v_v(0, 0, kIntTypes4),
sig_v_i(0, 1, kIntTypes4),
sig_v_ii(0, 2, kIntTypes4),
sig_v_iii(0, 3, kIntTypes4),
sig_v_a(0, 1, kAnyRefTypes4),
sig_v_a(0, 1, kExternRefTypes4),
sig_v_c(0, 1, kFuncTypes4),
sig_v_d(0, 1, kDoubleTypes4),
sig_s_i(1, 1, kSimd128IntTypes4),
......@@ -58,12 +58,12 @@ class TestSignatures {
for (int i = 0; i < 4; i++) kLongTypes4[i] = kWasmI64;
for (int i = 0; i < 4; i++) kFloatTypes4[i] = kWasmF32;
for (int i = 0; i < 4; i++) kDoubleTypes4[i] = kWasmF64;
for (int i = 0; i < 4; i++) kAnyRefTypes4[i] = kWasmAnyRef;
for (int i = 0; i < 4; i++) kExternRefTypes4[i] = kWasmExternRef;
for (int i = 0; i < 4; i++) kFuncTypes4[i] = kWasmFuncRef;
for (int i = 1; i < 4; i++) kIntLongTypes4[i] = kWasmI64;
for (int i = 1; i < 4; i++) kIntFloatTypes4[i] = kWasmF32;
for (int i = 1; i < 4; i++) kIntDoubleTypes4[i] = kWasmF64;
for (int i = 1; i < 4; i++) kIntAnyRefTypes4[i] = kWasmAnyRef;
for (int i = 1; i < 4; i++) kIntExternRefTypes4[i] = kWasmExternRef;
for (int i = 1; i < 4; i++) kIntFuncRefTypes4[i] = kWasmFuncRef;
for (int i = 0; i < 4; i++) kSimd128Types4[i] = kWasmS128;
for (int i = 1; i < 4; i++) kIntSimd128Types4[i] = kWasmS128;
......@@ -71,7 +71,7 @@ class TestSignatures {
kIntLongTypes4[0] = kWasmI32;
kIntFloatTypes4[0] = kWasmI32;
kIntDoubleTypes4[0] = kWasmI32;
kIntAnyRefTypes4[0] = kWasmI32;
kIntExternRefTypes4[0] = kWasmI32;
kIntFuncRefTypes4[0] = kWasmI32;
kIntSimd128Types4[0] = kWasmI32;
kSimd128IntTypes4[1] = kWasmI32;
......@@ -134,12 +134,12 @@ class TestSignatures {
ValueType kLongTypes4[4];
ValueType kFloatTypes4[4];
ValueType kDoubleTypes4[4];
ValueType kAnyRefTypes4[4];
ValueType kExternRefTypes4[4];
ValueType kFuncTypes4[4];
ValueType kIntLongTypes4[4];
ValueType kIntFloatTypes4[4];
ValueType kIntDoubleTypes4[4];
ValueType kIntAnyRefTypes4[4];
ValueType kIntExternRefTypes4[4];
ValueType kIntFuncRefTypes4[4];
ValueType kSimd128Types4[4];
ValueType kIntSimd128Types4[4];
......
......@@ -208,7 +208,7 @@
#define WASM_SELECT_D(tval, fval, cond) \
tval, fval, cond, kExprSelectWithType, U32V_1(1), kF64Code
#define WASM_SELECT_R(tval, fval, cond) \
tval, fval, cond, kExprSelectWithType, U32V_1(1), kAnyRefCode
tval, fval, cond, kExprSelectWithType, U32V_1(1), kExternRefCode
#define WASM_SELECT_A(tval, fval, cond) \
tval, fval, cond, kExprSelectWithType, U32V_1(1), kFuncRefCode
......
......@@ -238,6 +238,8 @@ std::string HeapTypeToJSByteEncoding(HeapType heap_type) {
return "kArrayRefCode";
case HeapType::kAny:
return "kAnyRefCode";
case HeapType::kExtern:
return "kExternRefCode";
case HeapType::kBottom:
UNREACHABLE();
default:
......@@ -257,6 +259,8 @@ std::string HeapTypeToConstantName(HeapType heap_type) {
return "kWasmDataRef";
case HeapType::kArray:
return "kWasmArrayRef";
case HeapType::kExtern:
return "kWasmExternRef";
case HeapType::kAny:
return "kWasmAnyRef";
case HeapType::kBottom:
......@@ -288,6 +292,8 @@ std::string ValueTypeToConstantName(ValueType type) {
return "kWasmFuncRef";
case HeapType::kEq:
return "kWasmEqRef";
case HeapType::kExtern:
return "kWasmExternRef";
case HeapType::kAny:
return "kWasmAnyRef";
case HeapType::kBottom:
......
......@@ -6,6 +6,7 @@
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
/* TODO(7748): Re-enable these tests once any ref tables are supported.
(function TestArrayNewElemStatic() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
......@@ -158,6 +159,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
assertTraps(kTrapNullDereference, () => table_get(0, 2));
assertTraps(kTrapArrayOutOfBounds, () => table_get(0, 3));
})();
*/
(function TestArrayNewElemStaticMistypedSegment() {
print(arguments.callee.name);
......@@ -208,6 +210,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
/invalid element segment index/);
})();
/* TODO(7748): Re-enable these tests once any ref tables are supported.
(function TestArrayNewElemStaticConstantArrayTooLarge() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
......@@ -326,3 +329,4 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
// An active segment counts as having 0 length.
assertTraps(kTrapElementSegmentOutOfBounds, () => instance.exports.init());
})();
*/
......@@ -143,6 +143,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
assertEquals(22, instance.exports.table_test(1, 33, 11));
})();
/* TODO(7748): Re-enable this test once any ref tables are supported.
(function TestAnyRefTable() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
......@@ -206,3 +207,4 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
assertEquals(10, instance.exports.struct_getter());
assertEquals(1, instance.exports.null_getter());
})();
*/
......@@ -53,7 +53,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function testGenericWrapper1ParamTrap() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32], [kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmI32], [kWasmExternRef]);
let sig_index = builder.addType(sig);
builder.addFunction("main", sig_index)
.addBody([
......@@ -69,7 +69,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function testGenericWrapper1ParamGeneral() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32], [kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmI32], [kWasmExternRef]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -96,7 +96,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function testGenericWrapper1ParamNotSmi() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32], [kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmI32], [kWasmExternRef]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -124,8 +124,8 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function testGenericWrapper4Param() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32, kWasmI32],
[kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmI32, kWasmI32, kWasmI32, kWasmI32],
[kWasmExternRef]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -166,8 +166,8 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(60, x);
})();
let kSig_r_riiiiiiii = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32,
kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32], [kWasmAnyRef]);
let kSig_r_riiiiiiii = makeSig([kWasmExternRef, kWasmI32, kWasmI32, kWasmI32,
kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32], [kWasmExternRef]);
(function testGenericWrapper8Param() {
print(arguments.callee.name);
......@@ -212,8 +212,8 @@ let kSig_r_riiiiiiii = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32,
(function testGenericWrapper4ParamWithLessParams() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32, kWasmI32],
[kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmI32, kWasmI32, kWasmI32, kWasmI32],
[kWasmExternRef]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -245,8 +245,8 @@ let kSig_r_riiiiiiii = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32,
(function testGenericWrapper4ParamWithMoreParams() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32, kWasmI32],
[kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmI32, kWasmI32, kWasmI32, kWasmI32],
[kWasmExternRef]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -278,7 +278,7 @@ let kSig_r_riiiiiiii = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32,
(function testGenericWrapper1I32ReturnSmi() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32], [kWasmI32]);
let sig = makeSig([kWasmExternRef, kWasmI32], [kWasmI32]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -304,7 +304,7 @@ let kSig_r_riiiiiiii = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32,
(function testGenericWrapper1I32ReturnHeapNumber() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32], [kWasmI32]);
let sig = makeSig([kWasmExternRef, kWasmI32], [kWasmI32]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -328,7 +328,7 @@ let kSig_r_riiiiiiii = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32,
assertEquals(2147483645, main(5));
})();
let kSig_i_rlili = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI64, kWasmI32],
let kSig_i_rlili = makeSig([kWasmExternRef, kWasmI64, kWasmI32, kWasmI64, kWasmI32],
[kWasmI32]);
(function testGenericWrapper4IParam1I32Ret() {
......@@ -361,8 +361,8 @@ let kSig_i_rlili = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI64, kWasmI32]
assertEquals(60, main(9n, param2, param3, 0));
})();
let kSig_r_riiili = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32, kWasmI64,
kWasmI32], [kWasmAnyRef]);
let kSig_r_riiili = makeSig([kWasmExternRef, kWasmI32, kWasmI32, kWasmI32, kWasmI64,
kWasmI32], [kWasmExternRef]);
(function testGenericWrapper5IParam() {
print(arguments.callee.name);
......@@ -396,8 +396,8 @@ let kSig_r_riiili = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32, kWasmI64
assertEquals(72, x);
})();
let kSig_r_riiilii = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32,
kWasmI64, kWasmI32, kWasmI32], [kWasmAnyRef]);
let kSig_r_riiilii = makeSig([kWasmExternRef, kWasmI32, kWasmI32, kWasmI32,
kWasmI64, kWasmI32, kWasmI32], [kWasmExternRef]);
(function testGenericWrapper6IParam() {
print(arguments.callee.name);
......@@ -433,7 +433,7 @@ let kSig_r_riiilii = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32,
assertEquals(93, x);
})();
let kSig_r_rliilliiil = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI32,
let kSig_r_rliilliiil = makeSig([kWasmExternRef, kWasmI64, kWasmI32, kWasmI32,
kWasmI64, kWasmI64, kWasmI32, kWasmI32, kWasmI32, kWasmI64], [kWasmI32]);
(function testGenericWrapper9IParam132Ret() {
......@@ -479,7 +479,7 @@ let kSig_r_rliilliiil = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI32,
(function testGenericWrapperTypeError() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI64], [kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmI64], [kWasmExternRef]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -504,7 +504,7 @@ let kSig_r_rliilliiil = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI32,
(function testGenericWrapper1I64Return() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef], [kWasmI64]);
let sig = makeSig([kWasmExternRef], [kWasmI64]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -528,7 +528,7 @@ let kSig_r_rliilliiil = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI32,
(function testGenericWrapper1F32Return() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef], [kWasmF32]);
let sig = makeSig([kWasmExternRef], [kWasmF32]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -552,7 +552,7 @@ let kSig_r_rliilliiil = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI32,
(function testGenericWrapper1F64Return() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef], [kWasmF64]);
let sig = makeSig([kWasmExternRef], [kWasmF64]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -576,7 +576,7 @@ let kSig_r_rliilliiil = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI32,
(function testGenericWrapper1Float32() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmF32], [kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmF32], [kWasmExternRef]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -603,7 +603,7 @@ let kSig_r_rliilliiil = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI32,
(function testGenericWrapper1Float64() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmF64], [kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmF64], [kWasmExternRef]);
let sig_index = builder.addType(sig);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
......@@ -627,8 +627,8 @@ let kSig_r_rliilliiil = makeSig([kWasmAnyRef, kWasmI64, kWasmI32, kWasmI32,
assertEquals(25, x);
})();
let kSig_r_rffddddff = makeSig([kWasmAnyRef, kWasmF32, kWasmF32, kWasmF64,
kWasmF64, kWasmF64, kWasmF64, kWasmF32, kWasmF32], [kWasmAnyRef]);
let kSig_r_rffddddff = makeSig([kWasmExternRef, kWasmF32, kWasmF32, kWasmF64,
kWasmF64, kWasmF64, kWasmF64, kWasmF32, kWasmF32], [kWasmExternRef]);
(function testGenericWrapper8Floats() {
print(arguments.callee.name);
......@@ -670,9 +670,9 @@ let kSig_r_rffddddff = makeSig([kWasmAnyRef, kWasmF32, kWasmF32, kWasmF64,
assertEquals(234, x);
})();
let kSig_r_riiliffddlfdff = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI64,
let kSig_r_riiliffddlfdff = makeSig([kWasmExternRef, kWasmI32, kWasmI32, kWasmI64,
kWasmI32, kWasmF32, kWasmF32, kWasmF64, kWasmF64, kWasmI64, kWasmF32,
kWasmF64, kWasmF32, kWasmF32], [kWasmAnyRef]);
kWasmF64, kWasmF32, kWasmF32], [kWasmExternRef]);
// Floats don't fit into param registers.
(function testGenericWrapper13ParamMix() {
print(arguments.callee.name);
......@@ -719,9 +719,9 @@ let kSig_r_riiliffddlfdff = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI64,
assertEquals(223, y);
})();
let kSig_r_riiliiiffddli = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI64,
let kSig_r_riiliiiffddli = makeSig([kWasmExternRef, kWasmI32, kWasmI32, kWasmI64,
kWasmI32, kWasmI32, kWasmI32, kWasmF32, kWasmF32, kWasmF64, kWasmF64,
kWasmI64, kWasmI32], [kWasmAnyRef]);
kWasmI64, kWasmI32], [kWasmExternRef]);
// Integers don't fit into param registers.
(function testGenericWrapper12ParamMix() {
print(arguments.callee.name);
......@@ -770,7 +770,7 @@ let kSig_r_riiliiiffddli = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI64,
assertEquals(13, y);
})();
let kSig_f_riiliiiffddlifffdi = makeSig([kWasmAnyRef, kWasmI32, kWasmI32,
let kSig_f_riiliiiffddlifffdi = makeSig([kWasmExternRef, kWasmI32, kWasmI32,
kWasmI64, kWasmI32, kWasmI32, kWasmI32, kWasmF32, kWasmF32, kWasmF64,
kWasmF64, kWasmI64, kWasmI32, kWasmF32, kWasmF32, kWasmF32, kWasmF64,
kWasmI32], [kWasmF32]);
......@@ -869,7 +869,7 @@ let kSig_f_riiliiiffddlifffdi = makeSig([kWasmAnyRef, kWasmI32, kWasmI32,
(function testDeoptWithIncorrectNumberOfParams() {
print(arguments.callee.name);
const builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32, kWasmI32], [kWasmAnyRef]);
let sig = makeSig([kWasmExternRef, kWasmI32, kWasmI32], [kWasmExternRef]);
let sig_index = builder.addType(sig);
let imp = builder.addImport('q', 'func', sig_index);
builder.addFunction('main', sig_index)
......@@ -901,7 +901,7 @@ let kSig_f_riiliiiffddlifffdi = makeSig([kWasmAnyRef, kWasmI32, kWasmI32,
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig_r_rddrrrrrrddddd = builder.addType(makeSig(
[kWasmAnyRef, kWasmF64, kWasmF64, kWasmExternRef, kWasmExternRef,
[kWasmExternRef, kWasmF64, kWasmF64, kWasmExternRef, kWasmExternRef,
kWasmExternRef, kWasmExternRef, kWasmExternRef, kWasmExternRef, kWasmF64,
kWasmF64, kWasmF64, kWasmF64, kWasmF64],
[kWasmExternRef]));
......
......@@ -209,7 +209,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestStackSwitchGC2() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32], [kWasmI32]);
let sig = makeSig([kWasmExternRef, kWasmI32], [kWasmI32]);
let import_index = builder.addImport('m', 'import', sig);
builder.addFunction("test", sig)
.addBody([
......@@ -260,7 +260,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
}
let builder = new WasmModuleBuilder();
// Number of param registers + 1 for both types.
let sig = makeSig([kWasmAnyRef, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32,
let sig = makeSig([kWasmExternRef, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32,
kWasmF32, kWasmF32, kWasmF32, kWasmF32, kWasmF32, kWasmF32, kWasmF32], [kWasmI32]);
import_index = builder.addImport('m', 'import', sig);
builder.addFunction("test", sig)
......@@ -292,7 +292,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestStackSwitchReturnFloat() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef], [kWasmF32]);
let sig = makeSig([kWasmExternRef], [kWasmF32]);
import_index = builder.addImport('m', 'import', sig);
builder.addFunction("test", sig)
.addBody([
......
......@@ -119,8 +119,8 @@ let kWasmI16 = 0x79;
// indices.
let kWasmFuncRef = -0x10;
let kWasmAnyFunc = kWasmFuncRef; // Alias named as in the JS API spec
let kWasmAnyRef = -0x11;
let kWasmExternRef = kWasmAnyRef; // Alias for test backwards compatibility.
let kWasmExternRef = -0x11;
let kWasmAnyRef = -0x12;
let kWasmEqRef = -0x13;
let kWasmI31Ref = -0x16;
let kWasmDataRef = -0x19;
......
......@@ -49,7 +49,7 @@ static const byte kCodeSetLocal0[] = {WASM_LOCAL_SET(0, WASM_ZERO)};
static const byte kCodeTeeLocal0[] = {WASM_LOCAL_TEE(0, WASM_ZERO)};
static const ValueType kValueTypes[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64,
kWasmAnyRef};
kWasmExternRef};
static const MachineType machineTypes[] = {
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
......@@ -1934,7 +1934,7 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs2) {
"call_indirect: Immediate signature #1 is not a subtype of "
"immediate table #0");
byte non_function_table_index = builder.InitializeTable(kWasmAnyRef);
byte non_function_table_index = builder.InitializeTable(kWasmExternRef);
ExpectFailure(
sigs.i_v(),
{WASM_CALL_INDIRECT_TABLE(non_function_table_index, table_type_index,
......@@ -2176,14 +2176,14 @@ TEST_F(FunctionBodyDecoderTest, TableSet) {
WASM_FEATURE_SCOPE(typed_funcref);
byte tab_type = builder.AddSignature(sigs.i_i());
byte tab_ref1 = builder.AddTable(kWasmAnyRef, 10, true, 20);
byte tab_ref1 = builder.AddTable(kWasmExternRef, 10, true, 20);
byte tab_func1 = builder.AddTable(kWasmFuncRef, 20, true, 30);
byte tab_func2 = builder.AddTable(kWasmFuncRef, 10, false, 20);
byte tab_ref2 = builder.AddTable(kWasmAnyRef, 10, false, 20);
byte tab_ref2 = builder.AddTable(kWasmExternRef, 10, false, 20);
byte tab_typed_func =
builder.AddTable(ValueType::RefNull(tab_type), 10, false, 20);
ValueType sig_types[]{kWasmAnyRef, kWasmFuncRef, kWasmI32,
ValueType sig_types[]{kWasmExternRef, kWasmFuncRef, kWasmI32,
ValueType::Ref(tab_type)};
FunctionSig sig(0, 4, sig_types);
byte local_ref = 0;
......@@ -2232,14 +2232,14 @@ TEST_F(FunctionBodyDecoderTest, TableGet) {
WASM_FEATURE_SCOPE(typed_funcref);
byte tab_type = builder.AddSignature(sigs.i_i());
byte tab_ref1 = builder.AddTable(kWasmAnyRef, 10, true, 20);
byte tab_ref1 = builder.AddTable(kWasmExternRef, 10, true, 20);
byte tab_func1 = builder.AddTable(kWasmFuncRef, 20, true, 30);
byte tab_func2 = builder.AddTable(kWasmFuncRef, 10, false, 20);
byte tab_ref2 = builder.AddTable(kWasmAnyRef, 10, false, 20);
byte tab_ref2 = builder.AddTable(kWasmExternRef, 10, false, 20);
byte tab_typed_func =
builder.AddTable(ValueType::RefNull(tab_type), 10, false, 20);
ValueType sig_types[]{kWasmAnyRef, kWasmFuncRef, kWasmI32,
ValueType sig_types[]{kWasmExternRef, kWasmFuncRef, kWasmI32,
ValueType::RefNull(tab_type)};
FunctionSig sig(0, 4, sig_types);
byte local_ref = 0;
......@@ -2296,10 +2296,10 @@ TEST_F(FunctionBodyDecoderTest, TableGet) {
}
TEST_F(FunctionBodyDecoderTest, MultiTableCallIndirect) {
byte tab_ref = builder.AddTable(kWasmAnyRef, 10, true, 20);
byte tab_ref = builder.AddTable(kWasmExternRef, 10, true, 20);
byte tab_func = builder.AddTable(kWasmFuncRef, 20, true, 30);
ValueType sig_types[]{kWasmAnyRef, kWasmFuncRef, kWasmI32};
ValueType sig_types[]{kWasmExternRef, kWasmFuncRef, kWasmI32};
FunctionSig sig(0, 3, sig_types);
byte sig_index = builder.AddSignature(sigs.i_v());
......@@ -2864,7 +2864,7 @@ TEST_F(FunctionBodyDecoderTest, Select_fail2) {
ValueType type = kValueTypes[i];
if (type == kWasmI32) continue;
// Select without specified type is only allowed for number types.
if (type == kWasmAnyRef) continue;
if (type == kWasmExternRef) continue;
ValueType types[] = {type, kWasmI32, type};
FunctionSig sig(1, 2, types);
......@@ -2904,8 +2904,8 @@ TEST_F(FunctionBodyDecoderTest, SelectWithType) {
ExpectValidates(sigs.l_l(),
{WASM_SELECT_L(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)});
ExpectValidates(sigs.a_a(),
{WASM_SELECT_R(WASM_REF_NULL(kAnyRefCode),
WASM_REF_NULL(kAnyRefCode), WASM_ZERO)});
{WASM_SELECT_R(WASM_REF_NULL(kExternRefCode),
WASM_REF_NULL(kExternRefCode), WASM_ZERO)});
ExpectValidates(sigs.c_c(),
{WASM_SELECT_A(WASM_REF_NULL(kFuncRefCode),
WASM_REF_NULL(kFuncRefCode), WASM_ZERO)});
......@@ -3344,7 +3344,8 @@ TEST_F(FunctionBodyDecoderTest, TableInit) {
TEST_F(FunctionBodyDecoderTest, TableInitWrongType) {
uint32_t table_index = builder.InitializeTable(wasm::kWasmFuncRef);
uint32_t element_index = builder.AddPassiveElementSegment(wasm::kWasmAnyRef);
uint32_t element_index =
builder.AddPassiveElementSegment(wasm::kWasmExternRef);
ExpectFailure(sigs.v_v(), {WASM_TABLE_INIT(table_index, element_index,
WASM_ZERO, WASM_ZERO, WASM_ZERO)});
}
......@@ -3419,21 +3420,21 @@ TEST_F(FunctionBodyDecoderTest, TableCopy) {
TEST_F(FunctionBodyDecoderTest, TableCopyWrongType) {
uint32_t dst_table_index = builder.InitializeTable(wasm::kWasmFuncRef);
uint32_t src_table_index = builder.InitializeTable(wasm::kWasmAnyRef);
uint32_t src_table_index = builder.InitializeTable(wasm::kWasmExternRef);
ExpectFailure(sigs.v_v(), {WASM_TABLE_COPY(dst_table_index, src_table_index,
WASM_ZERO, WASM_ZERO, WASM_ZERO)});
}
TEST_F(FunctionBodyDecoderTest, TableGrow) {
byte tab_func = builder.AddTable(kWasmFuncRef, 10, true, 20);
byte tab_ref = builder.AddTable(kWasmAnyRef, 10, true, 20);
byte tab_ref = builder.AddTable(kWasmExternRef, 10, true, 20);
ExpectValidates(
sigs.i_c(),
{WASM_TABLE_GROW(tab_func, WASM_REF_NULL(kFuncRefCode), WASM_ONE)});
ExpectValidates(
sigs.i_a(),
{WASM_TABLE_GROW(tab_ref, WASM_REF_NULL(kAnyRefCode), WASM_ONE)});
{WASM_TABLE_GROW(tab_ref, WASM_REF_NULL(kExternRefCode), WASM_ONE)});
// FuncRef table cannot be initialized with an ExternRef value.
ExpectFailure(sigs.i_a(),
{WASM_TABLE_GROW(tab_func, WASM_LOCAL_GET(0), WASM_ONE)});
......@@ -3443,7 +3444,7 @@ TEST_F(FunctionBodyDecoderTest, TableGrow) {
// Check that the table index gets verified.
ExpectFailure(
sigs.i_a(),
{WASM_TABLE_GROW(tab_ref + 2, WASM_REF_NULL(kAnyRefCode), WASM_ONE)});
{WASM_TABLE_GROW(tab_ref + 2, WASM_REF_NULL(kExternRefCode), WASM_ONE)});
}
TEST_F(FunctionBodyDecoderTest, TableSize) {
......@@ -3454,13 +3455,13 @@ TEST_F(FunctionBodyDecoderTest, TableSize) {
TEST_F(FunctionBodyDecoderTest, TableFill) {
byte tab_func = builder.AddTable(kWasmFuncRef, 10, true, 20);
byte tab_ref = builder.AddTable(kWasmAnyRef, 10, true, 20);
byte tab_ref = builder.AddTable(kWasmExternRef, 10, true, 20);
ExpectValidates(sigs.v_c(),
{WASM_TABLE_FILL(tab_func, WASM_ONE,
WASM_REF_NULL(kFuncRefCode), WASM_ONE)});
ExpectValidates(sigs.v_a(),
{WASM_TABLE_FILL(tab_ref, WASM_ONE,
WASM_REF_NULL(kAnyRefCode), WASM_ONE)});
WASM_REF_NULL(kExternRefCode), WASM_ONE)});
// FuncRef table cannot be initialized with an ExternRef value.
ExpectFailure(sigs.v_a(), {WASM_TABLE_FILL(tab_func, WASM_ONE,
WASM_LOCAL_GET(0), WASM_ONE)});
......@@ -3470,16 +3471,16 @@ TEST_F(FunctionBodyDecoderTest, TableFill) {
// Check that the table index gets verified.
ExpectFailure(sigs.v_a(),
{WASM_TABLE_FILL(tab_ref + 2, WASM_ONE,
WASM_REF_NULL(kAnyRefCode), WASM_ONE)});
WASM_REF_NULL(kExternRefCode), WASM_ONE)});
}
TEST_F(FunctionBodyDecoderTest, TableOpsWithoutTable) {
ExpectFailure(sigs.i_v(),
{WASM_TABLE_GROW(0, WASM_REF_NULL(kAnyRefCode), WASM_ONE)});
{WASM_TABLE_GROW(0, WASM_REF_NULL(kExternRefCode), WASM_ONE)});
ExpectFailure(sigs.i_v(), {WASM_TABLE_SIZE(0)});
ExpectFailure(
sigs.i_a(),
{WASM_TABLE_FILL(0, WASM_ONE, WASM_REF_NULL(kAnyRefCode), WASM_ONE)});
{WASM_TABLE_FILL(0, WASM_ONE, WASM_REF_NULL(kExternRefCode), WASM_ONE)});
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
ExpectFailure(sigs.v_v(),
{WASM_TABLE_INIT(0, 0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
......@@ -3490,7 +3491,7 @@ TEST_F(FunctionBodyDecoderTest, TableOpsWithoutTable) {
TEST_F(FunctionBodyDecoderTest, TableCopyMultiTable) {
{
TestModuleBuilder builder;
builder.AddTable(kWasmAnyRef, 10, true, 20);
builder.AddTable(kWasmExternRef, 10, true, 20);
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
module = builder.module();
// We added one table, therefore table.copy on table 0 should work.
......@@ -3511,8 +3512,8 @@ TEST_F(FunctionBodyDecoderTest, TableCopyMultiTable) {
}
{
TestModuleBuilder builder;
builder.AddTable(kWasmAnyRef, 10, true, 20);
builder.AddTable(kWasmAnyRef, 10, true, 20);
builder.AddTable(kWasmExternRef, 10, true, 20);
builder.AddTable(kWasmExternRef, 10, true, 20);
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
module = builder.module();
// We added two tables, therefore table.copy on table 0 should work.
......@@ -3538,8 +3539,8 @@ TEST_F(FunctionBodyDecoderTest, TableCopyMultiTable) {
TEST_F(FunctionBodyDecoderTest, TableInitMultiTable) {
{
TestModuleBuilder builder;
builder.AddTable(kWasmAnyRef, 10, true, 20);
builder.AddPassiveElementSegment(wasm::kWasmAnyRef);
builder.AddTable(kWasmExternRef, 10, true, 20);
builder.AddPassiveElementSegment(wasm::kWasmExternRef);
module = builder.module();
// We added one table, therefore table.init on table 0 should work.
int table_index = 0;
......@@ -3552,9 +3553,9 @@ TEST_F(FunctionBodyDecoderTest, TableInitMultiTable) {
}
{
TestModuleBuilder builder;
builder.AddTable(kWasmAnyRef, 10, true, 20);
builder.AddTable(kWasmAnyRef, 10, true, 20);
builder.AddPassiveElementSegment(wasm::kWasmAnyRef);
builder.AddTable(kWasmExternRef, 10, true, 20);
builder.AddTable(kWasmExternRef, 10, true, 20);
builder.AddPassiveElementSegment(wasm::kWasmExternRef);
module = builder.module();
// We added two tables, therefore table.init on table 0 should work.
int table_index = 0;
......@@ -3624,7 +3625,7 @@ TEST_F(FunctionBodyDecoderTest, StructNewDefault) {
TEST_F(FunctionBodyDecoderTest, DefaultableLocal) {
WASM_FEATURE_SCOPE(typed_funcref);
AddLocals(kWasmAnyRef, 1);
AddLocals(kWasmExternRef, 1);
ExpectValidates(sigs.v_v(), {});
}
......@@ -3726,7 +3727,9 @@ TEST_F(FunctionBodyDecoderTest, RefEq) {
kWasmF64,
kWasmS128,
kWasmFuncRef,
kWasmExternRef,
kWasmAnyRef,
ValueType::Ref(HeapType::kExtern),
ValueType::Ref(HeapType::kAny),
ValueType::Ref(HeapType::kFunc)};
......@@ -3759,8 +3762,9 @@ TEST_F(FunctionBodyDecoderTest, RefAsNonNull) {
byte struct_type_index = builder.AddStruct({F(kWasmI32, true)});
byte array_type_index = builder.AddArray(kWasmI32, true);
uint32_t heap_types[] = {struct_type_index, array_type_index, HeapType::kFunc,
HeapType::kEq, HeapType::kAny, HeapType::kI31};
uint32_t heap_types[] = {
struct_type_index, array_type_index, HeapType::kFunc, HeapType::kEq,
HeapType::kExtern, HeapType::kAny, HeapType::kI31};
ValueType non_compatible_types[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64,
kWasmS128};
......@@ -3796,9 +3800,9 @@ TEST_F(FunctionBodyDecoderTest, RefNull) {
byte struct_type_index = builder.AddStruct({F(kWasmI32, true)});
byte array_type_index = builder.AddArray(kWasmI32, true);
uint32_t type_reprs[] = {struct_type_index, array_type_index, HeapType::kFunc,
HeapType::kEq, HeapType::kAny, HeapType::kI31,
HeapType::kNone};
uint32_t type_reprs[] = {
struct_type_index, array_type_index, HeapType::kFunc, HeapType::kEq,
HeapType::kExtern, HeapType::kAny, HeapType::kI31, HeapType::kNone};
// It works with heap types.
for (uint32_t type_repr : type_reprs) {
const ValueType type = ValueType::RefNull(type_repr);
......@@ -3815,15 +3819,17 @@ TEST_F(FunctionBodyDecoderTest, RefIsNull) {
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(gc);
ExpectValidates(sigs.i_i(), {WASM_REF_IS_NULL(WASM_REF_NULL(kAnyRefCode))});
ExpectValidates(sigs.i_i(),
{WASM_REF_IS_NULL(WASM_REF_NULL(kExternRefCode))});
ExpectFailure(
sigs.i_i(), {WASM_REF_IS_NULL(WASM_LOCAL_GET(0))}, kAppendEnd,
"ref.is_null[0] expected reference type, found local.get of type i32");
byte struct_type_index = builder.AddStruct({F(kWasmI32, true)});
byte array_type_index = builder.AddArray(kWasmI32, true);
uint32_t heap_types[] = {struct_type_index, array_type_index, HeapType::kFunc,
HeapType::kEq, HeapType::kAny, HeapType::kI31};
uint32_t heap_types[] = {
struct_type_index, array_type_index, HeapType::kFunc, HeapType::kEq,
HeapType::kExtern, HeapType::kAny, HeapType::kI31};
for (uint32_t heap_type : heap_types) {
const ValueType types[] = {kWasmI32, ValueType::RefNull(heap_type)};
......@@ -4035,7 +4041,7 @@ TEST_F(FunctionBodyDecoderTest, GCArray) {
"(need 3, got 2)");
// Mistyped initializer.
ExpectFailure(&sig_r_v,
{WASM_ARRAY_NEW(array_type_index, WASM_REF_NULL(kAnyRefCode),
{WASM_ARRAY_NEW(array_type_index, WASM_REF_NULL(kExternRefCode),
WASM_I32V(10))},
kAppendEnd,
"array.new[0] expected type funcref, found ref.null "
......@@ -4256,7 +4262,8 @@ TEST_F(FunctionBodyDecoderTest, RefTestCast) {
std::make_tuple(array_heap, sub_struct_heap, true),
std::make_tuple(super_struct_heap, func_heap_1, true),
std::make_tuple(HeapType::kEq, super_struct_heap, false),
std::make_tuple(HeapType::kAny, func_heap_1, false),
std::make_tuple(HeapType::kExtern, func_heap_1, false),
std::make_tuple(HeapType::kAny, array_heap, false),
std::make_tuple(HeapType::kI31, array_heap, false)};
for (auto test : tests) {
......@@ -4353,17 +4360,17 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
"type error in branch[0] (expected i32, got (ref null 0))");
// Argument type error.
ExpectFailure(FunctionSig::Build(this->zone(), {subtype}, {kWasmAnyRef}),
ExpectFailure(FunctionSig::Build(this->zone(), {subtype}, {kWasmExternRef}),
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC(0, sub_struct),
WASM_GC_OP(kExprRefCastStatic), sub_struct},
kAppendEnd,
"br_on_cast_static[0] expected subtype of (ref null func) or "
"(ref null data), found local.get of type anyref");
ExpectFailure(FunctionSig::Build(this->zone(), {supertype}, {kWasmAnyRef}),
"(ref null data), found local.get of type externref");
ExpectFailure(FunctionSig::Build(this->zone(), {supertype}, {kWasmExternRef}),
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC_FAIL(0, sub_struct)},
kAppendEnd,
"br_on_cast_static_fail[0] expected subtype of (ref null func) "
"or (ref null data), found local.get of type anyref");
"or (ref null data), found local.get of type externref");
}
TEST_F(FunctionBodyDecoderTest, BrOnAbstractType) {
......
......@@ -29,7 +29,7 @@ namespace module_decoder_unittest {
#define WASM_INIT_EXPR_F32(val) WASM_F32(val), kExprEnd
#define WASM_INIT_EXPR_I64(val) WASM_I64(val), kExprEnd
#define WASM_INIT_EXPR_F64(val) WASM_F64(val), kExprEnd
#define WASM_INIT_EXPR_EXTERN_REF_NULL WASM_REF_NULL(kAnyRefCode), kExprEnd
#define WASM_INIT_EXPR_EXTERN_REF_NULL WASM_REF_NULL(kExternRefCode), kExprEnd
#define WASM_INIT_EXPR_FUNC_REF_NULL WASM_REF_NULL(kFuncRefCode), kExprEnd
#define WASM_INIT_EXPR_REF_FUNC(val) WASM_REF_FUNC(val), kExprEnd
#define WASM_INIT_EXPR_GLOBAL(index) WASM_GLOBAL_GET(index), kExprEnd
......@@ -182,12 +182,13 @@ struct ValueTypePair {
uint8_t code;
ValueType type;
} kValueTypes[] = {
{kI32Code, kWasmI32}, // --
{kI64Code, kWasmI64}, // --
{kF32Code, kWasmF32}, // --
{kF64Code, kWasmF64}, // --
{kFuncRefCode, kWasmFuncRef}, // --
{kAnyRefCode, kWasmAnyRef}, // --
// TODO(mliedtke): Cover other value types as well.
{kI32Code, kWasmI32}, // --
{kI64Code, kWasmI64}, // --
{kF32Code, kWasmF32}, // --
{kF64Code, kWasmF64}, // --
{kFuncRefCode, kWasmFuncRef}, // --
{kExternRefCode, kWasmExternRef}, // --
};
class WasmModuleVerifyTest : public TestWithIsolateAndZone {
......@@ -306,7 +307,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobal) {
TWO_EMPTY_FUNCTIONS(SIG_INDEX(0)),
SECTION(Global, // --
ENTRY_COUNT(2), // --
kAnyRefCode, // local type
kExternRefCode, // local type
0, // immutable
WASM_INIT_EXPR_EXTERN_REF_NULL, // init
kFuncRefCode, // local type
......@@ -333,7 +334,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobal) {
EXPECT_EQ(0u, result.value()->data_segments.size());
const WasmGlobal* global = &result.value()->globals[0];
EXPECT_EQ(kWasmAnyRef, global->type);
EXPECT_EQ(kWasmExternRef, global->type);
EXPECT_FALSE(global->mutability);
global = &result.value()->globals[1];
......@@ -407,12 +408,12 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobalWithGlobalInit) {
ADD_COUNT('m'), // module name
ADD_COUNT('f'), // global name
kExternalGlobal, // import kind
kAnyRefCode, // type
kExternRefCode, // type
0), // mutability
SECTION(Global, // --
ENTRY_COUNT(1),
kAnyRefCode, // local type
0, // immutable
kExternRefCode, // local type
0, // immutable
WASM_INIT_EXPR_GLOBAL(0)),
};
......@@ -426,7 +427,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobalWithGlobalInit) {
const WasmGlobal* global = &result.value()->globals.back();
EXPECT_EQ(kWasmAnyRef, global->type);
EXPECT_EQ(kWasmExternRef, global->type);
EXPECT_FALSE(global->mutability);
}
}
......@@ -438,12 +439,12 @@ TEST_F(WasmModuleVerifyTest, NullGlobalWithGlobalInit) {
ADD_COUNT('m'), // module name
ADD_COUNT('n'), // global name
kExternalGlobal, // import kind
kAnyRefCode, // type
kExternRefCode, // type
0), // mutability
SECTION(Global, // --
ENTRY_COUNT(1),
kAnyRefCode, // local type
0, // immutable
kExternRefCode, // local type
0, // immutable
WASM_INIT_EXPR_GLOBAL(0)),
};
......@@ -458,7 +459,7 @@ TEST_F(WasmModuleVerifyTest, NullGlobalWithGlobalInit) {
const WasmGlobal* global = &result.value()->globals.back();
EXPECT_EQ(kWasmAnyRef, global->type);
EXPECT_EQ(kWasmExternRef, global->type);
EXPECT_FALSE(global->mutability);
}
}
......@@ -1812,7 +1813,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionInitExternRefTableWithFuncRef) {
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
// table declaration ---------------------------------------------------
SECTION(Table, ENTRY_COUNT(2), // section header
kAnyRefCode, 0, 5, // table 0
kExternRefCode, 0, 5, // table 0
kFuncRefCode, 0, 9), // table 1
// elements ------------------------------------------------------------
SECTION(Element,
......@@ -1892,7 +1893,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionDontInitExternRefImportedTable) {
ADD_COUNT('m'), // module name
ADD_COUNT('s'), // table name
kExternalTable, // import kind
kAnyRefCode, // elem_type
kExternRefCode, // elem_type
0, // no maximum field
10), // initial size
// funcs ---------------------------------------------------------------
......@@ -2017,7 +2018,7 @@ TEST_F(WasmModuleVerifyTest, MultipleTables) {
kFuncRefCode, // table 1: type
0, // table 1: no maximum
10, // table 1: minimum size
kAnyRefCode, // table 2: type
kExternRefCode, // table 2: type
0, // table 2: no maximum
11), // table 2: minimum size
};
......@@ -2031,7 +2032,7 @@ TEST_F(WasmModuleVerifyTest, MultipleTables) {
EXPECT_EQ(kWasmFuncRef, result.value()->tables[0].type);
EXPECT_EQ(11u, result.value()->tables[1].initial_size);
EXPECT_EQ(kWasmAnyRef, result.value()->tables[1].type);
EXPECT_EQ(kWasmExternRef, result.value()->tables[1].type);
}
TEST_F(WasmModuleVerifyTest, TypedFunctionTable) {
......@@ -2224,7 +2225,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_v) {
Zone zone(&allocator, ZONE_NAME);
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_TRUE(sig != nullptr);
ASSERT_TRUE(sig != nullptr);
EXPECT_EQ(0u, sig->parameter_count());
EXPECT_EQ(0u, sig->return_count());
}
......@@ -2235,7 +2236,8 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
const byte data[] = {SIG_ENTRY_x(ret_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_TRUE(sig != nullptr);
SCOPED_TRACE("Return type " + ret_type.type.name());
ASSERT_TRUE(sig != nullptr);
EXPECT_EQ(0u, sig->parameter_count());
EXPECT_EQ(1u, sig->return_count());
EXPECT_EQ(ret_type.type, sig->GetReturn());
......@@ -2248,7 +2250,8 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
const byte data[] = {SIG_ENTRY_v_x(param_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_TRUE(sig != nullptr);
SCOPED_TRACE("Param type " + param_type.type.name());
ASSERT_TRUE(sig != nullptr);
EXPECT_EQ(1u, sig->parameter_count());
EXPECT_EQ(0u, sig->return_count());
EXPECT_EQ(param_type.type, sig->GetParam(0));
......@@ -2263,7 +2266,8 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_TRUE(sig != nullptr);
SCOPED_TRACE("Param type " + param_type.type.name());
ASSERT_TRUE(sig != nullptr);
EXPECT_EQ(1u, sig->parameter_count());
EXPECT_EQ(1u, sig->return_count());
EXPECT_EQ(param_type.type, sig->GetParam(0));
......@@ -2281,7 +2285,9 @@ TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
SIG_ENTRY_x_xx(kI32Code, p0_type.code, p1_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_TRUE(sig != nullptr);
SCOPED_TRACE("Signature i32(" + p0_type.type.name() + ", " +
p1_type.type.name() + ")");
ASSERT_TRUE(sig != nullptr);
EXPECT_EQ(2u, sig->parameter_count());
EXPECT_EQ(1u, sig->return_count());
EXPECT_EQ(p0_type.type, sig->GetParam(0));
......@@ -2299,7 +2305,9 @@ TEST_F(WasmSignatureDecodeTest, Ok_tt_tt) {
p0_type.code, p1_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
EXPECT_TRUE(sig != nullptr);
SCOPED_TRACE("p0 = " + p0_type.type.name() +
", p1 = " + p1_type.type.name());
ASSERT_TRUE(sig != nullptr);
EXPECT_EQ(2u, sig->parameter_count());
EXPECT_EQ(2u, sig->return_count());
EXPECT_EQ(p0_type.type, sig->GetParam(0));
......@@ -3156,7 +3164,7 @@ TEST_F(WasmModuleVerifyTest, PassiveElementSegmentExternRef) {
// table declaration -----------------------------------------------------
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
// element segments -----------------------------------------------------
SECTION(Element, ENTRY_COUNT(1), PASSIVE_WITH_ELEMENTS, kAnyRefCode,
SECTION(Element, ENTRY_COUNT(1), PASSIVE_WITH_ELEMENTS, kExternRefCode,
U32V_1(0)),
// code ------------------------------------------------------------------
ONE_EMPTY_BODY};
......
......@@ -213,6 +213,9 @@ TEST_F(WasmSubtypingTest, Subtyping) {
SUBTYPE(ref_type, kWasmAnyRef);
// Only anyref is a subtype of anyref.
SUBTYPE_IFF(kWasmAnyRef, ref_type, ref_type == kWasmAnyRef);
// TODO(mliedtke): Improve test coverage for externref.
// Only externref is a subtype of externref.
NOT_SUBTYPE(kWasmExternRef, ref_type);
// Each nullable reference type is a supertype of nullref.
SUBTYPE_IFF(kWasmNullRef, ref_type, ref_type.is_nullable());
// Only nullref is a subtype of nullref.
......
......@@ -22,7 +22,7 @@ TEST_F(WasmCallDescriptorTest, TestExternRefIsGrouped) {
ValueType params[kMaxCount];
for (size_t i = 0; i < kMaxCount; i += 2) {
params[i] = kWasmAnyRef;
params[i] = kWasmExternRef;
EXPECT_TRUE(i + 1 < kMaxCount);
params[i + 1] = kWasmI32;
}
......
......@@ -188,9 +188,9 @@ TEST_F(WasmCapiTest, DirectCallCapiFunction) {
ValType::make(::wasm::ANYREF)));
own<Func> func = Func::make(store(), cpp_sig.get(), PlusOne);
Extern* imports[] = {func.get()};
ValueType wasm_types[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64,
kWasmAnyRef, kWasmI32, kWasmI64, kWasmF32,
kWasmF64, kWasmAnyRef};
ValueType wasm_types[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64,
kWasmExternRef, kWasmI32, kWasmI64, kWasmF32,
kWasmF64, kWasmExternRef};
FunctionSig wasm_sig(5, 5, wasm_types);
int func_index = builder()->AddImport(base::CStrVector("func"), &wasm_sig);
builder()->ExportImportedFunction(base::CStrVector("func"), func_index);
......
......@@ -23,9 +23,9 @@ own<Trap> IdentityCallback(const Val args[], Val results[]) {
} // namespace
TEST_F(WasmCapiTest, HostRef) {
ValueType rr_reps[] = {kWasmAnyRef, kWasmAnyRef};
ValueType ri_reps[] = {kWasmAnyRef, kWasmI32};
ValueType ir_reps[] = {kWasmI32, kWasmAnyRef};
ValueType rr_reps[] = {kWasmExternRef, kWasmExternRef};
ValueType ri_reps[] = {kWasmExternRef, kWasmI32};
ValueType ir_reps[] = {kWasmI32, kWasmExternRef};
// Naming convention: result_params_sig.
FunctionSig r_r_sig(1, 1, rr_reps);
FunctionSig v_r_sig(0, 1, rr_reps);
......@@ -35,9 +35,9 @@ TEST_F(WasmCapiTest, HostRef) {
uint32_t func_index = builder()->AddImport(base::CStrVector("f"), &r_r_sig);
const bool kMutable = true;
uint32_t global_index = builder()->AddExportedGlobal(
kWasmAnyRef, kMutable, WasmInitExpr::RefNullConst(HeapType::kAny),
kWasmExternRef, kMutable, WasmInitExpr::RefNullConst(HeapType::kExtern),
base::CStrVector("global"));
uint32_t table_index = builder()->AddTable(kWasmAnyRef, 10);
uint32_t table_index = builder()->AddTable(kWasmExternRef, 10);
builder()->AddExport(base::CStrVector("table"), kExternalTable, table_index);
byte global_set_code[] = {WASM_GLOBAL_SET(global_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("global.set"), global_set_code,
......
......@@ -35,8 +35,8 @@ void ExpectName(const char* expected, const ::wasm::Name& name) {
TEST_F(WasmCapiTest, Reflect) {
// Create a module exporting a function, a global, a table, and a memory.
byte code[] = {WASM_UNREACHABLE};
ValueType types[] = {kWasmI32, kWasmAnyRef, kWasmI32,
kWasmI64, kWasmF32, kWasmF64};
ValueType types[] = {kWasmI32, kWasmExternRef, kWasmI32,
kWasmI64, kWasmF32, kWasmF64};
FunctionSig sig(2, 4, types);
AddExportedFunction(base::CStrVector(kFuncName), code, sizeof(code), &sig);
......
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