Skip to content

Commit

Permalink
simplify RestParameterInit
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Oct 9, 2023
1 parent ebe2471 commit f6ca5c1
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions boa_engine/src/vm/opcode/rest_parameter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,16 @@ impl Operation for RestParameterInit {
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let arg_count = context.vm.frame().argument_count as usize;
let param_count = context.vm.frame().code_block().params.as_ref().len();
if arg_count >= param_count {
let rest_count = arg_count - param_count + 1;
let mut args = Vec::with_capacity(rest_count);
for _ in 0..rest_count {
args.push(context.vm.pop());
}
args.reverse();
let array = Array::create_array_from_list(args, context);

context.vm.push(array);
let array = if arg_count >= param_count {
let rest_count = arg_count - param_count + 1;
let args = context.pop_n_arguments(rest_count);
Array::create_array_from_list(args, context)
} else {
let array =
Array::array_create(0, None, context).expect("could not create an empty array");
context.vm.push(array);
}
Array::array_create(0, None, context).expect("could not create an empty array")
};

context.vm.push(array);
Ok(CompletionType::Normal)
}
}

0 comments on commit f6ca5c1

Please sign in to comment.