Pass argmuent list to dart_runner v2 main invocation. (flutter/engine#28998)

Tested by running integration tests in fuchsia.git.
This commit is contained in:
Chase Latta
2021-10-04 14:03:34 -07:00
committed by GitHub
parent 638b129319
commit 951c5f2e64

View File

@@ -392,9 +392,30 @@ bool DartComponentControllerV2::RunDartMain() {
Dart_EnterScope();
// TODO(fxb/79871): Support argument passing.
// Note: Even though we do not support argument passing via the cml files
// at this time, we still need to create an argument list and pass it off
// to the invocation of main below. If we do not do this dart will look for
// a function with the signature `void main()` but existing dart components
// that run in the dart runner are written with main functions that have the
// signature `void main(List<String> args)`. In order to ensure that these
// components do not break we need to have this stub argument list.
Dart_Handle dart_arguments = Dart_NewListOf(Dart_CoreType_String, 0);
if (Dart_IsError(dart_arguments)) {
FX_LOGF(ERROR, LOG_TAG, "Failed to allocate Dart arguments list: %s",
Dart_GetError(dart_arguments));
Dart_ExitScope();
return false;
}
Dart_Handle argv[] = {
dart_arguments,
};
Dart_Handle main_result =
Dart_Invoke(Dart_RootLibrary() /* target */, ToDart("main") /* name */,
0 /* number_of_arguments */, {} /* arguments */);
dart_utils::ArraySize(argv) /* number_of_arguments */,
argv /* arguments */);
if (Dart_IsError(main_result)) {
auto dart_state = tonic::DartState::Current();