Skip to content

Commit afcb387

Browse files
authored
[Strings] Emit unreachable when a string instruction cannot be emitted properly (#6415)
See WebAssembly/stringref#66
1 parent b1535da commit afcb387

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/wasm/wasm-stack.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,14 @@ void BinaryInstWriter::visitRefAs(RefAs* curr) {
22932293
}
22942294

22952295
void BinaryInstWriter::visitStringNew(StringNew* curr) {
2296+
if (curr->ptr->type.isNull()) {
2297+
// This is a bottom type, so this is an array-receiving operation that does
2298+
// not receive an array. The spec allows this, but V8 does not, see
2299+
// https://github.com/WebAssembly/stringref/issues/66
2300+
// For now, just emit an unreachable here as this will definitely trap.
2301+
emitUnreachable();
2302+
return;
2303+
}
22962304
o << int8_t(BinaryConsts::GCPrefix);
22972305
switch (curr->op) {
22982306
case StringNewUTF8:
@@ -2371,6 +2379,11 @@ void BinaryInstWriter::visitStringMeasure(StringMeasure* curr) {
23712379
}
23722380

23732381
void BinaryInstWriter::visitStringEncode(StringEncode* curr) {
2382+
if (curr->ptr->type.isNull()) {
2383+
// See visitStringNew.
2384+
emitUnreachable();
2385+
return;
2386+
}
23742387
o << int8_t(BinaryConsts::GCPrefix);
23752388
switch (curr->op) {
23762389
case StringEncodeUTF8:

0 commit comments

Comments
 (0)