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

53 lines
1.2 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").
defineMethod("Equals", &Equals).
defineMethod("StrictEquals", &StrictEquals)
.store(&Class);
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 UINT2NUM(handle->Uint32Value());
}
if (handle->IsInt32()) {
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());
}
if (handle->IsObject()) {
return Object(handle->ToObject());
}
return Ref<v8::Value>::operator VALUE();
}
2012-05-02 19:15:11 -04:00
}