From a824c88352d13bab7cf55939d9404a6b702b2452 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Sep 2013 23:00:58 +0800 Subject: [PATCH] Use same name convention in string16_conversions. --- browser/api/atom_api_browser_ipc.cc | 2 +- browser/api/atom_api_event.cc | 2 +- browser/api/atom_api_menu.cc | 40 +++++++++++++------------- browser/api/atom_api_window.cc | 2 +- browser/api/atom_browser_bindings.cc | 4 +-- common/string16_conversions.h | 7 ++--- common/v8_conversions.h | 17 +++++------ renderer/api/atom_api_renderer_ipc.cc | 6 ++-- renderer/api/atom_renderer_bindings.cc | 2 +- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/browser/api/atom_api_browser_ipc.cc b/browser/api/atom_api_browser_ipc.cc index d100cb4e0c99..763a3dfba708 100644 --- a/browser/api/atom_api_browser_ipc.cc +++ b/browser/api/atom_api_browser_ipc.cc @@ -26,7 +26,7 @@ v8::Handle BrowserIPC::Send(const v8::Arguments &args) { if (!args[0]->IsString() || !args[1]->IsNumber() || !args[2]->IsNumber()) return node::ThrowTypeError("Bad argument"); - string16 channel(V8ValueToUTF16(args[0])); + string16 channel(FromV8Value(args[0])); int process_id = args[1]->IntegerValue(); int routing_id = args[2]->IntegerValue(); diff --git a/browser/api/atom_api_event.cc b/browser/api/atom_api_event.cc index 5a6ff2828bc9..7ab144670427 100644 --- a/browser/api/atom_api_event.cc +++ b/browser/api/atom_api_event.cc @@ -90,7 +90,7 @@ v8::Handle Event::SendReply(const v8::Arguments& args) { if (event->message_ == NULL) return node::ThrowError("Can only send reply to synchronous events once"); - string16 json = V8ValueToUTF16(args[0]); + string16 json = FromV8Value(args[0]); AtomViewHostMsg_Message_Sync::WriteReplyParams(event->message_, json); event->sender_->Send(event->message_); diff --git a/browser/api/atom_api_menu.cc b/browser/api/atom_api_menu.cc index df9f97a98afc..afb7e1577572 100644 --- a/browser/api/atom_api_menu.cc +++ b/browser/api/atom_api_menu.cc @@ -4,9 +4,9 @@ #include "browser/api/atom_api_menu.h" -#include "browser/api/atom_api_window.h" #include "browser/ui/accelerator_util.h" #include "common/string16_conversions.h" +#include "common/v8_conversions.h" #define UNWRAP_MEMNU_AND_CHECK \ Menu* self = ObjectWrap::Unwrap(args.This()); \ @@ -100,18 +100,18 @@ bool Menu::IsItemForCommandIdDynamic(int command_id) const { string16 Menu::GetLabelForCommandId(int command_id) const { v8::HandleScope scope; - return V8ValueToUTF16(CallDelegate(v8::False(), - handle(), - "getLabelForCommandId", - command_id)); + return FromV8Value(CallDelegate(v8::False(), + handle(), + "getLabelForCommandId", + command_id)); } string16 Menu::GetSublabelForCommandId(int command_id) const { v8::HandleScope scope; - return V8ValueToUTF16(CallDelegate(v8::False(), - handle(), - "getSubLabelForCommandId", - command_id)); + return FromV8Value(CallDelegate(v8::False(), + handle(), + "getSubLabelForCommandId", + command_id)); } void Menu::ExecuteCommand(int command_id, int event_flags) { @@ -141,10 +141,10 @@ v8::Handle Menu::InsertItem(const v8::Arguments &args) { int index = args[0]->IntegerValue(); if (index < 0) - self->model_->AddItem(args[1]->IntegerValue(), V8ValueToUTF16(args[2])); + self->model_->AddItem(args[1]->IntegerValue(), FromV8Value(args[2])); else self->model_->InsertItemAt( - index, args[1]->IntegerValue(), V8ValueToUTF16(args[2])); + index, args[1]->IntegerValue(), FromV8Value(args[2])); return v8::Undefined(); } @@ -160,9 +160,9 @@ v8::Handle Menu::InsertCheckItem(const v8::Arguments &args) { int command_id = args[1]->IntegerValue(); if (index < 0) - self->model_->AddCheckItem(command_id, V8ValueToUTF16(args[2])); + self->model_->AddCheckItem(command_id, FromV8Value(args[2])); else - self->model_->InsertCheckItemAt(index, command_id, V8ValueToUTF16(args[2])); + self->model_->InsertCheckItemAt(index, command_id, FromV8Value(args[2])); return v8::Undefined(); } @@ -182,10 +182,10 @@ v8::Handle Menu::InsertRadioItem(const v8::Arguments &args) { int group_id = args[3]->IntegerValue(); if (index < 0) - self->model_->AddRadioItem(command_id, V8ValueToUTF16(args[2]), group_id); + self->model_->AddRadioItem(command_id, FromV8Value(args[2]), group_id); else self->model_->InsertRadioItemAt( - index, command_id, V8ValueToUTF16(args[2]), group_id); + index, command_id, FromV8Value(args[2]), group_id); return v8::Undefined(); } @@ -226,10 +226,10 @@ v8::Handle Menu::InsertSubMenu(const v8::Arguments &args) { if (index < 0) self->model_->AddSubMenu( - command_id, V8ValueToUTF16(args[2]), submenu->model_.get()); + command_id, FromV8Value(args[2]), submenu->model_.get()); else self->model_->InsertSubMenuAt( - index, command_id, V8ValueToUTF16(args[2]), submenu->model_.get()); + index, command_id, FromV8Value(args[2]), submenu->model_.get()); return v8::Undefined(); } @@ -253,7 +253,7 @@ v8::Handle Menu::SetSublabel(const v8::Arguments &args) { if (!args[0]->IsNumber() || !args[1]->IsString()) return node::ThrowTypeError("Bad argument"); - self->model_->SetSublabel(args[0]->IntegerValue(), V8ValueToUTF16(args[1])); + self->model_->SetSublabel(args[0]->IntegerValue(), FromV8Value(args[1])); return v8::Undefined(); } @@ -291,14 +291,14 @@ v8::Handle Menu::GetCommandIdAt(const v8::Arguments &args) { v8::Handle Menu::GetLabelAt(const v8::Arguments &args) { UNWRAP_MEMNU_AND_CHECK; int index = args[0]->IntegerValue(); - return UTF16ToV8Value(self->model_->GetLabelAt(index)); + return ToV8Value(self->model_->GetLabelAt(index)); } // static v8::Handle Menu::GetSublabelAt(const v8::Arguments &args) { UNWRAP_MEMNU_AND_CHECK; int index = args[0]->IntegerValue(); - return UTF16ToV8Value(self->model_->GetSublabelAt(index)); + return ToV8Value(self->model_->GetSublabelAt(index)); } // static diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 192c318e6795..be582d87794c 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -465,7 +465,7 @@ v8::Handle Window::GetPageTitle(const v8::Arguments &args) { string16 title = self->window_->GetWebContents()->GetTitle(); - return UTF16ToV8Value(title); + return ToV8Value(title); } // static diff --git a/browser/api/atom_browser_bindings.cc b/browser/api/atom_browser_bindings.cc index 44df9a6c44d1..9c2189460f6e 100644 --- a/browser/api/atom_browser_bindings.cc +++ b/browser/api/atom_browser_bindings.cc @@ -55,7 +55,7 @@ void AtomBrowserBindings::OnRendererMessage(int process_id, // process.emit(channel, 'message', process_id, routing_id); std::vector> arguments; arguments.reserve(3 + args.GetSize()); - arguments.push_back(UTF16ToV8Value(channel)); + arguments.push_back(ToV8Value(channel)); const base::Value* value; if (args.Get(0, &value)) arguments.push_back(converter->ToV8Value(value, context)); @@ -91,7 +91,7 @@ void AtomBrowserBindings::OnRendererMessageSync( // process.emit(channel, 'sync-message', event, process_id, routing_id); std::vector> arguments; arguments.reserve(3 + args.GetSize()); - arguments.push_back(UTF16ToV8Value(channel)); + arguments.push_back(ToV8Value(channel)); const base::Value* value; if (args.Get(0, &value)) arguments.push_back(converter->ToV8Value(value, context)); diff --git a/common/string16_conversions.h b/common/string16_conversions.h index 314eb1b50a0c..db2d5da0bffe 100644 --- a/common/string16_conversions.h +++ b/common/string16_conversions.h @@ -5,18 +5,17 @@ #ifndef COMMON_STRING16_CONVERSIONS_H_ #define COMMON_STRING16_CONVERSIONS_H_ +#include "base/string16.h" #include "v8/include/v8.h" -class string16; - // Converts a V8 value to a string16. -inline string16 V8ValueToUTF16(v8::Handle value) { +inline string16 FromV8Value(v8::Handle value) { v8::String::Value s(value); return string16(reinterpret_cast(*s), s.length()); } // Converts string16 to V8 String. -inline v8::Handle UTF16ToV8Value(const string16& s) { +inline v8::Handle ToV8Value(const string16& s) { return v8::String::New(reinterpret_cast(s.data()), s.size()); } diff --git a/common/v8_conversions.h b/common/v8_conversions.h index b483d665915d..a82e5978c99c 100644 --- a/common/v8_conversions.h +++ b/common/v8_conversions.h @@ -72,6 +72,7 @@ inline v8::Handle ToV8Value(int code) { return v8::Integer::New(code); } +inline v8::Handle ToV8Value(const std::vector& paths) { v8::Handle result = v8::Array::New(paths.size()); for (size_t i = 0; i < paths.size(); ++i) @@ -106,7 +107,7 @@ bool V8ValueCanBeConvertedTo>( return value->IsArray(); } -template<> +template<> inline bool V8ValueCanBeConvertedTo(v8::Handle value) { using atom::api::Window; if (value->IsObject()) { @@ -124,7 +125,7 @@ bool V8ValueCanBeConvertedTo>( } // Check and convert V8's Arguments to native types. -template +template inline bool FromV8Arguments(const v8::Arguments& args, T1* value) { if (!V8ValueCanBeConvertedTo(args[index])) return false; @@ -132,18 +133,18 @@ bool FromV8Arguments(const v8::Arguments& args, T1* value) { return true; } -template +template inline bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2) { return FromV8Arguments(args, a1) && FromV8Arguments(args, a2); } -template +template inline bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2, T3* a3) { return FromV8Arguments(args, a1, a2) && FromV8Arguments(args, a3); } -template +template inline bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2, @@ -153,7 +154,7 @@ bool FromV8Arguments(const v8::Arguments& args, FromV8Arguments(args, a4); } -template +template inline bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2, @@ -165,7 +166,7 @@ bool FromV8Arguments(const v8::Arguments& args, } template + typename T6> inline bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2, @@ -178,7 +179,7 @@ bool FromV8Arguments(const v8::Arguments& args, } template + typename T6, typename T7> inline bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2, diff --git a/renderer/api/atom_api_renderer_ipc.cc b/renderer/api/atom_api_renderer_ipc.cc index 4bdbd4b8094f..16ded0687127 100644 --- a/renderer/api/atom_api_renderer_ipc.cc +++ b/renderer/api/atom_api_renderer_ipc.cc @@ -48,7 +48,7 @@ v8::Handle RendererIPC::Send(const v8::Arguments &args) { if (!args[0]->IsString()) return node::ThrowTypeError("Bad argument"); - string16 channel(V8ValueToUTF16(args[0])); + string16 channel = FromV8Value(args[0]); RenderView* render_view = GetCurrentRenderView(); // Convert Arguments to Array, so we can use V8ValueConverter to convert it @@ -82,7 +82,7 @@ v8::Handle RendererIPC::SendSync(const v8::Arguments &args) { return node::ThrowTypeError("Bad argument"); v8::Handle context = v8::Context::GetCurrent(); - string16 channel(V8ValueToUTF16(args[0])); + string16 channel = FromV8Value(args[0]); // Convert Arguments to Array, so we can use V8ValueConverter to convert it // to ListValue. @@ -110,7 +110,7 @@ v8::Handle RendererIPC::SendSync(const v8::Arguments &args) { if (!success) return node::ThrowError("Unable to send AtomViewHostMsg_Message_Sync"); - return scope.Close(UTF16ToV8Value(json)); + return scope.Close(ToV8Value(json)); } // static diff --git a/renderer/api/atom_renderer_bindings.cc b/renderer/api/atom_renderer_bindings.cc index e0260b9a279a..61d908785697 100644 --- a/renderer/api/atom_renderer_bindings.cc +++ b/renderer/api/atom_renderer_bindings.cc @@ -71,7 +71,7 @@ void AtomRendererBindings::OnBrowserMessage(const string16& channel, std::vector> arguments; arguments.reserve(1 + args.GetSize()); - arguments.push_back(UTF16ToV8Value(channel)); + arguments.push_back(ToV8Value(channel)); for (size_t i = 0; i < args.GetSize(); i++) { const base::Value* value;