Skip to content

Commit 0f51a3f

Browse files
committed
rename string allocation to v8_str
1 parent 9dd1ba6 commit 0f51a3f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/api/dispatcher.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141

4242
namespace nwapi {
4343

44+
static inline v8::Local<v8::String> v8_str(const char* x) {
45+
return v8::String::New(x);
46+
}
47+
4448
Dispatcher::Dispatcher(content::RenderView* render_view)
4549
: content::RenderViewObserver(render_view) {
4650
}
@@ -85,11 +89,11 @@ void Dispatcher::OnEvent(int object_id,
8589
v8::Handle<v8::Value> args = converter.ToV8Value(&arguments, node::g_context);
8690
DCHECK(!args.IsEmpty()) << "Invalid 'arguments' in Dispatcher::OnEvent";
8791
v8::Handle<v8::Value> argv[] = {
88-
v8::Integer::New(object_id), v8::String::New(event.c_str()), args };
92+
v8::Integer::New(object_id), v8_str(event.c_str()), args };
8993

9094
// __nwObjectsRegistry.handleEvent(object_id, event, arguments);
9195
v8::Handle<v8::Value> val =
92-
node::g_context->Global()->Get(v8::String::New("__nwObjectsRegistry"));
96+
node::g_context->Global()->Get(v8_str("__nwObjectsRegistry"));
9397
if (val->IsNull() || val->IsUndefined())
9498
return; // need to find out why it's undefined here in debugger
9599
v8::Handle<v8::Object> objects_registry = val->ToObject();
@@ -99,15 +103,15 @@ void Dispatcher::OnEvent(int object_id,
99103

100104
v8::Handle<v8::Object> Dispatcher::GetObjectRegistry() {
101105
v8::Handle<v8::Value> registry =
102-
node::g_context->Global()->Get(v8::String::New("__nwObjectsRegistry"));
106+
node::g_context->Global()->Get(v8_str("__nwObjectsRegistry"));
103107
// if (registry->IsNull() || registry->IsUndefined())
104108
// return v8::Undefined();
105109
return registry->ToObject();
106110
}
107111

108112
v8::Handle<v8::Value> Dispatcher::GetWindowId(WebKit::WebFrame* frame) {
109113
v8::Handle<v8::Value> v8win = frame->mainWorldScriptContext()->Global();
110-
v8::Handle<v8::Value> val = v8win->ToObject()->Get(v8::String::New("__nwWindowId"));
114+
v8::Handle<v8::Value> val = v8win->ToObject()->Get(v8_str("__nwWindowId"));
111115

112116
return val;
113117
}
@@ -127,7 +131,7 @@ void Dispatcher::ZoomLevelChanged() {
127131

128132
v8::Local<v8::Array> args = v8::Array::New();
129133
args->Set(0, v8::Number::New(zoom_level));
130-
v8::Handle<v8::Value> argv[] = {val, v8::String::New("zoom"), args };
134+
v8::Handle<v8::Value> argv[] = {val, v8_str("zoom"), args };
131135

132136
node::MakeCallback(objects_registry, "handleEvent", 3, argv);
133137
}

0 commit comments

Comments
 (0)