Skip to content

Commit

Permalink
Unreviewed, reverting 276672@main.
Browse files Browse the repository at this point in the history
  • Loading branch information
webkit-commit-queue authored and Constellation committed Mar 26, 2024
1 parent 8dfa8c3 commit b03ed17
Show file tree
Hide file tree
Showing 77 changed files with 249 additions and 243 deletions.
4 changes: 2 additions & 2 deletions Source/WTF/wtf/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ WTF_EXPORT_PRIVATE long long seekFile(PlatformFileHandle, long long offset, File
WTF_EXPORT_PRIVATE bool truncateFile(PlatformFileHandle, long long offset);
WTF_EXPORT_PRIVATE bool flushFile(PlatformFileHandle);
// Returns number of bytes actually read if successful, -1 otherwise.
WTF_EXPORT_PRIVATE int64_t writeToFile(PlatformFileHandle, const void* data, size_t length);
WTF_EXPORT_PRIVATE int writeToFile(PlatformFileHandle, const void* data, int length);
// Returns number of bytes actually written if successful, -1 otherwise.
WTF_EXPORT_PRIVATE int64_t readFromFile(PlatformFileHandle, void* data, size_t length);
WTF_EXPORT_PRIVATE int readFromFile(PlatformFileHandle, void* data, int length);

WTF_EXPORT_PRIVATE PlatformFileHandle openAndLockFile(const String&, FileOpenMode, OptionSet<FileLockMode> = FileLockMode::Exclusive);
WTF_EXPORT_PRIVATE void unlockAndCloseFile(PlatformFileHandle);
Expand Down
1 change: 0 additions & 1 deletion Source/WTF/wtf/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,6 @@ class Vector : private VectorBuffer<T, inlineCapacity, Malloc> {
size_t capacity() const { return Base::capacity(); }
bool isEmpty() const { return !size(); }
std::span<const T> span() const { return { data(), size() }; }
std::span<T> mutableSpan() { return { data(), size() }; }

Vector<T> subvector(size_t offset, size_t length = std::dynamic_extent) const
{
Expand Down
8 changes: 4 additions & 4 deletions Source/WTF/wtf/posix/FileSystemPOSIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,20 @@ bool flushFile(PlatformFileHandle handle)
return !fsync(handle);
}

int64_t writeToFile(PlatformFileHandle handle, const void* data, size_t length)
int writeToFile(PlatformFileHandle handle, const void* data, int length)
{
do {
auto bytesWritten = write(handle, data, length);
int bytesWritten = write(handle, data, static_cast<size_t>(length));
if (bytesWritten >= 0)
return bytesWritten;
} while (errno == EINTR);
return -1;
}

int64_t readFromFile(PlatformFileHandle handle, void* data, size_t length)
int readFromFile(PlatformFileHandle handle, void* data, int length)
{
do {
auto bytesRead = read(handle, data, length);
int bytesRead = read(handle, data, static_cast<size_t>(length));
if (bytesRead >= 0)
return bytesRead;
} while (errno == EINTR);
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/text/AtomStringImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AtomStringImpl final : public UniquedStringImpl {
ALWAYS_INLINE static Ref<AtomStringImpl> add(ASCIILiteral literal) { return addLiteral(literal.characters(), literal.length()); }

// Not using the add() naming to encourage developers to call add(ASCIILiteral) when they have a string literal.
ALWAYS_INLINE static RefPtr<AtomStringImpl> addCString(const char* s) { return s ? add(WTF::span8(s)) : nullptr; }
ALWAYS_INLINE static RefPtr<AtomStringImpl> addCString(const char* s) { return s ? add(std::span { s, strlen(s) }) : nullptr; }

// Returns null if the input data contains an invalid UTF-8 sequence.
static RefPtr<AtomStringImpl> addUTF8(const char* start, const char* end);
Expand Down
11 changes: 0 additions & 11 deletions Source/WTF/wtf/text/StringCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -1153,20 +1153,9 @@ inline std::span<const UChar> span(const UChar& character)
return { &character, 1 };
}

inline std::span<const LChar> span8(const char* string)
{
return { reinterpret_cast<const LChar*>(string), string ? strlen(string) : 0 };
}

inline std::span<const char> span(const char* string)
{
return { string, string ? strlen(string) : 0 };
}

}

using WTF::equalIgnoringASCIICase;
using WTF::equalLettersIgnoringASCIICase;
using WTF::isLatin1;
using WTF::span;
using WTF::span8;
2 changes: 1 addition & 1 deletion Source/WTF/wtf/text/StringImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class StringImpl : private StringImplShape {
template<size_t inlineCapacity> static Ref<StringImpl> create8BitIfPossible(const Vector<UChar, inlineCapacity>&);

// Not using create() naming to encourage developers to call create(ASCIILiteral) when they have a string literal.
ALWAYS_INLINE static Ref<StringImpl> createFromCString(const char* characters) { return create(WTF::span8(characters)); }
ALWAYS_INLINE static Ref<StringImpl> createFromCString(const char* characters) { return create(std::span { characters, strlen(characters) }); }

static Ref<StringImpl> createSubstringSharingImpl(StringImpl&, unsigned offset, unsigned length);

Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/text/StringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ inline StringView::StringView(std::span<const UChar> characters)

inline StringView::StringView(const char* characters)
{
initialize(WTF::span8(characters));
initialize(std::span { reinterpret_cast<const LChar*>(characters), characters ? strlen(characters) : 0 });
}

inline StringView::StringView(std::span<const char> characters)
Expand Down
8 changes: 4 additions & 4 deletions Source/WTF/wtf/win/FileSystemWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool flushFile(PlatformFileHandle)
return false;
}

int64_t writeToFile(PlatformFileHandle handle, const void* data, size_t length)
int writeToFile(PlatformFileHandle handle, const void* data, int length)
{
if (!isHandleValid(handle))
return -1;
Expand All @@ -285,10 +285,10 @@ int64_t writeToFile(PlatformFileHandle handle, const void* data, size_t length)

if (!success)
return -1;
return static_cast<int64_t>(bytesWritten);
return static_cast<int>(bytesWritten);
}

int64_t readFromFile(PlatformFileHandle handle, void* data, size_t length)
int readFromFile(PlatformFileHandle handle, void* data, int length)
{
if (!isHandleValid(handle))
return -1;
Expand All @@ -298,7 +298,7 @@ int64_t readFromFile(PlatformFileHandle handle, void* data, size_t length)

if (!success)
return -1;
return static_cast<int64_t>(bytesRead);
return static_cast<int>(bytesRead);
}

String localUserSpecificStorageDirectory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void ClipboardItemBindingsDataSource::ClipboardItemTypeLoader::didFinishLoading(
if (!stringResult.isNull())
m_data = { stringResult };
else if (auto arrayBuffer = m_blobLoader->arrayBufferResult())
m_data = { SharedBuffer::create(arrayBuffer->span()) };
m_data = { SharedBuffer::create(static_cast<const char*>(arrayBuffer->data()), arrayBuffer->byteLength()) };
m_blobLoader = nullptr;
invokeCompletionHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/cache/DOMCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void DOMCache::put(RequestInfo&& info, Ref<FetchResponse>&& response, DOMPromise
}

if (auto* chunk = result.returnValue())
data.append(*chunk);
data.append(chunk->data(), chunk->size());
else
this->putWithResponseData(WTFMove(promise), WTFMove(request), WTFMove(response), RefPtr<SharedBuffer> { data.takeAsContiguous() });
});
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ static RefPtr<SharedBuffer> sanitizeKeyids(const SharedBuffer& buffer)
kidsArray->pushString(base64URLEncodeToString(buffer->data(), buffer->size()));
object->setArray("kids"_s, WTFMove(kidsArray));

return SharedBuffer::create(object->toJSONString().utf8().span());
CString jsonData = object->toJSONString().utf8();
return SharedBuffer::create(jsonData.data(), jsonData.length());
}

