refactor: replace v8::Local<T>::Cast() with As<T>() (#29097)
This commit is contained in:
parent
e01faedaa5
commit
a51aaeb28f
13 changed files with 31 additions and 34 deletions
|
@ -38,7 +38,7 @@ struct Converter<std::pair<Type1, Type2>> {
|
|||
if (!val->IsArray())
|
||||
return false;
|
||||
|
||||
v8::Local<v8::Array> array(v8::Local<v8::Array>::Cast(val));
|
||||
v8::Local<v8::Array> array = val.As<v8::Array>();
|
||||
if (array->Length() != 2)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ bool Converter<net::HttpResponseHeaders*>::FromV8(
|
|||
};
|
||||
|
||||
auto context = isolate->GetCurrentContext();
|
||||
auto headers = v8::Local<v8::Object>::Cast(val);
|
||||
auto headers = val.As<v8::Object>();
|
||||
auto keys = headers->GetOwnPropertyNames(context).ToLocalChecked();
|
||||
for (uint32_t i = 0; i < keys->Length(); i++) {
|
||||
v8::Local<v8::Value> keyVal;
|
||||
|
@ -203,7 +203,7 @@ bool Converter<net::HttpResponseHeaders*>::FromV8(
|
|||
|
||||
auto localVal = headers->Get(context, keyVal).ToLocalChecked();
|
||||
if (localVal->IsArray()) {
|
||||
auto values = v8::Local<v8::Array>::Cast(localVal);
|
||||
auto values = localVal.As<v8::Array>();
|
||||
for (uint32_t j = 0; j < values->Length(); j++) {
|
||||
if (!addHeaderFromValue(key,
|
||||
values->Get(context, j).ToLocalChecked())) {
|
||||
|
|
|
@ -86,7 +86,7 @@ struct Converter<v8::Local<v8::Array>> {
|
|||
v8::Local<v8::Array>* out) {
|
||||
if (!val->IsArray())
|
||||
return false;
|
||||
*out = v8::Local<v8::Array>::Cast(val);
|
||||
*out = val.As<v8::Array>();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -102,7 +102,7 @@ struct Converter<v8::Local<v8::String>> {
|
|||
v8::Local<v8::String>* out) {
|
||||
if (!val->IsString())
|
||||
return false;
|
||||
*out = v8::Local<v8::String>::Cast(val);
|
||||
*out = val.As<v8::String>();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -128,7 +128,7 @@ struct Converter<std::set<T>> {
|
|||
|
||||
auto context = isolate->GetCurrentContext();
|
||||
std::set<T> result;
|
||||
v8::Local<v8::Array> array(v8::Local<v8::Array>::Cast(val));
|
||||
v8::Local<v8::Array> array = val.As<v8::Array>();
|
||||
uint32_t length = array->Length();
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
T item;
|
||||
|
|
|
@ -86,7 +86,7 @@ class RefCountedGlobal
|
|||
: public base::RefCountedThreadSafe<RefCountedGlobal<T>, DeleteOnUIThread> {
|
||||
public:
|
||||
RefCountedGlobal(v8::Isolate* isolate, v8::Local<v8::Value> value)
|
||||
: handle_(isolate, v8::Local<T>::Cast(value)) {}
|
||||
: handle_(isolate, value.As<T>()) {}
|
||||
|
||||
bool IsAlive() const { return !handle_.IsEmpty(); }
|
||||
|
||||
|
@ -147,8 +147,7 @@ v8::Local<v8::Value> BindFunctionWith(v8::Isolate* isolate,
|
|||
v8::MaybeLocal<v8::Value> bind =
|
||||
func->Get(context, gin::StringToV8(isolate, "bind"));
|
||||
CHECK(!bind.IsEmpty());
|
||||
v8::Local<v8::Function> bind_func =
|
||||
v8::Local<v8::Function>::Cast(bind.ToLocalChecked());
|
||||
v8::Local<v8::Function> bind_func = bind.ToLocalChecked().As<v8::Function>();
|
||||
v8::Local<v8::Value> converted[] = {func, arg1, arg2};
|
||||
return bind_func->Call(context, func, base::size(converted), converted)
|
||||
.ToLocalChecked();
|
||||
|
|
|
@ -59,7 +59,7 @@ v8::Local<v8::Object> CreateNativeEvent(
|
|||
if (frame && callback) {
|
||||
gin::Handle<Event> native_event = Event::Create(isolate);
|
||||
native_event->SetCallback(std::move(callback));
|
||||
event = v8::Local<v8::Object>::Cast(native_event.ToV8());
|
||||
event = native_event.ToV8().As<v8::Object>();
|
||||
} else {
|
||||
// No need to create native event if we do not need to send reply.
|
||||
event = CreateEvent(isolate);
|
||||
|
|
|
@ -53,8 +53,7 @@ struct Converter<gin_helper::PersistentDictionary> {
|
|||
gin_helper::PersistentDictionary* out) {
|
||||
if (!val->IsObject())
|
||||
return false;
|
||||
*out = gin_helper::PersistentDictionary(isolate,
|
||||
v8::Local<v8::Object>::Cast(val));
|
||||
*out = gin_helper::PersistentDictionary(isolate, val.As<v8::Object>());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -133,7 +133,7 @@ class Promise : public PromiseBase {
|
|||
v8::Context::Scope context_scope(GetContext());
|
||||
|
||||
v8::Local<v8::Value> value = gin::ConvertToV8(isolate(), std::move(cb));
|
||||
v8::Local<v8::Function> handler = v8::Local<v8::Function>::Cast(value);
|
||||
v8::Local<v8::Function> handler = value.As<v8::Function>();
|
||||
|
||||
return GetHandle()->Then(GetContext(), handler);
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace internal {
|
|||
void* FromV8Impl(v8::Isolate* isolate, v8::Local<v8::Value> val) {
|
||||
if (!val->IsObject())
|
||||
return nullptr;
|
||||
v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(val);
|
||||
v8::Local<v8::Object> obj = val.As<v8::Object>();
|
||||
if (obj->InternalFieldCount() != 1)
|
||||
return nullptr;
|
||||
return obj->GetAlignedPointerFromInternalField(0);
|
||||
|
|
|
@ -282,7 +282,7 @@ v8::Local<v8::Value> V8ValueConverter::ToArrayBuffer(
|
|||
}
|
||||
|
||||
v8::Local<v8::Value> args[] = {array_buffer};
|
||||
auto func = v8::Local<v8::Function>::Cast(from_value);
|
||||
auto func = from_value.As<v8::Function>();
|
||||
auto result = func->Call(context, v8::Null(isolate), 1, args);
|
||||
if (!result.IsEmpty()) {
|
||||
return result.ToLocalChecked();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue