Index: extensions/renderer/script_context.cc |
diff --git a/extensions/renderer/script_context.cc b/extensions/renderer/script_context.cc |
index 32222b0ca065128032dc5142f1401c19ba208368..56a157b9a6d9410006390afdb321ec95a30e1e6d 100644 |
--- a/extensions/renderer/script_context.cc |
+++ b/extensions/renderer/script_context.cc |
@@ -22,6 +22,7 @@ |
#include "extensions/common/features/base_feature_provider.h" |
#include "extensions/common/manifest_handlers/sandboxed_page_info.h" |
#include "extensions/common/permissions/permissions_data.h" |
+#include "extensions/renderer/v8_maybe_helpers.h" |
#include "gin/per_context_data.h" |
#include "third_party/WebKit/public/web/WebDataSource.h" |
#include "third_party/WebKit/public/web/WebDocument.h" |
@@ -181,8 +182,13 @@ v8::Local<v8::Value> ScriptContext::CallFunction( |
} |
v8::Local<v8::Object> global = v8_context()->Global(); |
- if (!web_frame_) |
- return handle_scope.Escape(function->Call(global, argc, argv)); |
+ if (!web_frame_) { |
+ v8::Local<v8::Value> result; |
+ if (function->Call(v8_context(), global, argc, argv).ToLocal(&result)) |
+ return handle_scope.Escape(result); |
+ return handle_scope.Escape( |
+ v8::Local<v8::Primitive>(v8::Undefined(isolate()))); |
+ } |
return handle_scope.Escape( |
v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled( |
function, global, argc, argv))); |
@@ -213,7 +219,7 @@ void ScriptContext::DispatchEvent(const char* event_name, |
v8::HandleScope handle_scope(isolate()); |
v8::Context::Scope context_scope(v8_context()); |
- v8::Local<v8::Value> argv[] = {v8::String::NewFromUtf8(isolate(), event_name), |
+ v8::Local<v8::Value> argv[] = {ToV8String(isolate(), event_name), |
args}; |
module_system_->CallModuleMethod( |
kEventBindings, "dispatchEvent", arraysize(argv), argv); |
@@ -296,14 +302,16 @@ void ScriptContext::OnResponseReceived(const std::string& name, |
const std::string& error) { |
v8::HandleScope handle_scope(isolate()); |
+ CHECK(name.size() < v8::String::kMaxLength); |
+ CHECK(error.size() < v8::String::kMaxLength); |
scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
v8::Local<v8::Value> argv[] = { |
v8::Integer::New(isolate(), request_id), |
- v8::String::NewFromUtf8(isolate(), name.c_str()), |
+ ToV8String(isolate(), name.c_str()), |
v8::Boolean::New(isolate(), success), |
converter->ToV8Value(&response, |
v8::Local<v8::Context>::New(isolate(), v8_context_)), |
- v8::String::NewFromUtf8(isolate(), error.c_str())}; |
+ ToV8String(isolate(), error.c_str())}; |
v8::Local<v8::Value> retval = module_system()->CallModuleMethod( |
"sendRequest", "handleResponse", arraysize(argv), argv); |
@@ -350,15 +358,17 @@ bool ScriptContext::HasAccessOrThrowError(const std::string& name) { |
static const char kMessage[] = |
"%s cannot be used within a sandboxed frame."; |
std::string error_msg = base::StringPrintf(kMessage, name.c_str()); |
+ CHECK(error_msg.size() < v8::String::kMaxLength); |
isolate()->ThrowException(v8::Exception::Error( |
- v8::String::NewFromUtf8(isolate(), error_msg.c_str()))); |
+ ToV8String(isolate(), error_msg.c_str()))); |
return false; |
} |
Feature::Availability availability = GetAvailability(name); |
if (!availability.is_available()) { |
+ CHECK(availability.message().size() < v8::String::kMaxLength); |
isolate()->ThrowException(v8::Exception::Error( |
- v8::String::NewFromUtf8(isolate(), availability.message().c_str()))); |
+ ToV8String(isolate(), availability.message().c_str()))); |
return false; |
} |