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

Side by Side Diff: extensions/renderer/utils_native_handler.cc

Issue 1192763002: extensions: Use V8 Maybe APIs in NativeHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « extensions/renderer/module_system.cc ('k') | extensions/renderer/v8_context_native_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/utils_native_handler.h" 5 #include "extensions/renderer/utils_native_handler.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "extensions/renderer/script_context.h" 8 #include "extensions/renderer/script_context.h"
9 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" 9 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
10 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" 10 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 v8::Local<v8::Value> func_as_value = context()->module_system()->RunString( 55 v8::Local<v8::Value> func_as_value = context()->module_system()->RunString(
56 source, v8::String::NewFromUtf8(GetIsolate(), name.c_str())); 56 source, v8::String::NewFromUtf8(GetIsolate(), name.c_str()));
57 if (func_as_value.IsEmpty() || func_as_value->IsUndefined()) { 57 if (func_as_value.IsEmpty() || func_as_value->IsUndefined()) {
58 args.GetReturnValue().SetUndefined(); 58 args.GetReturnValue().SetUndefined();
59 return; 59 return;
60 } 60 }
61 61
62 // TODO(fsamuel): Move privates from ModuleSystem to a shared location. 62 // TODO(fsamuel): Move privates from ModuleSystem to a shared location.
63 v8::Local<v8::Object> natives(context()->module_system()->NewInstance()); 63 v8::Local<v8::Object> natives(context()->module_system()->NewInstance());
64 CHECK(!natives.IsEmpty()); // this can happen if v8 has issues 64 CHECK(!natives.IsEmpty()); // this can happen if v8 has issues
65
65 v8::Local<v8::Function> func = func_as_value.As<v8::Function>(); 66 v8::Local<v8::Function> func = func_as_value.As<v8::Function>();
66 v8::Local<v8::Value> func_args[] = { 67 v8::Local<v8::Value> func_args[] = {
67 context()->safe_builtins()->GetObjekt(), 68 context()->safe_builtins()->GetObjekt(),
68 context()->safe_builtins()->GetFunction(), 69 context()->safe_builtins()->GetFunction(),
69 natives->Get(v8::String::NewFromUtf8(GetIsolate(), "privates", 70 natives->Get(v8::String::NewFromUtf8(GetIsolate(), "privates",
70 v8::String::kInternalizedString)), 71 v8::String::kInternalizedString)),
71 cls, 72 cls,
72 superclass}; 73 superclass};
73 v8::Local<v8::Value> result; 74 v8::Local<v8::Value> result;
74 { 75 {
75 v8::TryCatch try_catch; 76 v8::TryCatch try_catch;
76 try_catch.SetCaptureMessage(true); 77 try_catch.SetCaptureMessage(true);
77 result = context()->CallFunction(func, arraysize(func_args), func_args); 78 result = context()->CallFunction(func, arraysize(func_args), func_args);
78 if (try_catch.HasCaught()) { 79 if (try_catch.HasCaught()) {
79 args.GetReturnValue().SetUndefined(); 80 args.GetReturnValue().SetUndefined();
80 return; 81 return;
81 } 82 }
82 } 83 }
83 args.GetReturnValue().Set(result); 84 args.GetReturnValue().Set(result);
84 } 85 }
85 86
86 void UtilsNativeHandler::DeepCopy( 87 void UtilsNativeHandler::DeepCopy(
87 const v8::FunctionCallbackInfo<v8::Value>& args) { 88 const v8::FunctionCallbackInfo<v8::Value>& args) {
88 CHECK_EQ(1, args.Length()); 89 CHECK_EQ(1, args.Length());
89 args.GetReturnValue().Set( 90 args.GetReturnValue().Set(
90 blink::WebSerializedScriptValue::serialize(args[0]).deserialize()); 91 blink::WebSerializedScriptValue::serialize(args[0]).deserialize());
91 } 92 }
92 93
93 } // namespace extensions 94 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/module_system.cc ('k') | extensions/renderer/v8_context_native_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698