Skip to content

Commit 44b21de

Browse files
authored
Ensure that the constructed object in [[Set]] operation with primitive base cannot be extensible (jerryscript-project#2917)
Related part of the standard: https://www.ecma-international.org/ecma-262/5.1/#sec-8.7 1st note. This patch fixes jerryscript-project#2914. Co-authored-by: Gabor Loki loki@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
1 parent cbd41df commit 44b21de

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-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 /* ENABLED (JERRY_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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
var func2 = function (number) {
21+
"use strict";
22+
number.bar = "";
23+
};
24+
25+
try {
26+
func(-334918463);
27+
assert(false);
28+
} catch (e) {
29+
assert(e instanceof TypeError);
30+
}
31+
32+
try {
33+
Object.defineProperty(Number.prototype, "foo", { get : function() { throw ReferenceError("foo"); },
34+
set : function(a) { throw ReferenceError("bar"); },
35+
});
36+
func(-334918463);
37+
assert(false);
38+
} catch (e) {
39+
assert(e instanceof ReferenceError);
40+
assert(e.message === "bar");
41+
}
42+
43+
var setter_called = false;
44+
Object.defineProperty(Number.prototype, "bar", { get : function() { assert(false) },
45+
set : function(a) { setter_called = true; },
46+
});
47+
func2(-334918463);
48+
assert(setter_called === true);

0 commit comments

Comments
 (0)