Files
sdk/tests/ffi/async_callback_tests_utils.dart
T
Liam Appelbe e8d7425c4e [vm/ffi] Closure callbacks for sync callbacks
Bug: https://github.com/dart-lang/sdk/issues/52689
Change-Id: I54be397cfbf8519fe5b5a51b793fe46d602124d9
Fixes: https://github.com/dart-lang/sdk/issues/52689
Bug: https://github.com/dart-lang/sdk/issues/53096
TEST=isolate_local_function_callbacks_test.dart, plus generated tests and additions to existing tests
CoreLibraryReviewExempt: The isolate and FFI packages are VM-only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317060
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-08-25 03:35:44 +00:00

40 lines
1.1 KiB
Dart

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:ffi';
import 'dylib_utils.dart';
import "package:expect/expect.dart";
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
typedef NativeAsyncCallbackTest = Void Function(Pointer);
typedef NativeAsyncCallbackTestFn = void Function(Pointer);
class AsyncCallbackTest {
final String name;
final Future<void> Function() afterCallbackChecks;
// Either a NativeCallable or a Pointer.fromFunction.
final Object callback;
AsyncCallbackTest(this.name, this.callback, this.afterCallbackChecks) {}
Future<void> run() async {
final NativeAsyncCallbackTestFn tester = ffiTestFunctions.lookupFunction<
NativeAsyncCallbackTest, NativeAsyncCallbackTestFn>("TestAsync$name");
final cb = callback;
tester(cb is NativeCallable ? cb.nativeFunction : cb as Pointer);
await afterCallbackChecks();
if (cb is NativeCallable) {
cb.close();
}
}
}
void noChecks() {}