1 32 package org.jruby.internal.runtime.methods; 33 34 import org.jruby.Ruby; 35 import org.jruby.RubyModule; 36 import org.jruby.lexer.yacc.ISourcePosition; 37 import org.jruby.runtime.Arity; 38 import org.jruby.runtime.Block; 39 import org.jruby.runtime.ThreadContext; 40 import org.jruby.runtime.Visibility; 41 import org.jruby.runtime.builtin.IRubyObject; 42 import org.jruby.runtime.callback.Callback; 43 44 46 public class SimpleCallbackMethod extends DynamicMethod { 47 private Callback callback; 48 49 public SimpleCallbackMethod(RubyModule implementationClass, Callback callback, Visibility visibility) { 50 super(implementationClass, visibility); 51 this.callback = callback; 52 } 53 54 public void preMethod(ThreadContext context, RubyModule klazz, IRubyObject self, String name, IRubyObject[] args, boolean noSuper, Block block) { 55 } 56 57 public void postMethod(ThreadContext context) { 58 } 59 60 public IRubyObject internalCall(ThreadContext context, RubyModule klazz, IRubyObject self, String name, IRubyObject[] args, boolean noSuper, Block block) { 61 assert false; 62 return null; 63 } 64 65 public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject[] args, boolean noSuper, Block block) { 66 assert args != null; 67 Ruby runtime = context.getRuntime(); 68 69 if (runtime.getTraceFunction() != null) { 70 ISourcePosition position = context.getPosition(); 71 72 runtime.callTraceFunction(context, "c-call", position, self, name, getImplementationClass()); 73 try { 74 return callback.execute(self, args, Block.NULL_BLOCK); 75 } finally { 76 runtime.callTraceFunction(context, "c-return", position, self, name, getImplementationClass()); 77 } 78 } 79 return callback.execute(self, args, Block.NULL_BLOCK); 80 } 81 82 public Callback getCallback() { 83 return callback; 84 } 85 86 public Arity getArity() { 87 return getCallback().getArity(); 88 } 89 90 public DynamicMethod dup() { 91 return new SimpleCallbackMethod(getImplementationClass(), callback, getVisibility()); 92 } 93 } 94 | Popular Tags |