Skip to content

Commit

Permalink
Fixup other IRubyObect[] internal block types for call in addition to…
Browse files Browse the repository at this point in the history
… yield
  • Loading branch information
enebo committed Dec 7, 2016
1 parent 509dd05 commit 179099c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
19 changes: 11 additions & 8 deletions core/src/main/java/org/jruby/runtime/CallBlock.java
Expand Up @@ -58,14 +58,22 @@ private CallBlock(Signature signature, BlockCallback callback, ThreadContext con
this.dummyScope = context.runtime.getStaticScopeFactory().getDummyScope();
}

private IRubyObject[] adjustArgs(Block block, IRubyObject[] args) {
Signature signature = block.getSignature();
int required = signature.required();
if (signature.isFixed() && required > 0 && required != args.length) args = ArraySupport.newCopy(args, required);

return args;
}

@Override
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args) {
return callback.call(context, args, Block.NULL_BLOCK);
return callback.call(context, adjustArgs(block, args), Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
return callback.call(context, args, blockArg);
return callback.call(context, adjustArgs(block, args), blockArg);
}

@Override
Expand All @@ -85,12 +93,7 @@ protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject va

@Override
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
Signature signature = block.getSignature();
int required = signature.required();
if (signature.isFixed() && required > 0 && required != args.length) {
args = ArraySupport.newCopy(args, required);
}
return callback.call(context, args, Block.NULL_BLOCK);
return callback.call(context, adjustArgs(block, args), Block.NULL_BLOCK);
}

public StaticScope getStaticScope() {
Expand Down
21 changes: 12 additions & 9 deletions core/src/main/java/org/jruby/runtime/JavaInternalBlockBody.java
Expand Up @@ -47,14 +47,22 @@ private void threadCheck(ThreadContext yieldingContext) {
}
}

private IRubyObject[] adjustArgs(Block block, IRubyObject[] args) {
Signature signature = block.getSignature();
int required = signature.required();
if (signature.isFixed() && required > 0 && required != args.length) args = ArraySupport.newCopy(args, required);

return args;
}

@Override
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args) {
return yield(context, block, args, null);
return yield(context, block, adjustArgs(block, args), null);
}

@Override
public IRubyObject call(ThreadContext context, Block b, IRubyObject[] args, Block blockArg) {
return yield(context, b, args, null, blockArg);
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
return yield(context, block, adjustArgs(block, args), null, blockArg);
}

@Override
Expand All @@ -68,12 +76,7 @@ protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject va
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
threadCheck(context);

Signature signature = block.getSignature();
int required = signature.required();
if (signature.isFixed() && required > 0 && required != args.length) {
args = ArraySupport.newCopy(args, required);
}
return yield(context, args);
return yield(context, adjustArgs(block, args));
}

public abstract IRubyObject yield(ThreadContext context, IRubyObject[] args);
Expand Down

0 comments on commit 179099c

Please sign in to comment.