From fc45b805794b335210a989a0a1d6d63598b84f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20B=C3=A1tyai?= Date: Wed, 22 Jul 2015 16:23:29 +0200 Subject: [PATCH] Fix Array.prototype.toLocaleString() when toLocaleString returns non-string. 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-helpers.cpp | 13 +++++++++---- tests/jerry/array-prototype-tolocalestring.js | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp index be5da5d29..c03de0df4 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.cpp @@ -154,10 +154,15 @@ ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /** < t if (ecma_op_is_callable (to_locale_value)) { ecma_object_t *locale_func_obj_p = ecma_get_object_from_value (to_locale_value); - ret_value = ecma_op_function_call (locale_func_obj_p, - ecma_make_object_value (index_obj_p), - NULL, - 0); + ECMA_TRY_CATCH (call_value, + ecma_op_function_call (locale_func_obj_p, + ecma_make_object_value (index_obj_p), + NULL, + 0), + ret_value); + ret_value = ecma_op_to_string (call_value); + ECMA_FINALIZE (call_value); + } else { diff --git a/tests/jerry/array-prototype-tolocalestring.js b/tests/jerry/array-prototype-tolocalestring.js index 6f30aaed3..bc7faf644 100644 --- a/tests/jerry/array-prototype-tolocalestring.js +++ b/tests/jerry/array-prototype-tolocalestring.js @@ -26,6 +26,11 @@ var test_ok = { assert ([3, test_ok, 4, test_ok].toLocaleString() === "3,1,4,1"); +var obj = { toLocaleString: function() {} }; +var test_non_str_locale = [undefined, obj, null, obj, obj]; + +assert(test_non_str_locale.toLocaleString() === ",undefined,,undefined,undefined"); + var test_fail = { toLocaleString: "FAIL" };