Skip to content
Permalink
Browse files
[JSC] fix wrong text in WASM error message
https://bugs.webkit.org/show_bug.cgi?id=247280
rdar://101023980

Reviewed by Yusuke Suzuki.

Fix WASM error message for `local.get`.

* JSTests/stress/wasm-error-message-get-local.js: Added.
(shouldBe):
(async let):
* Source/JavaScriptCore/wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseIndexForLocal):

Canonical link: https://commits.webkit.org/256176@main
  • Loading branch information
Yijia Huang committed Nov 1, 2022
1 parent ddc412d commit 8ee3aa58b2a4699ea6846a28aa9ee66417c26e6e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
@@ -0,0 +1,23 @@
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}

const log = globalThis.console?.log ?? debug;

let expected = "--> CompileError: WebAssembly.Module doesn't validate: attempt to use unknown local 5, the number of locals is 5, in function at index 0";

/*
(module
(type (;0;) (func (result i64)))
(func (;0;) (type 0) (result i64)
(local i64 i64 i64 i64 i64)
local.get 5))
*/

(async function () {
let bytes = new Uint8Array([0x0, 0x61, 0x73, 0x6d, 0x1, 0x0, 0x0, 0x0, 0x1, 0x5, 0x1, 0x60, 0x0, 0x1, 0x7e, 0x3, 0x2, 0x1, 0x0, 0xa, 0x8, 0x1, 0x6, 0x1, 0x5, 0x7e, 0x20, 0x5, 0xb]);
await WebAssembly.instantiate(bytes, {});
})()
.then(() => log('bye'))
.catch(e => shouldBe(e, expected));
@@ -1078,7 +1078,7 @@ auto FunctionParser<Context>::parseIndexForLocal(uint32_t& resultIndex) -> Parti
{
uint32_t index;
WASM_PARSER_FAIL_IF(!parseVarUInt32(index), "can't get index for local");
WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to use unknown local ", index, " last one is ", m_locals.size());
WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to use unknown local ", index, ", the number of locals is ", m_locals.size());
resultIndex = index;
return { };
}
@@ -1927,7 +1927,7 @@ FOR_EACH_WASM_MEMORY_STORE_OP(CREATE_CASE)

TypedExpression value;
WASM_TRY_POP_EXPRESSION_STACK_INTO(value, "set_local");
WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to set unknown local ", index, " last one is ", m_locals.size());
WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to set unknown local ", index, ", the number of locals is ", m_locals.size());
WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), m_locals[index]), "set_local to type ", value.type().kind, " expected ", m_locals[index].kind);
WASM_TRY_ADD_TO_CONTEXT(setLocal(index, value));
return { };
@@ -1939,7 +1939,7 @@ FOR_EACH_WASM_MEMORY_STORE_OP(CREATE_CASE)

WASM_PARSER_FAIL_IF(m_expressionStack.isEmpty(), "can't tee_local on empty expression stack");
TypedExpression value = m_expressionStack.last();
WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to tee unknown local ", index, " last one is ", m_locals.size());
WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to tee unknown local ", index, ", the number of locals is ", m_locals.size());
WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), m_locals[index]), "set_local to type ", value.type().kind, " expected ", m_locals[index].kind);
WASM_TRY_ADD_TO_CONTEXT(setLocal(index, value));
return { };

0 comments on commit 8ee3aa5

Please sign in to comment.