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

Unified Diff: extensions/renderer/i18n_custom_bindings.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/i18n_custom_bindings.cc
diff --git a/extensions/renderer/i18n_custom_bindings.cc b/extensions/renderer/i18n_custom_bindings.cc
index 762627088ef020edda6d8603b421177df45da93a..0ba18c208e06e1c468a0ebd8d68870af2d5a593c 100644
--- a/extensions/renderer/i18n_custom_bindings.cc
+++ b/extensions/renderer/i18n_custom_bindings.cc
@@ -10,6 +10,7 @@
#include "extensions/common/extension_messages.h"
#include "extensions/common/message_bundle.h"
#include "extensions/renderer/script_context.h"
+#include "extensions/renderer/v8_maybe_helpers.h"
namespace extensions {
@@ -73,22 +74,28 @@ void I18NCustomBindings::GetL10nMessage(
if (count > 9)
return;
for (uint32_t i = 0; i < count; ++i) {
- substitutions.push_back(*v8::String::Utf8Value(placeholders->Get(
- v8::Integer::New(isolate, i))));
+ v8::Local<v8::Value> param;
+ if (!placeholders->Get(isolate->GetCurrentContext(),
+ v8::Integer::New(isolate, i))
+ .ToLocal(&param))
+ return;
+ substitutions.push_back(*v8::String::Utf8Value(param));
}
} else if (args[1]->IsString()) {
// chrome.i18n.getMessage("message_name", "one param");
substitutions.push_back(*v8::String::Utf8Value(args[1]));
}
- args.GetReturnValue().Set(v8::String::NewFromUtf8(
- isolate,
- ReplaceStringPlaceholders(message, substitutions, NULL).c_str()));
+ std::string ret_value =
+ ReplaceStringPlaceholders(message, substitutions, NULL);
+ if (ret_value.size() >= v8::String::kMaxLength)
+ return;
+ args.GetReturnValue().Set(ToV8String(isolate, ret_value.c_str()));
}
void I18NCustomBindings::GetL10nUILanguage(
const v8::FunctionCallbackInfo<v8::Value>& args) {
- args.GetReturnValue().Set(v8::String::NewFromUtf8(
+ args.GetReturnValue().Set(ToV8String(
args.GetIsolate(), content::RenderThread::Get()->GetLocale().c_str()));
}

Powered by Google App Engine
This is Rietveld 408576698