Commit 28717562 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[arraypiece] Change type of byte_length_ to size_t

Similar to the other data structures, I introduced new checked getters
that we can change eventually.

R=haraken@chromium.org

Bug: chromium:1008840
Change-Id: If36da1541bc9773310f968916f5a451b4248394c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929818Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718126}
parent 3c413e4f
......@@ -40,15 +40,14 @@ unsigned char* ArrayPiece::Bytes() const {
return static_cast<unsigned char*>(Data());
}
unsigned ArrayPiece::ByteLength() const {
size_t ArrayPiece::ByteLengthAsSizeT() const {
DCHECK(!IsNull());
return byte_length_;
}
void ArrayPiece::InitWithArrayBuffer(ArrayBuffer* buffer) {
if (buffer) {
InitWithData(buffer->Data(),
SafeCast<unsigned>(buffer->ByteLengthAsUnsigned()));
InitWithData(buffer->Data(), buffer->ByteLengthAsSizeT());
is_detached_ = buffer->IsDetached();
} else {
InitNull();
......@@ -64,7 +63,7 @@ void ArrayPiece::InitWithArrayBufferView(ArrayBufferView* buffer) {
}
}
void ArrayPiece::InitWithData(void* data, unsigned byte_length) {
void ArrayPiece::InitWithData(void* data, size_t byte_length) {
byte_length_ = byte_length;
data_ = data;
is_null_ = false;
......
......@@ -38,18 +38,18 @@ class CORE_EXPORT ArrayPiece {
bool IsDetached() const;
void* Data() const;
unsigned char* Bytes() const;
unsigned ByteLength() const;
size_t ByteLengthAsSizeT() const;
protected:
void InitWithArrayBuffer(ArrayBuffer*);
void InitWithArrayBufferView(ArrayBufferView*);
void InitWithData(void* data, unsigned byte_length);
void InitWithData(void* data, size_t byte_length);
private:
void InitNull();
void* data_;
unsigned byte_length_;
size_t byte_length_;
bool is_null_;
bool is_detached_;
};
......
......@@ -42,13 +42,13 @@ class CORE_EXPORT DOMArrayPiece : public ArrayPiece {
InitWithUnionOption = kTreatNullAsNull);
bool operator==(const DOMArrayBuffer& other) const {
return ByteLength() == other.DeprecatedByteLengthAsUnsigned() &&
memcmp(Data(), other.Data(), ByteLength()) == 0;
return ByteLengthAsSizeT() == other.ByteLengthAsSizeT() &&
memcmp(Data(), other.Data(), ByteLengthAsSizeT()) == 0;
}
bool operator==(const DOMArrayBufferView& other) const {
return ByteLength() == other.byteLength() &&
memcmp(Data(), other.BaseAddress(), ByteLength()) == 0;
return ByteLengthAsSizeT() == static_cast<size_t>(other.byteLength()) &&
memcmp(Data(), other.BaseAddress(), ByteLengthAsSizeT()) == 0;
}
};
......
......@@ -191,7 +191,7 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(
// If bytes is more than 512 bytes long (the maximum length of an attribute
// value, per Long Attribute Values) return a promise rejected with an
// InvalidModificationError and abort.
if (value.ByteLength() > 512) {
if (value.ByteLengthAsSizeT() > 512) {
return ScriptPromise::RejectWithDOMException(
script_state, MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidModificationError,
......@@ -200,7 +200,8 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(
// Let valueVector be a copy of the bytes held by value.
Vector<uint8_t> value_vector;
value_vector.Append(value.Bytes(), value.ByteLength());
value_vector.Append(value.Bytes(),
static_cast<wtf_size_t>(value.ByteLengthAsSizeT()));
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise();
......
......@@ -133,7 +133,7 @@ ScriptPromise BluetoothRemoteGATTDescriptor::writeValue(
// If bytes is more than 512 bytes long (the maximum length of an attribute
// value, per Long Attribute Values) return a promise rejected with an
// InvalidModificationError and abort.
if (value.ByteLength() > 512) {
if (value.ByteLengthAsSizeT() > 512) {
return ScriptPromise::RejectWithDOMException(
script_state, MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidModificationError,
......@@ -142,7 +142,8 @@ ScriptPromise BluetoothRemoteGATTDescriptor::writeValue(
// Let valueVector be a copy of the bytes held by value.
Vector<uint8_t> value_vector;
value_vector.Append(value.Bytes(), value.ByteLength());
value_vector.Append(value.Bytes(),
static_cast<wtf_size_t>(value.ByteLengthAsSizeT()));
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise();
......
......@@ -11,7 +11,7 @@
namespace blink {
inline WebVector<uint8_t> CopyBytes(const DOMArrayPiece& source) {
return WebVector<uint8_t>(static_cast<const uint8_t*>(source.Data()),
source.ByteLength());
source.ByteLengthAsSizeT());
}
} // namespace blink
......
......@@ -460,7 +460,7 @@ ScriptPromise MediaKeySession::generateRequest(
// 5. If initData is an empty array, return a promise rejected with a
// newly created TypeError.
if (!init_data.ByteLength()) {
if (!init_data.ByteLengthAsSizeT()) {
return ScriptPromise::Reject(
script_state,
V8ThrowException::CreateTypeError(script_state->GetIsolate(),
......@@ -487,7 +487,7 @@ ScriptPromise MediaKeySession::generateRequest(
// 7. Let init data be a copy of the contents of the initData parameter.
DOMArrayBuffer* init_data_buffer =
DOMArrayBuffer::Create(init_data.Data(), init_data.ByteLength());
DOMArrayBuffer::Create(init_data.Data(), init_data.ByteLengthAsSizeT());
// 8. Let session type be this object's session type.
// (Done in constructor.)
......@@ -699,7 +699,7 @@ ScriptPromise MediaKeySession::update(ScriptState* script_state,
// 3. If response is an empty array, return a promise rejected with a
// newly created TypeError.
if (!response.ByteLength()) {
if (!response.ByteLengthAsSizeT()) {
return ScriptPromise::Reject(
script_state,
V8ThrowException::CreateTypeError(script_state->GetIsolate(),
......@@ -708,7 +708,7 @@ ScriptPromise MediaKeySession::update(ScriptState* script_state,
// 4. Let response copy be a copy of the contents of the response parameter.
DOMArrayBuffer* response_copy =
DOMArrayBuffer::Create(response.Data(), response.ByteLength());
DOMArrayBuffer::Create(response.Data(), response.ByteLengthAsSizeT());
// 5. Let promise be a new promise.
SimpleResultPromise* result = MakeGarbageCollected<SimpleResultPromise>(
......
......@@ -284,7 +284,7 @@ ScriptPromise MediaKeys::setServerCertificate(
//
// 2. If serverCertificate is an empty array, return a promise rejected
// with a new a newly created TypeError.
if (!server_certificate.ByteLength()) {
if (!server_certificate.ByteLengthAsSizeT()) {
return ScriptPromise::Reject(
script_state, V8ThrowException::CreateTypeError(
script_state->GetIsolate(),
......@@ -294,7 +294,7 @@ ScriptPromise MediaKeys::setServerCertificate(
// 3. Let certificate be a copy of the contents of the serverCertificate
// parameter.
DOMArrayBuffer* server_certificate_buffer = DOMArrayBuffer::Create(
server_certificate.Data(), server_certificate.ByteLength());
server_certificate.Data(), server_certificate.ByteLengthAsSizeT());
// 4. Let promise be a new promise.
SetCertificateResultPromise* result =
......
......@@ -203,7 +203,7 @@ void RTCQuicTransport::connect(ExceptionState& exception_state) {
void RTCQuicTransport::listen(const DOMArrayPiece& remote_key,
ExceptionState& exception_state) {
if (remote_key.ByteLength() == 0u) {
if (remote_key.ByteLengthAsSizeT() == 0u) {
exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
"Cannot listen with an empty key.");
return;
......@@ -216,7 +216,7 @@ void RTCQuicTransport::listen(const DOMArrayPiece& remote_key,
}
start_reason_ = StartReason::kServerListening;
std::string pre_shared_key(static_cast<const char*>(remote_key.Data()),
remote_key.ByteLength());
remote_key.ByteLengthAsSizeT());
StartConnection(quic::Perspective::IS_SERVER,
P2PQuicTransport::StartConfig(pre_shared_key));
}
......@@ -397,17 +397,17 @@ void RTCQuicTransport::sendDatagram(const DOMArrayPiece& data,
"Cannot send datagram because not readyToSend()");
return;
}
if (data.ByteLength() > max_datagram_length_) {
if (data.ByteLengthAsSizeT() > max_datagram_length_) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
"data of size " + String::Number(data.ByteLength()) +
"data of size " + String::Number(data.ByteLengthAsSizeT()) +
" is too large to fit into a datagram of max size: " +
String::Number(max_datagram_length_.value_or(0)));
return;
}
Vector<uint8_t> datagram(data.ByteLength());
memcpy(datagram.data(), data.Data(), data.ByteLength());
Vector<uint8_t> datagram(static_cast<wtf_size_t>(data.ByteLengthAsSizeT()));
memcpy(datagram.data(), data.Data(), data.ByteLengthAsSizeT());
proxy_->SendDatagram(std::move(datagram));
num_buffered_sent_datagrams_++;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment