REVIEW: Don't use removed and deprecated Value::To* APIs

See https://chromium-review.googlesource.com/848782 for removed APIs.
This commit is contained in:
Aleksei Kuzmin 2018-04-12 17:05:54 +02:00 committed by Samuel Attard
parent a218c9696c
commit e1f25253db

View file

@ -273,7 +273,9 @@ v8::Local<v8::Value> V8ValueConverter::ToArrayBuffer(
return v8::Uint8Array::New(array_buffer, 0, length);
}
mate::Dictionary buffer_class(isolate, buffer_value->ToObject());
mate::Dictionary buffer_class(
isolate,
buffer_value->ToObject(isolate->GetCurrentContext()).ToLocalChecked());
v8::Local<v8::Value> from_value;
if (!buffer_class.Get("from", &from_value) || !from_value->IsFunction()) {
return v8::Uint8Array::New(array_buffer, 0, length);
@ -302,21 +304,23 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
if (val->IsNull())
return std::make_unique<base::Value>().release();
auto context = isolate->GetCurrentContext();
if (val->IsBoolean())
return new base::Value(val->ToBoolean()->Value());
return new base::Value(val->ToBoolean(context).ToLocalChecked()->Value());
if (val->IsInt32())
return new base::Value(val->ToInt32()->Value());
return new base::Value(val->ToInt32(context).ToLocalChecked()->Value());
if (val->IsNumber()) {
double val_as_double = val->ToNumber()->Value();
double val_as_double = val->ToNumber(context).ToLocalChecked()->Value();
if (!std::isfinite(val_as_double))
return nullptr;
return new base::Value(val_as_double);
}
if (val->IsString()) {
v8::String::Utf8Value utf8(val->ToString());
v8::String::Utf8Value utf8(val->ToString(context).ToLocalChecked());
return new base::Value(std::string(*utf8, utf8.length()));
}
@ -332,7 +336,7 @@ 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());
v8::String::Utf8Value utf8(result->ToString(context).ToLocalChecked());
return new base::Value(std::string(*utf8, utf8.length()));
}
}
@ -341,8 +345,10 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
if (val->IsRegExp()) {
if (!reg_exp_allowed_)
// JSON.stringify converts to an object.
return FromV8Object(val->ToObject(), state, isolate);
return new base::Value(*v8::String::Utf8Value(val->ToString()));
return FromV8Object(val->ToObject(context).ToLocalChecked(),
state, isolate);
return new base::Value(
*v8::String::Utf8Value(val->ToString(context).ToLocalChecked()));
}
// v8::Value doesn't have a ToArray() method for some reason.
@ -353,7 +359,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
if (!function_allowed_)
// JSON.stringify refuses to convert function(){}.
return nullptr;
return FromV8Object(val->ToObject(), state, isolate);
return FromV8Object(val->ToObject(context).ToLocalChecked(),
state, isolate);
}
if (node::Buffer::HasInstance(val)) {
@ -361,7 +368,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state,
}
if (val->IsObject()) {
return FromV8Object(val->ToObject(), state, isolate);
return FromV8Object(val->ToObject(context).ToLocalChecked(),
state, isolate);
}
LOG(ERROR) << "Unexpected v8 value type encountered.";
@ -443,7 +451,8 @@ base::Value* V8ValueConverter::FromV8Object(v8::Local<v8::Object> val,
continue;
}
v8::String::Utf8Value name_utf8(key->ToString());
v8::String::Utf8Value name_utf8(
key->ToString(isolate->GetCurrentContext()).ToLocalChecked());
v8::TryCatch try_catch(isolate);
v8::Local<v8::Value> child_v8 = val->Get(key);