add line and column values to callback id

This commit is contained in:
Robo 2015-10-29 16:52:12 +05:30
parent ac4df34ecd
commit 3a154ab8ea
8 changed files with 97 additions and 96 deletions

View file

@ -2,10 +2,10 @@ ipc = require 'ipc'
path = require 'path'
objectsRegistry = require './objects-registry.js'
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.
rendererCallbacks = new WeakMap()
rendererCallbacks = new IDWeakMap()
# Convert a real value into meta data.
valueToMeta = (sender, value, optimizeSimpleObject=false) ->

View 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)

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_API_ATOM_API_WEAK_MAP_H_
#define ATOM_COMMON_API_ATOM_API_WEAK_MAP_H_
#ifndef ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
#define ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
#include "atom/common/id_weak_map.h"
#include "native_mate/object_template_builder.h"
@ -13,7 +13,7 @@ namespace atom {
namespace api {
class WeakMap : public mate::Wrappable {
class IDWeakMap : public mate::Wrappable {
public:
static mate::Wrappable* Create(v8::Isolate* isolate);
@ -21,8 +21,8 @@ class WeakMap : public mate::Wrappable {
v8::Local<v8::ObjectTemplate> prototype);
protected:
WeakMap();
virtual ~WeakMap();
IDWeakMap();
virtual ~IDWeakMap();
// mate::Wrappable:
bool IsDestroyed() const override;
@ -34,13 +34,13 @@ class WeakMap : public mate::Wrappable {
bool Has(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 atom
#endif // ATOM_COMMON_API_ATOM_API_WEAK_MAP_H_
#endif // ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_

View file

@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "atom/common/api/object_life_monitor.h"
#include "atom/common/id_weak_map.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
#include "v8/include/v8-profiler.h"

View file

@ -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)

View file

@ -7,6 +7,9 @@ class CallbacksRegistry
@callbacks = {}
add: (callback) ->
if v8Util.getHiddenValue(callback, 'metaId')?
return v8Util.getHiddenValue(callback, 'metaId')
id = ++@nextId
# 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('atom.asar') isnt -1
[x, filenameAndLine] = /([^/^\)]*)\)?$/gi.exec(location)
[x, line, column] = /(\d+):(\d+)/g.exec(filenameAndLine)
id += parseInt(line) + parseInt(column)
break
if v8Util.getHiddenValue(callback, 'metaId')?
return v8Util.getHiddenValue(callback, 'metaId')
@callbacks[id] = callback
v8Util.setHiddenValue callback, 'metaId', id
v8Util.setHiddenValue callback, 'location', filenameAndLine

View file

@ -48,11 +48,11 @@ REFERENCE_MODULE(atom_browser_window);
REFERENCE_MODULE(atom_common_asar);
REFERENCE_MODULE(atom_common_clipboard);
REFERENCE_MODULE(atom_common_crash_reporter);
REFERENCE_MODULE(atom_common_id_weak_map);
REFERENCE_MODULE(atom_common_native_image);
REFERENCE_MODULE(atom_common_screen);
REFERENCE_MODULE(atom_common_shell);
REFERENCE_MODULE(atom_common_v8_util);
REFERENCE_MODULE(atom_common_weak_map);
REFERENCE_MODULE(atom_renderer_ipc);
REFERENCE_MODULE(atom_renderer_web_frame);
#undef REFERENCE_MODULE

View file

@ -255,13 +255,13 @@
'atom/common/api/atom_api_asar.cc',
'atom/common/api/atom_api_clipboard.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.h',
'atom/common/api/atom_api_native_image_mac.mm',
'atom/common/api/atom_api_shell.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.h',
'atom/common/api/event_emitter_caller.cc',