Commit bb926303 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[cleanup] Fix use of deprecated v8 functions in extensions/renderer

Replaces use of deprecated BooleanValue, Int32Value, Get and
GetOwnPropertyNames v8 functions.

Bug: v8:7279, v8:8238
Change-Id: I73bb7deb93dffb985d4ea2fdf77fb8400d436913
Reviewed-on: https://chromium-review.googlesource.com/c/1352760Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614674}
parent 958e6783
......@@ -54,20 +54,18 @@ namespace {
v8::Local<v8::Value> GetChildValue(v8::Local<v8::Object> value,
const std::string& key_name,
v8::Isolate* isolate) {
v8::Local<v8::Array> property_names(value->GetOwnPropertyNames());
for (uint32_t i = 0; i < property_names->Length(); ++i) {
v8::Local<v8::Value> key(property_names->Get(i));
if (key_name == *v8::String::Utf8Value(isolate, key)) {
v8::TryCatch try_catch(isolate);
v8::Local<v8::Value> child_v8 = value->Get(key);
if (try_catch.HasCaught()) {
return v8::Null(isolate);
}
return child_v8;
}
v8::Local<v8::Context> context) {
v8::Isolate* isolate = context->GetIsolate();
v8::TryCatch try_catch(isolate);
v8::Local<v8::String> key;
v8::Local<v8::Value> child_value;
if (v8::String::NewFromUtf8(isolate, key_name.c_str(),
v8::NewStringType::kNormal)
.ToLocal(&key) &&
value->HasOwnProperty(context, key).FromMaybe(false) &&
value->Get(context, key).ToLocal(&child_value)) {
return child_value;
}
return v8::Null(isolate);
}
......@@ -84,12 +82,13 @@ void DisplaySourceCustomBindings::StartSession(
CHECK(args[0]->IsObject());
v8::Isolate* isolate = context()->isolate();
v8::Local<v8::Context> v8_context = context()->v8_context();
v8::Local<v8::Object> start_info = args[0].As<v8::Object>();
v8::Local<v8::Value> sink_id_val =
GetChildValue(start_info, "sinkId", isolate);
GetChildValue(start_info, "sinkId", v8_context);
CHECK(sink_id_val->IsInt32());
const int sink_id = sink_id_val->ToInt32(isolate)->Value();
const int sink_id = sink_id_val.As<v8::Int32>()->Value();
if (GetDisplaySession(sink_id)) {
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, kSessionAlreadyStarted,
......@@ -99,9 +98,9 @@ void DisplaySourceCustomBindings::StartSession(
}
v8::Local<v8::Value> video_stream_val =
GetChildValue(start_info, "videoTrack", isolate);
GetChildValue(start_info, "videoTrack", v8_context);
v8::Local<v8::Value> audio_stream_val =
GetChildValue(start_info, "audioTrack", isolate);
GetChildValue(start_info, "audioTrack", v8_context);
if ((video_stream_val->IsNull() || video_stream_val->IsUndefined()) &&
(audio_stream_val->IsNull() || audio_stream_val->IsUndefined())) {
......@@ -141,7 +140,7 @@ void DisplaySourceCustomBindings::StartSession(
std::unique_ptr<DisplaySourceAuthInfo> auth_info;
v8::Local<v8::Value> auth_info_v8_val =
GetChildValue(start_info, "authenticationInfo", isolate);
GetChildValue(start_info, "authenticationInfo", v8_context);
if (!auth_info_v8_val->IsNull()) {
CHECK(auth_info_v8_val->IsObject());
std::unique_ptr<base::Value> auth_info_val =
......@@ -194,7 +193,7 @@ void DisplaySourceCustomBindings::TerminateSession(
CHECK(args[0]->IsInt32());
v8::Isolate* isolate = context()->isolate();
int sink_id = args[0]->ToInt32(args.GetIsolate())->Value();
int sink_id = args[0].As<v8::Int32>()->Value();
DisplaySourceSession* session = GetDisplaySession(sink_id);
if (!session) {
isolate->ThrowException(
......
......@@ -66,8 +66,7 @@ void LoggingNativeHandler::ParseArgs(
bool* check_value,
std::string* error_message) {
CHECK_LE(args.Length(), 2);
*check_value =
args[0]->BooleanValue(context()->v8_context()).FromMaybe(false);
*check_value = args[0]->BooleanValue(context()->isolate());
if (args.Length() == 2) {
*error_message = "Error: " + std::string(*v8::String::Utf8Value(
args.GetIsolate(), args[1]));
......
......@@ -34,12 +34,9 @@ void SendRequestNatives::StartRequest(
base::ElapsedTimer timer;
CHECK_EQ(5, args.Length());
std::string name = *v8::String::Utf8Value(args.GetIsolate(), args[0]);
bool has_callback =
args[2]->BooleanValue(context()->v8_context()).FromMaybe(false);
bool for_io_thread =
args[3]->BooleanValue(context()->v8_context()).FromMaybe(false);
bool preserve_null_in_objects =
args[4]->BooleanValue(context()->v8_context()).FromMaybe(false);
bool has_callback = args[2]->BooleanValue(context()->isolate());
bool for_io_thread = args[3]->BooleanValue(context()->isolate());
bool preserve_null_in_objects = args[4]->BooleanValue(context()->isolate());
int request_id = request_sender_->GetNextRequestId();
args.GetReturnValue().Set(static_cast<int32_t>(request_id));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment