diff --git a/include/v8.h b/include/v8.h index a716793ccc..12da59f2a0 100644 --- a/include/v8.h +++ b/include/v8.h @@ -8636,7 +8636,11 @@ class V8_EXPORT V8 { /** * Sets V8 flags from a string. */ - static void SetFlagsFromString(const char* str, int length); + static void SetFlagsFromString(const char* str); + static void SetFlagsFromString(const char* str, size_t length); + V8_DEPRECATE_SOON("use size_t version", + static void SetFlagsFromString(const char* str, + int length)); /** * Sets V8 flags from the command line. diff --git a/src/api.cc b/src/api.cc index 5cc20b077c..eec965b43c 100644 --- a/src/api.cc +++ b/src/api.cc @@ -891,11 +891,19 @@ void V8::SetDcheckErrorHandler(DcheckErrorCallback that) { v8::base::SetDcheckFunction(that); } -void V8::SetFlagsFromString(const char* str, int length) { +void V8::SetFlagsFromString(const char* str) { + SetFlagsFromString(str, strlen(str)); +} + +void V8::SetFlagsFromString(const char* str, size_t length) { i::FlagList::SetFlagsFromString(str, length); i::FlagList::EnforceFlagImplications(); } +void V8::SetFlagsFromString(const char* str, int length) { + CHECK_LE(0, length); + SetFlagsFromString(str, static_cast(length)); +} void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); @@ -10494,12 +10502,6 @@ int Testing::GetStressRuns() { #endif } - -static void SetFlagsFromString(const char* flags) { - V8::SetFlagsFromString(flags, i::StrLength(flags)); -} - - void Testing::PrepareStressRun(int run) { static const char* kLazyOptimizations = "--prepare-always-opt " @@ -10513,22 +10515,22 @@ void Testing::PrepareStressRun(int run) { static const char* kDeoptEvery13Times = "--deopt-every-n-times=13"; if (internal::Testing::stress_type() == Testing::kStressTypeDeopt && internal::FLAG_deopt_every_n_times == 0) { - SetFlagsFromString(kDeoptEvery13Times); + V8::SetFlagsFromString(kDeoptEvery13Times); } #ifdef DEBUG // As stressing in debug mode only make two runs skip the deopt stressing // here. if (run == GetStressRuns() - 1) { - SetFlagsFromString(kForcedOptimizations); + V8::SetFlagsFromString(kForcedOptimizations); } else { - SetFlagsFromString(kLazyOptimizations); + V8::SetFlagsFromString(kLazyOptimizations); } #else if (run == GetStressRuns() - 1) { - SetFlagsFromString(kForcedOptimizations); + V8::SetFlagsFromString(kForcedOptimizations); } else if (run != GetStressRuns() - 2) { - SetFlagsFromString(kLazyOptimizations); + V8::SetFlagsFromString(kLazyOptimizations); } #endif } diff --git a/src/d8.cc b/src/d8.cc index be90dd0859..acbe4b78f9 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -2794,12 +2794,6 @@ void Worker::PostMessageOut(const v8::FunctionCallbackInfo& args) { } } - -void SetFlagsFromString(const char* flags) { - v8::V8::SetFlagsFromString(flags, static_cast(strlen(flags))); -} - - bool Shell::SetOptions(int argc, char* argv[]) { bool logfile_per_isolate = false; for (int i = 0; i < argc; i++) { @@ -2976,7 +2970,7 @@ bool Shell::SetOptions(int argc, char* argv[]) { current->End(argc); if (!logfile_per_isolate && options.num_isolates) { - SetFlagsFromString("--nologfile_per_isolate"); + V8::SetFlagsFromString("--no-logfile-per-isolate"); } return true; @@ -3414,10 +3408,10 @@ int Shell::Main(int argc, char* argv[]) { } if (i::FLAG_trace_turbo_cfg_file == nullptr) { - SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); + V8::SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); } if (i::FLAG_redirect_code_traces_to == nullptr) { - SetFlagsFromString("--redirect-code-traces-to=code.asm"); + V8::SetFlagsFromString("--redirect-code-traces-to=code.asm"); } v8::V8::InitializePlatform(g_platform.get()); v8::V8::Initialize(); diff --git a/src/flags.cc b/src/flags.cc index d16c547c52..c87e5d5d45 100644 --- a/src/flags.cc +++ b/src/flags.cc @@ -526,14 +526,14 @@ static char* SkipBlackSpace(char* p) { // static -int FlagList::SetFlagsFromString(const char* str, int len) { +int FlagList::SetFlagsFromString(const char* str, size_t len) { // make a 0-terminated copy of str - ScopedVector copy0(len + 1); - MemCopy(copy0.start(), str, len); + std::unique_ptr copy0{NewArray(len + 1)}; + MemCopy(copy0.get(), str, len); copy0[len] = '\0'; // strip leading white space - char* copy = SkipWhiteSpace(copy0.start()); + char* copy = SkipWhiteSpace(copy0.get()); // count the number of 'arguments' int argc = 1; // be compatible with SetFlagsFromCommandLine() @@ -557,7 +557,6 @@ int FlagList::SetFlagsFromString(const char* str, int len) { return SetFlagsFromCommandLine(&argc, argv.start(), false); } - // static void FlagList::ResetAllFlags() { for (size_t i = 0; i < num_flags; ++i) { diff --git a/src/flags.h b/src/flags.h index d82c5b40d1..7e6e0cb715 100644 --- a/src/flags.h +++ b/src/flags.h @@ -51,7 +51,7 @@ class V8_EXPORT_PRIVATE FlagList { // Set the flag values by parsing the string str. Splits string into argc // substrings argv[], each of which consisting of non-white-space chars, // and then calls SetFlagsFromCommandLine() and returns its result. - static int SetFlagsFromString(const char* str, int len); + static int SetFlagsFromString(const char* str, size_t len); // Reset all flags to their default value. static void ResetAllFlags(); diff --git a/src/third_party/vtune/vtune-jit.cc b/src/third_party/vtune/vtune-jit.cc index 5c49855359..dbbab7fc58 100644 --- a/src/third_party/vtune/vtune-jit.cc +++ b/src/third_party/vtune/vtune-jit.cc @@ -257,8 +257,7 @@ void VTUNEJITInterface::event_handler(const v8::JitCodeEvent* event) { } // namespace internal v8::JitCodeEventHandler GetVtuneCodeEventHandler() { - v8::V8::SetFlagsFromString("--nocompact_code_space", - (int)strlen("--nocompact_code_space")); + v8::V8::SetFlagsFromString("--no-compact-code-space"); return vTune::internal::VTUNEJITInterface::event_handler; } diff --git a/test/cctest/heap/test-heap.cc b/test/cctest/heap/test-heap.cc index 166e1e7019..1d1066bc82 100644 --- a/test/cctest/heap/test-heap.cc +++ b/test/cctest/heap/test-heap.cc @@ -5144,7 +5144,7 @@ TEST(MessageObjectLeak) { CompileRun(test); const char* flag = "--turbo-filter=*"; - FlagList::SetFlagsFromString(flag, StrLength(flag)); + FlagList::SetFlagsFromString(flag, strlen(flag)); FLAG_always_opt = true; CompileRun(test); diff --git a/test/cctest/test-flags.cc b/test/cctest/test-flags.cc index e38a61f4b3..596a84082f 100644 --- a/test/cctest/test-flags.cc +++ b/test/cctest/test-flags.cc @@ -80,7 +80,7 @@ TEST(Flags2b) { "-notesting-maybe-bool-flag " "-testing_float_flag=.25 " "--testing_string_flag no_way! "; - CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); + CHECK_EQ(0, FlagList::SetFlagsFromString(str, strlen(str))); CHECK(!FLAG_testing_bool_flag); CHECK(FLAG_testing_maybe_bool_flag.has_value); CHECK(!FLAG_testing_maybe_bool_flag.value); @@ -117,7 +117,7 @@ TEST(Flags3b) { "--testing_int_flag -666 " "--testing_float_flag -12E10 " "-testing-string-flag=foo-bar"; - CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str))); + CHECK_EQ(0, FlagList::SetFlagsFromString(str, strlen(str))); CHECK(FLAG_testing_bool_flag); CHECK(FLAG_testing_maybe_bool_flag.has_value); CHECK(FLAG_testing_maybe_bool_flag.value); @@ -142,7 +142,7 @@ TEST(Flags4) { TEST(Flags4b) { SetFlagsToDefault(); const char* str = "--testing_bool_flag --foo"; - CHECK_EQ(2, FlagList::SetFlagsFromString(str, StrLength(str))); + CHECK_EQ(2, FlagList::SetFlagsFromString(str, strlen(str))); CHECK(!FLAG_testing_maybe_bool_flag.has_value); } @@ -161,7 +161,7 @@ TEST(Flags5) { TEST(Flags5b) { SetFlagsToDefault(); const char* str = " --testing_int_flag=\"foobar\""; - CHECK_EQ(1, FlagList::SetFlagsFromString(str, StrLength(str))); + CHECK_EQ(1, FlagList::SetFlagsFromString(str, strlen(str))); } @@ -180,7 +180,7 @@ TEST(Flags6) { TEST(Flags6b) { SetFlagsToDefault(); const char* str = " --testing-int-flag 0 --testing_float_flag "; - CHECK_EQ(3, FlagList::SetFlagsFromString(str, StrLength(str))); + CHECK_EQ(3, FlagList::SetFlagsFromString(str, strlen(str))); } TEST(FlagsRemoveIncomplete) { diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc index 2703113838..38e0eb19fc 100644 --- a/test/cctest/test-serialize.cc +++ b/test/cctest/test-serialize.cc @@ -1843,7 +1843,7 @@ TEST(CodeSerializerLargeCodeObjectWithIncrementalMarking) { ManualGCScope manual_gc_scope; FLAG_always_opt = false; const char* filter_flag = "--turbo-filter=NOTHING"; - FlagList::SetFlagsFromString(filter_flag, StrLength(filter_flag)); + FlagList::SetFlagsFromString(filter_flag, strlen(filter_flag)); FLAG_manual_evacuation_candidates_selection = true; LocalContext context;