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
1352273
This commit is contained in:
parent
7d5cd2051a
commit
d01db5a656
26 changed files with 94 additions and 46 deletions
|
@ -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).
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue