@@ -279,10 +279,36 @@ ecma_builtin_function_prototype_object_bind (ecma_value_t this_arg, /**< this ar
279279 * See also: ecma_object_get_class_name
280280 */
281281
282- /* 17 . */
282+ /* 16 . */
283283 ecma_number_t *length_p = ecma_alloc_number ();
284- *length_p = 0 ;
284+ *length_p = ECMA_NUMBER_ZERO;
285+
286+ ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
287+
288+ /* 15. */
289+ if (ecma_object_get_class_name (this_arg_obj_p) == LIT_MAGIC_STRING_FUNCTION_UL)
290+ {
291+ ecma_completion_value_t get_len_completion = ecma_op_object_get (this_arg_obj_p,
292+ magic_string_length_p);
293+ JERRY_ASSERT (ecma_is_completion_value_normal (get_len_completion));
294+
295+ ecma_value_t len_value = ecma_get_completion_value_value (get_len_completion);
296+ JERRY_ASSERT (ecma_is_value_number (len_value));
297+
298+ const ecma_length_t bound_arg_count = arg_count > 1 ? arg_count - 1 : 0 ;
285299
300+ /* 15.a */
301+ *length_p = *ecma_get_number_from_value (len_value) - ecma_uint32_to_number (bound_arg_count);
302+ ecma_free_completion_value (get_len_completion);
303+
304+ /* 15.b */
305+ if (ecma_number_is_negative (*length_p))
306+ {
307+ *length_p = ECMA_NUMBER_ZERO;
308+ }
309+ }
310+
311+ /* 17. */
286312 ecma_property_descriptor_t length_prop_desc = ecma_make_empty_property_descriptor ();
287313 {
288314 length_prop_desc.is_value_defined = true ;
@@ -297,7 +323,6 @@ ecma_builtin_function_prototype_object_bind (ecma_value_t this_arg, /**< this ar
297323 length_prop_desc.is_configurable_defined = true ;
298324 length_prop_desc.is_configurable = false ;
299325 }
300- ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
301326 ecma_completion_value_t completion = ecma_op_object_define_own_property (function_p,
302327 magic_string_length_p,
303328 &length_prop_desc,
0 commit comments