1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/ext/v8/v8_date.cpp
2011-04-13 08:45:07 -05:00

35 lines
No EOL
885 B
C++

#include "rr.h"
#include "v8_date.h"
#include "v8_value.h"
#include "v8_handle.h"
using namespace v8;
namespace {
VALUE DateClass;
VALUE New(VALUE self, VALUE time) {
HandleScope scope;
return rr_v8_handle_new(self, Date::New(NUM2DBL(time)));
}
// Override Value::NumberValue in order to ensure that we call the more specific and optimized
// Number Value in v8::Date
VALUE NumberValue(VALUE self) {
Persistent<Date> date = rr_v8_handle<Date>(self);
return rr_v82rb(date->NumberValue());
}
}
void rr_init_v8_date() {
DateClass = rr_define_class("Date", rr_v8_value_class());
rr_define_singleton_method(DateClass, "New", New, 1);
rr_define_method(DateClass, "NumberValue", NumberValue, 0);
}
VALUE rr_reflect_v8_date(Handle<Value> value) {
HandleScope hs;
Local<Date> date(Date::Cast(*value));
return rr_v8_handle_new(DateClass, date);
}