diff --git a/src/vu8/Class.hpp b/src/vu8/Class.hpp index 7159ad4..974ceb4 100644 --- a/src/vu8/Class.hpp +++ b/src/vu8/Class.hpp @@ -114,18 +114,34 @@ class ClassSingleton template static inline ValueHandle Forward(const v8::Arguments& args) { v8::HandleScope scope; - v8::Local self = args.Holder(); // this will kill without zero-overhead exception handling try { - return scope.Close(ForwardReturn

( - static_cast(self->GetPointerFromInternalField(0)), args)); + return scope.Close( + ForwardReturn

( + retrieveNativeObjectPtr(args.Holder()), + args + ) + ); } catch (std::runtime_error const& e) { return Throw(e.what()); } } + static inline T* retrieveNativeObjectPtr(v8::Local value) + { + while (value->IsObject()) { + v8::Local obj = value->ToObject(); + T * native = static_cast(obj->GetPointerFromInternalField(0)); + if (native) { + return native; + } + value = obj->GetPrototype(); + } + return NULL; + } + static inline void MadeWeak(v8::Persistent object, void *parameter) {