Enter a scope before calling Dart APIs in ThrowIfUIOperationsProhibited (flutter/engine#37226)
This commit is contained in:
@@ -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."));
|
||||
}
|
||||
|
||||
@@ -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.');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user