diff --git a/ext/v8/callbacks.cpp b/ext/v8/callbacks.cpp index c26e49d..f080b6b 100644 --- a/ext/v8/callbacks.cpp +++ b/ext/v8/callbacks.cpp @@ -10,11 +10,29 @@ namespace { return (VALUE)External::Unwrap(info.Data()); } + //returns all the ruby methods that can be called from + //this object. + //1.8: public_methods() return strings + //1.9: publi_methods() return symbols + //convert them all into string + + VALUE CALLABLE_METHODS(VALUE object) { + VALUE methods = rb_funcall(object, rb_intern("public_methods"), 1, Qfalse); + int length = RARRAY_LEN(methods); + VALUE str_methods = rb_ary_new2(length); + for (int i = 0; i < length; i++) { + VALUE method = rb_ary_entry(methods, i); + rb_ary_store(str_methods,i, rb_obj_as_string(method)); + } + return str_methods; + } + Local TO_ARRAY(Arguments& args) { Local array = Array::New(args.Length()); for (int i = 0; i < args.Length(); i++) { array->Set(Integer::New(i), args[i]); } + return array; } Local Racer_Call_Ruby_Method(VALUE object, VALUE method, Local args) { @@ -73,7 +91,7 @@ Handle RacerRubyNamedPropertyGetter(Local property, const Accesso VALUE object = unwrap(info); VALUE camel_name = V82RB((Local&)property); VALUE perl_name = rb_funcall(V8_To, rb_intern("perl_case"), 1, camel_name); - VALUE methods = rb_funcall(object, rb_intern("public_methods"), 1, Qfalse); + VALUE methods = CALLABLE_METHODS(object); if (RTEST(rb_ary_includes(methods, perl_name))) { return Racer_Access_Ruby_Property(object, perl_name); @@ -99,7 +117,7 @@ Handle RacerRubyNamedPropertySetter(Local property, Local VALUE object = unwrap(info); VALUE camel_name = V82RB((Local&)setter_name); VALUE perl_name = rb_funcall(V8_To, rb_intern("perl_case"), 1, camel_name); - VALUE methods = rb_funcall(object, rb_intern("public_methods"), 1, Qfalse); + VALUE methods = CALLABLE_METHODS(object); Local args = Array::New(1); args->Set(Integer::New(0), value); if (RTEST(rb_ary_includes(methods, perl_name))) { @@ -123,7 +141,7 @@ Handle RacerRubyNamedPropertyQuery(Local property, const Access return False(); } VALUE object = unwrap(info); - VALUE methods = rb_funcall(object, rb_intern("public_methods"), 1, Qfalse); + VALUE methods = CALLABLE_METHODS(object); VALUE attr_name = V82RB((Local&)property); VALUE perl_name = rb_funcall(V8_To, rb_intern("perl_case"), 1, attr_name); @@ -149,7 +167,7 @@ Handle RacerRubyNamedPropertyDeleter(Local property, const Acce */ Handle RacerRubyNamedPropertyEnumerator(const AccessorInfo& info) { VALUE object = unwrap(info); - VALUE methods = rb_funcall(object, rb_intern("public_methods"), 1, Qfalse); + VALUE methods = CALLABLE_METHODS(object); int length = RARRAY_LEN(methods); Local properties = Array::New(length); for (int i = 0; i < length; i++) {