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 FullFunctionCallbackMethod extends DynamicMethod { 47 private Callback callback; 48 49 public FullFunctionCallbackMethod(RubyModule implementationClass, Callback callback, Visibility visibility) { 50 super(implementationClass, visibility); 51 this.callback = callback; 52 } 53 54 public void preMethod(ThreadContext context, RubyModule clazz, IRubyObject self, String name, IRubyObject[] args, boolean noSuper, Block block) { 55 context.preReflectedMethodInternalCall(implementationClass, clazz, self, name, args, noSuper, block); 56 } 57 58 public void postMethod(ThreadContext context) { 59 context.postReflectedMethodInternalCall(); 60 } 61 62 public IRubyObject internalCall(ThreadContext context, RubyModule clazz, IRubyObject self, String name, IRubyObject[] args, boolean noSuper, Block block) { 63 assert args != null; 64 Ruby runtime = context.getRuntime(); 65 66 if (runtime.getTraceFunction() != null) { 67 ISourcePosition position = context.getPosition(); 68 69 runtime.callTraceFunction(context, "c-call", position, self, name, getImplementationClass()); 70 try { 71 return callback.execute(self, args, block); 72 } finally { 73 runtime.callTraceFunction(context, "c-return", position, self, name, getImplementationClass()); 74 } 75 } 76 return callback.execute(self, args, block); 77 } 78 79 public Callback getCallback() { 80 return callback; 81 } 82 83 public Arity getArity() { 84 return getCallback().getArity(); 85 } 86 87 public DynamicMethod dup() { 88 return new FullFunctionCallbackMethod(getImplementationClass(), callback, getVisibility()); 89 } 90 } 91 | Popular Tags |