mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
code compiles now, still broken though
This commit is contained in:
parent
77837092b0
commit
7f46bf908d
9 changed files with 83 additions and 46 deletions
|
@ -15,7 +15,7 @@ namespace {
|
|||
VALUE V82RB(Handle<Value>& value) {
|
||||
convert_v8_to_rb_t convert;
|
||||
VALUE result;
|
||||
VALUE type = V8_C_Object;
|
||||
VALUE type = rr_cV8_C_Object;
|
||||
if(convert(value, result)) {
|
||||
return result;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ VALUE V82RB(Handle<Value>& value) {
|
|||
}
|
||||
|
||||
if (value->IsFunction()) {
|
||||
type = V8_C_Function;
|
||||
type = rr_cV8_C_Function;
|
||||
}
|
||||
|
||||
if (value->IsObject()) {
|
||||
|
|
|
@ -68,6 +68,9 @@ VALUE rr_v82rb(Handle<String> value) {
|
|||
VALUE rr_v82rb(Handle<Object> value) {
|
||||
return rr_v82rb((Handle<Value>)value);
|
||||
}
|
||||
VALUE rr_v82rb(v8::Handle<v8::Function> value) {
|
||||
return rr_v82rb((Handle<Value>)value);
|
||||
}
|
||||
VALUE rr_v82rb(Handle<Integer> value) {
|
||||
return rr_v82rb((Handle<Value>)value);
|
||||
}
|
||||
|
@ -93,6 +96,24 @@ VALUE rr_v82rb(int32_t value) {
|
|||
return INT2FIX(value);
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
// VALUE rr_v82rb(v8::ScriptData *data) {
|
||||
// return rr_thunk(rr_wrap_script_data(data));
|
||||
// }
|
||||
|
|
29
ext/v8/rr.h
29
ext/v8/rr.h
|
@ -11,18 +11,21 @@ VALUE rr_define_class(const char *name, VALUE superclass = rb_cObject);
|
|||
VALUE rr_str_to_perl_case(VALUE str);
|
||||
VALUE rr_str_to_camel_case(VALUE str);
|
||||
|
||||
VALUE rr_to_ruby(v8::Handle<v8::Value> value);
|
||||
VALUE rr_to_ruby(v8::Handle<v8::Boolean> value);
|
||||
VALUE rr_to_ruby(v8::Handle<v8::Number> value);
|
||||
VALUE rr_to_ruby(v8::Handle<v8::String> value);
|
||||
VALUE rr_to_ruby(v8::Handle<v8::Object> value);
|
||||
VALUE rr_to_ruby(v8::Handle<v8::Integer> value);
|
||||
VALUE rr_to_ruby(v8::Handle<v8::Uint32> value);
|
||||
VALUE rr_to_ruby(v8::Handle<v8::Int32> value);
|
||||
VALUE rr_to_ruby(bool value);
|
||||
VALUE rr_to_ruby(double value);
|
||||
VALUE rr_to_ruby(int64_t value);
|
||||
VALUE rr_to_ruby(uint32_t value);
|
||||
VALUE rr_to_ruby(int32_t value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Value> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Boolean> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Number> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::String> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Object> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Function> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Integer> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Uint32> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Int32> value);
|
||||
VALUE rr_v82rb(bool value);
|
||||
VALUE rr_v82rb(double value);
|
||||
VALUE rr_v82rb(int64_t value);
|
||||
VALUE rr_v82rb(uint32_t value);
|
||||
VALUE rr_v82rb(int32_t value);
|
||||
|
||||
v8::Handle<v8::Value> rr_rb2v8(VALUE value);
|
||||
|
||||
#endif
|
|
@ -97,7 +97,7 @@ VALUE v8_cxt_eval(VALUE self, VALUE source, VALUE filename) {
|
|||
return Racer_Error_Message(exceptions);
|
||||
} else {
|
||||
printf("about to convert result\n");
|
||||
return rr_to_ruby(result);
|
||||
return rr_v82rb(result);
|
||||
// return V82RB(result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,15 @@
|
|||
|
||||
using namespace v8;
|
||||
|
||||
VALUE rr_cV8_C_Function;
|
||||
|
||||
namespace {
|
||||
VALUE FunctionClass;
|
||||
|
||||
VALUE Call(int, argc, VALUE *argv, VALUE self) {
|
||||
Local<Function> unwrap(VALUE value) {
|
||||
return V8_Ref_Get<Function>(value);
|
||||
}
|
||||
VALUE Call(int argc, VALUE *argv, VALUE self) {
|
||||
HandleScope handles;
|
||||
VALUE recv; VALUE f_argv;
|
||||
rb_scan_args(argc, argv, "1*", &recv, &f_argv);
|
||||
|
@ -18,11 +23,22 @@ namespace {
|
|||
int f_argc = argc - 1;
|
||||
Local<Value> arguments[f_argc];
|
||||
for (int i = 0; i < f_argc; i++) {
|
||||
arguments[i] = rr_rb2v8(rb_ary_entry(f_argv, i));
|
||||
arguments[i] = *rr_rb2v8(rb_ary_entry(f_argv, i));
|
||||
}
|
||||
Local<Value> result = function->Call(thisObject, f_argc, arguments);
|
||||
return rr_v82rb(result);
|
||||
}
|
||||
}
|
||||
VALUE NewInstance(int argc, VALUE *argv, VALUE self) {
|
||||
HandleScope handles;
|
||||
VALUE f_argv;
|
||||
rb_scan_args(argc, argv, "*", &f_argv);
|
||||
Local<Function> function = V8_Ref_Get<Function>(self);
|
||||
Local<Value> arguments[argc];
|
||||
for (int i = 0; i < argc; i++) {
|
||||
arguments[i] = *rr_rb2v8(rb_ary_entry(f_argv, i));
|
||||
}
|
||||
return rr_v82rb(function->NewInstance(argc, arguments));
|
||||
}
|
||||
VALUE GetName(VALUE self) {
|
||||
return rr_v82rb(unwrap(self)->GetName());
|
||||
}
|
||||
|
@ -30,11 +46,21 @@ namespace {
|
|||
Local<String> str = V8_Ref_Get<String>(name);
|
||||
unwrap(self)->SetName(str);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
}
|
||||
// VALUE GetScriptOrigin(VALUE self) {
|
||||
// return rr_v82rb(unwrap(self)->GetScriptOrigin());
|
||||
// }
|
||||
}
|
||||
|
||||
void rr_init_func() {
|
||||
FunctionClass = rr_define_class("Function", V8_C_Object);
|
||||
rr_define_method(FunctionClass, "Call", Call, -1);
|
||||
FunctionClass = rr_define_class("Function", rr_cV8_C_Object);
|
||||
rr_define_method(FunctionClass, "Call", Call, -1);
|
||||
rr_define_method(FunctionClass, "NewInstance", NewInstance, -1);
|
||||
rr_define_method(FunctionClass, "GetName", GetName, 0);
|
||||
rr_define_method(FunctionClass, "SetName", SetName, 1);
|
||||
// rr_define_method(FunctionClass, "GetScriptOrigin", GetScriptOrigin, 0);
|
||||
}
|
||||
|
||||
void rr_reflec_v8_function(Handle<Value> value) {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
#include "v8.h"
|
||||
#include "v8_ref.h"
|
||||
|
||||
extern VALUE V8_C_Function;
|
||||
extern VALUE rr_cV8_C_Function;
|
||||
|
||||
void rr_init_func();
|
||||
|
||||
VALUE V8_Wrap_Function(v8::Handle<v8::Function> f);
|
||||
VALUE rr_reflect_v8_function(v8::Handle<v8::Value> value);
|
||||
|
||||
VALUE v8_C_Function_Call(int argc, VALUE *argv, VALUE self);
|
||||
#endif
|
|
@ -1,5 +1,6 @@
|
|||
#include "v8_obj.h"
|
||||
#include "v8_ref.h"
|
||||
#include "v8_value.h"
|
||||
#include "converters.h"
|
||||
|
||||
using namespace v8;
|
||||
|
@ -10,12 +11,12 @@ VALUE rr_cV8_C_Object;
|
|||
|
||||
void rr_init_obj() {
|
||||
rr_cV8_C_Object = rr_define_class("Object", rr_cV8_C_Value);
|
||||
rr_define_singleton_method(V8_C_Object, "new", v8_Object_New, 0);
|
||||
rr_define_method(V8_C_Object, "Get", v8_Object_Get, 1);
|
||||
rr_define_method(V8_C_Object, "Set", v8_Object_Set, 2);
|
||||
rr_define_method(V8_C_Object, "GetPropertyNames", v8_Object_GetPropertyNames, 0);
|
||||
rr_define_method(V8_C_Object, "ToString", v8_Object_ToString, 0);
|
||||
rr_define_method(V8_C_Object, "context", v8_Object_context, 0);
|
||||
rr_define_singleton_method(rr_cV8_C_Object, "new", v8_Object_New, 0);
|
||||
rr_define_method(rr_cV8_C_Object, "Get", v8_Object_Get, 1);
|
||||
rr_define_method(rr_cV8_C_Object, "Set", v8_Object_Set, 2);
|
||||
rr_define_method(rr_cV8_C_Object, "GetPropertyNames", v8_Object_GetPropertyNames, 0);
|
||||
rr_define_method(rr_cV8_C_Object, "ToString", v8_Object_ToString, 0);
|
||||
rr_define_method(rr_cV8_C_Object, "context", v8_Object_context, 0);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -62,6 +62,6 @@ VALUE v8_FunctionTemplate_New(int argc, VALUE *argv, VALUE self) {
|
|||
VALUE v8_FunctionTemplate_GetFunction(VALUE self) {
|
||||
HandleScope handles;
|
||||
Local<FunctionTemplate> t = V8_Ref_Get<FunctionTemplate>(self);
|
||||
return V8_Wrap_Function(t->GetFunction());
|
||||
return rr_v82rb(t->GetFunction());
|
||||
}
|
||||
|
||||
|
|
13
lib/v8/to.rb
13
lib/v8/to.rb
|
@ -21,19 +21,6 @@ module V8
|
|||
value
|
||||
end
|
||||
end
|
||||
|
||||
def rb(value)
|
||||
puts "hello from To.rb"
|
||||
if value.IsFunction()
|
||||
V8::Function.new(value)
|
||||
elsif value.IsObject()
|
||||
V8::Object.new(value)
|
||||
elsif value.IsNumber()
|
||||
value.NumberValue()
|
||||
elsif value.IsBoolean()
|
||||
value.BooleanValue()
|
||||
end
|
||||
end
|
||||
|
||||
def camel_case(str)
|
||||
str.to_s.gsub(/_(\w)/) {$1.upcase}
|
||||
|
|
Loading…
Reference in a new issue