Skip to content

Commit be785f7

Browse files
authored
Pass argmuent list to dart_runner v2 main invocation. (flutter#28998)
Tested by running integration tests in fuchsia.git.
1 parent e69b310 commit be785f7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

shell/platform/fuchsia/dart_runner/dart_component_controller_v2.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,30 @@ bool DartComponentControllerV2::RunDartMain() {
392392
Dart_EnterScope();
393393

394394
// TODO(fxb/79871): Support argument passing.
395+
// Note: Even though we do not support argument passing via the cml files
396+
// at this time, we still need to create an argument list and pass it off
397+
// to the invocation of main below. If we do not do this dart will look for
398+
// a function with the signature `void main()` but existing dart components
399+
// that run in the dart runner are written with main functions that have the
400+
// signature `void main(List<String> args)`. In order to ensure that these
401+
// components do not break we need to have this stub argument list.
402+
Dart_Handle dart_arguments = Dart_NewListOf(Dart_CoreType_String, 0);
403+
404+
if (Dart_IsError(dart_arguments)) {
405+
FX_LOGF(ERROR, LOG_TAG, "Failed to allocate Dart arguments list: %s",
406+
Dart_GetError(dart_arguments));
407+
Dart_ExitScope();
408+
return false;
409+
}
410+
411+
Dart_Handle argv[] = {
412+
dart_arguments,
413+
};
414+
395415
Dart_Handle main_result =
396416
Dart_Invoke(Dart_RootLibrary() /* target */, ToDart("main") /* name */,
397-
0 /* number_of_arguments */, {} /* arguments */);
417+
dart_utils::ArraySize(argv) /* number_of_arguments */,
418+
argv /* arguments */);
398419

399420
if (Dart_IsError(main_result)) {
400421
auto dart_state = tonic::DartState::Current();

0 commit comments

Comments
 (0)