mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Fix error handling in SerializeJSONProperty (#3816)
Fixes #3813. JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
parent
3b4c259281
commit
d06c3a7f50
@ -1186,36 +1186,36 @@ ecma_builtin_json_serialize_property (ecma_json_stringify_context_t *context_p,
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
lit_magic_string_id_t class_name = ecma_object_get_class_name (obj_p);
|
||||
|
||||
ecma_value_t result = ECMA_VALUE_EMPTY;
|
||||
|
||||
/* 5.a */
|
||||
if (class_name == LIT_MAGIC_STRING_NUMBER_UL)
|
||||
{
|
||||
result = ecma_op_to_number (value);
|
||||
value = ecma_op_to_number (value);
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
/* 5.b */
|
||||
else if (class_name == LIT_MAGIC_STRING_STRING_UL)
|
||||
{
|
||||
ecma_string_t *str_p = ecma_op_to_string (value);
|
||||
result = ecma_make_string_value (str_p);
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
if (JERRY_UNLIKELY (str_p == NULL))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
value = ecma_make_string_value (str_p);
|
||||
}
|
||||
/* 5.c */
|
||||
else if (class_name == LIT_MAGIC_STRING_BOOLEAN_UL)
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p;
|
||||
result = ext_object_p->u.class_prop.u.value;
|
||||
}
|
||||
|
||||
if (!ecma_is_value_empty (result))
|
||||
{
|
||||
value = ext_object_p->u.class_prop.u.value;
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
value = result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
23
tests/jerry/regression-test-issue-3813.js
Normal file
23
tests/jerry/regression-test-issue-3813.js
Normal file
@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
|
||||
var o = Object("str");
|
||||
o.toString = function() { throw "toString error" };
|
||||
|
||||
try {
|
||||
JSON.stringify(o);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e === "toString error");
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user