2012-05-03 23:35:50 -04:00
|
|
|
#include "rr.h"
|
|
|
|
|
|
|
|
namespace rr {
|
|
|
|
|
2012-05-04 00:22:36 -04:00
|
|
|
VALUE Convert(bool b) {
|
|
|
|
return b ? Qtrue : Qfalse;
|
2012-05-03 23:35:50 -04:00
|
|
|
}
|
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) {
|
2012-05-03 23:35:50 -04:00
|
|
|
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()) {
|
2012-05-08 17:17:25 -04:00
|
|
|
return String::convert(value->ToString());
|
2012-05-03 23:35:50 -04:00
|
|
|
}
|
|
|
|
if (value->IsFunction()) {
|
|
|
|
// return Function(value);
|
|
|
|
}
|
|
|
|
if (value->IsArray()) {
|
|
|
|
// return Array(value);
|
|
|
|
}
|
|
|
|
if (value->IsDate()) {
|
|
|
|
// return rr_reflect_v8_date(value);
|
|
|
|
}
|
|
|
|
if (value->IsObject()) {
|
2012-05-08 17:17:25 -04:00
|
|
|
return Object::convert(value->ToObject());
|
2012-05-03 23:35:50 -04:00
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
}
|