Skip to content

Commit 77c2da1

Browse files
committed
timers: make Timer.close idempotent
fixes #1287 PR-URL: #1288 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent dbccf8d commit 77c2da1

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace node {
5555
V(bytes_parsed_string, "bytesParsed") \
5656
V(callback_string, "callback") \
5757
V(change_string, "change") \
58-
V(close_string, "close") \
58+
V(onclose_string, "_onclose") \
5959
V(code_string, "code") \
6060
V(compare_string, "compare") \
6161
V(ctime_string, "ctime") \

src/handle_wrap.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
5252
wrap->handle__ = nullptr;
5353

5454
if (args[0]->IsFunction()) {
55-
wrap->object()->Set(env->close_string(), args[0]);
55+
wrap->object()->Set(env->onclose_string(), args[0]);
5656
wrap->flags_ |= kCloseCallback;
5757
}
5858
}
@@ -94,7 +94,7 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
9494
Local<Object> object = wrap->object();
9595

9696
if (wrap->flags_ & kCloseCallback) {
97-
wrap->MakeCallback(env->close_string(), 0, nullptr);
97+
wrap->MakeCallback(env->onclose_string(), 0, nullptr);
9898
}
9999

100100
object->SetAlignedPointerInInternalField(0, nullptr);

test/parallel/test-timer-close.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var assert = require('assert');
2+
3+
var t = new (process.binding('timer_wrap').Timer);
4+
var called = 0;
5+
function onclose() {
6+
called++;
7+
}
8+
9+
t.close(onclose);
10+
t.close(onclose);
11+
12+
process.on('exit', function() {
13+
assert.equal(1, called);
14+
});

0 commit comments

Comments
 (0)