Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yield1/yieldX: Use $$arity if available. #2547

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions opal/corelib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1667,13 +1667,16 @@
}

var has_mlhs = block.$$has_top_level_mlhs_arg,
has_trailing_comma = block.$$has_trailing_comma_in_args;
has_trailing_comma = block.$$has_trailing_comma_in_args,
length = block.$$arity || block.length;

if (block.length > 1 || ((has_mlhs || has_trailing_comma) && block.length === 1)) {
if (length < 0) length = -length;

if (length > 1 || ((has_mlhs || has_trailing_comma) && length === 1)) {
arg = Opal.to_ary(arg);
}

if ((block.length > 1 || (has_trailing_comma && block.length === 1)) && arg.$$is_array) {
if ((length > 1 || (has_trailing_comma && length === 1)) && arg.$$is_array) {
return block.apply(null, arg);
}
else {
Expand All @@ -1687,7 +1690,11 @@
$raise(Opal.LocalJumpError, "no block given");
}

if (block.length > 1 && args.length === 1) {
var length = block.$$arity || block.length;

if (length < 0) length = -length;

if (length > 1 && args.length === 1) {
if (args[0].$$is_array) {
return block.apply(null, args[0]);
}
Expand Down