Skip to content

Commit

Permalink
Document rationale for Dart VM flag prefix match (#30195)
Browse files Browse the repository at this point in the history
Dart VM flags are passed to Flutter via an fml::CommandLine::Option that
looks something like:

   {"dart-flags, "--max_profile_depth 1,--trace_service"}

We perform a prefix match to handle cases where Dart VM options take
arguments.

Adding the comment since in a recent review I found myself wondering why
we're using a prefix match to begin with. While the original author had
forgotten, the good news is, he wrote a test that covers this exact
case. This comment just removes one level of indirection for future
readers.
  • Loading branch information
cbracken committed Dec 7, 2021
1 parent 7831529 commit 5672f9e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ static std::vector<std::string> ParseCommaDelimited(const std::string& input) {
static bool IsAllowedDartVMFlag(const std::string& flag) {
for (uint32_t i = 0; i < fml::size(gAllowedDartFlags); ++i) {
const std::string& allowed = gAllowedDartFlags[i];
// Check that the prefix of the flag matches one of the allowed flags.
// Check that the prefix of the flag matches one of the allowed flags. This
// is to handle cases where flags take arguments, such as in
// "--max_profile_depth 1".
//
// We don't need to worry about cases like "--safe --sneaky_dangerous" as
// the VM will discard these as a single unrecognized flag.
if (flag.length() >= allowed.length() &&
Expand Down

0 comments on commit 5672f9e

Please sign in to comment.