-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
area-dart2wasmIssues for the dart2wasm compiler.Issues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interopIssues that impact all js interop
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
:
class _JavaScriptError extends Error { |
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
area-dart2wasmIssues for the dart2wasm compiler.Issues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interopIssues that impact all js interop
Type
Projects
Status
No status