<commit_before>#include "node.h"
#include "timer.h"
#include <assert.h>

using namespace v8;
using namespace node;

#define REPEAT_SYMBOL   String::NewSymbol("repeat")

Persistent<FunctionTemplate> Timer::constructor_template;

void
Timer::Initialize (Handle<Object> target)
{
  HandleScope scope;

  Local<FunctionTemplate> t = FunctionTemplate::New(Timer::New);
  constructor_template = Persistent<FunctionTemplate>::New(t);
  constructor_template->Inherit(EventEmitter::constructor_template);
  constructor_template->InstanceTemplate()->SetInternalFieldCount(1);

  NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", Timer::Start);
  NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", Timer::Stop);

  constructor_template->PrototypeTemplate()->SetAccessor(REPEAT_SYMBOL,
      RepeatGetter, RepeatSetter);

  target->Set(String::NewSymbol("Timer"), constructor_template->GetFunction());
}

Handle<Value>
Timer::RepeatGetter (Local<String> property, const AccessorInfo& info)
{
  HandleScope scope;
  Timer *timer = NODE_UNWRAP(Timer, info.This());

  assert(timer);
  assert (property == REPEAT_SYMBOL);

  Local<Integer> v = Integer::New(timer->watcher_.repeat);

  return scope.Close(v);
}

void 
Timer::RepeatSetter (Local<String> property, Local<Value> value, const AccessorInfo& info)
{
  HandleScope scope;
  Timer *timer = NODE_UNWRAP(Timer, info.This());

  assert(timer);
  assert (property == REPEAT_SYMBOL);

  timer->watcher_.repeat = (double)(property->IntegerValue()) / 1000;
}

void
Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents)
{
  Timer *timer = static_cast<Timer*>(watcher->data);

  timer->Emit("Timeout", 0, NULL);

  /* XXX i'm a bit worried if this is the correct test? 
   * it's rather crutial for memory leaks the conditional here test to see
   * if the watcher will make another callback.
   */ 
  if (!ev_is_active(&timer->watcher_))<commit_msg>Timer::RepeatSetter wasn't getting the right value<commit_after>#include "node.h"
#include "timer.h"
#include <assert.h>

using namespace v8;
using namespace node;

#define REPEAT_SYMBOL   String::NewSymbol("repeat")

Persistent<FunctionTemplate> Timer::constructor_template;

void
Timer::Initialize (Handle<Object> target)
{
  HandleScope scope;

  Local<FunctionTemplate> t = FunctionTemplate::New(Timer::New);
  constructor_template = Persistent<FunctionTemplate>::New(t);
  constructor_template->Inherit(EventEmitter::constructor_template);
  constructor_template->InstanceTemplate()->SetInternalFieldCount(1);

  NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", Timer::Start);
  NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", Timer::Stop);

  constructor_template->PrototypeTemplate()->SetAccessor(REPEAT_SYMBOL,
      RepeatGetter, RepeatSetter);

  target->Set(String::NewSymbol("Timer"), constructor_template->GetFunction());
}

Handle<Value>
Timer::RepeatGetter (Local<String> property, const AccessorInfo& info)
{
  HandleScope scope;
  Timer *timer = NODE_UNWRAP(Timer, info.This());

  assert(timer);
  assert (property == REPEAT_SYMBOL);

  Local<Integer> v = Integer::New(timer->watcher_.repeat);

  return scope.Close(v);
}

void 
Timer::RepeatSetter (Local<String> property, Local<Value> value, const AccessorInfo& info)
{
  HandleScope scope;
  Timer *timer = NODE_UNWRAP(Timer, info.This());

  assert(timer);
  assert(property == REPEAT_SYMBOL);

  timer->watcher_.repeat = (double)(value->IntegerValue()) / 1000;
}

void
Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents)
{
  Timer *timer = static_cast<Timer*>(watcher->data);

  timer->Emit("Timeout", 0, NULL);

  /* XXX i'm a bit worried if this is the correct test? 
   * it's rather crutial for memory leaks the conditional here test to see
   * if the watcher will make another callback.
   */ 
  if (!ev_is_active(&timer->watcher_))
{'fraction_non_alphanumeric': 0.13188822146774615, 'fraction_numerical': 0.003656307129798903, 'mean_word_length': 6.267552182163188, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5662922', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1174, 'n_words': 263}