Skip to content

Commit cb192cd

Browse files
committed
Ensure that the constructed object in [[Set]] operation with primitive base cannot be extensible
Related part of the standard: https://www.ecma-international.org/ecma-262/5.1/#sec-8.7 1st note. This patch fixes #2914. Co-authored-by: Gabor Loki [email protected] JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 8ee8bc2 commit cb192cd

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

jerry-core/vm/vm.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ vm_op_set_value (ecma_value_t object, /**< base object */
144144
ecma_value_t value, /**< ecma value */
145145
bool is_strict) /**< strict mode */
146146
{
147+
ecma_object_t * object_p;
148+
147149
if (JERRY_UNLIKELY (!ecma_is_value_object (object)))
148150
{
149151
ecma_value_t to_object = ecma_op_to_object (object);
@@ -168,11 +170,15 @@ vm_op_set_value (ecma_value_t object, /**< base object */
168170
#endif /* JERRY_ENABLE_ERROR_MESSAGES */
169171
}
170172

171-
object = to_object;
173+
object_p = ecma_get_object_from_value (to_object);
174+
ecma_set_object_extensible (object_p, false);
175+
}
176+
else
177+
{
178+
object_p = ecma_get_object_from_value (object);
172179
}
173180

174181
ecma_string_t *property_p;
175-
ecma_object_t *object_p = ecma_get_object_from_value (object);
176182

177183
if (!ecma_is_value_prop_name (property))
178184
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 func = function (number) {
16+
"use strict";
17+
number.foo = "";
18+
};
19+
20+
try {
21+
func(-334918463);
22+
assert(false);
23+
} catch (e) {
24+
assert(e instanceof TypeError);
25+
}
26+
27+
try {
28+
Object.defineProperty(Number.prototype, "foo", { get : function() { throw ReferenceError("foo"); },
29+
set : function(a) { throw ReferenceError("bar"); },
30+
});
31+
func(-334918463);
32+
assert(false);
33+
} catch (e) {
34+
assert(e instanceof ReferenceError);
35+
assert(e.message === "bar");
36+
}

0 commit comments

Comments
 (0)