Skip to content

Commit

Permalink
C++20 Compatibility (mozilla#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdashti authored Feb 19, 2022
1 parent 94a3058 commit 2858516
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion js/src/debugger/Debugger-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inline bool js::Debugger::isHookCallAllowed(JSContext* cx) const {
// onNativeCall hook, we want to _only_ call the hooks attached to that
// specific debugger.
return !cx->insideDebuggerEvaluationWithOnNativeCallHook ||
this == cx->insideDebuggerEvaluationWithOnNativeCallHook;
this == cx->insideDebuggerEvaluationWithOnNativeCallHook.ref();
}

#endif /* debugger_Debugger_inl_h */
2 changes: 1 addition & 1 deletion js/src/gc/RootMarking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using RootEnum = RootedValueMap::Enum;
// ConcreteTraceable type are actually used at runtime.
struct ConcreteTraceable {
ConcreteTraceable() = delete;
void trace(JSTracer*) = delete;
void trace(JSTracer*) { MOZ_CRASH("This path is unreachable."); }
};

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions js/src/jit/InlineList.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class InlineForwardListIterator {

using Node = InlineForwardListNode<T>;

explicit InlineForwardListIterator<T>(const InlineForwardList<T>* owner)
explicit InlineForwardListIterator(const InlineForwardList<T>* owner)
: prev(const_cast<Node*>(static_cast<const Node*>(owner))),
iter(owner ? owner->next : nullptr)
#ifdef DEBUG
Expand All @@ -157,7 +157,7 @@ class InlineForwardListIterator {
{
}

InlineForwardListIterator<T>(const InlineForwardList<T>* owner, Node* node)
InlineForwardListIterator(const InlineForwardList<T>* owner, Node* node)
: prev(nullptr),
iter(node)
#ifdef DEBUG
Expand Down
8 changes: 4 additions & 4 deletions js/src/vm/Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -1649,11 +1649,11 @@ class AbstractBindingIter<JSAtom> : public BaseAbstractBindingIter<JSAtom> {
using Base = BaseAbstractBindingIter<JSAtom>;

public:
AbstractBindingIter<JSAtom>(ScopeKind kind, BaseScopeData* data,
uint32_t firstFrameSlot);
AbstractBindingIter(ScopeKind kind, BaseScopeData* data,
uint32_t firstFrameSlot);

explicit AbstractBindingIter<JSAtom>(Scope* scope);
explicit AbstractBindingIter<JSAtom>(JSScript* script);
explicit AbstractBindingIter(Scope* scope);
explicit AbstractBindingIter(JSScript* script);

using Base::Base;

Expand Down
9 changes: 9 additions & 0 deletions mfbt/TextUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ constexpr bool IsAscii(char aChar) {
return IsAscii(static_cast<unsigned char>(aChar));
}

#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811

/** Returns true iff |aChar| is ASCII, i.e. in the range [0, 0x80). */
constexpr bool IsAscii(char8_t aChar) {
return IsAscii(static_cast<unsigned char>(aChar));
}

#endif

/** Returns true iff |aChar| is ASCII, i.e. in the range [0, 0x80). */
constexpr bool IsAscii(char16_t aChar) { return aChar < 0x80; }

Expand Down
7 changes: 1 addition & 6 deletions mfbt/Utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,6 @@ size_t Utf16ValidUpTo(mozilla::Span<const char16_t> aString) {
size_t next = offset + 1;

char16_t unit_minus_surrogate_start = (unit - 0xD800);

// It's possible for 'unit' to be less than 0xD800. In that case, 'unit_minus_surrogate_start'
// underflows, but still the size of minimum underflow (when unit is 0 (i.e.,
// unit_minus_surrogate_start = 10240)) is way higher than (0xDFFF - 0xD800 = 2047). Then, these
// cases falls into the body of the following branch.
if (unit_minus_surrogate_start > (0xDFFF - 0xD800)) {
// Not a surrogate
offset = next;
Expand Down Expand Up @@ -262,7 +257,7 @@ size_t Utf16ValidUpTo(mozilla::Span<const char16_t> aString) {
// Latin1.h
////////////////////////////////////////////////////////////

inline size_t Utf8ValidUpToIndex(mozilla::Span<const char> aString) {
size_t Utf8ValidUpToIndex(mozilla::Span<const char> aString) {
size_t length = aString.Length();
const char* string = aString.Elements();
if (!length) return 0;
Expand Down
29 changes: 25 additions & 4 deletions mfbt/Utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ union Utf8Unit {

explicit constexpr Utf8Unit(char aUnit) : mValue(aUnit) {}

#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811

explicit constexpr Utf8Unit(char8_t aUnit)
: Utf8Unit(static_cast<char>(aUnit)) {}

#endif

explicit constexpr Utf8Unit(unsigned char aUnit)
: mValue(static_cast<char>(aUnit)) {
// Per the above comment, the prior cast is integral conversion with
Expand Down Expand Up @@ -251,10 +258,9 @@ constexpr bool IsAscii(Utf8Unit aUnit) {
*
* The string *may* contain U+0000 NULL code points.
*/
inline bool IsUtf8(mozilla::Span<const char> aString) {
namespace detail {
inline bool IsUtf8(const uint8_t* ptr, size_t length) {
#if MOZ_HAS_JSRUST()
size_t length = aString.Length();
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(aString.Elements());
// For short strings, the function call is a pessimization, and the SIMD
// code won't have a chance to kick in anyway.
if (length < 16) {
Expand All @@ -270,9 +276,24 @@ inline bool IsUtf8(mozilla::Span<const char> aString) {
end:
return length == encoding_utf8_valid_up_to(ptr, length);
#else
return detail::IsValidUtf8(aString.Elements(), aString.Length());
return detail::IsValidUtf8(ptr, length);
#endif
}
} // namespace detail

inline bool IsUtf8(mozilla::Span<const char> aString) {
return detail::IsUtf8(reinterpret_cast<const uint8_t*>(aString.Elements()),
aString.Length());
}

#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811

inline bool IsUtf8(mozilla::Span<const char8_t> aString) {
return detail::IsUtf8(reinterpret_cast<const uint8_t*>(aString.Elements()),
aString.Length());
}

#endif

#if MOZ_HAS_JSRUST()

Expand Down

0 comments on commit 2858516

Please sign in to comment.