Jeremy Apthorp 2019-01-09 11:17:05 -08:00
parent 7d5cd2051a
commit d01db5a656
26 changed files with 94 additions and 46 deletions

View file

@ -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());

View file

@ -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

View file

@ -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",

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -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",

View file

@ -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

View file

@ -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);
}

View file

@ -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

View file

@ -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

View file

@ -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);
}

View file

@ -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

View file

@ -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",

View file

@ -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

View file

@ -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);

View file

@ -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",

View file

@ -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

View file

@ -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

View file

@ -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).

View file

@ -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();
}
};

View file

@ -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());

View file

@ -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.

View file

@ -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

View file

@ -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) {

View file

@ -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);
}