From 1ae9f62e499adb97058716a7e032af2fb85cc07c Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 8 Jun 2010 12:48:13 +0300 Subject: [PATCH] reflect v8::External back into Ruby --- ext/v8/rr.cpp | 6 +++++- ext/v8/v8_external.cpp | 4 ++++ ext/v8/v8_external.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ext/v8/rr.cpp b/ext/v8/rr.cpp index 2481a1c..8fd3b72 100644 --- a/ext/v8/rr.cpp +++ b/ext/v8/rr.cpp @@ -7,6 +7,7 @@ #include "v8_str.h" #include "v8_date.h" #include "v8_msg.h" +#include "v8_external.h" using namespace v8; @@ -29,9 +30,12 @@ VALUE rr_v82rb(Handle value) { if (value.IsEmpty()) { return rr_cV8_C_Empty; } - if (value.IsEmpty() || value->IsUndefined() || value->IsNull()) { + if (value->IsUndefined() || value->IsNull()) { return Qnil; } + if (value->IsExternal()) { + return rr_reflect_v8_external(value); + } if (value->IsUint32()) { return UINT2NUM(value->Uint32Value()); } diff --git a/ext/v8/v8_external.cpp b/ext/v8/v8_external.cpp index b8948fe..d886183 100644 --- a/ext/v8/v8_external.cpp +++ b/ext/v8/v8_external.cpp @@ -38,6 +38,10 @@ void rr_init_v8_external() { // rr_define_method(ExternalClass, "Value", _Value, 0); } +VALUE rr_reflect_v8_external(Handle external) { + return rr_v8_ref_create(ExternalClass, external); +} + Handle rr_v8_external_create(VALUE value) { rb_hash_aset(references, rb_obj_id(value), value); Local external(External::Wrap((void *)value)); diff --git a/ext/v8/v8_external.h b/ext/v8/v8_external.h index 9f6e536..028a906 100644 --- a/ext/v8/v8_external.h +++ b/ext/v8/v8_external.h @@ -4,5 +4,6 @@ #include "rr.h" void rr_init_v8_external(); +VALUE rr_reflect_v8_external(v8::Handle value); v8::Handle rr_v8_external_create(VALUE value); #endif \ No newline at end of file