mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
simplify TryCatch to use stack allocation
This commit is contained in:
parent
bc53c63a47
commit
dc30dbc9ce
2 changed files with 8 additions and 12 deletions
|
@ -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 {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue