Skip to content

Commit 0d41169

Browse files
authored
Fix property descriptor queries (#3840)
When the getOwnPropertyDescriptor method was invoked the input property descriptor was not cleared in every case. This could lead to problems when the property descriptor is not set/modified by the getOwnPropertyDescriptor call, resulting in a failure at a later state. Related to this the Proxy getOwnPropertyDescriptor method incorrectly returned "undefined" value in a single case. JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
1 parent 252cfb0 commit 0d41169

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

jerry-core/ecma/operations/ecma-objects.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,8 @@ ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */
18581858
* [Enumerable], [Configurable]
18591859
* }.
18601860
*
1861+
* The output property descriptor will always be initialized to an empty descriptor.
1862+
*
18611863
* @return true - if property found
18621864
* false - otherwise
18631865
*/
@@ -1866,6 +1868,8 @@ ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, /**< the ob
18661868
ecma_string_t *property_name_p, /**< property name */
18671869
ecma_property_descriptor_t *prop_desc_p) /**< property descriptor */
18681870
{
1871+
*prop_desc_p = ecma_make_empty_property_descriptor ();
1872+
18691873
#if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
18701874
if (ECMA_OBJECT_IS_PROXY (object_p))
18711875
{
@@ -1885,8 +1889,6 @@ ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, /**< the ob
18851889
return ECMA_VALUE_FALSE;
18861890
}
18871891

1888-
*prop_desc_p = ecma_make_empty_property_descriptor ();
1889-
18901892
uint32_t flags = ecma_is_property_enumerable (property) ? ECMA_PROP_IS_ENUMERABLE : ECMA_PROP_NO_OPTS;
18911893
flags |= ecma_is_property_configurable (property) ? ECMA_PROP_IS_CONFIGURABLE: ECMA_PROP_NO_OPTS;
18921894

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ ecma_proxy_object_get_own_property_descriptor (ecma_object_t *obj_p, /**< proxy
735735
/* .a */
736736
if (ecma_is_value_false (target_status))
737737
{
738-
return ECMA_VALUE_UNDEFINED;
738+
return ECMA_VALUE_FALSE;
739739
}
740740
/* .b */
741741
if (!(target_desc.flags & ECMA_PROP_IS_CONFIGURABLE))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
function dummy ()
16+
{
17+
"D" + "a";
18+
}
19+
20+
var p1Handler = { getOwnPropertyDescriptor: dummy };
21+
var p1 = new Proxy({}, p1Handler);
22+
23+
function dummyString ()
24+
{
25+
return "a";
26+
}
27+
28+
var p2Handler = { deleteProperty: dummyString };
29+
var p2 = new Proxy(p1, p2Handler);
30+
31+
var result = (delete p2[1]);
32+
33+
assert (result);

0 commit comments

Comments
 (0)