Skip to content

Commit 6376164

Browse files
tetsuharuohzekisosukesuzuki
authored andcommitted
[JSC] Error.isError(WebAssembly.Exception) should be false
https://bugs.webkit.org/show_bug.cgi?id=304410 Reviewed by Yusuke Suzuki and Sosuke Suzuki. According to the spec discussion, the current `WebAssembly.Exception` does not have `[[ErrorData]]` semantically. So `Error.isError(WebAssembly.Exception)` should be `false`. - WebAssembly/spec#1914 - https://webassembly.github.io/spec/js-api/#exceptions Test: JSTests/wasm/stress/exception-thrown-out-of-wasm-integration-error-is-error.js * JSTests/wasm/stress/exception-thrown-out-of-wasm-integration-error-is-error.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.catch): * Source/JavaScriptCore/wasm/js/JSWebAssemblyException.cpp: (JSC::JSWebAssemblyException::createStructure): Canonical link: https://commits.webkit.org/304917@main
1 parent 45d2ff0 commit 6376164

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Builder from '../Builder.js'
2+
import * as assert from '../assert.js'
3+
4+
{
5+
const b = new Builder();
6+
b.Type().End()
7+
.Function().End()
8+
.Exception().Signature({ params: [] }).End()
9+
.Export().Function("call")
10+
.Exception("foo", 0)
11+
.End()
12+
.Code()
13+
.Function("call", { params: [], ret: "i32" })
14+
.Throw(0)
15+
.I32Const(1)
16+
.End()
17+
.End()
18+
19+
const bin = b.WebAssembly().get();
20+
const module = new WebAssembly.Module(bin);
21+
const instance = new WebAssembly.Instance(module);
22+
23+
let hasCaught = false;
24+
try {
25+
instance.exports.call();
26+
} catch (e) {
27+
hasCaught = true;
28+
assert.instanceof(e, WebAssembly.Exception, 'must be an instance of WebAssembly.Exception');
29+
// By the current (22 November 2025) spec semantics, `WebAssembly.Exception` does not have `[[ErrorData]]` in ECMA262 concept.
30+
// This means `Error.isError(<a instance of WebAssembly.Exception>)` should be `false`.
31+
//
32+
// - https://webassembly.github.io/spec/js-api/#exceptions
33+
// - https://github.com/WebAssembly/spec/issues/1914
34+
// - https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-properties-of-error-instances
35+
assert.eq(Error.isError(e), false, 'Error.isError(WebAssembly.Exception) should be false');
36+
}
37+
38+
assert.truthy(hasCaught, 'expected assertion was not called');
39+
}

Source/JavaScriptCore/wasm/js/JSWebAssemblyException.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const ClassInfo JSWebAssemblyException::s_info = { "WebAssembly.Exception"_s, &B
4545

4646
Structure* JSWebAssemblyException::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
4747
{
48-
return Structure::create(vm, globalObject, prototype, TypeInfo(ErrorInstanceType, StructureFlags), info());
48+
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
4949
}
5050

5151
JSWebAssemblyException::JSWebAssemblyException(VM& vm, Structure* structure, Ref<const Wasm::Tag>&& tag, FixedVector<uint64_t>&& payload)

0 commit comments

Comments
 (0)