From 1dd55ffa77c0916e22af0316272756454fa9eb38 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Mon, 18 Jan 2010 01:12:23 +0200 Subject: [PATCH] Enumerate ruby properties in javascript. --- ext/v8/callbacks.cpp | 10 +++++++++- ext/v8/v8_template.cpp | 2 +- lib/v8/to.rb | 2 +- spec/redjs | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ext/v8/callbacks.cpp b/ext/v8/callbacks.cpp index c0a86d6..1178312 100644 --- a/ext/v8/callbacks.cpp +++ b/ext/v8/callbacks.cpp @@ -148,5 +148,13 @@ Handle RacerRubyNamedPropertyDeleter(Local property, const Acce * property getter intercepts. */ Handle RacerRubyNamedPropertyEnumerator(const AccessorInfo& info) { - return Local(); + VALUE object = unwrap(info); + VALUE methods = rb_funcall(object, rb_intern("public_methods"), 1, Qfalse); + int length = RARRAY_LEN(methods); + Local properties = Array::New(length); + for (int i = 0; i < length; i++) { + VALUE camel_name = rb_funcall(V8_To, rb_intern("camel_case"), 1, rb_ary_entry(methods, i)); + properties->Set(Integer::New(i), RB2V8(camel_name)); + } + return properties; } diff --git a/ext/v8/v8_template.cpp b/ext/v8/v8_template.cpp index 31b8e8e..3ef286d 100644 --- a/ext/v8/v8_template.cpp +++ b/ext/v8/v8_template.cpp @@ -16,7 +16,7 @@ Local Racer_Create_V8_ObjectTemplate(VALUE value) { RacerRubyNamedPropertySetter, 0, // RacerRubyNamedPropertyQuery, 0, // RacerRubyNamedPropertyDeleter, - 0, // RacerRubyNamedPropertyEnumerator, + RacerRubyNamedPropertyEnumerator, External::Wrap((void *)value) ); return tmpl; diff --git a/lib/v8/to.rb b/lib/v8/to.rb index 9e2e167..9523224 100644 --- a/lib/v8/to.rb +++ b/lib/v8/to.rb @@ -21,7 +21,7 @@ module V8 end end - def camelcase(str) + def camel_case(str) str.to_s.gsub(/_(\w)/) {$1.upcase} end diff --git a/spec/redjs b/spec/redjs index 26e3054..9e8d547 160000 --- a/spec/redjs +++ b/spec/redjs @@ -1 +1 @@ -Subproject commit 26e3054452beb85bdb5ab6f42f1d9531f654a7d8 +Subproject commit 9e8d547fc7b217f9cab0192c04753499f47fdb38