51c73837b0
Currently when we catch an exception thrown from JS we assume that it's an `Error`, with a `stack` property. This causes crashes when the exception value is not an `Error`, and the behavior is also inconsistent with dart2js, which returns an empty stack trace. This fixes the crash and makes the behavior consistent with dart2js. To make sure the behavior stays consistent, the relevant test is updated and moved from a dart2wasm-specific directory to a web directory. Change-Id: Ic6af7d919678ba585854c6531a103c0a5764e099 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478400 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Ömer Ağacan <omersa@google.com>
43 lines
883 B
Dart
43 lines
883 B
Dart
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:js_interop';
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
@JS()
|
|
external void eval(String code);
|
|
|
|
@JS()
|
|
external void throwError();
|
|
|
|
@JS()
|
|
external void throwNonError();
|
|
|
|
void main() {
|
|
eval('''
|
|
self.throwNonError = function() {
|
|
throw 'Hi from JS';
|
|
}
|
|
|
|
self.throwError = function() {
|
|
throw new Error('Hi from JS');
|
|
}
|
|
''');
|
|
|
|
try {
|
|
throwError();
|
|
} catch (e, st) {
|
|
Expect.isTrue(e.toString().contains('Hi from JS'));
|
|
Expect.isTrue(st.toString().isNotEmpty);
|
|
}
|
|
|
|
try {
|
|
throwNonError();
|
|
} catch (e, st) {
|
|
Expect.isTrue(e.toString().contains('Hi from JS'));
|
|
Expect.isTrue(st.toString().isEmpty);
|
|
}
|
|
}
|