From c9a7bdcab87ce2b7f00dec633dab496e1c1a96dd Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Tue, 6 Jun 2023 06:47:42 +0200 Subject: [PATCH] Fix panic in constructor call (#3001) --- boa_engine/src/vm/code_block.rs | 3 ++- boa_engine/src/vm/tests.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/boa_engine/src/vm/code_block.rs b/boa_engine/src/vm/code_block.rs index 5013bbb0e7..6aae6bbc6e 100644 --- a/boa_engine/src/vm/code_block.rs +++ b/boa_engine/src/vm/code_block.rs @@ -1405,10 +1405,11 @@ impl JsObject { ); if code.has_parameters_env_bindings() { + last_env -= 1; context .vm .environments - .push_lexical(code.compile_environments[0].clone()); + .push_lexical(code.compile_environments[last_env].clone()); } // Taken from: `FunctionDeclarationInstantiation` abstract function. diff --git a/boa_engine/src/vm/tests.rs b/boa_engine/src/vm/tests.rs index edbf25aece..954d2f3fd0 100644 --- a/boa_engine/src/vm/tests.rs +++ b/boa_engine/src/vm/tests.rs @@ -309,3 +309,18 @@ fn recursion_runtime_limit() { ), ]); } + +#[test] +fn arguments_object_constructor_valid_index() { + run_test_actions([TestAction::assert_eq( + indoc! {r#" + let args; + function F(a = 1) { + args = arguments; + } + new F(); + typeof args + "#}, + "object", + )]); +}