mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
support for JavaScript Date
This commit is contained in:
parent
c35d1d1de5
commit
2dabbfe5e1
4 changed files with 32 additions and 0 deletions
18
ext/v8/date.cc
Normal file
18
ext/v8/date.cc
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "rr.h"
|
||||
|
||||
namespace rr {
|
||||
|
||||
void Date::Init() {
|
||||
ClassBuilder("Date", Value::Class).
|
||||
defineSingletonMethod("New", &New).
|
||||
defineMethod("NumberValue", &NumberValue).
|
||||
store(&Class);
|
||||
}
|
||||
|
||||
VALUE Date::New(VALUE self, VALUE time) {
|
||||
return Value(v8::Date::New(NUM2DBL(time)));
|
||||
}
|
||||
VALUE Date::NumberValue(VALUE self) {
|
||||
return rb_float_new(Date(self)->NumberValue());
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
Object::Init();
|
||||
Array::Init();
|
||||
Function::Init();
|
||||
Date::Init();
|
||||
External::Init();
|
||||
Script::Init();
|
||||
Template::Init();
|
||||
|
|
10
ext/v8/rr.h
10
ext/v8/rr.h
|
@ -513,6 +513,16 @@ public:
|
|||
inline Function(v8::Handle<v8::Function> function) : Ref<v8::Function>(function) {}
|
||||
};
|
||||
|
||||
class Date : public Ref<v8::Date> {
|
||||
public:
|
||||
static void Init();
|
||||
static VALUE New(VALUE self, VALUE time);
|
||||
static VALUE NumberValue(VALUE self);
|
||||
|
||||
inline Date(VALUE value) : Ref<v8::Date>(value) {}
|
||||
inline Date(v8::Handle<v8::Date> date) : Ref<v8::Date>(date) {}
|
||||
};
|
||||
|
||||
class Signature : public Ref<v8::Signature> {
|
||||
public:
|
||||
static void Init();
|
||||
|
|
|
@ -182,6 +182,9 @@ Value::operator VALUE() {
|
|||
if (handle->IsString()) {
|
||||
return String(handle->ToString());
|
||||
}
|
||||
if (handle->IsDate()) {
|
||||
return Date((v8::Handle<v8::Date>)v8::Date::Cast(*handle));
|
||||
}
|
||||
if (handle->IsObject()) {
|
||||
return Object(handle->ToObject());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue