Simplify V8 operations.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 5 Dec 2013 02:35:57 +0000 (10:35 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 5 Dec 2013 02:35:57 +0000 (10:35 +0800)
browser/api/atom_api_app.cc

index 3bb7fd6..375087a 100644 (file)
@@ -101,11 +101,7 @@ v8::Handle<v8::Value> App::Focus(const v8::Arguments &args) {
 
 // static
 v8::Handle<v8::Value> App::GetVersion(const v8::Arguments &args) {
-  v8::HandleScope scope;
-
-  std::string version(Browser::Get()->GetVersion());
-
-  return v8::String::New(version.data(), version.size());
+  return ToV8Value(Browser::Get()->GetVersion());
 }
 
 // static
@@ -123,11 +119,7 @@ v8::Handle<v8::Value> App::SetVersion(const v8::Arguments &args) {
 
 // static
 v8::Handle<v8::Value> App::GetName(const v8::Arguments &args) {
-  v8::HandleScope scope;
-
-  std::string name(Browser::Get()->GetName());
-
-  return v8::String::New(name.data(), version.size());
+  return ToV8Value(Browser::Get()->GetName());
 }
 
 // static
@@ -179,7 +171,10 @@ v8::Handle<v8::Value> App::AppendArgument(const v8::Arguments &args) {
 
 // static
 v8::Handle<v8::Value> App::DockBounce(const v8::Arguments& args) {
-  std::string type = FromV8Value(args[0]);
+  std::string type;
+  if (!FromV8Arguments(args, &type))
+    return node::ThrowError("Bad argument");
+
   int request_id = -1;
 
   if (type == "critical")
@@ -189,7 +184,7 @@ v8::Handle<v8::Value> App::DockBounce(const v8::Arguments& args) {
   else
     return node::ThrowTypeError("Invalid bounce type");
 
-  return v8::Integer::New(request_id);
+  return ToV8Value(request_id);
 }
 
 // static