From 5d07bd825d61aba5a8a0e57dc153274493e6f6e0 Mon Sep 17 00:00:00 2001 From: Lars T Hansen Date: Mon, 12 Apr 2021 16:01:57 +0000 Subject: [PATCH] Bug 1691886 - Remove BufferSize. r=jandem Remove the BufferSize abstraction, replace it with size_t everywhere. Differential Revision: https://phabricator.services.mozilla.com/D111101 --- js/src/builtin/Array.cpp | 4 +- js/src/builtin/AtomicsObject.cpp | 6 +- js/src/builtin/DataViewObject.cpp | 20 +-- js/src/builtin/DataViewObject.h | 14 +- js/src/builtin/Object.cpp | 2 +- js/src/builtin/TestingFunctions.cpp | 2 +- js/src/fuzz-tests/testWasm.cpp | 2 +- js/src/gc/Marking.cpp | 2 +- js/src/jit/CacheIR.cpp | 26 +-- js/src/jit/CodeGenerator.cpp | 2 +- js/src/jit/MacroAssembler.cpp | 2 +- js/src/jit/Recover.cpp | 2 +- js/src/jit/VMFunctions.cpp | 20 +-- js/src/jit/WarpCacheIRTranspiler.cpp | 2 +- js/src/jsapi-tests/testArrayBufferView.cpp | 2 +- js/src/shell/OSObject.cpp | 2 +- js/src/shell/js.cpp | 11 +- js/src/vm/ArrayBufferObject-inl.h | 2 +- js/src/vm/ArrayBufferObject.cpp | 197 ++++++++++----------- js/src/vm/ArrayBufferObject.h | 33 ++-- js/src/vm/ArrayBufferObjectMaybeShared.cpp | 8 +- js/src/vm/ArrayBufferViewObject.cpp | 76 ++++---- js/src/vm/ArrayBufferViewObject.h | 8 +- js/src/vm/BufferSize.h | 23 --- js/src/vm/Iteration.cpp | 2 +- js/src/vm/JSObject.cpp | 4 +- js/src/vm/NativeObject-inl.h | 2 +- js/src/vm/NativeObject.cpp | 2 +- js/src/vm/SelfHosting.cpp | 12 +- js/src/vm/SharedArrayObject.cpp | 56 +++--- js/src/vm/SharedArrayObject.h | 22 +-- js/src/vm/StructuredClone.cpp | 32 ++-- js/src/vm/TypedArrayObject-inl.h | 18 +- js/src/vm/TypedArrayObject.cpp | 97 +++++----- js/src/vm/TypedArrayObject.h | 12 +- js/src/wasm/AsmJS.cpp | 2 +- js/src/wasm/WasmInstance.cpp | 28 ++- js/src/wasm/WasmJS.cpp | 41 +++-- js/src/wasm/WasmJS.h | 7 +- js/src/wasm/WasmModule.cpp | 4 +- 40 files changed, 382 insertions(+), 427 deletions(-) delete mode 100644 js/src/vm/BufferSize.h diff --git a/js/src/builtin/Array.cpp b/js/src/builtin/Array.cpp index cf0eb4bc6123..56efa825cfec 100644 --- a/js/src/builtin/Array.cpp +++ b/js/src/builtin/Array.cpp @@ -383,7 +383,7 @@ bool js::GetElements(JSContext* cx, HandleObject aobj, uint32_t length, if (aobj->is()) { Handle typedArray = aobj.as(); - if (typedArray->length().get() == length) { + if (typedArray->length() == length) { return TypedArrayObject::getElements(cx, typedArray, vp); } } @@ -3142,7 +3142,7 @@ static bool GetIndexedPropertiesInRange(JSContext* cx, HandleObject obj, // Append typed array elements. if (nativeObj->is()) { - size_t len = nativeObj->as().length().get(); + size_t len = nativeObj->as().length(); for (uint32_t i = begin; i < len && i < end; i++) { if (!indexes.append(i)) { return false; diff --git a/js/src/builtin/AtomicsObject.cpp b/js/src/builtin/AtomicsObject.cpp index b8a0d545db3e..f39422049eee 100644 --- a/js/src/builtin/AtomicsObject.cpp +++ b/js/src/builtin/AtomicsObject.cpp @@ -116,7 +116,7 @@ static bool ValidateAtomicAccess(JSContext* cx, // Step 1 (implicit). MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - size_t length = typedArray->length().get(); + size_t length = typedArray->length(); // Step 2. uint64_t accessIndex; @@ -652,7 +652,7 @@ static bool DoAtomicsWait(JSContext* cx, cx, unwrappedTypedArray->bufferShared()); // Step 11. - size_t offset = unwrappedTypedArray->byteOffset().get(); + size_t offset = unwrappedTypedArray->byteOffset(); // Steps 12-13. // The computation will not overflow because range checks have been @@ -821,7 +821,7 @@ static bool atomics_notify(JSContext* cx, unsigned argc, Value* vp) { cx, unwrappedTypedArray->bufferShared()); // Step 6. - size_t offset = unwrappedTypedArray->byteOffset().get(); + size_t offset = unwrappedTypedArray->byteOffset(); // Steps 7-9. // The computation will not overflow because range checks have been diff --git a/js/src/builtin/DataViewObject.cpp b/js/src/builtin/DataViewObject.cpp index d5f3d885cd97..d0f00075a12d 100644 --- a/js/src/builtin/DataViewObject.cpp +++ b/js/src/builtin/DataViewObject.cpp @@ -50,7 +50,7 @@ using mozilla::AssertedCast; using mozilla::WrapToSigned; DataViewObject* DataViewObject::create( - JSContext* cx, BufferSize byteOffset, BufferSize byteLength, + JSContext* cx, size_t byteOffset, size_t byteLength, Handle arrayBuffer, HandleObject proto) { if (arrayBuffer->isDetached()) { JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, @@ -72,8 +72,8 @@ DataViewObject* DataViewObject::create( bool DataViewObject::getAndCheckConstructorArgs(JSContext* cx, HandleObject bufobj, const CallArgs& args, - BufferSize* byteOffsetPtr, - BufferSize* byteLengthPtr) { + size_t* byteOffsetPtr, + size_t* byteLengthPtr) { // Step 3. if (!bufobj->is()) { JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, @@ -97,7 +97,7 @@ bool DataViewObject::getAndCheckConstructorArgs(JSContext* cx, } // Step 6. - size_t bufferByteLength = buffer->byteLength().get(); + size_t bufferByteLength = buffer->byteLength(); // Step 7. if (offset > bufferByteLength) { @@ -128,8 +128,8 @@ bool DataViewObject::getAndCheckConstructorArgs(JSContext* cx, } MOZ_ASSERT(viewByteLength <= ArrayBufferObject::maxBufferByteLength()); - *byteOffsetPtr = BufferSize(offset); - *byteLengthPtr = BufferSize(viewByteLength); + *byteOffsetPtr = offset; + *byteLengthPtr = viewByteLength; return true; } @@ -139,8 +139,8 @@ bool DataViewObject::constructSameCompartment(JSContext* cx, MOZ_ASSERT(args.isConstructing()); cx->check(bufobj); - BufferSize byteOffset(0); - BufferSize byteLength(0); + size_t byteOffset = 0; + size_t byteLength = 0; if (!getAndCheckConstructorArgs(cx, bufobj, args, &byteOffset, &byteLength)) { return false; } @@ -185,8 +185,8 @@ bool DataViewObject::constructWrapped(JSContext* cx, HandleObject bufobj, } // NB: This entails the IsArrayBuffer check - BufferSize byteOffset(0); - BufferSize byteLength(0); + size_t byteOffset = 0; + size_t byteLength = 0; if (!getAndCheckConstructorArgs(cx, unwrapped, args, &byteOffset, &byteLength)) { return false; diff --git a/js/src/builtin/DataViewObject.h b/js/src/builtin/DataViewObject.h index 62b9dd272d4f..a94e3106a966 100644 --- a/js/src/builtin/DataViewObject.h +++ b/js/src/builtin/DataViewObject.h @@ -45,27 +45,27 @@ class DataViewObject : public ArrayBufferViewObject { static bool getAndCheckConstructorArgs(JSContext* cx, HandleObject bufobj, const CallArgs& args, - BufferSize* byteOffset, - BufferSize* byteLength); + size_t* byteOffset, + size_t* byteLength); static bool constructSameCompartment(JSContext* cx, HandleObject bufobj, const CallArgs& args); static bool constructWrapped(JSContext* cx, HandleObject bufobj, const CallArgs& args); static DataViewObject* create( - JSContext* cx, BufferSize byteOffset, BufferSize byteLength, + JSContext* cx, size_t byteOffset, size_t byteLength, Handle arrayBuffer, HandleObject proto); public: static const JSClass class_; static const JSClass protoClass_; - BufferSize byteLength() const { - return BufferSize(size_t(getFixedSlot(LENGTH_SLOT).toPrivate())); + size_t byteLength() const { + return size_t(getFixedSlot(LENGTH_SLOT).toPrivate()); } Value byteLengthValue() const { - size_t len = byteLength().get(); + size_t len = byteLength(); return NumberValue(len); } @@ -77,7 +77,7 @@ class DataViewObject : public ArrayBufferViewObject { MOZ_ASSERT(byteSize <= 8); mozilla::CheckedInt endOffset(offset); endOffset += byteSize; - return endOffset.isValid() && endOffset.value() <= byteLength().get(); + return endOffset.isValid() && endOffset.value() <= byteLength(); } static bool isOriginalByteOffsetGetter(Native native) { diff --git a/js/src/builtin/Object.cpp b/js/src/builtin/Object.cpp index 90bb06ba9a6f..e3cdd3a27776 100644 --- a/js/src/builtin/Object.cpp +++ b/js/src/builtin/Object.cpp @@ -1493,7 +1493,7 @@ static bool TryEnumerableOwnPropertiesNative(JSContext* cx, HandleObject obj, if (obj->is()) { Handle tobj = obj.as(); - size_t len = tobj->length().get(); + size_t len = tobj->length(); // Fail early if the typed array contains too many elements for a // dense array, because we likely OOM anyway when trying to allocate diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index e0566291f0a5..f64872dce9fd 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -5460,7 +5460,7 @@ static bool EvalStencilXDR(JSContext* cx, uint32_t argc, Value* vp) { frontend::CompilationStencil stencil(nullptr); /* Deserialize the stencil from XDR. */ - JS::TranscodeRange xdrRange(src->dataPointer(), src->byteLength().get()); + JS::TranscodeRange xdrRange(src->dataPointer(), src->byteLength()); bool succeeded = false; if (!stencil.deserializeStencils(cx, input.get(), xdrRange, &succeeded)) { return false; diff --git a/js/src/fuzz-tests/testWasm.cpp b/js/src/fuzz-tests/testWasm.cpp index 4bdf30d281f8..77a9f19e18de 100644 --- a/js/src/fuzz-tests/testWasm.cpp +++ b/js/src/fuzz-tests/testWasm.cpp @@ -424,7 +424,7 @@ static int testWasmFuzz(const uint8_t* buf, size_t size) { if (propObj->is()) { Rooted memory(gCx, &propObj->as()); - size_t byteLen = memory->volatileMemoryLength().get(); + size_t byteLen = memory->volatileMemoryLength(); if (byteLen) { // Read the bounds of the buffer to ensure it is valid. // AddressSanitizer would detect any out-of-bounds here. diff --git a/js/src/gc/Marking.cpp b/js/src/gc/Marking.cpp index 60a2bfda6499..2c984b2cdbc2 100644 --- a/js/src/gc/Marking.cpp +++ b/js/src/gc/Marking.cpp @@ -3201,7 +3201,7 @@ JSObject* js::TenuringTracer::moveToTenuredSlow(JSObject* src) { if (tarray->hasInlineElements()) { AllocKind srcKind = GetGCObjectKind(TypedArrayObject::FIXED_DATA_START); size_t headerSize = Arena::thingSize(srcKind); - srcSize = headerSize + tarray->byteLength().get(); + srcSize = headerSize + tarray->byteLength(); } } diff --git a/js/src/jit/CacheIR.cpp b/js/src/jit/CacheIR.cpp index ee3a936f9ed2..5153b0738b27 100644 --- a/js/src/jit/CacheIR.cpp +++ b/js/src/jit/CacheIR.cpp @@ -1782,21 +1782,21 @@ AttachDecision GetPropIRGenerator::tryAttachTypedArray(HandleObject obj, // callNativeGetterResult. EmitCallGetterResultGuards(writer, tarr, holder, shape, objId, mode_); if (isLength) { - if (tarr->length().get() <= INT32_MAX) { + if (tarr->length() <= INT32_MAX) { writer.loadArrayBufferViewLengthInt32Result(objId); } else { writer.loadArrayBufferViewLengthDoubleResult(objId); } trackAttached("TypedArrayLength"); } else if (isByteOffset) { - if (tarr->byteOffset().get() <= INT32_MAX) { + if (tarr->byteOffset() <= INT32_MAX) { writer.arrayBufferViewByteOffsetInt32Result(objId); } else { writer.arrayBufferViewByteOffsetDoubleResult(objId); } trackAttached("TypedArrayByteOffset"); } else { - if (tarr->byteLength().get() <= INT32_MAX) { + if (tarr->byteLength() <= INT32_MAX) { writer.typedArrayByteLengthInt32Result(objId); } else { writer.typedArrayByteLengthDoubleResult(objId); @@ -1860,14 +1860,14 @@ AttachDecision GetPropIRGenerator::tryAttachDataView(HandleObject obj, EmitCallGetterResultGuards(writer, dv, holder, shape, objId, mode_); writer.guardHasAttachedArrayBuffer(objId); if (isByteOffset) { - if (dv->byteOffset().get() <= INT32_MAX) { + if (dv->byteOffset() <= INT32_MAX) { writer.arrayBufferViewByteOffsetInt32Result(objId); } else { writer.arrayBufferViewByteOffsetDoubleResult(objId); } trackAttached("DataViewByteOffset"); } else { - if (dv->byteLength().get() <= INT32_MAX) { + if (dv->byteLength() <= INT32_MAX) { writer.loadArrayBufferViewLengthInt32Result(objId); } else { writer.loadArrayBufferViewLengthDoubleResult(objId); @@ -1922,7 +1922,7 @@ AttachDecision GetPropIRGenerator::tryAttachArrayBufferMaybeShared( // Emit all the normal guards for calling this native, but specialize // callNativeGetterResult. EmitCallGetterResultGuards(writer, buf, holder, shape, objId, mode_); - if (buf->byteLength().get() <= INT32_MAX) { + if (buf->byteLength() <= INT32_MAX) { writer.loadArrayBufferByteLengthInt32Result(objId); } else { writer.loadArrayBufferByteLengthDoubleResult(objId); @@ -2543,7 +2543,7 @@ AttachDecision GetPropIRGenerator::tryAttachSparseElement( // For Uint32Array we let the stub return a double only if the current result is // a double, to allow better codegen in Warp. static bool AllowDoubleForUint32Array(TypedArrayObject* tarr, uint64_t index) { - MOZ_ASSERT(index < tarr->length().get()); + MOZ_ASSERT(index < tarr->length()); if (tarr->type() != Scalar::Type::Uint32) { // Return value is only relevant for Uint32Array. @@ -2571,7 +2571,7 @@ AttachDecision GetPropIRGenerator::tryAttachTypedArrayElement( bool handleOOB = false; int64_t indexInt64; if (!ValueIsInt64Index(idVal_, &indexInt64) || indexInt64 < 0 || - uint64_t(indexInt64) >= tarr->length().get()) { + uint64_t(indexInt64) >= tarr->length()) { handleOOB = true; } @@ -4186,7 +4186,7 @@ AttachDecision SetPropIRGenerator::tryAttachSetTypedArrayElement( bool handleOOB = false; int64_t indexInt64; if (!ValueIsInt64Index(idVal_, &indexInt64) || indexInt64 < 0 || - uint64_t(indexInt64) >= tarr->length().get()) { + uint64_t(indexInt64) >= tarr->length()) { handleOOB = true; } @@ -7099,7 +7099,7 @@ static bool AtomicsMeetsPreconditions(TypedArrayObject* typedArray, if (!ValueIsInt64Index(index, &indexInt64)) { return false; } - if (indexInt64 < 0 || uint64_t(indexInt64) >= typedArray->length().get()) { + if (indexInt64 < 0 || uint64_t(indexInt64) >= typedArray->length()) { return false; } @@ -7951,7 +7951,7 @@ AttachDecision CallIRGenerator::tryAttachTypedArrayByteOffset( ValOperandId argId = writer.loadArgumentFixedSlot(ArgumentKind::Arg0, argc_); ObjOperandId objArgId = writer.guardToObject(argId); - if (tarr->byteOffset().get() <= INT32_MAX) { + if (tarr->byteOffset() <= INT32_MAX) { writer.arrayBufferViewByteOffsetInt32Result(objArgId); } else { writer.arrayBufferViewByteOffsetDoubleResult(objArgId); @@ -8011,7 +8011,7 @@ AttachDecision CallIRGenerator::tryAttachTypedArrayLength( writer.guardIsNotProxy(objArgId); } - if (tarr->length().get() <= INT32_MAX) { + if (tarr->length() <= INT32_MAX) { writer.loadArrayBufferViewLengthInt32Result(objArgId); } else { writer.loadArrayBufferViewLengthDoubleResult(objArgId); @@ -8050,7 +8050,7 @@ AttachDecision CallIRGenerator::tryAttachArrayBufferByteLength( writer.guardIsNotProxy(objArgId); } - if (buffer->byteLength().get() <= INT32_MAX) { + if (buffer->byteLength() <= INT32_MAX) { writer.loadArrayBufferByteLengthInt32Result(objArgId); } else { writer.loadArrayBufferByteLengthDoubleResult(objArgId); diff --git a/js/src/jit/CodeGenerator.cpp b/js/src/jit/CodeGenerator.cpp index 46f00de5bc3d..b3ee894447c2 100644 --- a/js/src/jit/CodeGenerator.cpp +++ b/js/src/jit/CodeGenerator.cpp @@ -6808,7 +6808,7 @@ void CodeGenerator::visitNewTypedArray(LNewTypedArray* lir) { TypedArrayObject* ttemplate = &templateObject->as(); - size_t n = ttemplate->length().get(); + size_t n = ttemplate->length(); MOZ_ASSERT(n <= INT32_MAX, "Template objects are only created for int32 lengths"); diff --git a/js/src/jit/MacroAssembler.cpp b/js/src/jit/MacroAssembler.cpp index 1ff4f891a5d8..b2757c9ed929 100644 --- a/js/src/jit/MacroAssembler.cpp +++ b/js/src/jit/MacroAssembler.cpp @@ -722,7 +722,7 @@ void MacroAssembler::initTypedArraySlots(Register obj, Register temp, "typed array inline buffer is limited by the maximum object byte size"); // Initialise data elements to zero. - size_t length = templateObj->length().get(); + size_t length = templateObj->length(); MOZ_ASSERT(length <= INT32_MAX, "Template objects are only created for int32 lengths"); size_t nbytes = length * templateObj->bytesPerElement(); diff --git a/js/src/jit/Recover.cpp b/js/src/jit/Recover.cpp index 759c2ba4fdc8..4dedb0cedcdd 100644 --- a/js/src/jit/Recover.cpp +++ b/js/src/jit/Recover.cpp @@ -1542,7 +1542,7 @@ bool RNewTypedArray::recover(JSContext* cx, SnapshotIterator& iter) const { RootedObject templateObject(cx, &iter.read().toObject()); RootedValue result(cx); - size_t length = templateObject.as()->length().get(); + size_t length = templateObject.as()->length(); MOZ_ASSERT(length <= INT32_MAX, "Template objects are only created for int32 lengths"); diff --git a/js/src/jit/VMFunctions.cpp b/js/src/jit/VMFunctions.cpp index 134b37b3702e..c456cf284753 100644 --- a/js/src/jit/VMFunctions.cpp +++ b/js/src/jit/VMFunctions.cpp @@ -2065,7 +2065,7 @@ bool HasNativeElementPure(JSContext* cx, NativeObject* obj, int32_t index, } // TypedArrayObject are also native and contain indexed properties. if (MOZ_UNLIKELY(obj->is())) { - size_t length = obj->as().length().get(); + size_t length = obj->as().length(); vp[0].setBoolean(uint32_t(index) < length); return true; } @@ -2435,7 +2435,7 @@ static int32_t AtomicsCompareExchange(TypedArrayObject* typedArray, AutoUnsafeCallWithABI unsafe; MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - MOZ_ASSERT(index < typedArray->length().get()); + MOZ_ASSERT(index < typedArray->length()); SharedMem addr = typedArray->dataPointerEither().cast(); return jit::AtomicOperations::compareExchangeSeqCst(addr + index, T(expected), @@ -2467,7 +2467,7 @@ static int32_t AtomicsExchange(TypedArrayObject* typedArray, size_t index, AutoUnsafeCallWithABI unsafe; MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - MOZ_ASSERT(index < typedArray->length().get()); + MOZ_ASSERT(index < typedArray->length()); SharedMem addr = typedArray->dataPointerEither().cast(); return jit::AtomicOperations::exchangeSeqCst(addr + index, T(value)); @@ -2498,7 +2498,7 @@ static int32_t AtomicsAdd(TypedArrayObject* typedArray, size_t index, AutoUnsafeCallWithABI unsafe; MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - MOZ_ASSERT(index < typedArray->length().get()); + MOZ_ASSERT(index < typedArray->length()); SharedMem addr = typedArray->dataPointerEither().cast(); return jit::AtomicOperations::fetchAddSeqCst(addr + index, T(value)); @@ -2529,7 +2529,7 @@ static int32_t AtomicsSub(TypedArrayObject* typedArray, size_t index, AutoUnsafeCallWithABI unsafe; MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - MOZ_ASSERT(index < typedArray->length().get()); + MOZ_ASSERT(index < typedArray->length()); SharedMem addr = typedArray->dataPointerEither().cast(); return jit::AtomicOperations::fetchSubSeqCst(addr + index, T(value)); @@ -2560,7 +2560,7 @@ static int32_t AtomicsAnd(TypedArrayObject* typedArray, size_t index, AutoUnsafeCallWithABI unsafe; MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - MOZ_ASSERT(index < typedArray->length().get()); + MOZ_ASSERT(index < typedArray->length()); SharedMem addr = typedArray->dataPointerEither().cast(); return jit::AtomicOperations::fetchAndSeqCst(addr + index, T(value)); @@ -2591,7 +2591,7 @@ static int32_t AtomicsOr(TypedArrayObject* typedArray, size_t index, AutoUnsafeCallWithABI unsafe; MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - MOZ_ASSERT(index < typedArray->length().get()); + MOZ_ASSERT(index < typedArray->length()); SharedMem addr = typedArray->dataPointerEither().cast(); return jit::AtomicOperations::fetchOrSeqCst(addr + index, T(value)); @@ -2622,7 +2622,7 @@ static int32_t AtomicsXor(TypedArrayObject* typedArray, size_t index, AutoUnsafeCallWithABI unsafe; MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - MOZ_ASSERT(index < typedArray->length().get()); + MOZ_ASSERT(index < typedArray->length()); SharedMem addr = typedArray->dataPointerEither().cast(); return jit::AtomicOperations::fetchXorSeqCst(addr + index, T(value)); @@ -2652,7 +2652,7 @@ static BigInt* AtomicAccess64(JSContext* cx, TypedArrayObject* typedArray, size_t index, AtomicOp op, Args... args) { MOZ_ASSERT(Scalar::isBigIntType(typedArray->type())); MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - MOZ_ASSERT(index < typedArray->length().get()); + MOZ_ASSERT(index < typedArray->length()); if (typedArray->type() == Scalar::BigInt64) { SharedMem addr = typedArray->dataPointerEither().cast(); @@ -2670,7 +2670,7 @@ static auto AtomicAccess64(TypedArrayObject* typedArray, size_t index, AtomicOp op, Args... args) { MOZ_ASSERT(Scalar::isBigIntType(typedArray->type())); MOZ_ASSERT(!typedArray->hasDetachedBuffer()); - MOZ_ASSERT(index < typedArray->length().get()); + MOZ_ASSERT(index < typedArray->length()); if (typedArray->type() == Scalar::BigInt64) { SharedMem addr = typedArray->dataPointerEither().cast(); diff --git a/js/src/jit/WarpCacheIRTranspiler.cpp b/js/src/jit/WarpCacheIRTranspiler.cpp index 5db3fdcb1760..a4f50419ad41 100644 --- a/js/src/jit/WarpCacheIRTranspiler.cpp +++ b/js/src/jit/WarpCacheIRTranspiler.cpp @@ -3642,7 +3642,7 @@ bool WarpCacheIRTranspiler::emitNewTypedArrayFromLengthResult( if (length->isConstant()) { int32_t len = length->toConstant()->toInt32(); if (len > 0 && - uint32_t(len) == templateObj->as().length().get()) { + uint32_t(len) == templateObj->as().length()) { auto* templateConst = constant(ObjectValue(*templateObj)); auto* obj = MNewTypedArray::New(alloc(), templateConst, heap); add(obj); diff --git a/js/src/jsapi-tests/testArrayBufferView.cpp b/js/src/jsapi-tests/testArrayBufferView.cpp index 43b7ff527962..7275d8de5e73 100644 --- a/js/src/jsapi-tests/testArrayBufferView.cpp +++ b/js/src/jsapi-tests/testArrayBufferView.cpp @@ -122,7 +122,7 @@ bool TestViewType(JSContext* cx) { AutoRealm ar(cx, otherGlobal); buffer = JS::NewArrayBuffer(cx, 8); CHECK(buffer); - CHECK(buffer->as().byteLength().get() == 8); + CHECK(buffer->as().byteLength() == 8); } CHECK(buffer->compartment() == otherGlobal->compartment()); CHECK(JS_WrapObject(cx, &buffer)); diff --git a/js/src/shell/OSObject.cpp b/js/src/shell/OSObject.cpp index f8f506228756..d97d7deaaed1 100644 --- a/js/src/shell/OSObject.cpp +++ b/js/src/shell/OSObject.cpp @@ -480,7 +480,7 @@ static bool osfile_writeTypedArrayToFile(JSContext* cx, unsigned argc, return false; } void* buf = obj->dataPointerUnshared(); - size_t length = obj->length().get(); + size_t length = obj->length(); if (fwrite(buf, obj->bytesPerElement(), length, file) != length || !autoClose.release()) { filename = JS_EncodeStringToUTF8(cx, str); diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 919daf83c004..32aded8303b9 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -2254,7 +2254,7 @@ static uint8_t* CacheEntry_getBytecode(JSContext* cx, HandleObject cache, } ArrayBufferObject* arrayBuffer = &v.toObject().as(); - *length = arrayBuffer->byteLength().get(); + *length = arrayBuffer->byteLength(); return arrayBuffer->dataPointer(); } @@ -2267,8 +2267,7 @@ static bool CacheEntry_setBytecode(JSContext* cx, HandleObject cache, BufferContents contents = BufferContents::createMalloced(buffer); Rooted arrayBuffer( - cx, - ArrayBufferObject::createForContents(cx, BufferSize(length), contents)); + cx, ArrayBufferObject::createForContents(cx, length, contents)); if (!arrayBuffer) { return false; } @@ -7584,7 +7583,7 @@ struct SharedObjectMailbox { union Value { struct { SharedArrayRawBuffer* buffer; - BufferSize length; + size_t length; } sarb; JS::WasmModule* module; double number; @@ -7655,7 +7654,7 @@ static bool GetSharedObject(JSContext* cx, unsigned argc, Value* vp) { // incremented prior to the SAB creation. SharedArrayRawBuffer* buf = mbx->val.sarb.buffer; - BufferSize length = mbx->val.sarb.length; + size_t length = mbx->val.sarb.length; if (!buf->addReference()) { JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_SC_SAB_REFCNT_OFLO); @@ -7892,7 +7891,7 @@ class StreamCacheEntryObject : public NativeObject { auto& bytes = args.thisv().toObject().as().cache().bytes(); RootedArrayBufferObject buffer( - cx, ArrayBufferObject::createZeroed(cx, BufferSize(bytes.length()))); + cx, ArrayBufferObject::createZeroed(cx, bytes.length())); if (!buffer) { return false; } diff --git a/js/src/vm/ArrayBufferObject-inl.h b/js/src/vm/ArrayBufferObject-inl.h index b982aa9bfa86..bba9174949a2 100644 --- a/js/src/vm/ArrayBufferObject-inl.h +++ b/js/src/vm/ArrayBufferObject-inl.h @@ -33,7 +33,7 @@ inline bool ArrayBufferObjectMaybeShared::isDetached() const { return false; } -inline BufferSize ArrayBufferObjectMaybeShared::byteLength() const { +inline size_t ArrayBufferObjectMaybeShared::byteLength() const { if (this->is()) { return this->as().byteLength(); } diff --git a/js/src/vm/ArrayBufferObject.cpp b/js/src/vm/ArrayBufferObject.cpp index 7dc4ce69cad4..4daed2ca9452 100644 --- a/js/src/vm/ArrayBufferObject.cpp +++ b/js/src/vm/ArrayBufferObject.cpp @@ -349,7 +349,7 @@ MOZ_ALWAYS_INLINE bool ArrayBufferObject::byteLengthGetterImpl( JSContext* cx, const CallArgs& args) { MOZ_ASSERT(IsArrayBuffer(args.thisv())); auto* buffer = &args.thisv().toObject().as(); - args.rval().setNumber(buffer->byteLength().get()); + args.rval().setNumber(buffer->byteLength()); return true; } @@ -399,7 +399,7 @@ bool ArrayBufferObject::class_constructor(JSContext* cx, unsigned argc, } // 24.1.1.1, steps 1 and 4-6. - JSObject* bufobj = createZeroed(cx, BufferSize(byteLength), proto); + JSObject* bufobj = createZeroed(cx, byteLength, proto); if (!bufobj) { return false; } @@ -410,15 +410,15 @@ bool ArrayBufferObject::class_constructor(JSContext* cx, unsigned argc, using ArrayBufferContents = UniquePtr; static ArrayBufferContents AllocateUninitializedArrayBufferContents( - JSContext* cx, BufferSize nbytes) { + JSContext* cx, size_t nbytes) { // First attempt a normal allocation. - uint8_t* p = cx->maybe_pod_arena_malloc(js::ArrayBufferContentsArena, - nbytes.get()); + uint8_t* p = + cx->maybe_pod_arena_malloc(js::ArrayBufferContentsArena, nbytes); if (MOZ_UNLIKELY(!p)) { // Otherwise attempt a large allocation, calling the // large-allocation-failure callback if necessary. p = static_cast(cx->runtime()->onOutOfMemoryCanGC( - js::AllocFunction::Malloc, js::ArrayBufferContentsArena, nbytes.get())); + js::AllocFunction::Malloc, js::ArrayBufferContentsArena, nbytes)); if (!p) { ReportOutOfMemory(cx); } @@ -428,15 +428,15 @@ static ArrayBufferContents AllocateUninitializedArrayBufferContents( } static ArrayBufferContents AllocateArrayBufferContents(JSContext* cx, - BufferSize nbytes) { + size_t nbytes) { // First attempt a normal allocation. - uint8_t* p = cx->maybe_pod_arena_calloc(js::ArrayBufferContentsArena, - nbytes.get()); + uint8_t* p = + cx->maybe_pod_arena_calloc(js::ArrayBufferContentsArena, nbytes); if (MOZ_UNLIKELY(!p)) { // Otherwise attempt a large allocation, calling the // large-allocation-failure callback if necessary. p = static_cast(cx->runtime()->onOutOfMemoryCanGC( - js::AllocFunction::Calloc, js::ArrayBufferContentsArena, nbytes.get())); + js::AllocFunction::Calloc, js::ArrayBufferContentsArena, nbytes)); if (!p) { ReportOutOfMemory(cx); } @@ -450,7 +450,7 @@ static ArrayBufferContents NewCopiedBufferContents( ArrayBufferContents dataCopy = AllocateUninitializedArrayBufferContents(cx, buffer->byteLength()); if (dataCopy) { - if (auto count = buffer->byteLength().get()) { + if (auto count = buffer->byteLength()) { memcpy(dataCopy.get(), buffer->dataPointer(), count); } } @@ -487,7 +487,7 @@ void ArrayBufferObject::detach(JSContext* cx, buffer->setDataPointer(BufferContents::createNoData()); } - buffer->setByteLength(BufferSize(0)); + buffer->setByteLength(0); buffer->setIsDetached(); } @@ -561,16 +561,16 @@ void ArrayBufferObject::detach(JSContext* cx, * */ -[[nodiscard]] bool WasmArrayRawBuffer::growToSizeInPlace(BufferSize oldSize, - BufferSize newSize) { - MOZ_ASSERT(newSize.get() >= oldSize.get()); - MOZ_ASSERT_IF(maxSize(), newSize.get() <= maxSize().value()); - MOZ_ASSERT(newSize.get() <= mappedSize()); +[[nodiscard]] bool WasmArrayRawBuffer::growToSizeInPlace(size_t oldSize, + size_t newSize) { + MOZ_ASSERT(newSize >= oldSize); + MOZ_ASSERT_IF(maxSize(), newSize <= maxSize().value()); + MOZ_ASSERT(newSize <= mappedSize()); - size_t delta = newSize.get() - oldSize.get(); + size_t delta = newSize - oldSize; MOZ_ASSERT(delta % wasm::PageSize == 0); - uint8_t* dataEnd = dataPointer() + oldSize.get(); + uint8_t* dataEnd = dataPointer() + oldSize; MOZ_ASSERT(uintptr_t(dataEnd) % gc::SystemPageSize() == 0); if (delta && !CommitBufferMemory(dataEnd, delta)) { @@ -611,23 +611,21 @@ void WasmArrayRawBuffer::tryGrowMaxSizeInPlace(uint64_t deltaMaxSize) { } /* static */ -WasmArrayRawBuffer* WasmArrayRawBuffer::Allocate(BufferSize numBytes, +WasmArrayRawBuffer* WasmArrayRawBuffer::Allocate(size_t numBytes, const Maybe& maxSize, const Maybe& mapped) { - size_t mappedSize = - mapped.isSome() - ? *mapped - : wasm::ComputeMappedSize(maxSize.valueOr(numBytes.get())); + size_t mappedSize = mapped.isSome() + ? *mapped + : wasm::ComputeMappedSize(maxSize.valueOr(numBytes)); MOZ_RELEASE_ASSERT(mappedSize <= SIZE_MAX - gc::SystemPageSize()); - MOZ_RELEASE_ASSERT(numBytes.get() <= SIZE_MAX - gc::SystemPageSize()); - MOZ_RELEASE_ASSERT(numBytes.get() <= - maxSize.valueOr(wasm::MaxMemory32Bytes())); - MOZ_ASSERT(numBytes.get() % gc::SystemPageSize() == 0); + MOZ_RELEASE_ASSERT(numBytes <= SIZE_MAX - gc::SystemPageSize()); + MOZ_RELEASE_ASSERT(numBytes <= maxSize.valueOr(wasm::MaxMemory32Bytes())); + MOZ_ASSERT(numBytes % gc::SystemPageSize() == 0); MOZ_ASSERT(mappedSize % gc::SystemPageSize() == 0); uint64_t mappedSizeWithHeader = mappedSize + gc::SystemPageSize(); - uint64_t numBytesWithHeader = numBytes.get() + gc::SystemPageSize(); + uint64_t numBytesWithHeader = numBytes + gc::SystemPageSize(); void* data = MapBufferMemory((size_t)mappedSizeWithHeader, (size_t)numBytesWithHeader); @@ -715,8 +713,8 @@ static bool CreateSpecificWasmBuffer32( } #endif - RawbufT* buffer = RawbufT::Allocate(BufferSize(size_t(initialSize)), - clampedMaxSize, mappedSize); + RawbufT* buffer = + RawbufT::Allocate(size_t(initialSize), clampedMaxSize, mappedSize); if (!buffer) { if (useHugeMemory) { WarnNumberASCII(cx, JSMSG_WASM_HUGE_MEMORY_FAILED); @@ -741,8 +739,8 @@ static bool CreateSpecificWasmBuffer32( for (; cur > initialSize; cur /= 2) { uint64_t clampedMaxSize = RoundUp(cur, wasm::PageSize); - buffer = RawbufT::Allocate(BufferSize(size_t(initialSize)), - Some(clampedMaxSize), mappedSize); + buffer = RawbufT::Allocate(size_t(initialSize), Some(clampedMaxSize), + mappedSize); if (buffer) { break; } @@ -764,8 +762,7 @@ static bool CreateSpecificWasmBuffer32( // ObjT::createFromNewRawBuffer assumes ownership of |buffer| even in case // of failure. RootedArrayBufferObjectMaybeShared object( - cx, ObjT::createFromNewRawBuffer(cx, buffer, - BufferSize(size_t(initialSize)))); + cx, ObjT::createFromNewRawBuffer(cx, buffer, size_t(initialSize))); if (!object) { return false; } @@ -830,9 +827,9 @@ bool js::CreateWasmBuffer32(JSContext* cx, uint64_t initialSize, } bool ArrayBufferObject::prepareForAsmJS() { - MOZ_ASSERT(byteLength().get() % wasm::PageSize == 0, + MOZ_ASSERT(byteLength() % wasm::PageSize == 0, "prior size checking should have guaranteed page-size multiple"); - MOZ_ASSERT(byteLength().get() > 0, + MOZ_ASSERT(byteLength() > 0, "prior size checking should have excluded empty buffers"); switch (bufferKind()) { @@ -905,7 +902,7 @@ void ArrayBufferObject::releaseData(JSFreeOp* fop) { // Inline data doesn't require releasing. break; case MALLOCED: - fop->free_(this, dataPointer(), byteLength().get(), + fop->free_(this, dataPointer(), byteLength(), MemoryUse::ArrayBufferContents); break; case NO_DATA: @@ -916,14 +913,13 @@ void ArrayBufferObject::releaseData(JSFreeOp* fop) { // User-owned data is released by, well, the user. break; case MAPPED: - gc::DeallocateMappedContent(dataPointer(), byteLength().get()); + gc::DeallocateMappedContent(dataPointer(), byteLength()); fop->removeCellMemory(this, associatedBytes(), MemoryUse::ArrayBufferContents); break; case WASM: WasmArrayRawBuffer::Release(dataPointer()); - fop->removeCellMemory(this, byteLength().get(), - MemoryUse::ArrayBufferContents); + fop->removeCellMemory(this, byteLength(), MemoryUse::ArrayBufferContents); break; case EXTERNAL: if (freeInfo()->freeFunc) { @@ -952,30 +948,30 @@ void ArrayBufferObject::setDataPointer(BufferContents contents) { } } -BufferSize ArrayBufferObject::byteLength() const { - return BufferSize(size_t(getFixedSlot(BYTE_LENGTH_SLOT).toPrivate())); +size_t ArrayBufferObject::byteLength() const { + return size_t(getFixedSlot(BYTE_LENGTH_SLOT).toPrivate()); } inline size_t ArrayBufferObject::associatedBytes() const { if (bufferKind() == MALLOCED) { - return byteLength().get(); + return byteLength(); } if (bufferKind() == MAPPED) { - return RoundUp(byteLength().get(), js::gc::SystemPageSize()); + return RoundUp(byteLength(), js::gc::SystemPageSize()); } MOZ_CRASH("Unexpected buffer kind"); } -void ArrayBufferObject::setByteLength(BufferSize length) { - MOZ_ASSERT(length.get() <= maxBufferByteLength()); - setFixedSlot(BYTE_LENGTH_SLOT, PrivateValue(length.get())); +void ArrayBufferObject::setByteLength(size_t length) { + MOZ_ASSERT(length <= maxBufferByteLength()); + setFixedSlot(BYTE_LENGTH_SLOT, PrivateValue(length)); } size_t ArrayBufferObject::wasmMappedSize() const { if (isWasm()) { return contents().wasmBuffer()->mappedSize(); } - return byteLength().get(); + return byteLength(); } size_t js::WasmArrayBufferMappedSize(const ArrayBufferObjectMaybeShared* buf) { @@ -989,7 +985,7 @@ Maybe ArrayBufferObject::wasmMaxSize() const { if (isWasm()) { return contents().wasmBuffer()->maxSize(); } - return Some(byteLength().get()); + return Some(byteLength()); } Maybe js::WasmArrayBufferMaxSize( @@ -1011,7 +1007,7 @@ static void CheckStealPreconditions(Handle buffer, /* static */ bool ArrayBufferObject::wasmGrowToSizeInPlace( - BufferSize newSize, HandleArrayBufferObject oldBuf, + size_t newSize, HandleArrayBufferObject oldBuf, MutableHandleArrayBufferObject newBuf, JSContext* cx) { CheckStealPreconditions(oldBuf, cx); @@ -1023,7 +1019,7 @@ bool ArrayBufferObject::wasmGrowToSizeInPlace( // last fallible operation. // Note, caller must guard on limit appropriate for the memory type - if (newSize.get() > ArrayBufferObject::maxBufferByteLength()) { + if (newSize > ArrayBufferObject::maxBufferByteLength()) { return false; } @@ -1047,31 +1043,31 @@ bool ArrayBufferObject::wasmGrowToSizeInPlace( oldBuf->setDataPointer(BufferContents::createNoData()); // Detach |oldBuf| now that doing so won't release |oldContents|. - RemoveCellMemory(oldBuf, oldBuf->byteLength().get(), + RemoveCellMemory(oldBuf, oldBuf->byteLength(), MemoryUse::ArrayBufferContents); ArrayBufferObject::detach(cx, oldBuf); // Set |newBuf|'s contents to |oldBuf|'s original contents. newBuf->initialize(newSize, oldContents); - AddCellMemory(newBuf, newSize.get(), MemoryUse::ArrayBufferContents); + AddCellMemory(newBuf, newSize, MemoryUse::ArrayBufferContents); return true; } /* static */ bool ArrayBufferObject::wasmMovingGrowToSize( - BufferSize newSize, HandleArrayBufferObject oldBuf, + size_t newSize, HandleArrayBufferObject oldBuf, MutableHandleArrayBufferObject newBuf, JSContext* cx) { // On failure, do not throw and ensure that the original buffer is // unmodified and valid. // Note, caller must guard on the limit appropriate to the memory type - if (newSize.get() > ArrayBufferObject::maxBufferByteLength()) { + if (newSize > ArrayBufferObject::maxBufferByteLength()) { return false; } - if (wasm::ComputeMappedSize(newSize.get()) <= oldBuf->wasmMappedSize() || - oldBuf->contents().wasmBuffer()->extendMappedSize(newSize.get())) { + if (wasm::ComputeMappedSize(newSize) <= oldBuf->wasmMappedSize() || + oldBuf->contents().wasmBuffer()->extendMappedSize(newSize)) { return wasmGrowToSizeInPlace(newSize, oldBuf, newBuf, cx); } @@ -1087,14 +1083,13 @@ bool ArrayBufferObject::wasmMovingGrowToSize( return false; } - AddCellMemory(newBuf, newSize.get(), MemoryUse::ArrayBufferContents); + AddCellMemory(newBuf, newSize, MemoryUse::ArrayBufferContents); BufferContents contents = BufferContents::createWasm(newRawBuf->dataPointer()); - newBuf->initialize(BufferSize(newSize), contents); + newBuf->initialize(newSize, contents); - memcpy(newBuf->dataPointer(), oldBuf->dataPointer(), - oldBuf->byteLength().get()); + memcpy(newBuf->dataPointer(), oldBuf->dataPointer(), oldBuf->byteLength()); ArrayBufferObject::detach(cx, oldBuf); return true; } @@ -1121,14 +1116,14 @@ static inline js::gc::AllocKind GetArrayBufferGCObjectKind(size_t numSlots) { } ArrayBufferObject* ArrayBufferObject::createForContents( - JSContext* cx, BufferSize nbytes, BufferContents contents) { + JSContext* cx, size_t nbytes, BufferContents contents) { MOZ_ASSERT(contents); MOZ_ASSERT(contents.kind() != INLINE_DATA); MOZ_ASSERT(contents.kind() != NO_DATA); MOZ_ASSERT(contents.kind() != WASM); // 24.1.1.1, step 3 (Inlined 6.2.6.1 CreateByteDataBlock, step 2). - if (!CheckArrayBufferTooLarge(cx, nbytes.get())) { + if (!CheckArrayBufferTooLarge(cx, nbytes)) { return nullptr; } @@ -1150,9 +1145,9 @@ ArrayBufferObject* ArrayBufferObject::createForContents( nslots += freeInfoSlots; } else { // The ABO is taking ownership, so account the bytes against the zone. - nAllocated = nbytes.get(); + nAllocated = nbytes; if (contents.kind() == MAPPED) { - nAllocated = RoundUp(nbytes.get(), js::gc::SystemPageSize()); + nAllocated = RoundUp(nbytes, js::gc::SystemPageSize()); } else { MOZ_ASSERT(contents.kind() == MALLOCED, "should have handled all possible callers' kinds"); @@ -1186,9 +1181,9 @@ ArrayBufferObject* ArrayBufferObject::createForContents( template /* static */ std::tuple ArrayBufferObject::createBufferAndData( - JSContext* cx, BufferSize nbytes, AutoSetNewObjectMetadata&, + JSContext* cx, size_t nbytes, AutoSetNewObjectMetadata&, JS::Handle proto /* = nullptr */) { - MOZ_ASSERT(nbytes.get() <= ArrayBufferObject::maxBufferByteLength(), + MOZ_ASSERT(nbytes <= ArrayBufferObject::maxBufferByteLength(), "caller must validate the byte count it passes"); // Try fitting the data inline with the object by repurposing fixed-slot @@ -1196,9 +1191,9 @@ ArrayBufferObject::createBufferAndData( // exceed the maximum number of fixed slots! size_t nslots = JSCLASS_RESERVED_SLOTS(&class_); ArrayBufferContents data; - if (nbytes.get() <= MaxInlineBytes) { - int newSlots = HowMany(nbytes.get(), sizeof(Value)); - MOZ_ASSERT(int(nbytes.get()) <= newSlots * int(sizeof(Value))); + if (nbytes <= MaxInlineBytes) { + int newSlots = HowMany(nbytes, sizeof(Value)); + MOZ_ASSERT(int(nbytes) <= newSlots * int(sizeof(Value))); nslots += newSlots; } else { @@ -1227,12 +1222,11 @@ ArrayBufferObject::createBufferAndData( if (data) { toFill = data.release(); buffer->initialize(nbytes, BufferContents::createMalloced(toFill)); - AddCellMemory(buffer, nbytes.get(), MemoryUse::ArrayBufferContents); + AddCellMemory(buffer, nbytes, MemoryUse::ArrayBufferContents); } else { - toFill = - static_cast(buffer->initializeToInlineData(nbytes.get())); + toFill = static_cast(buffer->initializeToInlineData(nbytes)); if constexpr (FillType == FillContents::Zero) { - memset(toFill, 0, nbytes.get()); + memset(toFill, 0, nbytes); } } @@ -1247,7 +1241,7 @@ ArrayBufferObject::createBufferAndData( return nullptr; } - BufferSize nbytes = unwrappedArrayBuffer->byteLength(); + size_t nbytes = unwrappedArrayBuffer->byteLength(); AutoSetNewObjectMetadata metadata(cx); auto [buffer, toFill] = createBufferAndData( @@ -1256,15 +1250,15 @@ ArrayBufferObject::createBufferAndData( return nullptr; } - std::uninitialized_copy_n(unwrappedArrayBuffer->dataPointer(), nbytes.get(), + std::uninitialized_copy_n(unwrappedArrayBuffer->dataPointer(), nbytes, toFill); return buffer; } ArrayBufferObject* ArrayBufferObject::createZeroed( - JSContext* cx, BufferSize nbytes, HandleObject proto /* = nullptr */) { + JSContext* cx, size_t nbytes, HandleObject proto /* = nullptr */) { // 24.1.1.1, step 3 (Inlined 6.2.6.1 CreateByteDataBlock, step 2). - if (!CheckArrayBufferTooLarge(cx, nbytes.get())) { + if (!CheckArrayBufferTooLarge(cx, nbytes)) { return nullptr; } @@ -1282,12 +1276,12 @@ ArrayBufferObject* ArrayBufferObject::createEmpty(JSContext* cx) { return nullptr; } - obj->initialize(BufferSize(0), BufferContents::createNoData()); + obj->initialize(0, BufferContents::createNoData()); return obj; } ArrayBufferObject* ArrayBufferObject::createFromNewRawBuffer( - JSContext* cx, WasmArrayRawBuffer* rawBuffer, BufferSize initialSize) { + JSContext* cx, WasmArrayRawBuffer* rawBuffer, size_t initialSize) { AutoSetNewObjectMetadata metadata(cx); ArrayBufferObject* buffer = NewBuiltinClassInstance(cx); if (!buffer) { @@ -1295,7 +1289,7 @@ ArrayBufferObject* ArrayBufferObject::createFromNewRawBuffer( return nullptr; } - MOZ_ASSERT(initialSize.get() == rawBuffer->byteLength().get()); + MOZ_ASSERT(initialSize == rawBuffer->byteLength()); buffer->setByteLength(initialSize); buffer->setFlags(0); @@ -1304,7 +1298,7 @@ ArrayBufferObject* ArrayBufferObject::createFromNewRawBuffer( auto contents = BufferContents::createWasm(rawBuffer->dataPointer()); buffer->setDataPointer(contents); - AddCellMemory(buffer, initialSize.get(), MemoryUse::ArrayBufferContents); + AddCellMemory(buffer, initialSize, MemoryUse::ArrayBufferContents); return buffer; } @@ -1318,7 +1312,7 @@ ArrayBufferObject* ArrayBufferObject::createFromNewRawBuffer( uint8_t* stolenData = buffer->dataPointer(); MOZ_ASSERT(stolenData); - RemoveCellMemory(buffer, buffer->byteLength().get(), + RemoveCellMemory(buffer, buffer->byteLength(), MemoryUse::ArrayBufferContents); // Overwrite the old data pointer *without* releasing the contents @@ -1448,13 +1442,12 @@ void ArrayBufferObject::addSizeOfExcludingThis( // not this view. break; case MAPPED: - info->objectsNonHeapElementsNormal += buffer.byteLength().get(); + info->objectsNonHeapElementsNormal += buffer.byteLength(); break; case WASM: - info->objectsNonHeapElementsWasm += buffer.byteLength().get(); - MOZ_ASSERT(buffer.wasmMappedSize() >= buffer.byteLength().get()); - info->wasmGuardPages += - buffer.wasmMappedSize() - buffer.byteLength().get(); + info->objectsNonHeapElementsWasm += buffer.byteLength(); + MOZ_ASSERT(buffer.wasmMappedSize() >= buffer.byteLength()); + info->wasmGuardPages += buffer.wasmMappedSize() - buffer.byteLength(); break; case BAD1: MOZ_CRASH("bad bufferKind()"); @@ -1471,10 +1464,10 @@ void ArrayBufferObject::copyData(Handle toBuffer, size_t toIndex, Handle fromBuffer, size_t fromIndex, size_t count) { - MOZ_ASSERT(toBuffer->byteLength().get() >= count); - MOZ_ASSERT(toBuffer->byteLength().get() >= toIndex + count); - MOZ_ASSERT(fromBuffer->byteLength().get() >= fromIndex); - MOZ_ASSERT(fromBuffer->byteLength().get() >= fromIndex + count); + MOZ_ASSERT(toBuffer->byteLength() >= count); + MOZ_ASSERT(toBuffer->byteLength() >= toIndex + count); + MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex); + MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex + count); memcpy(toBuffer->dataPointer() + toIndex, fromBuffer->dataPointer() + fromIndex, count); @@ -1651,7 +1644,7 @@ bool JSObject::is() const { JS_FRIEND_API size_t JS::GetArrayBufferByteLength(JSObject* obj) { ArrayBufferObject* aobj = obj->maybeUnwrapAs(); - return aobj ? aobj->byteLength().get() : 0; + return aobj ? aobj->byteLength() : 0; } JS_FRIEND_API uint8_t* JS::GetArrayBufferData(JSObject* obj, @@ -1716,7 +1709,7 @@ JS_FRIEND_API JSObject* JS::NewArrayBuffer(JSContext* cx, size_t nbytes) { AssertHeapIsIdle(); CHECK_THREAD(cx); - return ArrayBufferObject::createZeroed(cx, BufferSize(nbytes)); + return ArrayBufferObject::createZeroed(cx, nbytes); } JS_PUBLIC_API JSObject* JS::NewArrayBufferWithContents(JSContext* cx, @@ -1728,13 +1721,13 @@ JS_PUBLIC_API JSObject* JS::NewArrayBufferWithContents(JSContext* cx, if (!data) { // Don't pass nulled contents to |createForContents|. - return ArrayBufferObject::createZeroed(cx, BufferSize(0)); + return ArrayBufferObject::createZeroed(cx, 0); } using BufferContents = ArrayBufferObject::BufferContents; BufferContents contents = BufferContents::createMalloced(data); - return ArrayBufferObject::createForContents(cx, BufferSize(nbytes), contents); + return ArrayBufferObject::createForContents(cx, nbytes, contents); } JS_PUBLIC_API JSObject* JS::CopyArrayBuffer(JSContext* cx, @@ -1766,7 +1759,7 @@ JS_PUBLIC_API JSObject* JS::NewExternalArrayBuffer( BufferContents contents = BufferContents::createExternal(data, freeFunc, freeUserData); - return ArrayBufferObject::createForContents(cx, BufferSize(nbytes), contents); + return ArrayBufferObject::createForContents(cx, nbytes, contents); } JS_PUBLIC_API JSObject* JS::NewArrayBufferWithUserOwnedContents(JSContext* cx, @@ -1780,7 +1773,7 @@ JS_PUBLIC_API JSObject* JS::NewArrayBufferWithUserOwnedContents(JSContext* cx, using BufferContents = ArrayBufferObject::BufferContents; BufferContents contents = BufferContents::createUserOwned(data); - return ArrayBufferObject::createForContents(cx, BufferSize(nbytes), contents); + return ArrayBufferObject::createForContents(cx, nbytes, contents); } JS_FRIEND_API bool JS::IsArrayBufferObject(JSObject* obj) { @@ -1841,7 +1834,7 @@ JS_PUBLIC_API JSObject* JS::NewMappedArrayBufferWithContents(JSContext* cx, using BufferContents = ArrayBufferObject::BufferContents; BufferContents contents = BufferContents::createMapped(data); - return ArrayBufferObject::createForContents(cx, BufferSize(nbytes), contents); + return ArrayBufferObject::createForContents(cx, nbytes, contents); } JS_PUBLIC_API void* JS::CreateMappedArrayBufferContents(int fd, size_t offset, @@ -1871,7 +1864,7 @@ JS_FRIEND_API JSObject* JS::GetObjectAsArrayBuffer(JSObject* obj, return nullptr; } - *length = aobj->byteLength().get(); + *length = aobj->byteLength(); *data = aobj->dataPointer(); return aobj; @@ -1882,7 +1875,7 @@ JS_FRIEND_API void JS::GetArrayBufferLengthAndData(JSObject* obj, bool* isSharedMemory, uint8_t** data) { auto& aobj = obj->as(); - *length = aobj.byteLength().get(); + *length = aobj.byteLength(); *data = aobj.dataPointer(); *isSharedMemory = false; } diff --git a/js/src/vm/ArrayBufferObject.h b/js/src/vm/ArrayBufferObject.h index 308466b3fcd9..5ff00161a599 100644 --- a/js/src/vm/ArrayBufferObject.h +++ b/js/src/vm/ArrayBufferObject.h @@ -16,7 +16,6 @@ #include "gc/ZoneAllocator.h" #include "js/ArrayBuffer.h" #include "js/GCHashTable.h" -#include "vm/BufferSize.h" #include "vm/JSObject.h" #include "vm/Runtime.h" #include "vm/SharedMem.h" @@ -111,7 +110,7 @@ size_t WasmArrayBufferMappedSize(const ArrayBufferObjectMaybeShared* buf); class ArrayBufferObjectMaybeShared : public NativeObject { public: - inline BufferSize byteLength() const; + inline size_t byteLength() const; inline bool isDetached() const; inline SharedMem dataPointerEither(); @@ -247,7 +246,7 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared { template static std::tuple createBufferAndData( - JSContext* cx, BufferSize nbytes, AutoSetNewObjectMetadata&, + JSContext* cx, size_t nbytes, AutoSetNewObjectMetadata&, JS::Handle proto = nullptr); public: @@ -334,13 +333,13 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared { return native == byteLengthGetter; } - static ArrayBufferObject* createForContents(JSContext* cx, BufferSize nbytes, + static ArrayBufferObject* createForContents(JSContext* cx, size_t nbytes, BufferContents contents); static ArrayBufferObject* copy( JSContext* cx, JS::Handle unwrappedArrayBuffer); - static ArrayBufferObject* createZeroed(JSContext* cx, BufferSize nbytes, + static ArrayBufferObject* createZeroed(JSContext* cx, size_t nbytes, HandleObject proto = nullptr); // Create an ArrayBufferObject that is safely finalizable and can later be @@ -352,7 +351,7 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared { // is deallocated. static ArrayBufferObject* createFromNewRawBuffer(JSContext* cx, WasmArrayRawBuffer* buffer, - BufferSize initialSize); + size_t initialSize); static void copyData(Handle toBuffer, size_t toIndex, Handle fromBuffer, size_t fromIndex, @@ -404,7 +403,7 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared { public: uint8_t* dataPointer() const; SharedMem dataPointerShared() const; - BufferSize byteLength() const; + size_t byteLength() const; BufferContents contents() const { if (isExternal()) { @@ -444,10 +443,10 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared { size_t wasmMappedSize() const; mozilla::Maybe wasmMaxSize() const; [[nodiscard]] static bool wasmGrowToSizeInPlace( - BufferSize newSize, Handle oldBuf, + size_t newSize, Handle oldBuf, MutableHandle newBuf, JSContext* cx); [[nodiscard]] static bool wasmMovingGrowToSize( - BufferSize newSize, Handle oldBuf, + size_t newSize, Handle oldBuf, MutableHandle newBuf, JSContext* cx); static void finalize(JSFreeOp* fop, JSObject* obj); @@ -457,7 +456,7 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared { protected: void setDataPointer(BufferContents contents); - void setByteLength(BufferSize length); + void setByteLength(size_t length); size_t associatedBytes() const; @@ -473,7 +472,7 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared { setFlags(flags() | FOR_ASMJS); } - void initialize(BufferSize byteLength, BufferContents contents) { + void initialize(size_t byteLength, BufferContents contents) { setByteLength(byteLength); setFlags(0); setFirstView(nullptr); @@ -482,7 +481,7 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared { void* initializeToInlineData(size_t byteLength) { void* data = inlineDataPointer(); - initialize(BufferSize(byteLength), BufferContents::createInlineData(data)); + initialize(byteLength, BufferContents::createInlineData(data)); return data; } }; @@ -577,17 +576,17 @@ class MutableWrappedPtrOperations class WasmArrayRawBuffer { mozilla::Maybe maxSize_; size_t mappedSize_; // Not including the header page - BufferSize length_; + size_t length_; protected: WasmArrayRawBuffer(uint8_t* buffer, const mozilla::Maybe& maxSize, - size_t mappedSize, BufferSize length) + size_t mappedSize, size_t length) : maxSize_(maxSize), mappedSize_(mappedSize), length_(length) { MOZ_ASSERT(buffer == dataPointer()); } public: - static WasmArrayRawBuffer* Allocate(BufferSize numBytes, + static WasmArrayRawBuffer* Allocate(size_t numBytes, const mozilla::Maybe& maxSize, const mozilla::Maybe& mappedSize); static void Release(void* mem); @@ -608,9 +607,9 @@ class WasmArrayRawBuffer { mozilla::Maybe maxSize() const { return maxSize_; } - BufferSize byteLength() const { return length_; } + size_t byteLength() const { return length_; } - [[nodiscard]] bool growToSizeInPlace(BufferSize oldSize, BufferSize newSize); + [[nodiscard]] bool growToSizeInPlace(size_t oldSize, size_t newSize); [[nodiscard]] bool extendMappedSize(uint64_t maxSize); diff --git a/js/src/vm/ArrayBufferObjectMaybeShared.cpp b/js/src/vm/ArrayBufferObjectMaybeShared.cpp index 5fcdbb222b0a..108a1d141aa7 100644 --- a/js/src/vm/ArrayBufferObjectMaybeShared.cpp +++ b/js/src/vm/ArrayBufferObjectMaybeShared.cpp @@ -32,12 +32,12 @@ JS_PUBLIC_API void JS::GetArrayBufferMaybeSharedLengthAndData( if (obj->is()) { auto* buffer = &obj->as(); - *length = buffer->byteLength().get(); + *length = buffer->byteLength(); *data = buffer->dataPointerShared().unwrap(); *isSharedMemory = true; } else { auto* buffer = &obj->as(); - *length = buffer->byteLength().get(); + *length = buffer->byteLength(); *data = buffer->dataPointer(); *isSharedMemory = false; } @@ -64,8 +64,8 @@ JS_PUBLIC_API bool JS::IsLargeArrayBufferMaybeShared(JSObject* obj) { obj = UnwrapArrayBufferMaybeShared(obj); MOZ_ASSERT(obj); size_t len = obj->is() - ? obj->as().byteLength().get() - : obj->as().byteLength().get(); + ? obj->as().byteLength() + : obj->as().byteLength(); return len > ArrayBufferObject::MaxByteLengthForSmallBuffer; #else // Large ArrayBuffers are not supported on 32-bit. diff --git a/js/src/vm/ArrayBufferViewObject.cpp b/js/src/vm/ArrayBufferViewObject.cpp index 5fd3af6a72be..06706b963174 100644 --- a/js/src/vm/ArrayBufferViewObject.cpp +++ b/js/src/vm/ArrayBufferViewObject.cpp @@ -35,15 +35,15 @@ void ArrayBufferViewObject::trace(JSTracer* trc, JSObject* objArg) { if (gc::MaybeForwardedObjectIs(&bufSlot.toObject())) { ArrayBufferObject& buf = gc::MaybeForwardedObjectAs(&bufSlot.toObject()); - BufferSize offset = obj->byteOffset(); + size_t offset = obj->byteOffset(); - MOZ_ASSERT_IF(buf.dataPointer() == nullptr, offset.get() == 0); + MOZ_ASSERT_IF(buf.dataPointer() == nullptr, offset == 0); // The data may or may not be inline with the buffer. The buffer // can only move during a compacting GC, in which case its // objectMoved hook has already updated the buffer's data pointer. size_t nfixed = obj->numFixedSlotsMaybeForwarded(); - obj->setPrivateUnbarriered(nfixed, buf.dataPointer() + offset.get()); + obj->setPrivateUnbarriered(nfixed, buf.dataPointer() + offset); } } } @@ -78,19 +78,17 @@ ArrayBufferObjectMaybeShared* ArrayBufferViewObject::bufferObject( bool ArrayBufferViewObject::init(JSContext* cx, ArrayBufferObjectMaybeShared* buffer, - BufferSize byteOffset, BufferSize length, + size_t byteOffset, size_t length, uint32_t bytesPerElement) { - MOZ_ASSERT_IF(!buffer, byteOffset.get() == 0); + MOZ_ASSERT_IF(!buffer, byteOffset == 0); MOZ_ASSERT_IF(buffer, !buffer->isDetached()); - MOZ_ASSERT(byteOffset.get() <= ArrayBufferObject::maxBufferByteLength()); - MOZ_ASSERT(length.get() <= ArrayBufferObject::maxBufferByteLength()); - MOZ_ASSERT(byteOffset.get() + length.get() <= - ArrayBufferObject::maxBufferByteLength()); + MOZ_ASSERT(byteOffset <= ArrayBufferObject::maxBufferByteLength()); + MOZ_ASSERT(length <= ArrayBufferObject::maxBufferByteLength()); + MOZ_ASSERT(byteOffset + length <= ArrayBufferObject::maxBufferByteLength()); - MOZ_ASSERT_IF( - is(), - length.get() <= TypedArrayObject::maxByteLength() / bytesPerElement); + MOZ_ASSERT_IF(is(), + length <= TypedArrayObject::maxByteLength() / bytesPerElement); // The isSharedMemory property is invariant. Self-hosting code that // sets BUFFER_SLOT or the private slot (if it does) must maintain it by @@ -99,26 +97,26 @@ bool ArrayBufferViewObject::init(JSContext* cx, setIsSharedMemory(); } - initFixedSlot(BYTEOFFSET_SLOT, PrivateValue(byteOffset.get())); - initFixedSlot(LENGTH_SLOT, PrivateValue(length.get())); + initFixedSlot(BYTEOFFSET_SLOT, PrivateValue(byteOffset)); + initFixedSlot(LENGTH_SLOT, PrivateValue(length)); initFixedSlot(BUFFER_SLOT, ObjectOrNullValue(buffer)); if (buffer) { SharedMem ptr = buffer->dataPointerEither(); - initDataPointer(ptr + byteOffset.get()); + initDataPointer(ptr + byteOffset); // Only ArrayBuffers used for inline typed objects can have // nursery-allocated data and we shouldn't see such buffers here. - MOZ_ASSERT_IF(buffer->byteLength().get() > 0, !cx->nursery().isInside(ptr)); + MOZ_ASSERT_IF(buffer->byteLength() > 0, !cx->nursery().isInside(ptr)); } else { MOZ_ASSERT(is()); - MOZ_ASSERT(length.get() * bytesPerElement <= + MOZ_ASSERT(length * bytesPerElement <= TypedArrayObject::INLINE_BUFFER_LIMIT); void* data = fixedData(TypedArrayObject::FIXED_DATA_START); initPrivate(data); - memset(data, 0, length.get() * bytesPerElement); + memset(data, 0, length * bytesPerElement); #ifdef DEBUG - if (length.get() == 0) { + if (length == 0) { uint8_t* elements = static_cast(data); elements[0] = ZeroLengthArrayData; } @@ -127,9 +125,9 @@ bool ArrayBufferViewObject::init(JSContext* cx, #ifdef DEBUG if (buffer) { - size_t viewByteLength = length.get() * bytesPerElement; - size_t viewByteOffset = byteOffset.get(); - size_t bufferByteLength = buffer->byteLength().get(); + size_t viewByteLength = length * bytesPerElement; + size_t viewByteOffset = byteOffset; + size_t bufferByteLength = buffer->byteLength(); // Unwraps are safe: both are for the pointer value. MOZ_ASSERT_IF(buffer->is(), buffer->dataPointerEither().unwrap(/*safe*/) <= @@ -193,7 +191,7 @@ JS_FRIEND_API uint8_t* JS_GetArrayBufferViewFixedData(JSObject* obj, if (view->is()) { TypedArrayObject* ta = &view->as(); if (ta->hasInlineElements()) { - size_t bytes = ta->byteLength().get(); + size_t bytes = ta->byteLength(); if (bytes > bufSize) { return nullptr; // Does not fit. } @@ -242,10 +240,10 @@ JS_FRIEND_API size_t JS_GetArrayBufferViewByteLength(JSObject* obj) { if (!obj) { return 0; } - BufferSize length = obj->is() - ? obj->as().byteLength() - : obj->as().byteLength(); - return length.get(); + size_t length = obj->is() + ? obj->as().byteLength() + : obj->as().byteLength(); + return length; } JS_FRIEND_API size_t JS_GetArrayBufferViewByteOffset(JSObject* obj) { @@ -253,10 +251,10 @@ JS_FRIEND_API size_t JS_GetArrayBufferViewByteOffset(JSObject* obj) { if (!obj) { return 0; } - BufferSize offset = obj->is() - ? obj->as().byteOffset() - : obj->as().byteOffset(); - return offset.get(); + size_t offset = obj->is() + ? obj->as().byteOffset() + : obj->as().byteOffset(); + return offset; } JS_FRIEND_API JSObject* JS_GetObjectAsArrayBufferView(JSObject* obj, @@ -278,10 +276,10 @@ JS_FRIEND_API void js::GetArrayBufferViewLengthAndData(JSObject* obj, uint8_t** data) { MOZ_ASSERT(obj->is()); - BufferSize byteLength = obj->is() - ? obj->as().byteLength() - : obj->as().byteLength(); - *length = byteLength.get(); + size_t byteLength = obj->is() + ? obj->as().byteLength() + : obj->as().byteLength(); + *length = byteLength; ArrayBufferViewObject& view = obj->as(); *isSharedMemory = view.isSharedMemory(); @@ -300,10 +298,10 @@ JS_PUBLIC_API bool JS::IsArrayBufferViewShared(JSObject* obj) { JS_FRIEND_API bool JS::IsLargeArrayBufferView(JSObject* obj) { #ifdef JS_64BIT obj = &obj->unwrapAs(); - BufferSize len = obj->is() - ? obj->as().byteLength() - : obj->as().byteLength(); - return len.get() > ArrayBufferObject::MaxByteLengthForSmallBuffer; + size_t len = obj->is() + ? obj->as().byteLength() + : obj->as().byteLength(); + return len > ArrayBufferObject::MaxByteLengthForSmallBuffer; #else // Large ArrayBuffers are not supported on 32-bit. MOZ_ASSERT(ArrayBufferObject::maxBufferByteLength() == diff --git a/js/src/vm/ArrayBufferViewObject.h b/js/src/vm/ArrayBufferViewObject.h index d9cc14bda5e9..a210ea317375 100644 --- a/js/src/vm/ArrayBufferViewObject.h +++ b/js/src/vm/ArrayBufferViewObject.h @@ -70,7 +70,7 @@ class ArrayBufferViewObject : public NativeObject { public: [[nodiscard]] bool init(JSContext* cx, ArrayBufferObjectMaybeShared* buffer, - BufferSize byteOffset, BufferSize length, + size_t byteOffset, size_t length, uint32_t bytesPerElement); static ArrayBufferObjectMaybeShared* bufferObject( @@ -148,12 +148,12 @@ class ArrayBufferViewObject : public NativeObject { return buffer->isDetached(); } - BufferSize byteOffset() const { - return BufferSize(size_t(getFixedSlot(BYTEOFFSET_SLOT).toPrivate())); + size_t byteOffset() const { + return size_t(getFixedSlot(BYTEOFFSET_SLOT).toPrivate()); } Value byteOffsetValue() const { - size_t offset = byteOffset().get(); + size_t offset = byteOffset(); return NumberValue(offset); } diff --git a/js/src/vm/BufferSize.h b/js/src/vm/BufferSize.h deleted file mode 100644 index 774b33c609d5..000000000000 --- a/js/src/vm/BufferSize.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: set ts=8 sts=2 et sw=2 tw=80: - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef vm_BufferSize_h -#define vm_BufferSize_h - -namespace js { -// Class wrapping an ArrayBuffer or ArrayBufferView byte offset or length. -class BufferSize { - size_t size_ = 0; - - public: - explicit BufferSize(size_t size) : size_(size) {} - - size_t get() const { return size_; } -}; - -} // namespace js - -#endif // vm_BufferSize_h diff --git a/js/src/vm/Iteration.cpp b/js/src/vm/Iteration.cpp index 08d1122bb9db..1016622173b7 100644 --- a/js/src/vm/Iteration.cpp +++ b/js/src/vm/Iteration.cpp @@ -215,7 +215,7 @@ static bool EnumerateNativeProperties(JSContext* cx, HandleNativeObject pobj, // Collect any typed array or shared typed array elements from this // object. if (pobj->is()) { - size_t len = pobj->as().length().get(); + size_t len = pobj->as().length(); // Fail early if the typed array is enormous, because this will be very // slow and will likely report OOM. This also means we don't need to diff --git a/js/src/vm/JSObject.cpp b/js/src/vm/JSObject.cpp index f4b5d7cfe271..5ac574ae856b 100644 --- a/js/src/vm/JSObject.cpp +++ b/js/src/vm/JSObject.cpp @@ -684,7 +684,7 @@ bool js::TestIntegrityLevel(JSContext* cx, HandleObject obj, // Typed array elements are configurable, writable properties, so if any // elements are present, the typed array can neither be sealed nor frozen. if (nobj->is() && - nobj->as().length().get() > 0) { + nobj->as().length() > 0) { *result = false; return true; } @@ -3535,7 +3535,7 @@ js::gc::AllocKind JSObject::allocKindForTenure( if (is() && !as().hasBuffer()) { gc::AllocKind allocKind; if (as().hasInlineElements()) { - size_t nbytes = as().byteLength().get(); + size_t nbytes = as().byteLength(); allocKind = TypedArrayObject::AllocKindForLazyBuffer(nbytes); } else { allocKind = GetGCObjectKind(getClass()); diff --git a/js/src/vm/NativeObject-inl.h b/js/src/vm/NativeObject-inl.h index e2cd962e90fb..ec8ac3317607 100644 --- a/js/src/vm/NativeObject-inl.h +++ b/js/src/vm/NativeObject-inl.h @@ -731,7 +731,7 @@ static MOZ_ALWAYS_INLINE bool NativeLookupOwnPropertyInline( if (index.isSome()) { uint64_t idx = index.value(); - if (idx < obj->template as().length().get()) { + if (idx < obj->template as().length()) { propp.setTypedArrayElement(idx); } else { propp.setTypedArrayOutOfRange(); diff --git a/js/src/vm/NativeObject.cpp b/js/src/vm/NativeObject.cpp index db4a45ce5776..86776a1f480c 100644 --- a/js/src/vm/NativeObject.cpp +++ b/js/src/vm/NativeObject.cpp @@ -1903,7 +1903,7 @@ static bool DefineNonexistentProperty(JSContext* cx, HandleNativeObject obj, if (index) { // This method is only called for non-existent properties, which // means any absent indexed property must be out of range. - MOZ_ASSERT(index.value() >= obj->as().length().get()); + MOZ_ASSERT(index.value() >= obj->as().length()); // The following steps refer to 9.4.5.11 IntegerIndexedElementSet. diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp index ac42fe0016ae..8a929e35a8d8 100644 --- a/js/src/vm/SelfHosting.cpp +++ b/js/src/vm/SelfHosting.cpp @@ -1079,7 +1079,7 @@ static bool intrinsic_ArrayBufferByteLength(JSContext* cx, unsigned argc, MOZ_ASSERT(args[0].isObject()); MOZ_ASSERT(args[0].toObject().is()); - size_t byteLength = args[0].toObject().as().byteLength().get(); + size_t byteLength = args[0].toObject().as().byteLength(); args.rval().setNumber(byteLength); return true; } @@ -1097,7 +1097,7 @@ static bool intrinsic_PossiblyWrappedArrayBufferByteLength(JSContext* cx, return false; } - size_t byteLength = obj->byteLength().get(); + size_t byteLength = obj->byteLength(); args.rval().setNumber(byteLength); return true; } @@ -1395,9 +1395,9 @@ static bool intrinsic_TypedArrayBitwiseSlice(JSContext* cx, unsigned argc, size_t sourceOffset = size_t(args[2].toNumber()); size_t count = size_t(args[3].toNumber()); - MOZ_ASSERT(count > 0 && count <= source->length().get()); - MOZ_ASSERT(sourceOffset <= source->length().get() - count); - MOZ_ASSERT(count <= unsafeTypedArrayCrossCompartment->length().get()); + MOZ_ASSERT(count > 0 && count <= source->length()); + MOZ_ASSERT(sourceOffset <= source->length() - count); + MOZ_ASSERT(count <= unsafeTypedArrayCrossCompartment->length()); size_t elementSize = TypedArrayElemSize(sourceType); MOZ_ASSERT(elementSize == @@ -1455,7 +1455,7 @@ static bool intrinsic_TypedArrayInitFromPackedArray(JSContext* cx, RootedArrayObject source(cx, &args[1].toObject().as()); MOZ_ASSERT(IsPackedArray(source)); - MOZ_ASSERT(source->length() == target->length().get()); + MOZ_ASSERT(source->length() == target->length()); switch (target->type()) { #define INIT_TYPED_ARRAY(T, N) \ diff --git a/js/src/vm/SharedArrayObject.cpp b/js/src/vm/SharedArrayObject.cpp index 852f752cce4e..f24c98e83a74 100644 --- a/js/src/vm/SharedArrayObject.cpp +++ b/js/src/vm/SharedArrayObject.cpp @@ -45,12 +45,12 @@ static size_t SharedArrayMappedSize(size_t length) { // `maxSize` must be something for wasm, nothing for other cases. SharedArrayRawBuffer* SharedArrayRawBuffer::Allocate( - BufferSize length, const Maybe& maxSize, + size_t length, const Maybe& maxSize, const Maybe& mappedSize) { - MOZ_RELEASE_ASSERT(length.get() <= ArrayBufferObject::maxBufferByteLength()); + MOZ_RELEASE_ASSERT(length <= ArrayBufferObject::maxBufferByteLength()); - size_t accessibleSize = SharedArrayAccessibleSize(length.get()); - if (accessibleSize < length.get()) { + size_t accessibleSize = SharedArrayAccessibleSize(length); + if (accessibleSize < length) { return nullptr; } @@ -83,7 +83,7 @@ SharedArrayRawBuffer* SharedArrayRawBuffer::Allocate( uint8_t* base = buffer - sizeof(SharedArrayRawBuffer); SharedArrayRawBuffer* rawbuf = new (base) SharedArrayRawBuffer( buffer, length, computedMaxSize, computedMappedSize, preparedForWasm); - MOZ_ASSERT(rawbuf->length_ == length.get()); // Deallocation needs this + MOZ_ASSERT(rawbuf->length_ == length); // Deallocation needs this return rawbuf; } @@ -108,19 +108,19 @@ void SharedArrayRawBuffer::tryGrowMaxSizeInPlace(uint64_t deltaMaxSize) { } bool SharedArrayRawBuffer::wasmGrowToSizeInPlace(const Lock&, - BufferSize newLength) { + size_t newLength) { // Note, caller must guard on the limit appropriate to the memory type - if (newLength.get() > ArrayBufferObject::maxBufferByteLength()) { + if (newLength > ArrayBufferObject::maxBufferByteLength()) { return false; } - MOZ_ASSERT(newLength.get() >= length_); + MOZ_ASSERT(newLength >= length_); - if (newLength.get() == length_) { + if (newLength == length_) { return true; } - size_t delta = newLength.get() - length_; + size_t delta = newLength - length_; MOZ_ASSERT(delta % wasm::PageSize == 0); uint8_t* dataEnd = dataPointerShared().unwrap(/* for resize */) + length_; @@ -133,7 +133,7 @@ bool SharedArrayRawBuffer::wasmGrowToSizeInPlace(const Lock&, // We rely on CommitBufferMemory (and therefore memmap/VirtualAlloc) to only // return once it has committed memory for all threads. We only update with a // new length once this has occurred. - length_ = newLength.get(); + length_ = newLength; return true; } @@ -180,7 +180,7 @@ MOZ_ALWAYS_INLINE bool SharedArrayBufferObject::byteLengthGetterImpl( JSContext* cx, const CallArgs& args) { MOZ_ASSERT(IsSharedArrayBuffer(args.thisv())); auto* buffer = &args.thisv().toObject().as(); - args.rval().setNumber(buffer->byteLength().get()); + args.rval().setNumber(buffer->byteLength()); return true; } @@ -225,7 +225,7 @@ bool SharedArrayBufferObject::class_constructor(JSContext* cx, unsigned argc, } // 24.2.1.1, steps 1 and 4-6. - JSObject* bufobj = New(cx, BufferSize(byteLength), proto); + JSObject* bufobj = New(cx, byteLength, proto); if (!bufobj) { return false; } @@ -234,7 +234,7 @@ bool SharedArrayBufferObject::class_constructor(JSContext* cx, unsigned argc, } SharedArrayBufferObject* SharedArrayBufferObject::New(JSContext* cx, - BufferSize length, + size_t length, HandleObject proto) { SharedArrayRawBuffer* buffer = SharedArrayRawBuffer::Allocate(length, Nothing(), Nothing()); @@ -253,7 +253,7 @@ SharedArrayBufferObject* SharedArrayBufferObject::New(JSContext* cx, } SharedArrayBufferObject* SharedArrayBufferObject::New( - JSContext* cx, SharedArrayRawBuffer* buffer, BufferSize length, + JSContext* cx, SharedArrayRawBuffer* buffer, size_t length, HandleObject proto) { MOZ_ASSERT(cx->realm()->creationOptions().getSharedMemoryAndAtomicsEnabled()); @@ -277,19 +277,19 @@ SharedArrayBufferObject* SharedArrayBufferObject::New( } bool SharedArrayBufferObject::acceptRawBuffer(SharedArrayRawBuffer* buffer, - BufferSize length) { - if (!zone()->addSharedMemory(buffer, SharedArrayMappedSize(length.get()), + size_t length) { + if (!zone()->addSharedMemory(buffer, SharedArrayMappedSize(length), MemoryUse::SharedArrayRawBuffer)) { return false; } setFixedSlot(RAWBUF_SLOT, PrivateValue(buffer)); - setFixedSlot(LENGTH_SLOT, PrivateValue(length.get())); + setFixedSlot(LENGTH_SLOT, PrivateValue(length)); return true; } void SharedArrayBufferObject::dropRawBuffer() { - size_t size = SharedArrayMappedSize(byteLength().get()); + size_t size = SharedArrayMappedSize(byteLength()); zoneFromAnyThread()->removeSharedMemory(rawBufferObject(), size, MemoryUse::SharedArrayRawBuffer); setFixedSlot(RAWBUF_SLOT, UndefinedValue()); @@ -328,7 +328,7 @@ void SharedArrayBufferObject::addSizeOfExcludingThis( // just live with the risk. const SharedArrayBufferObject& buf = obj->as(); info->objectsNonHeapElementsShared += - buf.byteLength().get() / buf.rawBufferObject()->refcount(); + buf.byteLength() / buf.rawBufferObject()->refcount(); } /* static */ @@ -336,10 +336,10 @@ void SharedArrayBufferObject::copyData( Handle toBuffer, size_t toIndex, Handle fromBuffer, size_t fromIndex, size_t count) { - MOZ_ASSERT(toBuffer->byteLength().get() >= count); - MOZ_ASSERT(toBuffer->byteLength().get() >= toIndex + count); - MOZ_ASSERT(fromBuffer->byteLength().get() >= fromIndex); - MOZ_ASSERT(fromBuffer->byteLength().get() >= fromIndex + count); + MOZ_ASSERT(toBuffer->byteLength() >= count); + MOZ_ASSERT(toBuffer->byteLength() >= toIndex + count); + MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex); + MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex + count); jit::AtomicOperations::memcpySafeWhenRacy( toBuffer->dataPointerShared() + toIndex, @@ -347,7 +347,7 @@ void SharedArrayBufferObject::copyData( } SharedArrayBufferObject* SharedArrayBufferObject::createFromNewRawBuffer( - JSContext* cx, SharedArrayRawBuffer* buffer, BufferSize initialSize) { + JSContext* cx, SharedArrayRawBuffer* buffer, size_t initialSize) { MOZ_ASSERT(cx->realm()->creationOptions().getSharedMemoryAndAtomicsEnabled()); AutoSetNewObjectMetadata metadata(cx); @@ -420,7 +420,7 @@ const JSClass SharedArrayBufferObject::protoClass_ = { JS_FRIEND_API size_t JS::GetSharedArrayBufferByteLength(JSObject* obj) { auto* aobj = obj->maybeUnwrapAs(); - return aobj ? aobj->byteLength().get() : 0; + return aobj ? aobj->byteLength() : 0; } JS_FRIEND_API void JS::GetSharedArrayBufferLengthAndData(JSObject* obj, @@ -428,7 +428,7 @@ JS_FRIEND_API void JS::GetSharedArrayBufferLengthAndData(JSObject* obj, bool* isSharedMemory, uint8_t** data) { MOZ_ASSERT(obj->is()); - *length = obj->as().byteLength().get(); + *length = obj->as().byteLength(); *data = obj->as().dataPointerShared().unwrap( /*safe - caller knows*/); *isSharedMemory = true; @@ -443,7 +443,7 @@ JS_FRIEND_API JSObject* JS::NewSharedArrayBuffer(JSContext* cx, size_t nbytes) { return nullptr; } - return SharedArrayBufferObject::New(cx, BufferSize(nbytes), + return SharedArrayBufferObject::New(cx, nbytes, /* proto = */ nullptr); } diff --git a/js/src/vm/SharedArrayObject.h b/js/src/vm/SharedArrayObject.h index 5d5f58f52214..a9c422e64c30 100644 --- a/js/src/vm/SharedArrayObject.h +++ b/js/src/vm/SharedArrayObject.h @@ -66,10 +66,10 @@ class SharedArrayRawBuffer { } protected: - SharedArrayRawBuffer(uint8_t* buffer, BufferSize length, uint64_t maxSize, + SharedArrayRawBuffer(uint8_t* buffer, size_t length, uint64_t maxSize, size_t mappedSize, bool preparedForWasm) : refcount_(1), - length_(length.get()), + length_(length), growLock_(mutexid::SharedArrayGrow), maxSize_(maxSize), mappedSize_(mappedSize), @@ -94,7 +94,7 @@ class SharedArrayRawBuffer { // max must be Something for wasm, Nothing for other uses static SharedArrayRawBuffer* Allocate( - BufferSize length, const mozilla::Maybe& maxSize, + size_t length, const mozilla::Maybe& maxSize, const mozilla::Maybe& mappedSize); // This may be called from multiple threads. The caller must take @@ -116,7 +116,7 @@ class SharedArrayRawBuffer { dataPtr - sizeof(SharedArrayRawBuffer)); } - BufferSize volatileByteLength() const { return BufferSize(length_); } + size_t volatileByteLength() const { return length_; } uint64_t maxSize() const { return maxSize_; } @@ -126,7 +126,7 @@ class SharedArrayRawBuffer { void tryGrowMaxSizeInPlace(uint64_t deltaMaxSize); - bool wasmGrowToSizeInPlace(const Lock&, BufferSize newLength); + bool wasmGrowToSizeInPlace(const Lock&, size_t newLength); uint32_t refcount() const { return refcount_; } @@ -186,14 +186,14 @@ class SharedArrayBufferObject : public ArrayBufferObjectMaybeShared { } // Create a SharedArrayBufferObject with a new SharedArrayRawBuffer. - static SharedArrayBufferObject* New(JSContext* cx, BufferSize length, + static SharedArrayBufferObject* New(JSContext* cx, size_t length, HandleObject proto = nullptr); // Create a SharedArrayBufferObject using an existing SharedArrayRawBuffer, // recording the given length in the SharedArrayBufferObject. static SharedArrayBufferObject* New(JSContext* cx, SharedArrayRawBuffer* buffer, - BufferSize length, + size_t length, HandleObject proto = nullptr); static void Finalize(JSFreeOp* fop, JSObject* obj); @@ -219,8 +219,8 @@ class SharedArrayBufferObject : public ArrayBufferObjectMaybeShared { return dataPointerShared().asValue(); } - BufferSize byteLength() const { - return BufferSize(size_t(getFixedSlot(LENGTH_SLOT).toPrivate())); + size_t byteLength() const { + return size_t(getFixedSlot(LENGTH_SLOT).toPrivate()); } bool isWasm() const { return rawBufferObject()->isWasm(); } @@ -234,7 +234,7 @@ class SharedArrayBufferObject : public ArrayBufferObjectMaybeShared { // Assumes ownership of a reference to |buffer| even in case of failure, // i.e. on failure |buffer->dropReference()| is performed. static SharedArrayBufferObject* createFromNewRawBuffer( - JSContext* cx, SharedArrayRawBuffer* buffer, BufferSize initialSize); + JSContext* cx, SharedArrayRawBuffer* buffer, size_t initialSize); mozilla::Maybe wasmMaxSize() const { return mozilla::Some(rawBufferObject()->maxSize()); @@ -244,7 +244,7 @@ class SharedArrayBufferObject : public ArrayBufferObjectMaybeShared { private: [[nodiscard]] bool acceptRawBuffer(SharedArrayRawBuffer* buffer, - BufferSize length); + size_t length); void dropRawBuffer(); }; diff --git a/js/src/vm/StructuredClone.cpp b/js/src/vm/StructuredClone.cpp index 9439159612b1..afa7da696977 100644 --- a/js/src/vm/StructuredClone.cpp +++ b/js/src/vm/StructuredClone.cpp @@ -1273,7 +1273,7 @@ bool JSStructuredCloneWriter::writeTypedArray(HandleObject obj) { return false; } - uint64_t nelems = tarr->length().get(); + uint64_t nelems = tarr->length(); if (!out.write(nelems)) { return false; } @@ -1284,7 +1284,7 @@ bool JSStructuredCloneWriter::writeTypedArray(HandleObject obj) { return false; } - uint64_t byteOffset = tarr->byteOffset().get(); + uint64_t byteOffset = tarr->byteOffset(); return out.write(byteOffset); } @@ -1296,7 +1296,7 @@ bool JSStructuredCloneWriter::writeDataView(HandleObject obj) { return false; } - uint64_t byteLength = view->byteLength().get(); + uint64_t byteLength = view->byteLength(); if (!out.write(byteLength)) { return false; } @@ -1307,7 +1307,7 @@ bool JSStructuredCloneWriter::writeDataView(HandleObject obj) { return false; } - uint64_t byteOffset = view->byteOffset().get(); + uint64_t byteOffset = view->byteOffset(); return out.write(byteOffset); } @@ -1320,7 +1320,7 @@ bool JSStructuredCloneWriter::writeArrayBuffer(HandleObject obj) { return false; } - uint64_t byteLength = buffer->byteLength().get(); + uint64_t byteLength = buffer->byteLength(); if (!out.write(byteLength)) { return false; } @@ -1364,7 +1364,7 @@ bool JSStructuredCloneWriter::writeSharedArrayBuffer(HandleObject obj) { // rawbuf - that length can be different, and it can change at any time. intptr_t p = reinterpret_cast(rawbuf); - uint64_t byteLength = sharedArrayBuffer->byteLength().get(); + uint64_t byteLength = sharedArrayBuffer->byteLength(); if (!(out.writePair(SCTAG_SHARED_ARRAY_BUFFER_OBJECT, static_cast(sizeof(p))) && out.writeBytes(&byteLength, sizeof(byteLength)) && @@ -2013,7 +2013,7 @@ bool JSStructuredCloneWriter::transferOwnership() { return false; } } else { - size_t nbytes = arrayBuffer->byteLength().get(); + size_t nbytes = arrayBuffer->byteLength(); using BufferContents = ArrayBufferObject::BufferContents; @@ -2364,21 +2364,20 @@ bool JSStructuredCloneReader::readArrayBuffer(StructuredDataType type, } // The maximum ArrayBuffer size depends on the platform and prefs, and we cast - // to BufferSize/size_t below, so we have to check this here. + // to size_t below, so we have to check this here. if (nbytes > ArrayBufferObject::maxBufferByteLength()) { JS_ReportErrorNumberASCII(context(), GetErrorMessage, nullptr, JSMSG_BAD_ARRAY_LENGTH); return false; } - JSObject* obj = - ArrayBufferObject::createZeroed(context(), BufferSize(nbytes)); + JSObject* obj = ArrayBufferObject::createZeroed(context(), size_t(nbytes)); if (!obj) { return false; } vp.setObject(*obj); ArrayBufferObject& buffer = obj->as(); - MOZ_ASSERT(buffer.byteLength().get() == nbytes); + MOZ_ASSERT(buffer.byteLength() == nbytes); return in.readArray(buffer.dataPointer(), nbytes); } @@ -2399,7 +2398,7 @@ bool JSStructuredCloneReader::readSharedArrayBuffer(MutableHandleValue vp) { } // The maximum ArrayBuffer size depends on the platform and prefs, and we cast - // to BufferSize/size_t below, so we have to check this here. + // to size_t below, so we have to check this here. if (byteLength > ArrayBufferObject::maxBufferByteLength()) { JS_ReportErrorNumberASCII(context(), GetErrorMessage, nullptr, JSMSG_BAD_ARRAY_LENGTH); @@ -2435,8 +2434,8 @@ bool JSStructuredCloneReader::readSharedArrayBuffer(MutableHandleValue vp) { return false; } - RootedObject obj(context(), SharedArrayBufferObject::New( - context(), rawbuf, BufferSize(byteLength))); + RootedObject obj(context(), + SharedArrayBufferObject::New(context(), rawbuf, byteLength)); if (!obj) { rawbuf->dropReference(); return false; @@ -2524,14 +2523,13 @@ bool JSStructuredCloneReader::readV1ArrayBuffer(uint32_t arrayType, return false; } - JSObject* obj = - ArrayBufferObject::createZeroed(context(), BufferSize(nbytes.value())); + JSObject* obj = ArrayBufferObject::createZeroed(context(), nbytes.value()); if (!obj) { return false; } vp.setObject(*obj); ArrayBufferObject& buffer = obj->as(); - MOZ_ASSERT(buffer.byteLength().get() == nbytes); + MOZ_ASSERT(buffer.byteLength() == nbytes); switch (arrayType) { case Scalar::Int8: diff --git a/js/src/vm/TypedArrayObject-inl.h b/js/src/vm/TypedArrayObject-inl.h index a913579b4a01..f7dd928b2230 100644 --- a/js/src/vm/TypedArrayObject-inl.h +++ b/js/src/vm/TypedArrayObject-inl.h @@ -304,8 +304,8 @@ class ElementSpecific { MOZ_ASSERT(!target->hasDetachedBuffer(), "target isn't detached"); MOZ_ASSERT(!source->hasDetachedBuffer(), "source isn't detached"); - MOZ_ASSERT(offset <= target->length().get()); - MOZ_ASSERT(source->length().get() <= target->length().get() - offset); + MOZ_ASSERT(offset <= target->length()); + MOZ_ASSERT(source->length() <= target->length() - offset); if (TypedArrayObject::sameBuffer(target, source)) { return setFromOverlappingTypedArray(target, source, offset); @@ -313,7 +313,7 @@ class ElementSpecific { SharedMem dest = target->dataPointerEither().template cast() + offset; - size_t count = source->length().get(); + size_t count = source->length(); if (source->type() == target->type()) { Ops::podCopy(dest, source->dataPointerEither().template cast(), @@ -459,7 +459,7 @@ class ElementSpecific { return false; } - len = std::min(len, target->length().get()); + len = std::min(len, target->length()); if (i >= len) { break; } @@ -484,7 +484,7 @@ class ElementSpecific { "target type and NativeType must match"); MOZ_ASSERT(!target->hasDetachedBuffer(), "target isn't detached"); MOZ_ASSERT(IsPackedArray(source), "source array must be packed"); - MOZ_ASSERT(source->getDenseInitializedLength() <= target->length().get()); + MOZ_ASSERT(source->getDenseInitializedLength() <= target->length()); size_t len = source->getDenseInitializedLength(); size_t i = 0; @@ -524,7 +524,7 @@ class ElementSpecific { // |target| is a newly allocated typed array and not yet visible to // content script, so valueToNative can't detach the underlying // buffer. - MOZ_ASSERT(i < target->length().get()); + MOZ_ASSERT(i < target->length()); // Compute every iteration in case GC moves the data. SharedMem newDest = target->dataPointerEither().template cast(); @@ -549,12 +549,12 @@ class ElementSpecific { "the provided arrays don't actually overlap, so it's " "undesirable to use this method"); - MOZ_ASSERT(offset <= target->length().get()); - MOZ_ASSERT(source->length().get() <= target->length().get() - offset); + MOZ_ASSERT(offset <= target->length()); + MOZ_ASSERT(source->length() <= target->length() - offset); SharedMem dest = target->dataPointerEither().template cast() + offset; - size_t len = source->length().get(); + size_t len = source->length(); if (source->type() == target->type()) { SharedMem src = source->dataPointerEither().template cast(); diff --git a/js/src/vm/TypedArrayObject.cpp b/js/src/vm/TypedArrayObject.cpp index aaba75647e36..2b99685daf45 100644 --- a/js/src/vm/TypedArrayObject.cpp +++ b/js/src/vm/TypedArrayObject.cpp @@ -113,7 +113,7 @@ bool TypedArrayObject::ensureHasBuffer(JSContext* cx, return true; } - size_t byteLength = tarray->byteLength().get(); + size_t byteLength = tarray->byteLength(); AutoRealm ar(cx, tarray); Rooted buffer( @@ -147,7 +147,7 @@ bool TypedArrayObject::ensureHasBuffer(JSContext* cx, #ifdef DEBUG void TypedArrayObject::assertZeroLengthArrayData() const { - if (length().get() == 0 && !hasBuffer()) { + if (length() == 0 && !hasBuffer()) { uint8_t* end = fixedData(TypedArrayObject::FIXED_DATA_START); MOZ_ASSERT(end[0] == ZeroLengthArrayData); } @@ -173,7 +173,7 @@ void TypedArrayObject::finalize(JSFreeOp* fop, JSObject* obj) { // Free the data slot pointer if it does not point into the old JSObject. if (!curObj->hasInlineElements()) { - size_t nbytes = RoundUp(curObj->byteLength().get(), sizeof(Value)); + size_t nbytes = RoundUp(curObj->byteLength(), sizeof(Value)); fop->free_(obj, curObj->elements(), nbytes, MemoryUse::TypedArrayElements); } } @@ -210,7 +210,7 @@ size_t TypedArrayObject::objectMoved(JSObject* obj, JSObject* old) { Nursery& nursery = obj->runtimeFromMainThread()->gc.nursery(); if (!nursery.isInside(buf)) { nursery.removeMallocedBufferDuringMinorGC(buf); - size_t nbytes = RoundUp(newObj->byteLength().get(), sizeof(Value)); + size_t nbytes = RoundUp(newObj->byteLength(), sizeof(Value)); AddCellMemory(newObj, nbytes, MemoryUse::TypedArrayElements); return 0; } @@ -218,7 +218,7 @@ size_t TypedArrayObject::objectMoved(JSObject* obj, JSObject* old) { // Determine if we can use inline data for the target array. If this is // possible, the nursery will have picked an allocation size that is large // enough. - size_t nbytes = oldObj->byteLength().get(); + size_t nbytes = oldObj->byteLength(); MOZ_ASSERT(nbytes <= Nursery::MaxNurseryBufferSize); constexpr size_t headerSize = dataOffset() + sizeof(HeapSlot); @@ -265,7 +265,7 @@ size_t TypedArrayObject::objectMoved(JSObject* obj, JSObject* old) { bool TypedArrayObject::hasInlineElements() const { return elements() == this->fixedData(TypedArrayObject::FIXED_DATA_START) && - byteLength().get() <= TypedArrayObject::INLINE_BUFFER_LIMIT; + byteLength() <= TypedArrayObject::INLINE_BUFFER_LIMIT; } void TypedArrayObject::setInlineElements() { @@ -395,12 +395,12 @@ class TypedArrayObjectTemplate : public TypedArrayObject { static TypedArrayObject* makeInstance( JSContext* cx, Handle buffer, - BufferSize byteOffset, BufferSize len, HandleObject proto) { - MOZ_ASSERT(len.get() <= maxByteLength() / BYTES_PER_ELEMENT); + size_t byteOffset, size_t len, HandleObject proto) { + MOZ_ASSERT(len <= maxByteLength() / BYTES_PER_ELEMENT); gc::AllocKind allocKind = buffer ? gc::GetGCObjectKind(instanceClass()) - : AllocKindForLazyBuffer(len.get() * BYTES_PER_ELEMENT); + : AllocKindForLazyBuffer(len * BYTES_PER_ELEMENT); AutoSetNewObjectMetadata metadata(cx); Rooted obj(cx); @@ -662,7 +662,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject { // Steps 9-12. static bool computeAndCheckLength( JSContext* cx, HandleArrayBufferObjectMaybeShared bufferMaybeUnwrapped, - uint64_t byteOffset, uint64_t lengthIndex, BufferSize* length) { + uint64_t byteOffset, uint64_t lengthIndex, size_t* length) { MOZ_ASSERT(byteOffset % BYTES_PER_ELEMENT == 0); MOZ_ASSERT(byteOffset < uint64_t(DOUBLE_INTEGRAL_PRECISION_LIMIT)); MOZ_ASSERT_IF(lengthIndex != UINT64_MAX, @@ -676,7 +676,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject { } // Step 10. - size_t bufferByteLength = bufferMaybeUnwrapped->byteLength().get(); + size_t bufferByteLength = bufferMaybeUnwrapped->byteLength(); size_t len; if (lengthIndex == UINT64_MAX) { @@ -715,7 +715,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject { } MOZ_ASSERT(len < SIZE_MAX); - *length = BufferSize(len); + *length = len; return true; } @@ -726,13 +726,13 @@ class TypedArrayObjectTemplate : public TypedArrayObject { JSContext* cx, HandleArrayBufferObjectMaybeShared buffer, uint64_t byteOffset, uint64_t lengthIndex, HandleObject proto) { // Steps 9-12. - BufferSize length(0); + size_t length = 0; if (!computeAndCheckLength(cx, buffer, byteOffset, lengthIndex, &length)) { return nullptr; } // Steps 13-17. - return makeInstance(cx, buffer, BufferSize(byteOffset), length, proto); + return makeInstance(cx, buffer, byteOffset, length, proto); } // Create a TypedArray object in another compartment. @@ -767,7 +767,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject { RootedArrayBufferObjectMaybeShared unwrappedBuffer(cx); unwrappedBuffer = &unwrapped->as(); - BufferSize length(0); + size_t length = 0; if (!computeAndCheckLength(cx, unwrappedBuffer, byteOffset, lengthIndex, &length)) { return nullptr; @@ -792,8 +792,8 @@ class TypedArrayObjectTemplate : public TypedArrayObject { return nullptr; } - typedArray = makeInstance(cx, unwrappedBuffer, BufferSize(byteOffset), - length, wrappedProto); + typedArray = + makeInstance(cx, unwrappedBuffer, byteOffset, length, wrappedProto); if (!typedArray) { return nullptr; } @@ -833,13 +833,13 @@ class TypedArrayObjectTemplate : public TypedArrayObject { JSMSG_BAD_ARRAY_LENGTH); return false; } - BufferSize byteLength = BufferSize(count * BYTES_PER_ELEMENT); + size_t byteLength = count * BYTES_PER_ELEMENT; - MOZ_ASSERT(byteLength.get() <= maxByteLength()); + MOZ_ASSERT(byteLength <= maxByteLength()); static_assert(INLINE_BUFFER_LIMIT % BYTES_PER_ELEMENT == 0, "ArrayBuffer inline storage shouldn't waste any space"); - if (!nonDefaultProto && byteLength.get() <= INLINE_BUFFER_LIMIT) { + if (!nonDefaultProto && byteLength <= INLINE_BUFFER_LIMIT) { // The array's data can be inline, and the buffer created lazily. return true; } @@ -867,12 +867,11 @@ class TypedArrayObjectTemplate : public TypedArrayObject { return nullptr; } - return makeInstance(cx, buffer, BufferSize(0), BufferSize(nelements), - proto); + return makeInstance(cx, buffer, 0, nelements, proto); } static bool AllocateArrayBuffer(JSContext* cx, HandleObject ctor, - BufferSize count, + size_t count, MutableHandle buffer); static TypedArrayObject* fromArray(JSContext* cx, HandleObject other, @@ -885,13 +884,13 @@ class TypedArrayObjectTemplate : public TypedArrayObject { HandleObject proto); static const NativeType getIndex(TypedArrayObject* tarray, size_t index) { - MOZ_ASSERT(index < tarray->length().get()); + MOZ_ASSERT(index < tarray->length()); return jit::AtomicOperations::loadSafeWhenRacy( tarray->dataPointerEither().cast() + index); } static void setIndex(TypedArrayObject& tarray, size_t index, NativeType val) { - MOZ_ASSERT(index < tarray.length().get()); + MOZ_ASSERT(index < tarray.length()); jit::AtomicOperations::storeSafeWhenRacy( tarray.dataPointerEither().cast() + index, val); } @@ -960,7 +959,7 @@ template JSContext* cx, Handle obj, uint64_t index, HandleValue v, ObjectOpResult& result) { MOZ_ASSERT(!obj->hasDetachedBuffer()); - MOZ_ASSERT(index < obj->length().get()); + MOZ_ASSERT(index < obj->length()); // Step 1 is enforced by the caller. @@ -971,7 +970,7 @@ template } // Step 4. - if (index < obj->length().get()) { + if (index < obj->length()) { MOZ_ASSERT(!obj->hasDetachedBuffer(), "detaching an array buffer sets the length to zero"); TypedArrayObjectTemplate::setIndex(*obj, index, nativeValue); @@ -1045,7 +1044,7 @@ TypedArrayObject* js::NewTypedArrayWithTemplateAndBuffer( // byteLength = count * BYTES_PER_ELEMENT template /* static */ bool TypedArrayObjectTemplate::AllocateArrayBuffer( - JSContext* cx, HandleObject ctor, BufferSize count, + JSContext* cx, HandleObject ctor, size_t count, MutableHandle buffer) { // 24.1.1.1 step 1 (partially). RootedObject proto(cx); @@ -1065,7 +1064,7 @@ template } // 24.1.1.1 steps 1 (remaining part), 2-6. - if (!maybeCreateArrayBuffer(cx, count.get(), proto, buffer)) { + if (!maybeCreateArrayBuffer(cx, count, proto, buffer)) { return false; } @@ -1197,7 +1196,7 @@ template // Step 8 (skipped). // Step 9. - BufferSize elementLength = srcArray->length(); + size_t elementLength = srcArray->length(); // Steps 10-15 (skipped). @@ -1240,7 +1239,7 @@ template // Steps 3-4 (remaining part), 20-23. Rooted obj( - cx, makeInstance(cx, buffer, BufferSize(0), elementLength, proto)); + cx, makeInstance(cx, buffer, 0, elementLength, proto)); if (!obj) { return nullptr; } @@ -1306,8 +1305,7 @@ template return nullptr; } - Rooted obj( - cx, makeInstance(cx, buffer, BufferSize(0), BufferSize(len), proto)); + Rooted obj(cx, makeInstance(cx, buffer, 0, len, proto)); if (!obj) { return nullptr; } @@ -1383,8 +1381,7 @@ template MOZ_ASSERT(len <= maxByteLength() / BYTES_PER_ELEMENT); - Rooted obj( - cx, makeInstance(cx, buffer, BufferSize(0), BufferSize(len), proto)); + Rooted obj(cx, makeInstance(cx, buffer, 0, len, proto)); if (!obj) { return nullptr; } @@ -1650,7 +1647,7 @@ bool TypedArrayObject::set_impl(JSContext* cx, const CallArgs& args) { } // Step 10 (Reordered). - size_t targetLength = target->length().get(); + size_t targetLength = target->length(); // Step 22 (Split into two checks to provide better error messages). if (targetOffset > targetLength) { @@ -1660,7 +1657,7 @@ bool TypedArrayObject::set_impl(JSContext* cx, const CallArgs& args) { // Step 22 (Cont'd). size_t offset = size_t(targetOffset); - if (srcTypedArray->length().get() > targetLength - offset) { + if (srcTypedArray->length() > targetLength - offset) { JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_SOURCE_ARRAY_TOO_LONG); return false; @@ -1691,7 +1688,7 @@ bool TypedArrayObject::set_impl(JSContext* cx, const CallArgs& args) { // Step 10. // We can't reorder this step because side-effects in step 16 can // detach the underlying array buffer from the typed array. - size_t targetLength = target->length().get(); + size_t targetLength = target->length(); // Step 16. uint64_t srcLength; @@ -1790,7 +1787,7 @@ bool TypedArrayObject::copyWithin_impl(JSContext* cx, const CallArgs& args) { } // Step 3. - size_t len = tarray->length().get(); + size_t len = tarray->length(); // Step 4. double relativeTarget; @@ -1884,7 +1881,7 @@ bool TypedArrayObject::copyWithin_impl(JSContext* cx, const CallArgs& args) { #ifdef DEBUG { - size_t viewByteLength = tarray->byteLength().get(); + size_t viewByteLength = tarray->byteLength(); MOZ_ASSERT(byteSize <= viewByteLength); MOZ_ASSERT(byteDest < viewByteLength); MOZ_ASSERT(byteSrc < viewByteLength); @@ -2143,7 +2140,7 @@ bool TypedArrayObject::getElementPure(size_t index, Value* vp) { bool TypedArrayObject::getElements(JSContext* cx, Handle tarray, Value* vp) { - size_t length = tarray->length().get(); + size_t length = tarray->length(); MOZ_ASSERT_IF(length > 0, !tarray->hasDetachedBuffer()); switch (tarray->type()) { @@ -2301,28 +2298,28 @@ bool js::IsBufferSource(JSObject* object, SharedMem* dataPointer, if (object->is()) { TypedArrayObject& view = object->as(); *dataPointer = view.dataPointerEither().cast(); - *byteLength = view.byteLength().get(); + *byteLength = view.byteLength(); return true; } if (object->is()) { DataViewObject& view = object->as(); *dataPointer = view.dataPointerEither().cast(); - *byteLength = view.byteLength().get(); + *byteLength = view.byteLength(); return true; } if (object->is()) { ArrayBufferObject& buffer = object->as(); *dataPointer = buffer.dataPointerShared(); - *byteLength = buffer.byteLength().get(); + *byteLength = buffer.byteLength(); return true; } if (object->is()) { SharedArrayBufferObject& buffer = object->as(); *dataPointer = buffer.dataPointerShared(); - *byteLength = buffer.byteLength().get(); + *byteLength = buffer.byteLength(); return true; } @@ -2551,7 +2548,7 @@ bool js::DefineTypedArrayElement(JSContext* cx, Handle obj, // These are all substeps of 3.b. // Step i. - if (index >= obj->length().get()) { + if (index >= obj->length()) { if (obj->hasDetachedBuffer()) { return result.fail(JSMSG_TYPED_ARRAY_DETACHED); } @@ -2658,7 +2655,7 @@ struct ExternalTypeOf { return nullptr; \ } \ TypedArrayObject* tarr = &obj->as(); \ - *length = tarr->length().get(); \ + *length = tarr->length(); \ *isShared = tarr->isSharedMemory(); \ *data = static_cast::Type*>( \ tarr->dataPointerEither().unwrap( \ @@ -2690,7 +2687,7 @@ JS_FRIEND_API size_t JS_GetTypedArrayLength(JSObject* obj) { if (!tarr) { return 0; } - return tarr->length().get(); + return tarr->length(); } JS_FRIEND_API size_t JS_GetTypedArrayByteOffset(JSObject* obj) { @@ -2698,7 +2695,7 @@ JS_FRIEND_API size_t JS_GetTypedArrayByteOffset(JSObject* obj) { if (!tarr) { return 0; } - return tarr->byteOffset().get(); + return tarr->byteOffset(); } JS_FRIEND_API size_t JS_GetTypedArrayByteLength(JSObject* obj) { @@ -2706,7 +2703,7 @@ JS_FRIEND_API size_t JS_GetTypedArrayByteLength(JSObject* obj) { if (!tarr) { return 0; } - return tarr->byteLength().get(); + return tarr->byteLength(); } JS_FRIEND_API bool JS_GetTypedArraySharedness(JSObject* obj) { diff --git a/js/src/vm/TypedArrayObject.h b/js/src/vm/TypedArrayObject.h index 805242caa4fc..7c257f3aa38e 100644 --- a/js/src/vm/TypedArrayObject.h +++ b/js/src/vm/TypedArrayObject.h @@ -92,21 +92,19 @@ class TypedArrayObject : public ArrayBufferViewObject { static bool ensureHasBuffer(JSContext* cx, Handle tarray); - BufferSize byteLength() const { - return BufferSize(length().get() * bytesPerElement()); - } + size_t byteLength() const { return length() * bytesPerElement(); } - BufferSize length() const { - return BufferSize(size_t(getFixedSlot(LENGTH_SLOT).toPrivate())); + size_t length() const { + return size_t(getFixedSlot(LENGTH_SLOT).toPrivate()); } Value byteLengthValue() const { - size_t len = byteLength().get(); + size_t len = byteLength(); return NumberValue(len); } Value lengthValue() const { - size_t len = length().get(); + size_t len = length(); return NumberValue(len); } diff --git a/js/src/wasm/AsmJS.cpp b/js/src/wasm/AsmJS.cpp index 9b22226586ee..09d88c432197 100644 --- a/js/src/wasm/AsmJS.cpp +++ b/js/src/wasm/AsmJS.cpp @@ -6729,7 +6729,7 @@ static bool CheckBuffer(JSContext* cx, const AsmJSMetadata& metadata, buffer.set(&bufferObj->as()); - size_t memoryLength = buffer->byteLength().get(); + size_t memoryLength = buffer->byteLength(); if (!IsValidAsmJSHeapLength(memoryLength)) { UniqueChars msg( diff --git a/js/src/wasm/WasmInstance.cpp b/js/src/wasm/WasmInstance.cpp index f8a7b2d74a3e..28fd72f4439b 100644 --- a/js/src/wasm/WasmInstance.cpp +++ b/js/src/wasm/WasmInstance.cpp @@ -350,7 +350,7 @@ Instance::callImport_general(Instance* instance, int32_t funcImportIndex, // write tests for cross-realm calls. MOZ_ASSERT(TlsContext.get()->realm() == instance->realm()); - size_t byteLength = instance->memory()->volatileMemoryLength().get(); + size_t byteLength = instance->memory()->volatileMemoryLength(); #ifdef JS_64BIT // Ensure that the memory size is no more than 4GB. MOZ_ASSERT(byteLength <= 0x100000000); @@ -376,8 +376,7 @@ static int32_t PerformWait(Instance* instance, uint32_t byteOffset, T value, return -1; } - if (byteOffset + sizeof(T) > - instance->memory()->volatileMemoryLength().get()) { + if (byteOffset + sizeof(T) > instance->memory()->volatileMemoryLength()) { JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_OUT_OF_BOUNDS); return -1; @@ -432,7 +431,7 @@ static int32_t PerformWait(Instance* instance, uint32_t byteOffset, T value, return -1; } - if (byteOffset >= instance->memory()->volatileMemoryLength().get()) { + if (byteOffset >= instance->memory()->volatileMemoryLength()) { JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_WASM_OUT_OF_BOUNDS); return -1; @@ -480,7 +479,7 @@ inline int32_t WasmMemoryCopy32(T memBase, size_t memLen, MOZ_ASSERT(SASigMemCopy32.failureMode == FailureMode::FailOnNegI32); const WasmArrayRawBuffer* rawBuf = WasmArrayRawBuffer::fromDataPtr(memBase); - size_t memLen = rawBuf->byteLength().get(); + size_t memLen = rawBuf->byteLength(); return WasmMemoryCopy32(memBase, memLen, dstByteOffset, srcByteOffset, len, memmove); @@ -497,7 +496,7 @@ inline int32_t WasmMemoryCopy32(T memBase, size_t memLen, const SharedArrayRawBuffer* rawBuf = SharedArrayRawBuffer::fromDataPtr(memBase); - size_t memLen = rawBuf->volatileByteLength().get(); + size_t memLen = rawBuf->volatileByteLength(); return WasmMemoryCopy32, RacyMemMove>( SharedMem::shared(memBase), memLen, dstByteOffset, @@ -547,7 +546,7 @@ inline int32_t WasmMemoryFill32(T memBase, size_t memLen, uint32_t byteOffset, MOZ_ASSERT(SASigMemFill32.failureMode == FailureMode::FailOnNegI32); const WasmArrayRawBuffer* rawBuf = WasmArrayRawBuffer::fromDataPtr(memBase); - size_t memLen = rawBuf->byteLength().get(); + size_t memLen = rawBuf->byteLength(); return WasmMemoryFill32(memBase, memLen, byteOffset, value, len, memset); } @@ -560,7 +559,7 @@ inline int32_t WasmMemoryFill32(T memBase, size_t memLen, uint32_t byteOffset, const SharedArrayRawBuffer* rawBuf = SharedArrayRawBuffer::fromDataPtr(memBase); - size_t memLen = rawBuf->volatileByteLength().get(); + size_t memLen = rawBuf->volatileByteLength(); return WasmMemoryFill32(SharedMem::shared(memBase), memLen, byteOffset, value, len, @@ -591,7 +590,7 @@ inline int32_t WasmMemoryFill32(T memBase, size_t memLen, uint32_t byteOffset, const uint32_t segLen = seg.bytes.length(); WasmMemoryObject* mem = instance->memory(); - const size_t memLen = mem->volatileMemoryLength().get(); + const size_t memLen = mem->volatileMemoryLength(); // We are proposing to copy // @@ -1002,8 +1001,7 @@ bool Instance::initElems(uint32_t tableIndex, const ElemSegment& seg, JSContext* cx = TlsContext.get(); SharedExceptionTag tag = instance->exceptionTags()[exnIndex]; - RootedArrayBufferObject buf( - cx, ArrayBufferObject::createZeroed(cx, BufferSize(nbytes))); + RootedArrayBufferObject buf(cx, ArrayBufferObject::createZeroed(cx, nbytes)); if (!buf) { return nullptr; @@ -1215,7 +1213,7 @@ bool Instance::init(JSContext* cx, const JSFunctionVector& funcImports, tlsData()->memoryBase = memory_ ? memory_->buffer().dataPointerEither().unwrap() : nullptr; - size_t limit = memory_ ? memory_->boundsCheckLimit().get() : 0; + size_t limit = memory_ ? memory_->boundsCheckLimit() : 0; #if !defined(JS_64BIT) || defined(ENABLE_WASM_CRANELIFT) // We assume that the limit is a 32-bit quantity MOZ_ASSERT(limit <= UINT32_MAX); @@ -1464,7 +1462,7 @@ bool Instance::memoryAccessInGuardRegion(const uint8_t* addr, } size_t lastByteOffset = addr - base + (numBytes - 1); - return lastByteOffset >= memory()->volatileMemoryLength().get() && + return lastByteOffset >= memory()->volatileMemoryLength() && lastByteOffset < memoryMappedSize(); } @@ -1481,7 +1479,7 @@ bool Instance::memoryAccessInBounds(const uint8_t* addr, return false; } - size_t length = memory()->volatileMemoryLength().get(); + size_t length = memory()->volatileMemoryLength(); if (addr >= base + length) { return false; } @@ -2068,7 +2066,7 @@ void Instance::onMovingGrowMemory() { ArrayBufferObject& buffer = memory_->buffer().as(); tlsData()->memoryBase = buffer.dataPointer(); - size_t limit = memory_->boundsCheckLimit().get(); + size_t limit = memory_->boundsCheckLimit(); #if !defined(JS_64BIT) || defined(ENABLE_WASM_CRANELIFT) // We assume that the limit is a 32-bit quantity MOZ_ASSERT(limit <= UINT32_MAX); diff --git a/js/src/wasm/WasmJS.cpp b/js/src/wasm/WasmJS.cpp index 70e17743db92..3dd0f5ba3cec 100644 --- a/js/src/wasm/WasmJS.cpp +++ b/js/src/wasm/WasmJS.cpp @@ -705,7 +705,7 @@ bool wasm::Eval(JSContext* cx, Handle code, } if (!bytecode->append((uint8_t*)code->dataPointerEither().unwrap(), - code->byteLength().get())) { + code->byteLength())) { ReportOutOfMemory(cx); return false; } @@ -1391,7 +1391,7 @@ bool WasmModuleObject::customSections(JSContext* cx, unsigned argc, Value* vp) { continue; } - buf = ArrayBufferObject::createZeroed(cx, BufferSize(cs.payload->length())); + buf = ArrayBufferObject::createZeroed(cx, cs.payload->length()); if (!buf) { return false; } @@ -2396,14 +2396,13 @@ bool WasmMemoryObject::bufferGetterImpl(JSContext* cx, const CallArgs& args) { RootedArrayBufferObjectMaybeShared buffer(cx, &memoryObj->buffer()); if (memoryObj->isShared()) { - size_t memoryLength = memoryObj->volatileMemoryLength().get(); - MOZ_ASSERT(memoryLength >= buffer->byteLength().get()); + size_t memoryLength = memoryObj->volatileMemoryLength(); + MOZ_ASSERT(memoryLength >= buffer->byteLength()); - if (memoryLength > buffer->byteLength().get()) { + if (memoryLength > buffer->byteLength()) { RootedSharedArrayBufferObject newBuffer( - cx, - SharedArrayBufferObject::New(cx, memoryObj->sharedArrayRawBuffer(), - BufferSize(memoryLength))); + cx, SharedArrayBufferObject::New( + cx, memoryObj->sharedArrayRawBuffer(), memoryLength)); if (!newBuffer) { return false; } @@ -2501,7 +2500,7 @@ bool WasmMemoryObject::typeImpl(JSContext* cx, const CallArgs& args) { } uint32_t minimumPages = mozilla::AssertedCast( - memoryObj->volatileMemoryLength().get() / wasm::PageSize); + memoryObj->volatileMemoryLength() / wasm::PageSize); if (!props.append(IdValuePair(NameToId(cx->names().minimum), Int32Value(minimumPages)))) { return false; @@ -2527,7 +2526,7 @@ bool WasmMemoryObject::type(JSContext* cx, unsigned argc, Value* vp) { } #endif -BufferSize WasmMemoryObject::volatileMemoryLength() const { +size_t WasmMemoryObject::volatileMemoryLength() const { if (isShared()) { return sharedArrayRawBuffer()->volatileByteLength(); } @@ -2580,7 +2579,7 @@ bool WasmMemoryObject::movingGrowable() const { return !isHuge() && !buffer().wasmMaxSize(); } -BufferSize WasmMemoryObject::boundsCheckLimit() const { +size_t WasmMemoryObject::boundsCheckLimit() const { if (!buffer().isWasm() || isHuge()) { return buffer().byteLength(); } @@ -2597,7 +2596,7 @@ BufferSize WasmMemoryObject::boundsCheckLimit() const { MOZ_ASSERT(wasm::IsValidBoundsCheckImmediate(mappedSize - wasm::GuardSize)); size_t limit = mappedSize - wasm::GuardSize; MOZ_ASSERT(limit <= MaxMemory32BoundsCheckLimit()); - return BufferSize(limit); + return limit; } bool WasmMemoryObject::addMovingGrowObserver(JSContext* cx, @@ -2623,8 +2622,8 @@ uint32_t WasmMemoryObject::growShared(HandleWasmMemoryObject memory, SharedArrayRawBuffer* rawBuf = memory->sharedArrayRawBuffer(); SharedArrayRawBuffer::Lock lock(rawBuf); - MOZ_ASSERT(rawBuf->volatileByteLength().get() % PageSize == 0); - uint32_t oldNumPages = rawBuf->volatileByteLength().get() / PageSize; + MOZ_ASSERT(rawBuf->volatileByteLength() % PageSize == 0); + uint32_t oldNumPages = rawBuf->volatileByteLength() / PageSize; CheckedInt newSize = oldNumPages; newSize += delta; @@ -2643,7 +2642,7 @@ uint32_t WasmMemoryObject::growShared(HandleWasmMemoryObject memory, return -1; } - if (!rawBuf->wasmGrowToSizeInPlace(lock, BufferSize(newSize.value()))) { + if (!rawBuf->wasmGrowToSizeInPlace(lock, newSize.value())) { return -1; } @@ -2662,8 +2661,8 @@ uint32_t WasmMemoryObject::grow(HandleWasmMemoryObject memory, uint32_t delta, RootedArrayBufferObject oldBuf(cx, &memory->buffer().as()); - MOZ_ASSERT(oldBuf->byteLength().get() % PageSize == 0); - uint32_t oldNumPages = oldBuf->byteLength().get() / PageSize; + MOZ_ASSERT(oldBuf->byteLength() % PageSize == 0); + uint32_t oldNumPages = oldBuf->byteLength() / PageSize; #if !defined(JS_64BIT) || defined(ENABLE_WASM_CRANELIFT) // TODO (large ArrayBuffer): For Cranelift, limit the memory size to something @@ -2692,8 +2691,8 @@ uint32_t WasmMemoryObject::grow(HandleWasmMemoryObject memory, uint32_t delta, if (memory->movingGrowable()) { MOZ_ASSERT(!memory->isHuge()); - if (!ArrayBufferObject::wasmMovingGrowToSize(BufferSize(newSize.value()), - oldBuf, &newBuf, cx)) { + if (!ArrayBufferObject::wasmMovingGrowToSize(newSize.value(), oldBuf, + &newBuf, cx)) { return -1; } } else { @@ -2703,8 +2702,8 @@ uint32_t WasmMemoryObject::grow(HandleWasmMemoryObject memory, uint32_t delta, } } - if (!ArrayBufferObject::wasmGrowToSizeInPlace(BufferSize(newSize.value()), - oldBuf, &newBuf, cx)) { + if (!ArrayBufferObject::wasmGrowToSizeInPlace(newSize.value(), oldBuf, + &newBuf, cx)) { return -1; } } diff --git a/js/src/wasm/WasmJS.h b/js/src/wasm/WasmJS.h index 56d3ffe77ef6..dd6e74e11c09 100644 --- a/js/src/wasm/WasmJS.h +++ b/js/src/wasm/WasmJS.h @@ -34,9 +34,8 @@ #include "js/RootingAPI.h" // MovableCellHasher #include "js/SweepingAPI.h" // JS::WeakCache #include "js/TypeDecls.h" // HandleValue, HandleObject, MutableHandleObject, MutableHandleFunction -#include "js/Vector.h" // JS::Vector +#include "js/Vector.h" // JS::Vector #include "js/WasmFeatures.h" -#include "vm/BufferSize.h" #include "vm/JSFunction.h" // JSFunction #include "vm/NativeObject.h" // NativeObject #include "wasm/WasmTypes.h" // MutableHandleWasmInstanceObject, wasm::* @@ -401,12 +400,12 @@ class WasmMemoryObject : public NativeObject { // The current length of the memory. In the case of shared memory, the // length can change at any time. Also note that this will acquire a lock // for shared memory, so do not call this from a signal handler. - js::BufferSize volatileMemoryLength() const; + size_t volatileMemoryLength() const; bool isShared() const; bool isHuge() const; bool movingGrowable() const; - js::BufferSize boundsCheckLimit() const; + size_t boundsCheckLimit() const; // If isShared() is true then obtain the underlying buffer object. SharedArrayRawBuffer* sharedArrayRawBuffer() const; diff --git a/js/src/wasm/WasmModule.cpp b/js/src/wasm/WasmModule.cpp index 74c3f93f7fa5..06587d2721de 100644 --- a/js/src/wasm/WasmModule.cpp +++ b/js/src/wasm/WasmModule.cpp @@ -567,7 +567,7 @@ bool Module::initSegments(JSContext* cx, HandleWasmInstanceObject instanceObj, } if (memoryObj) { - size_t memoryLength = memoryObj->volatileMemoryLength().get(); + size_t memoryLength = memoryObj->volatileMemoryLength(); uint8_t* memoryBase = memoryObj->buffer().dataPointerEither().unwrap(/* memcpy */); @@ -719,7 +719,7 @@ bool Module::instantiateMemory(JSContext* cx, if (!CheckLimits(cx, declaredMin, declaredMax, /* defaultMax */ uint64_t(MaxMemory32Bytes()), /* actualLength */ - uint64_t(memory->volatileMemoryLength().get()), + uint64_t(memory->volatileMemoryLength()), memory->buffer().wasmMaxSize(), metadata().isAsmJS(), "Memory")) { return false;