Commit 6304d1b1 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[cleanup] Fix use of deprecated v8 methods in cast extensions

Replace deprecated parameterless *Type*Value() methods with the
*Type*Value(Local<Context>) equivalent method. Since these functions
return a Maybe, use FromMaybe() on the return value to guarantee a
return value even if the conversion could throw an exception.

(In future many of these could be converted to use
As<Int32>::Cast()->Value() if they had IsInt32 checks instead of
IsNumber).

This is the cast version of a chromium CL:
https://chromium-review.googlesource.com/c/chromium/src/+/1153247

Bug: v8:7786
Change-Id: I09a59a7de133ec429fa1aea1c5350e8af8bc81c3
Reviewed-on: https://chromium-review.googlesource.com/1174730Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583194}
parent e8e8d46d
......@@ -145,7 +145,10 @@ class TreeIDWrapper : public base::RefCountedThreadSafe<TreeIDWrapper> {
if (args.Length() != 1 || !args[0]->IsNumber())
ThrowInvalidArgumentsException(automation_bindings_);
int tree_id = args[0]->Int32Value();
int tree_id =
args[0]
->Int32Value(automation_bindings_->context()->v8_context())
.FromMaybe(0);
AutomationAXTreeWrapper* tree_wrapper =
automation_bindings_->GetAutomationAXTreeWrapperFromTreeID(tree_id);
if (!tree_wrapper)
......@@ -190,8 +193,10 @@ class NodeIDWrapper : public base::RefCountedThreadSafe<NodeIDWrapper> {
if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
ThrowInvalidArgumentsException(automation_bindings_);
int tree_id = args[0]->Int32Value();
int node_id = args[1]->Int32Value();
v8::Local<v8::Context> context =
automation_bindings_->context()->v8_context();
int tree_id = args[0]->Int32Value(context).FromMaybe(0);
int node_id = args[1]->Int32Value(context).FromMaybe(0);
AutomationAXTreeWrapper* tree_wrapper =
automation_bindings_->GetAutomationAXTreeWrapperFromTreeID(tree_id);
......@@ -242,8 +247,10 @@ class NodeIDPlusAttributeWrapper
ThrowInvalidArgumentsException(automation_bindings_);
}
int tree_id = args[0]->Int32Value();
int node_id = args[1]->Int32Value();
v8::Local<v8::Context> context =
automation_bindings_->context()->v8_context();
int tree_id = args[0]->Int32Value(context).FromMaybe(0);
int node_id = args[1]->Int32Value(context).FromMaybe(0);
std::string attribute = *v8::String::Utf8Value(isolate, args[2]);
AutomationAXTreeWrapper* tree_wrapper =
......@@ -296,10 +303,12 @@ class NodeIDPlusRangeWrapper
ThrowInvalidArgumentsException(automation_bindings_);
}
int tree_id = args[0]->Int32Value();
int node_id = args[1]->Int32Value();
int start = args[2]->Int32Value();
int end = args[3]->Int32Value();
v8::Local<v8::Context> context =
automation_bindings_->context()->v8_context();
int tree_id = args[0]->Int32Value(context).FromMaybe(0);
int node_id = args[1]->Int32Value(context).FromMaybe(0);
int start = args[2]->Int32Value(context).FromMaybe(0);
int end = args[3]->Int32Value(context).FromMaybe(0);
AutomationAXTreeWrapper* tree_wrapper =
automation_bindings_->GetAutomationAXTreeWrapperFromTreeID(tree_id);
......@@ -1028,7 +1037,7 @@ void AutomationInternalCustomBindings::DestroyAccessibilityTree(
return;
}
int tree_id = args[0]->Int32Value();
int tree_id = args[0]->Int32Value(context()->v8_context()).FromMaybe(0);
auto iter = tree_id_to_tree_wrapper_map_.find(tree_id);
if (iter == tree_id_to_tree_wrapper_map_.end())
return;
......@@ -1046,7 +1055,7 @@ void AutomationInternalCustomBindings::AddTreeChangeObserver(
}
TreeChangeObserver observer;
observer.id = args[0]->Int32Value();
observer.id = args[0]->Int32Value(context()->v8_context()).FromMaybe(0);
std::string filter_str = *v8::String::Utf8Value(args.GetIsolate(), args[1]);
observer.filter = api::automation::ParseTreeChangeObserverFilter(filter_str);
......@@ -1063,7 +1072,7 @@ void AutomationInternalCustomBindings::RemoveTreeChangeObserver(
return;
}
int observer_id = args[0]->Int32Value();
int observer_id = args[0]->Int32Value(context()->v8_context()).FromMaybe(0);
for (auto iter = tree_change_observers_.begin();
iter != tree_change_observers_.end(); ++iter) {
......@@ -1131,7 +1140,7 @@ void AutomationInternalCustomBindings::GetFocus(
return;
}
int tree_id = args[0]->Int32Value();
int tree_id = args[0]->Int32Value(context()->v8_context()).FromMaybe(0);
AutomationAXTreeWrapper* tree_wrapper =
GetAutomationAXTreeWrapperFromTreeID(tree_id);
if (!tree_wrapper)
......@@ -1154,8 +1163,8 @@ void AutomationInternalCustomBindings::GetHtmlAttributes(
if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
ThrowInvalidArgumentsException(this);
int tree_id = args[0]->Int32Value();
int node_id = args[1]->Int32Value();
int tree_id = args[0]->Int32Value(context()->v8_context()).FromMaybe(0);
int node_id = args[1]->Int32Value(context()->v8_context()).FromMaybe(0);
AutomationAXTreeWrapper* tree_wrapper =
GetAutomationAXTreeWrapperFromTreeID(tree_id);
......@@ -1178,8 +1187,8 @@ void AutomationInternalCustomBindings::GetState(
if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
ThrowInvalidArgumentsException(this);
int tree_id = args[0]->Int32Value();
int node_id = args[1]->Int32Value();
int tree_id = args[0]->Int32Value(context()->v8_context()).FromMaybe(0);
int node_id = args[1]->Int32Value(context()->v8_context()).FromMaybe(0);
AutomationAXTreeWrapper* tree_wrapper =
GetAutomationAXTreeWrapperFromTreeID(tree_id);
......@@ -1317,8 +1326,8 @@ void AutomationInternalCustomBindings::GetChildIDAtIndex(
return;
}
int tree_id = args[0]->Int32Value();
int node_id = args[1]->Int32Value();
int tree_id = args[0]->Int32Value(context()->v8_context()).FromMaybe(0);
int node_id = args[1]->Int32Value(context()->v8_context()).FromMaybe(0);
const auto iter = tree_id_to_tree_wrapper_map_.find(tree_id);
if (iter == tree_id_to_tree_wrapper_map_.end())
......@@ -1329,7 +1338,7 @@ void AutomationInternalCustomBindings::GetChildIDAtIndex(
if (!node)
return;
int index = args[2]->Int32Value();
int index = args[2]->Int32Value(context()->v8_context()).FromMaybe(0);
if (index < 0 || index >= node->child_count())
return;
......
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