From 261e264b01d2892f94edce17ac0cdc3878c6ccc6 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:20:59 +0200 Subject: [PATCH] Fix order of `ToString` call in Function constructor (#3820) The `ToString` method was being called on the body before the paramater list, this caused some test262 tests to fail. --- core/engine/src/builtins/function/mod.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/engine/src/builtins/function/mod.rs b/core/engine/src/builtins/function/mod.rs index da223b3bc0a..0d1604fcba4 100644 --- a/core/engine/src/builtins/function/mod.rs +++ b/core/engine/src/builtins/function/mod.rs @@ -436,15 +436,18 @@ impl BuiltInFunctionObject { // 6. Let argCount be the number of elements in parameterArgs. let (body, param_list) = if let Some((body, params)) = args.split_last() { - // 7. Let bodyString be ? ToString(bodyArg). - let body = body.to_string(context)?; - // 8. Let parameterStrings be a new empty List. + // 7. Let parameterStrings be a new empty List. let mut parameters = Vec::with_capacity(args.len()); - // 9. For each element arg of parameterArgs, do + + // 8. For each element arg of parameterArgs, do for param in params { - // a. Append ? ToString(arg) to parameterStrings. + // a. Append ? ToString(arg) to parameterStrings. parameters.push(param.to_string(context)?); } + + // 9. Let bodyString be ? ToString(bodyArg). + let body = body.to_string(context)?; + (body, parameters) } else { (js_string!(), Vec::new())