Skip to content

Commit 5fcadc6

Browse files
zandersoduanqz
authored andcommitted
Revert "Call Dart plugin registrant if available (flutter#23813)" (flutter#25221)
1 parent 5c773a5 commit 5fcadc6

File tree

4 files changed

+6
-88
lines changed

4 files changed

+6
-88
lines changed

lib/ui/hooks.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,10 @@ typedef _ListStringArgFunction(List<String> args);
132132
@pragma('vm:entry-point')
133133
// ignore: unused_element
134134
void _runMainZoned(Function startMainIsolateFunction,
135-
Function? dartPluginRegistrant,
136135
Function userMainFunction,
137136
List<String> args) {
138137
startMainIsolateFunction(() {
139138
runZonedGuarded<void>(() {
140-
if (dartPluginRegistrant != null) {
141-
dartPluginRegistrant();
142-
}
143139
if (userMainFunction is _ListStringArgFunction) {
144140
(userMainFunction as dynamic)(args);
145141
} else {

runtime/dart_isolate.cc

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ bool DartIsolate::MarkIsolateRunnable() {
695695

696696
[[nodiscard]] static bool InvokeMainEntrypoint(
697697
Dart_Handle user_entrypoint_function,
698-
Dart_Handle plugin_registrant_function,
699698
Dart_Handle args) {
700699
if (tonic::LogIfError(user_entrypoint_function)) {
701700
FML_LOG(ERROR) << "Could not resolve main entrypoint function.";
@@ -713,8 +712,7 @@ bool DartIsolate::MarkIsolateRunnable() {
713712

714713
if (tonic::LogIfError(tonic::DartInvokeField(
715714
Dart_LookupLibrary(tonic::ToDart("dart:ui")), "_runMainZoned",
716-
{start_main_isolate_function, plugin_registrant_function,
717-
user_entrypoint_function, args}))) {
715+
{start_main_isolate_function, user_entrypoint_function, args}))) {
718716
FML_LOG(ERROR) << "Could not invoke the main entrypoint.";
719717
return false;
720718
}
@@ -739,34 +737,12 @@ bool DartIsolate::RunFromLibrary(std::optional<std::string> library_name,
739737
auto entrypoint_handle = entrypoint.has_value() && !entrypoint.value().empty()
740738
? tonic::ToDart(entrypoint.value().c_str())
741739
: tonic::ToDart("main");
742-
auto entrypoint_args = tonic::ToDart(args);
743740
auto user_entrypoint_function =
744741
::Dart_GetField(library_handle, entrypoint_handle);
745742

746-
// The Dart plugin registrant is a function named `_registerPlugins`
747-
// generated by the Flutter tool.
748-
//
749-
// This function binds a plugin implementation to their platform
750-
// interface based on the configuration of the app's pubpec.yaml, and the
751-
// plugin's pubspec.yaml.
752-
//
753-
// Since this function may or may not be defined. Check that it is a top
754-
// level function, and call it in hooks.dart before the main entrypoint
755-
// function.
756-
//
757-
// If it's not defined, then just call the main entrypoint function
758-
// as usual.
759-
//
760-
// This allows embeddings to change the name of the entrypoint function.
761-
auto plugin_registrant_function =
762-
::Dart_GetField(library_handle, tonic::ToDart("_registerPlugins"));
763-
764-
if (Dart_IsError(plugin_registrant_function)) {
765-
plugin_registrant_function = Dart_Null();
766-
}
767-
768-
if (!InvokeMainEntrypoint(user_entrypoint_function,
769-
plugin_registrant_function, entrypoint_args)) {
743+
auto entrypoint_args = tonic::ToDart(args);
744+
745+
if (!InvokeMainEntrypoint(user_entrypoint_function, entrypoint_args)) {
770746
return false;
771747
}
772748

runtime/dart_isolate_unittests.cc

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -613,39 +613,5 @@ TEST_F(DartIsolateTest, DISABLED_ValidLoadingUnitSucceeds) {
613613
Wait();
614614
}
615615

616-
TEST_F(DartIsolateTest, DartPluginRegistrantIsCalled) {
617-
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
618-
619-
std::vector<std::string> messages;
620-
fml::AutoResetWaitableEvent latch;
621-
622-
AddNativeCallback(
623-
"PassMessage",
624-
CREATE_NATIVE_ENTRY(([&latch, &messages](Dart_NativeArguments args) {
625-
auto message = tonic::DartConverter<std::string>::FromDart(
626-
Dart_GetNativeArgument(args, 0));
627-
messages.push_back(message);
628-
latch.Signal();
629-
})));
630-
631-
const auto settings = CreateSettingsForFixture();
632-
auto vm_ref = DartVMRef::Create(settings);
633-
auto thread = CreateNewThread();
634-
TaskRunners task_runners(GetCurrentTestName(), //
635-
thread, //
636-
thread, //
637-
thread, //
638-
thread //
639-
);
640-
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners,
641-
"mainForPluginRegistrantTest", {},
642-
GetFixturesPath());
643-
ASSERT_TRUE(isolate);
644-
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
645-
latch.Wait();
646-
ASSERT_EQ(messages.size(), 1u);
647-
ASSERT_EQ(messages[0], "_registerPlugins was called");
648-
}
649-
650616
} // namespace testing
651617
} // namespace flutter

runtime/fixtures/runtime_test.dart

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import 'dart:ui';
1010

1111
import 'split_lib_test.dart' deferred as splitlib;
1212

13-
void main() {}
13+
void main() {
14+
}
1415

1516
@pragma('vm:entry-point')
1617
void sayHi() {
@@ -114,24 +115,3 @@ void testCanConvertListOfInts(List<int> args){
114115
args[2] == 3 &&
115116
args[3] == 4);
116117
}
117-
118-
bool didCallRegistrantBeforeEntrypoint = false;
119-
120-
// Test the Dart plugin registrant.
121-
// _registerPlugins requires the entrypoint annotation, so the compiler doesn't tree shake it.
122-
@pragma('vm:entry-point')
123-
void _registerPlugins() { // ignore: unused_element
124-
if (didCallRegistrantBeforeEntrypoint) {
125-
throw '_registerPlugins is being called twice';
126-
}
127-
didCallRegistrantBeforeEntrypoint = true;
128-
}
129-
130-
@pragma('vm:entry-point')
131-
void mainForPluginRegistrantTest() { // ignore: unused_element
132-
if (didCallRegistrantBeforeEntrypoint) {
133-
passMessage('_registerPlugins was called');
134-
} else {
135-
passMessage('_registerPlugins was not called');
136-
}
137-
}

0 commit comments

Comments
 (0)