commit 7a26c6d7a5fb669e0b3126d3ff1e6cd62180edaf
parent 973c1d7f9b0fa67c119e95013bdefdfe32c2d563
Author: André Bargull <andre.bargull@gmail.com>
Date: Wed, 17 Dec 2025 13:42:07 +0000
Bug 2002523: Move lambdas into MOZ_ASSERT. r=spidermonkey-reviewers,jandem
C++20 allows lambdas in unevaluated contexts, so the issue described in
bug 1583449 no longer applies.
Differential Revision: https://phabricator.services.mozilla.com/D274125
Diffstat:
5 files changed, 17 insertions(+), 34 deletions(-)
diff --git a/intl/components/src/Locale.h b/intl/components/src/Locale.h
@@ -422,13 +422,10 @@ class MOZ_STACK_CLASS Locale final {
* Set the variant subtags. Each element must be a valid variant subtag.
*/
void SetVariants(VariantsVector&& aVariants) {
-#ifdef DEBUG
- // See bug 1583449 for why the lambda can't be in the MOZ_ASSERT.
- auto isValidVariant = [](const auto& variant) {
- return IsStructurallyValidVariantTag(variant.Span());
- };
-#endif
- MOZ_ASSERT(std::all_of(aVariants.begin(), aVariants.end(), isValidVariant));
+ MOZ_ASSERT(std::all_of(
+ aVariants.begin(), aVariants.end(), [](const auto& variant) {
+ return IsStructurallyValidVariantTag(variant.Span());
+ }));
mVariants = std::move(aVariants);
}
diff --git a/js/src/builtin/intl/CommonFunctions.cpp b/js/src/builtin/intl/CommonFunctions.cpp
@@ -145,20 +145,15 @@ js::UniqueChars js::intl::EncodeLocale(JSContext* cx, JSString* locale) {
MOZ_ASSERT(locale->length() > 0);
js::UniqueChars chars = EncodeAscii(cx, locale);
+ if (!chars) {
+ return nullptr;
+ }
-#ifdef DEBUG
// Ensure the returned value contains only valid BCP 47 characters.
- // (Lambdas can't be placed inside MOZ_ASSERT, so move the checks in an
- // #ifdef block.)
- if (chars) {
- auto alnumOrDash = [](char c) {
- return mozilla::IsAsciiAlphanumeric(c) || c == '-';
- };
- MOZ_ASSERT(mozilla::IsAsciiAlpha(chars[0]));
- MOZ_ASSERT(
- std::all_of(chars.get(), chars.get() + locale->length(), alnumOrDash));
- }
-#endif
+ MOZ_ASSERT(mozilla::IsAsciiAlpha(chars[0]));
+ MOZ_ASSERT(std::all_of(
+ chars.get(), chars.get() + locale->length(),
+ [](char c) { return mozilla::IsAsciiAlphanumeric(c) || c == '-'; }));
return chars;
}
diff --git a/js/src/builtin/intl/IntlObject.cpp b/js/src/builtin/intl/IntlObject.cpp
@@ -223,14 +223,10 @@ template <size_t N>
static ArrayObject* CreateArrayFromSortedList(
JSContext* cx, const std::array<const char*, N>& list) {
// Ensure the list is sorted and doesn't contain duplicates.
-#ifdef DEBUG
- // See bug 1583449 for why the lambda can't be in the MOZ_ASSERT.
- auto isLargerThanOrEqual = [](const auto& a, const auto& b) {
- return std::strcmp(a, b) >= 0;
- };
-#endif
MOZ_ASSERT(std::adjacent_find(std::begin(list), std::end(list),
- isLargerThanOrEqual) == std::end(list));
+ [](const auto& a, const auto& b) {
+ return std::strcmp(a, b) >= 0;
+ }) == std::end(list));
size_t length = std::size(list);
diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp
@@ -1614,13 +1614,10 @@ bool TokenStreamCharsBase<Unit>::addLineOfContext(ErrorMetadata* err,
static_assert(std::is_same_v<Unit, Utf8Unit>, "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) == simple,
+ [](Unit u) { return IsAscii(u); }) == simple,
"equal window lengths in UTF-8 should correspond only to "
"wholly-ASCII text");
-#endif
if (simple) {
err->tokenOffset = encodedTokenOffset;
err->lineLength = encodedWindowLength;
diff --git a/js/src/util/StringBuilder.cpp b/js/src/util/StringBuilder.cpp
@@ -115,11 +115,9 @@ JSLinearString* StringBuilder::finishStringInternal(JSContext* cx,
gc::Heap heap) {
// The Vector must include space for the mozilla::StringBuffer header.
MOZ_ASSERT(numHeaderChars_ == numHeaderChars<CharT>());
-#ifdef DEBUG
- auto isZeroChar = [](CharT c) { return c == '\0'; };
MOZ_ASSERT(std::all_of(chars<CharT>().begin(),
- chars<CharT>().begin() + numHeaderChars_, isZeroChar));
-#endif
+ chars<CharT>().begin() + numHeaderChars_,
+ [](CharT c) { return c == '\0'; }));
size_t len = length();