From 2e0334ccb25e1e2815ecc64927f73c6536c3ae46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20B=C3=A1tyai?= Date: Mon, 20 Jul 2015 10:53:07 +0200 Subject: [PATCH] Returned array of Array.prototype.map() should have same length as original. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai.u-szeged@partner.samsung.com --- .../ecma/builtin-objects/ecma-builtin-array-prototype.cpp | 4 ++++ tests/jerry/array-prototype-map.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp index 0e9a35bf09..028c38f32a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.cpp @@ -2384,7 +2384,11 @@ ecma_builtin_array_prototype_object_map (ecma_value_t this_arg, /**< this argume if (ecma_is_completion_value_empty (ret_value)) { + ECMA_TRY_CATCH (set_length_value, + ecma_builtin_array_prototype_helper_set_length (new_array_p, ecma_uint32_to_number (len)), + ret_value); ret_value = new_array; + ECMA_FINALIZE (set_length_value); } else { diff --git a/tests/jerry/array-prototype-map.js b/tests/jerry/array-prototype-map.js index cc2c5acc81..7a95ca252f 100644 --- a/tests/jerry/array-prototype-map.js +++ b/tests/jerry/array-prototype-map.js @@ -52,6 +52,10 @@ assert ([1, 4, 9].map(func).equals([1,5,11])); assert ([1, "X", 10].map(func).equals([1, "X1", 12])); +var arr = [1,2,3]; +arr.length = 5; +assert(arr.map(func).length === arr.length); + var long_array = [0, 1]; assert (long_array.map(func).equals([0,2]));