Skip to content

Commit

Permalink
Bug 1490601 part 2 - Move C++ entry points to encoding_c_mem to mfbt/…
Browse files Browse the repository at this point in the history
…. r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D43957

--HG--
extra : moz-landing-system : lando
  • Loading branch information
hsivonen committed Sep 18, 2019
1 parent 97bba9f commit c193518
Show file tree
Hide file tree
Showing 54 changed files with 618 additions and 352 deletions.
3 changes: 2 additions & 1 deletion dom/base/ThirdPartyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "mozilla/dom/Document.h"
#include "mozilla/Logging.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/TextUtils.h"
#include "mozilla/Unused.h"
#include "nsGlobalWindowOuter.h"

Expand Down Expand Up @@ -433,7 +434,7 @@ NS_IMETHODIMP
ThirdPartyUtil::GetBaseDomainFromSchemeHost(const nsACString& aScheme,
const nsACString& aAsciiHost,
nsACString& aBaseDomain) {
MOZ_DIAGNOSTIC_ASSERT(IsASCII(aAsciiHost));
MOZ_DIAGNOSTIC_ASSERT(IsAscii(aAsciiHost));

// Get the base domain. this will fail if the host contains a leading dot,
// more than one trailing dot, or is otherwise malformed.
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8038,7 +8038,7 @@ class BulkAppender {
void Append(Span<const char> aStr) {
size_t len = aStr.Length();
MOZ_ASSERT(mPosition + len <= mHandle.Length());
ConvertLatin1toUTF16(aStr, mHandle.AsSpan().From(mPosition));
ConvertLatin1toUtf16(aStr, mHandle.AsSpan().From(mPosition));
mPosition += len;
}

Expand Down
8 changes: 4 additions & 4 deletions dom/base/nsTextFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ bool nsTextFragment::SetTo(const char16_t* aBuffer, int32_t aLength,
}

// Copy data
LossyConvertUTF16toLatin1(MakeSpan(aBuffer, aLength),
LossyConvertUtf16toLatin1(MakeSpan(aBuffer, aLength),
MakeSpan(buff, aLength));
m1b = buff;
mState.mIs2b = false;
Expand Down Expand Up @@ -344,7 +344,7 @@ void nsTextFragment::CopyTo(char16_t* aDest, int32_t aOffset, int32_t aCount) {
memcpy(aDest, Get2b() + aOffset, sizeof(char16_t) * aCount);
} else {
const char* cp = m1b + aOffset;
ConvertLatin1toUTF16(MakeSpan(cp, aCount), MakeSpan(aDest, aCount));
ConvertLatin1toUtf16(MakeSpan(cp, aCount), MakeSpan(aDest, aCount));
}
}
}
Expand Down Expand Up @@ -429,7 +429,7 @@ bool nsTextFragment::Append(const char16_t* aBuffer, uint32_t aLength,

// Copy data into buff
char16_t* data = static_cast<char16_t*>(buff->Data());
ConvertLatin1toUTF16(MakeSpan(m1b, mState.mLength),
ConvertLatin1toUtf16(MakeSpan(m1b, mState.mLength),
MakeSpan(data, mState.mLength));

memcpy(data + mState.mLength, aBuffer, aLength * sizeof(char16_t));
Expand Down Expand Up @@ -471,7 +471,7 @@ bool nsTextFragment::Append(const char16_t* aBuffer, uint32_t aLength,
}

// Copy aBuffer into buff.
LossyConvertUTF16toLatin1(MakeSpan(aBuffer, aLength),
LossyConvertUtf16toLatin1(MakeSpan(aBuffer, aLength),
MakeSpan(buff + mState.mLength, aLength));

m1b = buff;
Expand Down
2 changes: 1 addition & 1 deletion dom/bindings/BindingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2654,7 +2654,7 @@ bool NonVoidByteStringToJsval(JSContext* cx, const nsACString& str,
void NormalizeUSVString(nsAString& aString) { EnsureUTF16Validity(aString); }

void NormalizeUSVString(binding_detail::FakeString& aString) {
EnsureUTF16ValiditySpan(aString);
EnsureUtf16ValiditySpan(aString);
}

bool ConvertJSValueToByteString(JSContext* cx, JS::Handle<JS::Value> v,
Expand Down
3 changes: 2 additions & 1 deletion dom/crypto/WebCryptoTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "jsapi.h"
#include "mozilla/Telemetry.h"
#include "mozilla/Utf8.h"
#include "mozilla/dom/CryptoBuffer.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/KeyAlgorithmProxy.h"
Expand Down Expand Up @@ -1365,7 +1366,7 @@ class ImportKeyTask : public WebCryptoTask {
nsDependentCSubstring utf8(
(const char*)mKeyData.Elements(),
(const char*)(mKeyData.Elements() + mKeyData.Length()));
if (!IsUTF8(utf8)) {
if (!IsUtf8(utf8)) {
mEarlyRv = NS_ERROR_DOM_DATA_ERR;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions dom/encoding/TextEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void TextEncoder::Encode(JSContext* aCx, JS::Handle<JSObject*> aObj,
return;
}

size_t utf8Len = ConvertUTF16toUTF8(
size_t utf8Len = ConvertUtf16toUtf8(
aString, MakeSpan(reinterpret_cast<char*>(data.get()), bufLen.value()));
MOZ_ASSERT(utf8Len <= bufLen.value());

Expand All @@ -53,7 +53,7 @@ void TextEncoder::EncodeInto(const nsAString& aSrc, const Uint8Array& aDst,
aDst.ComputeLengthAndData();
size_t read;
size_t written;
Tie(read, written) = ConvertUTF16toUTF8Partial(
Tie(read, written) = ConvertUtf16toUtf8Partial(
aSrc, MakeSpan(reinterpret_cast<char*>(aDst.Data()), aDst.Length()));
aResult.mRead.Construct() = read;
aResult.mWritten.Construct() = written;
Expand Down
2 changes: 1 addition & 1 deletion dom/file/FileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace {
void PopulateBufferForBinaryString(char16_t* aDest, const char* aSource,
uint32_t aCount) {
// Zero-extend each char to char16_t.
ConvertLatin1toUTF16(MakeSpan(aSource, aCount), MakeSpan(aDest, aCount));
ConvertLatin1toUtf16(MakeSpan(aSource, aCount), MakeSpan(aDest, aCount));
}

nsresult ReadFuncBinaryString(nsIInputStream* aInputStream, void* aClosure,
Expand Down
3 changes: 2 additions & 1 deletion dom/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "mozilla/dom/WheelEventBinding.h"
#include "mozilla/PresShell.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/TextUtils.h"
#include "nsAttrValueInlines.h"
#include "nsCRTGlue.h"
#include "nsQueryObject.h"
Expand Down Expand Up @@ -1540,7 +1541,7 @@ int32_t HTMLInputElement::MonthsSinceJan1970(uint32_t aYear,

/* static */
Decimal HTMLInputElement::StringToDecimal(const nsAString& aValue) {
if (!IsASCII(aValue)) {
if (!IsAscii(aValue)) {
return Decimal::nan();
}
NS_LossyConvertUTF16toASCII asciiString(aValue);
Expand Down
4 changes: 3 additions & 1 deletion dom/jsurl/nsJSProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@

#include "mozilla/LoadInfo.h"
#include "mozilla/Maybe.h"
#include "mozilla/TextUtils.h"
#include "mozilla/ipc/URIUtils.h"

using mozilla::IsAscii;
using mozilla::dom::AutoEntryScript;

static NS_DEFINE_CID(kJSURICID, NS_JSURI_CID);
Expand Down Expand Up @@ -1078,7 +1080,7 @@ nsresult nsJSProtocolHandler::Create(nsISupports* aOuter, REFNSIID aIID,
uStr);
NS_ENSURE_SUCCESS(rv, rv);

if (!IsASCII(uStr)) {
if (!IsAscii(uStr)) {
rv = NS_EscapeURL(NS_ConvertUTF16toUTF8(uStr),
esc_AlwaysCopy | esc_OnlyNonASCII, aUTF8Spec,
mozilla::fallible);
Expand Down
6 changes: 4 additions & 2 deletions dom/media/ogg/OggCodecState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <string.h>

#include "mozilla/EndianUtils.h"
#include "mozilla/TextUtils.h"
#include "mozilla/Utf8.h"
#include <stdint.h>
#include <algorithm>
#include <opus/opus.h>
Expand Down Expand Up @@ -109,7 +111,7 @@ bool OggCodecState::AddVorbisComment(UniquePtr<MetadataTags>& aTags,
}
uint32_t valueLength = aLength - (div - aComment);
nsCString value = nsCString(div + 1, valueLength);
if (!IsUTF8(value)) {
if (!IsUtf8(value)) {
LOG(LogLevel::Debug, ("Skipping comment: invalid UTF-8 in value"));
return false;
}
Expand Down Expand Up @@ -1598,7 +1600,7 @@ bool SkeletonState::DecodeFisbone(ogg_packet* aPacket) {
return false;
}

if ((i == 0 && IsASCII(strMsg)) || (i != 0 && IsUTF8(strMsg))) {
if ((i == 0 && IsAscii(strMsg)) || (i != 0 && IsUtf8(strMsg))) {
EMsgHeaderType eHeaderType = kFieldTypeMaps[i].mMsgHeaderType;
field->mValuesStore.LookupForAdd(eHeaderType)
.OrInsert([i, msgHead, msgProbe]() {
Expand Down
3 changes: 2 additions & 1 deletion dom/media/wave/WaveDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "mozilla/Assertions.h"
#include "mozilla/EndianUtils.h"
#include "mozilla/Utf8.h"
#include "BufferReader.h"
#include "VideoUtils.h"
#include "TimeUnits.h"
Expand Down Expand Up @@ -229,7 +230,7 @@ bool WAVTrackDemuxer::ListChunkParserInit(uint32_t aChunkSize) {

bytesRead += length;

if (!IsUTF8(val)) {
if (!IsUtf8(val)) {
mHeaderParser.Reset();
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion dom/plugins/base/nsPluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "mozilla/LoadInfo.h"
#include "mozilla/plugins/PluginBridge.h"
#include "mozilla/plugins/PluginTypes.h"
#include "mozilla/TextUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/ipc/URIUtils.h"

Expand Down Expand Up @@ -1375,7 +1376,7 @@ nsresult nsPluginHost::GetPlugin(const nsACString& aMimeType,

// Normalize 'host' to ACE.
nsresult nsPluginHost::NormalizeHostname(nsCString& host) {
if (IsASCII(host)) {
if (IsAscii(host)) {
ToLowerCase(host);
return NS_OK;
}
Expand Down
4 changes: 3 additions & 1 deletion extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
#include "nsJSPrincipals.h"
#include "nsIScriptError.h"
#include "js/Wrapper.h"
#include "mozilla/Utf8.h"

extern mozilla::LazyLogModule MCD;
using mozilla::AutoSafeJSContext;
using mozilla::IsUtf8;
using mozilla::NullPrincipal;
using mozilla::dom::AutoJSAPI;

Expand Down Expand Up @@ -138,7 +140,7 @@ nsresult EvaluateAdminConfigScript(JS::HandleObject sandbox,
JS::RootedValue v(cx);

nsString convertedScript;
bool isUTF8 = IsUTF8(script);
bool isUTF8 = IsUtf8(script);
if (isUTF8) {
convertedScript = NS_ConvertUTF8toUTF16(script);
} else {
Expand Down
3 changes: 2 additions & 1 deletion gfx/thebes/gfxGDIFontList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>

#include "mozilla/Logging.h"
#include "mozilla/TextUtils.h"
#include "mozilla/Sprintf.h"

#include "gfxGDIFontList.h"
Expand Down Expand Up @@ -638,7 +639,7 @@ int CALLBACK gfxGDIFontList::EnumFontFamExProc(ENUMLOGFONTEXW* lpelfe,
// GDI, then if a family name is non-ASCII immediately read in other
// family names. This assures that MS Gothic, MS Mincho are all found
// before lookups begin.
if (!IsASCII(faceName)) {
if (!IsAscii(faceName)) {
family->ReadOtherFamilyNames(gfxPlatformFontList::PlatformFontList());
}

Expand Down
5 changes: 3 additions & 2 deletions gfx/thebes/gfxPlatformFontList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "mozilla/gfx/2D.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/TextUtils.h"
#include "mozilla/Unused.h"

#include "base/eintr_wrapper.h"
Expand Down Expand Up @@ -944,7 +945,7 @@ bool gfxPlatformFontList::FindAndAddFamilies(
// since reading name table entries is expensive.
// Although ASCII localized family names are possible they don't occur
// in practice, so avoid pulling in names at startup.
if (!mOtherFamilyNamesInitialized && !IsASCII(aFamily)) {
if (!mOtherFamilyNamesInitialized && !IsAscii(aFamily)) {
InitOtherFamilyNames(
!(aFlags & FindFamiliesFlags::eForceOtherFamilyNamesLoading));
family = SharedFontList()->FindFamily(key);
Expand Down Expand Up @@ -981,7 +982,7 @@ bool gfxPlatformFontList::FindAndAddFamilies(
// since reading name table entries is expensive.
// although ASCII localized family names are possible they don't occur
// in practice so avoid pulling in names at startup
if (!familyEntry && !mOtherFamilyNamesInitialized && !IsASCII(aFamily)) {
if (!familyEntry && !mOtherFamilyNamesInitialized && !IsAscii(aFamily)) {
InitOtherFamilyNames(
!(aFlags & FindFamiliesFlags::eForceOtherFamilyNamesLoading));
familyEntry = mOtherFamilyNames.GetWeak(key);
Expand Down
4 changes: 3 additions & 1 deletion intl/locale/MozLocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* 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/. */

#include "mozilla/TextUtils.h"
#include "mozilla/intl/MozLocale.h"

#include "nsReadableUtils.h"
Expand All @@ -11,13 +12,14 @@
#include "unicode/uloc.h"

using namespace mozilla::intl;
using mozilla::IsAscii;

/**
* Note: The file name is `MozLocale` to avoid compilation problems on
* case-insensitive Windows. The class name is `Locale`.
*/
Locale::Locale(const nsACString& aLocale) {
if (aLocale.IsEmpty() || !IsASCII(aLocale)) {
if (aLocale.IsEmpty() || !IsAscii(aLocale)) {
mIsWellFormed = false;
return;
}
Expand Down
1 change: 0 additions & 1 deletion intl/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ EXPORTS.mozilla += [
EXPORTS += [
'../third_party/rust/encoding_c/include/encoding_rs.h',
'../third_party/rust/encoding_c/include/encoding_rs_statics.h',
'../third_party/rust/encoding_c_mem/include/encoding_rs_mem.h',
'../third_party/rust/shift_or_euc_c/include/shift_or_euc.h',
]

Expand Down
8 changes: 5 additions & 3 deletions intl/uconv/nsTextToSubURI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/Encoding.h"
#include "mozilla/Preferences.h"
#include "mozilla/TextUtils.h"
#include "mozilla/Utf8.h"
#include "nsISupportsPrimitives.h"

using namespace mozilla;
Expand Down Expand Up @@ -79,11 +81,11 @@ nsresult nsTextToSubURI::convertURItoUnicode(const nsCString& aCharset,
bool isStatefulCharset = statefulCharset(aCharset.get());

if (!isStatefulCharset) {
if (IsASCII(aURI)) {
if (IsAscii(aURI)) {
CopyASCIItoUTF16(aURI, aOut);
return NS_OK;
}
if (IsUTF8(aURI)) {
if (IsUtf8(aURI)) {
CopyUTF8toUTF16(aURI, aOut);
return NS_OK;
}
Expand Down Expand Up @@ -148,7 +150,7 @@ nsTextToSubURI::UnEscapeNonAsciiURI(const nsACString& aCharset,
// leave the URI as it is if it's not UTF-8 and aCharset is not a ASCII
// superset since converting "http:" with such an encoding is always a bad
// idea.
if (!IsUTF8(unescapedSpec) &&
if (!IsUtf8(unescapedSpec) &&
(aCharset.LowerCaseEqualsLiteral("utf-16") ||
aCharset.LowerCaseEqualsLiteral("utf-16be") ||
aCharset.LowerCaseEqualsLiteral("utf-16le") ||
Expand Down
6 changes: 4 additions & 2 deletions js/src/frontend/TokenStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,11 +1763,13 @@ bool TokenStreamCharsBase<Unit>::addLineOfContext(ErrorMetadata* err,
"should only see UTF-8 here");

bool simple = utf16WindowLength == encodedWindowLength;
#ifdef DEBUG
auto isAscii = [](Unit u) { return IsAscii(u); };
MOZ_ASSERT(std::all_of(encodedWindow, encodedWindow + encodedWindowLength,
IsAscii<Unit>) == simple,
isAscii) == simple,
"equal window lengths in UTF-8 should correspond only to "
"wholly-ASCII text");

#endif
if (simple) {
err->tokenOffset = encodedTokenOffset;
err->lineLength = encodedWindowLength;
Expand Down
2 changes: 1 addition & 1 deletion js/src/frontend/TokenStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ class TokenStreamCharsShared {
*/
static constexpr MOZ_ALWAYS_INLINE MOZ_MUST_USE bool isAsciiCodePoint(
int32_t unit) {
return mozilla::IsAscii(unit);
return mozilla::IsAscii(static_cast<char32_t>(unit));
}

JSAtom* drainCharBufferIntoAtom(JSContext* cx) {
Expand Down
6 changes: 4 additions & 2 deletions js/src/wasm/WasmValidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ using namespace js;
using namespace js::jit;
using namespace js::wasm;

using mozilla::AsChars;
using mozilla::CheckedInt;
using mozilla::CheckedInt32;
using mozilla::IsValidUtf8;
using mozilla::IsUtf8;
using mozilla::MakeSpan;
using mozilla::Unused;

// Decoder implementation.
Expand Down Expand Up @@ -1544,7 +1546,7 @@ static UniqueChars DecodeName(Decoder& d) {
return nullptr;
}

if (!IsValidUtf8(bytes, numBytes)) {
if (!IsUtf8(AsChars(MakeSpan(bytes, numBytes)))) {
return nullptr;
}

Expand Down
Loading

0 comments on commit c193518

Please sign in to comment.