Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
adding the ruby parts
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed May 22, 2008
1 parent 819db19 commit 3924b2e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 14 deletions.
16 changes: 12 additions & 4 deletions ext/spidermonkey/context.c
Expand Up @@ -4,7 +4,7 @@
#include "error.h"
#include "extensions.h"
#include "idhash.h"
#include "jscntxt.h"
#include "jsdbgapi.h"

/*
* call-seq:
Expand Down Expand Up @@ -133,13 +133,21 @@ set_debugger(VALUE self, VALUE debugger)
{
OurContext* context;
JSDebugHooks* debug_hooks;
bool gthings_rooted_p = false;

Data_Get_Struct(self, OurContext, context);
Data_Get_Struct(debugger, JSDebugHooks, debug_hooks);
context->js->debugHooks = debug_hooks;

return debugger;
JS_SetInterrupt(context->runtime, debug_hooks->interruptHandler, debugger);
JS_SetNewScriptHook(context->runtime, debug_hooks->newScriptHook, debugger);
JS_SetDestroyScriptHook(context->runtime, debug_hooks->destroyScriptHook, debugger);
JS_SetDebuggerHandler(context->runtime, debug_hooks->debuggerHandler, debugger);
JS_SetSourceHandler(context->runtime, debug_hooks->sourceHandler, debugger);
JS_SetExecuteHook(context->runtime, debug_hooks->executeHook, debugger);
JS_SetCallHook(context->runtime, debug_hooks->callHook, debugger);
JS_SetThrowHook(context->runtime, debug_hooks->throwHook, debugger);
JS_SetDebugErrorHook(context->runtime, debug_hooks->debugErrorHook, debugger);

return Qtrue;
}

/*
Expand Down
54 changes: 44 additions & 10 deletions ext/spidermonkey/debugger.c
@@ -1,63 +1,97 @@
#include "debugger.h"

static JSTrapStatus interrupt_handler(JSContext *cx, JSScript *script,
static JSTrapStatus interrupt_handler(JSContext *js, JSScript *script,
jsbytecode *pc, jsval *rval, void *rb)
{
VALUE context = (VALUE)JS_GetContextPrivate(js);
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("interrupt_handler"), 1, context);
return JSTRAP_CONTINUE;
}

static void new_script_hook(JSContext *cx,
static void new_script_hook(JSContext *js,
const char *filename,
uintN lineno,
JSScript *script,
JSFunction *fun,
void *rb)
{
VALUE context = (VALUE)JS_GetContextPrivate(js);
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("new_script_hook"), 1, context);
}

static void destroy_script_hook(JSContext *cx,
static void destroy_script_hook(JSContext *js,
JSScript *script,
void *rb)
{
VALUE context = (VALUE)JS_GetContextPrivate(js);
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("destroy_script_hook"), 1, context);
}

static JSTrapStatus debugger_handler(JSContext *cx, JSScript *script,
static JSTrapStatus debugger_handler(JSContext *js, JSScript *script,
jsbytecode *pc, jsval *rval, void *rb)
{
VALUE context = (VALUE)JS_GetContextPrivate(js);
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("debugger_handler"), 1, context);
return JSTRAP_CONTINUE;
}

static void source_handler(const char *filename, uintN lineno,
jschar *str, size_t length,
void **listenerTSData, void *rb)
{
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("source_handler"), 0);
}

static void * execute_hook(JSContext *cx, JSStackFrame *fp, JSBool before,
static void * execute_hook(JSContext *js, JSStackFrame *fp, JSBool before,
JSBool *ok, void *rb)
{
VALUE context = (VALUE)JS_GetContextPrivate(js);
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("execute_hook"), 1, context);
return rb;
}

static void * call_hook(JSContext *cx, JSStackFrame *fp, JSBool before,
static void * call_hook(JSContext *js, JSStackFrame *fp, JSBool before,
JSBool *ok, void *rb)
{
VALUE context = (VALUE)JS_GetContextPrivate(js);
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("call_hook"), 1, context);
return rb;
}

static void object_hook(JSContext *cx, JSObject *obj, JSBool isNew, void *rb)
static void object_hook(JSContext *js, JSObject *obj, JSBool isNew, void *rb)
{
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("object_hook"), 0);
}

static JSTrapStatus throw_hook(JSContext *cx, JSScript *script,
static JSTrapStatus throw_hook(JSContext *js, JSScript *script,
jsbytecode *pc, jsval *rval, void *rb)
{
VALUE context = (VALUE)JS_GetContextPrivate(js);
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("throw_hook"), 1, context);
return JSTRAP_CONTINUE;
}

static JSBool debug_error_hook(JSContext *cx, const char *message,
static JSBool debug_error_hook(JSContext *js, const char *message,
JSErrorReport *report, void *rb)
{
VALUE context = (VALUE)JS_GetContextPrivate(js);
VALUE self = (VALUE)rb;
rb_funcall(self, rb_intern("debug_error_hook"), 1, context);
return JS_TRUE;
}

static void deallocate(JSDebugHooks * hooks)
{
free(hooks);
//free(hooks);
}

static VALUE allocate(VALUE klass)
Expand Down
1 change: 1 addition & 0 deletions lib/johnson.rb
Expand Up @@ -19,6 +19,7 @@
require "johnson/spidermonkey/js_land_proxy"
require "johnson/spidermonkey/ruby_land_proxy"
require "johnson/spidermonkey/mutable_tree_visitor"
require "johnson/spidermonkey/debugger"
require "johnson/spidermonkey/immutable_node"

# the 'public' interface
Expand Down
57 changes: 57 additions & 0 deletions lib/johnson/spidermonkey/debugger.rb
@@ -0,0 +1,57 @@
module Johnson #:nodoc:
module SpiderMonkey #:nodoc:
class Debugger # native
# Enum constants from jsprvtd.h
JSTRAP_ERROR = 0
JSTRAP_CONTINUE = 1
JSTRAP_RETURN = 2
JSTRAP_THROW = 3
JSTRAP_LIMIT = 4

attr_accessor :logger
def initialize(logger)
@logger = logger
end

def interrupt_handler(context)
logger.debug("interrupt_handler")
end

def new_script_hook(context)
logger.debug("new_script_hook")
end

def destroy_script_hook(context)
logger.debug("destroy_script_hook")
end

def debugger_handler(context)
logger.debug("debugger_handler")
end

def source_handler
logger.debug("source_handler")
end

def execute_hook(context)
logger.debug("execute_hook")
end

def call_hook(context)
logger.debug("call_hook")
end

def object_hook
logger.debug("object_hook")
end

def throw_hook(context)
logger.debug("throw_hook")
end

def debug_error_hook(context)
logger.debug("debug_error_hook")
end
end
end
end
3 changes: 3 additions & 0 deletions test/johnson/context_test.rb
@@ -1,9 +1,12 @@
require File.expand_path(File.join(File.dirname(__FILE__), "/../helper"))

require 'logger'
module Johnson
class ContextTest < Johnson::TestCase
def setup
@context = Johnson::Context.new
db = Johnson::SpiderMonkey::Debugger.new(Logger.new(STDOUT))
@context.delegate.debugger = db
end

def test_default_delegate_is_spidermonkey
Expand Down

0 comments on commit 3924b2e

Please sign in to comment.