Sha256: 7dbe1bdb1a0d427de3fa65f6a21fbc0b7e0bdc5eb8a66c28c61a2b9ad6312eec

Contents?: true

Size: 1.81 KB

Versions: 8

Compression:

Stored size: 1.81 KB

Contents

#include "v8_exception.h"
#include "rr.h"
#include "execinfo.h"
#include "signal.h"

using namespace v8;
namespace {

  static void* stack[20];

  void fatal(const char* location, const char* message) {
    rb_raise(rb_eFatal, "%s: %s", location, message);    
  }
  void segfault(int sig) {
    fprintf(stderr, "segfault: game over.\n");
    int size = backtrace(stack, 20);
    backtrace_symbols_fd(stack, size, 2);
    exit(1);
  }
  VALUE _ThrowException(VALUE rbmod, VALUE value) {
    HandleScope scope;
    Handle<Value> err = rr_rb2v8(value);
    return rr_v82rb(ThrowException(err));
  }
  VALUE RangeError(VALUE rbclass, VALUE value) {
    HandleScope scope;
    return rr_v82rb(Exception::RangeError(rr_rb2v8(value)->ToString()));
  }
  VALUE ReferenceError(VALUE rbclass, VALUE value) {
    HandleScope scope;
    return rr_v82rb(Exception::ReferenceError(rr_rb2v8(value)->ToString()));
  }
  VALUE SyntaxError(VALUE rbclass, VALUE value) {
    HandleScope scope;
    return rr_v82rb(Exception::SyntaxError(rr_rb2v8(value)->ToString()));
  }
  VALUE Error(VALUE rbclass, VALUE value) {
    HandleScope scope;
    return rr_v82rb(Exception::Error(rr_rb2v8(value)->ToString()));
  }
}

void rr_init_v8_exception() {
  VALUE V8 = rb_define_module("V8");
  VALUE V8_C = rb_define_module_under(V8, "C");
  rr_define_singleton_method(V8_C, "ThrowException", _ThrowException, 1);
  VALUE ExceptionClass = rr_define_class("Exception");
  rr_define_singleton_method(ExceptionClass, "RangeError", RangeError, 1);
  rr_define_singleton_method(ExceptionClass, "ReferenceError", ReferenceError, 1);
  rr_define_singleton_method(ExceptionClass, "SyntaxError", SyntaxError, 1);
  rr_define_singleton_method(ExceptionClass, "Error", Error, 1);
  
  v8::V8::SetFatalErrorHandler(fatal);
  //comment this in for debugging.
  // signal(SIGSEGV, segfault);
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
therubyracer-0.8.0.pre3 ext/v8/v8_exception.cpp
therubyracer-0.8.0.pre2 ext/v8/v8_exception.cpp
therubyracer-0.8.0.pre ext/v8/v8_exception.cpp
therubyracer-0.7.5 ext/v8/v8_exception.cpp
therubyracer-0.7.4 ext/v8/v8_exception.cpp
therubyracer-0.7.3 ext/v8/v8_exception.cpp
therubyracer-0.7.2 ext/v8/v8_exception.cpp
therubyracer-0.7.2.pre ext/v8/v8_exception.cpp