Skip to content

Commit 7198f0e

Browse files
authored
Fix JS tag fuzzing: throw the same in JS and the binaryen interpreter (#7286)
We do not compare exceptions in binaryen (not in the optimizer, where we assume we can reorder traps, and not in the fuzzer, where we assume VMs may have different text for them). But, since we have try-catch in wasm, we can actually end up comparing them, by catching the exception and logging the output. For that reason, we need to throw exactly the same JS exception in #7283, which this fixes.
1 parent 57c9c25 commit 7198f0e

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

scripts/fuzz_shell.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,10 @@ var imports = {
270270
// Throw an exception from JS.
271271
'throw': (which) => {
272272
if (!which) {
273-
throw 'some JS error';
273+
// Throw a JS exception.
274+
throw 0;
274275
} else {
276+
// Throw a wasm exception.
275277
throw new WebAssembly.Exception(wasmTag, [which]);
276278
}
277279
},

src/tools/execution-results.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ struct LoggingExternalInterface : public ShellExternalInterface {
182182

183183
void throwJSException() {
184184
// JS exceptions contain an externref, which wasm can't read (so the actual
185-
// value here does not matter).
185+
// value here does not matter, but it does need to match what the 'throw'
186+
// import does in fuzz_shell.js, as the fuzzer will do comparisons).
186187
Literal externref = Literal::makeI31(0, Unshared).externalize();
187188
Literals arguments = {externref};
188189
auto payload = std::make_shared<ExnData>(jsTag, arguments);

test/lit/d8/fuzz_shell_exceptions.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
;; RUN: v8 %S/../../../scripts/fuzz_shell.js -- %t.wasm | filecheck %s
3232
;;
3333
;; CHECK: [fuzz-exec] calling throwing-js
34-
;; CHECK: exception thrown: some JS error
34+
;; CHECK: exception thrown: 0
3535
;; CHECK: [fuzz-exec] calling throwing-tag
3636
;; CHECK: exception thrown: [object WebAssembly.Exception]
3737

0 commit comments

Comments
 (0)