diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 12 | ||||
-rw-r--r-- | src/wasm/wasm-stack.cpp | 31 |
2 files changed, 31 insertions, 12 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 0b4a3d2f4..5399be0b7 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -6984,6 +6984,9 @@ bool WasmBinaryBuilder::maybeVisitStringNew(Expression*& out, uint32_t code) { Expression* start = nullptr; Expression* end = nullptr; if (code == BinaryConsts::StringNewWTF8) { + if (getInt8() != 0) { + throwError("Unexpected nonzero memory index"); + } auto policy = getU32LEB(); switch (policy) { case BinaryConsts::StringPolicy::UTF8: @@ -7000,6 +7003,9 @@ bool WasmBinaryBuilder::maybeVisitStringNew(Expression*& out, uint32_t code) { } length = popNonVoidExpression(); } else if (code == BinaryConsts::StringNewWTF16) { + if (getInt8() != 0) { + throwError("Unexpected nonzero memory index"); + } op = StringNewWTF16; length = popNonVoidExpression(); } else if (code == BinaryConsts::StringNewWTF8Array) { @@ -7080,6 +7086,9 @@ bool WasmBinaryBuilder::maybeVisitStringEncode(Expression*& out, Expression* start = nullptr; // TODO: share this code with string.measure? if (code == BinaryConsts::StringEncodeWTF8) { + if (getInt8() != 0) { + throwError("Unexpected nonzero memory index"); + } auto policy = getU32LEB(); switch (policy) { case BinaryConsts::StringPolicy::UTF8: @@ -7092,6 +7101,9 @@ bool WasmBinaryBuilder::maybeVisitStringEncode(Expression*& out, throwError("bad policy for string.encode"); } } else if (code == BinaryConsts::StringEncodeWTF16) { + if (getInt8() != 0) { + throwError("Unexpected nonzero memory index"); + } op = StringEncodeWTF16; } else if (code == BinaryConsts::StringEncodeWTF8Array) { auto policy = getU32LEB(); diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index 95da14c72..83586f559 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -2176,19 +2176,23 @@ void BinaryInstWriter::visitStringNew(StringNew* curr) { o << int8_t(BinaryConsts::GCPrefix); switch (curr->op) { case StringNewUTF8: - o << int8_t(BinaryConsts::StringNewWTF8) - << U32LEB(BinaryConsts::StringPolicy::UTF8); + o << int8_t(BinaryConsts::StringNewWTF8); + o << int8_t(0); // Memory index. + o << U32LEB(BinaryConsts::StringPolicy::UTF8); break; case StringNewWTF8: - o << int8_t(BinaryConsts::StringNewWTF8) - << U32LEB(BinaryConsts::StringPolicy::WTF8); + o << int8_t(BinaryConsts::StringNewWTF8); + o << int8_t(0); // Memory index. + o << U32LEB(BinaryConsts::StringPolicy::WTF8); break; case StringNewReplace: - o << int8_t(BinaryConsts::StringNewWTF8) - << U32LEB(BinaryConsts::StringPolicy::Replace); + o << int8_t(BinaryConsts::StringNewWTF8); + o << int8_t(0); // Memory index. + o << U32LEB(BinaryConsts::StringPolicy::Replace); break; case StringNewWTF16: o << int8_t(BinaryConsts::StringNewWTF16); + o << int8_t(0); // Memory index. break; case StringNewUTF8Array: o << int8_t(BinaryConsts::StringNewWTF8Array) @@ -2244,19 +2248,22 @@ void BinaryInstWriter::visitStringEncode(StringEncode* curr) { o << int8_t(BinaryConsts::GCPrefix); switch (curr->op) { case StringEncodeUTF8: - o << int8_t(BinaryConsts::StringEncodeWTF8) - << U32LEB(BinaryConsts::StringPolicy::UTF8); + o << int8_t(BinaryConsts::StringEncodeWTF8); + o << int8_t(0); // Memory index. + o << U32LEB(BinaryConsts::StringPolicy::UTF8); break; case StringEncodeWTF8: - o << int8_t(BinaryConsts::StringEncodeWTF8) - << U32LEB(BinaryConsts::StringPolicy::WTF8); + o << int8_t(BinaryConsts::StringEncodeWTF8); + o << int8_t(0); // Memory index. + o << U32LEB(BinaryConsts::StringPolicy::WTF8); break; case StringEncodeWTF16: o << int8_t(BinaryConsts::StringEncodeWTF16); + o << int8_t(0); // Memory index. break; case StringEncodeUTF8Array: - o << int8_t(BinaryConsts::StringEncodeWTF8Array) - << U32LEB(BinaryConsts::StringPolicy::UTF8); + o << int8_t(BinaryConsts::StringEncodeWTF8Array); + o << U32LEB(BinaryConsts::StringPolicy::UTF8); break; case StringEncodeWTF8Array: o << int8_t(BinaryConsts::StringEncodeWTF8Array) |