Skip to content

Commit 088b178

Browse files
aamCommit Queue
authored and
Commit Queue
committed
[vm/isolates] Ensure removeErrorListener makes exceptions unhandled.
BUG=#53850 TEST=lib/isolate/remove_error_listener_test Change-Id: I442ea403671cd42275a2a420c2cb234c2c5fa126 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335321 Commit-Queue: Alexander Aprelev <aam@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
1 parent 1ecc1ba commit 088b178

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

runtime/vm/isolate.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,14 +2305,16 @@ bool Isolate::NotifyErrorListeners(const char* message,
23052305
arr_values[1] = &stack;
23062306

23072307
SendPort& listener = SendPort::Handle(current_zone());
2308+
bool was_somebody_notified = false;
23082309
for (intptr_t i = 0; i < listeners.Length(); i++) {
23092310
listener ^= listeners.At(i);
23102311
if (!listener.IsNull()) {
23112312
Dart_Port port_id = listener.Id();
23122313
PortMap::PostMessage(SerializeMessage(current_zone(), port_id, &arr));
2314+
was_somebody_notified = true;
23132315
}
23142316
}
2315-
return listeners.Length() > 0;
2317+
return was_somebody_notified;
23162318
}
23172319

23182320
static void ShutdownIsolate(uword parameter) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// Test that removing error listener makes exception throwing unhandled.
6+
7+
import 'dart:io';
8+
import 'dart:isolate';
9+
10+
import "package:expect/expect.dart";
11+
12+
void main(List<String> args) {
13+
if (args.length == 0) {
14+
final result = Process.runSync(Platform.executable, [
15+
...Platform.executableArguments,
16+
Platform.script.toFilePath(),
17+
'child'
18+
]);
19+
Expect.isTrue(
20+
result.stderr.contains("Unhandled exception:\nException: Oops!"));
21+
return;
22+
}
23+
{
24+
final port = ReceivePort();
25+
Isolate.current.addErrorListener(port.sendPort);
26+
Isolate.current.removeErrorListener(port.sendPort);
27+
port.close();
28+
throw Exception('Oops!');
29+
}
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// @dart = 2.9
6+
//
7+
// Test that removing error listener makes exception throwing unhandled.
8+
9+
import 'dart:io';
10+
import 'dart:isolate';
11+
12+
import "package:expect/expect.dart";
13+
14+
void main(List<String> args) {
15+
if (args.length == 0) {
16+
final result = Process.runSync(Platform.executable, [
17+
...Platform.executableArguments,
18+
Platform.script.toFilePath(),
19+
'child'
20+
]);
21+
Expect.isTrue(
22+
result.stderr.contains("Unhandled exception:\nException: Oops!"));
23+
return;
24+
}
25+
{
26+
final port = ReceivePort();
27+
Isolate.current.addErrorListener(port.sendPort);
28+
Isolate.current.removeErrorListener(port.sendPort);
29+
port.close();
30+
throw Exception('Oops!');
31+
}
32+
}

0 commit comments

Comments
 (0)