Skip to content

Commit a3c8dbf

Browse files
committed
[JSC] Avoid accessing missing indexing headers in Butterfly helpers.
https://bugs.webkit.org/show_bug.cgi?id=324343 Reviewed by Yusuke Suzuki. An object whose properties all have names, and which has no indexed elements, keeps them in a butterfly with no IndexingHeader, since that header only describes indexed elements. Butterfly::indexingHeader() hands back a pointer to one regardless, by subtracting a slot from the butterfly pointer. It cannot do better, because it never sees the Structure and so has no way to know whether a header is there; on a headerless butterfly the address it returns lands just past the end of the allocation. preCapacity() and indexingPayloadSizeInBytes() were reached through it. Both consult the indexing type and answer zero when nothing is indexed, so they look safe, but that check ran too late: calling them meant deriving the header pointer first and passing it as the object they operate on. Inside a non-static member function the language guarantees that the "this" object is really there, so a compiler need not prove that reading its fields is safe; the call itself is the proof. GCC uses that, from version 13: it speculatively dereferences the header pointer before the check has run, so the check still answers zero but too late to prevent the read. On a headerless butterfly that read comes from an address outside the butterfly's allocation which crashes when unmapped. For more details see the analysis at gcc.gnu.org/PR127434 which was filed there first as a compiler bug. Whether that read crashes depends on what follows the butterfly in memory. WPE 2.52 crashed on 32-bit ARM while growing named property storage because bmalloc, which it used there, can end a heap block right before an unmapped page. Main does not reproduce it, since libpas, mimalloc and the system malloc all keep mapped memory after a heap block, so the read succeeds and its value is discarded; nothing uses that value unless the indexing type says a header exists, so a successful read is harmless. However, the read is still in the code main compiles. I verified this by preloading 2.52 bmalloc into a main build and that brings the crash back on 32-bit ARM, in the same place. Since the pointer is formed before the check can run, no guard inside those functions can help. Move both queries to Butterfly, which is what they describe: they answer how large this butterfly indexed payload is and how much room sits before its property storage, they feed Butterfly::totalSize(), and Butterfly already hosts this kind of structure-aware layout query next to base(Structure*). They consult the Structure first and only derive a header in the branches whose indexing type guarantees one. IndexingHeader is then left with no function that takes a Structure, which is the rule worth keeping: needing a Structure to answer means having to cope with there being no header, so the header cannot be the object the function is called on. VMInspector and ObjectInitializationScope read header fields before deciding one existed, so they are fixed in a similar way. The new test adds named properties to objects until their storage has to grow, and runs with --libpasForcePGMWithRate=1, which puts an inaccessible page after every allocation so the early read faults instead of landing in readable heap bytes. Before this patch, a build of main with GCC at -O2 crashes always, while Clang 22 passes because it leaves the read inside the guard. So the test only catches this when the compiler speculatively moves the read. It is worth running everywhere regardless, because the mistake is in our code rather than in the compiler, and a newer Clang version could start moving the read too. * JSTests/stress/butterfly-headerless-property-growth.js: Added. * Source/JavaScriptCore/CMakeLists.txt: * Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj: * Source/JavaScriptCore/runtime/Butterfly.h: (JSC::Butterfly::propertyStorage): (JSC::Butterfly::propertyStorage const): (JSC::Butterfly::indexOfPropertyStorage): * Source/JavaScriptCore/runtime/ButterflyInlines.h: (JSC::Butterfly::preCapacity): (JSC::Butterfly::indexingPayloadSizeInBytes): (JSC::Butterfly::base): (JSC::Butterfly::createOrGrowPropertyStorage): (JSC::Butterfly::growArrayRight): (JSC::Butterfly::reallocArrayRightIfPossible): (JSC::Butterfly::resizeArray): (JSC::Butterfly::unshift): * Source/JavaScriptCore/runtime/IndexingHeader.h: * Source/JavaScriptCore/runtime/IndexingHeaderInlines.h: Removed. * Source/JavaScriptCore/runtime/JSObject.cpp: (JSC::JSObjectWithButterfly::markAuxiliaryAndVisitOutOfLineProperties): (JSC::JSObject::reallocateAndShrinkButterfly): (JSC::JSObject::shiftButterflyAfterFlattening): * Source/JavaScriptCore/runtime/JSObject.h: (JSC::JSObject::butterflyPreCapacity): (JSC::JSObject::butterflyTotalSize): * Source/JavaScriptCore/runtime/ObjectInitializationScope.cpp: (JSC::ObjectInitializationScope::verifyPropertiesAreInitialized): * Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp: (JSC::createRegExpMatchesArrayWithGroupsOrIndices): (JSC::createRegExpMatchesArrayForPlainRegExpHavingABadTime): * Source/JavaScriptCore/runtime/RegExpMatchesArray.h: (JSC::createRegExpMatchesArrayForPlainRegExp): * Source/JavaScriptCore/runtime/Structure.cpp: (JSC::Structure::flattenDictionaryStructure): * Source/JavaScriptCore/tools/VMInspector.cpp: (JSC::VMInspector::dumpCellMemoryToStream): * Source/WebCore/WebCorePrefix.h: * Source/WebKit/WebKitPrefix.h: Canonical link: https://commits.webkit.org/324229@main
1 parent f2d83dd commit a3c8dbf

16 files changed

Lines changed: 100 additions & 102 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//@ runDefault("--libpasForcePGMWithRate=1")
2+
3+
// An object with only named properties has no IndexingHeader in its butterfly, since that header
4+
// only describes indexed elements. This test checks that the address returned by indexingHeader()
5+
// in that case is never read, because it lies past the end of the butterfly's allocation, so
6+
// reading it is invalid and can crash.
7+
//
8+
// Usually such a read would go unnoticed, because the memory after a butterfly is normally mapped.
9+
// --libpasForcePGMWithRate=1 puts an inaccessible page after every allocation, forcing a crash.
10+
//
11+
// This is a regression test for webkit.org/b/324343 which crashed on builds done with GCC 13 or
12+
// newer at -O2. It is worth running everywhere regardless, because the error was in our code
13+
// rather than in the compiler, and newer Clang versions could be affected.
14+
//
15+
// It does not use testLoopCount, because what reproduces the bug is the shape of the heap, not
16+
// how often a loop runs. 48 properties grow the storage through capacities 4, 8, 16, 32 and 64,
17+
// reallocating at each step. The object count matters too: without the fix 54 objects never crash
18+
// and 55 always do, so 150 leaves a wide margin and still runs in ten milliseconds.
19+
20+
const objectCount = 150;
21+
const propertiesPerObject = 48;
22+
23+
const objects = [];
24+
for (let objectIndex = 0; objectIndex < objectCount; ++objectIndex) {
25+
const object = {};
26+
for (let propertyIndex = 0; propertyIndex < propertiesPerObject; ++propertyIndex)
27+
object["p" + propertyIndex] = objectIndex * 1000 + propertyIndex;
28+
objects.push(object);
29+
}
30+
31+
for (let objectIndex = 0; objectIndex < objectCount; ++objectIndex) {
32+
for (let propertyIndex = 0; propertyIndex < propertiesPerObject; ++propertyIndex) {
33+
const expected = objectIndex * 1000 + propertyIndex;
34+
const actual = objects[objectIndex]["p" + propertyIndex];
35+
if (actual !== expected)
36+
throw new Error(`object ${objectIndex} property p${propertyIndex}: expected ${expected}, got ${actual}`);
37+
}
38+
}

‎Source/JavaScriptCore/CMakeLists.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,6 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
11851185
runtime/ImplementationVisibility.h
11861186
runtime/ImportMap.h
11871187
runtime/IndexingHeader.h
1188-
runtime/IndexingHeaderInlines.h
11891188
runtime/IndexingType.h
11901189
runtime/IndexingTypeInlines.h
11911190
runtime/IndirectEvalExecutable.h

‎Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@
495495
0FB7F39715ED8E4600F167B2 /* Butterfly.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB7F38B15ED8E3800F167B2 /* Butterfly.h */; settings = {ATTRIBUTES = (Private, ); }; };
496496
0FB7F39815ED8E4600F167B2 /* ButterflyInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB7F38C15ED8E3800F167B2 /* ButterflyInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
497497
0FB7F39915ED8E4600F167B2 /* IndexingHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB7F38D15ED8E3800F167B2 /* IndexingHeader.h */; settings = {ATTRIBUTES = (Private, ); }; };
498-
0FB7F39A15ED8E4600F167B2 /* IndexingHeaderInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB7F38E15ED8E3800F167B2 /* IndexingHeaderInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
499498
A16A70A2A71A40468FFB3BC9 /* IndexingTypeInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 9397766836314A2A884F602C /* IndexingTypeInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
500499
0FB7F39B15ED8E4600F167B2 /* IndexingType.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB7F38F15ED8E3800F167B2 /* IndexingType.h */; settings = {ATTRIBUTES = (Private, ); }; };
501500
0FB7F39C15ED8E4600F167B2 /* PropertyStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB7F39015ED8E3800F167B2 /* PropertyStorage.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -3635,7 +3634,6 @@
36353634
0FB7F38B15ED8E3800F167B2 /* Butterfly.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Butterfly.h; sourceTree = "<group>"; };
36363635
0FB7F38C15ED8E3800F167B2 /* ButterflyInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ButterflyInlines.h; sourceTree = "<group>"; };
36373636
0FB7F38D15ED8E3800F167B2 /* IndexingHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexingHeader.h; sourceTree = "<group>"; };
3638-
0FB7F38E15ED8E3800F167B2 /* IndexingHeaderInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexingHeaderInlines.h; sourceTree = "<group>"; };
36393637
9397766836314A2A884F602C /* IndexingTypeInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexingTypeInlines.h; sourceTree = "<group>"; };
36403638
0FB7F38F15ED8E3800F167B2 /* IndexingType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexingType.h; sourceTree = "<group>"; };
36413639
0FB7F39015ED8E3800F167B2 /* PropertyStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PropertyStorage.h; sourceTree = "<group>"; };
@@ -9137,7 +9135,6 @@
91379135
E3285D8E28DD8317008E0090 /* ImportMap.cpp */,
91389136
E3CDCFAE28DD065A00215350 /* ImportMap.h */,
91399137
0FB7F38D15ED8E3800F167B2 /* IndexingHeader.h */,
9140-
0FB7F38E15ED8E3800F167B2 /* IndexingHeaderInlines.h */,
91419138
0F13E04C16164A1B00DC8DE7 /* IndexingType.cpp */,
91429139
0FB7F38F15ED8E3800F167B2 /* IndexingType.h */,
91439140
9397766836314A2A884F602C /* IndexingTypeInlines.h */,
@@ -12161,7 +12158,6 @@
1216112158
A382C5312667111D0042CD99 /* InByVariant.h in Headers */,
1216212159
C25F8BCE157544A900245B71 /* IncrementalSweeper.h in Headers */,
1216312160
0FB7F39915ED8E4600F167B2 /* IndexingHeader.h in Headers */,
12164-
0FB7F39A15ED8E4600F167B2 /* IndexingHeaderInlines.h in Headers */,
1216512161
0FB7F39B15ED8E4600F167B2 /* IndexingType.h in Headers */,
1216612162
A16A70A2A71A40468FFB3BC9 /* IndexingTypeInlines.h in Headers */,
1216712163
14386A791DD6989C008652C4 /* IndirectEvalExecutable.h in Headers */,

