@@ -279,10 +279,38 @@ 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. */
283282 ecma_number_t *length_p = ecma_alloc_number ();
284- *length_p = 0 ;
283+ ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
284+
285+ /* 15. */
286+ if (ecma_object_get_class_name (this_arg_obj_p) == LIT_MAGIC_STRING_FUNCTION_UL)
287+ {
288+ ecma_completion_value_t get_len_completion = ecma_op_object_get (this_arg_obj_p,
289+ magic_string_length_p);
290+ JERRY_ASSERT (ecma_is_completion_value_normal (get_len_completion));
291+
292+ ecma_value_t len_value = ecma_get_completion_value_value (get_len_completion);
293+ JERRY_ASSERT (ecma_is_value_number (len_value));
294+
295+ const ecma_length_t bound_arg_count = arg_count > 1 ? arg_count - 1 : 0 ;
296+
297+ /* 15.a */
298+ *length_p = *ecma_get_number_from_value (len_value) - ecma_uint32_to_number (bound_arg_count);
299+ ecma_free_completion_value (get_len_completion);
300+
301+ /* 15.b */
302+ if (ecma_number_is_negative (*length_p))
303+ {
304+ *length_p = ECMA_NUMBER_ZERO;
305+ }
306+ }
307+ else
308+ {
309+ /* 16. */
310+ *length_p = ECMA_NUMBER_ZERO;
311+ }
285312
313+ /* 17. */
286314 ecma_property_descriptor_t length_prop_desc = ecma_make_empty_property_descriptor ();
287315 {
288316 length_prop_desc.is_value_defined = true ;
@@ -297,7 +325,6 @@ ecma_builtin_function_prototype_object_bind (ecma_value_t this_arg, /**< this ar
297325 length_prop_desc.is_configurable_defined = true ;
298326 length_prop_desc.is_configurable = false ;
299327 }
300- ecma_string_t *magic_string_length_p = ecma_get_magic_string (LIT_MAGIC_STRING_LENGTH);
301328 ecma_completion_value_t completion = ecma_op_object_define_own_property (function_p,
302329 magic_string_length_p,
303330 &length_prop_desc,
0 commit comments