From 04d59991b0b6a1fe65e023aa4146844e87cc7052 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 11 May 2016 16:15:32 +0900 Subject: [PATCH] Use create function instead of IDWeakMap constructor --- atom/common/api/atom_api_id_weak_map.cc | 14 +++++--------- atom/common/api/atom_api_id_weak_map.h | 2 +- lib/browser/rpc-server.js | 9 +++++---- lib/renderer/api/remote.js | 7 +++---- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/atom/common/api/atom_api_id_weak_map.cc b/atom/common/api/atom_api_id_weak_map.cc index 1669f25373c9..93457943fce5 100644 --- a/atom/common/api/atom_api_id_weak_map.cc +++ b/atom/common/api/atom_api_id_weak_map.cc @@ -5,7 +5,6 @@ #include "atom/common/api/atom_api_id_weak_map.h" #include "atom/common/node_includes.h" -#include "native_mate/constructor.h" #include "native_mate/dictionary.h" namespace atom { @@ -13,6 +12,7 @@ namespace atom { namespace api { IDWeakMap::IDWeakMap(v8::Isolate* isolate) { + Init(isolate); } IDWeakMap::~IDWeakMap() { @@ -47,8 +47,8 @@ void IDWeakMap::BuildPrototype(v8::Isolate* isolate, } // static -mate::WrappableBase* IDWeakMap::Create(v8::Isolate* isolate) { - return new IDWeakMap(isolate); +mate::Handle IDWeakMap::Create(v8::Isolate* isolate) { + return mate::CreateHandle(isolate, new IDWeakMap(isolate)); } } // namespace api @@ -61,12 +61,8 @@ using atom::api::IDWeakMap; void Initialize(v8::Local exports, v8::Local unused, v8::Local context, void* priv) { - v8::Isolate* isolate = context->GetIsolate(); - v8::Local constructor = mate::CreateConstructor( - isolate, "IDWeakMap", base::Bind(&IDWeakMap::Create)); - mate::Dictionary id_weak_map(isolate, constructor); - mate::Dictionary dict(isolate, exports); - dict.Set("IDWeakMap", id_weak_map); + mate::Dictionary dict(context->GetIsolate(), exports); + dict.SetMethod("createIDWeakMap", &atom::api::IDWeakMap::Create); } } // namespace diff --git a/atom/common/api/atom_api_id_weak_map.h b/atom/common/api/atom_api_id_weak_map.h index 16012b4e20de..6d5a8bf7f430 100644 --- a/atom/common/api/atom_api_id_weak_map.h +++ b/atom/common/api/atom_api_id_weak_map.h @@ -15,7 +15,7 @@ namespace api { class IDWeakMap : public mate::Wrappable { public: - static mate::WrappableBase* Create(v8::Isolate* isolate); + static mate::Handle Create(v8::Isolate* isolate); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index 1dff5fdb8ade..00b0e9f468ee 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -1,10 +1,11 @@ 'use strict' const electron = require('electron') -const ipcMain = electron.ipcMain -const objectsRegistry = require('./objects-registry') const v8Util = process.atomBinding('v8_util') -const IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap +const {ipcMain} = electron +const {createIDWeakMap} = process.atomBinding('id_weak_map') + +const objectsRegistry = require('./objects-registry') // The internal properties of Function. const FUNCTION_PROPERTIES = [ @@ -13,7 +14,7 @@ const FUNCTION_PROPERTIES = [ // The remote functions in renderer processes. // id => Function -let rendererFunctions = new IDWeakMap() +let rendererFunctions = createIDWeakMap() // Merge two IDs together. let mergeIds = function (webContentsId, metaId) { diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index 6631ea22575a..ae3011c5eb1b 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -1,15 +1,14 @@ 'use strict' -const ipcRenderer = require('electron').ipcRenderer -const CallbacksRegistry = require('electron').CallbacksRegistry const v8Util = process.atomBinding('v8_util') -const IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap +const {ipcRenderer, CallbacksRegistry} = require('electron') +const {createIDWeakMap} = process.atomBinding('id_weak_map') const callbacksRegistry = new CallbacksRegistry() var includes = [].includes -var remoteObjectCache = new IDWeakMap() +var remoteObjectCache = createIDWeakMap() // Check for circular reference. var isCircular = function (field, visited) {