Skip to content

Fix JS tag fuzzing: throw the same in JS and the binaryen interpreter #7286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/fuzz_shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ var imports = {
// Throw an exception from JS.
'throw': (which) => {
if (!which) {
throw 'some JS error';
// Throw a JS exception.
throw 0;
} else {
// Throw a wasm exception.
throw new WebAssembly.Exception(wasmTag, [which]);
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/tools/execution-results.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ struct LoggingExternalInterface : public ShellExternalInterface {

void throwJSException() {
// JS exceptions contain an externref, which wasm can't read (so the actual
// value here does not matter).
// value here does not matter, but it does need to match what the 'throw'
// import does in fuzz_shell.js, as the fuzzer will do comparisons).
Literal externref = Literal::makeI31(0, Unshared).externalize();
Literals arguments = {externref};
auto payload = std::make_shared<ExnData>(jsTag, arguments);
Expand Down
2 changes: 1 addition & 1 deletion test/lit/d8/fuzz_shell_exceptions.wast
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
;; RUN: v8 %S/../../../scripts/fuzz_shell.js -- %t.wasm | filecheck %s
;;
;; CHECK: [fuzz-exec] calling throwing-js
;; CHECK: exception thrown: some JS error
;; CHECK: exception thrown: 0
;; CHECK: [fuzz-exec] calling throwing-tag
;; CHECK: exception thrown: [object WebAssembly.Exception]

Expand Down