std::optional<Vector<std::unique_ptr<ISOProtectionSystemSpecificHeaderBox>>> InitDataRegistry::extractPsshBoxesFromCenc(const SharedBuffer& buffer)
Expand Down Expand Up @@ -178,7 +179,7 @@ std::optional<Vector<Ref<SharedBuffer>>> InitDataRegistry::extractKeyIDsCenc(con
if (CDMPrivateFairPlayStreaming::validFairPlayStreamingSchemes().contains(scheme)) {
for (const auto& request : fpsPssh->initDataBox().requests()) {
auto& keyID = request.requestInfo().keyID();
keyIDs.append(SharedBuffer::create(keyID.span()));
keyIDs.append(SharedBuffer::create(keyID.data(), keyID.size()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void MediaKeySession::generateRequest(const AtomString& initDataType, const Buff
// 8. Let session type be this object's session type.
// 9. Let promise be a new promise.
// 10. Run the following steps in parallel:
queueTaskKeepingObjectAlive(*this, TaskSource::Networking, [this, weakThis = WeakPtr { *this }, initData = SharedBuffer::create(initData.span()), initDataType, promise = WTFMove(promise), identifier = WTFMove(identifier)] () mutable {
queueTaskKeepingObjectAlive(*this, TaskSource::Networking, [this, weakThis = WeakPtr { *this }, initData = SharedBuffer::create(initData.data(), initData.length()), initDataType, promise = WTFMove(promise), identifier = WTFMove(identifier)] () mutable {
// 10.1. If the init data is not valid for initDataType, reject promise with a newly created TypeError.
// 10.2. Let sanitized init data be a validated and sanitized version of init data.
RefPtr<SharedBuffer> sanitizedInitData = m_implementation->sanitizeInitData(initDataType, initData);
Expand Down Expand Up @@ -422,7 +422,7 @@ void MediaKeySession::update(const BufferSource& response, Ref<DeferredPromise>&
// 4. Let response copy be a copy of the contents of the response parameter.
// 5. Let promise be a new promise.
// 6. Run the following steps in parallel:
queueTaskKeepingObjectAlive(*this, TaskSource::Networking, [this, weakThis = WeakPtr { *this }, response = SharedBuffer::create(response.span()), promise = WTFMove(promise), identifier = WTFMove(identifier)] () mutable {
queueTaskKeepingObjectAlive(*this, TaskSource::Networking, [this, weakThis = WeakPtr { *this }, response = SharedBuffer::create(response.data(), response.length()), promise = WTFMove(promise), identifier = WTFMove(identifier)] () mutable {
// 6.1. Let sanitized response be a validated and/or sanitized version of response copy.
RefPtr<SharedBuffer> sanitizedResponse = m_implementation->sanitizeResponse(response);

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void MediaKeys::setServerCertificate(const BufferSource& serverCertificate, Ref<
}

// 3. Let certificate be a copy of the contents of the serverCertificate parameter.
auto certificate = SharedBuffer::create(serverCertificate.span());
auto certificate = SharedBuffer::create(serverCertificate.data(), serverCertificate.length());

// 4. Let promise be a new promise.
// 5. Run the following steps in parallel:
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void FetchBodyConsumer::resolve(Ref<DeferredPromise>&& promise, const String& co
return;
}

data.append(*chunk);
data.append(chunk->data(), chunk->size());
});
m_sink->pipeFrom(*stream);
return;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void FetchResponse::setBodyData(ResponseData&& data, uint64_t bodySizeWithPaddin

void FetchResponse::consumeChunk(Ref<JSC::Uint8Array>&& chunk)
{
body().consumer().append(SharedBuffer::create(chunk->span()));
body().consumer().append(SharedBuffer::create(chunk->data(), chunk->byteLength()));
}

void FetchResponse::consumeBodyAsStream()
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/highlight/AppHighlightRangeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Ref<FragmentedSharedBuffer> AppHighlightRangeData::toSharedBuffer() const
{
WTF::Persistence::Encoder encoder;
encoder << *this;
return SharedBuffer::create(encoder.span());
return SharedBuffer::create(encoder.buffer(), encoder.bufferSize());
}

} // namespace WebCore
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/Modules/mediasource/SourceBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ ExceptionOr<void> SourceBuffer::setAppendWindowEnd(double newValue)

ExceptionOr<void> SourceBuffer::appendBuffer(const BufferSource& data)
{
return appendBufferInternal(data.span());
return appendBufferInternal(static_cast<const unsigned char*>(data.data()), data.length());
}

void SourceBuffer::resetParserState()
Expand Down Expand Up @@ -582,7 +582,7 @@ void SourceBuffer::scheduleEvent(const AtomString& eventName)
queueTaskToDispatchEvent(*this, TaskSource::MediaElement, Event::create(eventName, Event::CanBubble::No, Event::IsCancelable::No));
}

ExceptionOr<void> SourceBuffer::appendBufferInternal(std::span<const uint8_t> data)
ExceptionOr<void> SourceBuffer::appendBufferInternal(const unsigned char* data, unsigned size)
{
// Section 3.2 appendBuffer()
// https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
Expand All @@ -597,15 +597,15 @@ ExceptionOr<void> SourceBuffer::appendBufferInternal(std::span<const uint8_t> da
if (isRemoved() || m_updating)
return Exception { ExceptionCode::InvalidStateError };

ALWAYS_LOG(LOGIDENTIFIER, "size = ", data.size(), "maximumBufferSize = ", maximumBufferSize(), "buffered = ", m_buffered->ranges(), " streaming = ", m_source->streaming());
ALWAYS_LOG(LOGIDENTIFIER, "size = ", size, "maximumBufferSize = ", maximumBufferSize(), "buffered = ", m_buffered->ranges(), " streaming = ", m_source->streaming());

// 3. If the readyState attribute of the parent media source is in the "ended" state then run the following steps:
// 3.1. Set the readyState attribute of the parent media source to "open"
// 3.2. Queue a task to fire a simple event named sourceopen at the parent media source .
m_source->openIfInEndedState();

// 4. Run the coded frame eviction algorithm.
bool bufferFull = m_private->evictCodedFrames(data.size(), m_source->currentTime());
bool bufferFull = m_private->evictCodedFrames(size, m_source->currentTime());

// 5. If the buffer full flag equals true, then throw a QuotaExceededError exception and abort these step.
if (bufferFull) {
Expand All @@ -616,7 +616,7 @@ ExceptionOr<void> SourceBuffer::appendBufferInternal(std::span<const uint8_t> da
// NOTE: Return to 3.2 appendBuffer()
// 3. Add data to the end of the input buffer.
ASSERT(!m_pendingAppendData);
m_pendingAppendData = SharedBuffer::create(data);
m_pendingAppendData = SharedBuffer::create(data, size);

// 4. Set the updating attribute to true.
m_updating = true;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/mediasource/SourceBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class SourceBuffer
bool isRemoved() const;
void scheduleEvent(const AtomString& eventName);

ExceptionOr<void> appendBufferInternal(std::span<const uint8_t>);
ExceptionOr<void> appendBufferInternal(const unsigned char*, unsigned);
void sourceBufferPrivateAppendComplete(MediaPromise::Result&&);
void resetParserState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void LibWebRTCDataChannelHandler::OnMessage(const webrtc::DataBuffer& buffer)
if (!m_hasClient) {
auto* data = buffer.data.data<uint8_t>();
if (buffer.binary)
m_bufferedMessages.append(SharedBuffer::create(std::span { data, buffer.size() }));
m_bufferedMessages.append(SharedBuffer::create(data, buffer.size()));
else
m_bufferedMessages.append(String::fromUTF8(data, buffer.size()));
return;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSFontFaceSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void CSSFontFaceSource::load(Document* document)
} else if (m_immediateSource) {
ASSERT(!m_immediateFontCustomPlatformData);
bool wrapping;
auto buffer = SharedBuffer::create(m_immediateSource->span());
auto buffer = SharedBuffer::create(static_cast<const char*>(m_immediateSource->baseAddress()), m_immediateSource->byteLength());
m_immediateFontCustomPlatformData = CachedFont::createCustomFontData(buffer.get(), String(), wrapping);
success = static_cast<bool>(m_immediateFontCustomPlatformData);
} else {
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/ImageBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ void ImageBitmap::createFromBuffer(ScriptExecutionContext& scriptExecutionContex
return;
}

auto sharedBuffer = SharedBuffer::create(arrayBuffer->span());
auto sharedBuffer = SharedBuffer::create(static_cast<const char*>(arrayBuffer->data()), arrayBuffer->byteLength());
auto observer = ImageBitmapImageObserver::create(mimeType, expectedContentLength, sourceURL);
auto image = BitmapImage::create(observer.ptr());
auto result = image->setData(sharedBuffer.copyRef(), true);
Expand Down
12 changes: 8 additions & 4 deletions Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,8 +1296,10 @@ Inspector::Protocol::ErrorStringOr<void> InspectorNetworkAgent::interceptWithRes
return makeUnexpected("Unable to decode given content"_s);

overrideData = SharedBuffer::create(WTFMove(*buffer));
} else
overrideData = SharedBuffer::create(content.utf8().span());
} else {
auto utf8Content = content.utf8();
overrideData = SharedBuffer::create(utf8Content.data(), utf8Content.length());
}

pendingInterceptResponse->respond(overrideResponse, overrideData);

Expand All @@ -1322,8 +1324,10 @@ Inspector::Protocol::ErrorStringOr<void> InspectorNetworkAgent::interceptRequest
return makeUnexpected("Unable to decode given content"_s);

data = SharedBuffer::create(WTFMove(*buffer));
} else
data = SharedBuffer::create(content.utf8().span());
} else {
auto utf8Content = content.utf8();
data = SharedBuffer::create(utf8Content.data(), utf8Content.length());
}

// Mimic data URL load behavior - report didReceiveResponse & didFinishLoading.
ResourceResponse response(pendingRequest->m_loader->url(), mimeType, data->size(), String());
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/loader/FrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ SubstituteData FrameLoader::defaultSubstituteDataForURL(const URL& url)
CString encodedSrcdoc = srcdoc.string().utf8();

ResourceResponse response(URL(), textHTMLContentTypeAtom(), encodedSrcdoc.length(), "UTF-8"_s);
return SubstituteData(SharedBuffer::create(encodedSrcdoc.span()), URL(), response, SubstituteData::SessionHistoryVisibility::Hidden);
return SubstituteData(SharedBuffer::create(encodedSrcdoc.data(), encodedSrcdoc.length()), URL(), response, SubstituteData::SessionHistoryVisibility::Hidden);
}

void FrameLoader::load(FrameLoadRequest&& request)
Expand Down
14 changes: 7 additions & 7 deletions Source/WebCore/loader/archive/mhtml/MHTMLArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Ref<FragmentedSharedBuffer> MHTMLArchive::generateMHTMLData(Page* page)
ASSERT(stringBuilder.toString().containsOnlyASCII());
CString asciiString = stringBuilder.toString().utf8();
SharedBufferBuilder mhtmlData;
mhtmlData.append(asciiString.span());
mhtmlData.append(asciiString.data(), asciiString.length());

for (auto& resource : resources) {
stringBuilder.clear();
Expand All @@ -183,15 +183,15 @@ Ref<FragmentedSharedBuffer> MHTMLArchive::generateMHTMLData(Page* page)
stringBuilder.append("\r\nContent-Transfer-Encoding: ", contentEncoding, "\r\nContent-Location: ", resource.url.string(), "\r\n\r\n");

asciiString = stringBuilder.toString().utf8();
mhtmlData.append(asciiString.span());
mhtmlData.append(asciiString.data(), asciiString.length());

// FIXME: ideally we would encode the content as a stream without having to fetch it all.
auto* data = resource.data->data();
size_t dataLength = resource.data->size();
if (!strcmp(contentEncoding, quotedPrintable)) {
auto encodedData = quotedPrintableEncode(data, dataLength);
mhtmlData.append(encodedData.span());
mhtmlData.append("\r\n"_span);
mhtmlData.append(encodedData.data(), encodedData.size());
mhtmlData.append("\r\n", 2);
} else {
ASSERT(!strcmp(contentEncoding, base64));
// We are not specifying insertLFs = true below as it would cut the lines with LFs and MHTML requires CRLFs.
Expand All @@ -201,15 +201,15 @@ Ref<FragmentedSharedBuffer> MHTMLArchive::generateMHTMLData(Page* page)
size_t encodedDataLength = encodedData.size();
do {
size_t lineLength = std::min(encodedDataLength - index, maximumLineLength);
mhtmlData.append(encodedData.subspan(index, lineLength));
mhtmlData.append("\r\n"_span);
mhtmlData.append(encodedData.data() + index, lineLength);
mhtmlData.append("\r\n", 2);
index += maximumLineLength;
} while (index < encodedDataLength);
}
}

asciiString = makeString("--", boundary, "--\r\n").utf8();
mhtmlData.append(asciiString.span());
mhtmlData.append(asciiString.data(), asciiString.length());

return mhtmlData.take();
}
Expand Down
Loading

0 comments on commit b03ed17

Please sign in to comment.