mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
bind to low level C::StackTrace and C::StackFrame API
This commit is contained in:
parent
514ce122fa
commit
22727d1e4a
5 changed files with 99 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
#include "v8_date.h"
|
||||
#include "v8_msg.h"
|
||||
#include "v8_external.h"
|
||||
#include "v8_exception.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
|
@ -75,6 +76,13 @@ VALUE rr_v82rb(Handle<Value> value) {
|
|||
VALUE rr_v82rb(Handle<Message> value) {
|
||||
return rr_reflect_v8_message(value);
|
||||
}
|
||||
VALUE rr_v82rb(Handle<StackTrace> value) {
|
||||
return rr_reflect_v8_stacktrace(value);
|
||||
}
|
||||
VALUE rr_v82rb(Handle<StackFrame> value) {
|
||||
return rr_reflect_v8_stackframe(value);
|
||||
}
|
||||
|
||||
VALUE rr_v82rb(Handle<Boolean> value) {
|
||||
return rr_v82rb((Handle<Value>)value);
|
||||
}
|
||||
|
@ -87,6 +95,9 @@ VALUE rr_v82rb(Handle<String> value) {
|
|||
VALUE rr_v82rb(Handle<Object> value) {
|
||||
return rr_v82rb((Handle<Value>)value);
|
||||
}
|
||||
VALUE rr_v82rb(Handle<Array> value) {
|
||||
return rr_v82rb((Handle<Value>)value);
|
||||
}
|
||||
VALUE rr_v82rb(v8::Handle<v8::Function> value) {
|
||||
return rr_v82rb((Handle<Value>)value);
|
||||
}
|
||||
|
|
|
@ -16,11 +16,15 @@ VALUE rr_v82rb(v8::Handle<v8::Boolean> value);
|
|||
VALUE rr_v82rb(v8::Handle<v8::Number> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::String> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Object> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Array> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Function> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Integer> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Uint32> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Int32> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::Message> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::StackTrace> value);
|
||||
VALUE rr_v82rb(v8::Handle<v8::StackFrame> value);
|
||||
|
||||
VALUE rr_v82rb(bool value);
|
||||
VALUE rr_v82rb(double value);
|
||||
VALUE rr_v82rb(int64_t value);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "v8_exception.h"
|
||||
#include "rr.h"
|
||||
#include "v8_ref.h"
|
||||
#include "execinfo.h"
|
||||
#include "signal.h"
|
||||
|
||||
|
@ -38,19 +39,90 @@ namespace {
|
|||
HandleScope scope;
|
||||
return rr_v82rb(Exception::Error(rr_rb2v8(value)->ToString()));
|
||||
}
|
||||
|
||||
VALUE StackTraceClass;
|
||||
VALUE StackFrameClass;
|
||||
namespace Trace {
|
||||
|
||||
Local<StackTrace> trace(VALUE value) {
|
||||
return V8_Ref_Get<StackTrace>(value);
|
||||
}
|
||||
VALUE GetFrame(VALUE self, VALUE index) {
|
||||
HandleScope scope;
|
||||
return rr_v82rb(trace(self)->GetFrame(NUM2UINT(index)));
|
||||
}
|
||||
VALUE GetFrameCount(VALUE self) {
|
||||
HandleScope scope;
|
||||
Local<StackTrace> t = trace(self);
|
||||
return rr_v82rb(t->GetFrameCount());
|
||||
}
|
||||
VALUE AsArray(VALUE self) {
|
||||
return rr_v82rb(trace(self)->AsArray());
|
||||
}
|
||||
VALUE CurrentStackTrace(VALUE self, VALUE frame_limit) {
|
||||
return rr_v82rb(StackTrace::CurrentStackTrace(NUM2INT(frame_limit)));
|
||||
}
|
||||
}
|
||||
|
||||
namespace Frame {
|
||||
Local<StackFrame> frame(VALUE value) {
|
||||
return V8_Ref_Get<StackFrame>(value);
|
||||
}
|
||||
VALUE GetLineNumber(VALUE self) {
|
||||
return rr_v82rb(frame(self)->GetLineNumber());
|
||||
}
|
||||
VALUE GetColumn(VALUE self) {
|
||||
return rr_v82rb(frame(self)->GetColumn());
|
||||
}
|
||||
VALUE GetScriptName(VALUE self) {
|
||||
return rr_v82rb(frame(self)->GetScriptName());
|
||||
}
|
||||
VALUE GetFunctionName(VALUE self) {
|
||||
return rr_v82rb(frame(self)->GetFunctionName());
|
||||
}
|
||||
VALUE IsEval(VALUE self) {
|
||||
return rr_v82rb(frame(self)->IsEval());
|
||||
}
|
||||
VALUE IsConstructor(VALUE self) {
|
||||
return rr_v82rb(frame(self)->IsConstructor());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
StackTraceClass = rr_define_class("StackTrace");
|
||||
rr_define_singleton_method(StackTraceClass, "CurrentStackTrace", Trace::CurrentStackTrace, 0);
|
||||
rr_define_method(StackTraceClass, "GetFrame", Trace::GetFrame, 1);
|
||||
rr_define_method(StackTraceClass, "GetFrameCount", Trace::GetFrameCount, 0);
|
||||
rr_define_method(StackTraceClass, "AsArray", Trace::AsArray, 0);
|
||||
|
||||
StackFrameClass = rr_define_class("StackFrame");
|
||||
rr_define_method(StackFrameClass, "GetLineNumber", Frame::GetLineNumber, 0);
|
||||
rr_define_method(StackFrameClass, "GetColumn", Frame::GetColumn, 0);
|
||||
rr_define_method(StackFrameClass, "GetScriptName", Frame::GetScriptName, 0);
|
||||
rr_define_method(StackFrameClass, "GetFunctionName", Frame::GetFunctionName, 0);
|
||||
rr_define_method(StackFrameClass, "IsEval", Frame::IsEval, 0);
|
||||
rr_define_method(StackFrameClass, "IsConstructor", Frame::IsConstructor, 0);
|
||||
|
||||
v8::V8::SetFatalErrorHandler(fatal);
|
||||
//comment this in for debugging.
|
||||
// signal(SIGSEGV, segfault);
|
||||
}
|
||||
}
|
||||
|
||||
VALUE rr_reflect_v8_stacktrace(Handle<StackTrace> value) {
|
||||
return rr_v8_ref_create(StackTraceClass, value);
|
||||
}
|
||||
VALUE rr_reflect_v8_stackframe(Handle<StackTrace> value) {
|
||||
return rr_v8_ref_create(StackFrameClass, value);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#ifndef _RR_V8_EXCEPTION_
|
||||
#define _RR_V8_EXCEPTION_
|
||||
|
||||
#include "v8.h"
|
||||
#include "ruby.h"
|
||||
|
||||
void rr_init_v8_exception();
|
||||
VALUE rr_reflect_v8_stacktrace(v8::Handle<v8::StackTrace> value);
|
||||
VALUE rr_reflect_v8_stackframe(v8::Handle<v8::StackFrame> value);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,6 +23,10 @@ namespace {
|
|||
return rr_v82rb(unwrap(self)->GetScriptResourceName());
|
||||
}
|
||||
|
||||
VALUE GetStackTrace(VALUE self) {
|
||||
return rr_v82rb(unwrap(self)->GetStackTrace());
|
||||
}
|
||||
|
||||
VALUE GetLineNumber(VALUE self) {
|
||||
return rr_v82rb(unwrap(self)->GetLineNumber());
|
||||
}
|
||||
|
@ -49,6 +53,7 @@ void rr_init_msg() {
|
|||
rr_define_method(MessageClass, "Get", Get, 0);
|
||||
rr_define_method(MessageClass, "GetSourceLine", GetSourceLine, 0);
|
||||
rr_define_method(MessageClass, "GetScriptResourceName", GetScriptResourceName, 0);
|
||||
rr_define_method(MessageClass, "GetStackTrace", GetStackTrace, 0);
|
||||
rr_define_method(MessageClass, "GetLineNumber", GetLineNumber, 0);
|
||||
rr_define_method(MessageClass, "GetStartPosition", GetStartPosition, 0);
|
||||
rr_define_method(MessageClass, "GetEndPosition", GetEndPosition, 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue