From f6ca5c1bb938397007434a69f80365fb3ca37be4 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Mon, 9 Oct 2023 14:10:02 +0200 Subject: [PATCH] simplify RestParameterInit --- .../src/vm/opcode/rest_parameter/mod.rs | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/boa_engine/src/vm/opcode/rest_parameter/mod.rs b/boa_engine/src/vm/opcode/rest_parameter/mod.rs index 1bc6bbffd2e..545e10957b5 100644 --- a/boa_engine/src/vm/opcode/rest_parameter/mod.rs +++ b/boa_engine/src/vm/opcode/rest_parameter/mod.rs @@ -18,21 +18,16 @@ impl Operation for RestParameterInit { fn execute(context: &mut Context<'_>) -> JsResult { 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) } }