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

193 lines
5.3 KiB
C++
Raw Normal View History

2012-05-02 19:15:11 -04:00
#include "rr.h"
namespace rr {
void Value::Init() {
2012-05-04 00:22:36 -04:00
ClassBuilder("Value").
2012-05-25 16:53:13 -04:00
defineMethod("IsUndefined", &IsUndefined).
defineMethod("IsNull", &IsNull).
defineMethod("IsTrue", &IsTrue).
defineMethod("IsFalse", &IsFalse).
defineMethod("IsString", &IsString).
defineMethod("IsFunction", &IsFunction).
defineMethod("IsArray", &IsArray).
defineMethod("IsObject", &IsObject).
defineMethod("IsBoolean", &IsBoolean).
defineMethod("IsNumber", &IsNumber).
defineMethod("IsExternal", &IsExternal).
defineMethod("IsInt32", &IsInt32).
defineMethod("IsUint32", &IsUint32).
defineMethod("IsDate", &IsDate).
defineMethod("IsBooleanObject", &IsBooleanObject).
defineMethod("IsNumberObject", &IsNumberObject).
defineMethod("IsStringObject", &IsStringObject).
defineMethod("IsNativeError", &IsNativeError).
defineMethod("IsRegExp", &IsRegExp).
defineMethod("ToString", &ToString).
defineMethod("ToDetailString", &ToDetailString).
defineMethod("ToObject", &ToObject).
defineMethod("BooleanValue", &BooleanValue).
defineMethod("NumberValue", &NumberValue).
defineMethod("IntegerValue", &IntegerValue).
defineMethod("Uint32Value", &Uint32Value).
defineMethod("IntegerValue", &IntegerValue).
2012-05-04 00:22:36 -04:00
defineMethod("Equals", &Equals).
defineMethod("StrictEquals", &StrictEquals)
.store(&Class);
2012-05-04 00:22:36 -04:00
}
2012-05-25 16:53:13 -04:00
VALUE Value::IsUndefined(VALUE self) {
return Bool(Value(self)->IsUndefined());
}
VALUE Value::IsNull(VALUE self) {
return Bool(Value(self)->IsNull());
}
VALUE Value::IsTrue(VALUE self) {
return Bool(Value(self)->IsTrue());
}
VALUE Value::IsFalse(VALUE self) {
return Bool(Value(self)->IsFalse());
}
VALUE Value::IsString(VALUE self) {
return Bool(Value(self)->IsString());
}
VALUE Value::IsFunction(VALUE self) {
return Bool(Value(self)->IsFunction());
}
VALUE Value::IsArray(VALUE self) {
return Bool(Value(self)->IsArray());
}
VALUE Value::IsObject(VALUE self) {
return Bool(Value(self)->IsObject());
}
VALUE Value::IsBoolean(VALUE self) {
return Bool(Value(self)->IsBoolean());
}
VALUE Value::IsNumber(VALUE self) {
return Bool(Value(self)->IsNumber());
}
VALUE Value::IsExternal(VALUE self) {
return Bool(Value(self)->IsExternal());
}
VALUE Value::IsInt32(VALUE self) {
return Bool(Value(self)->IsInt32());
}
VALUE Value::IsUint32(VALUE self) {
return Bool(Value(self)->IsUint32());
}
VALUE Value::IsDate(VALUE self) {
return Bool(Value(self)->IsDate());
}
VALUE Value::IsBooleanObject(VALUE self) {
return Bool(Value(self)->IsBooleanObject());
}
VALUE Value::IsNumberObject(VALUE self) {
return Bool(Value(self)->IsNumberObject());
}
VALUE Value::IsStringObject(VALUE self) {
return Bool(Value(self)->IsStringObject());
}
VALUE Value::IsNativeError(VALUE self) {
return Bool(Value(self)->IsNativeError());
}
VALUE Value::IsRegExp(VALUE self) {
return Bool(Value(self)->IsRegExp());
}
// VALUE Value::ToBoolean(VALUE self) {
// return Boolean(Value(self)->ToBoolean());
// }
// VALUE Value::ToNumber(VALUE self) {
// return Number(Value(self)->ToNumber());
// }
VALUE Value::ToString(VALUE self) {
return String(Value(self)->ToString());
}
VALUE Value::ToDetailString(VALUE self) {
return String(Value(self)->ToDetailString());
}
VALUE Value::ToObject(VALUE self) {
return Object(Value(self)->ToObject());
}
// VALUE Value::ToInteger(VALUE self) {
// return Integer(Value(self)->ToInteger());
// }
// VALUE Value::ToUint32(VALUE self) {
// return Uint32(Value(self)->ToUint32());
// }
// VALUE Value::ToInt32(VALUE self) {
// return Int32(Value(self)->ToInt32());
// }
// VALUE Value::ToArrayIndex(VALUE self) {
// return Uint32(Value(self)->ToArrayIndex());
// }
VALUE Value::BooleanValue(VALUE self) {
return Bool(Value(self)->BooleanValue());
}
VALUE Value::NumberValue(VALUE self) {
return rb_float_new(Value(self)->NumberValue());
}
VALUE Value::IntegerValue(VALUE self) {
return INT2NUM(Value(self)->IntegerValue());
}
VALUE Value::Uint32Value(VALUE self) {
return UINT2NUM(Value(self)->Uint32Value());
}
VALUE Value::Int32Value(VALUE self) {
return INT2FIX(Value(self)->Int32Value());
}
2012-05-04 00:22:36 -04:00
VALUE Value::Equals(VALUE self, VALUE other) {
return Bool(Value(self)->Equals(Value(other)));
2012-05-04 00:22:36 -04:00
}
VALUE Value::StrictEquals(VALUE self, VALUE other) {
return Bool(Value(self)->StrictEquals(Value(other)));
}
Value::operator VALUE() {
if (handle.IsEmpty() || handle->IsUndefined() || handle->IsNull()) {
return Qnil;
}
2012-05-15 17:37:22 -04:00
if (handle->IsTrue()) {
return Qtrue;
}
if (handle->IsFalse()) {
return Qfalse;
}
if (handle->IsExternal()) {
return External((v8::Handle<v8::External>)v8::External::Cast(*handle));
}
if (handle->IsUint32()) {
return UInt32(handle->Uint32Value());
}
if (handle->IsInt32()) {
2012-05-23 00:06:21 -04:00
return INT2FIX(handle->Int32Value());
}
if (handle->IsBoolean()) {
return handle->BooleanValue() ? Qtrue : Qfalse;
}
if (handle->IsNumber()) {
return rb_float_new(handle->NumberValue());
}
if (handle->IsString()) {
return String(handle->ToString());
}
2012-06-07 11:02:10 -04:00
if (handle->IsDate()) {
return Date((v8::Handle<v8::Date>)v8::Date::Cast(*handle));
}
if (handle->IsObject()) {
return Object(handle->ToObject());
}
return Ref<v8::Value>::operator VALUE();
}
2012-05-02 19:15:11 -04:00
}