| Method from org.jruby.internal.runtime.methods.DynamicMethod Detail: |
protected static RubyModule calculateProtectedClass(RubyModule cls) {
// singleton classes don't get their own visibility domain
if (cls.isSingleton()) cls = cls.getSuperClass();
while (cls.isIncluded()) cls = cls.getMetaClass();
// For visibility we need real meta class and not anonymous one from class < < self
if (cls instanceof MetaClass) cls = ((MetaClass) cls).getRealClass();
return cls;
}
Calculate, based on given RubyModule, which class in its hierarchy
should be used to determine protected access. |
public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule klazz,
String name) {
return call(context, self, klazz, name, Block.NULL_BLOCK);
}
A default implementation of zero arity, non-block 'call' method,
which simply calls the zero-arity, block-receiving version with
Block.NULL_BLOCK. |
public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule clazz,
String name,
IRubyObject[] args) {
return call(context, self, clazz, name, args, Block.NULL_BLOCK);
}
A default implementation of n-arity, non-block 'call' method,
which simply calls the n-arity, block-receiving version with
the arg list and Block.NULL_BLOCK. |
public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule klazz,
String name,
IRubyObject arg) {
return call(context, self, klazz, name, arg, Block.NULL_BLOCK);
}
A default implementation of one-arity, non-block 'call' method,
which simply calls the one-arity, block-receiving version with
the argument and Block.NULL_BLOCK. |
public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule klazz,
String name,
Block block) {
return call(context, self, klazz, name, IRubyObject.NULL_ARRAY, block);
}
A default implementation of zero arity, block-receiving 'call' method,
which simply calls the n-arity, block-receiving version with
IRubyObject.NULL_ARRAY. |
abstract public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule clazz,
String name,
IRubyObject[] args,
Block block)
The minimum 'call' method required for a dynamic method handle.
Subclasses must impleemnt this method, but may implement the other
signatures to provide faster, non-boxing call paths. Typically
subclasses will implement this method to check variable arity calls,
then performing a specific-arity invocation to the appropriate method
or performing variable-arity logic in-line. |
public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule klazz,
String name,
IRubyObject arg1,
IRubyObject arg2) {
return call(context, self, klazz, name, arg1,arg2, Block.NULL_BLOCK);
}
A default implementation of two-arity, non-block 'call' method,
which simply calls the two-arity, block-receiving version with
the arguments and Block.NULL_BLOCK. |
public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule klazz,
String name,
IRubyObject arg,
Block block) {
return call(context, self, klazz, name, new IRubyObject[] {arg}, block);
}
A default implementation of one-arity, block-receiving 'call' method,
which simply calls the n-arity, block-receiving version with
a boxed arg list. |
public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule klazz,
String name,
IRubyObject arg1,
IRubyObject arg2,
IRubyObject arg3) {
return call(context, self, klazz, name, arg1,arg2,arg3, Block.NULL_BLOCK);
}
A default implementation of three-arity, non-block 'call' method,
which simply calls the three-arity, block-receiving version with
the arguments and Block.NULL_BLOCK. |
public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule klazz,
String name,
IRubyObject arg1,
IRubyObject arg2,
Block block) {
return call(context, self, klazz, name, new IRubyObject[] {arg1,arg2}, block);
}
A default implementation of two-arity, block-receiving 'call' method,
which simply calls the n-arity, block-receiving version with
a boxed arg list. |
public IRubyObject call(ThreadContext context,
IRubyObject self,
RubyModule klazz,
String name,
IRubyObject arg1,
IRubyObject arg2,
IRubyObject arg3,
Block block) {
return call(context, self, klazz, name, new IRubyObject[] {arg1,arg2,arg3}, block);
}
A default implementation of three-arity, block-receiving 'call' method,
which simply calls the n-arity, block-receiving version with
a boxed arg list. |
abstract public DynamicMethod dup()
Duplicate this method, returning DynamicMethod referencing the same code
and with the same attributes.
It is not required that this method produce a new object if the
semantics of the DynamicMethod subtype do not require such. |
public Arity getArity() {
return Arity.optional();
}
Retrieve the arity of this method, used for reporting arity to Ruby
code. This arity may or may not reflect the actual specific or variable
arities of the referenced method. |
public CallConfiguration getCallConfig() {
return callConfig;
}
Get the CallConfiguration used for pre/post logic for this method handle. |
public RubyModule getImplementationClass() {
return implementationClass;
}
Retrieve the class or module on which this method is implemented, used
for 'super' logic among others. |
protected RubyModule getProtectedClass() {
return protectedClass;
}
Retrieve the pre-calculated "protected class" used for access checks. |
public DynamicMethod getRealMethod() {
return this;
}
Get the "real" method contained within this method. This simply returns
self except in cases where a method is wrapped to give it a new
name or new implementation class (AliasMethod, WrapperMethod, ...). |
public Visibility getVisibility() {
return visibility;
}
Get the visibility of this method. |
protected IRubyObject handleRedo(Ruby runtime) throws RaiseException {
throw runtime.newLocalJumpError("redo", runtime.getNil(), "unexpected redo");
}
|
protected IRubyObject handleReturn(ThreadContext context,
JumpException.ReturnJump rj) {
if (rj.getTarget() == context.getFrameJumpTarget()) {
return (IRubyObject) rj.getValue();
}
throw rj;
}
|
protected void init(RubyModule implementationClass,
Visibility visibility,
CallConfiguration callConfig) {
this.visibility = visibility;
this.implementationClass = implementationClass;
// TODO: Determine whether we should perhaps store non-singleton class
// in the implementationClass
this.protectedClass = calculateProtectedClass(implementationClass);
this.callConfig = callConfig;
}
|
public boolean isCallableFrom(IRubyObject caller,
CallType callType) {
switch (visibility) {
case PUBLIC:
return true;
case PRIVATE:
return callType != CallType.NORMAL;
case PROTECTED:
return protectedAccessOk(caller);
}
return true;
}
Determine whether this method is callable from the given object using
the given call type. |
public boolean isNative() {
return false;
}
Returns true if this method is backed by native (i.e. Java) code. |
public final boolean isUndefined() {
return this instanceof UndefinedMethod;
}
Whether this method is the "undefined" method, used to represent a
missing or undef'ed method. Only returns true for UndefinedMethod
instances, of which there should be only one (a singleton). |
public void setCallConfig(CallConfiguration callConfig) {
this.callConfig = callConfig;
}
Set the CallConfiguration used for pre/post logic for this method handle. |
public void setImplementationClass(RubyModule implClass) {
implementationClass = implClass;
protectedClass = calculateProtectedClass(implClass);
}
Set the class on which this method is implemented, used for 'super'
logic, among others. |
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
Set the visibility of this method. |