Skip to content

Commit 9098b79

Browse files
sstricklCommit Queue
authored andcommitted
[vm] Verify entry point annotations in Dart_GetStaticMethodClosure.
Methods that are accessed via Dart_GetStaticMethodClosure should be annotated as a getter entry point, so now the runtime verifies that. See the discussion on flutter/engine#57158 for additional context. TEST=vm/cc/DartAPI_GetStaticMethodClosure Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-debug-x64-try,vm-linux-release-x64-try,vm-appjit-linux-product-x64-try Change-Id: I4b65ed4332dfabe662a364e7cde0ef0596beee54 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400583 Commit-Queue: Tess Strickland <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent d76f568 commit 9098b79

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

runtime/vm/dart_api_impl.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,6 +2795,11 @@ DART_EXPORT Dart_Handle Dart_GetStaticMethodClosure(Dart_Handle library,
27952795
return Api::NewError(
27962796
"function_name must be the name of a regular function.");
27972797
}
2798+
2799+
if (FLAG_verify_entry_points) {
2800+
CHECK_ERROR_HANDLE(func.VerifyEntryPoint(EntryPointPragma::kGetterOnly));
2801+
}
2802+
27982803
func = func.ImplicitClosureFunction();
27992804
if (func.IsNull()) {
28002805
return Dart_Null();

runtime/vm/dart_api_impl_test.cc

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,17 +1270,29 @@ TEST_CASE(DartAPI_ClosureFunction) {
12701270
}
12711271

12721272
TEST_CASE(DartAPI_GetStaticMethodClosure) {
1273-
const char* kScriptChars =
1274-
"class Foo {\n"
1275-
" static int getInt() {\n"
1276-
" return 1;\n"
1277-
" }\n"
1278-
" double getDouble() {\n"
1279-
" return 1.0;\n"
1280-
" }\n"
1281-
"}\n";
1273+
const char* kScriptChars = R"(
1274+
@pragma("vm:entry-point")
1275+
class Foo {
1276+
static int getIntNoAnnotation() {
1277+
return 1;
1278+
}
1279+
@pragma("vm:entry-point", "call")
1280+
static int getIntCallOnly() {
1281+
return 1;
1282+
}
1283+
@pragma("vm:entry-point", "get")
1284+
static int getInt() {
1285+
return 1;
1286+
}
1287+
@pragma("vm:entry-point", "get")
1288+
double getDouble() {
1289+
return 1.0;
1290+
}
1291+
}
1292+
)";
1293+
// Ensure entry points are checked.
1294+
SetFlagScope<bool> sfs(&FLAG_verify_entry_points, true);
12821295
// Create a test library and Load up a test script in it.
1283-
SetFlagScope<bool> sfs(&FLAG_verify_entry_points, false);
12841296
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, nullptr);
12851297
EXPECT_VALID(lib);
12861298
Dart_Handle foo_cls = Dart_GetClass(lib, NewString("Foo"));
@@ -1321,6 +1333,15 @@ TEST_CASE(DartAPI_GetStaticMethodClosure) {
13211333
EXPECT_ERROR(Dart_GetStaticMethodClosure(lib, foo_cls, Dart_Null()),
13221334
"Dart_GetStaticMethodClosure expects argument 'function_name' "
13231335
"to be non-null.");
1336+
EXPECT_ERROR(
1337+
Dart_GetStaticMethodClosure(lib, foo_cls,
1338+
NewString("getIntNoAnnotation")),
1339+
"To closurize 'file:///test-lib::Foo.getIntNoAnnotation' from native "
1340+
"code, it must be annotated.");
1341+
EXPECT_ERROR(
1342+
Dart_GetStaticMethodClosure(lib, foo_cls, NewString("getIntCallOnly")),
1343+
"To closurize 'file:///test-lib::Foo.getIntCallOnly' from native "
1344+
"code, it must be annotated.");
13241345
}
13251346

13261347
TEST_CASE(DartAPI_ClassLibrary) {

0 commit comments

Comments
 (0)