Skip to content
Closed
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
timers: make Timer.close idempotent
fixes #1287
  • Loading branch information
petkaantonov committed Mar 27, 2015
commit f1dbd36db04eb5ce6c7245dcc4504f4887df4ed8
2 changes: 1 addition & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace node {
V(bytes_parsed_string, "bytesParsed") \
V(callback_string, "callback") \
V(change_string, "change") \
V(close_string, "close") \
V(onclose_string, "_onclose") \
V(code_string, "code") \
V(compare_string, "compare") \
V(ctime_string, "ctime") \
Expand Down
4 changes: 2 additions & 2 deletions src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
wrap->handle__ = nullptr;

if (args[0]->IsFunction()) {
wrap->object()->Set(env->close_string(), args[0]);
wrap->object()->Set(env->onclose_string(), args[0]);
wrap->flags_ |= kCloseCallback;
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
Local<Object> object = wrap->object();

if (wrap->flags_ & kCloseCallback) {
wrap->MakeCallback(env->close_string(), 0, nullptr);
wrap->MakeCallback(env->onclose_string(), 0, nullptr);
}

object->SetAlignedPointerInInternalField(0, nullptr);
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-timer-close.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var assert = require('assert');

var t = new (process.binding('timer_wrap').Timer);
var called = 0;
function onclose() {
called++;
}

t.close(onclose);
t.close(onclose);

process.on('exit', function() {
assert.equal(1, called);
});