Skip to content

Commit

Permalink
Drop Vector::append(T*, size_t) and use Vector::append(std::span<cons…
Browse files Browse the repository at this point in the history
…t T>) instead

https://bugs.webkit.org/show_bug.cgi?id=271118

Reviewed by Darin Adler and Brent Fulgham.

Drop Vector::append(T*, size_t) and use Vector::append(std::span<const T>) instead.
This is part of an effort to use std::span more in the codebase, for better security.

* Source/JavaScriptCore/API/ObjcRuntimeExtras.h:
(forEachProtocolImplementingProtocol):
* Source/JavaScriptCore/assembler/AbstractMacroAssembler.h:
(JSC::AbstractMacroAssembler::JumpList::append):
* Source/JavaScriptCore/bytecode/ObjectPropertyConditionSet.cpp:
(JSC::ObjectPropertyConditionSet::mergedWith const):
* Source/JavaScriptCore/jsc.cpp:
(runWithOptions):
* Source/JavaScriptCore/parser/Lexer.cpp:
(JSC::Lexer<CharacterType>::parseIdentifierSlowCase):
(JSC::Lexer<T>::parseTemplateLiteral):
* Source/JavaScriptCore/parser/Lexer.h:
(JSC::Lexer::append16):
* Source/JavaScriptCore/runtime/IntlLocale.cpp:
(JSC::LocaleIDBuilder::overrideLanguageScriptRegion):
* Source/JavaScriptCore/runtime/IntlObject.cpp:
(JSC::canonicalizeUnicodeExtensionsAfterICULocaleCanonicalization):
(JSC::addScriptlessLocaleIfNeeded):
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
(JSC::illFormedIndex):
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/tools/JSDollarVM.cpp:
* Source/JavaScriptCore/wasm/WasmBBQPlan.h:
* Source/JavaScriptCore/wasm/WasmEntryPlan.cpp:
(JSC::Wasm::EntryPlan::parseAndValidateModule):
* Source/JavaScriptCore/wasm/WasmEntryPlan.h:
* Source/JavaScriptCore/wasm/WasmIPIntPlan.cpp:
(JSC::Wasm::IPIntPlan::IPIntPlan):
* Source/JavaScriptCore/wasm/WasmLLIntPlan.cpp:
(JSC::Wasm::LLIntPlan::LLIntPlan):
* Source/JavaScriptCore/wasm/WasmStreamingCompiler.h:
* Source/JavaScriptCore/wasm/WasmStreamingParser.cpp:
(JSC::Wasm::StreamingParser::consume):
(JSC::Wasm::StreamingParser::consumeVarUInt32):
(JSC::Wasm::StreamingParser::addBytes):
(JSC::Wasm::StreamingParser::finalize):
* Source/JavaScriptCore/wasm/WasmStreamingParser.h:
(JSC::Wasm::StreamingParser::addBytes):
* Source/WTF/wtf/StreamBuffer.h:
(WTF::StreamBuffer::append):
* Source/WTF/wtf/TrailingArray.h:
(WTF::TrailingArray::span const):
* Source/WTF/wtf/URL.cpp:
(WTF::appendEncodedHostname):
* Source/WTF/wtf/URLParser.cpp:
(WTF::URLParser::appendToASCIIBuffer):
(WTF::URLParser::utf8PercentEncode):
(WTF::URLParser::utf8QueryEncode):
(WTF::URLParser::copyASCIIStringUntil):
(WTF::URLParser::syntaxViolation):
(WTF::URLParser::parse):
(WTF::URLParser::appendNumberToASCIIBuffer):
(WTF::URLParser::serializeIPv6):
(WTF::URLParser::domainToASCII):
(WTF::URLParser::parseHostAndPort):
* Source/WTF/wtf/URLParser.h:
(WTF::URLParser::appendToASCIIBuffer): Deleted.
* Source/WTF/wtf/Vector.h:
(WTF::Vector::subspan const):
(WTF::Vector::tryAppend):
(WTF::Vector::append):
(WTF::Vector::appendList):
(WTF::Malloc>::append):
(WTF::Malloc>::appendVector):
* Source/WTF/wtf/cf/VectorCF.h:
* Source/WTF/wtf/cocoa/FileSystemCocoa.mm:
(WTF::FileSystemImpl::openTemporaryFile):
* Source/WTF/wtf/text/AtomString.h:
* Source/WTF/wtf/text/SuperFastHash.h:
(WTF::SuperFastHash::addCharacters):
(WTF::SuperFastHash::computeHash):
* Source/WTF/wtf/text/WTFString.cpp:
(WTF::String::charactersWithoutNullTermination const):
* Source/WebCore/Modules/indexeddb/server/IDBSerialization.cpp:
(WebCore::writeLittleEndian):
(WebCore::encodeKey):
(WebCore::decodeKey):
* Source/WebCore/Modules/mediastream/SFrameUtils.cpp:
(WebCore::toRbsp):
(WebCore::computeVP8PrefixBuffer):
* Source/WebCore/Modules/mediastream/STUNMessageParsing.cpp:
(WebCore::WebRTC::getSTUNOrTURNMessageLengths):
(WebCore::WebRTC::extractSTUNOrTURNMessages):
* Source/WebCore/Modules/mediastream/STUNMessageParsing.h:
* Source/WebCore/Modules/webauthn/cbor/CBORReader.cpp:
(cbor::CBORReader::readBytes):
* Source/WebCore/Modules/webauthn/cbor/CBORWriter.cpp:
(cbor::CBORWriter::encodeCBOR):
* Source/WebCore/Modules/webauthn/fido/FidoHidPacket.cpp:
(fido::FidoHidInitPacket::getSerializedData const):
(fido::FidoHidContinuationPacket::getSerializedData const):
* Source/WebCore/Modules/webauthn/fido/FidoParsingUtils.cpp:
(fido::getInitPacketData):
(fido::getContinuationPacketData):
* Source/WebCore/Modules/webauthn/fido/U2fCommandConstructor.cpp:
(fido::WebCore::constructU2fSignCommand):
* Source/WebCore/Modules/websockets/WebSocketFrame.cpp:
(WebCore::WebSocketFrame::makeFrameData):
* Source/WebCore/Modules/websockets/WebSocketHandshake.cpp:
(WebCore::WebSocketHandshake::readHTTPHeaders):
* Source/WebCore/PAL/pal/text/TextCodecCJK.cpp:
(PAL::appendDecimal):
* Source/WebCore/PAL/pal/text/TextCodecICU.cpp:
(PAL::TextCodecICU::encode const):
* Source/WebCore/PAL/pal/text/TextCodecLatin1.cpp:
(PAL::encodeComplexWindowsLatin1):
* Source/WebCore/PAL/pal/text/TextCodecUserDefined.cpp:
(PAL::encodeComplexUserDefined):
* Source/WebCore/accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::supportsPressAction const):
* Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:
(WebCore::handleResponseOnStreamingAction):
* Source/WebCore/bindings/js/SerializedScriptValue.cpp:
(WebCore::writeLittleEndian):
(WebCore::writeLittleEndian<uint8_t>):
(WebCore::CloneSerializer::serialize):
(WebCore::CloneSerializer::dumpImageBitmap):
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneSerializer::write):
(WebCore::CloneDeserializer::read):
* Source/WebCore/crypto/SubtleCrypto.cpp:
(WebCore::SubtleCrypto::wrapKey):
* Source/WebCore/crypto/cocoa/CryptoAlgorithmECDSAMac.cpp:
(WebCore::signECDSA):
(WebCore::verifyECDSA):
* Source/WebCore/crypto/cocoa/CryptoKeyECMac.cpp:
(WebCore::CryptoKeyEC::platformExportSpki const):
(WebCore::CryptoKeyEC::platformImportPkcs8):
(WebCore::CryptoKeyEC::platformExportPkcs8 const):
* Source/WebCore/crypto/cocoa/CryptoKeyOKPCocoa.cpp:
(WebCore::CryptoKeyOKP::exportSpki const):
(WebCore::CryptoKeyOKP::exportPkcs8 const):
* Source/WebCore/crypto/cocoa/CryptoKeyRSAMac.cpp:
(WebCore::CryptoKeyRSA::exportSpki const):
(WebCore::CryptoKeyRSA::exportPkcs8 const):
* Source/WebCore/crypto/parameters/CryptoAlgorithmAesCbcCfbParams.h:
* Source/WebCore/crypto/parameters/CryptoAlgorithmAesCtrParams.h:
* Source/WebCore/crypto/parameters/CryptoAlgorithmAesGcmParams.h:
* Source/WebCore/crypto/parameters/CryptoAlgorithmHkdfParams.h:
* Source/WebCore/crypto/parameters/CryptoAlgorithmPbkdf2Params.h:
* Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
(WebCore::CryptoAlgorithmRsaKeyGenParams::publicExponentVector const):
* Source/WebCore/crypto/parameters/CryptoAlgorithmRsaOaepParams.h:
* Source/WebCore/dom/DatasetDOMStringMap.cpp:
(WebCore::convertPropertyNameToAttributeName):
* Source/WebCore/fileapi/BlobBuilder.cpp:
(WebCore::BlobBuilder::append):
* Source/WebCore/history/HistoryItem.cpp:
(WebCore::HistoryItem::showTreeWithIndent const):
* Source/WebCore/html/parser/HTMLToken.h:
(WebCore::HTMLToken::appendToComment):
* Source/WebCore/loader/TextResourceDecoder.cpp:
(WebCore::TextResourceDecoder::decode):
* Source/WebCore/page/EventSource.cpp:
(WebCore::EventSource::parseEventStreamLine):
* Source/WebCore/page/PageConsoleClient.cpp:
(WebCore::PageConsoleClient::addMessage):
(WebCore::PageConsoleClient::messageWithTypeAndLevel):
* Source/WebCore/platform/SharedBuffer.cpp:
(WebCore::combineSegmentsData):
(WebCore::FragmentedSharedBuffer::getContiguousData const):
(WebCore::FragmentedSharedBuffer::read const):
* Source/WebCore/platform/SharedStringHash.cpp:
(WebCore::findSlashDotDotSlash):
(WebCore::findSlashSlash):
(WebCore::findSlashDotSlash):
(WebCore::containsColonSlashSlash):
(WebCore::cleanSlashDotDotSlashes):
(WebCore::mergeDoubleSlashes):
(WebCore::cleanSlashDotSlashes):
(WebCore::cleanPath):
(WebCore::needsTrailingSlash):
(WebCore::computeSharedStringHashInline):
(WebCore::computeSharedStringHash):
(WebCore::computeVisitedLinkHash):
* Source/WebCore/platform/SharedStringHash.h:
* Source/WebCore/platform/audio/MultiChannelResampler.cpp:
(WebCore::MultiChannelResampler::provideInputForChannel):
* Source/WebCore/platform/audio/SincResampler.cpp:
(WebCore::SincResampler::processBuffer):
(WebCore::SincResampler::process):
* Source/WebCore/platform/graphics/cg/ImageBufferUtilitiesCG.cpp:
(WebCore::encode):
(WebCore::encodeToVector):
* Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp:
(WebCore::WebMParser::AudioTrackData::consumeFrameData):
* Source/WebCore/platform/graphics/cocoa/WebMAudioUtilitiesCocoa.h:
* Source/WebCore/platform/graphics/cocoa/WebMAudioUtilitiesCocoa.mm:
(WebCore::cookieFromVorbisCodecPrivate):
(WebCore::createVorbisAudioInfo):
* Source/WebCore/platform/network/FormData.cpp:
(WebCore::FormData::flatten const):
* Source/WebCore/platform/network/FormDataBuilder.cpp:
(WebCore::FormDataBuilder::append):
* Source/WebCore/platform/network/HTTPParsers.cpp:
(WebCore::parseHTTPHeader):
(WebCore::parseHTTPRequestBody):
* Source/WebCore/platform/network/HTTPParsers.h:
* Source/WebCore/platform/network/SynchronousLoaderClient.cpp:
(WebCore::SynchronousLoaderClient::didReceiveData):
* Source/WebCore/platform/network/curl/CurlMultipartHandle.cpp:
(WebCore::CurlMultipartHandle::parseHeadersIfPossible):
* Source/WebCore/platform/text/QuotedPrintable.cpp:
(WebCore::quotedPrintableEncode):
* Source/WebCore/rendering/svg/SVGTextChunk.cpp:
(WebCore::SVGTextChunk::SVGTextChunk):
* Source/WebCore/svg/SVGToOTFFontConversion.cpp:
(WebCore::SVGToOTFFontConverter::appendOS2Table):
* Source/WebCore/testing/MockContentFilter.cpp:
(WebCore::MockContentFilter::maybeDetermineStatus):
* Source/WebCore/xml/parser/XMLDocumentParser.h:
* Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::PendingCallbacks::appendCharactersCallback):
(WebCore::XMLDocumentParser::characters):
(WebCore::charactersHandler):
* Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::sendReplyToSynchronousRequest):
* Source/WebKit/NetworkProcess/webrtc/LibWebRTCSocketClient.cpp:
(WebKit::LibWebRTCSocketClient::sendTo):
* Source/WebKit/NetworkProcess/webrtc/LibWebRTCSocketClient.h:
* Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp:
(WebKit::NetworkRTCProvider::sendToSocket):
* Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.h:
* Source/WebKit/NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.h:
* Source/WebKit/NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.mm:
(WebKit::NetworkRTCTCPSocketCocoa::createMessageBuffer):
(WebKit::NetworkRTCTCPSocketCocoa::sendTo):
* Source/WebKit/NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.h:
* Source/WebKit/NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.mm:
(WebKit::NetworkRTCUDPSocketCocoa::sendTo):
(WebKit::NetworkRTCUDPSocketCocoaConnections::sendTo):
* Source/WebKit/Shared/API/APIData.h:
(API::Data::data const):
(API::Data::bytes const):
(API::Data::dataReference const): Deleted.
* Source/WebKit/Shared/API/APIData.serialization.in:
* Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:
(-[WKRemoteObjectDecoder decodeBytesForKey:returnedLength:]):
* Source/WebKit/Shared/API/c/WKData.cpp:
(WKDataGetBytes):
* Source/WebKit/Shared/APIWebArchive.mm:
(API::WebArchive::WebArchive):
* Source/WebKit/Shared/APIWebArchiveResource.mm:
(API::WebArchiveResource::WebArchiveResource):
* Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm:
(WebKit::SandboxExtension::createHandleForTemporaryFile):
* Source/WebKit/Shared/Cocoa/WKNSData.mm:
(-[WKNSData bytes]):
* Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm:
(WebKit::fileContents):
(WebKit::compileAndCacheSandboxProfile):
* Source/WebKit/UIProcess/API/C/WKNotificationManager.cpp:
(WKNotificationManagerProviderDidClickNotification_b):
* Source/WebKit/UIProcess/API/C/WKPage.cpp:
(WKPageLoadData):
(WKPageLoadDataWithUserData):
(restoreFromSessionState):
* Source/WebKit/UIProcess/API/C/WKSessionStateRef.cpp:
(WKSessionStateCreateFromData):
* Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp:
(WebKit::WebNotificationManagerProxy::providerDidCloseNotifications):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didChooseFilesForOpenPanelWithDisplayStringAndIcon):
(WebKit::WebPageProxy::getWebCryptoMasterKey):
* Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::resumeDownload):
* Source/WebKit/UIProcess/mac/LegacySessionStateCoding.cpp:
(WebKit::HistoryEntryDataDecoder::operator>>):
* Source/WebKit/UIProcess/mac/WKPrintingView.mm:
(-[WKPrintingView _preparePDFDataForPrintingOnSecondaryThread]):
* Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp:
(WebKit::InjectedBundlePageEditorClient::getPasteboardDataForRange):
* Source/WebKit/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm:
(WebKit::createUnarchiver):
* Source/WebKit/WebProcess/Plugins/PDF/PDFIncrementalLoader.mm:
(WebKit::ByteRangeRequest::addData):
(WebKit::PDFPluginStreamLoaderClient::didReceiveData):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::completeTextManipulation):
* Source/WebKitLegacy/WebCoreSupport/SocketStreamHandleClient.h:
* Source/WebKitLegacy/WebCoreSupport/SocketStreamHandleImpl.cpp:
(WebCore::removeTerminationCharacters):
(WebCore::cookieDataForHandshake):
(WebCore::SocketStreamHandleImpl::platformSendHandshake):
* Source/WebKitLegacy/WebCoreSupport/SocketStreamHandleImplCFNet.cpp:
(WebCore::SocketStreamHandleImpl::readStreamCallback):
* Source/WebKitLegacy/WebCoreSupport/WebCryptoClient.mm:
(WebCryptoClient::wrapCryptoKey const):
(WebCryptoClient::unwrapCryptoKey const):
* Source/WebKitLegacy/WebCoreSupport/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::didReceiveSocketStreamData):
(WebCore::WebSocketChannel::appendToBuffer):
* Source/WebKitLegacy/WebCoreSupport/WebSocketChannel.h:
* Source/WebKitLegacy/mac/WebCoreSupport/WebVisitedLinkStore.mm:
(WebVisitedLinkStore::addVisitedLink):
* Tools/DumpRenderTree/PixelDumpSupport.cpp:
(convertChecksumToPNGComment):
* Tools/TestWebKitAPI/Tests/WebCore/ASN1Utilities.cpp:
* Tools/TestWebKitAPI/Tests/WebCore/CtapPinTest.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp:
(TestWebKitAPI::getTestAttestedCredentialDataBytes):
(TestWebKitAPI::getTestAttestationObjectBytes):
(TestWebKitAPI::getTestCorruptedSignResponse):
(TestWebKitAPI::getTestU2fRegisterResponse):
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/MediaLoading.mm:
(TestWebKitAPI::testVideoBytes):
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
(respondToRangeRequests):
* Tools/TestWebKitAPI/cocoa/HTTPServer.mm:
(TestWebKitAPI::vectorFromData):
(TestWebKitAPI::appendUTF8ToVector):
(TestWebKitAPI::H2::Connection::receive const):
* Tools/WebKitTestRunner/PixelDumpSupport.cpp:
(convertChecksumToPNGComment):

Canonical link: https://commits.webkit.org/276319@main
  • Loading branch information
cdumez committed Mar 19, 2024
1 parent 2aaac53 commit c904754
Show file tree
Hide file tree
Showing 163 changed files with 559 additions and 564 deletions.
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/API/ObjcRuntimeExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ inline void forEachProtocolImplementingProtocol(Class cls, Protocol *target, voi
{
unsigned protocolsCount;
auto protocols = adoptSystem<__unsafe_unretained Protocol*[]>(class_copyProtocolList(cls, &protocolsCount));
worklist.append(protocols.get(), protocolsCount);
worklist.append(std::span { protocols.get(), protocolsCount });
}

bool stop = false;
Expand All @@ -83,7 +83,7 @@ inline void forEachProtocolImplementingProtocol(Class cls, Protocol *target, voi
{
unsigned protocolsCount;
auto protocols = adoptSystem<__unsafe_unretained Protocol*[]>(protocol_copyProtocolList(protocol, &protocolsCount));
worklist.append(protocols.get(), protocolsCount);
worklist.append(std::span { protocols.get(), protocolsCount });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/assembler/AbstractMacroAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ class AbstractMacroAssembler : public AbstractMacroAssemblerBase {

void append(const JumpList& other)
{
m_jumps.append(other.m_jumps.begin(), other.m_jumps.size());
m_jumps.appendVector(other.m_jumps);
}

bool empty() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ObjectPropertyConditionSet ObjectPropertyConditionSet::mergedWith(
Vector<ObjectPropertyCondition, 16> result;

if (!isEmpty())
result.append(m_data->begin(), m_data->size());
result.append(m_data->span());

for (const ObjectPropertyCondition& newCondition : other) {
bool foundMatch = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void RemoteInspectorConnectionClient::didReceive(RemoteInspectorSocketEndpoint&,
}
});
});
result.iterator->value.pushReceivedData(data.data(), data.size());
result.iterator->value.pushReceivedData(data.span());
}

std::optional<RemoteInspectorConnectionClient::Event> RemoteInspectorConnectionClient::extractEvent(ConnectionID clientID, Vector<uint8_t>&& data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ Vector<uint8_t> MessageParser::createMessage(const uint8_t* data, size_t size)
return messageBuffer;
}

void MessageParser::pushReceivedData(const uint8_t* data, size_t size)
void MessageParser::pushReceivedData(std::span<const uint8_t> data)
{
if (!data || !size || !m_listener)
if (data.empty() || !m_listener)
return;

m_buffer.append(data, size);
m_buffer.append(data);

if (!parse())
clearReceivedData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MessageParser {

MessageParser() { }
MessageParser(Function<void(Vector<uint8_t>&&)>&&);
void pushReceivedData(const uint8_t*, size_t);
void pushReceivedData(std::span<const uint8_t>);
void clearReceivedData();

private:
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/jsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3697,7 +3697,7 @@ static void runWithOptions(GlobalObject* globalObject, CommandLine& options, boo
case Script::CodeSource::File: {
fileName = String::fromLatin1(scripts[i].argument);
if (scripts[i].strictMode == Script::StrictMode::Strict)
scriptBuffer.append("\"use strict\";\n", strlen("\"use strict\";\n"));
scriptBuffer.append("\"use strict\";\n"_span);

if (isModule) {
// If necessary, prepend "./" so the module loader doesn't think this is a bare-name specifier.
Expand Down
10 changes: 5 additions & 5 deletions Source/JavaScriptCore/parser/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ JSTokenType Lexer<CharacterType>::parseIdentifierSlowCase(JSTokenData* tokenData
auto fillBuffer = [&] (bool isStart = false) {
// \uXXXX unicode characters or Surrogate pairs.
if (identifierStart != currentSourcePtr())
m_buffer16.append(identifierStart, currentSourcePtr() - identifierStart);
m_buffer16.append(std::span(identifierStart, currentSourcePtr() - identifierStart));

if (m_current == '\\') {
tokenData->escaped = true;
Expand Down Expand Up @@ -1150,7 +1150,7 @@ JSTokenType Lexer<CharacterType>::parseIdentifierSlowCase(JSTokenData* tokenData
const Identifier* ident = nullptr;
if (shouldCreateIdentifier) {
if (identifierStart != currentSourcePtr())
m_buffer16.append(identifierStart, currentSourcePtr() - identifierStart);
m_buffer16.append(std::span(identifierStart, currentSourcePtr() - identifierStart));
ident = makeIdentifier(m_buffer16.data(), m_buffer16.size());

tokenData->ident = ident;
Expand Down Expand Up @@ -1431,7 +1431,7 @@ typename Lexer<T>::StringParseResult Lexer<T>::parseTemplateLiteral(JSTokenData*
ASSERT_WITH_MESSAGE(rawStringStart != currentSourcePtr(), "We should have at least shifted the escape.");

if (rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings) {
m_bufferForRawTemplateString16.append(rawStringStart, currentSourcePtr() - rawStringStart);
m_bufferForRawTemplateString16.append(std::span(rawStringStart, currentSourcePtr() - rawStringStart));
m_bufferForRawTemplateString16.append('\n');
}

Expand Down Expand Up @@ -1474,7 +1474,7 @@ typename Lexer<T>::StringParseResult Lexer<T>::parseTemplateLiteral(JSTokenData*
if (stringStart != currentSourcePtr())
append16(stringStart, currentSourcePtr() - stringStart);
if (rawStringStart != currentSourcePtr() && rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings)
m_bufferForRawTemplateString16.append(rawStringStart, currentSourcePtr() - rawStringStart);
m_bufferForRawTemplateString16.append(std::span(rawStringStart, currentSourcePtr() - rawStringStart));

record16('\n');
if (rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings)
Expand All @@ -1497,7 +1497,7 @@ typename Lexer<T>::StringParseResult Lexer<T>::parseTemplateLiteral(JSTokenData*
if (currentSourcePtr() != stringStart)
append16(stringStart, currentSourcePtr() - stringStart);
if (rawStringStart != currentSourcePtr() && rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings)
m_bufferForRawTemplateString16.append(rawStringStart, currentSourcePtr() - rawStringStart);
m_bufferForRawTemplateString16.append(std::span(rawStringStart, currentSourcePtr() - rawStringStart));

if (!parseCookedFailed)
tokenData->cooked = makeIdentifier(m_buffer16.data(), m_buffer16.size());
Expand Down
3 changes: 2 additions & 1 deletion Source/JavaScriptCore/parser/Lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ class Lexer {
void record16(int);
void record16(T);
void recordUnicodeCodePoint(char32_t);
// FIXME: These should take in spans.
void append16(const LChar*, size_t);
void append16(const UChar* characters, size_t length) { m_buffer16.append(characters, length); }
void append16(const UChar* characters, size_t length) { m_buffer16.append(std::span { characters, length }); }

static constexpr char32_t errorCodePoint = 0xFFFFFFFFu;
char32_t currentCodePoint() const;
Expand Down
8 changes: 4 additions & 4 deletions Source/JavaScriptCore/runtime/IntlLocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ void LocaleIDBuilder::overrideLanguageScriptRegion(StringView language, StringVi

ASSERT(subtag.containsOnlyASCII());
if (subtag.is8Bit())
buffer.append(subtag.characters8(), subtag.length());
buffer.append(subtag.span8());
else
buffer.append(subtag.characters16(), subtag.length());
buffer.append(subtag.span16());
}

if (endOfLanguageScriptRegionVariant != length) {
auto rest = localeIDView.right(length - endOfLanguageScriptRegionVariant);

ASSERT(rest.containsOnlyASCII());
if (rest.is8Bit())
buffer.append(rest.characters8(), rest.length());
buffer.append(rest.span8());
else
buffer.append(rest.characters16(), rest.length());
buffer.append(rest.span16());
}

buffer.append('\0');
Expand Down
15 changes: 6 additions & 9 deletions Source/JavaScriptCore/runtime/IntlObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,15 @@ Vector<char, 32> canonicalizeUnicodeExtensionsAfterICULocaleCanonicalization(Vec
end++;
}

Vector<char, 32> result;
result.append(buffer.data(), extensionIndex + 2); // "-u" is included.
Vector<char, 32> result(buffer.subspan(0, extensionIndex + 2)); // "-u" is included.
StringView extension = locale.substring(extensionIndex, extensionLength);
ASSERT(extension.is8Bit());
auto subtags = unicodeExtensionComponents(extension);
for (unsigned index = 0; index < subtags.size();) {
auto subtag = subtags[index];
ASSERT(subtag.is8Bit());
result.append('-');
result.append(subtag.characters8(), subtag.length());
result.append(subtag.span8());

if (subtag.length() != 2) {
++index;
Expand All @@ -384,15 +383,13 @@ Vector<char, 32> canonicalizeUnicodeExtensionsAfterICULocaleCanonicalization(Vec
auto value = subtags[valueIndex];
if (value != "true"_s) {
result.append('-');
result.append(value.characters8(), value.length());
result.append(value.span8());
}
}
index = valueIndexEnd;
}

unsigned remainingStart = extensionIndex + extensionLength;
unsigned remainingLength = buffer.size() - remainingStart;
result.append(buffer.data() + remainingStart, remainingLength);
result.append(buffer.subspan(extensionIndex + extensionLength));
return result;
}

Expand Down Expand Up @@ -432,10 +429,10 @@ static void addScriptlessLocaleIfNeeded(LocaleSet& availableLocales, StringView

Vector<char, 12> buffer;
ASSERT(subtags[0].is8Bit() && subtags[0].containsOnlyASCII());
buffer.append(reinterpret_cast<const char*>(subtags[0].characters8()), subtags[0].length());
buffer.append(subtags[0].span8());
buffer.append('-');
ASSERT(subtags[2].is8Bit() && subtags[2].containsOnlyASCII());
buffer.append(reinterpret_cast<const char*>(subtags[2].characters8()), subtags[2].length());
buffer.append(subtags[2].span8());

availableLocales.add(StringImpl::createStaticStringImpl(buffer.data(), buffer.size()));
}
Expand Down
21 changes: 10 additions & 11 deletions Source/JavaScriptCore/runtime/StringPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1971,9 +1971,9 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncNormalize, (JSGlobalObject* globalObject
RELEASE_AND_RETURN(scope, JSValue::encode(normalize(globalObject, string, form)));
}

static inline std::optional<unsigned> illFormedIndex(const UChar* characters, unsigned length)
static inline std::optional<unsigned> illFormedIndex(std::span<const UChar> characters)
{
for (unsigned index = 0; index < length; ++index) {
for (unsigned index = 0; index < characters.size(); ++index) {
UChar character = characters[index];
if (!U16_IS_SURROGATE(character))
continue;
Expand All @@ -1982,7 +1982,7 @@ static inline std::optional<unsigned> illFormedIndex(const UChar* characters, un
return index;

ASSERT(U16_IS_SURROGATE_LEAD(character));
if ((index + 1) == length)
if ((index + 1) == characters.size())
return index;
UChar nextCharacter = characters[index + 1];

Expand Down Expand Up @@ -2015,7 +2015,7 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncIsWellFormed, (JSGlobalObject* globalObj

if (string.is8Bit())
return JSValue::encode(jsBoolean(true));
return JSValue::encode(jsBoolean(!illFormedIndex(string.characters16(), string.length())));
return JSValue::encode(jsBoolean(!illFormedIndex(string.span16())));
}

JSC_DEFINE_HOST_FUNCTION(stringProtoFuncToWellFormed, (JSGlobalObject* globalObject, CallFrame* callFrame))
Expand Down Expand Up @@ -2043,16 +2043,15 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncToWellFormed, (JSGlobalObject* globalObj
if (string.is8Bit())
return JSValue::encode(stringValue);

const UChar* characters = string.characters16();
unsigned length = string.length();
auto firstIllFormedIndex = illFormedIndex(characters, length);
auto characters = string.span16();
auto firstIllFormedIndex = illFormedIndex(characters);
if (!firstIllFormedIndex)
return JSValue::encode(stringValue);

Vector<UChar> buffer;
buffer.reserveInitialCapacity(length);
buffer.append(characters, firstIllFormedIndex.value());
for (unsigned index = firstIllFormedIndex.value(); index < length; ++index) {
buffer.reserveInitialCapacity(characters.size());
buffer.append(characters.first(*firstIllFormedIndex));
for (unsigned index = firstIllFormedIndex.value(); index < characters.size(); ++index) {
UChar character = characters[index];

if (!U16_IS_SURROGATE(character)) {
Expand All @@ -2066,7 +2065,7 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncToWellFormed, (JSGlobalObject* globalObj
}

ASSERT(U16_IS_SURROGATE_LEAD(character));
if ((index + 1) == length) {
if ((index + 1) == characters.size()) {
buffer.append(replacementCharacter);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/tools/JSDollarVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ JSC_DEFINE_HOST_FUNCTION(functionWasmStreamingParserAddBytes, (JSGlobalObject* g

auto data = getWasmBufferFromValue(globalObject, value, guard);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
RELEASE_AND_RETURN(scope, JSValue::encode(jsNumber(static_cast<int32_t>(thisObject->streamingParser().addBytes(bitwise_cast<const uint8_t*>(data.first), data.second)))));
RELEASE_AND_RETURN(scope, JSValue::encode(jsNumber(static_cast<int32_t>(thisObject->streamingParser().addBytes(std::span { bitwise_cast<const uint8_t*>(data.first), data.second })))));
}

JSC_DEFINE_HOST_FUNCTION(functionWasmStreamingParserFinalize, (JSGlobalObject*, CallFrame* callFrame))
Expand Down Expand Up @@ -2112,7 +2112,7 @@ JSC_DEFINE_HOST_FUNCTION(functionWasmStreamingCompilerAddBytes, (JSGlobalObject*

auto data = getWasmBufferFromValue(globalObject, value, guard);
RETURN_IF_EXCEPTION(scope, { });
thisObject->streamingCompiler().addBytes(bitwise_cast<const uint8_t*>(data.first), data.second);
thisObject->streamingCompiler().addBytes(std::span { bitwise_cast<const uint8_t*>(data.first), data.second });
return JSValue::encode(jsUndefined());
}

Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/wasm/WasmBBQPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class BBQPlan final : public EntryPlan {

bool parseAndValidateModule()
{
return Base::parseAndValidateModule(m_source.data(), m_source.size());
return Base::parseAndValidateModule(m_source.span());
}

static FunctionAllowlist& ensureGlobalBBQAllowlist();
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/wasm/WasmEntryPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void EntryPlan::moveToState(State state)
m_state = state;
}

bool EntryPlan::parseAndValidateModule(const uint8_t* source, size_t sourceLength)
bool EntryPlan::parseAndValidateModule(std::span<const uint8_t> source)
{
if (m_state != State::Initial)
return true;
Expand All @@ -88,7 +88,7 @@ bool EntryPlan::parseAndValidateModule(const uint8_t* source, size_t sourceLengt
if (WasmEntryPlanInternal::verbose || Options::reportCompileTimes())
startTime = MonotonicTime::now();

m_streamingParser.addBytes(source, sourceLength);
m_streamingParser.addBytes(source);
{
Locker locker { m_lock };
if (failed())
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/wasm/WasmEntryPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class EntryPlan : public Plan, public StreamingParserClient {
// For some reason friendship doesn't extend to parent classes...
using Base::m_lock;

bool parseAndValidateModule(const uint8_t*, size_t);
bool parseAndValidateModule(std::span<const uint8_t>);

const char* stateString(State);
void moveToState(State);
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/wasm/WasmIPIntPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace JSC { namespace Wasm {
IPIntPlan::IPIntPlan(VM& vm, Vector<uint8_t>&& source, CompilerMode compilerMode, CompletionTask&& task)
: Base(vm, WTFMove(source), compilerMode, WTFMove(task))
{
if (parseAndValidateModule(m_source.data(), m_source.size()))
if (parseAndValidateModule(m_source.span()))
prepare();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/wasm/WasmLLIntPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace JSC { namespace Wasm {
LLIntPlan::LLIntPlan(VM& vm, Vector<uint8_t>&& source, CompilerMode compilerMode, CompletionTask&& task)
: Base(vm, WTFMove(source), compilerMode, WTFMove(task))
{
if (parseAndValidateModule(m_source.data(), m_source.size()))
if (parseAndValidateModule(m_source.span()))
prepare();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/wasm/WasmStreamingCompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class StreamingCompiler final : public StreamingParserClient, public ThreadSafeR

JS_EXPORT_PRIVATE ~StreamingCompiler();

void addBytes(const uint8_t* bytes, size_t length) { m_parser.addBytes(bytes, length); }
void addBytes(std::span<const uint8_t> bytes) { m_parser.addBytes(bytes); }
JS_EXPORT_PRIVATE void finalize(JSGlobalObject*);
JS_EXPORT_PRIVATE void fail(JSGlobalObject*, JSValue);
JS_EXPORT_PRIVATE void cancel();
Expand Down
Loading

0 comments on commit c904754

Please sign in to comment.