Enter a scope before calling Dart APIs in ThrowIfUIOperationsProhibited (flutter/engine#37226)

This commit is contained in:
Jason Simmons
2022-11-02 19:14:38 -07:00
committed by GitHub
parent b775d084e7
commit 17bcea458b
2 changed files with 12 additions and 0 deletions

View File

@@ -97,6 +97,7 @@ void UIDartState::DidSetIsolate() {
void UIDartState::ThrowIfUIOperationsProhibited() {
if (!UIDartState::Current()->IsRootIsolate()) {
Dart_EnterScope();
Dart_ThrowException(
tonic::ToDart("UI actions are only available on root isolate."));
}

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:isolate';
import 'dart:ui';
import 'package:litetest/litetest.dart';
@@ -20,4 +21,14 @@ void main() {
}
expect(threw, true);
});
test('UI isolate API throws in a background isolate', () async {
void callUiApi(void message) {
PlatformDispatcher.instance.onReportTimings = (_) {};
}
final ReceivePort errorPort = ReceivePort();
await Isolate.spawn<void>(callUiApi, null, onError: errorPort.sendPort);
final List<dynamic> isolateError = await errorPort.first as List<dynamic>;
expect(isolateError[0], 'UI actions are only available on root isolate.');
});
}