diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp index 8a8df5005..fdc093de5 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp @@ -131,6 +131,10 @@ ecma_builtin_function_helper_get_arguments (const ecma_value_t *arguments_list_p { ret_value = ecma_make_normal_completion_value (ecma_make_string_value (arguments_str_p)); } + else + { + ecma_deref_ecma_string (arguments_str_p); + } return ret_value; } /* ecma_builtin_function_helper_get_arguments */ diff --git a/tests/jerry/function-construct.js b/tests/jerry/function-construct.js index fed3df1b9..66a1e7da9 100644 --- a/tests/jerry/function-construct.js +++ b/tests/jerry/function-construct.js @@ -98,6 +98,20 @@ catch (e) assert (e instanceof TypeError); } +var p = { toString : function() { throw 1; } }; +var body = { toString : function() { throw "body"; } }; + +try +{ + new Function (p, body); + // Should not be reached. + assert (false); +} +catch (e) +{ + assert (e === 1); +} + // Check SyntaxError handling try {