Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b68e8dd

Browse files
committed
Enter a scope before calling Dart APIs in ThrowIfUIOperationsProhibited
Fixes flutter/flutter#114138
1 parent 88a0a56 commit b68e8dd

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/ui/ui_dart_state.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void UIDartState::DidSetIsolate() {
9797

9898
void UIDartState::ThrowIfUIOperationsProhibited() {
9999
if (!UIDartState::Current()->IsRootIsolate()) {
100+
Dart_EnterScope();
100101
Dart_ThrowException(
101102
tonic::ToDart("UI actions are only available on root isolate."));
102103
}

testing/dart/isolate_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'dart:isolate';
6+
import 'dart:ui';
67

78
import 'package:litetest/litetest.dart';
89

@@ -20,4 +21,14 @@ void main() {
2021
}
2122
expect(threw, true);
2223
});
24+
25+
test('UI isolate API throws in a background isolate', () async {
26+
void callUiApi(void message) {
27+
PlatformDispatcher.instance.onReportTimings = (_) {};
28+
}
29+
final ReceivePort errorPort = ReceivePort();
30+
await Isolate.spawn<void>(callUiApi, null, onError: errorPort.sendPort);
31+
final List<dynamic> isolateError = await errorPort.first as List<dynamic>;
32+
expect(isolateError[0], 'UI actions are only available on root isolate.');
33+
});
2334
}

0 commit comments

Comments
 (0)