From e4184c97f9ef88912c3a626746124787970beda7 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 15 May 2012 16:37:22 -0500 Subject: [PATCH] thunk down values and objects --- ext/v8/object.cc | 25 ++++++++++++++++++++++++- ext/v8/rr.h | 1 + ext/v8/value.cc | 6 ++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ext/v8/object.cc b/ext/v8/object.cc index f4c4628..d4c9cf1 100644 --- a/ext/v8/object.cc +++ b/ext/v8/object.cc @@ -279,5 +279,28 @@ VALUE Object::SetAccessor(int argc, VALUE* argv, VALUE self) { // V8EXPORT Local CallAsConstructor(int argc, // Handle argv[]); - +Object::operator VALUE() { + if (handle->IsFunction()) { + // return Function(handle); + } + if (handle->IsArray()) { + // return Array(handle); + } + if (handle->IsDate()) { + // return Date(handle); + } + if (handle->IsBooleanObject()) { + // return BooleanObject(handle); + } + if (handle->IsNumberObject()) { + // return NumberObject(handle); + } + if (handle->IsStringObject()) { + // return StringObject(handle); + } + if (handle->IsRegExp()) { + // return RegExp(handle); + } + return Ref::operator VALUE(); +} } \ No newline at end of file diff --git a/ext/v8/rr.h b/ext/v8/rr.h index 568f9ff..613391c 100644 --- a/ext/v8/rr.h +++ b/ext/v8/rr.h @@ -256,6 +256,7 @@ public: inline Object(VALUE value) : Ref(value) {} inline Object(v8::Handle object) : Ref(object) {} + virtual operator VALUE(); }; class V8 { diff --git a/ext/v8/value.cc b/ext/v8/value.cc index 2607c88..1154eba 100644 --- a/ext/v8/value.cc +++ b/ext/v8/value.cc @@ -21,6 +21,12 @@ Value::operator VALUE() { if (handle.IsEmpty() || handle->IsUndefined() || handle->IsNull()) { return Qnil; } + if (handle->IsTrue()) { + return Qtrue; + } + if (handle->IsFalse()) { + return Qfalse; + } if (handle->IsExternal()) { return External((v8::Handle)v8::External::Cast(*handle)); }