Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9e518a1ba1a3
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8786740e3af6
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on May 9, 2015

  1. Missed new file.

    headius committed May 9, 2015
    Copy the full SHA
    ee06c44 View commit details
  2. Copy the full SHA
    8786740 View commit details
Showing with 88 additions and 42 deletions.
  1. +88 −0 core/src/main/java/org/jruby/runtime/MethodBlockBody.java
  2. +0 −24 lib/ruby/stdlib/jruby/ext.rb
  3. +0 −1 test/jruby.index
  4. +0 −17 test/jruby/test_jruby_ext.rb
88 changes: 88 additions & 0 deletions core/src/main/java/org/jruby/runtime/MethodBlockBody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.jruby.runtime;

import org.jruby.RubyModule;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.builtin.IRubyObject;

/**
* Represents a method wrapped in a block (proc), as in Method#to_proc.
*/
public class MethodBlockBody extends ContextAwareBlockBody {
private final DynamicMethod method;
private final ArgumentDescriptor[] argsDesc;
private final IRubyObject receiver;
private final RubyModule originModule;
private final String originName;
private final String file;
private final int line;

public MethodBlockBody(StaticScope staticScope, Signature signature, DynamicMethod method, ArgumentDescriptor[] argsDesc, IRubyObject receiver, RubyModule originModule, String originName, String file, int line) {
super(staticScope, signature);
this.method = method;
this.argsDesc = argsDesc;
this.receiver = receiver;
this.originModule = originModule;
this.originName = originName;
this.file = file;
this.line = line;
}

public static Block createMethodBlock(MethodBlockBody body) {
RubyModule module = body.method.getImplementationClass();
Frame frame = new Frame();

frame.setKlazz(module);
frame.setName(body.method.getName());
frame.setSelf(body.receiver);
frame.setVisibility(body.method.getVisibility());

Binding binding = new Binding(
frame,
body.getStaticScope().getDummyScope(),
body.method.getName(), body.getFile(), body.getLine());

return new Block(body, binding);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Block.Type type) {
args = prepareArgumentsForCall(context, args, type);

return method.call(context, receiver, originModule, originName, args);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding,
Block.Type type, Block block) {
args = prepareArgumentsForCall(context, args, type);

return method.call(context, receiver, originModule, originName, args, block);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding binding, Block.Type type) {
IRubyObject[] realArgs = Helpers.restructureBlockArgs19(value, getSignature(), type, false, false);
return method.call(context, receiver, originModule, originName, realArgs, Block.NULL_BLOCK);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Block.Type type) {
return method.call(context, receiver, originModule, originName, args, Block.NULL_BLOCK);
}

@Override
public String getFile() {
return file;
}

@Override
public int getLine() {
return line;
}

@Override
public ArgumentDescriptor[] getArgumentDescriptors() {
return argsDesc;
}
}
24 changes: 0 additions & 24 deletions lib/ruby/stdlib/jruby/ext.rb
Original file line number Diff line number Diff line change
@@ -45,28 +45,4 @@ def steal_methods(type, *method_names)
end
end
end

class ::Method
def args
self_r = JRuby.reference0(self)
method = self_r.get_method
args_ary = []

case method
when MethodArgs2
return Helpers.parameter_list_to_parameters(JRuby.runtime, method.parameter_list, true)
when IRMethodArgs
a = method.parameter_list
(0...(a.size)).step(2) do |i|
args_ary << (a[i+1] == "" ? [a[i].to_sym] : [a[i].to_sym, a[i+1].to_sym])
end
else
if method.arity == Arity::OPTIONAL
args_ary << [:rest]
end
end

args_ary
end
end
end
1 change: 0 additions & 1 deletion test/jruby.index
Original file line number Diff line number Diff line change
@@ -86,7 +86,6 @@ jruby/test_null_channel
jruby/test_irubyobject_java_passing
jruby/test_jruby_object_input_stream
jruby/test_jar_on_load_path
jruby/test_jruby_ext
jruby/test_jruby_core_ext
jruby/test_thread_context_frame_dereferences_unreachable_variables
jruby/test_context_classloader
17 changes: 0 additions & 17 deletions test/jruby/test_jruby_ext.rb

This file was deleted.