From 71bac03d5133043a6bfd83c044333b897dc1ab95 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 29 Jun 2015 22:30:47 +0300 Subject: [PATCH] Fix construction of Arguments object: add handler for 'caller' property that throws TypeError upon read or write access. JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com --- .../ecma/operations/ecma-objects-arguments.cpp | 10 ++++++++-- tests/jerry/arguments.js | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/jerry-core/ecma/operations/ecma-objects-arguments.cpp b/jerry-core/ecma/operations/ecma-objects-arguments.cpp index 9fab7fc3b..5886499f9 100644 --- a/jerry-core/ecma/operations/ecma-objects-arguments.cpp +++ b/jerry-core/ecma/operations/ecma-objects-arguments.cpp @@ -268,16 +268,22 @@ ecma_op_create_arguments_object (ecma_object_t *func_obj_p, /**< callee function } ecma_string_t *callee_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_CALLEE); - ecma_string_t *caller_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_CALLER); completion = ecma_op_object_define_own_property (obj_p, callee_magic_string_p, &prop_desc, false); JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)); - ecma_deref_ecma_string (callee_magic_string_p); + + ecma_string_t *caller_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_CALLER); + completion = ecma_op_object_define_own_property (obj_p, + caller_magic_string_p, + &prop_desc, + false); + JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)); ecma_deref_ecma_string (caller_magic_string_p); + ecma_deref_object (thrower_p); } diff --git a/tests/jerry/arguments.js b/tests/jerry/arguments.js index 40189d08f..d1488f913 100644 --- a/tests/jerry/arguments.js +++ b/tests/jerry/arguments.js @@ -109,6 +109,19 @@ fn_expr = function (a, b, c) assert (arguments[0] === 'new value'); assert (arguments[1] === 'p'); assert (arguments[2] === 'q'); + + function check_type_error_for_property (obj, prop) { + try { + var v = obj[prop]; + assert (false); + } + catch (e) { + assert (e instanceof TypeError); + } + } + + check_type_error_for_property (arguments, 'caller'); + check_type_error_for_property (arguments, 'callee'); } fn_expr (1);