timers: make Timer.close idempotent
authorPetka Antonov <petka_antonov@hotmail.com>
Fri, 27 Mar 2015 18:43:25 +0000 (20:43 +0200)
committerPetka Antonov <petka_antonov@hotmail.com>
Fri, 27 Mar 2015 18:50:09 +0000 (20:50 +0200)
fixes #1287

PR-URL: https://github.com/iojs/io.js/pull/1288
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
src/env.h
src/handle_wrap.cc
test/parallel/test-timer-close.js [new file with mode: 0644]

index 027c79d..9099b3b 100644 (file)
--- a/src/env.h
+++ b/src/env.h
@@ -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")                                                    \
index 70e7cbb..341ecfd 100644 (file)
@@ -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;
   }
 }
@@ -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);
diff --git a/test/parallel/test-timer-close.js b/test/parallel/test-timer-close.js
new file mode 100644 (file)
index 0000000..b374fe1
--- /dev/null
@@ -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);
+});