Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ created with. If this is called with a dead reference, `undefined` is returned.
Checks to see if `ref` is a dead reference. Returns `true` if the original Object
has already been GC'd, `false` otherwise.


### Boolean weak.isNearDeath(Weakref ref)

Checks to see if `ref` is "near death". This will be `true` exactly during the
weak reference callback function, and `false` any other time.


### Boolean weak.isWeakRef(Object obj)

Checks to see if `obj` is "weak reference" instance. Returns `true` if the
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
"function",
"callback"
],
"version": "1.0.1",
"version": "2.0.0",
"repository": {
"type": "git",
"url": "git://github.com/TooTallNate/node-weak.git"
},
"main": "lib/weak.js",
"scripts": {
"test": "mocha -gc --reporter spec"
"test": "mocha --expose-gc --gc-global --reporter spec"
},
"dependencies": {
"bindings": "^1.2.1",
"nan": "^2.0.5"
"bindings": "^1.5.0",
"nan": "^2.13.2"
},
"devDependencies": {
"mocha": "5"
"mocha": "6"
}
}
24 changes: 4 additions & 20 deletions src/weakref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static void TargetCallback(const Nan::WeakCallbackInfo<proxy_container> &info) {
// node::MakeCallback() which calls into process._tickCallback()
// too. Those other callbacks are not safe to run from here.
v8::Local<v8::Function> globalCallbackDirect = globalCallback->GetFunction();
globalCallbackDirect->Call(Nan::GetCurrentContext()->Global(), 1, argv);
globalCallbackDirect->Call(Nan::GetCurrentContext(), Nan::GetCurrentContext()->Global(), 1, argv);

// clean everything up
Local<Object> proxy = Nan::New<Object>(cont->proxy);
Expand All @@ -177,7 +177,9 @@ NAN_METHOD(Create) {

Local<Object> _target = info[0].As<Object>();
Local<Object> _emitter = info[1].As<Object>();
Local<Object> proxy = Nan::New<ObjectTemplate>(proxyClass)->NewInstance();

Local<Object> proxy = Nan::New<ObjectTemplate>(proxyClass)->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();

cont->proxy.Reset(proxy);
cont->emitter.Reset(_emitter);
cont->target.Reset(_target);
Expand Down Expand Up @@ -224,23 +226,6 @@ NAN_METHOD(Get) {
info.GetReturnValue().Set(Unwrap(proxy));
}

/**
* `isNearDeath(weakref)` JS function.
*/

NAN_METHOD(IsNearDeath) {
WEAKREF_FIRST_ARG

proxy_container *cont = reinterpret_cast<proxy_container*>(
Nan::GetInternalFieldPointer(proxy, FIELD_INDEX_CONTAINER)
);
assert(cont != NULL);

Local<Boolean> rtn = Nan::New<Boolean>(cont->target.IsNearDeath());

info.GetReturnValue().Set(rtn);
}

/**
* `isDead(weakref)` JS function.
*/
Expand Down Expand Up @@ -293,7 +278,6 @@ NAN_MODULE_INIT(Initialize) {

Nan::SetMethod(target, "get", Get);
Nan::SetMethod(target, "isWeakRef", IsWeakRef);
Nan::SetMethod(target, "isNearDeath", IsNearDeath);
Nan::SetMethod(target, "isDead", IsDead);
Nan::SetMethod(target, "_create", Create);
Nan::SetMethod(target, "_getEmitter", GetEmitter);
Expand Down
1 change: 0 additions & 1 deletion test/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('exports', function () {
checkFunction('get')
checkFunction('create')
checkFunction('isWeakRef')
checkFunction('isNearDeath')
checkFunction('isDead')
checkFunction('callbacks')
checkFunction('addCallback')
Expand Down