Permalink
Browse files

Fix ruby1.8.7...

  • Loading branch information...
1 parent cdb30a5 commit 305245c482893ea067809724a8f59c741a558002 @ConradIrwin committed Aug 11, 2012
Showing with 41 additions and 7 deletions.
  1. +6 −1 Rakefile
  2. +21 −2 ext/interception.c
  3. +1 −1 lib/interception.rb
  4. +13 −3 spec/interception_spec.rb
View
@@ -1,6 +1,11 @@
+task :clean do
+ sh 'rm -f ext/*.o ext/*.so ext/*.dylib'
+ sh 'rm -f ext/org/pryrepl/*.class'
+end
+
desc "Compile *.c files"
-task :compile do
+task :compile => [:clean] do
cd 'ext/' do
sh 'ruby extconf.rb'
sh 'make'
View
@@ -2,12 +2,26 @@
static VALUE rb_mInterception;
+extern struct FRAME {
+ VALUE self;
+ int argc;
+ ID last_func;
+ ID orig_func;
+ VALUE last_class;
+ struct FRAME *prev;
+ struct FRAME *tmp;
+ struct RNode *node;
+ int iter;
+ int flags;
+ unsigned long uniq;
+} *ruby_frame;
+
#ifdef RUBY_19
void
interception_hook(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
{
- VALUE binding = rb_funcall(rb_mKernel, rb_intern("binding"), 0, NULL);
+ VALUE binding = rb_funcall(self, rb_intern("binding"), 0, NULL);
rb_funcall(rb_mInterception, rb_intern("rescue"), 2, rb_errinfo(), binding);
}
@@ -24,7 +38,12 @@ interception_start(VALUE self)
void
interception_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)
{
- VALUE binding = rb_funcall(rb_mKernel, rb_intern("binding"), 0, NULL);
+ VALUE bself = ruby_frame->prev->self;
+ if (node == ruby_frame->node) {
+ bself = ruby_frame->prev->prev->self;
+ }
+
+ VALUE binding = rb_funcall(bself, rb_intern("binding"), 0, NULL);
rb_funcall(rb_mInterception, rb_intern("rescue"), 2, ruby_errinfo, binding);
}
View
@@ -63,7 +63,7 @@ def self.listen(for_block=nil, &listen_block)
raise ArgumentError, "no block given" unless listen_block || for_block
mutex.synchronize{
start if listeners.empty?
- listeners << listen_block || for_block
+ listeners << (listen_block || for_block)
}
if listen_block && for_block
View
@@ -1,3 +1,9 @@
+Interception.listen(proc {
+ begin; raise "fooo"; rescue; end
+}) do |e, b|
+ $initial_eb = [e,b]
+end
+
describe Interception do
before do
@@ -67,7 +73,7 @@
e1, e2 = nil
block = proc{
begin
- raise "foo"
+ line = __LINE__; raise "foo"
rescue => e1
#
end
@@ -112,7 +118,7 @@
#
end
- @exceptions.map{ |e, b| [e] + b.eval('[__LINE__, shoulder]') }.should == [[e1, line, :bucket]]
+ @exceptions.map{ |e, b| [e] + b.eval('[__LINE__, shoulder, self]') }.should == [[e1, line, :bucket, self]]
e1.message.should =~ /desnrok/
end
@@ -125,7 +131,11 @@
#
end
- @exceptions.map{ |e, b| [e] + b.eval('[__LINE__, shoulder]') }.should == [[e1, line, :bucket]]
+ @exceptions.map{ |e, b| [e] + b.eval('[__LINE__, shoulder, self]') }.should == [[e1, line, :bucket, self]]
ZeroDivisionError.should === e1
end
+
+ it "should have the right exception and binding at the top level" do
+ $initial_eb.last.eval("self").should == TOPLEVEL_BINDING.eval("self")
+ end
end

0 comments on commit 305245c

Please sign in to comment.