Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,14 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
}
}

if (SAFE_ACCESS(args, dart_entrypoint_argc, 0)) {
Comment thread
gw280 marked this conversation as resolved.
Outdated
std::vector<std::string> arguments(args->dart_entrypoint_argc);
for (int i = 0; i < args->dart_entrypoint_argc; ++i) {
arguments[i] = std::string{args->dart_entrypoint_argv[i]};
}
settings.dart_entrypoint_args = std::move(arguments);
}

if (!run_configuration.IsValid()) {
return LOG_EMBEDDER_ERROR(
kInvalidArguments,
Expand Down
9 changes: 9 additions & 0 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,15 @@ typedef struct {
/// matches what the platform would natively resolve to as possible.
FlutterComputePlatformResolvedLocaleCallback
compute_platform_resolved_locale_callback;

/// The command line argument count for arguments passed through to the Dart
/// entrypoint.
int dart_entrypoint_argc;

/// The command line arguments passed through to the Dart entrypoint. The
/// strings must be `NULL` terminated.
const char* const* dart_entrypoint_argv;
Comment thread
gw280 marked this conversation as resolved.

} FlutterProjectArgs;

//------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/embedder/fixtures/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -733,3 +733,10 @@ void render_targets_are_recycled() {
};
window.scheduleFrame();
}

void nativeArgumentsCallback(List<String> args) native 'NativeArgumentsCallback';

@pragma('vm:entry-point')
void dart_entrypoint_args(List<String> args) {
nativeArgumentsCallback(args);
}
28 changes: 28 additions & 0 deletions shell/platform/embedder/tests/embedder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,34 @@ TEST_F(EmbedderTest, VMShutsDownWhenNoEnginesInProcess) {
}
}

//------------------------------------------------------------------------------
///
TEST_F(EmbedderTest, DartEntrypointArgs) {
auto& context = GetEmbedderContext(ContextType::kSoftwareContext);
EmbedderConfigBuilder builder(context);
builder.SetSoftwareRendererConfig();
builder.GetProjectArgs().dart_entrypoint_argc = 2;
Comment thread
gw280 marked this conversation as resolved.
Outdated
std::vector<const char*> args = {"foo", "bar"};
builder.GetProjectArgs().dart_entrypoint_argv = args.data();
builder.SetDartEntrypoint("dart_entrypoint_args");
fml::AutoResetWaitableEvent callbackLatch;
Comment thread
gw280 marked this conversation as resolved.
Outdated
std::vector<std::string> callbackArgs;
auto nativeArgumentsCallback = [&callbackArgs,
&callbackLatch](Dart_NativeArguments args) {
Dart_Handle exception = nullptr;
callbackArgs =
tonic::DartConverter<std::vector<std::string>>::FromArguments(
args, 0, exception);
callbackLatch.Signal();
};
context.AddNativeCallback("NativeArgumentsCallback",
CREATE_NATIVE_ENTRY(nativeArgumentsCallback));
auto engine = builder.LaunchEngine();
callbackLatch.Wait();
ASSERT_EQ(callbackArgs[0], "foo");
ASSERT_EQ(callbackArgs[1], "bar");
}

//------------------------------------------------------------------------------
/// These snapshots may be materialized from symbols and the size field may not
/// be relevant. Since this information is redundant, engine launch should not
Expand Down