From d5fccb8e680d5f5b3b1c4ed1686cdc86e496b66f Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Tue, 18 Feb 2020 14:44:32 +0100 Subject: [PATCH] [d8] Cleanup String creation - Avoid NewStringType::kNormal where possible - Use Template::Set const char helper - Use NewStringType::kInternalized where possible BUG: v8:10155 Change-Id: I4d19e46879c8a574838d2c25c591e510ef16d89f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2061556 Reviewed-by: Sathya Gunasekaran Reviewed-by: Ulan Degenbaev Commit-Queue: Camillo Bruni Cr-Commit-Position: refs/heads/master@{#66333} --- src/d8/d8.cc | 288 +++++++++++++++++---------------------------------- 1 file changed, 94 insertions(+), 194 deletions(-) diff --git a/src/d8/d8.cc b/src/d8/d8.cc index 57d8414d08..5b65f554e4 100644 --- a/src/d8/d8.cc +++ b/src/d8/d8.cc @@ -308,8 +308,7 @@ std::unique_ptr g_platform; static Local Throw(Isolate* isolate, const char* message) { return isolate->ThrowException( - String::NewFromUtf8(isolate, message, NewStringType::kNormal) - .ToLocalChecked()); + String::NewFromUtf8(isolate, message).ToLocalChecked()); } static MaybeLocal TryGetValue(v8::Isolate* isolate, @@ -317,8 +316,7 @@ static MaybeLocal TryGetValue(v8::Isolate* isolate, Local object, const char* property) { Local v8_str = - String::NewFromUtf8(isolate, property, NewStringType::kNormal) - .FromMaybe(Local()); + String::NewFromUtf8(isolate, property).FromMaybe(Local()); if (v8_str.IsEmpty()) return Local(); return object->Get(context, v8_str); } @@ -370,8 +368,7 @@ class TraceConfigParser { HandleScope inner_scope(isolate); Local source = - String::NewFromUtf8(isolate, json_str, NewStringType::kNormal) - .ToLocalChecked(); + String::NewFromUtf8(isolate, json_str).ToLocalChecked(); Local result = JSON::Parse(context, source).ToLocalChecked(); Local trace_config_object = Local::Cast(result); @@ -791,8 +788,7 @@ MaybeLocal Shell::FetchModuleTree(Local context, return MaybeLocal(); } ScriptOrigin origin( - String::NewFromUtf8(isolate, file_name.c_str(), NewStringType::kNormal) - .ToLocalChecked(), + String::NewFromUtf8(isolate, file_name.c_str()).ToLocalChecked(), Local(), Local(), Local(), Local(), Local(), Local(), Local(), True(isolate)); ScriptCompiler::Source source(source_text, origin); @@ -928,10 +924,9 @@ void Shell::HostInitializeImportMetaObject(Local context, CHECK(specifier_it != d->module_to_specifier_map.end()); Local url_key = - String::NewFromUtf8(isolate, "url", NewStringType::kNormal) + String::NewFromUtf8(isolate, "url", NewStringType::kInternalized) .ToLocalChecked(); - Local url = String::NewFromUtf8(isolate, specifier_it->second.c_str(), - NewStringType::kNormal) + Local url = String::NewFromUtf8(isolate, specifier_it->second.c_str()) .ToLocalChecked(); meta->CreateDataProperty(context, url_key, url).ToChecked(); } @@ -1508,8 +1503,7 @@ void Shell::Read(const v8::FunctionCallbackInfo& args) { Local Shell::ReadFromStdin(Isolate* isolate) { static const int kBufferSize = 256; char buffer[kBufferSize]; - Local accumulator = - String::NewFromUtf8(isolate, "", NewStringType::kNormal).ToLocalChecked(); + Local accumulator = String::NewFromUtf8(isolate, "").ToLocalChecked(); int length; while (true) { // Continue reading if the line ends with an escape '\\' or the line has @@ -1558,9 +1552,7 @@ void Shell::Load(const v8::FunctionCallbackInfo& args) { } if (!ExecuteString( args.GetIsolate(), source, - String::NewFromUtf8(args.GetIsolate(), *file, - NewStringType::kNormal) - .ToLocalChecked(), + String::NewFromUtf8(args.GetIsolate(), *file).ToLocalChecked(), kNoPrintResult, options.quiet_load ? kNoReportExceptions : kReportExceptions, kNoProcessMessageQueue)) { @@ -1734,10 +1726,9 @@ void Shell::NotifyDone(const v8::FunctionCallbackInfo& args) { } void Shell::Version(const v8::FunctionCallbackInfo& args) { - args.GetReturnValue().Set(String::NewFromUtf8(args.GetIsolate(), - V8::GetVersion(), - NewStringType::kNormal) - .ToLocalChecked()); + args.GetReturnValue().Set( + String::NewFromUtf8(args.GetIsolate(), V8::GetVersion()) + .ToLocalChecked()); } void Shell::ReportException(Isolate* isolate, Local message, @@ -1891,11 +1882,9 @@ Local Shell::Stringify(Isolate* isolate, Local value) { v8::Local::New(isolate, evaluation_context_); if (stringify_function_.IsEmpty()) { Local source = - String::NewFromUtf8(isolate, stringify_source_, NewStringType::kNormal) - .ToLocalChecked(); + String::NewFromUtf8(isolate, stringify_source_).ToLocalChecked(); Local name = - String::NewFromUtf8(isolate, "d8-stringify", NewStringType::kNormal) - .ToLocalChecked(); + String::NewFromUtf8(isolate, "d8-stringify").ToLocalChecked(); ScriptOrigin origin(name); Local