Avoiding modification of vm->retval in njs_add_event().
diff --git a/src/njs_event.c b/src/njs_event.c
index 011a666..56c831f 100644
--- a/src/njs_event.c
+++ b/src/njs_event.c
@@ -62,8 +62,6 @@
         return NJS_ERROR;
     }
 
-    njs_set_number(&vm->retval, vm->event_id - 1);
-
     return NJS_OK;
 }
 
diff --git a/src/njs_timer.c b/src/njs_timer.c
index 6c21ce0..d0356d2 100644
--- a/src/njs_timer.c
+++ b/src/njs_timer.c
@@ -68,7 +68,11 @@
         return NJS_ERROR;
     }
 
-    return njs_add_event(vm, event);
+    if (njs_add_event(vm, event) == NJS_OK) {
+        njs_set_number(&vm->retval, vm->event_id - 1);
+    }
+
+    return NJS_OK;
 
 memory_error: