Skip to content

Commit 5a0dd78

Browse files
committed
Merged: [const-tracking] Ensure map is updated before generalizing constness
Revision: db2acd7 BUG=chromium:1195331 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true [email protected] Change-Id: I7ce1b36b8860a49838d208bc7857021e03f83916 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2831474 Reviewed-by: Leszek Swirski <[email protected]> Cr-Commit-Position: refs/branch-heads/9.0@{v8#37} Cr-Branched-From: bd0108b-refs/heads/9.0.257@{#1} Cr-Branched-From: 349bcc6-refs/heads/master@{#73001}
1 parent c87b3c1 commit 5a0dd78

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

src/objects/map-updater.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,20 @@ Handle<Map> MapUpdater::ReconfigureToDataField(InternalIndex descriptor,
139139
if (old_details.constness() == PropertyConstness::kConst &&
140140
old_details.location() == kField &&
141141
old_details.attributes() != new_attributes_) {
142+
// Ensure we'll be updating constness of the up-to-date version of old_map_.
143+
Handle<Map> old_map = Map::Update(isolate_, old_map_);
144+
PropertyDetails details =
145+
old_map->instance_descriptors(kRelaxedLoad).GetDetails(descriptor);
142146
Handle<FieldType> field_type(
143-
old_descriptors_->GetFieldType(modified_descriptor_), isolate_);
144-
Map::GeneralizeField(isolate_, old_map_, descriptor,
145-
PropertyConstness::kMutable,
146-
old_details.representation(), field_type);
147+
old_map->instance_descriptors(kRelaxedLoad).GetFieldType(descriptor),
148+
isolate_);
149+
Map::GeneralizeField(isolate_, old_map, descriptor,
150+
PropertyConstness::kMutable, details.representation(),
151+
field_type);
152+
DCHECK_EQ(PropertyConstness::kMutable,
153+
old_map->instance_descriptors(kRelaxedLoad)
154+
.GetDetails(descriptor)
155+
.constness());
147156
// The old_map_'s property must become mutable.
148157
// Note, that the {old_map_} and {old_descriptors_} are not expected to be
149158
// updated by the generalization if the map is already deprecated.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2021 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --allow-natives-syntax
6+
7+
let o1 = { a: 1, b: 0 };
8+
let o2 = { a: 2, b: 0 };
9+
assertTrue(%HaveSameMap(o1, o2));
10+
assertTrue(%HasOwnConstDataProperty(o1, "a"));
11+
assertTrue(%HasOwnConstDataProperty(o1, "b"));
12+
13+
Object.defineProperty(o1, "b", {
14+
value: 4.2, enumerable: true, configurable: true, writable: true,
15+
});
16+
assertFalse(%HaveSameMap(o1, o2));
17+
assertTrue(%HasOwnConstDataProperty(o1, "a"));
18+
assertFalse(%HasOwnConstDataProperty(o1, "b"));
19+
assertTrue(%HasOwnConstDataProperty(o2, "a"));
20+
assertTrue(%HasOwnConstDataProperty(o2, "b"));
21+
22+
let o3 = { a: "foo", b: 0 };
23+
assertFalse(%HaveSameMap(o2, o3));
24+
assertTrue(%HasOwnConstDataProperty(o3, "a"));
25+
assertFalse(%HasOwnConstDataProperty(o3, "b"));
26+
27+
Object.defineProperty(o2, "a", {
28+
value:2, enumerable: false, configurable: true, writable: true,
29+
});
30+
assertFalse(%HasOwnConstDataProperty(o1, "a"));
31+
assertFalse(%HasOwnConstDataProperty(o1, "b"));
32+
assertFalse(%HasOwnConstDataProperty(o3, "a"));
33+
assertFalse(%HasOwnConstDataProperty(o3, "b"));
34+
35+
assertFalse(%HasOwnConstDataProperty(o2, "a"));
36+
assertTrue(%HasOwnConstDataProperty(o2, "b"));

0 commit comments

Comments
 (0)