@@ -192,21 +192,20 @@ impl Function {
192192 let local_env = new_function_environment (
193193 function,
194194 None ,
195- Some ( self . environment . as_ref ( ) . unwrap ( ) . clone ( ) ) ,
195+ self . environment . as_ref ( ) . cloned ( ) ,
196196 BindingStatus :: Uninitialized ,
197197 ) ;
198198
199199 // Add argument bindings to the function environment
200- for i in 0 ..self . params . len ( ) {
201- let param = self . params . get ( i) . expect ( "Could not get param" ) ;
200+ for ( i, param) in self . params . iter ( ) . enumerate ( ) {
202201 // Rest Parameters
203202 if param. is_rest_param ( ) {
204203 self . add_rest_param ( param, i, args_list, interpreter, & local_env) ;
205204 break ;
206205 }
207206
208- let value = args_list. get ( i) . expect ( "Could not get value" ) ;
209- self . add_arguments_to_environment ( param, value. clone ( ) , & local_env) ;
207+ let value = args_list. get ( i) . cloned ( ) . unwrap_or_else ( Value :: undefined ) ;
208+ self . add_arguments_to_environment ( param, value, & local_env) ;
210209 }
211210
212211 // Add arguments object
@@ -253,7 +252,7 @@ impl Function {
253252 let local_env = new_function_environment (
254253 function,
255254 Some ( this. clone ( ) ) ,
256- Some ( self . environment . as_ref ( ) . unwrap ( ) . clone ( ) ) ,
255+ self . environment . as_ref ( ) . cloned ( ) ,
257256 BindingStatus :: Initialized ,
258257 ) ;
259258
@@ -265,8 +264,8 @@ impl Function {
265264 break ;
266265 }
267266
268- let value = args_list. get ( i) . expect ( "Could not get value" ) ;
269- self . add_arguments_to_environment ( param, value. clone ( ) , & local_env) ;
267+ let value = args_list. get ( i) . cloned ( ) . unwrap_or_else ( Value :: undefined ) ;
268+ self . add_arguments_to_environment ( param, value, & local_env) ;
270269 }
271270
272271 // Add arguments object
0 commit comments