Browse Source

migrate to non-deprecated v8 functions

https://bugs.chromium.org/p/v8/issues/detail?id=8238

https://bugs.chromium.org/p/v8/issues/detail?id=7295

https://chromium-review.googlesource.com/c/v8/v8/+/1352273
Jeremy Apthorp 6 years ago
parent
commit
d01db5a656

+ 3 - 1
atom/browser/api/atom_api_app.cc

@@ -1401,7 +1401,9 @@ void Initialize(v8::Local<v8::Object> exports,
                 void* priv) {
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
-  dict.Set("App", atom::api::App::GetConstructor(isolate)->GetFunction());
+  dict.Set("App", atom::api::App::GetConstructor(isolate)
+                      ->GetFunction(context)
+                      .ToLocalChecked());
   dict.Set("app", atom::api::App::Create(isolate));
 #if defined(OS_MACOSX)
   auto browser = base::Unretained(Browser::Get());

+ 3 - 1
atom/browser/api/atom_api_auto_updater.cc

@@ -147,7 +147,9 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
   dict.Set("autoUpdater", AutoUpdater::Create(isolate));
-  dict.Set("AutoUpdater", AutoUpdater::GetConstructor(isolate)->GetFunction());
+  dict.Set("AutoUpdater", AutoUpdater::GetConstructor(isolate)
+                              ->GetFunction(context)
+                              .ToLocalChecked());
 }
 
 }  // namespace

+ 3 - 2
atom/browser/api/atom_api_browser_view.cc

@@ -159,8 +159,9 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   BrowserView::SetConstructor(isolate, base::Bind(&BrowserView::New));
 
-  mate::Dictionary browser_view(
-      isolate, BrowserView::GetConstructor(isolate)->GetFunction());
+  mate::Dictionary browser_view(isolate, BrowserView::GetConstructor(isolate)
+                                             ->GetFunction(context)
+                                             .ToLocalChecked());
   browser_view.SetMethod("fromId",
                          &mate::TrackableObject<BrowserView>::FromWeakMapID);
   browser_view.SetMethod("getAllViews",

+ 3 - 1
atom/browser/api/atom_api_debugger.cc

@@ -194,7 +194,9 @@ void Initialize(v8::Local<v8::Object> exports,
                 void* priv) {
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary(isolate, exports)
-      .Set("Debugger", Debugger::GetConstructor(isolate)->GetFunction());
+      .Set("Debugger", Debugger::GetConstructor(isolate)
+                           ->GetFunction(context)
+                           .ToLocalChecked());
 }
 
 }  // namespace

+ 3 - 2
atom/browser/api/atom_api_download_item.cc

@@ -244,8 +244,9 @@ void Initialize(v8::Local<v8::Object> exports,
                 void* priv) {
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary(isolate, exports)
-      .Set("DownloadItem",
-           atom::api::DownloadItem::GetConstructor(isolate)->GetFunction());
+      .Set("DownloadItem", atom::api::DownloadItem::GetConstructor(isolate)
+                               ->GetFunction(context)
+                               .ToLocalChecked());
 }
 
 }  // namespace

+ 3 - 2
atom/browser/api/atom_api_in_app_purchase.cc

@@ -132,8 +132,9 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
   dict.Set("inAppPurchase", InAppPurchase::Create(isolate));
-  dict.Set("InAppPurchase",
-           InAppPurchase::GetConstructor(isolate)->GetFunction());
+  dict.Set("InAppPurchase", InAppPurchase::GetConstructor(isolate)
+                                ->GetFunction(context)
+                                .ToLocalChecked());
 #endif
 }
 

+ 3 - 1
atom/browser/api/atom_api_menu.cc

@@ -233,7 +233,9 @@ void Initialize(v8::Local<v8::Object> exports,
   Menu::SetConstructor(isolate, base::Bind(&Menu::New));
 
   mate::Dictionary dict(isolate, exports);
-  dict.Set("Menu", Menu::GetConstructor(isolate)->GetFunction());
+  dict.Set(
+      "Menu",
+      Menu::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
 #if defined(OS_MACOSX)
   dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
   dict.SetMethod("sendActionToFirstResponder",

+ 5 - 2
atom/browser/api/atom_api_net.cc

@@ -31,7 +31,9 @@ void Net::BuildPrototype(v8::Isolate* isolate,
 }
 
 v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
-  return URLRequest::GetConstructor(isolate)->GetFunction();
+  return URLRequest::GetConstructor(isolate)
+      ->GetFunction(isolate->GetCurrentContext())
+      .ToLocalChecked();
 }
 
 }  // namespace api
@@ -53,7 +55,8 @@ void Initialize(v8::Local<v8::Object> exports,
 
   mate::Dictionary dict(isolate, exports);
   dict.Set("net", Net::Create(isolate));
-  dict.Set("Net", Net::GetConstructor(isolate)->GetFunction());
+  dict.Set("Net",
+           Net::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
 }
 
 }  // namespace

+ 3 - 2
atom/browser/api/atom_api_notification.cc

@@ -263,8 +263,9 @@ void Initialize(v8::Local<v8::Object> exports,
   Notification::SetConstructor(isolate, base::Bind(&Notification::New));
 
   mate::Dictionary dict(isolate, exports);
-  dict.Set("Notification",
-           Notification::GetConstructor(isolate)->GetFunction());
+  dict.Set("Notification", Notification::GetConstructor(isolate)
+                               ->GetFunction(context)
+                               .ToLocalChecked());
 
   dict.SetMethod("isSupported", &Notification::IsSupported);
 }

+ 3 - 2
atom/browser/api/atom_api_power_monitor.cc

@@ -141,8 +141,9 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
   dict.Set("powerMonitor", PowerMonitor::Create(isolate));
-  dict.Set("PowerMonitor",
-           PowerMonitor::GetConstructor(isolate)->GetFunction());
+  dict.Set("PowerMonitor", PowerMonitor::GetConstructor(isolate)
+                               ->GetFunction(context)
+                               .ToLocalChecked());
 }
 
 }  // namespace

+ 3 - 1
atom/browser/api/atom_api_screen.cc

@@ -164,7 +164,9 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
   dict.Set("screen", Screen::Create(isolate));
-  dict.Set("Screen", Screen::GetConstructor(isolate)->GetFunction());
+  dict.Set(
+      "Screen",
+      Screen::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
 }
 
 }  // namespace

+ 6 - 2
atom/browser/api/atom_api_session.cc

@@ -805,8 +805,12 @@ void Initialize(v8::Local<v8::Object> exports,
                 void* priv) {
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
-  dict.Set("Session", Session::GetConstructor(isolate)->GetFunction());
-  dict.Set("Cookies", Cookies::GetConstructor(isolate)->GetFunction());
+  dict.Set(
+      "Session",
+      Session::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
+  dict.Set(
+      "Cookies",
+      Cookies::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
   dict.SetMethod("fromPartition", &FromPartition);
 }
 

+ 3 - 2
atom/browser/api/atom_api_system_preferences.cc

@@ -121,8 +121,9 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
   dict.Set("systemPreferences", SystemPreferences::Create(isolate));
-  dict.Set("SystemPreferences",
-           SystemPreferences::GetConstructor(isolate)->GetFunction());
+  dict.Set("SystemPreferences", SystemPreferences::GetConstructor(isolate)
+                                    ->GetFunction(context)
+                                    .ToLocalChecked());
 }
 
 }  // namespace

+ 3 - 2
atom/browser/api/atom_api_top_level_window.cc

@@ -1179,8 +1179,9 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   TopLevelWindow::SetConstructor(isolate, base::Bind(&TopLevelWindow::New));
 
-  mate::Dictionary constructor(
-      isolate, TopLevelWindow::GetConstructor(isolate)->GetFunction());
+  mate::Dictionary constructor(isolate, TopLevelWindow::GetConstructor(isolate)
+                                            ->GetFunction(context)
+                                            .ToLocalChecked());
   constructor.SetMethod("fromId",
                         &mate::TrackableObject<TopLevelWindow>::FromWeakMapID);
   constructor.SetMethod("getAllWindows",

+ 3 - 1
atom/browser/api/atom_api_tray.cc

@@ -254,7 +254,9 @@ void Initialize(v8::Local<v8::Object> exports,
   Tray::SetConstructor(isolate, base::Bind(&Tray::New));
 
   mate::Dictionary dict(isolate, exports);
-  dict.Set("Tray", Tray::GetConstructor(isolate)->GetFunction());
+  dict.Set(
+      "Tray",
+      Tray::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
 }
 
 }  // namespace

+ 3 - 2
atom/browser/api/atom_api_view.cc

@@ -76,8 +76,9 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   View::SetConstructor(isolate, base::Bind(&View::New));
 
-  mate::Dictionary constructor(isolate,
-                               View::GetConstructor(isolate)->GetFunction());
+  mate::Dictionary constructor(
+      isolate,
+      View::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
 
   mate::Dictionary dict(isolate, exports);
   dict.Set("View", constructor);

+ 3 - 1
atom/browser/api/atom_api_web_contents.cc

@@ -2284,7 +2284,9 @@ void Initialize(v8::Local<v8::Object> exports,
                 void* priv) {
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
-  dict.Set("WebContents", WebContents::GetConstructor(isolate)->GetFunction());
+  dict.Set("WebContents", WebContents::GetConstructor(isolate)
+                              ->GetFunction(context)
+                              .ToLocalChecked());
   dict.SetMethod("create", &WebContents::Create);
   dict.SetMethod("fromId", &mate::TrackableObject<WebContents>::FromWeakMapID);
   dict.SetMethod("getAllWebContents",

+ 2 - 1
atom/browser/api/event_emitter.cc

@@ -35,7 +35,8 @@ v8::Local<v8::Object> CreateEventObject(v8::Isolate* isolate) {
   }
 
   return v8::Local<v8::ObjectTemplate>::New(isolate, event_template)
-      ->NewInstance();
+      ->NewInstance(isolate->GetCurrentContext())
+      .ToLocalChecked();
 }
 
 }  // namespace

+ 1 - 1
atom/common/api/constructor.h

@@ -25,7 +25,7 @@ v8::Local<v8::Function> CreateConstructor(v8::Isolate* isolate,
       isolate, base::Bind(&mate::internal::InvokeNew<Sig>, func));
   templ->InstanceTemplate()->SetInternalFieldCount(1);
   T::BuildPrototype(isolate, templ);
-  return templ->GetFunction();
+  return templ->GetFunction(isolate->GetCurrentContext()).ToLocalChecked();
 }
 
 }  // namespace mate

+ 10 - 6
atom/common/native_mate_converters/callback.cc

@@ -43,16 +43,19 @@ void CallTranslater(v8::Local<v8::External> external,
                     mate::Arguments* args) {
   // Whether the callback should only be called for once.
   v8::Isolate* isolate = args->isolate();
-  bool one_time = state->Has(mate::StringToSymbol(isolate, "oneTime"));
+  auto context = isolate->GetCurrentContext();
+  bool one_time =
+      state->Has(context, mate::StringToSymbol(isolate, "oneTime")).ToChecked();
 
   // Check if the callback has already been called.
   if (one_time) {
     auto called_symbol = mate::StringToSymbol(isolate, "called");
-    if (state->Has(called_symbol)) {
+    if (state->Has(context, called_symbol).ToChecked()) {
       args->ThrowError("callback can only be called for once");
       return;
     } else {
-      state->Set(called_symbol, v8::Boolean::New(isolate, true));
+      state->Set(context, called_symbol, v8::Boolean::New(isolate, true))
+          .ToChecked();
     }
   }
 
@@ -130,9 +133,10 @@ v8::Local<v8::Value> CreateFunctionFromTranslater(v8::Isolate* isolate,
   Dictionary state = mate::Dictionary::CreateEmpty(isolate);
   if (one_time)
     state.Set("oneTime", true);
-  return BindFunctionWith(isolate, isolate->GetCurrentContext(),
-                          call_translater->GetFunction(),
-                          holder->handle.Get(isolate), state.GetHandle());
+  auto context = isolate->GetCurrentContext();
+  return BindFunctionWith(
+      isolate, context, call_translater->GetFunction(context).ToLocalChecked(),
+      holder->handle.Get(isolate), state.GetHandle());
 }
 
 // func.bind(func, arg1).

+ 8 - 3
atom/common/native_mate_converters/callback.h

@@ -55,8 +55,10 @@ struct V8FunctionInvoker<v8::Local<v8::Value>(ArgTypes...)> {
     v8::Local<v8::Context> context = holder->CreationContext();
     v8::Context::Scope context_scope(context);
     std::vector<v8::Local<v8::Value>> args{ConvertToV8(isolate, raw)...};
-    v8::Local<v8::Value> ret(holder->Call(
-        holder, args.size(), args.empty() ? nullptr : &args.front()));
+    v8::Local<v8::Value> ret(holder
+                                 ->Call(context, holder, args.size(),
+                                        args.empty() ? nullptr : &args.front())
+                                 .ToLocalChecked());
     return handle_scope.Escape(ret);
   }
 };
@@ -76,7 +78,10 @@ struct V8FunctionInvoker<void(ArgTypes...)> {
     v8::Local<v8::Context> context = holder->CreationContext();
     v8::Context::Scope context_scope(context);
     std::vector<v8::Local<v8::Value>> args{ConvertToV8(isolate, raw)...};
-    holder->Call(holder, args.size(), args.empty() ? nullptr : &args.front());
+    holder
+        ->Call(context, holder, args.size(),
+               args.empty() ? nullptr : &args.front())
+        .ToLocalChecked();
   }
 };
 

