Skip to content

Commit 71bac03

Browse files
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 [email protected]
1 parent ec02ace commit 71bac03

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

jerry-core/ecma/operations/ecma-objects-arguments.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,22 @@ ecma_op_create_arguments_object (ecma_object_t *func_obj_p, /**< callee function
268268
}
269269

270270
ecma_string_t *callee_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_CALLEE);
271-
ecma_string_t *caller_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_CALLER);
272271

273272
completion = ecma_op_object_define_own_property (obj_p,
274273
callee_magic_string_p,
275274
&prop_desc,
276275
false);
277276
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
278-
279277
ecma_deref_ecma_string (callee_magic_string_p);
278+
279+
ecma_string_t *caller_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_CALLER);
280+
completion = ecma_op_object_define_own_property (obj_p,
281+
caller_magic_string_p,
282+
&prop_desc,
283+
false);
284+
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
280285
ecma_deref_ecma_string (caller_magic_string_p);
286+
281287
ecma_deref_object (thrower_p);
282288
}
283289

tests/jerry/arguments.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ fn_expr = function (a, b, c)
109109
assert (arguments[0] === 'new value');
110110
assert (arguments[1] === 'p');
111111
assert (arguments[2] === 'q');
112+
113+
function check_type_error_for_property (obj, prop) {
114+
try {
115+
var v = obj[prop];
116+
assert (false);
117+
}
118+
catch (e) {
119+
assert (e instanceof TypeError);
120+
}
121+
}
122+
123+
check_type_error_for_property (arguments, 'caller');
124+
check_type_error_for_property (arguments, 'callee');
112125
}
113126

114127
fn_expr (1);

0 commit comments

Comments
 (0)