Sha256: b110320ff24da82856c18de8d3b5700c0cf4c1ac77d396fc66b377ca70274817

Contents?: true

Size: 1.86 KB

Versions: 71

Compression:

Stored size: 1.86 KB

Contents

#include "rr.h"
#include "v8_try_catch.h"
#include "v8_message.h"

using namespace v8;

namespace {
  VALUE TryCatchClass;

  TryCatch *unwrap(VALUE self) {
    TryCatch *tc = 0;
    Data_Get_Struct(self, class TryCatch, tc);
    if (RTEST(rb_iv_get(self, "dead"))) {
      rb_raise(rb_eScriptError, "out of scope access of %s", RSTRING_PTR(rb_inspect(self)));
      return false;
    } else {
      return tc;
    }
  }
  
  VALUE Try(int argc, VALUE *argv, VALUE self) {
    if (rb_block_given_p()) {
      HandleScope scope;
      TryCatch tc;
      VALUE try_catch = Data_Wrap_Struct(TryCatchClass, 0, 0, &tc);
      rb_iv_set(try_catch, "dead", Qfalse);
      VALUE result = rb_yield(try_catch);
      rb_iv_set(try_catch, "dead", Qtrue);
      tc.Reset();
      return result;
    } else {
      return Qnil;
    }
  }
  
  VALUE HasCaught(VALUE self) {
    TryCatch *tc = unwrap(self);
    return tc ? rr_v82rb(tc->HasCaught()) : Qnil;
  }
  
  VALUE _Exception(VALUE self) {
    TryCatch *tc = unwrap(self);
    return tc ? rr_v82rb(tc->Exception()) : Qnil;
  }
  
  VALUE _StackTrace(VALUE self) {
    TryCatch *tc = unwrap(self);
    return tc ? rr_v82rb(tc->StackTrace()) : Qnil;
  }    
  
  VALUE _Message(VALUE self) {
    TryCatch *tc = unwrap(self);
    return tc ? rr_v82rb(tc->Message()) : Qnil;
  }
  
  VALUE CanContinue(VALUE self) {
    TryCatch *tc = unwrap(self);
    return tc ? rr_v82rb(tc->CanContinue()) : Qnil;    
  }
}

void rr_init_v8_try_catch() {
  TryCatchClass = rr_define_class("TryCatch");
  rr_define_singleton_method(TryCatchClass, "try", Try, -1);
  rr_define_method(TryCatchClass, "HasCaught", HasCaught, 0);
  rr_define_method(TryCatchClass, "Exception", _Exception, 0);
  rr_define_method(TryCatchClass, "StackTrace", _StackTrace, 0);
  rr_define_method(TryCatchClass, "Message", _Message, 0);
  rr_define_method(TryCatchClass, "CanContinue", CanContinue, 0);
}

Version data entries

71 entries across 71 versions & 5 rubygems

Version Path
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
classiccms-0.3.8 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
therubyracer-freebsd-0.10.1 ext/v8/v8_try_catch.cpp
classiccms-0.3.7 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
classiccms-0.3.6 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
classiccms-0.3.5 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
classiccms-0.3.4 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
classiccms-0.3.3 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
classiccms-0.3.2 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
classiccms-0.3.1 vendor/bundle/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
horseman-0.0.5 vendor/ruby/1.9.1/gems/therubyracer-0.10.1/ext/v8/v8_try_catch.cpp
therubyracer-0.10.1 ext/v8/v8_try_catch.cpp
therubyracer-0.10.0 ext/v8/v8_try_catch.cpp
therubyracer-0.9.10 ext/v8/v8_try_catch.cpp
therubyracer-0.9.9 ext/v8/v8_try_catch.cpp
therubyracer-0.9.8 ext/v8/v8_try_catch.cpp
therubyracer-0.10.0beta1 ext/v8/v8_try_catch.cpp
therubyracer-0.9.7 ext/v8/v8_try_catch.cpp