add line and column values to callback id
This commit is contained in:
parent
ac4df34ecd
commit
3a154ab8ea
8 changed files with 97 additions and 96 deletions
|
@ -2,10 +2,10 @@ ipc = require 'ipc'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
objectsRegistry = require './objects-registry.js'
|
objectsRegistry = require './objects-registry.js'
|
||||||
v8Util = process.atomBinding 'v8_util'
|
v8Util = process.atomBinding 'v8_util'
|
||||||
WeakMap = process.atomBinding('weak_map').WeakMap
|
IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap
|
||||||
|
|
||||||
# Weak reference to callback with their registry ID.
|
# Weak reference to callback with their registry ID.
|
||||||
rendererCallbacks = new WeakMap()
|
rendererCallbacks = new IDWeakMap()
|
||||||
|
|
||||||
# Convert a real value into meta data.
|
# Convert a real value into meta data.
|
||||||
valueToMeta = (sender, value, optimizeSimpleObject=false) ->
|
valueToMeta = (sender, value, optimizeSimpleObject=false) ->
|
||||||
|
|
79
atom/common/api/atom_api_id_weak_map.cc
Normal file
79
atom/common/api/atom_api_id_weak_map.cc
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
// Copyright (c) 2015 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#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 {
|
||||||
|
|
||||||
|
namespace api {
|
||||||
|
|
||||||
|
IDWeakMap::IDWeakMap() {
|
||||||
|
id_weak_map_.reset(new atom::IDWeakMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
IDWeakMap::~IDWeakMap() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDWeakMap::Set(v8::Isolate* isolate,
|
||||||
|
int32_t id,
|
||||||
|
v8::Local<v8::Object> object) {
|
||||||
|
id_weak_map_->Set(isolate, id, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Object> IDWeakMap::Get(v8::Isolate* isolate, int32_t id) {
|
||||||
|
return id_weak_map_->Get(isolate, id).ToLocalChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IDWeakMap::Has(int32_t id) {
|
||||||
|
return id_weak_map_->Has(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDWeakMap::Remove(int32_t id) {
|
||||||
|
id_weak_map_->Remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IDWeakMap::IsDestroyed() const {
|
||||||
|
return !id_weak_map_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void IDWeakMap::BuildPrototype(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::ObjectTemplate> prototype) {
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype)
|
||||||
|
.SetMethod("set", &IDWeakMap::Set)
|
||||||
|
.SetMethod("get", &IDWeakMap::Get)
|
||||||
|
.SetMethod("has", &IDWeakMap::Has)
|
||||||
|
.SetMethod("remove", &IDWeakMap::Remove);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
mate::Wrappable* IDWeakMap::Create(v8::Isolate* isolate) {
|
||||||
|
return new IDWeakMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace api
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using atom::api::IDWeakMap;
|
||||||
|
|
||||||
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
|
v8::Local<v8::Function> constructor = mate::CreateConstructor<IDWeakMap>(
|
||||||
|
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
|
||||||
|
|
||||||
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_id_weak_map, Initialize)
|
|
@ -2,8 +2,8 @@
|
||||||
// Use of this source code is governed by the MIT license that can be
|
// Use of this source code is governed by the MIT license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#ifndef ATOM_COMMON_API_ATOM_API_WEAK_MAP_H_
|
#ifndef ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
|
||||||
#define ATOM_COMMON_API_ATOM_API_WEAK_MAP_H_
|
#define ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
|
||||||
|
|
||||||
#include "atom/common/id_weak_map.h"
|
#include "atom/common/id_weak_map.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
|
@ -13,7 +13,7 @@ namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
class WeakMap : public mate::Wrappable {
|
class IDWeakMap : public mate::Wrappable {
|
||||||
public:
|
public:
|
||||||
static mate::Wrappable* Create(v8::Isolate* isolate);
|
static mate::Wrappable* Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ class WeakMap : public mate::Wrappable {
|
||||||
v8::Local<v8::ObjectTemplate> prototype);
|
v8::Local<v8::ObjectTemplate> prototype);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
WeakMap();
|
IDWeakMap();
|
||||||
virtual ~WeakMap();
|
virtual ~IDWeakMap();
|
||||||
|
|
||||||
// mate::Wrappable:
|
// mate::Wrappable:
|
||||||
bool IsDestroyed() const override;
|
bool IsDestroyed() const override;
|
||||||
|
@ -34,13 +34,13 @@ class WeakMap : public mate::Wrappable {
|
||||||
bool Has(int32_t id);
|
bool Has(int32_t id);
|
||||||
void Remove(int32_t id);
|
void Remove(int32_t id);
|
||||||
|
|
||||||
scoped_ptr<IDWeakMap> id_weak_map_;
|
scoped_ptr<atom::IDWeakMap> id_weak_map_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(WeakMap);
|
DISALLOW_COPY_AND_ASSIGN(IDWeakMap);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
||||||
#endif // ATOM_COMMON_API_ATOM_API_WEAK_MAP_H_
|
#endif // ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
|
|
@ -3,7 +3,6 @@
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "atom/common/api/object_life_monitor.h"
|
#include "atom/common/api/object_life_monitor.h"
|
||||||
#include "atom/common/id_weak_map.h"
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "v8/include/v8-profiler.h"
|
#include "v8/include/v8-profiler.h"
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
// Copyright (c) 2015 GitHub, Inc.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "atom/common/api/atom_api_weak_map.h"
|
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
|
||||||
#include "native_mate/constructor.h"
|
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
namespace api {
|
|
||||||
|
|
||||||
WeakMap::WeakMap() {
|
|
||||||
id_weak_map_.reset(new atom::IDWeakMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
WeakMap::~WeakMap() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void WeakMap::Set(v8::Isolate* isolate,
|
|
||||||
int32_t id,
|
|
||||||
v8::Local<v8::Object> object) {
|
|
||||||
id_weak_map_->Set(isolate, id, object);
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Local<v8::Object> WeakMap::Get(v8::Isolate* isolate, int32_t id) {
|
|
||||||
return id_weak_map_->Get(isolate, id).ToLocalChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WeakMap::Has(int32_t id) {
|
|
||||||
return id_weak_map_->Has(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WeakMap::Remove(int32_t id) {
|
|
||||||
id_weak_map_->Remove(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WeakMap::IsDestroyed() const {
|
|
||||||
return !id_weak_map_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
|
||||||
void WeakMap::BuildPrototype(v8::Isolate* isolate,
|
|
||||||
v8::Local<v8::ObjectTemplate> prototype) {
|
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
|
||||||
.SetMethod("set", &WeakMap::Set)
|
|
||||||
.SetMethod("get", &WeakMap::Get)
|
|
||||||
.SetMethod("has", &WeakMap::Has)
|
|
||||||
.SetMethod("remove", &WeakMap::Remove);
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
|
||||||
mate::Wrappable* WeakMap::Create(v8::Isolate* isolate) {
|
|
||||||
return new WeakMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace api
|
|
||||||
|
|
||||||
} // namespace atom
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
using atom::api::WeakMap;
|
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
|
||||||
v8::Local<v8::Function> constructor = mate::CreateConstructor<WeakMap>(
|
|
||||||
isolate, "WeakMap", base::Bind(&WeakMap::Create));
|
|
||||||
mate::Dictionary weak_map(isolate, constructor);
|
|
||||||
mate::Dictionary dict(isolate, exports);
|
|
||||||
dict.Set("WeakMap", weak_map);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_weak_map, Initialize)
|
|
|
@ -7,6 +7,9 @@ class CallbacksRegistry
|
||||||
@callbacks = {}
|
@callbacks = {}
|
||||||
|
|
||||||
add: (callback) ->
|
add: (callback) ->
|
||||||
|
if v8Util.getHiddenValue(callback, 'metaId')?
|
||||||
|
return v8Util.getHiddenValue(callback, 'metaId')
|
||||||
|
|
||||||
id = ++@nextId
|
id = ++@nextId
|
||||||
|
|
||||||
# Capture the location of the function and put it in the ID string,
|
# Capture the location of the function and put it in the ID string,
|
||||||
|
@ -19,11 +22,10 @@ class CallbacksRegistry
|
||||||
continue if location.indexOf('(native)') isnt -1
|
continue if location.indexOf('(native)') isnt -1
|
||||||
continue if location.indexOf('atom.asar') isnt -1
|
continue if location.indexOf('atom.asar') isnt -1
|
||||||
[x, filenameAndLine] = /([^/^\)]*)\)?$/gi.exec(location)
|
[x, filenameAndLine] = /([^/^\)]*)\)?$/gi.exec(location)
|
||||||
|
[x, line, column] = /(\d+):(\d+)/g.exec(filenameAndLine)
|
||||||
|
id += parseInt(line) + parseInt(column)
|
||||||
break
|
break
|
||||||
|
|
||||||
if v8Util.getHiddenValue(callback, 'metaId')?
|
|
||||||
return v8Util.getHiddenValue(callback, 'metaId')
|
|
||||||
|
|
||||||
@callbacks[id] = callback
|
@callbacks[id] = callback
|
||||||
v8Util.setHiddenValue callback, 'metaId', id
|
v8Util.setHiddenValue callback, 'metaId', id
|
||||||
v8Util.setHiddenValue callback, 'location', filenameAndLine
|
v8Util.setHiddenValue callback, 'location', filenameAndLine
|
||||||
|
|
|
@ -48,11 +48,11 @@ REFERENCE_MODULE(atom_browser_window);
|
||||||
REFERENCE_MODULE(atom_common_asar);
|
REFERENCE_MODULE(atom_common_asar);
|
||||||
REFERENCE_MODULE(atom_common_clipboard);
|
REFERENCE_MODULE(atom_common_clipboard);
|
||||||
REFERENCE_MODULE(atom_common_crash_reporter);
|
REFERENCE_MODULE(atom_common_crash_reporter);
|
||||||
|
REFERENCE_MODULE(atom_common_id_weak_map);
|
||||||
REFERENCE_MODULE(atom_common_native_image);
|
REFERENCE_MODULE(atom_common_native_image);
|
||||||
REFERENCE_MODULE(atom_common_screen);
|
REFERENCE_MODULE(atom_common_screen);
|
||||||
REFERENCE_MODULE(atom_common_shell);
|
REFERENCE_MODULE(atom_common_shell);
|
||||||
REFERENCE_MODULE(atom_common_v8_util);
|
REFERENCE_MODULE(atom_common_v8_util);
|
||||||
REFERENCE_MODULE(atom_common_weak_map);
|
|
||||||
REFERENCE_MODULE(atom_renderer_ipc);
|
REFERENCE_MODULE(atom_renderer_ipc);
|
||||||
REFERENCE_MODULE(atom_renderer_web_frame);
|
REFERENCE_MODULE(atom_renderer_web_frame);
|
||||||
#undef REFERENCE_MODULE
|
#undef REFERENCE_MODULE
|
||||||
|
|
|
@ -255,13 +255,13 @@
|
||||||
'atom/common/api/atom_api_asar.cc',
|
'atom/common/api/atom_api_asar.cc',
|
||||||
'atom/common/api/atom_api_clipboard.cc',
|
'atom/common/api/atom_api_clipboard.cc',
|
||||||
'atom/common/api/atom_api_crash_reporter.cc',
|
'atom/common/api/atom_api_crash_reporter.cc',
|
||||||
|
'atom/common/api/atom_api_id_weak_map.cc',
|
||||||
|
'atom/common/api/atom_api_id_weak_map.h',
|
||||||
'atom/common/api/atom_api_native_image.cc',
|
'atom/common/api/atom_api_native_image.cc',
|
||||||
'atom/common/api/atom_api_native_image.h',
|
'atom/common/api/atom_api_native_image.h',
|
||||||
'atom/common/api/atom_api_native_image_mac.mm',
|
'atom/common/api/atom_api_native_image_mac.mm',
|
||||||
'atom/common/api/atom_api_shell.cc',
|
'atom/common/api/atom_api_shell.cc',
|
||||||
'atom/common/api/atom_api_v8_util.cc',
|
'atom/common/api/atom_api_v8_util.cc',
|
||||||
'atom/common/api/atom_api_weak_map.cc',
|
|
||||||
'atom/common/api/atom_api_weak_map.h',
|
|
||||||
'atom/common/api/atom_bindings.cc',
|
'atom/common/api/atom_bindings.cc',
|
||||||
'atom/common/api/atom_bindings.h',
|
'atom/common/api/atom_bindings.h',
|
||||||
'atom/common/api/event_emitter_caller.cc',
|
'atom/common/api/event_emitter_caller.cc',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue