Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: extensions/renderer/object_backed_native_handler.cc

Issue 1167423002: Use V8 Maybe APIs in extensions/renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/object_backed_native_handler.cc
diff --git a/extensions/renderer/object_backed_native_handler.cc b/extensions/renderer/object_backed_native_handler.cc
index b88bf32ca4cb291c6d5cfe86a09732f229e23d67..861a5b3ff1b2c5210804ed54bdf1c1e8cdbca367 100644
--- a/extensions/renderer/object_backed_native_handler.cc
+++ b/extensions/renderer/object_backed_native_handler.cc
@@ -9,6 +9,7 @@
#include "extensions/renderer/console.h"
#include "extensions/renderer/module_system.h"
#include "extensions/renderer/script_context.h"
+#include "extensions/renderer/v8_maybe_helpers.h"
#include "v8/include/v8.h"
namespace extensions {
@@ -28,9 +29,9 @@ ObjectBackedNativeHandler::ObjectBackedNativeHandler(ScriptContext* context)
ObjectBackedNativeHandler::~ObjectBackedNativeHandler() {
}
-v8::Local<v8::Object> ObjectBackedNativeHandler::NewInstance() {
+v8::MaybeLocal<v8::Object> ObjectBackedNativeHandler::NewInstance() {
return v8::Local<v8::ObjectTemplate>::New(GetIsolate(), object_template_)
- ->NewInstance();
+ ->NewInstance(context_->v8_context());
}
// static
@@ -38,11 +39,12 @@ void ObjectBackedNativeHandler::Router(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope(args.GetIsolate());
v8::Local<v8::Object> data = args.Data().As<v8::Object>();
+ v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
- v8::Local<v8::Value> handler_function_value =
- data->Get(v8::String::NewFromUtf8(args.GetIsolate(), kHandlerFunction));
+ v8::Local<v8::Value> handler_function_value;
// See comment in header file for why we do this.
- if (handler_function_value.IsEmpty() ||
+ if (!data->Get(context, ToV8String(args.GetIsolate(), kHandlerFunction))
+ .ToLocal(&handler_function_value) ||
handler_function_value->IsUndefined()) {
console::Error(args.GetIsolate()->GetCallingContext(),
"Extension view no longer exists");
@@ -58,11 +60,12 @@ void ObjectBackedNativeHandler::RouteFunction(
const HandlerFunction& handler_function) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handle_scope(isolate);
- v8::Context::Scope context_scope(context_->v8_context());
+ v8::Local<v8::Context> v8_context = context_->v8_context();
+ v8::Context::Scope context_scope(v8_context);
v8::Local<v8::Object> data = v8::Object::New(isolate);
- data->Set(
- v8::String::NewFromUtf8(isolate, kHandlerFunction),
+ SetProperty(
+ v8_context, data, ToV8String(isolate, kHandlerFunction),
v8::External::New(isolate, new HandlerFunction(handler_function)));
v8::Local<v8::FunctionTemplate> function_template =
v8::FunctionTemplate::New(isolate, Router, data);
@@ -78,16 +81,16 @@ v8::Isolate* ObjectBackedNativeHandler::GetIsolate() const {
void ObjectBackedNativeHandler::Invalidate() {
v8::Isolate* isolate = GetIsolate();
v8::HandleScope handle_scope(isolate);
- v8::Context::Scope context_scope(context_->v8_context());
+ v8::Local<v8::Context> v8_context = context_->v8_context();
+ v8::Context::Scope context_scope(v8_context);
for (size_t i = 0; i < router_data_.Size(); i++) {
v8::Local<v8::Object> data = router_data_.Get(i);
v8::Local<v8::Value> handler_function_value =
- data->Get(v8::String::NewFromUtf8(isolate, kHandlerFunction));
- CHECK(!handler_function_value.IsEmpty());
+ UnsafeGet(v8_context, data, ToV8String(isolate, kHandlerFunction));
delete static_cast<HandlerFunction*>(
handler_function_value.As<v8::External>()->Value());
- data->Delete(v8::String::NewFromUtf8(isolate, kHandlerFunction));
+ data->Delete(v8_context, ToV8String(isolate, kHandlerFunction));
}
router_data_.Clear();
« no previous file with comments | « extensions/renderer/object_backed_native_handler.h ('k') | extensions/renderer/process_info_native_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698