Skip to content

Commit b400755

Browse files
committed
Bug 1842773 - Part 36: Rename ArrayBufferObject::MaxByteLength to ByteLengthLimit. r=sfink,nbp
Rename `MaxByteLength` to avoid confusion with the new `maxByteLength` slot for resizable ArrayBuffers. - Prefer "Limit" instead of "Max" because the latter could be misinterpreted to refer to `maxByteLength`, because it also includes the substring "max". Differential Revision: https://phabricator.services.mozilla.com/D196312
1 parent 6923cf6 commit b400755

15 files changed

+64
-64
lines changed

js/src/builtin/DataViewObject.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ bool DataViewObject::getAndCheckConstructorArgs(
247247
JSMSG_OFFSET_OUT_OF_BUFFER);
248248
return false;
249249
}
250-
MOZ_ASSERT(offset <= ArrayBufferObject::MaxByteLength);
250+
MOZ_ASSERT(offset <= ArrayBufferObject::ByteLengthLimit);
251251

252252
uint64_t viewByteLength = 0;
253253
bool autoLength = false;
@@ -275,7 +275,7 @@ bool DataViewObject::getAndCheckConstructorArgs(
275275
return false;
276276
}
277277
}
278-
MOZ_ASSERT(viewByteLength <= ArrayBufferObject::MaxByteLength);
278+
MOZ_ASSERT(viewByteLength <= ArrayBufferObject::ByteLengthLimit);
279279

280280
*byteOffsetPtr = offset;
281281
*byteLengthPtr = viewByteLength;

