From ee9024da88463b9b8572991fc43932d0fe3fc478 Mon Sep 17 00:00:00 2001 From: Tess Strickland Date: Fri, 13 Dec 2024 16:22:17 +0100 Subject: [PATCH] Add entry-point annotations for test-only code. (flutter/engine#57158) This change adds entry-point annotations to methods and classes accessed by native code during engine tests. Currently, entry point annotations are not checked by the Dart VM when running in JIT mode, only in AOT mode. In order to also enforce entry point annotations in JIT mode, first tests in Flutter must be appropriately annotated to avoid roll failures. Related issues: * https://github.com/flutter/flutter/issues/118608 * https://github.com/dart-lang/sdk/issues/50649 --- .../flutter/testing/dart/plugin_utilities_test.dart | 13 ++++++++++--- engine/src/flutter/testing/dart/spawn_helper.dart | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/testing/dart/plugin_utilities_test.dart b/engine/src/flutter/testing/dart/plugin_utilities_test.dart index a30c029ea0..8c6392022a 100644 --- a/engine/src/flutter/testing/dart/plugin_utilities_test.dart +++ b/engine/src/flutter/testing/dart/plugin_utilities_test.dart @@ -9,11 +9,15 @@ import 'package:test/test.dart'; typedef StringFunction = String Function(); typedef IntFunction = int Function(); +@pragma('vm:entry-point', 'get') String top() => 'top'; +@pragma('vm:entry-point') class Foo { const Foo(); + @pragma('vm:entry-point') static int getInt() => 1; + @pragma('vm:entry-point') double getDouble() => 1.0; } @@ -23,14 +27,16 @@ void main() { final CallbackHandle hTop = PluginUtilities.getCallbackHandle(top)!; expect(hTop, isNot(0)); expect(PluginUtilities.getCallbackHandle(top), hTop); - final StringFunction topClosure = PluginUtilities.getCallbackFromHandle(hTop)! as StringFunction; + final StringFunction topClosure = + PluginUtilities.getCallbackFromHandle(hTop)! as StringFunction; expect(topClosure(), 'top'); // Static method callback. final CallbackHandle hGetInt = PluginUtilities.getCallbackHandle(Foo.getInt)!; expect(hGetInt, isNot(0)); expect(PluginUtilities.getCallbackHandle(Foo.getInt), hGetInt); - final IntFunction getIntClosure = PluginUtilities.getCallbackFromHandle(hGetInt)! as IntFunction; + final IntFunction getIntClosure = + PluginUtilities.getCallbackFromHandle(hGetInt)! as IntFunction; expect(getIntClosure(), 1); // Instance method callbacks cannot be looked up. @@ -38,7 +44,8 @@ void main() { expect(PluginUtilities.getCallbackHandle(foo.getDouble), isNull); // Anonymous closures cannot be looked up. - final Function anon = (int a, int b) => a + b; // ignore: prefer_function_declarations_over_variables + final Function anon = // ignore: prefer_function_declarations_over_variables + (int a, int b) => a + b; expect(PluginUtilities.getCallbackHandle(anon), isNull); }); } diff --git a/engine/src/flutter/testing/dart/spawn_helper.dart b/engine/src/flutter/testing/dart/spawn_helper.dart index 31d1acefd6..22e8281417 100644 --- a/engine/src/flutter/testing/dart/spawn_helper.dart +++ b/engine/src/flutter/testing/dart/spawn_helper.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@pragma('vm:entry-point', 'get') void main() {} @pragma('vm:entry-point')