Commit 0b46881f authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[cleanup] Fix use of deprecated v8 methods in pepper

Fixes uses of Object::Set, Get, ToObject and GetPropertyNames in
content/renderer/pepper/ppb_var_deprecated_impl.cc.

Bug: v8:7283, v8:7286, v8:7279, v8:8238
Change-Id: I54b420f7173b23d241508ad697c0410c8ae45da6
Reviewed-on: https://chromium-review.googlesource.com/c/1349332Reviewed-by: default avatarBill Budge <bbudge@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610921}
parent 4335a96e
......@@ -56,6 +56,11 @@ ppapi::ScopedPPVar PepperTryCatch::FromV8(v8::Local<v8::Value> v8_value) {
return result;
}
ppapi::ScopedPPVar PepperTryCatch::FromV8Maybe(
v8::MaybeLocal<v8::Value> v8_value) {
return FromV8(v8_value.FromMaybe(v8::Local<v8::Value>()));
}
PepperTryCatchV8::PepperTryCatchV8(PepperPluginInstanceImpl* instance,
V8VarConverter* var_converter,
v8::Isolate* isolate)
......
......@@ -35,6 +35,7 @@ class CONTENT_EXPORT PepperTryCatch {
// exception if there is an error in the conversion.
v8::Local<v8::Value> ToV8(PP_Var var);
ppapi::ScopedPPVar FromV8(v8::Local<v8::Value> v8_value);
ppapi::ScopedPPVar FromV8Maybe(v8::MaybeLocal<v8::Value> v8_value);
protected:
// Make sure that |instance_| is alive for the lifetime of PepperTryCatch.
......
......@@ -132,10 +132,12 @@ bool HasMethodDeprecated(PP_Var var, PP_Var name, PP_Var* exception) {
return false;
}
bool result = has_name && accessor.GetObject()->Get(v8_name)->IsFunction();
if (try_catch.HasException())
if (!has_name)
return false;
return result;
v8::Local<v8::Value> function;
return accessor.GetObject()->Get(context, v8_name).ToLocal(&function) &&
function->IsFunction();
}
PP_Var GetProperty(PP_Var var, PP_Var name, PP_Var* exception) {
......@@ -149,7 +151,9 @@ PP_Var GetProperty(PP_Var var, PP_Var name, PP_Var* exception) {
if (try_catch.HasException())
return PP_MakeUndefined();
ScopedPPVar result_var = try_catch.FromV8(accessor.GetObject()->Get(v8_name));
v8::Local<v8::Value> result;
ScopedPPVar result_var = try_catch.FromV8Maybe(
accessor.GetObject()->Get(try_catch.GetContext(), v8_name));
if (try_catch.HasException())
return PP_MakeUndefined();
......@@ -170,12 +174,14 @@ void EnumerateProperties(PP_Var var,
*properties = nullptr;
*property_count = 0;
v8::Local<v8::Array> identifiers = accessor.GetObject()->GetPropertyNames();
if (try_catch.HasException())
v8::Local<v8::Context> context = try_catch.GetContext();
v8::Local<v8::Array> identifiers;
if (!accessor.GetObject()->GetPropertyNames(context).ToLocal(&identifiers))
return;
ScopedPPVarArray identifier_vars(identifiers->Length());
for (uint32_t i = 0; i < identifiers->Length(); ++i) {
ScopedPPVar identifier = try_catch.FromV8(identifiers->Get(i));
ScopedPPVar identifier =
try_catch.FromV8Maybe(identifiers->Get(context, i));
if (try_catch.HasException())
return;
identifier_vars.Set(i, identifier);
......@@ -203,8 +209,11 @@ void SetPropertyDeprecated(PP_Var var,
if (try_catch.HasException())
return;
accessor.GetObject()->Set(v8_name, v8_value);
try_catch.HasException(); // Ensure an exception gets set if one occured.
if (accessor.GetObject()
->Set(try_catch.GetContext(), v8_name, v8_value)
.IsNothing()) {
try_catch.HasException(); // Ensure an exception gets set.
}
}
void DeletePropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) {
......@@ -260,11 +269,15 @@ PP_Var CallDeprecatedInternal(PP_Var var,
}
v8::Local<v8::Object> function = accessor.GetObject();
v8::Local<v8::Object> recv =
accessor.instance()->GetMainWorldContext()->Global();
v8::Local<v8::Context> context = accessor.instance()->GetMainWorldContext();
v8::Local<v8::Object> recv = context->Global();
if (v8_method_name.As<v8::String>()->Length() != 0) {
function = function->Get(v8_method_name)
->ToObject(accessor.instance()->GetIsolate());
v8::Local<v8::Value> value;
if (!function->Get(context, v8_method_name).ToLocal(&value) ||
!value->ToObject(context).ToLocal(&function)) {
try_catch.SetException(kUnableToCallMethodException);
return PP_MakeUndefined();
}
recv = accessor.GetObject();
}
......
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