js/src/builtin/TestingFunctions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2216,8 +2216,8 @@ static bool WasmGcArrayLength(JSContext* cx, unsigned argc, Value* vp) {
22162216

22172217
static bool LargeArrayBufferSupported(JSContext* cx, unsigned argc, Value* vp) {
22182218
CallArgs args = CallArgsFromVp(argc, vp);
2219-
args.rval().setBoolean(ArrayBufferObject::MaxByteLength >
2220-
ArrayBufferObject::MaxByteLengthForSmallBuffer);
2219+
args.rval().setBoolean(ArrayBufferObject::ByteLengthLimit >
2220+
ArrayBufferObject::ByteLengthLimitForSmallBuffer);
22212221
return true;
22222222
}
22232223

js/src/ctypes/CTypes.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8011,7 +8011,7 @@ static bool ReadTypedArrayCommon(JSContext* cx, unsigned argc, Value* vp,
80118011

80128012
CheckedInt<size_t> size = *length;
80138013
size *= CType::GetSize(baseType);
8014-
if (!size.isValid() || size.value() > ArrayBufferObject::MaxByteLength) {
8014+
if (!size.isValid() || size.value() > ArrayBufferObject::ByteLengthLimit) {
80158015
return SizeOverflow(cx, "data", "typed array");
80168016
}
80178017

js/src/jit/RangeAnalysis.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1791,13 +1791,13 @@ void MInitializedLength::computeRange(TempAllocator& alloc) {
17911791
}
17921792

17931793
void MArrayBufferViewLength::computeRange(TempAllocator& alloc) {
1794-
if constexpr (ArrayBufferObject::MaxByteLength <= INT32_MAX) {
1794+
if constexpr (ArrayBufferObject::ByteLengthLimit <= INT32_MAX) {
17951795
setRange(Range::NewUInt32Range(alloc, 0, INT32_MAX));
17961796
}
17971797
}
17981798

17991799
void MArrayBufferViewByteOffset::computeRange(TempAllocator& alloc) {
1800-
if constexpr (ArrayBufferObject::MaxByteLength <= INT32_MAX) {
1800+
if constexpr (ArrayBufferObject::ByteLengthLimit <= INT32_MAX) {
18011801
setRange(Range::NewUInt32Range(alloc, 0, INT32_MAX));
18021802
}
18031803
}

js/src/jit/VMFunctions.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2353,16 +2353,16 @@ void AllocateAndInitTypedArrayBuffer(JSContext* cx, TypedArrayObject* obj,
23532353
// Negative numbers or zero will bail out to the slow path, which in turn will
23542354
// raise an invalid argument exception or create a correct object with zero
23552355
// elements.
2356-
constexpr size_t maxByteLength = TypedArrayObject::MaxByteLength;
2357-
if (count <= 0 || size_t(count) > maxByteLength / obj->bytesPerElement()) {
2356+
constexpr size_t byteLengthLimit = TypedArrayObject::ByteLengthLimit;
2357+
if (count <= 0 || size_t(count) > byteLengthLimit / obj->bytesPerElement()) {
23582358
obj->setFixedSlot(TypedArrayObject::LENGTH_SLOT, PrivateValue(size_t(0)));
23592359
return;
23602360
}
23612361

23622362
obj->setFixedSlot(TypedArrayObject::LENGTH_SLOT, PrivateValue(count));
23632363

23642364
size_t nbytes = size_t(count) * obj->bytesPerElement();
2365-
MOZ_ASSERT(nbytes <= maxByteLength);
2365+
MOZ_ASSERT(nbytes <= byteLengthLimit);
23662366
nbytes = RoundUp(nbytes, sizeof(Value));
23672367

23682368
MOZ_ASSERT(!obj->isTenured());

js/src/shell/OSObject.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ JSObject* FileAsTypedArray(JSContext* cx, JS::HandleString pathnameStr) {
320320
return nullptr;
321321
}
322322

323-
if (len > ArrayBufferObject::MaxByteLength) {
323+
if (len > ArrayBufferObject::ByteLengthLimit) {
324324
JS_ReportErrorUTF8(cx, "file %s is too large for a Uint8Array",
325325
pathname.get());
326326
return nullptr;

js/src/vm/ArrayBufferObject.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ uint64_t js::WasmReservedBytes() { return wasmReservedBytes; }
162162
[[nodiscard]] static bool CheckArrayBufferTooLarge(JSContext* cx,
163163
uint64_t nbytes) {
164164
// Refuse to allocate too large buffers.
165-
if (MOZ_UNLIKELY(nbytes > ArrayBufferObject::MaxByteLength)) {
165+
if (MOZ_UNLIKELY(nbytes > ArrayBufferObject::ByteLengthLimit)) {
166166
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
167167
JSMSG_BAD_ARRAY_LENGTH);
168168
return false;
@@ -1488,7 +1488,7 @@ inline size_t ArrayBufferObject::associatedBytes() const {
14881488
}
14891489

14901490
void ArrayBufferObject::setByteLength(size_t length) {
1491-
MOZ_ASSERT(length <= ArrayBufferObject::MaxByteLength);
1491+
MOZ_ASSERT(length <= ArrayBufferObject::ByteLengthLimit);
14921492
setFixedSlot(BYTE_LENGTH_SLOT, PrivateValue(length));
14931493
}
14941494

@@ -1594,7 +1594,7 @@ ArrayBufferObject* ArrayBufferObject::wasmGrowToPagesInPlace(
15941594
return nullptr;
15951595
}
15961596
MOZ_ASSERT(newPages <= wasm::MaxMemoryPages(t) &&
1597-
newPages.byteLength() <= ArrayBufferObject::MaxByteLength);
1597+
newPages.byteLength() <= ArrayBufferObject::ByteLengthLimit);
15981598

15991599
// We have checked against the clamped maximum and so we know we can convert
16001600
// to byte lengths now.
@@ -1652,7 +1652,7 @@ ArrayBufferObject* ArrayBufferObject::wasmMovingGrowToPages(
16521652
return nullptr;
16531653
}
16541654
MOZ_ASSERT(newPages <= wasm::MaxMemoryPages(t) &&
1655-
newPages.byteLength() < ArrayBufferObject::MaxByteLength);
1655+
newPages.byteLength() < ArrayBufferObject::ByteLengthLimit);
16561656

16571657
// We have checked against the clamped maximum and so we know we can convert
16581658
// to byte lengths now.
@@ -1847,7 +1847,7 @@ template <class ArrayBufferType, ArrayBufferObject::FillContents FillType>
18471847
ArrayBufferObject::createUninitializedBufferAndData(
18481848
JSContext* cx, size_t nbytes, AutoSetNewObjectMetadata&,
18491849
JS::Handle<JSObject*> proto) {
1850-
MOZ_ASSERT(nbytes <= ArrayBufferObject::MaxByteLength,
1850+
MOZ_ASSERT(nbytes <= ArrayBufferObject::ByteLengthLimit,
18511851
"caller must validate the byte count it passes");
18521852

18531853
static_assert(std::is_same_v<ArrayBufferType, FixedLengthArrayBufferObject> ||
@@ -1898,7 +1898,7 @@ template <ArrayBufferObject::FillContents FillType>
18981898
ArrayBufferObject::createBufferAndData(
18991899
JSContext* cx, size_t nbytes, AutoSetNewObjectMetadata& metadata,
19001900
JS::Handle<JSObject*> proto /* = nullptr */) {
1901-
MOZ_ASSERT(nbytes <= ArrayBufferObject::MaxByteLength,
1901+
MOZ_ASSERT(nbytes <= ArrayBufferObject::ByteLengthLimit,
19021902
"caller must validate the byte count it passes");
19031903

19041904
auto [buffer, data] =
@@ -1925,7 +1925,7 @@ ResizableArrayBufferObject::createBufferAndData(
19251925
JSContext* cx, size_t byteLength, size_t maxByteLength,
19261926
AutoSetNewObjectMetadata& metadata, Handle<JSObject*> proto) {
19271927
MOZ_ASSERT(byteLength <= maxByteLength);
1928-
MOZ_ASSERT(maxByteLength <= ArrayBufferObject::MaxByteLength,
1928+
MOZ_ASSERT(maxByteLength <= ArrayBufferObject::ByteLengthLimit,
19291929
"caller must validate the byte count it passes");
19301930

19311931
// NOTE: The spec proposal for resizable ArrayBuffers suggests to use a
@@ -1958,7 +1958,7 @@ ResizableArrayBufferObject::createBufferAndData(
19581958
JSContext* cx, size_t newByteLength,
19591959
JS::Handle<ArrayBufferObject*> source) {
19601960
MOZ_ASSERT(!source->isDetached());
1961-
MOZ_ASSERT(newByteLength <= ArrayBufferObject::MaxByteLength,
1961+
MOZ_ASSERT(newByteLength <= ArrayBufferObject::ByteLengthLimit,
19621962
"caller must validate the byte count it passes");
19631963

19641964
size_t sourceByteLength = source->byteLength();
@@ -2037,7 +2037,7 @@ ResizableArrayBufferObject::createBufferAndData(
20372037
JSContext* cx, size_t newByteLength,
20382038
JS::Handle<ArrayBufferObject*> source) {
20392039
MOZ_ASSERT(!source->isDetached());
2040-
MOZ_ASSERT(newByteLength <= ArrayBufferObject::MaxByteLength,
2040+
MOZ_ASSERT(newByteLength <= ArrayBufferObject::ByteLengthLimit,
20412041
"caller must validate the byte count it passes");
20422042

20432043
if (newByteLength > FixedLengthArrayBufferObject::MaxInlineBytes &&
@@ -2103,7 +2103,7 @@ ResizableArrayBufferObject::createBufferAndData(
21032103
MOZ_ASSERT(source->bufferKind() == MALLOCED_ARRAYBUFFER_CONTENTS_ARENA);
21042104
MOZ_ASSERT(newByteLength > FixedLengthArrayBufferObject::MaxInlineBytes,
21052105
"prefer copying small buffers");
2106-
MOZ_ASSERT(newByteLength <= ArrayBufferObject::MaxByteLength,
2106+
MOZ_ASSERT(newByteLength <= ArrayBufferObject::ByteLengthLimit,
21072107
"caller must validate the byte count it passes");
21082108

21092109
size_t oldByteLength = source->associatedBytes();

js/src/vm/ArrayBufferObject.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared {
207207

208208
// The length of an ArrayBuffer or SharedArrayBuffer can be at most INT32_MAX
209209
// on 32-bit platforms. Allow a larger limit on 64-bit platforms.
210-
static constexpr size_t MaxByteLengthForSmallBuffer = INT32_MAX;
210+
static constexpr size_t ByteLengthLimitForSmallBuffer = INT32_MAX;
211211
#ifdef JS_64BIT
212-
static constexpr size_t MaxByteLength =
212+
static constexpr size_t ByteLengthLimit =
213213
size_t(8) * 1024 * 1024 * 1024; // 8 GB.
214214
#else
215-
static constexpr size_t MaxByteLength = MaxByteLengthForSmallBuffer;
215+
static constexpr size_t ByteLengthLimit = ByteLengthLimitForSmallBuffer;
216216
#endif
217217

218218
public:
@@ -649,7 +649,7 @@ class ResizableArrayBufferObject : public ArrayBufferObject {
649649
bool hasInlineData() const { return dataPointer() == inlineDataPointer(); }
650650

651651
void setMaxByteLength(size_t length) {
652-
MOZ_ASSERT(length <= ArrayBufferObject::MaxByteLength);
652+
MOZ_ASSERT(length <= ArrayBufferObject::ByteLengthLimit);
653653
setFixedSlot(MAX_BYTE_LENGTH_SLOT, PrivateValue(length));
654654
}
655655

js/src/vm/ArrayBufferObjectMaybeShared.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ JS_PUBLIC_API bool JS::IsLargeArrayBufferMaybeShared(JSObject* obj) {
6666
size_t len = obj->is<ArrayBufferObject>()
6767
? obj->as<ArrayBufferObject>().byteLength()
6868
: obj->as<SharedArrayBufferObject>().byteLength();
69-
return len > ArrayBufferObject::MaxByteLengthForSmallBuffer;
69+
return len > ArrayBufferObject::ByteLengthLimitForSmallBuffer;
7070
#else
7171
// Large ArrayBuffers are not supported on 32-bit.
72-
static_assert(ArrayBufferObject::MaxByteLength ==
73-
ArrayBufferObject::MaxByteLengthForSmallBuffer);
72+
static_assert(ArrayBufferObject::ByteLengthLimit ==
73+
ArrayBufferObject::ByteLengthLimitForSmallBuffer);
7474
return false;
7575
#endif
7676
}

js/src/vm/ArrayBufferViewObject.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ bool ArrayBufferViewObject::init(JSContext* cx,
114114
MOZ_ASSERT_IF(!buffer, byteOffset == 0);
115115
MOZ_ASSERT_IF(buffer, !buffer->isDetached());
116116

117-
MOZ_ASSERT(byteOffset <= ArrayBufferObject::MaxByteLength);
118-
MOZ_ASSERT(length <= ArrayBufferObject::MaxByteLength);
119-
MOZ_ASSERT(byteOffset + length <= ArrayBufferObject::MaxByteLength);
117+
MOZ_ASSERT(byteOffset <= ArrayBufferObject::ByteLengthLimit);
118+
MOZ_ASSERT(length <= ArrayBufferObject::ByteLengthLimit);
119+
MOZ_ASSERT(byteOffset + length <= ArrayBufferObject::ByteLengthLimit);
120120

121121
MOZ_ASSERT_IF(is<TypedArrayObject>(),
122-
length <= TypedArrayObject::MaxByteLength / bytesPerElement);
122+
length <= TypedArrayObject::ByteLengthLimit / bytesPerElement);
123123

124124
// The isSharedMemory property is invariant. Self-hosting code that
125125
// sets BUFFER_SLOT or the private slot (if it does) must maintain it by
@@ -359,11 +359,11 @@ JS_PUBLIC_API bool JS::IsLargeArrayBufferView(JSObject* obj) {
359359
size_t len = obj->is<DataViewObject>()
360360
? obj->as<DataViewObject>().byteLength().valueOr(0)
361361
: obj->as<TypedArrayObject>().byteLength().valueOr(0);
362-
return len > ArrayBufferObject::MaxByteLengthForSmallBuffer;
362+
return len > ArrayBufferObject::ByteLengthLimitForSmallBuffer;
363363
#else
364364
// Large ArrayBuffers are not supported on 32-bit.
365-
static_assert(ArrayBufferObject::MaxByteLength ==
366-
ArrayBufferObject::MaxByteLengthForSmallBuffer);
365+
static_assert(ArrayBufferObject::ByteLengthLimit ==
366+
ArrayBufferObject::ByteLengthLimitForSmallBuffer);
367367
return false;
368368
#endif
369369
}

js/src/vm/SharedArrayObject.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static size_t WasmSharedArrayAccessibleSize(size_t length) {
4040
}
4141

4242
static size_t NonWasmSharedArrayAllocSize(size_t length) {
43-
MOZ_ASSERT(length <= ArrayBufferObject::MaxByteLength);
43+
MOZ_ASSERT(length <= ArrayBufferObject::ByteLengthLimit);
4444
return sizeof(SharedArrayRawBuffer) + length;
4545
}
4646

@@ -60,8 +60,8 @@ static size_t SharedArrayMappedSize(bool isWasm, size_t length) {
6060
SharedArrayRawBuffer* SharedArrayRawBuffer::Allocate(bool isGrowable,
6161
size_t length,
6262
size_t maxLength) {
63-
MOZ_RELEASE_ASSERT(length <= ArrayBufferObject::MaxByteLength);
64-
MOZ_RELEASE_ASSERT(maxLength <= ArrayBufferObject::MaxByteLength);
63+
MOZ_RELEASE_ASSERT(length <= ArrayBufferObject::ByteLengthLimit);
64+
MOZ_RELEASE_ASSERT(maxLength <= ArrayBufferObject::ByteLengthLimit);
6565
MOZ_ASSERT_IF(!isGrowable, length == maxLength);
6666
MOZ_ASSERT_IF(isGrowable, length <= maxLength);
6767

@@ -84,7 +84,7 @@ WasmSharedArrayRawBuffer* WasmSharedArrayRawBuffer::AllocateWasm(
8484
MOZ_ASSERT(initialPages.hasByteLength());
8585
size_t length = initialPages.byteLength();
8686

87-
MOZ_RELEASE_ASSERT(length <= ArrayBufferObject::MaxByteLength);
87+
MOZ_RELEASE_ASSERT(length <= ArrayBufferObject::ByteLengthLimit);
8888

8989
size_t accessibleSize = WasmSharedArrayAccessibleSize(length);
9090
if (accessibleSize < length) {
@@ -144,7 +144,7 @@ bool WasmSharedArrayRawBuffer::wasmGrowToPagesInPlace(const Lock&,
144144
return false;
145145
}
146146
MOZ_ASSERT(newPages <= wasm::MaxMemoryPages(t) &&
147-
newPages.byteLength() <= ArrayBufferObject::MaxByteLength);
147+
newPages.byteLength() <= ArrayBufferObject::ByteLengthLimit);
148148

149149
// We have checked against the clamped maximum and so we know we can convert
150150
// to byte lengths now.
@@ -471,7 +471,7 @@ bool SharedArrayBufferObject::class_constructor(JSContext* cx, unsigned argc,
471471

472472
// 24.2.1.1, step 3 (Inlined 6.2.7.2 CreateSharedByteDataBlock, step 2).
473473
// Refuse to allocate too large buffers.
474-
if (byteLength > ArrayBufferObject::MaxByteLength) {
474+
if (byteLength > ArrayBufferObject::ByteLengthLimit) {
475475
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
476476
JSMSG_SHARED_ARRAY_BAD_LENGTH);
477477
return false;
@@ -796,7 +796,7 @@ JS_PUBLIC_API void JS::GetSharedArrayBufferLengthAndData(JSObject* obj,
796796
JS_PUBLIC_API JSObject* JS::NewSharedArrayBuffer(JSContext* cx, size_t nbytes) {
797797
MOZ_ASSERT(cx->realm()->creationOptions().getSharedMemoryAndAtomicsEnabled());
798798

799-
if (nbytes > ArrayBufferObject::MaxByteLength) {
799+
if (nbytes > ArrayBufferObject::ByteLengthLimit) {
800800
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
801801
JSMSG_SHARED_ARRAY_BAD_LENGTH);
802802
return nullptr;

js/src/vm/StructuredClone.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -2621,8 +2621,8 @@ bool JSStructuredCloneReader::readTypedArray(uint32_t arrayType,
26212621
}
26222622

26232623
// Ensure invalid 64-bit values won't be truncated below.
2624-
if (nelems > ArrayBufferObject::MaxByteLength ||
2625-
byteOffset > ArrayBufferObject::MaxByteLength) {
2624+
if (nelems > ArrayBufferObject::ByteLengthLimit ||
2625+
byteOffset > ArrayBufferObject::ByteLengthLimit) {
26262626
JS_ReportErrorNumberASCII(context(), GetErrorMessage, nullptr,
26272627
JSMSG_SC_BAD_SERIALIZED_DATA,
26282628
"invalid typed array length or offset");
@@ -2703,8 +2703,8 @@ bool JSStructuredCloneReader::readDataView(uint64_t byteLength,
27032703
}
27042704

27052705
// Ensure invalid 64-bit values won't be truncated below.
2706-
if (byteLength > ArrayBufferObject::MaxByteLength ||
2707-
byteOffset > ArrayBufferObject::MaxByteLength) {
2706+
if (byteLength > ArrayBufferObject::ByteLengthLimit ||
2707+
byteOffset > ArrayBufferObject::ByteLengthLimit) {
27082708
JS_ReportErrorNumberASCII(context(), GetErrorMessage, nullptr,
27092709
JSMSG_SC_BAD_SERIALIZED_DATA,
27102710
"invalid DataView length or offset");
@@ -2753,8 +2753,8 @@ bool JSStructuredCloneReader::readArrayBuffer(StructuredDataType type,
27532753

27542754
// The maximum ArrayBuffer size depends on the platform, and we cast to size_t
27552755
// below, so we have to check this here.
2756-
if (nbytes > ArrayBufferObject::MaxByteLength ||
2757-
maxbytes > ArrayBufferObject::MaxByteLength) {
2756+
if (nbytes > ArrayBufferObject::ByteLengthLimit ||
2757+
maxbytes > ArrayBufferObject::ByteLengthLimit) {
27582758
JS_ReportErrorNumberASCII(context(), GetErrorMessage, nullptr,
27592759
JSMSG_BAD_ARRAY_LENGTH);
27602760
return false;
@@ -2799,7 +2799,7 @@ bool JSStructuredCloneReader::readSharedArrayBuffer(StructuredDataType type,
27992799

28002800
// The maximum ArrayBuffer size depends on the platform, and we cast to size_t
28012801
// below, so we have to check this here.
2802-
if (byteLength > ArrayBufferObject::MaxByteLength) {
2802+
if (byteLength > ArrayBufferObject::ByteLengthLimit) {
28032803
JS_ReportErrorNumberASCII(context(), GetErrorMessage, nullptr,
28042804
JSMSG_BAD_ARRAY_LENGTH);
28052805
return false;
@@ -3395,7 +3395,7 @@ bool JSStructuredCloneReader::readTransferMap() {
33953395
return false;
33963396
}
33973397

3398-
MOZ_RELEASE_ASSERT(extraData <= ArrayBufferObject::MaxByteLength);
3398+
MOZ_RELEASE_ASSERT(extraData <= ArrayBufferObject::ByteLengthLimit);
33993399
size_t nbytes = extraData;
34003400

34013401
MOZ_ASSERT(data == JS::SCTAG_TMO_ALLOC_DATA ||

0 commit comments

Comments
 (0)