Skip to content

Commit 3c5fb34

Browse files
authored
Update "arguments" and "caller" properties of function object to conform ES6 changes (#3530)
This patch resolves #3393. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent b7a2a15 commit 3c5fb34

9 files changed

+98
-4
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ ROUTINE (LIT_MAGIC_STRING_BIND, ECMA_FUNCTION_PROTOTYPE_BIND, NON_FIXED, 1)
4848
* the property attributes are: { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
4949
*/
5050
ROUTINE_WITH_FLAGS (LIT_GLOBAL_SYMBOL_HAS_INSTANCE, ECMA_FUNCTION_PROTOTYPE_SYMBOL_HAS_INSTANCE, 1, 1, 0 /* flags */)
51+
ACCESSOR_BUILTIN_FUNCTION (LIT_MAGIC_STRING_ARGUMENTS,
52+
ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
53+
ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
54+
ECMA_PROPERTY_FLAG_CONFIGURABLE)
55+
ACCESSOR_BUILTIN_FUNCTION (LIT_MAGIC_STRING_CALLER,
56+
ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
57+
ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
58+
ECMA_PROPERTY_FLAG_CONFIGURABLE)
5159
#endif /* ENABLED (JERRY_ES2015) */
5260

5361
#include "ecma-builtin-helpers-macro-undefs.inc.h"

jerry-core/ecma/builtin-objects/ecma-builtin-helpers-macro-defines.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#ifndef INTRINSIC_PROPERTY
3434
#define INTRINSIC_PROPERTY(name, magic_string_id)
3535
#endif /* !INTRINSIC_PROPERTY */
36+
37+
#ifndef ACCESSOR_BUILTIN_FUNCTION_OBJECT
38+
#define ACCESSOR_BUILTIN_FUNCTION_OBJECT(name, getter_builtin_id, setter_builtin_id, prop_attributes)
39+
#endif /* !ACCESSOR_BUILTIN_FUNCTION_OBJECT */
3640
#endif /* ENABLED (JERRY_ES2015) */
3741

3842
#ifndef OBJECT_VALUE

jerry-core/ecma/builtin-objects/ecma-builtin-helpers-macro-undefs.inc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#if ENABLED (JERRY_ES2015)
2020
#undef SYMBOL_VALUE
2121
#undef INTRINSIC_PROPERTY
22+
#undef ACCESSOR_BUILTIN_FUNCTION_OBJECT
2223
#endif /* ENABLED (JERRY_ES2015) */
2324
#undef OBJECT_VALUE
2425
#undef ROUTINE

jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
189189
ECMA_PROPERTY_CONFIGURABLE_WRITABLE, \
190190
magic_string_id \
191191
},
192+
#define ACCESSOR_BUILTIN_FUNCTION(name, getter_builtin_id, setter_builtin_id, prop_attributes) \
193+
{ \
194+
name, \
195+
ECMA_BUILTIN_PROPERTY_ACCESSOR_BUILTIN_FUNCTION, \
196+
prop_attributes, \
197+
ECMA_ACCESSOR_READ_WRITE (getter_builtin_id, setter_builtin_id) \
198+
},
192199
#endif /* ENABLED (JERRY_ES2015) */
193200
#define ACCESSOR_READ_WRITE(name, c_getter_name, c_setter_name, prop_attributes) \
194201
{ \

jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ ecma_builtin_type_error_thrower_dispatch_call (const ecma_value_t *arguments_lis
5555
{
5656
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
5757

58-
/* The object should throw TypeError */
59-
return ecma_raise_type_error (ECMA_ERR_MSG (""));
58+
return ecma_raise_type_error (ECMA_ERR_MSG ("'caller', 'callee', and 'arguments' properties may not be accessed"
59+
" on strict mode functions or the arguments objects for calls to them"));
6060
} /* ecma_builtin_type_error_thrower_dispatch_call */
6161

6262
/**
@@ -73,8 +73,7 @@ ecma_builtin_type_error_thrower_dispatch_construct (const ecma_value_t *argument
7373
{
7474
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
7575

76-
/* The object is not a constructor */
77-
return ecma_raise_type_error (ECMA_ERR_MSG (""));
76+
return ecma_builtin_type_error_thrower_dispatch_call (arguments_list_p, arguments_list_len);
7877
} /* ecma_builtin_type_error_thrower_dispatch_construct */
7978

8079
/**

jerry-core/ecma/builtin-objects/ecma-builtins-internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ typedef enum
3434
#if ENABLED (JERRY_ES2015)
3535
ECMA_BUILTIN_PROPERTY_SYMBOL, /**< symbol value property */
3636
ECMA_BUILTIN_PROPERTY_INTRINSIC_PROPERTY, /**< intrinsic routine property */
37+
ECMA_BUILTIN_PROPERTY_ACCESSOR_BUILTIN_FUNCTION, /**< full accessor property with builtin function object
38+
getter/setter pair */
3739
#endif /* ENABLED (JERRY_ES2015) */
3840
ECMA_BUILTIN_PROPERTY_OBJECT, /**< builtin object property */
3941
ECMA_BUILTIN_PROPERTY_ROUTINE, /**< routine property */

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,17 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object *
814814
(lit_magic_string_id_t) curr_property_p->value);
815815
break;
816816
}
817+
case ECMA_BUILTIN_PROPERTY_ACCESSOR_BUILTIN_FUNCTION:
818+
{
819+
is_accessor = true;
820+
uint16_t getter_id = ECMA_ACCESSOR_READ_WRITE_GET_GETTER_ID (curr_property_p->value);
821+
uint16_t setter_id = ECMA_ACCESSOR_READ_WRITE_GET_SETTER_ID (curr_property_p->value);
822+
getter_p = ecma_builtin_get (getter_id);
823+
setter_p = ecma_builtin_get (setter_id);
824+
ecma_ref_object (getter_p);
825+
ecma_ref_object (setter_p);
826+
break;
827+
}
817828
#endif /* ENABLED (JERRY_ES2015) */
818829
case ECMA_BUILTIN_PROPERTY_OBJECT:
819830
{

jerry-core/ecma/operations/ecma-function-object.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,19 @@ ecma_op_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**<
16431643
}
16441644
#endif /* ENABLED (JERRY_ES2015) */
16451645

1646+
#if ENABLED (JERRY_ES2015)
1647+
if (!(bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE))
1648+
{
1649+
ecma_property_t *value_prop_p;
1650+
/* The property_name_p argument contans the name. */
1651+
ecma_property_value_t *value_p = ecma_create_named_data_property (object_p,
1652+
property_name_p,
1653+
ECMA_PROPERTY_FIXED,
1654+
&value_prop_p);
1655+
value_p->value = ECMA_VALUE_NULL;
1656+
return value_prop_p;
1657+
}
1658+
#else /* !ENABLED (JERRY_ES2015) */
16461659
if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE)
16471660
{
16481661
ecma_object_t *thrower_p = ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER);
@@ -1657,6 +1670,8 @@ ecma_op_function_try_to_lazy_instantiate_property (ecma_object_t *object_p, /**<
16571670
&caller_prop_p);
16581671
return caller_prop_p;
16591672
}
1673+
#endif /* ENABLED (JERRY_ES2015) */
1674+
16601675
}
16611676

16621677
return NULL;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
var props = ['arguments', 'caller'];
16+
17+
function f_simple () {
18+
}
19+
20+
function f_strict () {
21+
"use strict";
22+
}
23+
24+
for (let prop of props) {
25+
try {
26+
Function.prototype[prop];
27+
assert(false);
28+
} catch (e) {
29+
assert(e instanceof TypeError);
30+
}
31+
32+
assert(f_simple[prop] === null);
33+
34+
try {
35+
f_strict[prop];
36+
assert(false);
37+
} catch (e) {
38+
assert(e instanceof TypeError);
39+
}
40+
41+
let desc = Object.getOwnPropertyDescriptor(f_simple, prop);
42+
assert(desc.value === null);
43+
assert(desc.writable === false);
44+
assert(desc.enumerable === false);
45+
assert(desc.configurable === false);
46+
assert(Object.getOwnPropertyDescriptor(f_strict, prop) === undefined);
47+
}

0 commit comments

Comments
 (0)