Open
Description
import 'dart:js_interop';
@JS()
external void eval(String code);
@JS()
external void throwFunction();
void main() {
eval('''
self.throwFunction = function() {
throw new Error('hello world');
}
''');
try {
throwFunction();
} on JSObject catch (e) {
print(e);
}
}
DDC and dart2js catch the JS error as it is a subtype of interceptors.JavaScriptObject
(and therefore a subtype of JSObject
). dart2wasm does not, as its implementation of JS errors is not a subtype of JSObject
:
JSValue
, but it's not clear if a Wasm instruction exists to convert the error to an externref
that can then be boxed. Making this a subtype of JSValue
also has the other issue that if we replaced JSObject
with JSString
, dart2wasm would catch the error (because JSString
is a JSValue
) whereas DDC and dart2js will not.
For now, users should avoid catching JS errors using an interop type for consistency.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status