1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/ext/v8/convert.cc

47 lines
990 B
C++
Raw Normal View History

#include "rr.h"
namespace rr {
2012-05-04 00:22:36 -04:00
VALUE Convert(bool b) {
return b ? Qtrue : Qfalse;
}
2012-05-08 12:45:06 -04:00
VALUE Convert(int i) {
return INT2FIX(i);
}
2012-05-04 00:22:36 -04:00
VALUE Convert(v8::Handle<v8::Value> value) {
if (value.IsEmpty() || value->IsUndefined() || value->IsNull()) {
return Qnil;
}
if (value->IsExternal()) {
return Qnil;
}
if (value->IsUint32()) {
return UINT2NUM(value->Uint32Value());
}
if (value->IsInt32()) {
return INT2FIX(value->Int32Value());
}
if (value->IsBoolean()) {
return value->BooleanValue() ? Qtrue : Qfalse;
}
if (value->IsNumber()) {
return rb_float_new(value->NumberValue());
}
if (value->IsString()) {
return String::convert(value->ToString());
}
if (value->IsFunction()) {
// return Function(value);
}
if (value->IsArray()) {
// return Array(value);
}
if (value->IsDate()) {
// return rr_reflect_v8_date(value);
}
if (value->IsObject()) {
return Object::convert(value->ToObject());
}
return Qnil;
}
}