]> khamidou — GitHub mirrors - electron.git/commitdiff
Use Dictionary to set module.exports.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 16 Apr 2014 07:31:59 +0000 (15:31 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 16 Apr 2014 07:43:06 +0000 (15:43 +0800)
atom/common/api/atom_api_clipboard.cc
atom/common/api/atom_api_crash_reporter.cc
atom/common/api/atom_api_screen.cc
atom/common/api/atom_api_shell.cc
atom/common/api/atom_api_v8_util.cc
atom/renderer/api/atom_api_renderer_ipc.cc
vendor/native_mate

index d41e0ff8859bb88c177bf40def81af9f63ee0004..3bb3758608303763eea97441d14b3036d954328c 100644 (file)
@@ -5,7 +5,7 @@
 #include <string>
 #include <vector>
 
-#include "native_mate/object_template_builder.h"
+#include "native_mate/dictionary.h"
 #include "ui/base/clipboard/clipboard.h"
 
 #include "atom/common/v8/node_common.h"
@@ -49,13 +49,12 @@ void Clear() {
 }
 
 void Initialize(v8::Handle<v8::Object> exports) {
-  mate::ObjectTemplateBuilder builder(v8::Isolate::GetCurrent());
-  builder.SetMethod("has", &Has)
-         .SetMethod("read", &Read)
-         .SetMethod("readText", &ReadText)
-         .SetMethod("writeText", &WriteText)
-         .SetMethod("clear", &Clear);
-  exports->SetPrototype(builder.Build()->NewInstance());
+  mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
+  dict.SetMethod("has", &Has);
+  dict.SetMethod("read", &Read);
+  dict.SetMethod("readText", &ReadText);
+  dict.SetMethod("writeText", &WriteText);
+  dict.SetMethod("clear", &Clear);
 }
 
 }  // namespace
index ba840e36d28cd3f880a06930ce69daf09781da46..a3338e7ed3cda5af5d6b1605b756717948eb7c97 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "atom/common/crash_reporter/crash_reporter.h"
 #include "base/bind.h"
-#include "native_mate/object_template_builder.h"
+#include "native_mate/dictionary.h"
 
 #include "atom/common/v8/node_common.h"
 
@@ -37,11 +37,10 @@ namespace {
 
 void Initialize(v8::Handle<v8::Object> exports) {
   using crash_reporter::CrashReporter;
-  mate::ObjectTemplateBuilder builder(v8::Isolate::GetCurrent());
-  builder.SetMethod("start",
-                    base::Bind(&CrashReporter::Start,
-                               base::Unretained(CrashReporter::GetInstance())));
-  exports->SetPrototype(builder.Build()->NewInstance());
+  mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
+  dict.SetMethod("start",
+                 base::Bind(&CrashReporter::Start,
+                            base::Unretained(CrashReporter::GetInstance())));
 }
 
 }  // namespace
index 2814cb68dde624f29b1d29a7ddbb45ad53c33bb7..1b244cde281b7b657c506dc59f8e9cf7c15c6479 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "native_mate/object_template_builder.h"
+#include "native_mate/dictionary.h"
 #include "ui/gfx/screen.h"
 
 #include "atom/common/v8/node_common.h"
@@ -92,15 +92,13 @@ void Initialize(v8::Handle<v8::Object> exports) {
 #endif
 
   gfx::Screen* screen = gfx::Screen::GetNativeScreen();
-
-  mate::ObjectTemplateBuilder builder(v8::Isolate::GetCurrent());
-  builder.SetMethod("getCursorScreenPoint",
-                    base::Bind(&gfx::Screen::GetCursorScreenPoint,
-                               base::Unretained(screen)))
-         .SetMethod("getPrimaryDisplay",
-                    base::Bind(&gfx::Screen::GetPrimaryDisplay,
-                               base::Unretained(screen)));
-  exports->SetPrototype(builder.Build()->NewInstance());
+  mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
+  dict.SetMethod("getCursorScreenPoint",
+                 base::Bind(&gfx::Screen::GetCursorScreenPoint,
+                            base::Unretained(screen)));
+  dict.SetMethod("getPrimaryDisplay",
+                 base::Bind(&gfx::Screen::GetPrimaryDisplay,
+                            base::Unretained(screen)));
 }
 
 }  // namespace
index be6ab614d33236714e6214e39da50f2eb4ca6efd..edb90997a34806c4c34e391b53a0b2ad18e0bb08 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "atom/common/platform_util.h"
 #include "atom/common/v8_converters/file_path_converter.h"
-#include "native_mate/object_template_builder.h"
+#include "native_mate/dictionary.h"
 #include "url/gurl.h"
 
 #include "atom/common/v8/node_common.h"
@@ -33,13 +33,12 @@ struct Converter<GURL> {
 namespace {
 
 void Initialize(v8::Handle<v8::Object> exports) {
-  mate::ObjectTemplateBuilder builder(v8::Isolate::GetCurrent());
-  builder.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder)
-         .SetMethod("openItem", &platform_util::OpenItem)
-         .SetMethod("openExternal", &platform_util::OpenExternal)
-         .SetMethod("moveItemToTrash", &platform_util::MoveItemToTrash)
-         .SetMethod("beep", &platform_util::Beep);
-  exports->SetPrototype(builder.Build()->NewInstance());
+  mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
+  dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder);
+  dict.SetMethod("openItem", &platform_util::OpenItem);
+  dict.SetMethod("openExternal", &platform_util::OpenExternal);
+  dict.SetMethod("moveItemToTrash", &platform_util::MoveItemToTrash);
+  dict.SetMethod("beep", &platform_util::Beep);
 }
 
 }  // namespace