‎Source/JavaScriptCore/runtime/Butterfly.h‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,16 @@ class Butterfly {
178178
static Butterfly* create(VM&, JSObject* intendedOwner, size_t preCapacity, size_t propertyCapacity, bool hasIndexingHeader, const IndexingHeader&, size_t indexingPayloadSizeInBytes);
179179
static Butterfly* create(VM&, JSObject* intendedOwner, Structure*);
180180

181+
// Don't use the returned IndexingHeader on a butterfly that has none, as with an object with no indexed elements: in that case
182+
// the returned address is past the end of the allocation. indexingHeader() can't check that, because it never sees the Structure.
181183
IndexingHeader* indexingHeader() { return IndexingHeader::from(this); }
182184
const IndexingHeader* indexingHeader() const { return IndexingHeader::from(this); }
183-
PropertyStorage propertyStorage() { return indexingHeader()->propertyStorage(); }
184-
ConstPropertyStorage propertyStorage() const { return indexingHeader()->propertyStorage(); }
185+
186+
size_t preCapacity(Structure*);
187+
size_t indexingPayloadSizeInBytes(Structure*);
188+
189+
PropertyStorage propertyStorage() { return reinterpret_cast_ptr<PropertyStorage>(this) + indexOfPropertyStorage(); }
190+
ConstPropertyStorage propertyStorage() const { return reinterpret_cast_ptr<ConstPropertyStorage>(this) + indexOfPropertyStorage(); }
185191

186192
uint32_t publicLength() const { return indexingHeader()->publicLength(); }
187193
uint32_t vectorLength() const { return indexingHeader()->vectorLength(); }
@@ -214,7 +220,8 @@ class Butterfly {
214220
static constexpr ptrdiff_t offsetOfPropertyStorage() { return -static_cast<ptrdiff_t>(sizeof(IndexingHeader)); }
215221
constexpr static int indexOfPropertyStorage()
216222
{
217-
ASSERT(sizeof(IndexingHeader) == sizeof(EncodedJSValue));
223+
static_assert(sizeof(IndexingHeader) == sizeof(EncodedJSValue));
224+
static_assert(sizeof(WriteBarrierBase<Unknown>) == sizeof(IndexingHeader));
218225
return -1;
219226
}
220227

‎Source/JavaScriptCore/runtime/ButterflyInlines.h‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,32 @@ inline size_t LEGACY_NODELETE nextLength(size_t length)
4343
return length + length / 2;
4444
}
4545

46+
inline size_t Butterfly::preCapacity(Structure* structure)
47+
{
48+
if (!hasAnyArrayStorage(structure->indexingType())) [[likely]]
49+
return 0;
50+
51+
return IndexingHeader::from(this)->arrayStorage()->m_indexBias;
52+
}
53+
54+
inline size_t Butterfly::indexingPayloadSizeInBytes(Structure* structure)
55+
{
56+
switch (structure->indexingType()) {
57+
case ALL_UNDECIDED_INDEXING_TYPES:
58+
case ALL_INT32_INDEXING_TYPES:
59+
case ALL_DOUBLE_INDEXING_TYPES:
60+
case ALL_CONTIGUOUS_INDEXING_TYPES:
61+
return IndexingHeader::from(this)->vectorLength() * sizeof(EncodedJSValue);
62+
63+
case ALL_ARRAY_STORAGE_INDEXING_TYPES:
64+
return ArrayStorage::sizeFor(IndexingHeader::from(this)->arrayStorage()->vectorLength());
65+
66+
default:
67+
ASSERT(!hasIndexedProperties(structure->indexingType()));
68+
return 0;
69+
}
70+
}
71+
4672
ALWAYS_INLINE unsigned Butterfly::availableContiguousVectorLength(size_t propertyCapacity, unsigned vectorLength)
4773
{
4874
size_t cellSize = totalSize(0, propertyCapacity, true, sizeof(EncodedJSValue) * vectorLength);
@@ -123,7 +149,7 @@ inline Butterfly* Butterfly::create(VM& vm, JSObject* intendedOwner, Structure*
123149

124150
inline void* Butterfly::base(Structure* structure)
125151
{
126-
return base(indexingHeader()->preCapacity(structure), structure->outOfLineCapacity());
152+
return base(preCapacity(structure), structure->outOfLineCapacity());
127153
}
128154

129155
inline Butterfly* Butterfly::createOrGrowPropertyStorage(
@@ -133,8 +159,8 @@ inline Butterfly* Butterfly::createOrGrowPropertyStorage(
133159
if (!oldButterfly)
134160
return create(vm, intendedOwner, 0, newPropertyCapacity, false, IndexingHeader(), 0);
135161

136-
size_t preCapacity = oldButterfly->indexingHeader()->preCapacity(structure);
137-
size_t indexingPayloadSizeInBytes = oldButterfly->indexingHeader()->indexingPayloadSizeInBytes(structure);
162+
size_t preCapacity = oldButterfly->preCapacity(structure);
163+
size_t indexingPayloadSizeInBytes = oldButterfly->indexingPayloadSizeInBytes(structure);
138164
bool hasIndexingHeader = structure->hasIndexingHeader(intendedOwner);
139165
Butterfly* result = createUninitialized(vm, intendedOwner, preCapacity, newPropertyCapacity, hasIndexingHeader, indexingPayloadSizeInBytes);
140166
// Use memcpy since this butterfly is not tied to any object yet.
@@ -166,7 +192,7 @@ inline Butterfly* Butterfly::growArrayRight(
166192
bool hadIndexingHeader, size_t oldIndexingPayloadSizeInBytes,
167193
size_t newIndexingPayloadSizeInBytes)
168194
{
169-
ASSERT_UNUSED(oldStructure, !indexingHeader()->preCapacity(oldStructure));
195+
ASSERT_UNUSED(oldStructure, !preCapacity(oldStructure));
170196
ASSERT_UNUSED(intendedOwner, hadIndexingHeader == oldStructure->hasIndexingHeader(intendedOwner));
171197
void* theBase = base(0, propertyCapacity);
172198
size_t oldSize = totalSize(0, propertyCapacity, hadIndexingHeader, oldIndexingPayloadSizeInBytes);
@@ -186,7 +212,7 @@ inline Butterfly* Butterfly::growArrayRight(
186212
return growArrayRight(
187213
vm, intendedOwner, oldStructure, oldStructure->outOfLineCapacity(),
188214
oldStructure->hasIndexingHeader(intendedOwner),
189-
indexingHeader()->indexingPayloadSizeInBytes(oldStructure),
215+
indexingPayloadSizeInBytes(oldStructure),
190216
newIndexingPayloadSizeInBytes);
191217
}
192218

@@ -195,7 +221,7 @@ inline Butterfly* Butterfly::reallocArrayRightIfPossible(
195221
bool hadIndexingHeader, size_t oldIndexingPayloadSizeInBytes,
196222
size_t newIndexingPayloadSizeInBytes)
197223
{
198-
ASSERT_UNUSED(oldStructure, !indexingHeader()->preCapacity(oldStructure));
224+
ASSERT_UNUSED(oldStructure, !preCapacity(oldStructure));
199225
ASSERT_UNUSED(intendedOwner, hadIndexingHeader == oldStructure->hasIndexingHeader(intendedOwner));
200226

201227
void* theBase = base(0, propertyCapacity);
@@ -247,14 +273,14 @@ inline Butterfly* Butterfly::resizeArray(
247273
bool hasIndexingHeader = structure->hasIndexingHeader(intendedOwner);
248274
return resizeArray(
249275
vm, intendedOwner, structure->outOfLineCapacity(), hasIndexingHeader,
250-
indexingHeader()->indexingPayloadSizeInBytes(structure), newPreCapacity,
276+
indexingPayloadSizeInBytes(structure), newPreCapacity,
251277
hasIndexingHeader, newIndexingPayloadSizeInBytes);
252278
}
253279

254280
inline Butterfly* Butterfly::unshift(Structure* structure, size_t numberOfSlots)
255281
{
256282
ASSERT(hasAnyArrayStorage(structure->indexingType()));
257-
ASSERT(numberOfSlots <= indexingHeader()->preCapacity(structure));
283+
ASSERT(numberOfSlots <= preCapacity(structure));
258284
unsigned propertyCapacity = structure->outOfLineCapacity();
259285
// FIXME: It would probably be wise to rewrite this as a loop since (1) we know in which
260286
// direction we're moving memory so we don't need the extra check of memmove and (2) we're

‎Source/JavaScriptCore/runtime/IndexingHeader.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ class IndexingHeader {
114114
return reinterpret_cast<Butterfly*>(this + 1);
115115
}
116116

117-
// These methods are not standalone in the sense that they cannot be
118-
// used on a copy of the IndexingHeader.
119-
size_t preCapacity(Structure*);
120-
size_t indexingPayloadSizeInBytes(Structure*);
121-
122117
private:
123118
friend class LLIntOffsetsExtractor;
124119

‎Source/JavaScriptCore/runtime/IndexingHeaderInlines.h‎

Lines changed: 0 additions & 60 deletions
This file was deleted.

‎Source/JavaScriptCore/runtime/JSObject.cpp‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "GCDeferralContextInlines.h"
3333
#include "GetterSetter.h"
3434
#include "HeapAnalyzer.h"
35-
#include "IndexingHeaderInlines.h"
3635
#include "JSCInlines.h"
3736
#include "IndexingTypeInlines.h"
3837
#include "JSCellButterfly.h"
@@ -99,7 +98,7 @@ ALWAYS_INLINE void JSObjectWithButterfly::markAuxiliaryAndVisitOutOfLineProperti
9998
bool hasIndexingHeader = structure->hasIndexingHeader(this);
10099
size_t preCapacity;
101100
if (hasIndexingHeader)
102-
preCapacity = butterfly->indexingHeader()->preCapacity(structure);
101+
preCapacity = butterfly->preCapacity(structure);
103102
else
104103
preCapacity = 0;
105104

@@ -3913,7 +3912,7 @@ void JSObject::reallocateAndShrinkButterfly(VM& vm, unsigned length)
39133912
ASSERT(hasContiguous(indexingType()) || hasInt32(indexingType()) || hasDouble(indexingType()) || hasUndecided(indexingType()));
39143913
ASSERT(this->butterfly()->vectorLength() > length);
39153914
ASSERT(this->butterfly()->publicLength() >= length);
3916-
ASSERT(!this->butterfly()->indexingHeader()->preCapacity(structure()));
3915+
ASSERT(!this->butterfly()->preCapacity(structure()));
39173916

39183917
DeferGC deferGC(vm);
39193918
Butterfly* newButterfly = this->butterfly()->resizeArray(vm, this, structure(), 0, ArrayStorage::sizeFor(length));
@@ -4115,8 +4114,8 @@ void JSObject::shiftButterflyAfterFlattening(const ConcurrentJSLocker&, VM& vm,
41154114
size_t indexingPayloadSizeInBytes;
41164115
bool hasIndexingHeader = this->hasIndexingHeader();
41174116
if (hasIndexingHeader) [[unlikely]] {
4118-
preCapacity = oldButterfly->indexingHeader()->preCapacity(structure);
4119-
indexingPayloadSizeInBytes = oldButterfly->indexingHeader()->indexingPayloadSizeInBytes(structure);
4117+
preCapacity = oldButterfly->preCapacity(structure);
4118+
indexingPayloadSizeInBytes = oldButterfly->indexingPayloadSizeInBytes(structure);
41204119
} else {
41214120
preCapacity = 0;
41224121
indexingPayloadSizeInBytes = 0;

‎Source/JavaScriptCore/runtime/JSObject.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <JavaScriptCore/DOMAttributeGetterSetter.h>
3232
#include <JavaScriptCore/DeletePropertySlot.h>
3333
#include <JavaScriptCore/Heap.h>
34-
#include <JavaScriptCore/IndexingHeaderInlines.h>
3534
#include <JavaScriptCore/Intrinsic.h>
3635
#include <JavaScriptCore/JSCJSValueCell.h>
3736
#include <JavaScriptCore/JSCast.h>
@@ -1262,7 +1261,7 @@ inline constexpr intptr_t offsetInButterfly(PropertyOffset offset)
12621261
inline size_t JSObject::butterflyPreCapacity()
12631262
{
12641263
if (hasIndexingHeader()) [[unlikely]]
1265-
return butterfly()->indexingHeader()->preCapacity(structure());
1264+
return butterfly()->preCapacity(structure());
12661265
return 0;
12671266
}
12681267

@@ -1275,8 +1274,8 @@ inline size_t JSObject::butterflyTotalSize()
12751274
bool hasIndexingHeader = this->hasIndexingHeader();
12761275

12771276
if (hasIndexingHeader) [[unlikely]] {
1278-
preCapacity = butterfly->indexingHeader()->preCapacity(structure);
1279-
indexingPayloadSizeInBytes = butterfly->indexingHeader()->indexingPayloadSizeInBytes(structure);
1277+
preCapacity = butterfly->preCapacity(structure);
1278+
indexingPayloadSizeInBytes = butterfly->indexingPayloadSizeInBytes(structure);
12801279
} else {
12811280
preCapacity = 0;
12821281
indexingPayloadSizeInBytes = 0;

‎Source/JavaScriptCore/runtime/ObjectInitializationScope.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ void ObjectInitializationScope::verifyPropertiesAreInitialized(JSObject* object)
7575
Butterfly* butterfly = object->butterfly();
7676
Structure* structure = object->structure();
7777
IndexingType indexingType = structure->indexingType();
78-
unsigned vectorLength = butterfly->vectorLength();
7978
if (hasUndecided(indexingType)) [[unlikely]] {
8079
// Nothing to verify.
8180
} else if (!hasIndexedProperties(indexingType)) {
8281
// Nothing to verify.
8382
} else if (!hasAnyArrayStorage(indexingType)) [[likely]] {
83+
unsigned vectorLength = butterfly->vectorLength();
8484
auto data = butterfly->contiguous().data();
8585
for (unsigned i = 0; i < vectorLength; ++i) {
8686
if (isScribbledValue(data[i].get())) {
@@ -90,6 +90,7 @@ void ObjectInitializationScope::verifyPropertiesAreInitialized(JSObject* object)
9090
}
9191
} else {
9292
ArrayStorage* storage = butterfly->arrayStorage();
93+
unsigned vectorLength = storage->vectorLength();
9394
for (unsigned i = 0; i < vectorLength; ++i) {
9495
if (isScribbledValue(storage->m_vector[i].get())) {
9596
dataLogLn("Found scribbled value at i = ", i);

0 commit comments

Comments
 (0)