Skip to content

Commit

Permalink
Bug 1730188 - wasm: Fix Table.type method to report type as RefType i…
Browse files Browse the repository at this point in the history
…nstead of TableRepr. r=lth

We should report the precise RefType that a table has, not the
flattened TableRepr.

Depends on D125225

Differential Revision: https://phabricator.services.mozilla.com/D125226
  • Loading branch information
eqrion committed Sep 14, 2021
1 parent 9fb97a0 commit 5d8b82a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
24 changes: 6 additions & 18 deletions js/src/wasm/WasmJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3076,26 +3076,14 @@ static bool ToTableIndex(JSContext* cx, HandleValue v, const Table& table,
#ifdef ENABLE_WASM_TYPE_REFLECTIONS
/* static */
bool WasmTableObject::typeImpl(JSContext* cx, const CallArgs& args) {
Rooted<IdValueVector> props(cx, IdValueVector(cx));
Table& table = args.thisv().toObject().as<WasmTableObject>().table();

const char* elementValue;
switch (table.repr()) {
case TableRepr::Func:
elementValue = "funcref";
break;
case TableRepr::Ref:
elementValue = "externref";
break;
default:
MOZ_CRASH("Should not happen");
}
JSString* elementString = UTF8CharsToString(cx, elementValue);
if (!elementString) {
return false;
}
if (!props.append(IdValuePair(NameToId(cx->names().element),
StringValue(elementString)))) {
Rooted<IdValueVector> props(cx, IdValueVector(cx));

RootedString elementType(
cx, UTF8CharsToString(cx, ToString(table.elemType()).get()));
if (!elementType || !props.append(IdValuePair(NameToId(cx->names().element),
StringValue(elementType)))) {
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions js/src/wasm/WasmValType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ bool wasm::ToValType(JSContext* cx, HandleValue v, ValType* out) {
return true;
}

UniqueChars wasm::ToString(RefType type) { return ToString(ValType(type)); }

UniqueChars wasm::ToString(ValType type) {
const char* literal = nullptr;
switch (type.kind()) {
Expand Down
2 changes: 2 additions & 0 deletions js/src/wasm/WasmValType.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ static inline jit::MIRType ToMIRType(const Maybe<ValType>& t) {

extern bool ToValType(JSContext* cx, HandleValue v, ValType* out);

extern UniqueChars ToString(RefType type);

extern UniqueChars ToString(ValType type);

extern UniqueChars ToString(const Maybe<ValType>& type);
Expand Down

0 comments on commit 5d8b82a

Please sign in to comment.