Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added a root isolate token test
  • Loading branch information
gaaclarke committed Sep 7, 2022
commit a458d8de56a86467d0e14257c1349e754eb11dfa
18 changes: 17 additions & 1 deletion lib/ui/fixtures/ui_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'dart:async';
import 'dart:typed_data';
import 'dart:ui';
import 'dart:isolate' show ReceivePort, SendPort;
import 'dart:isolate';
import 'dart:ffi';

void main() {}
Expand Down Expand Up @@ -902,9 +902,25 @@ void hooksTests() {
expectEquals(result, true);
});

test('root isolate token', () async {
if (RootIsolateToken.instance == null) {
throw Exception('We should have a token on a root isolate.');
}
ReceivePort receivePort = ReceivePort();
Isolate.spawn(_backgroundRootIsolateTestMain, receivePort.sendPort);
bool didPass = await receivePort.first as bool;
if (!didPass) {
throw Exception('Background isolate found a root isolate id.');
}
});

_finish();
}

void _backgroundRootIsolateTestMain(SendPort port) {
port.send(RootIsolateToken.instance == null);
}

typedef _Callback<T> = void Function(T result);
typedef _Callbacker<T> = String? Function(_Callback<T?> callback);

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class RootIsolateToken {

/// The token for the root isolate that is executing this Dart code. If this
/// Dart code is not executing on a root isolate [instance] will be null.
late final RootIsolateToken? instance = () {
static late final RootIsolateToken? instance = () {
final int rootIsolateId = __getRootIsolateId();
return rootIsolateId == 0 ? null : RootIsolateToken._(rootIsolateId);
}();
Expand Down