Commit bcf34be9 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] Remove v8_helpers::CallFunction

v8_helpers::CallFunction wraps v8::Function::Call. However, we should be
avoiding using v8::Function::Call whenever possible, since it doesn't
account for all possible state in the renderer (e.g., script suspension,
etc).

Remove v8_helpers::CallFunction and inline the v8::Function::Call at the
two places it was used, along with a TODO to update them.

Bug: None

Change-Id: If3358bfda74126c3898cea2483fc6a012bdd6f24
Reviewed-on: https://chromium-review.googlesource.com/823010Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523557}
parent aba55d24
...@@ -72,15 +72,21 @@ v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() { ...@@ -72,15 +72,21 @@ v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() {
create_binding_value.As<v8::Function>(); create_binding_value.As<v8::Function>();
// require('Binding').Binding.create(api_name); // require('Binding').Binding.create(api_name);
v8::Local<v8::Value> argv[] = {v8_api_name};
v8::Local<v8::Value> binding_instance_value;
v8::Local<v8::Object> binding_instance; v8::Local<v8::Object> binding_instance;
if (!CallFunction(v8_context, create_binding, binding, arraysize(argv), argv, {
&binding_instance_value) || v8::Local<v8::Value> argv[] = {v8_api_name};
!binding_instance_value->ToObject(v8_context) v8::Local<v8::Value> binding_instance_value;
.ToLocal(&binding_instance)) { v8::MicrotasksScope microtasks_scope(
NOTREACHED(); v8_context->GetIsolate(), v8::MicrotasksScope::kDoNotRunMicrotasks);
return v8::Local<v8::Object>(); // TODO(devlin): We should not be using v8::Function::Call() directly here.
// Instead, we should use JSRunner once it's used outside native bindings.
if (!create_binding->Call(v8_context, binding, arraysize(argv), argv)
.ToLocal(&binding_instance_value) ||
!binding_instance_value->ToObject(v8_context)
.ToLocal(&binding_instance)) {
NOTREACHED();
return v8::Local<v8::Object>();
}
} }
// require('binding').Binding.create(api_name).generate; // require('binding').Binding.create(api_name).generate;
...@@ -94,10 +100,16 @@ v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() { ...@@ -94,10 +100,16 @@ v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() {
// require('binding').Binding.create(api_name).generate(); // require('binding').Binding.create(api_name).generate();
v8::Local<v8::Value> compiled_schema; v8::Local<v8::Value> compiled_schema;
if (!CallFunction(v8_context, generate, binding_instance, 0, nullptr, {
&compiled_schema)) { v8::MicrotasksScope microtasks_scope(
NOTREACHED(); v8_context->GetIsolate(), v8::MicrotasksScope::kDoNotRunMicrotasks);
return v8::Local<v8::Object>(); // TODO(devlin): We should not be using v8::Function::Call() directly here.
// Instead, we should use JSRunner once it's used outside native bindings.
if (!generate->Call(v8_context, binding_instance, 0, nullptr)
.ToLocal(&compiled_schema)) {
NOTREACHED();
return v8::Local<v8::Object>();
}
} }
// var result = {}; // var result = {};
......
...@@ -143,18 +143,6 @@ inline v8::Local<v8::Value> GetPropertyUnsafe( ...@@ -143,18 +143,6 @@ inline v8::Local<v8::Value> GetPropertyUnsafe(
.ToLocalChecked(); .ToLocalChecked();
} }
// Wraps v8::Function::Call(). Returns true on success.
inline bool CallFunction(v8::Local<v8::Context> context,
v8::Local<v8::Function> function,
v8::Local<v8::Value> recv,
int argc,
v8::Local<v8::Value> argv[],
v8::Local<v8::Value>* out) {
v8::MicrotasksScope microtasks_scope(
context->GetIsolate(), v8::MicrotasksScope::kDoNotRunMicrotasks);
return function->Call(context, recv, argc, argv).ToLocal(out);
}
} // namespace v8_helpers } // namespace v8_helpers
} // namespace extensions } // namespace extensions
......
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