+ 3 - 2
atom/common/native_mate_converters/v8_value_converter.cc

@@ -331,8 +331,9 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
     v8::Local<v8::Value> toISOString =
         date->Get(v8::String::NewFromUtf8(isolate, "toISOString"));
     if (toISOString->IsFunction()) {
-      v8::Local<v8::Value> result =
-          toISOString.As<v8::Function>()->Call(val, 0, nullptr);
+      v8::Local<v8::Value> result = toISOString.As<v8::Function>()
+                                        ->Call(context, val, 0, nullptr)
+                                        .ToLocalChecked();
       if (!result.IsEmpty()) {
         v8::String::Utf8Value utf8(isolate,
                                    result->ToString(context).ToLocalChecked());

+ 3 - 2
atom/renderer/api/atom_api_spell_check_client.cc

@@ -211,10 +211,11 @@ void SpellCheckClient::SpellCheckWords(
   v8::Local<v8::FunctionTemplate> templ = mate::CreateFunctionTemplate(
       isolate_, base::Bind(&SpellCheckClient::OnSpellCheckDone, AsWeakPtr()));
 
+  auto context = isolate_->GetCurrentContext();
   v8::Local<v8::Value> args[] = {mate::ConvertToV8(isolate_, words),
-                                 templ->GetFunction()};
+                                 templ->GetFunction(context).ToLocalChecked()};
   // Call javascript with the words and the callback function
-  scope.spell_check_->Call(scope.provider_, 2, args);
+  scope.spell_check_->Call(context, scope.provider_, 2, args).ToLocalChecked();
 }
 
 // Returns whether or not the given string is a contraction.

+ 6 - 2
atom/renderer/api/atom_api_web_frame.cc

@@ -222,7 +222,9 @@ int WebFrame::GetWebFrameId(v8::Local<v8::Value> content_window) {
 void WebFrame::SetSpellCheckProvider(mate::Arguments* args,
                                      const std::string& language,
                                      v8::Local<v8::Object> provider) {
-  if (!provider->Has(mate::StringToV8(args->isolate(), "spellCheck"))) {
+  auto context = args->isolate()->GetCurrentContext();
+  if (!provider->Has(context, mate::StringToV8(args->isolate(), "spellCheck"))
+           .ToChecked()) {
     args->ThrowError("\"spellCheck\" has to be defined");
     return;
   }
@@ -541,7 +543,9 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
   dict.Set("webFrame", WebFrame::Create(isolate));
-  dict.Set("WebFrame", WebFrame::GetConstructor(isolate)->GetFunction());
+  dict.Set(
+      "WebFrame",
+      WebFrame::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
 }
 
 }  // namespace

+ 3 - 1
native_mate/native_mate/dictionary.h

@@ -106,7 +106,9 @@ class Dictionary {
   bool SetMethod(const base::StringPiece& key, const T& callback) {
     return GetHandle()->Set(
         StringToV8(isolate_, key),
-        CallbackTraits<T>::CreateTemplate(isolate_, callback)->GetFunction());
+        CallbackTraits<T>::CreateTemplate(isolate_, callback)
+            ->GetFunction(isolate_->GetCurrentContext())
+            .ToLocalChecked());
   }
 
   bool Delete(const base::StringPiece& key) {

+ 2 - 1
native_mate/native_mate/wrappable.cc

@@ -39,7 +39,8 @@ void WrappableBase::InitWith(v8::Isolate* isolate,
   // Call object._init if we have one.
   v8::Local<v8::Function> init;
   if (Dictionary(isolate, wrapper).Get("_init", &init))
-    init->Call(wrapper, 0, nullptr);
+    init->Call(isolate->GetCurrentContext(), wrapper, 0, nullptr)
+        .ToLocalChecked();
 
   AfterInit(isolate);
 }