Skip to content

Commit af91072

Browse files
rerobikarobertsipka
authored andcommitted
Ensure that ecma_builtin_json_str_helper uses [[DefineOwnProperty]] internal method (#2665)
This patch fixes #2652 and fixes #2653 as well, also reverts #2521. Related part of the standard ECMAScript v5.1 15.12.3.10. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
1 parent 1f204de commit af91072

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-json.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -915,19 +915,15 @@ static ecma_value_t ecma_builtin_json_str_helper (const ecma_value_t arg1, /**<
915915
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
916916
ecma_object_t *obj_wrapper_p = ecma_op_create_object_object_noarg ();
917917
ecma_string_t *empty_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
918-
ecma_value_t put_comp_val = ecma_op_object_put (obj_wrapper_p,
919-
empty_str_p,
920-
arg1,
921-
false);
918+
ecma_value_t put_comp_val = ecma_builtin_helper_def_prop (obj_wrapper_p,
919+
empty_str_p,
920+
arg1,
921+
ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE,
922+
false);
922923

923-
if (ecma_is_value_true (put_comp_val))
924-
{
925-
ret_value = ecma_builtin_json_str (empty_str_p, obj_wrapper_p, &context);
926-
}
927-
else
928-
{
929-
ret_value = ECMA_VALUE_UNDEFINED;
930-
}
924+
JERRY_ASSERT (ecma_is_value_true (put_comp_val));
925+
926+
ret_value = ecma_builtin_json_str (empty_str_p, obj_wrapper_p, &context);
931927

932928
ecma_free_value (put_comp_val);
933929
ecma_deref_ecma_string (empty_str_p);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
Object.defineProperty (Object.prototype, "", { 'set' : function () { throw ReferenceError ("") } });
16+
assert (JSON.stringify () === undefined);
17+
print (JSON.stringify ());

0 commit comments

Comments
 (0)