652565b083
In `_JavaScriptError`, instead of using `toString` method of the caught objects, use the `String` constructor. Fixes crashes when printing `null` and `undefined` exception values. This is not directly related to #55481, but the issue was caught while working on it. Change-Id: Id6f7124730b4ffa125bd9d0fc8bcf3ed4de15a81 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478367 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Ömer Ağacan <omersa@google.com>
71 lines
1.3 KiB
Dart
71 lines
1.3 KiB
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();
|
|
|
|
@JS()
|
|
external void throwNull();
|
|
|
|
@JS()
|
|
external void throwUndefined();
|
|
|
|
void main() {
|
|
eval('''
|
|
self.throwNonError = function() {
|
|
throw 'Hi from JS';
|
|
}
|
|
|
|
self.throwError = function() {
|
|
throw new Error('Hi from JS');
|
|
}
|
|
|
|
self.throwNull = function() {
|
|
throw null;
|
|
}
|
|
|
|
self.throwUndefined = function() {
|
|
throw undefined;
|
|
}
|
|
''');
|
|
|
|
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);
|
|
}
|
|
|
|
try {
|
|
throwNull();
|
|
} catch (e, st) {
|
|
Expect.isTrue(e.toString().contains('null'));
|
|
Expect.isTrue(st.toString().isEmpty);
|
|
}
|
|
|
|
try {
|
|
throwUndefined();
|
|
} catch (e, st) {
|
|
Expect.isTrue(e.toString().contains('undefined'));
|
|
Expect.isTrue(st.toString().isEmpty);
|
|
}
|
|
}
|