mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:58:32 +00:00
e8d7425c4e
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>
52 lines
1.5 KiB
Dart
52 lines
1.5 KiB
Dart
// Copyright (c) 2019, 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 NativeCallbackTest = Int32 Function(Pointer);
|
|
typedef NativeCallbackTestFn = int Function(Pointer);
|
|
|
|
class CallbackTest {
|
|
final String name;
|
|
final void Function() afterCallbackChecks;
|
|
final bool isLeaf;
|
|
|
|
// Either a NativeCallable or a Pointer.fromFunction.
|
|
final Object callback;
|
|
|
|
CallbackTest(this.name, this.callback, {this.isLeaf = false})
|
|
: afterCallbackChecks = noChecks {}
|
|
CallbackTest.withCheck(this.name, this.callback, this.afterCallbackChecks,
|
|
{this.isLeaf = false}) {}
|
|
|
|
void run() {
|
|
final NativeCallbackTestFn tester = isLeaf
|
|
? ffiTestFunctions.lookupFunction<NativeCallbackTest,
|
|
NativeCallbackTestFn>("Test$name", isLeaf: true)
|
|
: ffiTestFunctions.lookupFunction<NativeCallbackTest,
|
|
NativeCallbackTestFn>("Test$name", isLeaf: false);
|
|
|
|
final cb = callback;
|
|
final int testCode =
|
|
tester(cb is NativeCallable ? cb.nativeFunction : cb as Pointer);
|
|
|
|
if (testCode != 0) {
|
|
Expect.fail("Test $name failed.");
|
|
}
|
|
|
|
afterCallbackChecks();
|
|
if (cb is NativeCallable) {
|
|
cb.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
void noChecks() {}
|