mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
53 lines
No EOL
1.2 KiB
C++
53 lines
No EOL
1.2 KiB
C++
#include "rr.h"
|
|
|
|
namespace rr {
|
|
|
|
void Value::Init() {
|
|
ClassBuilder("Value").
|
|
defineMethod("Equals", &Equals).
|
|
defineMethod("StrictEquals", &StrictEquals)
|
|
.store(&Class);
|
|
}
|
|
|
|
VALUE Value::Equals(VALUE self, VALUE other) {
|
|
return Bool(Value(self)->Equals(Value(other)));
|
|
}
|
|
|
|
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;
|
|
}
|
|
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()) {
|
|
return Int(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();
|
|
}
|
|
} |