Skip to content

Commit fb1d2d3

Browse files
committed
Improvements for ecma_op_general_object_define_own_property.
List of improvements: - Get the [[Enumerable]] and [[Configurable]] attributes before removing a property. - Directly check the type of the property in asserts. Related issues: #115 and #132 JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
1 parent 5c012a1 commit fb1d2d3

File tree

3 files changed

+72
-8
lines changed

3 files changed

+72
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the objec
747747
return ecma_reject (is_throw);
748748
}
749749

750+
bool was_enumerable = ecma_is_property_enumerable (current_p);
751+
bool was_configurable = ecma_is_property_configurable (current_p);
752+
750753
ecma_delete_property (obj_p, current_p);
751754

752755
if (is_current_data_descriptor)
@@ -757,8 +760,8 @@ ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the objec
757760
property_name_p,
758761
NULL,
759762
NULL,
760-
ecma_is_property_enumerable (current_p),
761-
ecma_is_property_configurable (current_p));
763+
was_enumerable,
764+
was_configurable);
762765
}
763766
else
764767
{
@@ -767,8 +770,8 @@ ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the objec
767770
current_p = ecma_create_named_data_property (obj_p,
768771
property_name_p,
769772
false,
770-
ecma_is_property_enumerable (current_p),
771-
ecma_is_property_configurable (current_p));
773+
was_enumerable,
774+
was_configurable);
772775
}
773776
}
774777
else if (is_property_desc_data_descriptor && is_current_data_descriptor)
@@ -819,28 +822,28 @@ ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the objec
819822
// 12.
820823
if (property_desc_p->is_value_defined)
821824
{
822-
JERRY_ASSERT (is_current_data_descriptor);
825+
JERRY_ASSERT (current_p->type == ECMA_PROPERTY_NAMEDDATA);
823826

824827
ecma_named_data_property_assign_value (obj_p, current_p, property_desc_p->value);
825828
}
826829

827830
if (property_desc_p->is_writable_defined)
828831
{
829-
JERRY_ASSERT (is_current_data_descriptor);
832+
JERRY_ASSERT (current_p->type == ECMA_PROPERTY_NAMEDDATA);
830833

831834
ecma_set_property_writable_attr (current_p, property_desc_p->is_writable);
832835
}
833836

834837
if (property_desc_p->is_get_defined)
835838
{
836-
JERRY_ASSERT (is_current_accessor_descriptor);
839+
JERRY_ASSERT (current_p->type == ECMA_PROPERTY_NAMEDACCESSOR);
837840

838841
ecma_set_named_accessor_property_getter (obj_p, current_p, property_desc_p->get_p);
839842
}
840843

841844
if (property_desc_p->is_set_defined)
842845
{
843-
JERRY_ASSERT (is_current_accessor_descriptor);
846+
JERRY_ASSERT (current_p->type == ECMA_PROPERTY_NAMEDACCESSOR);
844847

845848
ecma_set_named_accessor_property_setter (obj_p, current_p, property_desc_p->set_p);
846849
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 Samsung Electronics Co., Ltd.
2+
// Copyright 2015 University of Szeged.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
var v_1 = [,];
17+
Object.defineProperty(v_1, "0", {
18+
set: function() {},
19+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2015 Samsung Electronics Co., Ltd.
2+
// Copyright 2015 University of Szeged.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
// Test raised by fuzzer
17+
v_0 = [,];
18+
v_1 = [,];
19+
v_2 = Object.defineProperties([,], { '0': { get: function() { } } });
20+
21+
// Test change from data to accessor type
22+
var a = { x:2 };
23+
Object.defineProperty(a, "x", {
24+
enumerable: true,
25+
configurable: true,
26+
get: function() { return 0; }
27+
});
28+
29+
// Test change from accessor to data type
30+
var obj = {test: 2};
31+
32+
Object.defineProperty(obj, "test", {
33+
enumerable: true,
34+
configurable: true,
35+
get: function() { return 0; }
36+
});
37+
38+
Object.defineProperty(obj, "x", {
39+
enumerable: true,
40+
configurable: true,
41+
value: -2
42+
});

0 commit comments

Comments
 (0)