diff --git a/shell/common/api/electron_api_asar.cc b/shell/common/api/electron_api_asar.cc index 212d7dec31fb..2661292360d7 100644 --- a/shell/common/api/electron_api_asar.cc +++ b/shell/common/api/electron_api_asar.cc @@ -18,8 +18,7 @@ class Archive : public node::ObjectWrap { static v8::Local CreateFunctionTemplate( v8::Isolate* isolate) { auto tpl = v8::FunctionTemplate::New(isolate, Archive::New); - tpl->SetClassName( - v8::String::NewFromUtf8(isolate, "Archive").ToLocalChecked()); + tpl->SetClassName(v8::String::NewFromUtf8Literal(isolate, "Archive")); tpl->InstanceTemplate()->SetInternalFieldCount(1); NODE_SET_PROTOTYPE_METHOD(tpl, "getFileInfo", &Archive::GetFileInfo); diff --git a/shell/renderer/api/electron_api_web_frame.cc b/shell/renderer/api/electron_api_web_frame.cc index 5424994f51e6..35861aa941e5 100644 --- a/shell/renderer/api/electron_api_web_frame.cc +++ b/shell/renderer/api/electron_api_web_frame.cc @@ -146,7 +146,7 @@ class ScriptExecutionCallback { const v8::Local& result) { v8::MaybeLocal maybe_result; bool success = true; - std::string error_message = + std::string errmsg = "An unknown exception occurred while getting the result of the script"; { v8::TryCatch try_catch(isolate); @@ -164,7 +164,7 @@ class ScriptExecutionCallback { auto message = try_catch.Message(); if (!message.IsEmpty()) { - gin::ConvertFromV8(isolate, message->Get(), &error_message); + gin::ConvertFromV8(isolate, message->Get(), &errmsg); } } } @@ -173,10 +173,11 @@ class ScriptExecutionCallback { if (callback_) std::move(callback_).Run( v8::Undefined(isolate), - v8::Exception::Error( - v8::String::NewFromUtf8(isolate, error_message.c_str()) - .ToLocalChecked())); - promise_.RejectWithErrorMessage(error_message); + v8::Exception::Error(v8::String::NewFromUtf8( + isolate, errmsg.data(), + v8::NewStringType::kNormal, errmsg.size()) + .ToLocalChecked())); + promise_.RejectWithErrorMessage(errmsg); } else { v8::Local context = promise_.GetContext(); v8::Context::Scope context_scope(context); @@ -210,7 +211,7 @@ class ScriptExecutionCallback { promise_.Resolve(value); } } else { - const char error_message[] = + const char errmsg[] = "Script failed to execute, this normally means an error " "was thrown. Check the renderer console for the error."; if (!callback_.is_null()) { @@ -219,13 +220,12 @@ class ScriptExecutionCallback { std::move(callback_).Run( v8::Undefined(isolate), v8::Exception::Error( - v8::String::NewFromUtf8(isolate, error_message) - .ToLocalChecked())); + v8::String::NewFromUtf8Literal(isolate, errmsg))); } - promise_.RejectWithErrorMessage(error_message); + promise_.RejectWithErrorMessage(errmsg); } } else { - const char error_message[] = + const char errmsg[] = "WebFrame was removed before script could run. This normally means " "the underlying frame was destroyed"; if (!callback_.is_null()) { @@ -233,10 +233,10 @@ class ScriptExecutionCallback { v8::Context::Scope context_scope(context); std::move(callback_).Run( v8::Undefined(isolate), - v8::Exception::Error(v8::String::NewFromUtf8(isolate, error_message) - .ToLocalChecked())); + v8::Exception::Error( + v8::String::NewFromUtf8Literal(isolate, errmsg))); } - promise_.RejectWithErrorMessage(error_message); + promise_.RejectWithErrorMessage(errmsg); } delete this; } @@ -716,15 +716,14 @@ class WebFrameRenderer final : public gin::Wrappable, script.Get("url", &url); if (!script.Get("code", &code)) { - const char error_message[] = "Invalid 'code'"; + const char errmsg[] = "Invalid 'code'"; if (!completion_callback.is_null()) { std::move(completion_callback) .Run(v8::Undefined(isolate), v8::Exception::Error( - v8::String::NewFromUtf8(isolate, error_message) - .ToLocalChecked())); + v8::String::NewFromUtf8Literal(isolate, errmsg))); } - promise.RejectWithErrorMessage(error_message); + promise.RejectWithErrorMessage(errmsg); return handle; } diff --git a/shell/renderer/electron_renderer_client.cc b/shell/renderer/electron_renderer_client.cc index d5c4409031aa..959a3f69b9ff 100644 --- a/shell/renderer/electron_renderer_client.cc +++ b/shell/renderer/electron_renderer_client.cc @@ -121,11 +121,11 @@ void ElectronRendererClient::DidCreateScriptContext( "Headers"}; for (const auto& key : keys) { v8::MaybeLocal value = - global->Get(renderer_context, gin::StringToV8(isolate, key.c_str())); + global->Get(renderer_context, gin::StringToV8(isolate, key)); if (!value.IsEmpty()) { std::string blink_key = "blink" + key; global - ->Set(renderer_context, gin::StringToV8(isolate, blink_key.c_str()), + ->Set(renderer_context, gin::StringToV8(isolate, blink_key), value.ToLocalChecked()) .Check(); } diff --git a/shell/renderer/electron_sandboxed_renderer_client.cc b/shell/renderer/electron_sandboxed_renderer_client.cc index 109b2729257a..560d66e76e80 100644 --- a/shell/renderer/electron_sandboxed_renderer_client.cc +++ b/shell/renderer/electron_sandboxed_renderer_client.cc @@ -60,7 +60,7 @@ v8::Local GetBinding(v8::Isolate* isolate, std::string binding_key = gin::V8ToString(isolate, key); gin_helper::Dictionary cache(isolate, GetBindingCache(isolate)); - if (cache.Get(binding_key.c_str(), &exports)) { + if (cache.Get(binding_key, &exports)) { return exports; } @@ -79,7 +79,7 @@ v8::Local GetBinding(v8::Isolate* isolate, DCHECK_NE(mod->nm_context_register_func, nullptr); mod->nm_context_register_func(exports, v8::Null(isolate), isolate->GetCurrentContext(), mod->nm_priv); - cache.Set(binding_key.c_str(), exports); + cache.Set(binding_key, exports); return exports; }