mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Invoke ruby methods with their javascript property names.
This commit is contained in:
parent
7fe378fa0e
commit
772fa7d586
4 changed files with 16 additions and 1 deletions
|
@ -9,6 +9,8 @@ namespace {
|
|||
std::string UNDEFINED_STR("undefined");
|
||||
}
|
||||
|
||||
VALUE V8_To;
|
||||
|
||||
VALUE V82RB(Handle<Value>& value) {
|
||||
convert_v8_to_rb_t convert;
|
||||
VALUE result;
|
||||
|
@ -42,9 +44,13 @@ Local<Value> RB2V8(VALUE value) {
|
|||
int len = RARRAY(methods)->len;
|
||||
for (int i = 0; i < len; i++) {
|
||||
VALUE method_name = RARRAY(methods)->ptr[i];
|
||||
VALUE camel_method_name = rb_funcall(V8_To, rb_intern("camelcase"), 1, method_name);
|
||||
VALUE method = rb_funcall(value, rb_intern("method"), 1, method_name);
|
||||
Local<String> keystr = (String *)*RB2V8(method_name);
|
||||
tmpl->Set(keystr, RB2V8(method));
|
||||
Local<String> camelstr = (String *)*RB2V8(camel_method_name);
|
||||
Local<Value> fun = RB2V8(method);
|
||||
tmpl->Set(keystr, fun);
|
||||
tmpl->Set(camelstr, fun);
|
||||
}
|
||||
return tmpl->NewInstance();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "convert_v8.h"
|
||||
#include <cstring>
|
||||
|
||||
extern VALUE V8_To;
|
||||
|
||||
typedef RubyValueSource<V8LocalDest, v8::Local<v8::Value> > convert_rb_to_v8_t;
|
||||
typedef V8HandleSource<RubyValueDest, VALUE> convert_v8_to_rb_t;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "v8_script.h"
|
||||
#include "v8_template.h"
|
||||
#include "v8_standalone.h"
|
||||
#include "converters.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -29,6 +30,8 @@ extern "C" {
|
|||
|
||||
rb_mModule = rb_define_module("V8");
|
||||
rb_define_singleton_method(rb_mModule, "what_is_this?", (VALUE(*)(...)) v8_what_is_this, 1);
|
||||
|
||||
V8_To = rb_define_module_under(rb_mModule, "To");
|
||||
|
||||
//native module setup
|
||||
VALUE rb_mNative = rb_define_module_under(rb_mModule, "C");
|
||||
|
|
|
@ -20,6 +20,10 @@ module V8
|
|||
value
|
||||
end
|
||||
end
|
||||
|
||||
def camelcase(str)
|
||||
str.to_s.gsub(/_(\w)/) {$1.upcase}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue