Use create function instead of IDWeakMap constructor

This commit is contained in:
Cheng Zhao 2016-05-11 16:15:32 +09:00
parent c708ae8eb5
commit 04d59991b0
4 changed files with 14 additions and 18 deletions

View file

@ -5,7 +5,6 @@
#include "atom/common/api/atom_api_id_weak_map.h" #include "atom/common/api/atom_api_id_weak_map.h"
#include "atom/common/node_includes.h" #include "atom/common/node_includes.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
namespace atom { namespace atom {
@ -13,6 +12,7 @@ namespace atom {
namespace api { namespace api {
IDWeakMap::IDWeakMap(v8::Isolate* isolate) { IDWeakMap::IDWeakMap(v8::Isolate* isolate) {
Init(isolate);
} }
IDWeakMap::~IDWeakMap() { IDWeakMap::~IDWeakMap() {
@ -47,8 +47,8 @@ void IDWeakMap::BuildPrototype(v8::Isolate* isolate,
} }
// static // static
mate::WrappableBase* IDWeakMap::Create(v8::Isolate* isolate) { mate::Handle<IDWeakMap> IDWeakMap::Create(v8::Isolate* isolate) {
return new IDWeakMap(isolate); return mate::CreateHandle(isolate, new IDWeakMap(isolate));
} }
} // namespace api } // namespace api
@ -61,12 +61,8 @@ using atom::api::IDWeakMap;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused, void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) { v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate(); mate::Dictionary dict(context->GetIsolate(), exports);
v8::Local<v8::Function> constructor = mate::CreateConstructor<IDWeakMap>( dict.SetMethod("createIDWeakMap", &atom::api::IDWeakMap::Create);
isolate, "IDWeakMap", base::Bind(&IDWeakMap::Create));
mate::Dictionary id_weak_map(isolate, constructor);
mate::Dictionary dict(isolate, exports);
dict.Set("IDWeakMap", id_weak_map);
} }
} // namespace } // namespace

View file

@ -15,7 +15,7 @@ namespace api {
class IDWeakMap : public mate::Wrappable<IDWeakMap> { class IDWeakMap : public mate::Wrappable<IDWeakMap> {
public: public:
static mate::WrappableBase* Create(v8::Isolate* isolate); static mate::Handle<IDWeakMap> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype); v8::Local<v8::ObjectTemplate> prototype);

View file

@ -1,10 +1,11 @@
'use strict' 'use strict'
const electron = require('electron') const electron = require('electron')
const ipcMain = electron.ipcMain
const objectsRegistry = require('./objects-registry')
const v8Util = process.atomBinding('v8_util') 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. // The internal properties of Function.
const FUNCTION_PROPERTIES = [ const FUNCTION_PROPERTIES = [
@ -13,7 +14,7 @@ const FUNCTION_PROPERTIES = [
// The remote functions in renderer processes. // The remote functions in renderer processes.
// id => Function // id => Function
let rendererFunctions = new IDWeakMap() let rendererFunctions = createIDWeakMap()
// Merge two IDs together. // Merge two IDs together.
let mergeIds = function (webContentsId, metaId) { let mergeIds = function (webContentsId, metaId) {

View file

@ -1,15 +1,14 @@
'use strict' 'use strict'
const ipcRenderer = require('electron').ipcRenderer
const CallbacksRegistry = require('electron').CallbacksRegistry
const v8Util = process.atomBinding('v8_util') 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() const callbacksRegistry = new CallbacksRegistry()
var includes = [].includes var includes = [].includes
var remoteObjectCache = new IDWeakMap() var remoteObjectCache = createIDWeakMap()
// Check for circular reference. // Check for circular reference.
var isCircular = function (field, visited) { var isCircular = function (field, visited) {