22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ import 'dart:isolate' ;
56import 'dart:ui' ;
67
78import 'package:litetest/litetest.dart' ;
@@ -19,6 +20,34 @@ class Foo {
1920
2021const Foo foo = Foo ();
2122
23+ @pragma ('vm:entry-point' )
24+ Future <void > included () async {
25+
26+ }
27+
28+ Future <void > excluded () async {
29+
30+ }
31+
32+ @pragma ('vm:entry-point' )
33+ Future <void > runCallback (IsolateParam param) async {
34+ try {
35+ final Future <dynamic > Function () func = PluginUtilities .getCallbackFromHandle (CallbackHandle .fromRawHandle (param.rawHandle))! as Future <dynamic > Function ();
36+ await func.call ();
37+ param.sendPort.send (true );
38+ }
39+ catch (e) {
40+ print (e);
41+ param.sendPort.send (false );
42+ }
43+ }
44+
45+ class IsolateParam {
46+ const IsolateParam (this .sendPort, this .rawHandle);
47+ final SendPort sendPort;
48+ final int rawHandle;
49+ }
50+
2251void main () {
2352 test ('PluginUtilities Callback Handles' , () {
2453 // Top level callback.
@@ -43,4 +72,15 @@ void main() {
4372 final Function anon = (int a, int b) => a + b; // ignore: prefer_function_declarations_over_variables
4473 expect (PluginUtilities .getCallbackHandle (anon), isNull);
4574 });
75+
76+ test ('PluginUtilities Callback Handles in Isolate' , () async {
77+ ReceivePort port = ReceivePort ();
78+ await Isolate .spawn (runCallback, IsolateParam (port.sendPort, PluginUtilities .getCallbackHandle (included)! .toRawHandle ()));
79+ expect (await port.first, true );
80+ port.close ();
81+ port = ReceivePort ();
82+ await Isolate .spawn (runCallback, IsolateParam (port.sendPort, PluginUtilities .getCallbackHandle (excluded)! .toRawHandle ()));
83+ expect (await port.first, false );
84+ port.close ();
85+ });
4686}
0 commit comments