2010-05-08 12:58:43 -05:00
|
|
|
#include "rr.h"
|
2010-05-17 15:13:23 +03:00
|
|
|
#include "v8_cxt.h"
|
2010-05-11 12:41:07 -05:00
|
|
|
#include "v8_value.h"
|
2010-05-13 17:14:54 -05:00
|
|
|
#include "v8_obj.h"
|
2010-05-13 17:10:48 -05:00
|
|
|
#include "v8_func.h"
|
2010-05-17 14:39:29 +03:00
|
|
|
#include "v8_array.h"
|
2010-05-12 17:30:53 -05:00
|
|
|
#include "v8_str.h"
|
2010-05-25 09:40:33 +03:00
|
|
|
#include "v8_date.h"
|
2010-05-18 13:27:23 +03:00
|
|
|
#include "v8_msg.h"
|
2010-06-08 12:48:13 +03:00
|
|
|
#include "v8_external.h"
|
2010-05-11 12:41:07 -05:00
|
|
|
|
|
|
|
using namespace v8;
|
2010-05-08 12:58:43 -05:00
|
|
|
|
2010-05-10 07:56:52 -05:00
|
|
|
VALUE rr_define_class(const char *name, VALUE superclass) {
|
2010-05-08 12:58:43 -05:00
|
|
|
VALUE V8 = rb_define_module("V8");
|
|
|
|
VALUE V8_C = rb_define_module_under(V8, "C");
|
2010-05-18 20:57:16 +03:00
|
|
|
VALUE klass = rb_define_class_under(V8_C, name, superclass);
|
|
|
|
rb_funcall(klass, rb_intern("private_class_method"), 1, rb_str_new2("new"));
|
|
|
|
return klass;
|
2010-05-10 08:28:07 -05:00
|
|
|
}
|
|
|
|
|
2010-08-06 10:24:01 -05:00
|
|
|
VALUE rr_define_module(const char *name) {
|
|
|
|
VALUE V8 = rb_define_module("V8");
|
|
|
|
VALUE V8_C = rb_define_module_under(V8, "C");
|
|
|
|
return rb_define_module_under(V8_C, name);
|
|
|
|
}
|
|
|
|
|
2010-05-22 09:15:00 +03:00
|
|
|
VALUE rr_define_const(const char *name, VALUE value) {
|
|
|
|
VALUE V8 = rb_define_module("V8");
|
|
|
|
VALUE V8_C = rb_define_module_under(V8, "C");
|
|
|
|
rb_define_const(V8_C, name, value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(Handle<Value> value) {
|
2010-05-22 09:15:00 +03:00
|
|
|
if (value.IsEmpty()) {
|
|
|
|
return rr_cV8_C_Empty;
|
|
|
|
}
|
2010-06-08 12:48:13 +03:00
|
|
|
if (value->IsUndefined() || value->IsNull()) {
|
2010-05-12 17:30:53 -05:00
|
|
|
return Qnil;
|
|
|
|
}
|
2010-06-08 12:48:13 +03:00
|
|
|
if (value->IsExternal()) {
|
|
|
|
return rr_reflect_v8_external(value);
|
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
if (value->IsUint32()) {
|
|
|
|
return UINT2NUM(value->Uint32Value());
|
|
|
|
}
|
|
|
|
if (value->IsInt32()) {
|
|
|
|
return INT2FIX(value->Int32Value());
|
|
|
|
}
|
|
|
|
if (value->IsBoolean()) {
|
2010-05-17 15:18:29 +03:00
|
|
|
return value->BooleanValue() ? Qtrue : Qfalse;
|
2010-05-12 17:30:53 -05:00
|
|
|
}
|
|
|
|
if (value->IsNumber()) {
|
|
|
|
return rb_float_new(value->NumberValue());
|
|
|
|
}
|
|
|
|
if (value->IsString()) {
|
|
|
|
return rr_reflect_v8_string(value);
|
|
|
|
}
|
|
|
|
if (value->IsFunction()) {
|
|
|
|
return rr_reflect_v8_function(value);
|
|
|
|
}
|
|
|
|
if (value->IsArray()) {
|
|
|
|
return rr_reflect_v8_array(value);
|
|
|
|
}
|
2010-05-25 09:40:33 +03:00
|
|
|
if (value->IsDate()) {
|
|
|
|
return rr_reflect_v8_date(value);
|
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
if (value->IsObject()) {
|
|
|
|
return rr_reflect_v8_object(value);
|
|
|
|
}
|
|
|
|
return rr_wrap_v8_value(value);
|
2010-05-11 12:41:07 -05:00
|
|
|
}
|
2010-05-17 15:13:23 +03:00
|
|
|
|
2010-05-18 13:27:23 +03:00
|
|
|
VALUE rr_v82rb(Handle<Message> value) {
|
|
|
|
return rr_reflect_v8_message(value);
|
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(Handle<Boolean> value) {
|
|
|
|
return rr_v82rb((Handle<Value>)value);
|
2010-05-11 12:41:07 -05:00
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(Handle<Number> value) {
|
|
|
|
return rr_v82rb((Handle<Value>)value);
|
2010-05-11 12:41:07 -05:00
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(Handle<String> value) {
|
|
|
|
return rr_v82rb((Handle<Value>)value);
|
2010-05-11 12:41:07 -05:00
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(Handle<Object> value) {
|
|
|
|
return rr_v82rb((Handle<Value>)value);
|
2010-05-11 12:41:07 -05:00
|
|
|
}
|
2010-05-13 16:53:09 -05:00
|
|
|
VALUE rr_v82rb(v8::Handle<v8::Function> value) {
|
|
|
|
return rr_v82rb((Handle<Value>)value);
|
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(Handle<Integer> value) {
|
|
|
|
return rr_v82rb((Handle<Value>)value);
|
2010-05-11 12:41:07 -05:00
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(Handle<Uint32> value) {
|
|
|
|
return rr_v82rb((Handle<Value>)value);
|
2010-05-11 12:41:07 -05:00
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(Handle<Int32> value) {
|
|
|
|
return rr_v82rb((Handle<Value>)value);
|
2010-05-11 12:41:07 -05:00
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(bool value) {
|
2010-05-11 12:41:07 -05:00
|
|
|
return value ? Qtrue : Qfalse;
|
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
VALUE rr_v82rb(double value) {
|
|
|
|
return rb_float_new(value);
|
|
|
|
}
|
|
|
|
VALUE rr_v82rb(int64_t value) {
|
|
|
|
return INT2FIX(value);
|
|
|
|
}
|
|
|
|
VALUE rr_v82rb(uint32_t value) {
|
|
|
|
return UINT2NUM(value);
|
|
|
|
}
|
|
|
|
VALUE rr_v82rb(int32_t value) {
|
|
|
|
return INT2FIX(value);
|
|
|
|
}
|
2010-05-11 12:41:07 -05:00
|
|
|
|
2010-05-13 16:53:09 -05:00
|
|
|
Handle<Value> rr_rb2v8(VALUE value) {
|
|
|
|
switch (TYPE(value)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
return Integer::New(FIX2INT(value));
|
|
|
|
case T_FLOAT:
|
|
|
|
return Number::New(NUM2DBL(value));
|
|
|
|
case T_STRING:
|
|
|
|
return String::New(RSTRING_PTR(value), RSTRING_LEN(value));
|
|
|
|
case T_NIL:
|
|
|
|
return Null();
|
|
|
|
case T_TRUE:
|
|
|
|
return True();
|
|
|
|
case T_FALSE:
|
|
|
|
return False();
|
2010-05-17 18:53:14 +03:00
|
|
|
case T_DATA:
|
|
|
|
return V8_Ref_Get<Value>(value);
|
2010-05-17 16:07:43 +03:00
|
|
|
case T_OBJECT:
|
|
|
|
case T_CLASS:
|
|
|
|
case T_ICLASS:
|
|
|
|
case T_MODULE:
|
|
|
|
case T_REGEXP:
|
|
|
|
case T_MATCH:
|
|
|
|
case T_ARRAY:
|
|
|
|
case T_HASH:
|
|
|
|
case T_STRUCT:
|
|
|
|
case T_BIGNUM:
|
|
|
|
case T_FILE:
|
|
|
|
case T_SYMBOL:
|
2010-05-23 18:35:25 +03:00
|
|
|
// case T_BLKTAG: (not in 1.9)
|
2010-05-17 16:07:43 +03:00
|
|
|
case T_UNDEF:
|
2010-05-23 18:35:25 +03:00
|
|
|
// case T_VARMAP: (not in 1.9)
|
|
|
|
// case T_SCOPE: (not in 1.9)
|
2010-05-17 16:07:43 +03:00
|
|
|
case T_NODE:
|
|
|
|
default:
|
2010-06-18 14:44:44 +03:00
|
|
|
rb_warn("unknown conversion to V8 for: %s", RSTRING_PTR(rb_inspect(value)));
|
2010-05-17 16:07:43 +03:00
|
|
|
return String::New("Undefined Conversion");
|
2010-05-13 16:53:09 -05:00
|
|
|
}
|
2010-06-18 14:44:44 +03:00
|
|
|
|
2010-05-13 16:53:09 -05:00
|
|
|
return Undefined();
|
|
|
|
}
|
2010-05-12 17:30:53 -05:00
|
|
|
// VALUE rr_v82rb(v8::ScriptData *data) {
|
2010-05-11 12:41:07 -05:00
|
|
|
// return rr_thunk(rr_wrap_script_data(data));
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|