index 2bebf53df417f6c702a8980210c8b95cb71c817e..8889591f0b26ebd62076d7377df80b8650215cf7 100644 (file)
@@ -3,57 +3,54 @@
 // found in the LICENSE file.
 
 #include "atom/common/api/object_life_monitor.h"
+#include "native_mate/dictionary.h"
 #include "v8/include/v8-profiler.h"
 
 #include "atom/common/v8/node_common.h"
 
-namespace atom {
-
-namespace api {
-
 namespace {
 
-void CreateObjectWithName(const v8::FunctionCallbackInfo<v8::Value>& args) {
+v8::Handle<v8::Object> CreateObjectWithName(v8::Handle<v8::String> name) {
   v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
-  t->SetClassName(args[0]->ToString());
-  args.GetReturnValue().Set(t->GetFunction()->NewInstance());
+  t->SetClassName(name);
+  return t->GetFunction()->NewInstance();
 }
 
-void GetHiddenValue(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  args.GetReturnValue().Set(
-      args[0]->ToObject()->GetHiddenValue(args[1]->ToString()));
+v8::Handle<v8::Value> GetHiddenValue(v8::Handle<v8::Object> object,
+                                     v8::Handle<v8::String> key) {
+  return object->GetHiddenValue(key);
 }
 
-void SetHiddenValue(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  args[0]->ToObject()->SetHiddenValue(args[1]->ToString(), args[2]);
+void SetHiddenValue(v8::Handle<v8::Object> object,
+                    v8::Handle<v8::String> key,
+                    v8::Handle<v8::Value> value) {
+  object->SetHiddenValue(key, value);
 }
 
-void GetObjectHash(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  args.GetReturnValue().Set(args[0]->ToObject()->GetIdentityHash());
+int32_t GetObjectHash(v8::Handle<v8::Object> object) {
+  return object->GetIdentityHash();
 }
 
-void SetDestructor(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  ObjectLifeMonitor::BindTo(args[0]->ToObject(), args[1]);
+void SetDestructor(v8::Handle<v8::Object> object,
+                   v8::Handle<v8::Function> callback) {
+  atom::ObjectLifeMonitor::BindTo(object, callback);
 }
 
-void TakeHeapSnapshot(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void TakeHeapSnapshot() {
   node::node_isolate->GetHeapProfiler()->TakeHeapSnapshot(
       v8::String::New("test"));
 }
 
-}  // namespace
-
-void InitializeV8Util(v8::Handle<v8::Object> target) {
-  NODE_SET_METHOD(target, "createObjectWithName", CreateObjectWithName);
-  NODE_SET_METHOD(target, "getHiddenValue", GetHiddenValue);
-  NODE_SET_METHOD(target, "setHiddenValue", SetHiddenValue);
-  NODE_SET_METHOD(target, "getObjectHash", GetObjectHash);
-  NODE_SET_METHOD(target, "setDestructor", SetDestructor);
-  NODE_SET_METHOD(target, "takeHeapSnapshot", TakeHeapSnapshot);
+void Initialize(v8::Handle<v8::Object> exports) {
+  mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
+  dict.SetMethod("createObjectWithName", &CreateObjectWithName);
+  dict.SetMethod("getHiddenValue", &GetHiddenValue);
+  dict.SetMethod("setHiddenValue", &SetHiddenValue);
+  dict.SetMethod("getObjectHash", &GetObjectHash);
+  dict.SetMethod("setDestructor", &SetDestructor);
+  dict.SetMethod("takeHeapSnapshot", &TakeHeapSnapshot);
 }
 
-}  // namespace api
-
-}  // namespace atom
+}  // namespace
 
-NODE_MODULE(atom_common_v8_util, atom::api::InitializeV8Util)
+NODE_MODULE(atom_common_v8_util, Initialize)
index bd305f1977f776666877bb5213bf4581f0c3e2a1..c93d8a0a3bbc374c3cdb543a6525e0a96ecd0e5c 100644 (file)
@@ -6,7 +6,7 @@
 #include "atom/common/v8/v8_value_converter.h"
 #include "atom/common/v8_converters/string16_converter.h"
 #include "content/public/renderer/render_view.h"
-#include "native_mate/object_template_builder.h"
+#include "native_mate/dictionary.h"
 #include "third_party/WebKit/public/web/WebFrame.h"
 #include "third_party/WebKit/public/web/WebView.h"
 
@@ -83,10 +83,9 @@ string16 SendSync(const string16& channel, const base::ListValue& arguments) {
 }
 
 void Initialize(v8::Handle<v8::Object> exports) {
-  mate::ObjectTemplateBuilder builder(v8::Isolate::GetCurrent());
-  builder.SetMethod("send", &Send)
-         .SetMethod("sendSync", &SendSync);
-  exports->SetPrototype(builder.Build()->NewInstance());
+  mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
+  dict.SetMethod("send", &Send);
+  dict.SetMethod("sendSync", &SendSync);
 }
 
 }  // namespace
index c9fa29ef640e8d3d2edf6b48c2311b16ce314464..94dec0ff85c9337d33cae01638897bc1059b7dca 160000 (submodule)
@@ -1 +1 @@
-Subproject commit c9fa29ef640e8d3d2edf6b48c2311b16ce314464
+Subproject commit 94dec0ff85c9337d33cae01638897bc1059b7dca