2010-05-25 09:40:33 +03:00
|
|
|
#include "rr.h"
|
|
|
|
#include "v8_date.h"
|
|
|
|
#include "v8_value.h"
|
2011-04-10 23:19:26 -05:00
|
|
|
#include "v8_handle.h"
|
2011-05-03 14:54:57 -05:00
|
|
|
#include "v8_object.h"
|
2010-05-25 09:40:33 +03:00
|
|
|
|
|
|
|
using namespace v8;
|
|
|
|
|
|
|
|
namespace {
|
2010-10-11 09:19:34 -05:00
|
|
|
|
2010-05-25 09:40:33 +03:00
|
|
|
VALUE DateClass;
|
2010-10-11 09:19:34 -05:00
|
|
|
|
2010-05-25 09:40:33 +03:00
|
|
|
VALUE New(VALUE self, VALUE time) {
|
|
|
|
HandleScope scope;
|
2011-04-10 23:19:26 -05:00
|
|
|
return rr_v8_handle_new(self, Date::New(NUM2DBL(time)));
|
2010-10-11 09:19:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Override Value::NumberValue in order to ensure that we call the more specific and optimized
|
|
|
|
// Number Value in v8::Date
|
|
|
|
VALUE NumberValue(VALUE self) {
|
2011-04-10 23:19:26 -05:00
|
|
|
Persistent<Date> date = rr_v8_handle<Date>(self);
|
2010-10-11 09:19:34 -05:00
|
|
|
return rr_v82rb(date->NumberValue());
|
2010-05-25 09:40:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rr_init_v8_date() {
|
2011-04-11 13:32:14 -05:00
|
|
|
DateClass = rr_define_class("Date", rr_v8_value_class());
|
2010-05-25 09:40:33 +03:00
|
|
|
rr_define_singleton_method(DateClass, "New", New, 1);
|
2010-10-11 09:19:34 -05:00
|
|
|
rr_define_method(DateClass, "NumberValue", NumberValue, 0);
|
2010-05-25 09:40:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE rr_reflect_v8_date(Handle<Value> value) {
|
2011-05-03 14:54:57 -05:00
|
|
|
return rr_reflect_v8_object_as(Handle<Object>::Cast(value), DateClass);
|
2010-05-25 09:40:33 +03:00
|
|
|
}
|