|
16 | 16 |
|
17 | 17 | #include "ecma-alloc.h"
|
18 | 18 | #include "ecma-array-object.h"
|
19 |
| -#include "ecma-array-prototype.h" |
20 | 19 | #include "ecma-builtin-helpers.h"
|
21 | 20 | #include "ecma-builtins.h"
|
22 | 21 | #include "ecma-comparison.h"
|
@@ -314,6 +313,67 @@ ecma_builtin_array_prototype_object_for_each (ecma_value_t this_arg, /**< this a
|
314 | 313 | return ret_value;
|
315 | 314 | } /* ecma_builtin_array_prototype_object_for_each */
|
316 | 315 |
|
| 316 | +/** |
| 317 | + * The Array.prototype.toString's separator creation routine |
| 318 | + * |
| 319 | + * See also: |
| 320 | + * ECMA-262 v5.1, 15.4.4.2 4th step |
| 321 | + * |
| 322 | + * @return completion value |
| 323 | + * Returned value must be freed with ecma_free_completion_value. |
| 324 | + */ |
| 325 | +static ecma_completion_value_t |
| 326 | +ecma_op_array_get_separator_string (ecma_value_t separator) /** < possible separator */ |
| 327 | +{ |
| 328 | + if (ecma_is_value_undefined (separator)) |
| 329 | + { |
| 330 | + ecma_string_t *comma_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_COMMA_CHAR); |
| 331 | + return ecma_make_normal_completion_value (ecma_make_string_value (comma_string_p)); |
| 332 | + } |
| 333 | + else |
| 334 | + { |
| 335 | + return ecma_op_to_string (separator); |
| 336 | + } |
| 337 | +} /* ecma_op_array_get_separator_string */ |
| 338 | + |
| 339 | +/** |
| 340 | + * The Array.prototype's 'toString' single element operation routine |
| 341 | + * |
| 342 | + * See also: |
| 343 | + * ECMA-262 v5.1, 15.4.4.2 |
| 344 | + * |
| 345 | + * @return ecma_completion_value_t value |
| 346 | + * Returned value must be freed with ecma_free_completion_value. |
| 347 | + */ |
| 348 | +static ecma_completion_value_t |
| 349 | +ecma_op_array_get_to_string_at_index (ecma_object_t *obj_p, /** < this object */ |
| 350 | + uint32_t index) /** < array index */ |
| 351 | +{ |
| 352 | + ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); |
| 353 | + ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index); |
| 354 | + |
| 355 | + ECMA_TRY_CATCH (index_value, |
| 356 | + ecma_op_object_get (obj_p, index_string_p), |
| 357 | + ret_value); |
| 358 | + |
| 359 | + if (ecma_is_value_undefined (index_value) |
| 360 | + || ecma_is_value_null (index_value)) |
| 361 | + { |
| 362 | + ecma_string_t *empty_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); |
| 363 | + ret_value = ecma_make_normal_completion_value (ecma_make_string_value (empty_string_p)); |
| 364 | + } |
| 365 | + else |
| 366 | + { |
| 367 | + ret_value = ecma_op_to_string (index_value); |
| 368 | + } |
| 369 | + |
| 370 | + ECMA_FINALIZE (index_value); |
| 371 | + |
| 372 | + ecma_deref_ecma_string (index_string_p); |
| 373 | + |
| 374 | + return ret_value; |
| 375 | +} /* ecma_op_array_get_to_string_at_index */ |
| 376 | + |
317 | 377 | /**
|
318 | 378 | * The Array.prototype object's 'join' routine
|
319 | 379 | *
|
|
0 commit comments