diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc index 676df30e42..b65db60154 100644 --- a/src/wasm/wasm-js.cc +++ b/src/wasm/wasm-js.cc @@ -2046,10 +2046,20 @@ void WebAssemblyExceptionGetArg( } auto maybe_values = i::WasmExceptionPackage::GetExceptionValues(i_isolate, exception); - if (maybe_values->IsUndefined()) { + + auto this_tag = + i::WasmExceptionPackage::GetExceptionTag(i_isolate, exception); + if (this_tag->IsUndefined()) { thrower.TypeError("Expected a WebAssembly.Exception object"); return; } + DCHECK(this_tag->IsWasmExceptionTag()); + if (tag->tag() != *this_tag) { + thrower.TypeError("First argument does not match the exception tag"); + return; + } + + DCHECK(!maybe_values->IsUndefined()); auto values = i::Handle::cast(maybe_values); auto signature = tag->serialized_signature(); if (index >= static_cast(signature.length())) { diff --git a/test/mjsunit/wasm/exceptions-api.js b/test/mjsunit/wasm/exceptions-api.js index 8d21f40a8e..29d3de0602 100644 --- a/test/mjsunit/wasm/exceptions-api.js +++ b/test/mjsunit/wasm/exceptions-api.js @@ -211,6 +211,9 @@ function TestGetArgHelper(types_str, types, values) { /Index must be convertible to a valid number/); assertThrows(() => exception.getArg(tag, 0xFFFFFFFF), RangeError, /Index out of range/); + let wrong_tag = new WebAssembly.Tag({parameters: ['i32']}); + assertThrows(() => exception.getArg(wrong_tag, 0), TypeError, + /First argument does not match the exception tag/); // Check decoding. TestGetArgHelper(['i32'], [kWasmI32], [1]);