diff --git a/ext/v8/rr.h b/ext/v8/rr.h index 5807856..f3826d5 100644 --- a/ext/v8/rr.h +++ b/ext/v8/rr.h @@ -726,9 +726,8 @@ public: class TryCatch { public: static void Init(); - TryCatch(); + TryCatch(v8::TryCatch*); TryCatch(VALUE value); - ~TryCatch(); operator VALUE(); inline v8::TryCatch* operator->() {return this->impl;} static VALUE HasCaught(VALUE self); @@ -746,7 +745,6 @@ private: static VALUE doCall(VALUE code); static VALUE Class; v8::TryCatch* impl; - bool allocated; }; class Locker { diff --git a/ext/v8/trycatch.cc b/ext/v8/trycatch.cc index f2ea11f..3bda381 100644 --- a/ext/v8/trycatch.cc +++ b/ext/v8/trycatch.cc @@ -20,15 +20,13 @@ namespace rr { rb_define_singleton_method(c, "TryCatch", (VALUE (*)(...))&doTryCatch, -1); } - TryCatch::TryCatch() : impl(new v8::TryCatch()), allocated(true) {} - TryCatch::TryCatch(VALUE value) : allocated(false) { + TryCatch::TryCatch(v8::TryCatch* impl) { + this->impl = impl; + } + TryCatch::TryCatch(VALUE value) { Data_Get_Struct(value, class v8::TryCatch, impl); } - TryCatch::~TryCatch() { - if (this->allocated) { - delete this->impl; - } - } + TryCatch::operator VALUE() { return Data_Wrap_Struct(Class, 0, 0, impl); } @@ -80,7 +78,7 @@ namespace rr { } VALUE TryCatch::doCall(VALUE code) { - TryCatch trycatch; - return rb_funcall(code, rb_intern("call"), 1, (VALUE)trycatch); + v8::TryCatch trycatch; + return rb_funcall(code, rb_intern("call"), 1, (VALUE)TryCatch(&trycatch)); } } \ No newline at end of file