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 { ...@@ -6341,6 +6341,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
// wasm::kRefNull, it's the null object. Either way it's good to go // wasm::kRefNull, it's the null object. Either way it's good to go
// already to JS. // already to JS.
return node; return node;
case wasm::HeapType::kExtern:
case wasm::HeapType::kAny: { case wasm::HeapType::kAny: {
if (!enabled_features_.has_gc()) return node; if (!enabled_features_.has_gc()) return node;
// Wrap {node} in object wrapper if it is an array/struct. // Wrap {node} in object wrapper if it is an array/struct.
...@@ -6543,6 +6544,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6543,6 +6544,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
case wasm::kRef: case wasm::kRef:
case wasm::kRefNull: { case wasm::kRefNull: {
switch (type.heap_representation()) { switch (type.heap_representation()) {
case wasm::HeapType::kExtern:
case wasm::HeapType::kAny: case wasm::HeapType::kAny:
if (!enabled_features_.has_gc()) return input; if (!enabled_features_.has_gc()) return input;
// If this is a wrapper for arrays/structs/i31s, unpack it. // If this is a wrapper for arrays/structs/i31s, unpack it.
......
...@@ -905,6 +905,7 @@ Handle<WasmValueObject> WasmValueObject::New( ...@@ -905,6 +905,7 @@ Handle<WasmValueObject> WasmValueObject::New(
} }
case wasm::kRefNull: case wasm::kRefNull:
case wasm::kRef: { case wasm::kRef: {
// TODO(12868): Support stringrefs.
t = GetRefTypeName(isolate, value.type(), module_object->native_module()); t = GetRefTypeName(isolate, value.type(), module_object->native_module());
Handle<Object> ref = value.to_ref(); Handle<Object> ref = value.to_ref();
if (ref->IsWasmStruct()) { if (ref->IsWasmStruct()) {
...@@ -915,7 +916,7 @@ Handle<WasmValueObject> WasmValueObject::New( ...@@ -915,7 +916,7 @@ Handle<WasmValueObject> WasmValueObject::New(
v = handle(Handle<WasmInternalFunction>::cast(ref)->external(), v = handle(Handle<WasmInternalFunction>::cast(ref)->external(),
isolate); isolate);
} else if (ref->IsJSFunction() || ref->IsSmi() || ref->IsNull() || } 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; v = ref;
} else { } else {
// Fail gracefully. // Fail gracefully.
......
...@@ -84,7 +84,7 @@ ValKind V8ValueTypeToWasm(i::wasm::ValueType v8_valtype) { ...@@ -84,7 +84,7 @@ ValKind V8ValueTypeToWasm(i::wasm::ValueType v8_valtype) {
switch (v8_valtype.heap_representation()) { switch (v8_valtype.heap_representation()) {
case i::wasm::HeapType::kFunc: case i::wasm::HeapType::kFunc:
return FUNCREF; return FUNCREF;
case i::wasm::HeapType::kAny: case i::wasm::HeapType::kExtern:
return ANYREF; return ANYREF;
default: default:
// TODO(wasm+): support new value types // TODO(wasm+): support new value types
...@@ -109,7 +109,7 @@ i::wasm::ValueType WasmValKindToV8(ValKind kind) { ...@@ -109,7 +109,7 @@ i::wasm::ValueType WasmValKindToV8(ValKind kind) {
case FUNCREF: case FUNCREF:
return i::wasm::kWasmFuncRef; return i::wasm::kWasmFuncRef;
case ANYREF: case ANYREF:
return i::wasm::kWasmAnyRef; return i::wasm::kWasmExternRef;
default: default:
// TODO(wasm+): support new value types // TODO(wasm+): support new value types
UNREACHABLE(); UNREACHABLE();
...@@ -1930,7 +1930,7 @@ auto Table::make(Store* store_abs, const TableType* type, const Ref* ref) ...@@ -1930,7 +1930,7 @@ auto Table::make(Store* store_abs, const TableType* type, const Ref* ref)
break; break;
case ANYREF: case ANYREF:
// See Engine::make(). // See Engine::make().
i_type = i::wasm::kWasmAnyRef; i_type = i::wasm::kWasmExternRef;
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -1976,7 +1976,7 @@ auto Table::type() const -> own<TableType> { ...@@ -1976,7 +1976,7 @@ auto Table::type() const -> own<TableType> {
case i::wasm::HeapType::kFunc: case i::wasm::HeapType::kFunc:
kind = FUNCREF; kind = FUNCREF;
break; break;
case i::wasm::HeapType::kAny: case i::wasm::HeapType::kExtern:
kind = ANYREF; kind = ANYREF;
break; break;
default: default:
......
...@@ -237,7 +237,7 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc, ...@@ -237,7 +237,7 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc,
case kI31RefCode: case kI31RefCode:
case kDataRefCode: case kDataRefCode:
case kArrayRefCode: case kArrayRefCode:
case kAnyRefCodeAlias: case kAnyRefCode:
case kNoneCode: case kNoneCode:
if (!VALIDATE(enabled.has_gc())) { if (!VALIDATE(enabled.has_gc())) {
DecodeError<validate>( DecodeError<validate>(
...@@ -247,7 +247,7 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc, ...@@ -247,7 +247,7 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc,
return HeapType(HeapType::kBottom); return HeapType(HeapType::kBottom);
} }
V8_FALLTHROUGH; V8_FALLTHROUGH;
case kAnyRefCode: case kExternRefCode:
case kFuncRefCode: case kFuncRefCode:
return HeapType::from_code(code); return HeapType::from_code(code);
case kStringRefCode: case kStringRefCode:
...@@ -314,7 +314,7 @@ ValueType read_value_type(Decoder* decoder, const byte* pc, ...@@ -314,7 +314,7 @@ ValueType read_value_type(Decoder* decoder, const byte* pc,
case kI31RefCode: case kI31RefCode:
case kDataRefCode: case kDataRefCode:
case kArrayRefCode: case kArrayRefCode:
case kAnyRefCodeAlias: case kAnyRefCode:
case kNoneCode: case kNoneCode:
if (!VALIDATE(enabled.has_gc())) { if (!VALIDATE(enabled.has_gc())) {
DecodeError<validate>( DecodeError<validate>(
...@@ -324,7 +324,7 @@ ValueType read_value_type(Decoder* decoder, const byte* pc, ...@@ -324,7 +324,7 @@ ValueType read_value_type(Decoder* decoder, const byte* pc,
return kWasmBottom; return kWasmBottom;
} }
V8_FALLTHROUGH; V8_FALLTHROUGH;
case kAnyRefCode: case kExternRefCode:
case kFuncRefCode: { case kFuncRefCode: {
HeapType heap_type = HeapType::from_code(code); HeapType heap_type = HeapType::from_code(code);
Nullability nullability = Nullability nullability =
......
...@@ -64,7 +64,8 @@ class HeapType { ...@@ -64,7 +64,8 @@ class HeapType {
kI31, // shorthand: j kI31, // shorthand: j
kData, // shorthand: o kData, // shorthand: o
kArray, // shorthand: g kArray, // shorthand: g
kAny, // shorthand: a. Aka kExtern. kAny, //
kExtern, // shorthand: a.
kString, // shorthand: w. kString, // shorthand: w.
kStringViewWtf8, // shorthand: x. kStringViewWtf8, // shorthand: x.
kStringViewWtf16, // shorthand: y. kStringViewWtf16, // shorthand: y.
...@@ -84,8 +85,9 @@ class HeapType { ...@@ -84,8 +85,9 @@ class HeapType {
case ValueTypeCode::kI31RefCode: case ValueTypeCode::kI31RefCode:
return HeapType(kI31); return HeapType(kI31);
case ValueTypeCode::kAnyRefCode: case ValueTypeCode::kAnyRefCode:
case ValueTypeCode::kAnyRefCodeAlias:
return HeapType(kAny); return HeapType(kAny);
case ValueTypeCode::kExternRefCode:
return HeapType(kExtern);
case ValueTypeCode::kDataRefCode: case ValueTypeCode::kDataRefCode:
return HeapType(kData); return HeapType(kData);
case ValueTypeCode::kArrayRefCode: case ValueTypeCode::kArrayRefCode:
...@@ -152,8 +154,10 @@ class HeapType { ...@@ -152,8 +154,10 @@ class HeapType {
return std::string("data"); return std::string("data");
case kArray: case kArray:
return std::string("array"); return std::string("array");
case kExtern:
return std::string("extern");
case kAny: case kAny:
return std::string(FLAG_experimental_wasm_gc ? "any" : "extern"); return std::string("any");
case kString: case kString:
return std::string("string"); return std::string("string");
case kStringViewWtf8: case kStringViewWtf8:
...@@ -185,6 +189,8 @@ class HeapType { ...@@ -185,6 +189,8 @@ class HeapType {
return mask | kDataRefCode; return mask | kDataRefCode;
case kArray: case kArray:
return mask | kArrayRefCode; return mask | kArrayRefCode;
case kExtern:
return mask | kExternRefCode;
case kAny: case kAny:
return mask | kAnyRefCode; return mask | kAnyRefCode;
case kString: case kString:
...@@ -522,6 +528,8 @@ class ValueType { ...@@ -522,6 +528,8 @@ class ValueType {
return kFuncRefCode; return kFuncRefCode;
case HeapType::kEq: case HeapType::kEq:
return kEqRefCode; return kEqRefCode;
case HeapType::kExtern:
return kExternRefCode;
case HeapType::kAny: case HeapType::kAny:
return kAnyRefCode; return kAnyRefCode;
case HeapType::kString: case HeapType::kString:
...@@ -575,6 +583,7 @@ class ValueType { ...@@ -575,6 +583,7 @@ class ValueType {
return heap_representation() != HeapType::kFunc && return heap_representation() != HeapType::kFunc &&
heap_representation() != HeapType::kEq && heap_representation() != HeapType::kEq &&
heap_representation() != HeapType::kAny && heap_representation() != HeapType::kAny &&
heap_representation() != HeapType::kExtern &&
heap_representation() != HeapType::kString && heap_representation() != HeapType::kString &&
heap_representation() != HeapType::kStringViewWtf8 && heap_representation() != HeapType::kStringViewWtf8 &&
heap_representation() != HeapType::kStringViewWtf16 && heap_representation() != HeapType::kStringViewWtf16 &&
...@@ -683,6 +692,7 @@ constexpr ValueType kWasmBottom = ValueType::Primitive(kBottom); ...@@ -683,6 +692,7 @@ constexpr ValueType kWasmBottom = ValueType::Primitive(kBottom);
// Established reference-type and wasm-gc proposal shorthands. // Established reference-type and wasm-gc proposal shorthands.
constexpr ValueType kWasmFuncRef = ValueType::RefNull(HeapType::kFunc); constexpr ValueType kWasmFuncRef = ValueType::RefNull(HeapType::kFunc);
constexpr ValueType kWasmAnyRef = ValueType::RefNull(HeapType::kAny); constexpr ValueType kWasmAnyRef = ValueType::RefNull(HeapType::kAny);
constexpr ValueType kWasmExternRef = ValueType::RefNull(HeapType::kExtern);
constexpr ValueType kWasmEqRef = ValueType::RefNull(HeapType::kEq); constexpr ValueType kWasmEqRef = ValueType::RefNull(HeapType::kEq);
constexpr ValueType kWasmI31Ref = ValueType::Ref(HeapType::kI31); constexpr ValueType kWasmI31Ref = ValueType::Ref(HeapType::kI31);
constexpr ValueType kWasmDataRef = ValueType::Ref(HeapType::kData); constexpr ValueType kWasmDataRef = ValueType::Ref(HeapType::kData);
......
...@@ -37,10 +37,9 @@ enum ValueTypeCode : uint8_t { ...@@ -37,10 +37,9 @@ enum ValueTypeCode : uint8_t {
kI16Code = 0x79, kI16Code = 0x79,
// Current reference types // Current reference types
kFuncRefCode = 0x70, kFuncRefCode = 0x70,
kAnyRefCode = 0x6f, // aka externref kExternRefCode = 0x6f,
// typed-funcref and GC proposal types // typed-funcref and GC proposal types
// TODO(7748): For backwards compatibility only, remove when able. kAnyRefCode = 0x6e,
kAnyRefCodeAlias = 0x6e,
kEqRefCode = 0x6d, kEqRefCode = 0x6d,
kRefNullCode = 0x6c, kRefNullCode = 0x6c,
kRefCode = 0x6b, kRefCode = 0x6b,
......
...@@ -1188,8 +1188,7 @@ void WebAssemblyTable(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1188,8 +1188,7 @@ void WebAssemblyTable(const v8::FunctionCallbackInfo<v8::Value>& args) {
// and anyfunc just becomes an alias for "funcref". // and anyfunc just becomes an alias for "funcref".
type = i::wasm::kWasmFuncRef; type = i::wasm::kWasmFuncRef;
} else if (string->StringEquals(v8_str(isolate, "externref"))) { } else if (string->StringEquals(v8_str(isolate, "externref"))) {
// externref is known as anyref as of wasm-gc. type = i::wasm::kWasmExternRef;
type = i::wasm::kWasmAnyRef;
} else if (enabled_features.has_stringref() && } else if (enabled_features.has_stringref() &&
string->StringEquals(v8_str(isolate, "stringref"))) { string->StringEquals(v8_str(isolate, "stringref"))) {
type = i::wasm::kWasmStringRef; type = i::wasm::kWasmStringRef;
...@@ -1385,7 +1384,7 @@ bool GetValueType(Isolate* isolate, MaybeLocal<Value> maybe, ...@@ -1385,7 +1384,7 @@ bool GetValueType(Isolate* isolate, MaybeLocal<Value> maybe,
} else if (string->StringEquals(v8_str(isolate, "f64"))) { } else if (string->StringEquals(v8_str(isolate, "f64"))) {
*type = i::wasm::kWasmF64; *type = i::wasm::kWasmF64;
} else if (string->StringEquals(v8_str(isolate, "externref"))) { } else if (string->StringEquals(v8_str(isolate, "externref"))) {
*type = i::wasm::kWasmAnyRef; *type = i::wasm::kWasmExternRef;
} else if (enabled_features.has_type_reflection() && } else if (enabled_features.has_type_reflection() &&
string->StringEquals(v8_str(isolate, "funcref"))) { string->StringEquals(v8_str(isolate, "funcref"))) {
// The type reflection proposal renames "anyfunc" to "funcref", and makes // The type reflection proposal renames "anyfunc" to "funcref", and makes
...@@ -1400,6 +1399,9 @@ bool GetValueType(Isolate* isolate, MaybeLocal<Value> maybe, ...@@ -1400,6 +1399,9 @@ bool GetValueType(Isolate* isolate, MaybeLocal<Value> maybe,
} else if (enabled_features.has_stringref() && } else if (enabled_features.has_stringref() &&
string->StringEquals(v8_str(isolate, "stringref"))) { string->StringEquals(v8_str(isolate, "stringref"))) {
*type = i::wasm::kWasmStringRef; *type = i::wasm::kWasmStringRef;
} else if (enabled_features.has_gc() &&
string->StringEquals(v8_str(isolate, "anyref"))) {
*type = i::wasm::kWasmAnyRef;
} else { } else {
// Unrecognized type. // Unrecognized type.
*type = i::wasm::kWasmVoid; *type = i::wasm::kWasmVoid;
...@@ -1551,7 +1553,7 @@ void WebAssemblyGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1551,7 +1553,7 @@ void WebAssemblyGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
case i::wasm::kRef: case i::wasm::kRef:
case i::wasm::kRefNull: { case i::wasm::kRefNull: {
switch (type.heap_representation()) { switch (type.heap_representation()) {
case i::wasm::HeapType::kAny: { case i::wasm::HeapType::kExtern: {
if (args.Length() < 2) { if (args.Length() < 2) {
// When no initial value is provided, we have to use the WebAssembly // When no initial value is provided, we have to use the WebAssembly
// default value 'null', and not the JS default value 'undefined'. // default value 'null', and not the JS default value 'undefined'.
...@@ -1599,6 +1601,7 @@ void WebAssemblyGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1599,6 +1601,7 @@ void WebAssemblyGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
case internal::wasm::HeapType::kI31: case internal::wasm::HeapType::kI31:
case internal::wasm::HeapType::kData: case internal::wasm::HeapType::kData:
case internal::wasm::HeapType::kArray: case internal::wasm::HeapType::kArray:
case internal::wasm::HeapType::kAny:
case internal::wasm::HeapType::kStringViewWtf8: case internal::wasm::HeapType::kStringViewWtf8:
case internal::wasm::HeapType::kStringViewWtf16: case internal::wasm::HeapType::kStringViewWtf16:
case internal::wasm::HeapType::kStringViewIter: case internal::wasm::HeapType::kStringViewIter:
...@@ -1789,6 +1792,7 @@ void EncodeExceptionValues(v8::Isolate* isolate, ...@@ -1789,6 +1792,7 @@ void EncodeExceptionValues(v8::Isolate* isolate,
case i::wasm::kRefNull: case i::wasm::kRefNull:
switch (type.heap_representation()) { switch (type.heap_representation()) {
case i::wasm::HeapType::kFunc: case i::wasm::HeapType::kFunc:
case i::wasm::HeapType::kExtern:
case i::wasm::HeapType::kAny: case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq: case i::wasm::HeapType::kEq:
case i::wasm::HeapType::kI31: case i::wasm::HeapType::kI31:
...@@ -2032,12 +2036,12 @@ void WebAssemblyFunctionType(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -2032,12 +2036,12 @@ void WebAssemblyFunctionType(const v8::FunctionCallbackInfo<v8::Value>& args) {
// promise as an externref instead of the original return type. // promise as an externref instead of the original return type.
size_t param_count = sig->parameter_count(); size_t param_count = sig->parameter_count();
DCHECK_GE(param_count, 1); 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); i::wasm::FunctionSig::Builder builder(&zone, 1, param_count - 1);
for (size_t i = 1; i < param_count; ++i) { for (size_t i = 1; i < param_count; ++i) {
builder.AddParam(sig->GetParam(i)); builder.AddParam(sig->GetParam(i));
} }
builder.AddReturn(i::wasm::kWasmAnyRef); builder.AddReturn(i::wasm::kWasmExternRef);
sig = builder.Build(); sig = builder.Build();
} }
} else if (i::WasmJSFunction::IsWasmJSFunction(*arg0)) { } else if (i::WasmJSFunction::IsWasmJSFunction(*arg0)) {
...@@ -2049,13 +2053,13 @@ void WebAssemblyFunctionType(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -2049,13 +2053,13 @@ void WebAssemblyFunctionType(const v8::FunctionCallbackInfo<v8::Value>& args) {
// parameter which will be consumed by the wasm-to-JS wrapper. // parameter which will be consumed by the wasm-to-JS wrapper.
size_t param_count = sig->parameter_count(); size_t param_count = sig->parameter_count();
i::wasm::FunctionSig::Builder builder(&zone, 1, param_count + 1); 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) { for (size_t i = 0; i < param_count; ++i) {
builder.AddParam(sig->GetParam(i)); builder.AddParam(sig->GetParam(i));
} }
DCHECK_EQ(1, sig->return_count()); DCHECK_EQ(1, sig->return_count());
DCHECK_EQ(i::wasm::kWasmAnyRef, sig->GetReturn(0)); DCHECK_EQ(i::wasm::kWasmExternRef, sig->GetReturn(0));
builder.AddReturn(i::wasm::kWasmAnyRef); builder.AddReturn(i::wasm::kWasmExternRef);
sig = builder.Build(); sig = builder.Build();
} }
} else { } else {
...@@ -2226,7 +2230,9 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -2226,7 +2230,9 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
} }
i::Handle<i::Object> external_element; 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); .ToHandle(&external_element);
i::WasmTableObject::Set(i_isolate, table_object, index, i::WasmTableObject::Set(i_isolate, table_object, index,
...@@ -2411,6 +2417,7 @@ void WebAssemblyExceptionGetArg( ...@@ -2411,6 +2417,7 @@ void WebAssemblyExceptionGetArg(
case i::wasm::kRefNull: case i::wasm::kRefNull:
switch (signature.get(i).heap_representation()) { switch (signature.get(i).heap_representation()) {
case i::wasm::HeapType::kFunc: case i::wasm::HeapType::kFunc:
case i::wasm::HeapType::kExtern:
case i::wasm::HeapType::kAny: case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq: case i::wasm::HeapType::kEq:
case i::wasm::HeapType::kI31: case i::wasm::HeapType::kI31:
...@@ -2473,6 +2480,7 @@ void WebAssemblyExceptionGetArg( ...@@ -2473,6 +2480,7 @@ void WebAssemblyExceptionGetArg(
case i::wasm::kRefNull: case i::wasm::kRefNull:
switch (signature.get(index).heap_representation()) { switch (signature.get(index).heap_representation()) {
case i::wasm::HeapType::kFunc: case i::wasm::HeapType::kFunc:
case i::wasm::HeapType::kExtern:
case i::wasm::HeapType::kAny: case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq: case i::wasm::HeapType::kEq:
case i::wasm::HeapType::kI31: case i::wasm::HeapType::kI31:
...@@ -2555,7 +2563,7 @@ void WebAssemblyGlobalGetValueCommon( ...@@ -2555,7 +2563,7 @@ void WebAssemblyGlobalGetValueCommon(
case i::wasm::kRef: case i::wasm::kRef:
case i::wasm::kRefNull: case i::wasm::kRefNull:
switch (receiver->type().heap_representation()) { switch (receiver->type().heap_representation()) {
case i::wasm::HeapType::kAny: case i::wasm::HeapType::kExtern:
case i::wasm::HeapType::kString: case i::wasm::HeapType::kString:
return_value.Set(Utils::ToLocal(receiver->GetRef())); return_value.Set(Utils::ToLocal(receiver->GetRef()));
break; break;
...@@ -2583,6 +2591,7 @@ void WebAssemblyGlobalGetValueCommon( ...@@ -2583,6 +2591,7 @@ void WebAssemblyGlobalGetValueCommon(
case i::wasm::HeapType::kI31: case i::wasm::HeapType::kI31:
case i::wasm::HeapType::kData: case i::wasm::HeapType::kData:
case i::wasm::HeapType::kArray: case i::wasm::HeapType::kArray:
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq: case i::wasm::HeapType::kEq:
default: default:
// TODO(7748): Implement these. // TODO(7748): Implement these.
...@@ -2660,7 +2669,7 @@ void WebAssemblyGlobalSetValue( ...@@ -2660,7 +2669,7 @@ void WebAssemblyGlobalSetValue(
case i::wasm::kRef: case i::wasm::kRef:
case i::wasm::kRefNull: case i::wasm::kRefNull:
switch (receiver->type().heap_representation()) { switch (receiver->type().heap_representation()) {
case i::wasm::HeapType::kAny: case i::wasm::HeapType::kExtern:
receiver->SetExternRef(Utils::OpenHandle(*args[0])); receiver->SetExternRef(Utils::OpenHandle(*args[0]));
break; break;
case i::wasm::HeapType::kFunc: { case i::wasm::HeapType::kFunc: {
...@@ -2704,6 +2713,7 @@ void WebAssemblyGlobalSetValue( ...@@ -2704,6 +2713,7 @@ void WebAssemblyGlobalSetValue(
case i::wasm::HeapType::kI31: case i::wasm::HeapType::kI31:
case i::wasm::HeapType::kData: case i::wasm::HeapType::kData:
case i::wasm::HeapType::kArray: case i::wasm::HeapType::kArray:
case i::wasm::HeapType::kAny:
case i::wasm::HeapType::kEq: case i::wasm::HeapType::kEq:
default: default:
// TODO(7748): Implement these. // TODO(7748): Implement these.
...@@ -2760,9 +2770,9 @@ void WebAssemblyReturnPromiseOnSuspend( ...@@ -2760,9 +2770,9 @@ void WebAssemblyReturnPromiseOnSuspend(
"Expected a WebAssembly.Function with exactly one return type"); "Expected a WebAssembly.Function with exactly one return type");
} }
if (data.sig()->parameter_count() == 0 || 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", 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; if (thrower.error()) return;
int index = data.function_index(); int index = data.function_index();
...@@ -2803,9 +2813,10 @@ void WebAssemblySuspendOnReturnedPromise( ...@@ -2803,9 +2813,10 @@ void WebAssemblySuspendOnReturnedPromise(
return; return;
} }
sig = i::Handle<i::WasmJSFunction>::cast(arg0)->GetSignature(&zone); 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", thrower.TypeError("Expected a WebAssembly.Function with return type %s",
i::wasm::kWasmAnyRef.name().c_str()); i::wasm::kWasmExternRef.name().c_str());
return; return;
} }
......
...@@ -607,7 +607,7 @@ struct WasmTable { ...@@ -607,7 +607,7 @@ struct WasmTable {
static bool IsValidTableType(ValueType type, const WasmModule* module) { static bool IsValidTableType(ValueType type, const WasmModule* module) {
if (!type.is_object_reference()) return false; if (!type.is_object_reference()) return false;
HeapType heap_type = type.heap_type(); 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::kString ||
heap_type == HeapType::kStringViewWtf8 || heap_type == HeapType::kStringViewWtf8 ||
heap_type == HeapType::kStringViewWtf16 || heap_type == HeapType::kStringViewWtf16 ||
......
...@@ -167,7 +167,7 @@ void WasmGlobalObject::SetF64(double value) { ...@@ -167,7 +167,7 @@ void WasmGlobalObject::SetF64(double value) {
} }
void WasmGlobalObject::SetExternRef(Handle<Object> 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); tagged_buffer().set(offset(), *value);
} }
......
...@@ -377,7 +377,7 @@ void WasmTableObject::Set(Isolate* isolate, Handle<WasmTableObject> table, ...@@ -377,7 +377,7 @@ void WasmTableObject::Set(Isolate* isolate, Handle<WasmTableObject> table,
int entry_index = static_cast<int>(index); int entry_index = static_cast<int>(index);
switch (table->type().heap_representation()) { switch (table->type().heap_representation()) {
case wasm::HeapType::kAny: case wasm::HeapType::kExtern:
case wasm::HeapType::kString: case wasm::HeapType::kString:
case wasm::HeapType::kStringViewWtf8: case wasm::HeapType::kStringViewWtf8:
case wasm::HeapType::kStringViewWtf16: case wasm::HeapType::kStringViewWtf16:
...@@ -390,6 +390,7 @@ void WasmTableObject::Set(Isolate* isolate, Handle<WasmTableObject> table, ...@@ -390,6 +390,7 @@ void WasmTableObject::Set(Isolate* isolate, Handle<WasmTableObject> table,
case wasm::HeapType::kEq: case wasm::HeapType::kEq:
case wasm::HeapType::kData: case wasm::HeapType::kData:
case wasm::HeapType::kArray: case wasm::HeapType::kArray:
case wasm::HeapType::kAny:
case wasm::HeapType::kI31: case wasm::HeapType::kI31:
// TODO(7748): Implement once we have struct/arrays/i31ref/string tables. // TODO(7748): Implement once we have struct/arrays/i31ref/string tables.
UNREACHABLE(); UNREACHABLE();
...@@ -423,7 +424,7 @@ Handle<Object> WasmTableObject::Get(Isolate* isolate, ...@@ -423,7 +424,7 @@ Handle<Object> WasmTableObject::Get(Isolate* isolate,
} }
switch (table->type().heap_representation()) { switch (table->type().heap_representation()) {
case wasm::HeapType::kAny: case wasm::HeapType::kExtern:
case wasm::HeapType::kString: case wasm::HeapType::kString:
case wasm::HeapType::kStringViewWtf8: case wasm::HeapType::kStringViewWtf8:
case wasm::HeapType::kStringViewWtf16: case wasm::HeapType::kStringViewWtf16:
...@@ -436,6 +437,7 @@ Handle<Object> WasmTableObject::Get(Isolate* isolate, ...@@ -436,6 +437,7 @@ Handle<Object> WasmTableObject::Get(Isolate* isolate,
case wasm::HeapType::kI31: case wasm::HeapType::kI31:
case wasm::HeapType::kData: case wasm::HeapType::kData:
case wasm::HeapType::kArray: case wasm::HeapType::kArray:
case wasm::HeapType::kAny:
// TODO(7748): Implement once we have a story for struct/arrays/i31ref in // TODO(7748): Implement once we have a story for struct/arrays/i31ref in
// JS. // JS.
UNIMPLEMENTED(); UNIMPLEMENTED();
...@@ -2188,7 +2190,7 @@ bool WasmJSFunction::MatchesSignatureForSuspend(const wasm::FunctionSig* sig) { ...@@ -2188,7 +2190,7 @@ bool WasmJSFunction::MatchesSignatureForSuspend(const wasm::FunctionSig* sig) {
// WebAssembly.suspendOnReturnedPromise, so the return type has to be // WebAssembly.suspendOnReturnedPromise, so the return type has to be
// externref. // externref.
CHECK_EQ(function_data.serialized_return_count(), 1); 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; const wasm::ValueType* expected = sig->parameters().begin() + 1;
return function_data.serialized_signature().matches(1, expected, return function_data.serialized_signature().matches(1, expected,
parameter_count - 1); parameter_count - 1);
...@@ -2312,10 +2314,11 @@ bool TypecheckJSObject(Isolate* isolate, const WasmModule* module, ...@@ -2312,10 +2314,11 @@ bool TypecheckJSObject(Isolate* isolate, const WasmModule* module,
} }
return true; return true;
} }
case HeapType::kAny: case HeapType::kExtern:
return true; return true;
case HeapType::kData: case HeapType::kData:
case HeapType::kArray: case HeapType::kArray:
case HeapType::kAny:
case HeapType::kEq: case HeapType::kEq:
case HeapType::kI31: { case HeapType::kI31: {
// TODO(7748): Change this when we have a decision on the JS API for // 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( ...@@ -174,6 +174,8 @@ V8_NOINLINE V8_EXPORT_PRIVATE bool IsHeapSubtypeOfImpl(
return sub_heap == super_heap || super_heap == HeapType::kAny; return sub_heap == super_heap || super_heap == HeapType::kAny;
case HeapType::kAny: case HeapType::kAny:
return super_heap == HeapType::kAny; return super_heap == HeapType::kAny;
case HeapType::kExtern:
return super_heap == HeapType::kExtern;
case HeapType::kI31: case HeapType::kI31:
case HeapType::kData: case HeapType::kData:
return super_heap == sub_heap || super_heap == HeapType::kEq || return super_heap == sub_heap || super_heap == HeapType::kEq ||
...@@ -213,6 +215,8 @@ V8_NOINLINE V8_EXPORT_PRIVATE bool IsHeapSubtypeOfImpl( ...@@ -213,6 +215,8 @@ V8_NOINLINE V8_EXPORT_PRIVATE bool IsHeapSubtypeOfImpl(
return false; return false;
case HeapType::kAny: case HeapType::kAny:
return true; return true;
case HeapType::kExtern:
return false;
case HeapType::kString: case HeapType::kString:
case HeapType::kStringViewWtf8: case HeapType::kStringViewWtf8:
case HeapType::kStringViewWtf16: case HeapType::kStringViewWtf16:
...@@ -340,6 +344,8 @@ HeapType::Representation CommonAncestorWithGeneric(HeapType heap1, ...@@ -340,6 +344,8 @@ HeapType::Representation CommonAncestorWithGeneric(HeapType heap1,
case HeapType::kAny: case HeapType::kAny:
case HeapType::kFunc: case HeapType::kFunc:
return HeapType::kAny; return HeapType::kAny;
case HeapType::kExtern:
UNREACHABLE();
default: default:
return module2->has_signature(heap2.ref_index()) ? HeapType::kAny return module2->has_signature(heap2.ref_index()) ? HeapType::kAny
: HeapType::kEq; : HeapType::kEq;
...@@ -356,6 +362,8 @@ HeapType::Representation CommonAncestorWithGeneric(HeapType heap1, ...@@ -356,6 +362,8 @@ HeapType::Representation CommonAncestorWithGeneric(HeapType heap1,
case HeapType::kAny: case HeapType::kAny:
case HeapType::kFunc: case HeapType::kFunc:
return HeapType::kAny; return HeapType::kAny;
case HeapType::kExtern:
UNREACHABLE();
default: default:
return module2->has_signature(heap2.ref_index()) ? HeapType::kAny return module2->has_signature(heap2.ref_index()) ? HeapType::kAny
: HeapType::kData; : HeapType::kData;
...@@ -373,6 +381,8 @@ HeapType::Representation CommonAncestorWithGeneric(HeapType heap1, ...@@ -373,6 +381,8 @@ HeapType::Representation CommonAncestorWithGeneric(HeapType heap1,
case HeapType::kAny: case HeapType::kAny:
case HeapType::kFunc: case HeapType::kFunc:
return HeapType::kAny; return HeapType::kAny;
case HeapType::kExtern:
UNREACHABLE();
default: default:
return module2->has_array(heap2.ref_index()) ? HeapType::kArray return module2->has_array(heap2.ref_index()) ? HeapType::kArray
: module2->has_struct(heap2.ref_index()) ? HeapType::kData : module2->has_struct(heap2.ref_index()) ? HeapType::kData
......
...@@ -25,8 +25,8 @@ class TestSignatures { ...@@ -25,8 +25,8 @@ class TestSignatures {
sig_i_ff(1, 2, kIntFloatTypes4), sig_i_ff(1, 2, kIntFloatTypes4),
sig_i_d(1, 1, kIntDoubleTypes4), sig_i_d(1, 1, kIntDoubleTypes4),
sig_i_dd(1, 2, kIntDoubleTypes4), sig_i_dd(1, 2, kIntDoubleTypes4),
sig_i_a(1, 1, kIntAnyRefTypes4), sig_i_a(1, 1, kIntExternRefTypes4),
sig_i_aa(1, 2, kIntAnyRefTypes4), sig_i_aa(1, 2, kIntExternRefTypes4),
sig_i_c(1, 1, kIntFuncRefTypes4), sig_i_c(1, 1, kIntFuncRefTypes4),
sig_i_s(1, 1, kIntSimd128Types4), sig_i_s(1, 1, kIntSimd128Types4),
sig_l_v(1, 0, kLongTypes4), sig_l_v(1, 0, kLongTypes4),
...@@ -37,15 +37,15 @@ class TestSignatures { ...@@ -37,15 +37,15 @@ class TestSignatures {
sig_f_ff(1, 2, kFloatTypes4), sig_f_ff(1, 2, kFloatTypes4),
sig_d_d(1, 1, kDoubleTypes4), sig_d_d(1, 1, kDoubleTypes4),
sig_d_dd(1, 2, 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_c_v(1, 0, kFuncTypes4),
sig_a_a(1, 1, kAnyRefTypes4), sig_a_a(1, 1, kExternRefTypes4),
sig_c_c(1, 1, kFuncTypes4), sig_c_c(1, 1, kFuncTypes4),
sig_v_v(0, 0, kIntTypes4), sig_v_v(0, 0, kIntTypes4),
sig_v_i(0, 1, kIntTypes4), sig_v_i(0, 1, kIntTypes4),
sig_v_ii(0, 2, kIntTypes4), sig_v_ii(0, 2, kIntTypes4),
sig_v_iii(0, 3, 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_c(0, 1, kFuncTypes4),
sig_v_d(0, 1, kDoubleTypes4), sig_v_d(0, 1, kDoubleTypes4),
sig_s_i(1, 1, kSimd128IntTypes4), sig_s_i(1, 1, kSimd128IntTypes4),
...@@ -58,12 +58,12 @@ class TestSignatures { ...@@ -58,12 +58,12 @@ class TestSignatures {
for (int i = 0; i < 4; i++) kLongTypes4[i] = kWasmI64; 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++) kFloatTypes4[i] = kWasmF32;
for (int i = 0; i < 4; i++) kDoubleTypes4[i] = kWasmF64; 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 = 0; i < 4; i++) kFuncTypes4[i] = kWasmFuncRef;
for (int i = 1; i < 4; i++) kIntLongTypes4[i] = kWasmI64; 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++) kIntFloatTypes4[i] = kWasmF32;
for (int i = 1; i < 4; i++) kIntDoubleTypes4[i] = kWasmF64; 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 = 1; i < 4; i++) kIntFuncRefTypes4[i] = kWasmFuncRef;
for (int i = 0; i < 4; i++) kSimd128Types4[i] = kWasmS128; for (int i = 0; i < 4; i++) kSimd128Types4[i] = kWasmS128;
for (int i = 1; i < 4; i++) kIntSimd128Types4[i] = kWasmS128; for (int i = 1; i < 4; i++) kIntSimd128Types4[i] = kWasmS128;
...@@ -71,7 +71,7 @@ class TestSignatures { ...@@ -71,7 +71,7 @@ class TestSignatures {
kIntLongTypes4[0] = kWasmI32; kIntLongTypes4[0] = kWasmI32;
kIntFloatTypes4[0] = kWasmI32; kIntFloatTypes4[0] = kWasmI32;
kIntDoubleTypes4[0] = kWasmI32; kIntDoubleTypes4[0] = kWasmI32;
kIntAnyRefTypes4[0] = kWasmI32; kIntExternRefTypes4[0] = kWasmI32;
kIntFuncRefTypes4[0] = kWasmI32; kIntFuncRefTypes4[0] = kWasmI32;
kIntSimd128Types4[0] = kWasmI32; kIntSimd128Types4[0] = kWasmI32;
kSimd128IntTypes4[1] = kWasmI32; kSimd128IntTypes4[1] = kWasmI32;
...@@ -134,12 +134,12 @@ class TestSignatures { ...@@ -134,12 +134,12 @@ class TestSignatures {
ValueType kLongTypes4[4]; ValueType kLongTypes4[4];
ValueType kFloatTypes4[4]; ValueType kFloatTypes4[4];
ValueType kDoubleTypes4[4]; ValueType kDoubleTypes4[4];
ValueType kAnyRefTypes4[4]; ValueType kExternRefTypes4[4];
ValueType kFuncTypes4[4]; ValueType kFuncTypes4[4];
ValueType kIntLongTypes4[4]; ValueType kIntLongTypes4[4];
ValueType kIntFloatTypes4[4]; ValueType kIntFloatTypes4[4];
ValueType kIntDoubleTypes4[4]; ValueType kIntDoubleTypes4[4];
ValueType kIntAnyRefTypes4[4]; ValueType kIntExternRefTypes4[4];
ValueType kIntFuncRefTypes4[4]; ValueType kIntFuncRefTypes4[4];
ValueType kSimd128Types4[4]; ValueType kSimd128Types4[4];
ValueType kIntSimd128Types4[4]; ValueType kIntSimd128Types4[4];
......
...@@ -208,7 +208,7 @@ ...@@ -208,7 +208,7 @@
#define WASM_SELECT_D(tval, fval, cond) \ #define WASM_SELECT_D(tval, fval, cond) \
tval, fval, cond, kExprSelectWithType, U32V_1(1), kF64Code tval, fval, cond, kExprSelectWithType, U32V_1(1), kF64Code
#define WASM_SELECT_R(tval, fval, cond) \ #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) \ #define WASM_SELECT_A(tval, fval, cond) \
tval, fval, cond, kExprSelectWithType, U32V_1(1), kFuncRefCode tval, fval, cond, kExprSelectWithType, U32V_1(1), kFuncRefCode
......
...@@ -238,6 +238,8 @@ std::string HeapTypeToJSByteEncoding(HeapType heap_type) { ...@@ -238,6 +238,8 @@ std::string HeapTypeToJSByteEncoding(HeapType heap_type) {
return "kArrayRefCode"; return "kArrayRefCode";
case HeapType::kAny: case HeapType::kAny:
return "kAnyRefCode"; return "kAnyRefCode";
case HeapType::kExtern:
return "kExternRefCode";
case HeapType::kBottom: case HeapType::kBottom:
UNREACHABLE(); UNREACHABLE();
default: default:
...@@ -257,6 +259,8 @@ std::string HeapTypeToConstantName(HeapType heap_type) { ...@@ -257,6 +259,8 @@ std::string HeapTypeToConstantName(HeapType heap_type) {
return "kWasmDataRef"; return "kWasmDataRef";
case HeapType::kArray: case HeapType::kArray:
return "kWasmArrayRef"; return "kWasmArrayRef";
case HeapType::kExtern:
return "kWasmExternRef";
case HeapType::kAny: case HeapType::kAny:
return "kWasmAnyRef"; return "kWasmAnyRef";
case HeapType::kBottom: case HeapType::kBottom:
...@@ -288,6 +292,8 @@ std::string ValueTypeToConstantName(ValueType type) { ...@@ -288,6 +292,8 @@ std::string ValueTypeToConstantName(ValueType type) {
return "kWasmFuncRef"; return "kWasmFuncRef";
case HeapType::kEq: case HeapType::kEq:
return "kWasmEqRef"; return "kWasmEqRef";
case HeapType::kExtern:
return "kWasmExternRef";
case HeapType::kAny: case HeapType::kAny:
return "kWasmAnyRef"; return "kWasmAnyRef";
case HeapType::kBottom: case HeapType::kBottom:
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
/* TODO(7748): Re-enable these tests once any ref tables are supported.
(function TestArrayNewElemStatic() { (function TestArrayNewElemStatic() {
print(arguments.callee.name); print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
...@@ -158,6 +159,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -158,6 +159,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
assertTraps(kTrapNullDereference, () => table_get(0, 2)); assertTraps(kTrapNullDereference, () => table_get(0, 2));
assertTraps(kTrapArrayOutOfBounds, () => table_get(0, 3)); assertTraps(kTrapArrayOutOfBounds, () => table_get(0, 3));
})(); })();
*/
(function TestArrayNewElemStaticMistypedSegment() { (function TestArrayNewElemStaticMistypedSegment() {
print(arguments.callee.name); print(arguments.callee.name);
...@@ -208,6 +210,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -208,6 +210,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
/invalid element segment index/); /invalid element segment index/);
})(); })();
/* TODO(7748): Re-enable these tests once any ref tables are supported.
(function TestArrayNewElemStaticConstantArrayTooLarge() { (function TestArrayNewElemStaticConstantArrayTooLarge() {
print(arguments.callee.name); print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
...@@ -326,3 +329,4 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -326,3 +329,4 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
// An active segment counts as having 0 length. // An active segment counts as having 0 length.
assertTraps(kTrapElementSegmentOutOfBounds, () => instance.exports.init()); assertTraps(kTrapElementSegmentOutOfBounds, () => instance.exports.init());
})(); })();
*/
...@@ -143,6 +143,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -143,6 +143,7 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
assertEquals(22, instance.exports.table_test(1, 33, 11)); assertEquals(22, instance.exports.table_test(1, 33, 11));
})(); })();
/* TODO(7748): Re-enable this test once any ref tables are supported.
(function TestAnyRefTable() { (function TestAnyRefTable() {
print(arguments.callee.name); print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
...@@ -206,3 +207,4 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -206,3 +207,4 @@ d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
assertEquals(10, instance.exports.struct_getter()); assertEquals(10, instance.exports.struct_getter());
assertEquals(1, instance.exports.null_getter()); assertEquals(1, instance.exports.null_getter());
})(); })();
*/
This diff is collapsed.
...@@ -209,7 +209,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -209,7 +209,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestStackSwitchGC2() { (function TestStackSwitchGC2() {
print(arguments.callee.name); print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef, kWasmI32], [kWasmI32]); let sig = makeSig([kWasmExternRef, kWasmI32], [kWasmI32]);
let import_index = builder.addImport('m', 'import', sig); let import_index = builder.addImport('m', 'import', sig);
builder.addFunction("test", sig) builder.addFunction("test", sig)
.addBody([ .addBody([
...@@ -260,7 +260,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -260,7 +260,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
} }
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
// Number of param registers + 1 for both types. // 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]); kWasmF32, kWasmF32, kWasmF32, kWasmF32, kWasmF32, kWasmF32, kWasmF32], [kWasmI32]);
import_index = builder.addImport('m', 'import', sig); import_index = builder.addImport('m', 'import', sig);
builder.addFunction("test", sig) builder.addFunction("test", sig)
...@@ -292,7 +292,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -292,7 +292,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestStackSwitchReturnFloat() { (function TestStackSwitchReturnFloat() {
print(arguments.callee.name); print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
let sig = makeSig([kWasmAnyRef], [kWasmF32]); let sig = makeSig([kWasmExternRef], [kWasmF32]);
import_index = builder.addImport('m', 'import', sig); import_index = builder.addImport('m', 'import', sig);
builder.addFunction("test", sig) builder.addFunction("test", sig)
.addBody([ .addBody([
......
...@@ -119,8 +119,8 @@ let kWasmI16 = 0x79; ...@@ -119,8 +119,8 @@ let kWasmI16 = 0x79;
// indices. // indices.
let kWasmFuncRef = -0x10; let kWasmFuncRef = -0x10;
let kWasmAnyFunc = kWasmFuncRef; // Alias named as in the JS API spec let kWasmAnyFunc = kWasmFuncRef; // Alias named as in the JS API spec
let kWasmAnyRef = -0x11; let kWasmExternRef = -0x11;
let kWasmExternRef = kWasmAnyRef; // Alias for test backwards compatibility. let kWasmAnyRef = -0x12;
let kWasmEqRef = -0x13; let kWasmEqRef = -0x13;
let kWasmI31Ref = -0x16; let kWasmI31Ref = -0x16;
let kWasmDataRef = -0x19; let kWasmDataRef = -0x19;
......
...@@ -29,7 +29,7 @@ namespace module_decoder_unittest { ...@@ -29,7 +29,7 @@ namespace module_decoder_unittest {
#define WASM_INIT_EXPR_F32(val) WASM_F32(val), kExprEnd #define WASM_INIT_EXPR_F32(val) WASM_F32(val), kExprEnd
#define WASM_INIT_EXPR_I64(val) WASM_I64(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_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_FUNC_REF_NULL WASM_REF_NULL(kFuncRefCode), kExprEnd
#define WASM_INIT_EXPR_REF_FUNC(val) WASM_REF_FUNC(val), kExprEnd #define WASM_INIT_EXPR_REF_FUNC(val) WASM_REF_FUNC(val), kExprEnd
#define WASM_INIT_EXPR_GLOBAL(index) WASM_GLOBAL_GET(index), kExprEnd #define WASM_INIT_EXPR_GLOBAL(index) WASM_GLOBAL_GET(index), kExprEnd
...@@ -182,12 +182,13 @@ struct ValueTypePair { ...@@ -182,12 +182,13 @@ struct ValueTypePair {
uint8_t code; uint8_t code;
ValueType type; ValueType type;
} kValueTypes[] = { } kValueTypes[] = {
{kI32Code, kWasmI32}, // -- // TODO(mliedtke): Cover other value types as well.
{kI64Code, kWasmI64}, // -- {kI32Code, kWasmI32}, // --
{kF32Code, kWasmF32}, // -- {kI64Code, kWasmI64}, // --
{kF64Code, kWasmF64}, // -- {kF32Code, kWasmF32}, // --
{kFuncRefCode, kWasmFuncRef}, // -- {kF64Code, kWasmF64}, // --
{kAnyRefCode, kWasmAnyRef}, // -- {kFuncRefCode, kWasmFuncRef}, // --
{kExternRefCode, kWasmExternRef}, // --
}; };
class WasmModuleVerifyTest : public TestWithIsolateAndZone { class WasmModuleVerifyTest : public TestWithIsolateAndZone {
...@@ -306,7 +307,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobal) { ...@@ -306,7 +307,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobal) {
TWO_EMPTY_FUNCTIONS(SIG_INDEX(0)), TWO_EMPTY_FUNCTIONS(SIG_INDEX(0)),
SECTION(Global, // -- SECTION(Global, // --
ENTRY_COUNT(2), // -- ENTRY_COUNT(2), // --
kAnyRefCode, // local type kExternRefCode, // local type
0, // immutable 0, // immutable
WASM_INIT_EXPR_EXTERN_REF_NULL, // init WASM_INIT_EXPR_EXTERN_REF_NULL, // init
kFuncRefCode, // local type kFuncRefCode, // local type
...@@ -333,7 +334,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobal) { ...@@ -333,7 +334,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobal) {
EXPECT_EQ(0u, result.value()->data_segments.size()); EXPECT_EQ(0u, result.value()->data_segments.size());
const WasmGlobal* global = &result.value()->globals[0]; const WasmGlobal* global = &result.value()->globals[0];
EXPECT_EQ(kWasmAnyRef, global->type); EXPECT_EQ(kWasmExternRef, global->type);
EXPECT_FALSE(global->mutability); EXPECT_FALSE(global->mutability);
global = &result.value()->globals[1]; global = &result.value()->globals[1];
...@@ -407,12 +408,12 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobalWithGlobalInit) { ...@@ -407,12 +408,12 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobalWithGlobalInit) {
ADD_COUNT('m'), // module name ADD_COUNT('m'), // module name
ADD_COUNT('f'), // global name ADD_COUNT('f'), // global name
kExternalGlobal, // import kind kExternalGlobal, // import kind
kAnyRefCode, // type kExternRefCode, // type
0), // mutability 0), // mutability
SECTION(Global, // -- SECTION(Global, // --
ENTRY_COUNT(1), ENTRY_COUNT(1),
kAnyRefCode, // local type kExternRefCode, // local type
0, // immutable 0, // immutable
WASM_INIT_EXPR_GLOBAL(0)), WASM_INIT_EXPR_GLOBAL(0)),
}; };
...@@ -426,7 +427,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobalWithGlobalInit) { ...@@ -426,7 +427,7 @@ TEST_F(WasmModuleVerifyTest, ExternRefGlobalWithGlobalInit) {
const WasmGlobal* global = &result.value()->globals.back(); const WasmGlobal* global = &result.value()->globals.back();
EXPECT_EQ(kWasmAnyRef, global->type); EXPECT_EQ(kWasmExternRef, global->type);
EXPECT_FALSE(global->mutability); EXPECT_FALSE(global->mutability);
} }
} }
...@@ -438,12 +439,12 @@ TEST_F(WasmModuleVerifyTest, NullGlobalWithGlobalInit) { ...@@ -438,12 +439,12 @@ TEST_F(WasmModuleVerifyTest, NullGlobalWithGlobalInit) {
ADD_COUNT('m'), // module name ADD_COUNT('m'), // module name
ADD_COUNT('n'), // global name ADD_COUNT('n'), // global name
kExternalGlobal, // import kind kExternalGlobal, // import kind
kAnyRefCode, // type kExternRefCode, // type
0), // mutability 0), // mutability
SECTION(Global, // -- SECTION(Global, // --
ENTRY_COUNT(1), ENTRY_COUNT(1),
kAnyRefCode, // local type kExternRefCode, // local type
0, // immutable 0, // immutable
WASM_INIT_EXPR_GLOBAL(0)), WASM_INIT_EXPR_GLOBAL(0)),
}; };
...@@ -458,7 +459,7 @@ TEST_F(WasmModuleVerifyTest, NullGlobalWithGlobalInit) { ...@@ -458,7 +459,7 @@ TEST_F(WasmModuleVerifyTest, NullGlobalWithGlobalInit) {
const WasmGlobal* global = &result.value()->globals.back(); const WasmGlobal* global = &result.value()->globals.back();
EXPECT_EQ(kWasmAnyRef, global->type); EXPECT_EQ(kWasmExternRef, global->type);
EXPECT_FALSE(global->mutability); EXPECT_FALSE(global->mutability);
} }
} }
...@@ -1812,7 +1813,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionInitExternRefTableWithFuncRef) { ...@@ -1812,7 +1813,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionInitExternRefTableWithFuncRef) {
ONE_EMPTY_FUNCTION(SIG_INDEX(0)), ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
// table declaration --------------------------------------------------- // table declaration ---------------------------------------------------
SECTION(Table, ENTRY_COUNT(2), // section header SECTION(Table, ENTRY_COUNT(2), // section header
kAnyRefCode, 0, 5, // table 0 kExternRefCode, 0, 5, // table 0
kFuncRefCode, 0, 9), // table 1 kFuncRefCode, 0, 9), // table 1
// elements ------------------------------------------------------------ // elements ------------------------------------------------------------
SECTION(Element, SECTION(Element,
...@@ -1892,7 +1893,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionDontInitExternRefImportedTable) { ...@@ -1892,7 +1893,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionDontInitExternRefImportedTable) {
ADD_COUNT('m'), // module name ADD_COUNT('m'), // module name
ADD_COUNT('s'), // table name ADD_COUNT('s'), // table name
kExternalTable, // import kind kExternalTable, // import kind
kAnyRefCode, // elem_type kExternRefCode, // elem_type
0, // no maximum field 0, // no maximum field
10), // initial size 10), // initial size
// funcs --------------------------------------------------------------- // funcs ---------------------------------------------------------------
...@@ -2017,7 +2018,7 @@ TEST_F(WasmModuleVerifyTest, MultipleTables) { ...@@ -2017,7 +2018,7 @@ TEST_F(WasmModuleVerifyTest, MultipleTables) {
kFuncRefCode, // table 1: type kFuncRefCode, // table 1: type
0, // table 1: no maximum 0, // table 1: no maximum
10, // table 1: minimum size 10, // table 1: minimum size
kAnyRefCode, // table 2: type kExternRefCode, // table 2: type
0, // table 2: no maximum 0, // table 2: no maximum
11), // table 2: minimum size 11), // table 2: minimum size
}; };
...@@ -2031,7 +2032,7 @@ TEST_F(WasmModuleVerifyTest, MultipleTables) { ...@@ -2031,7 +2032,7 @@ TEST_F(WasmModuleVerifyTest, MultipleTables) {
EXPECT_EQ(kWasmFuncRef, result.value()->tables[0].type); EXPECT_EQ(kWasmFuncRef, result.value()->tables[0].type);
EXPECT_EQ(11u, result.value()->tables[1].initial_size); 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) { TEST_F(WasmModuleVerifyTest, TypedFunctionTable) {
...@@ -2224,7 +2225,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_v) { ...@@ -2224,7 +2225,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_v) {
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
const FunctionSig* sig = DecodeSig(data, data + sizeof(data)); 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->parameter_count());
EXPECT_EQ(0u, sig->return_count()); EXPECT_EQ(0u, sig->return_count());
} }
...@@ -2235,7 +2236,8 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_v) { ...@@ -2235,7 +2236,8 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
const byte data[] = {SIG_ENTRY_x(ret_type.code)}; const byte data[] = {SIG_ENTRY_x(ret_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data)); 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(0u, sig->parameter_count());
EXPECT_EQ(1u, sig->return_count()); EXPECT_EQ(1u, sig->return_count());
EXPECT_EQ(ret_type.type, sig->GetReturn()); EXPECT_EQ(ret_type.type, sig->GetReturn());
...@@ -2248,7 +2250,8 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_t) { ...@@ -2248,7 +2250,8 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
const byte data[] = {SIG_ENTRY_v_x(param_type.code)}; const byte data[] = {SIG_ENTRY_v_x(param_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data)); 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->parameter_count());
EXPECT_EQ(0u, sig->return_count()); EXPECT_EQ(0u, sig->return_count());
EXPECT_EQ(param_type.type, sig->GetParam(0)); EXPECT_EQ(param_type.type, sig->GetParam(0));
...@@ -2263,7 +2266,8 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_t) { ...@@ -2263,7 +2266,8 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)}; const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data)); 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->parameter_count());
EXPECT_EQ(1u, sig->return_count()); EXPECT_EQ(1u, sig->return_count());
EXPECT_EQ(param_type.type, sig->GetParam(0)); EXPECT_EQ(param_type.type, sig->GetParam(0));
...@@ -2281,7 +2285,9 @@ TEST_F(WasmSignatureDecodeTest, Ok_i_tt) { ...@@ -2281,7 +2285,9 @@ TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
SIG_ENTRY_x_xx(kI32Code, p0_type.code, p1_type.code)}; SIG_ENTRY_x_xx(kI32Code, p0_type.code, p1_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data)); 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(2u, sig->parameter_count());
EXPECT_EQ(1u, sig->return_count()); EXPECT_EQ(1u, sig->return_count());
EXPECT_EQ(p0_type.type, sig->GetParam(0)); EXPECT_EQ(p0_type.type, sig->GetParam(0));
...@@ -2299,7 +2305,9 @@ TEST_F(WasmSignatureDecodeTest, Ok_tt_tt) { ...@@ -2299,7 +2305,9 @@ TEST_F(WasmSignatureDecodeTest, Ok_tt_tt) {
p0_type.code, p1_type.code)}; p0_type.code, p1_type.code)};
const FunctionSig* sig = DecodeSig(data, data + sizeof(data)); 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->parameter_count());
EXPECT_EQ(2u, sig->return_count()); EXPECT_EQ(2u, sig->return_count());
EXPECT_EQ(p0_type.type, sig->GetParam(0)); EXPECT_EQ(p0_type.type, sig->GetParam(0));
...@@ -3156,7 +3164,7 @@ TEST_F(WasmModuleVerifyTest, PassiveElementSegmentExternRef) { ...@@ -3156,7 +3164,7 @@ TEST_F(WasmModuleVerifyTest, PassiveElementSegmentExternRef) {
// table declaration ----------------------------------------------------- // table declaration -----------------------------------------------------
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1), SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
// element segments ----------------------------------------------------- // element segments -----------------------------------------------------
SECTION(Element, ENTRY_COUNT(1), PASSIVE_WITH_ELEMENTS, kAnyRefCode, SECTION(Element, ENTRY_COUNT(1), PASSIVE_WITH_ELEMENTS, kExternRefCode,
U32V_1(0)), U32V_1(0)),
// code ------------------------------------------------------------------ // code ------------------------------------------------------------------
ONE_EMPTY_BODY}; ONE_EMPTY_BODY};
......
...@@ -213,6 +213,9 @@ TEST_F(WasmSubtypingTest, Subtyping) { ...@@ -213,6 +213,9 @@ TEST_F(WasmSubtypingTest, Subtyping) {
SUBTYPE(ref_type, kWasmAnyRef); SUBTYPE(ref_type, kWasmAnyRef);
// Only anyref is a subtype of anyref. // Only anyref is a subtype of anyref.
SUBTYPE_IFF(kWasmAnyRef, ref_type, ref_type == kWasmAnyRef); 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. // Each nullable reference type is a supertype of nullref.
SUBTYPE_IFF(kWasmNullRef, ref_type, ref_type.is_nullable()); SUBTYPE_IFF(kWasmNullRef, ref_type, ref_type.is_nullable());
// Only nullref is a subtype of nullref. // Only nullref is a subtype of nullref.
......
...@@ -22,7 +22,7 @@ TEST_F(WasmCallDescriptorTest, TestExternRefIsGrouped) { ...@@ -22,7 +22,7 @@ TEST_F(WasmCallDescriptorTest, TestExternRefIsGrouped) {
ValueType params[kMaxCount]; ValueType params[kMaxCount];
for (size_t i = 0; i < kMaxCount; i += 2) { for (size_t i = 0; i < kMaxCount; i += 2) {
params[i] = kWasmAnyRef; params[i] = kWasmExternRef;
EXPECT_TRUE(i + 1 < kMaxCount); EXPECT_TRUE(i + 1 < kMaxCount);
params[i + 1] = kWasmI32; params[i + 1] = kWasmI32;
} }
......
...@@ -188,9 +188,9 @@ TEST_F(WasmCapiTest, DirectCallCapiFunction) { ...@@ -188,9 +188,9 @@ TEST_F(WasmCapiTest, DirectCallCapiFunction) {
ValType::make(::wasm::ANYREF))); ValType::make(::wasm::ANYREF)));
own<Func> func = Func::make(store(), cpp_sig.get(), PlusOne); own<Func> func = Func::make(store(), cpp_sig.get(), PlusOne);
Extern* imports[] = {func.get()}; Extern* imports[] = {func.get()};
ValueType wasm_types[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64, ValueType wasm_types[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64,
kWasmAnyRef, kWasmI32, kWasmI64, kWasmF32, kWasmExternRef, kWasmI32, kWasmI64, kWasmF32,
kWasmF64, kWasmAnyRef}; kWasmF64, kWasmExternRef};
FunctionSig wasm_sig(5, 5, wasm_types); FunctionSig wasm_sig(5, 5, wasm_types);
int func_index = builder()->AddImport(base::CStrVector("func"), &wasm_sig); int func_index = builder()->AddImport(base::CStrVector("func"), &wasm_sig);
builder()->ExportImportedFunction(base::CStrVector("func"), func_index); builder()->ExportImportedFunction(base::CStrVector("func"), func_index);
......
...@@ -23,9 +23,9 @@ own<Trap> IdentityCallback(const Val args[], Val results[]) { ...@@ -23,9 +23,9 @@ own<Trap> IdentityCallback(const Val args[], Val results[]) {
} // namespace } // namespace
TEST_F(WasmCapiTest, HostRef) { TEST_F(WasmCapiTest, HostRef) {
ValueType rr_reps[] = {kWasmAnyRef, kWasmAnyRef}; ValueType rr_reps[] = {kWasmExternRef, kWasmExternRef};
ValueType ri_reps[] = {kWasmAnyRef, kWasmI32}; ValueType ri_reps[] = {kWasmExternRef, kWasmI32};
ValueType ir_reps[] = {kWasmI32, kWasmAnyRef}; ValueType ir_reps[] = {kWasmI32, kWasmExternRef};
// Naming convention: result_params_sig. // Naming convention: result_params_sig.
FunctionSig r_r_sig(1, 1, rr_reps); FunctionSig r_r_sig(1, 1, rr_reps);
FunctionSig v_r_sig(0, 1, rr_reps); FunctionSig v_r_sig(0, 1, rr_reps);
...@@ -35,9 +35,9 @@ TEST_F(WasmCapiTest, HostRef) { ...@@ -35,9 +35,9 @@ TEST_F(WasmCapiTest, HostRef) {
uint32_t func_index = builder()->AddImport(base::CStrVector("f"), &r_r_sig); uint32_t func_index = builder()->AddImport(base::CStrVector("f"), &r_r_sig);
const bool kMutable = true; const bool kMutable = true;
uint32_t global_index = builder()->AddExportedGlobal( uint32_t global_index = builder()->AddExportedGlobal(
kWasmAnyRef, kMutable, WasmInitExpr::RefNullConst(HeapType::kAny), kWasmExternRef, kMutable, WasmInitExpr::RefNullConst(HeapType::kExtern),
base::CStrVector("global")); 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); builder()->AddExport(base::CStrVector("table"), kExternalTable, table_index);
byte global_set_code[] = {WASM_GLOBAL_SET(global_index, WASM_LOCAL_GET(0))}; byte global_set_code[] = {WASM_GLOBAL_SET(global_index, WASM_LOCAL_GET(0))};
AddExportedFunction(base::CStrVector("global.set"), global_set_code, AddExportedFunction(base::CStrVector("global.set"), global_set_code,
......
...@@ -35,8 +35,8 @@ void ExpectName(const char* expected, const ::wasm::Name& name) { ...@@ -35,8 +35,8 @@ void ExpectName(const char* expected, const ::wasm::Name& name) {
TEST_F(WasmCapiTest, Reflect) { TEST_F(WasmCapiTest, Reflect) {
// Create a module exporting a function, a global, a table, and a memory. // Create a module exporting a function, a global, a table, and a memory.
byte code[] = {WASM_UNREACHABLE}; byte code[] = {WASM_UNREACHABLE};
ValueType types[] = {kWasmI32, kWasmAnyRef, kWasmI32, ValueType types[] = {kWasmI32, kWasmExternRef, kWasmI32,
kWasmI64, kWasmF32, kWasmF64}; kWasmI64, kWasmF32, kWasmF64};
FunctionSig sig(2, 4, types); FunctionSig sig(2, 4, types);
AddExportedFunction(base::CStrVector(kFuncName), code, sizeof(code), &sig); 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