1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/ext/v8/trycatch.cc

87 lines
2.5 KiB
C++
Raw Normal View History

2012-05-25 16:53:13 -04:00
#include "rr.h"
namespace rr {
VALUE TryCatch::Class;
void TryCatch::Init() {
ClassBuilder("TryCatch").
defineMethod("HasCaught", &HasCaught).
defineMethod("CanContinue", &CanContinue).
defineMethod("ReThrow", &ReThrow).
defineMethod("Exception", &Exception).
defineMethod("StackTrace", &StackTrace).
defineMethod("Message", &Message).
defineMethod("Reset", &Reset).
defineMethod("SetVerbose", &SetVerbose).
defineMethod("SetCaptureMessage", &SetCaptureMessage).
store(&Class);
VALUE v8 = rb_define_module("V8");
VALUE c = rb_define_module_under(v8, "C");
rb_define_singleton_method(c, "TryCatch", (VALUE (*)(...))&doTryCatch, -1);
}
TryCatch::TryCatch(v8::TryCatch* impl) {
this->impl = impl;
2012-05-25 16:53:13 -04:00
}
TryCatch::TryCatch(VALUE value) {
Data_Get_Struct(value, class v8::TryCatch, impl);
2012-05-25 16:53:13 -04:00
}
2012-05-25 16:53:13 -04:00
TryCatch::operator VALUE() {
return Data_Wrap_Struct(Class, 0, 0, impl);
}
VALUE TryCatch::HasCaught(VALUE self) {
return Bool(TryCatch(self)->HasCaught());
}
VALUE TryCatch::CanContinue(VALUE self) {
return Bool(TryCatch(self)->CanContinue());
}
VALUE TryCatch::ReThrow(VALUE self) {
return Value(TryCatch(self)->ReThrow());
}
VALUE TryCatch::Exception(VALUE self) {
return Value(TryCatch(self)->Exception());
}
VALUE TryCatch::StackTrace(VALUE self) {
return Value(TryCatch(self)->StackTrace());
}
VALUE TryCatch::Message(VALUE self) {
return rr::Message(TryCatch(self)->Message());
}
VALUE TryCatch::Reset(VALUE self) {
Void(TryCatch(self)->Reset());
}
VALUE TryCatch::SetVerbose(VALUE self, VALUE value) {
Void(TryCatch(self)->SetVerbose(Bool(value)));
}
VALUE TryCatch::SetCaptureMessage(VALUE self, VALUE value) {
Void(TryCatch(self)->SetCaptureMessage(Bool(value)));
}
VALUE TryCatch::doTryCatch(int argc, VALUE argv[], VALUE self) {
if (!rb_block_given_p()) {
return Qnil;
}
int state = 0;
VALUE code;
rb_scan_args(argc,argv,"00&", &code);
VALUE result = setupAndCall(&state, code);
if (state != 0) {
rb_jump_tag(state);
}
return result;
}
VALUE TryCatch::setupAndCall(int* state, VALUE code) {
2012-08-01 10:15:04 -04:00
v8::TryCatch trycatch;
rb_iv_set(code, "_v8_trycatch", TryCatch(&trycatch));
VALUE result = rb_protect(&doCall, code, state);
rb_iv_set(code, "_v8_trycatch", Qnil);
return result;
2012-05-25 16:53:13 -04:00
}
VALUE TryCatch::doCall(VALUE code) {
2012-08-01 10:15:04 -04:00
return rb_funcall(code, rb_intern("call"), 1, rb_iv_get(code, "_v8_trycatch"));
2012-05-25 16:53:13 -04:00
}
}