Use same name convention in string16_conversions.
This commit is contained in:
parent
8fdd3b3044
commit
a824c88352
9 changed files with 41 additions and 41 deletions
|
@ -26,7 +26,7 @@ v8::Handle<v8::Value> 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();
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ v8::Handle<v8::Value> 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_);
|
||||
|
|
|
@ -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<Menu>(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<v8::Value> 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<v8::Value> 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<v8::Value> 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<v8::Value> 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<v8::Value> 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<v8::Value> Menu::GetCommandIdAt(const v8::Arguments &args) {
|
|||
v8::Handle<v8::Value> 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<v8::Value> 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
|
||||
|
|
|
@ -465,7 +465,7 @@ v8::Handle<v8::Value> Window::GetPageTitle(const v8::Arguments &args) {
|
|||
|
||||
string16 title = self->window_->GetWebContents()->GetTitle();
|
||||
|
||||
return UTF16ToV8Value(title);
|
||||
return ToV8Value(title);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -55,7 +55,7 @@ void AtomBrowserBindings::OnRendererMessage(int process_id,
|
|||
// process.emit(channel, 'message', process_id, routing_id);
|
||||
std::vector<v8::Handle<v8::Value>> 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<v8::Handle<v8::Value>> 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));
|
||||
|
|
|
@ -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<v8::Value> value) {
|
||||
inline string16 FromV8Value(v8::Handle<v8::Value> value) {
|
||||
v8::String::Value s(value);
|
||||
return string16(reinterpret_cast<const char16*>(*s), s.length());
|
||||
}
|
||||
|
||||
// Converts string16 to V8 String.
|
||||
inline v8::Handle<v8::Value> UTF16ToV8Value(const string16& s) {
|
||||
inline v8::Handle<v8::Value> ToV8Value(const string16& s) {
|
||||
return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ inline v8::Handle<v8::Value> ToV8Value(int code) {
|
|||
return v8::Integer::New(code);
|
||||
}
|
||||
|
||||
inline
|
||||
v8::Handle<v8::Value> ToV8Value(const std::vector<base::FilePath>& paths) {
|
||||
v8::Handle<v8::Array> result = v8::Array::New(paths.size());
|
||||
for (size_t i = 0; i < paths.size(); ++i)
|
||||
|
@ -106,7 +107,7 @@ bool V8ValueCanBeConvertedTo<std::vector<std::string>>(
|
|||
return value->IsArray();
|
||||
}
|
||||
|
||||
template<>
|
||||
template<> inline
|
||||
bool V8ValueCanBeConvertedTo<atom::NativeWindow*>(v8::Handle<v8::Value> value) {
|
||||
using atom::api::Window;
|
||||
if (value->IsObject()) {
|
||||
|
@ -124,7 +125,7 @@ bool V8ValueCanBeConvertedTo<v8::Persistent<v8::Function>>(
|
|||
}
|
||||
|
||||
// Check and convert V8's Arguments to native types.
|
||||
template<typename T1, int index = 0>
|
||||
template<typename T1, int index = 0> inline
|
||||
bool FromV8Arguments(const v8::Arguments& args, T1* value) {
|
||||
if (!V8ValueCanBeConvertedTo<T1>(args[index]))
|
||||
return false;
|
||||
|
@ -132,18 +133,18 @@ bool FromV8Arguments(const v8::Arguments& args, T1* value) {
|
|||
return true;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
template<typename T1, typename T2> inline
|
||||
bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2) {
|
||||
return FromV8Arguments<T1>(args, a1) && FromV8Arguments<T2, 1>(args, a2);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
template<typename T1, typename T2, typename T3> inline
|
||||
bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2, T3* a3) {
|
||||
return FromV8Arguments<T1, T2>(args, a1, a2) &&
|
||||
FromV8Arguments<T3, 2>(args, a3);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4>
|
||||
template<typename T1, typename T2, typename T3, typename T4> inline
|
||||
bool FromV8Arguments(const v8::Arguments& args,
|
||||
T1* a1,
|
||||
T2* a2,
|
||||
|
@ -153,7 +154,7 @@ bool FromV8Arguments(const v8::Arguments& args,
|
|||
FromV8Arguments<T4, 3>(args, a4);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5> inline
|
||||
bool FromV8Arguments(const v8::Arguments& args,
|
||||
T1* a1,
|
||||
T2* a2,
|
||||
|
@ -165,7 +166,7 @@ bool FromV8Arguments(const v8::Arguments& args,
|
|||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6>
|
||||
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 T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7>
|
||||
typename T6, typename T7> inline
|
||||
bool FromV8Arguments(const v8::Arguments& args,
|
||||
T1* a1,
|
||||
T2* a2,
|
||||
|
|
|
@ -48,7 +48,7 @@ v8::Handle<v8::Value> 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<v8::Value> RendererIPC::SendSync(const v8::Arguments &args) {
|
|||
return node::ThrowTypeError("Bad argument");
|
||||
|
||||
v8::Handle<v8::Context> 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<v8::Value> 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
|
||||
|
|
|
@ -71,7 +71,7 @@ void AtomRendererBindings::OnBrowserMessage(const string16& channel,
|
|||
|
||||
std::vector<v8::Handle<v8::Value>> 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;
|
||||
|
|
Loading…
Reference in a new issue