Browse Source

chore: fix V8 deprecation warnings (#15842)

Milan Burda 6 years ago
parent
commit
81e00d8e56

+ 5 - 1
BUILD.gn

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

+ 2 - 2
atom/browser/ui/message_box_gtk.cc

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

+ 4 - 3
atom/common/api/atom_api_asar.cc

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

+ 1 - 1
atom/common/native_mate_converters/string16_converter.h

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

+ 8 - 6
atom/common/native_mate_converters/v8_value_converter.cc

@@ -317,7 +317,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
   }
 
   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()));
   }
 
@@ -333,7 +334,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
       v8::Local<v8::Value> result =
           toISOString.As<v8::Function>()->Call(val, 0, nullptr);
       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()));
       }
     }
@@ -344,8 +346,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
       // JSON.stringify converts to an object.
       return FromV8Object(val->ToObject(context).ToLocalChecked(), state,
                           isolate);
-    return new base::Value(
-        *v8::String::Utf8Value(val->ToString(context).ToLocalChecked()));
+    return new base::Value(*v8::String::Utf8Value(
+        isolate, val->ToString(context).ToLocalChecked()));
   }
 
   // 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.
     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";
       continue;
     }
 
     v8::String::Utf8Value name_utf8(
-        key->ToString(isolate->GetCurrentContext()).ToLocalChecked());
+        isolate, key->ToString(isolate->GetCurrentContext()).ToLocalChecked());
 
     v8::TryCatch try_catch(isolate);
     v8::Local<v8::Value> child_v8 = val->Get(key);

+ 3 - 1
atom/common/promise_util.cc

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

+ 3 - 2
atom/renderer/atom_renderer_client.cc

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

+ 6 - 4
atom/renderer/atom_sandboxed_renderer_client.cc

@@ -87,8 +87,9 @@ v8::Local<v8::Value> GetBinding(v8::Isolate* isolate,
 
 v8::Local<v8::Value> CreatePreloadScript(v8::Isolate* isolate,
                                          v8::Local<v8::String> preloadSrc) {
-  auto script = v8::Script::Compile(preloadSrc);
-  auto func = script->Run();
+  auto context = isolate->GetCurrentContext();
+  auto script = v8::Script::Compile(context, preloadSrc).ToLocalChecked();
+  auto func = script->Run(context).ToLocalChecked();
   return func;
 }
 
@@ -206,10 +207,11 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
   std::string left = "(function(binding, require) {\n";
   std::string right = "\n})";
   // 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(),
       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 =
       v8::Handle<v8::Function>::Cast(script->Run(context).ToLocalChecked());
   // Create and initialize the binding object

+ 0 - 2
native_mate/BUILD.gn

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