1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/ext/v8/converters.cpp
Bill Robertson 0e30abaff2 methods too
2010-01-09 10:52:30 -05:00

61 lines
No EOL
1.2 KiB
C++

#include "converters.h"
#include "callbacks.h"
#include "v8_ref.h"
#include "v8_obj.h"
using namespace v8;
namespace {
std::string UNDEFINED_STR("undefined");
}
VALUE V82RB(Handle<Value>& value) {
convert_v8_to_rb_t convert;
VALUE result;
if(convert(value, result)) {
return result;
}
if (value->IsObject()) {
Local<Object> object(Object::Cast(*value));
return V8_Ref_Create(V8_C_Object, value);
}
return Qnil;
}
Local<Value> RB2V8(VALUE value) {
VALUE valueClass = rb_class_of(value);
if(valueClass == rb_cProc || valueClass == rb_cMethod) {
Local<FunctionTemplate> t = FunctionTemplate::New(RacerRubyInvocationCallback, External::Wrap((void *)value));
return t->GetFunction();
}
convert_rb_to_v8_t convert;
return convert(value);
}
std::string RB2String(VALUE value) {
convert_rb_to_string_t convert;
return convert(value);
}
std::string V82String(Handle<Value>& value) {
convert_v8_to_string_t convert;
std::string result;
if(convert(value, result)) {
return result;
}
if (value->IsObject()) {
Local<Object> object(Object::Cast(*value));
Local<String> str = object->ToString();
if(convert(value, result)) {
return result;
}
}
return UNDEFINED_STR;
}