From 0d05dfcd68f7e988e213b178fae37a2f448cffd7 Mon Sep 17 00:00:00 2001 From: Peter Marki Date: Fri, 14 Sep 2018 12:04:47 +0200 Subject: [PATCH] Remove bad assertion in ecma_builtin_json_str_helper (#2521) Fixes #2494 JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu --- .../ecma/builtin-objects/ecma-builtin-json.c | 17 ++++++++++------- tests/jerry/regression-test-issue-2494.js | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 tests/jerry/regression-test-issue-2494.js diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c index 84edd81c3..a3d1bcd31 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c @@ -923,13 +923,16 @@ static ecma_value_t ecma_builtin_json_str_helper (const ecma_value_t arg1, /**< empty_str_p, arg1, false); - JERRY_ASSERT (ecma_is_value_true (put_comp_val)); - ecma_free_value (put_comp_val); - ECMA_TRY_CATCH (str_val, - ecma_builtin_json_str (empty_str_p, obj_wrapper_p, &context), - ret_value); - ret_value = ecma_copy_value (str_val); - ECMA_FINALIZE (str_val); + + if (ecma_is_value_true (put_comp_val)) + { + ret_value = ecma_builtin_json_str (empty_str_p, obj_wrapper_p, &context); + } + else + { + ret_value = ECMA_VALUE_UNDEFINED; + } + ecma_free_value (put_comp_val); ecma_deref_ecma_string (empty_str_p); ecma_deref_object (obj_wrapper_p); diff --git a/tests/jerry/regression-test-issue-2494.js b/tests/jerry/regression-test-issue-2494.js new file mode 100644 index 000000000..0a87b63aa --- /dev/null +++ b/tests/jerry/regression-test-issue-2494.js @@ -0,0 +1,16 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Object.defineProperty(Object.prototype, "", {}); +assert(JSON.stringify() === undefined)