chore: fix V8 deprecation warnings (#15842)

This commit is contained in:
Milan Burda 2018-11-27 22:42:02 +01:00 committed by Shelley Vohr
parent 455f0669e7
commit 81e00d8e56
9 changed files with 32 additions and 22 deletions

View file

@ -287,9 +287,13 @@ static_library("electron_lib") {
"//third_party/blink/renderer", "//third_party/blink/renderer",
] ]
defines = [] defines = [ "V8_DEPRECATION_WARNINGS" ]
libs = [] libs = []
if (is_linux) {
defines += [ "GDK_DISABLE_DEPRECATION_WARNINGS" ]
}
extra_source_filters = [] extra_source_filters = []
if (!is_linux) { if (!is_linux) {
extra_source_filters += [ extra_source_filters += [

View file

@ -68,8 +68,8 @@ class GtkMessageBox : public NativeWindowObserver {
GtkWidget* w = gtk_image_new_from_pixbuf(scaled_pixbuf); GtkWidget* w = gtk_image_new_from_pixbuf(scaled_pixbuf);
gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(dialog_), w); gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(dialog_), w);
gtk_widget_show(w); gtk_widget_show(w);
g_clear_pointer(&scaled_pixbuf, gdk_pixbuf_unref); g_clear_pointer(&scaled_pixbuf, g_object_unref);
g_clear_pointer(&pixbuf, gdk_pixbuf_unref); g_clear_pointer(&pixbuf, g_object_unref);
} }
if (!checkbox_label.empty()) { if (!checkbox_label.empty()) {

View file

@ -122,9 +122,10 @@ void InitAsarSupport(v8::Isolate* isolate,
v8::Local<v8::Value> process, v8::Local<v8::Value> process,
v8::Local<v8::Value> require) { v8::Local<v8::Value> require) {
// Evaluate asar_init.js. // Evaluate asar_init.js.
v8::Local<v8::Script> asar_init = auto context = isolate->GetCurrentContext();
v8::Script::Compile(node::asar_init_value.ToStringChecked(isolate)); auto source = node::asar_init_value.ToStringChecked(isolate);
v8::Local<v8::Value> result = asar_init->Run(); auto asar_init = v8::Script::Compile(context, source).ToLocalChecked();
auto result = asar_init->Run(context).ToLocalChecked();
// Initialize asar support. // Initialize asar support.
if (result->IsFunction()) { if (result->IsFunction()) {

View file

@ -24,7 +24,7 @@ struct Converter<base::string16> {
if (!val->IsString()) if (!val->IsString())
return false; return false;
v8::String::Value s(val); v8::String::Value s(isolate, val);
out->assign(reinterpret_cast<const base::char16*>(*s), s.length()); out->assign(reinterpret_cast<const base::char16*>(*s), s.length());
return true; return true;
} }

View file

@ -317,7 +317,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
} }
if (val->IsString()) { if (val->IsString()) {
v8::String::Utf8Value utf8(val->ToString(context).ToLocalChecked()); v8::String::Utf8Value utf8(isolate,
val->ToString(context).ToLocalChecked());
return new base::Value(std::string(*utf8, utf8.length())); return new base::Value(std::string(*utf8, utf8.length()));
} }
@ -333,7 +334,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
v8::Local<v8::Value> result = v8::Local<v8::Value> result =
toISOString.As<v8::Function>()->Call(val, 0, nullptr); toISOString.As<v8::Function>()->Call(val, 0, nullptr);
if (!result.IsEmpty()) { if (!result.IsEmpty()) {
v8::String::Utf8Value utf8(result->ToString(context).ToLocalChecked()); v8::String::Utf8Value utf8(isolate,
result->ToString(context).ToLocalChecked());
return new base::Value(std::string(*utf8, utf8.length())); return new base::Value(std::string(*utf8, utf8.length()));
} }
} }
@ -344,8 +346,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
// JSON.stringify converts to an object. // JSON.stringify converts to an object.
return FromV8Object(val->ToObject(context).ToLocalChecked(), state, return FromV8Object(val->ToObject(context).ToLocalChecked(), state,
isolate); isolate);
return new base::Value( return new base::Value(*v8::String::Utf8Value(
*v8::String::Utf8Value(val->ToString(context).ToLocalChecked())); isolate, val->ToString(context).ToLocalChecked()));
} }
// v8::Value doesn't have a ToArray() method for some reason. // v8::Value doesn't have a ToArray() method for some reason.
@ -442,14 +444,14 @@ base::Value* V8ValueConverter::FromV8Object(v8::Local<v8::Object> val,
// Extend this test to cover more types as necessary and if sensible. // Extend this test to cover more types as necessary and if sensible.
if (!key->IsString() && !key->IsNumber()) { if (!key->IsString() && !key->IsNumber()) {
NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key) NOTREACHED() << "Key \"" << *v8::String::Utf8Value(isolate, key)
<< "\" " << "\" "
"is neither a string nor a number"; "is neither a string nor a number";
continue; continue;
} }
v8::String::Utf8Value name_utf8( v8::String::Utf8Value name_utf8(
key->ToString(isolate->GetCurrentContext()).ToLocalChecked()); isolate, key->ToString(isolate->GetCurrentContext()).ToLocalChecked());
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
v8::Local<v8::Value> child_v8 = val->Get(key); v8::Local<v8::Value> child_v8 = val->Get(key);

View file

@ -11,8 +11,10 @@ namespace atom {
namespace util { namespace util {
Promise::Promise(v8::Isolate* isolate) { Promise::Promise(v8::Isolate* isolate) {
auto context = isolate->GetCurrentContext();
auto resolver = v8::Promise::Resolver::New(context).ToLocalChecked();
isolate_ = isolate; isolate_ = isolate;
resolver_.Reset(isolate, v8::Promise::Resolver::New(isolate)); resolver_.Reset(isolate, resolver);
} }
Promise::~Promise() = default; Promise::~Promise() = default;

View file

@ -198,10 +198,11 @@ void AtomRendererClient::SetupMainWorldOverrides(
// an argument. // an argument.
std::string left = "(function (binding, require) {\n"; std::string left = "(function (binding, require) {\n";
std::string right = "\n})"; std::string right = "\n})";
auto script = v8::Script::Compile(v8::String::Concat( auto source = v8::String::Concat(
mate::ConvertToV8(isolate, left)->ToString(), mate::ConvertToV8(isolate, left)->ToString(),
v8::String::Concat(node::isolated_bundle_value.ToStringChecked(isolate), v8::String::Concat(node::isolated_bundle_value.ToStringChecked(isolate),
mate::ConvertToV8(isolate, right)->ToString()))); mate::ConvertToV8(isolate, right)->ToString()));
auto script = v8::Script::Compile(context, source).ToLocalChecked();
auto func = auto func =
v8::Handle<v8::Function>::Cast(script->Run(context).ToLocalChecked()); v8::Handle<v8::Function>::Cast(script->Run(context).ToLocalChecked());

View file

@ -87,8 +87,9 @@ v8::Local<v8::Value> GetBinding(v8::Isolate* isolate,
v8::Local<v8::Value> CreatePreloadScript(v8::Isolate* isolate, v8::Local<v8::Value> CreatePreloadScript(v8::Isolate* isolate,
v8::Local<v8::String> preloadSrc) { v8::Local<v8::String> preloadSrc) {
auto script = v8::Script::Compile(preloadSrc); auto context = isolate->GetCurrentContext();
auto func = script->Run(); auto script = v8::Script::Compile(context, preloadSrc).ToLocalChecked();
auto func = script->Run(context).ToLocalChecked();
return func; return func;
} }
@ -206,10 +207,11 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
std::string left = "(function(binding, require) {\n"; std::string left = "(function(binding, require) {\n";
std::string right = "\n})"; std::string right = "\n})";
// Compile the wrapper and run it to get the function object // Compile the wrapper and run it to get the function object
auto script = v8::Script::Compile(v8::String::Concat( auto source = v8::String::Concat(
mate::ConvertToV8(isolate, left)->ToString(), mate::ConvertToV8(isolate, left)->ToString(),
v8::String::Concat(node::preload_bundle_value.ToStringChecked(isolate), v8::String::Concat(node::preload_bundle_value.ToStringChecked(isolate),
mate::ConvertToV8(isolate, right)->ToString()))); mate::ConvertToV8(isolate, right)->ToString()));
auto script = v8::Script::Compile(context, source).ToLocalChecked();
auto func = auto func =
v8::Handle<v8::Function>::Cast(script->Run(context).ToLocalChecked()); v8::Handle<v8::Function>::Cast(script->Run(context).ToLocalChecked());
// Create and initialize the binding object // Create and initialize the binding object

View file

@ -1,7 +1,5 @@
config("native_mate_config") { config("native_mate_config") {
include_dirs = [ "." ] include_dirs = [ "." ]
cflags_cc = [ "-Wno-deprecated-declarations" ]
cflags_objcc = cflags_cc
} }
source_set("native_mate") { source_set("native_mate") {