mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1488698 - Always use braces for if/for/while statements in js/public. r=jandem
--HG-- extra : rebase_source : 075f0747c9256fee67925853b501b7a3549cebba
This commit is contained in:
parent
670c162df3
commit
ab644b087f
@ -79,8 +79,9 @@ class TempAllocPolicy : public AllocPolicyBase
|
||||
template <typename T>
|
||||
T* onOutOfMemoryTyped(AllocFunction allocFunc, size_t numElems, void* reallocPtr = nullptr) {
|
||||
size_t bytes;
|
||||
if (MOZ_UNLIKELY(!CalculateAllocSize<T>(numElems, &bytes)))
|
||||
if (MOZ_UNLIKELY(!CalculateAllocSize<T>(numElems, &bytes))) {
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<T*>(onOutOfMemory(allocFunc, bytes, reallocPtr));
|
||||
}
|
||||
|
||||
@ -90,24 +91,27 @@ class TempAllocPolicy : public AllocPolicyBase
|
||||
template <typename T>
|
||||
T* pod_malloc(size_t numElems) {
|
||||
T* p = this->maybe_pod_malloc<T>(numElems);
|
||||
if (MOZ_UNLIKELY(!p))
|
||||
if (MOZ_UNLIKELY(!p)) {
|
||||
p = onOutOfMemoryTyped<T>(AllocFunction::Malloc, numElems);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* pod_calloc(size_t numElems) {
|
||||
T* p = this->maybe_pod_calloc<T>(numElems);
|
||||
if (MOZ_UNLIKELY(!p))
|
||||
if (MOZ_UNLIKELY(!p)) {
|
||||
p = onOutOfMemoryTyped<T>(AllocFunction::Calloc, numElems);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* pod_realloc(T* prior, size_t oldSize, size_t newSize) {
|
||||
T* p2 = this->maybe_pod_realloc<T>(prior, oldSize, newSize);
|
||||
if (MOZ_UNLIKELY(!p2))
|
||||
if (MOZ_UNLIKELY(!p2)) {
|
||||
p2 = onOutOfMemoryTyped<T>(AllocFunction::Realloc, newSize, prior);
|
||||
}
|
||||
return p2;
|
||||
}
|
||||
|
||||
|
@ -165,12 +165,14 @@ class MOZ_STACK_CLASS CallArgsBase
|
||||
// CALLING/CONSTRUCTING-DIFFERENTIATIONS
|
||||
|
||||
bool isConstructing() const {
|
||||
if (!argv_[-1].isMagic())
|
||||
if (!argv_[-1].isMagic()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef JS_DEBUG
|
||||
if (!this->usedRval())
|
||||
if (!this->usedRval()) {
|
||||
CheckIsValidConstructible(calleev());
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@ -312,8 +314,9 @@ class MOZ_STACK_CLASS CallArgs : public detail::CallArgsBase<detail::IncludeUsed
|
||||
#ifdef DEBUG
|
||||
MOZ_ASSERT(ValueIsNotGray(args.thisv()));
|
||||
MOZ_ASSERT(ValueIsNotGray(args.calleev()));
|
||||
for (unsigned i = 0; i < argc; ++i)
|
||||
for (unsigned i = 0; i < argc; ++i) {
|
||||
MOZ_ASSERT(ValueIsNotGray(argv[i]));
|
||||
}
|
||||
#endif
|
||||
return args;
|
||||
}
|
||||
|
@ -96,8 +96,9 @@ MOZ_ALWAYS_INLINE bool
|
||||
CallNonGenericMethod(JSContext* cx, const CallArgs& args)
|
||||
{
|
||||
HandleValue thisv = args.thisv();
|
||||
if (Test(thisv))
|
||||
if (Test(thisv)) {
|
||||
return Impl(cx, args);
|
||||
}
|
||||
|
||||
return detail::CallMethodIfWrapped(cx, Test, Impl, args);
|
||||
}
|
||||
@ -106,8 +107,9 @@ MOZ_ALWAYS_INLINE bool
|
||||
CallNonGenericMethod(JSContext* cx, IsAcceptableThis Test, NativeImpl Impl, const CallArgs& args)
|
||||
{
|
||||
HandleValue thisv = args.thisv();
|
||||
if (Test(thisv))
|
||||
if (Test(thisv)) {
|
||||
return Impl(cx, args);
|
||||
}
|
||||
|
||||
return detail::CallMethodIfWrapped(cx, Test, Impl, args);
|
||||
}
|
||||
|
@ -224,8 +224,9 @@ class ObjectOpResult
|
||||
* - Otherwise, do nothing and return true.
|
||||
*/
|
||||
bool checkStrictErrorOrWarning(JSContext* cx, HandleObject obj, HandleId id, bool strict) {
|
||||
if (ok())
|
||||
if (ok()) {
|
||||
return true;
|
||||
}
|
||||
return reportStrictErrorOrWarning(cx, obj, id, strict);
|
||||
}
|
||||
|
||||
@ -687,8 +688,9 @@ struct MOZ_STATIC_CLASS ClassSpec
|
||||
static_assert(JSProto_Null == 0, "zeroed key must be null");
|
||||
|
||||
// Default: Inherit from Object.
|
||||
if (!(flags & ProtoKeyMask))
|
||||
if (!(flags & ProtoKeyMask)) {
|
||||
return JSProto_Object;
|
||||
}
|
||||
|
||||
return JSProtoKey(flags & ProtoKeyMask);
|
||||
}
|
||||
|
@ -340,8 +340,9 @@ class JS_PUBLIC_API(OwningCompileOptions) final
|
||||
const char* intro, unsigned line,
|
||||
JSScript* script, uint32_t offset)
|
||||
{
|
||||
if (!setIntroducerFilename(cx, introducerFn))
|
||||
if (!setIntroducerFilename(cx, introducerFn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
introductionType = intro;
|
||||
introductionLineno = line;
|
||||
|
@ -109,18 +109,22 @@ OrdinaryToPrimitive(JSContext* cx, HandleObject obj, JSType type, MutableHandleV
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
ToBoolean(HandleValue v)
|
||||
{
|
||||
if (v.isBoolean())
|
||||
if (v.isBoolean()) {
|
||||
return v.toBoolean();
|
||||
if (v.isInt32())
|
||||
}
|
||||
if (v.isInt32()) {
|
||||
return v.toInt32() != 0;
|
||||
if (v.isNullOrUndefined())
|
||||
}
|
||||
if (v.isNullOrUndefined()) {
|
||||
return false;
|
||||
}
|
||||
if (v.isDouble()) {
|
||||
double d = v.toDouble();
|
||||
return !mozilla::IsNaN(d) && d != 0;
|
||||
}
|
||||
if (v.isSymbol())
|
||||
if (v.isSymbol()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* The slow path handles strings, BigInts and objects. */
|
||||
return js::ToBooleanSlow(v);
|
||||
@ -143,12 +147,14 @@ ToNumber(JSContext* cx, HandleValue v, double* out)
|
||||
inline double
|
||||
ToInteger(double d)
|
||||
{
|
||||
if (d == 0)
|
||||
if (d == 0) {
|
||||
return d;
|
||||
}
|
||||
|
||||
if (!mozilla::IsFinite(d)) {
|
||||
if (mozilla::IsNaN(d))
|
||||
if (mozilla::IsNaN(d)) {
|
||||
return 0;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
@ -271,8 +277,9 @@ ToString(JSContext* cx, HandleValue v)
|
||||
{
|
||||
detail::AssertArgumentsAreSane(cx, v);
|
||||
|
||||
if (v.isString())
|
||||
if (v.isString()) {
|
||||
return v.toString();
|
||||
}
|
||||
return js::ToStringSlow(cx, v);
|
||||
}
|
||||
|
||||
@ -282,8 +289,9 @@ ToObject(JSContext* cx, HandleValue v)
|
||||
{
|
||||
detail::AssertArgumentsAreSane(cx, v);
|
||||
|
||||
if (v.isObject())
|
||||
if (v.isObject()) {
|
||||
return &v.toObject();
|
||||
}
|
||||
return js::ToObjectSlow(cx, v, false);
|
||||
}
|
||||
|
||||
@ -318,8 +326,9 @@ ToUnsignedInteger(double d)
|
||||
|
||||
// If the exponent's less than zero, abs(d) < 1, so the result is 0. (This
|
||||
// also handles subnormals.)
|
||||
if (exp < 0)
|
||||
if (exp < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint_fast16_t exponent = mozilla::AssertedCast<uint_fast16_t>(exp);
|
||||
|
||||
@ -330,8 +339,9 @@ ToUnsignedInteger(double d)
|
||||
// 2**84 + 2**32. Thus if UnsignedInteger is uint32_t, an exponent >= 84
|
||||
// implies floor(abs(d)) == 0 mod 2**32.) Return 0 in all these cases.
|
||||
constexpr size_t ResultWidth = CHAR_BIT * sizeof(UnsignedInteger);
|
||||
if (exponent >= DoubleExponentShift + ResultWidth)
|
||||
if (exponent >= DoubleExponentShift + ResultWidth) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The significand contains the bits that will determine the final result.
|
||||
// Shift those bits left or right, according to the exponent, to their
|
||||
|
@ -103,8 +103,9 @@ TimeClip(double time)
|
||||
{
|
||||
// Steps 1-2.
|
||||
const double MaxTimeMagnitude = 8.64e15;
|
||||
if (!mozilla::IsFinite(time) || mozilla::Abs(time) > MaxTimeMagnitude)
|
||||
if (!mozilla::IsFinite(time) || mozilla::Abs(time) > MaxTimeMagnitude) {
|
||||
return ClippedTime(mozilla::UnspecifiedNaN<double>());
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
return ClippedTime(ToInteger(time) + (+0.0));
|
||||
|
@ -77,8 +77,9 @@ class GCHashMap : public js::HashMap<Key, Value, HashPolicy, AllocPolicy>
|
||||
|
||||
void sweep() {
|
||||
for (typename Base::Enum e(*this); !e.empty(); e.popFront()) {
|
||||
if (MapSweepPolicy::needsSweep(&e.front().mutableKey(), &e.front().value()))
|
||||
if (MapSweepPolicy::needsSweep(&e.front().mutableKey(), &e.front().value())) {
|
||||
e.removeFront();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,10 +122,11 @@ class GCRekeyableHashMap : public JS::GCHashMap<Key, Value, HashPolicy, AllocPol
|
||||
void sweep() {
|
||||
for (typename Base::Enum e(*this); !e.empty(); e.popFront()) {
|
||||
Key key(e.front().key());
|
||||
if (MapSweepPolicy::needsSweep(&key, &e.front().value()))
|
||||
if (MapSweepPolicy::needsSweep(&key, &e.front().value())) {
|
||||
e.removeFront();
|
||||
else if (!HashPolicy::match(key, e.front().key()))
|
||||
} else if (!HashPolicy::match(key, e.front().key())) {
|
||||
e.rekeyFront(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,8 +244,9 @@ class GCHashSet : public js::HashSet<T, HashPolicy, AllocPolicy>
|
||||
|
||||
static void trace(GCHashSet* set, JSTracer* trc) { set->trace(trc); }
|
||||
void trace(JSTracer* trc) {
|
||||
for (typename Base::Enum e(*this); !e.empty(); e.popFront())
|
||||
for (typename Base::Enum e(*this); !e.empty(); e.popFront()) {
|
||||
GCPolicy<T>::trace(trc, &e.mutableFront(), "hashset element");
|
||||
}
|
||||
}
|
||||
|
||||
bool needsSweep() const {
|
||||
@ -252,8 +255,9 @@ class GCHashSet : public js::HashSet<T, HashPolicy, AllocPolicy>
|
||||
|
||||
void sweep() {
|
||||
for (typename Base::Enum e(*this); !e.empty(); e.popFront()) {
|
||||
if (GCPolicy<T>::needsSweep(&e.mutableFront()))
|
||||
if (GCPolicy<T>::needsSweep(&e.mutableFront())) {
|
||||
e.removeFront();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,8 +443,9 @@ class WeakCache<GCHashMap<Key, Value, HashPolicy, AllocPolicy, MapSweepPolicy>>
|
||||
typename Map::Range range;
|
||||
|
||||
void settle() {
|
||||
while (!empty() && entryNeedsSweep(front()))
|
||||
while (!empty() && entryNeedsSweep(front())) {
|
||||
popFront();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -531,8 +536,9 @@ class WeakCache<GCHashMap<Key, Value, HashPolicy, AllocPolicy, MapSweepPolicy>>
|
||||
|
||||
void remove(const Lookup& l) {
|
||||
Ptr p = lookup(l);
|
||||
if (p)
|
||||
if (p) {
|
||||
remove(p);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename KeyInput, typename ValueInput>
|
||||
@ -634,8 +640,9 @@ class WeakCache<GCHashSet<T, HashPolicy, AllocPolicy>>
|
||||
typename Set::Range range;
|
||||
|
||||
void settle() {
|
||||
while (!empty() && entryNeedsSweep(front()))
|
||||
while (!empty() && entryNeedsSweep(front())) {
|
||||
popFront();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -726,8 +733,9 @@ class WeakCache<GCHashSet<T, HashPolicy, AllocPolicy>>
|
||||
|
||||
void remove(const Lookup& l) {
|
||||
Ptr p = lookup(l);
|
||||
if (p)
|
||||
if (p) {
|
||||
remove(p);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TInput>
|
||||
|
@ -112,12 +112,14 @@ struct GCPointerPolicy
|
||||
"Non-pointer type not allowed for GCPointerPolicy");
|
||||
|
||||
static void trace(JSTracer* trc, T* vp, const char* name) {
|
||||
if (*vp)
|
||||
if (*vp) {
|
||||
js::UnsafeTraceManuallyBarrieredEdge(trc, vp, name);
|
||||
}
|
||||
}
|
||||
static bool needsSweep(T* vp) {
|
||||
if (*vp)
|
||||
if (*vp) {
|
||||
return js::gc::IsAboutToBeFinalizedUnbarriered(vp);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static bool isValid(T v) {
|
||||
@ -134,12 +136,14 @@ template <typename T>
|
||||
struct NonGCPointerPolicy
|
||||
{
|
||||
static void trace(JSTracer* trc, T* vp, const char* name) {
|
||||
if (*vp)
|
||||
if (*vp) {
|
||||
(*vp)->trace(trc);
|
||||
}
|
||||
}
|
||||
static bool needsSweep(T* vp) {
|
||||
if (*vp)
|
||||
if (*vp) {
|
||||
return (*vp)->needsSweep();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static bool isValid(T v) {
|
||||
@ -163,17 +167,20 @@ template <typename T, typename D>
|
||||
struct GCPolicy<mozilla::UniquePtr<T, D>>
|
||||
{
|
||||
static void trace(JSTracer* trc, mozilla::UniquePtr<T,D>* tp, const char* name) {
|
||||
if (tp->get())
|
||||
if (tp->get()) {
|
||||
GCPolicy<T>::trace(trc, tp->get(), name);
|
||||
}
|
||||
}
|
||||
static bool needsSweep(mozilla::UniquePtr<T,D>* tp) {
|
||||
if (tp->get())
|
||||
if (tp->get()) {
|
||||
return GCPolicy<T>::needsSweep(tp->get());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static bool isValid(const mozilla::UniquePtr<T,D>& t) {
|
||||
if (t.get())
|
||||
if (t.get()) {
|
||||
return GCPolicy<T>::isValid(*t.get());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -184,17 +191,20 @@ template <typename T>
|
||||
struct GCPolicy<mozilla::Maybe<T>>
|
||||
{
|
||||
static void trace(JSTracer* trc, mozilla::Maybe<T>* tp, const char* name) {
|
||||
if (tp->isSome())
|
||||
if (tp->isSome()) {
|
||||
GCPolicy<T>::trace(trc, tp->ptr(), name);
|
||||
}
|
||||
}
|
||||
static bool needsSweep(mozilla::Maybe<T>* tp) {
|
||||
if (tp->isSome())
|
||||
if (tp->isSome()) {
|
||||
return GCPolicy<T>::needsSweep(tp->ptr());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static bool isValid(const mozilla::Maybe<T>& t) {
|
||||
if (t.isSome())
|
||||
if (t.isSome()) {
|
||||
return GCPolicy<T>::isValid(t.ref());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -48,8 +48,9 @@ struct GCVariantImplementation<T>
|
||||
template <typename ConcreteVariant>
|
||||
static void trace(JSTracer* trc, ConcreteVariant* v, const char* name) {
|
||||
T& thing = v->template as<T>();
|
||||
if (!mozilla::IsPointer<T>::value || thing)
|
||||
if (!mozilla::IsPointer<T>::value || thing) {
|
||||
GCPolicy<T>::trace(trc, &thing, name);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Matcher, typename ConcreteVariant>
|
||||
@ -77,8 +78,9 @@ struct GCVariantImplementation<T, Ts...>
|
||||
static void trace(JSTracer* trc, ConcreteVariant* v, const char* name) {
|
||||
if (v->template is<T>()) {
|
||||
T& thing = v->template as<T>();
|
||||
if (!mozilla::IsPointer<T>::value || thing)
|
||||
if (!mozilla::IsPointer<T>::value || thing) {
|
||||
GCPolicy<T>::trace(trc, &thing, name);
|
||||
}
|
||||
} else {
|
||||
Next::trace(trc, v, name);
|
||||
}
|
||||
|
@ -131,8 +131,9 @@ class GCVector
|
||||
static void trace(GCVector* vec, JSTracer* trc) { vec->trace(trc); }
|
||||
|
||||
void trace(JSTracer* trc) {
|
||||
for (auto& elem : vector)
|
||||
for (auto& elem : vector) {
|
||||
GCPolicy<T>::trace(trc, &elem, "vector element");
|
||||
}
|
||||
}
|
||||
|
||||
bool needsSweep() const {
|
||||
@ -143,14 +144,16 @@ class GCVector
|
||||
uint32_t src, dst = 0;
|
||||
for (src = 0; src < length(); src++) {
|
||||
if (!GCPolicy<T>::needsSweep(&vector[src])) {
|
||||
if (dst != src)
|
||||
if (dst != src) {
|
||||
vector[dst] = vector[src].unbarrieredGet();
|
||||
}
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
|
||||
if (dst != length())
|
||||
if (dst != length()) {
|
||||
vector.shrinkTo(dst);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -275,8 +275,9 @@ class JS_FRIEND_API(GCCellPtr)
|
||||
|
||||
JS::TraceKind kind() const {
|
||||
JS::TraceKind traceKind = JS::TraceKind(ptr & OutOfLineTraceKindMask);
|
||||
if (uintptr_t(traceKind) != OutOfLineTraceKindMask)
|
||||
if (uintptr_t(traceKind) != OutOfLineTraceKindMask) {
|
||||
return traceKind;
|
||||
}
|
||||
return outOfLineKind();
|
||||
}
|
||||
|
||||
@ -319,10 +320,12 @@ class JS_FRIEND_API(GCCellPtr)
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_INLINE bool mayBeOwnedByOtherRuntime() const {
|
||||
if (!is<JSString>() && !is<JS::Symbol>())
|
||||
if (!is<JSString>() && !is<JS::Symbol>()) {
|
||||
return false;
|
||||
if (is<JSString>())
|
||||
}
|
||||
if (is<JSString>()) {
|
||||
return JS::shadow::String::isPermanentAtom(asCell());
|
||||
}
|
||||
MOZ_ASSERT(is<JS::Symbol>());
|
||||
return JS::shadow::Symbol::isWellKnownSymbol(asCell());
|
||||
}
|
||||
@ -429,8 +432,9 @@ TenuredCellIsMarkedGray(const Cell* cell)
|
||||
uintptr_t* grayWord, grayMask;
|
||||
js::gc::detail::GetGCThingMarkWordAndMask(uintptr_t(cell), js::gc::ColorBit::GrayOrBlackBit,
|
||||
&grayWord, &grayMask);
|
||||
if (!(*grayWord & grayMask))
|
||||
if (!(*grayWord & grayMask)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uintptr_t* blackWord, blackMask;
|
||||
js::gc::detail::GetGCThingMarkWordAndMask(uintptr_t(cell), js::gc::ColorBit::BlackBit,
|
||||
@ -442,8 +446,9 @@ static MOZ_ALWAYS_INLINE bool
|
||||
CellIsMarkedGray(const Cell* cell)
|
||||
{
|
||||
MOZ_ASSERT(cell);
|
||||
if (js::gc::IsInsideNursery(cell))
|
||||
if (js::gc::IsInsideNursery(cell)) {
|
||||
return false;
|
||||
}
|
||||
return TenuredCellIsMarkedGray(cell);
|
||||
}
|
||||
|
||||
@ -481,8 +486,9 @@ NurseryCellHasStoreBuffer(const void* cell)
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
IsInsideNursery(const js::gc::Cell* cell)
|
||||
{
|
||||
if (!cell)
|
||||
if (!cell) {
|
||||
return false;
|
||||
}
|
||||
auto location = detail::GetCellLocation(cell);
|
||||
MOZ_ASSERT(location == ChunkLocation::Nursery || location == ChunkLocation::TenuredHeap);
|
||||
return location == ChunkLocation::Nursery;
|
||||
@ -492,21 +498,25 @@ MOZ_ALWAYS_INLINE bool
|
||||
IsCellPointerValid(const void* cell)
|
||||
{
|
||||
auto addr = uintptr_t(cell);
|
||||
if (addr < ChunkSize || addr % CellAlignBytes != 0)
|
||||
if (addr < ChunkSize || addr % CellAlignBytes != 0) {
|
||||
return false;
|
||||
}
|
||||
auto location = detail::GetCellLocation(cell);
|
||||
if (location == ChunkLocation::TenuredHeap)
|
||||
if (location == ChunkLocation::TenuredHeap) {
|
||||
return !!detail::GetGCThingZone(addr);
|
||||
if (location == ChunkLocation::Nursery)
|
||||
}
|
||||
if (location == ChunkLocation::Nursery) {
|
||||
return detail::NurseryCellHasStoreBuffer(cell);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
IsCellPointerValidOrNull(const void* cell)
|
||||
{
|
||||
if (!cell)
|
||||
if (!cell) {
|
||||
return true;
|
||||
}
|
||||
return IsCellPointerValid(cell);
|
||||
}
|
||||
|
||||
@ -528,8 +538,9 @@ GetNurseryStringZone(JSString* str);
|
||||
static MOZ_ALWAYS_INLINE Zone*
|
||||
GetStringZone(JSString* str)
|
||||
{
|
||||
if (!js::gc::IsInsideNursery(reinterpret_cast<js::gc::Cell*>(str)))
|
||||
if (!js::gc::IsInsideNursery(reinterpret_cast<js::gc::Cell*>(str))) {
|
||||
return js::gc::detail::GetGCThingZone(reinterpret_cast<uintptr_t>(str));
|
||||
}
|
||||
return GetNurseryStringZone(str);
|
||||
}
|
||||
|
||||
@ -539,8 +550,9 @@ GetObjectZone(JSObject* obj);
|
||||
static MOZ_ALWAYS_INLINE bool
|
||||
GCThingIsMarkedGray(GCCellPtr thing)
|
||||
{
|
||||
if (thing.mayBeOwnedByOtherRuntime())
|
||||
if (thing.mayBeOwnedByOtherRuntime()) {
|
||||
return false;
|
||||
}
|
||||
return js::gc::detail::CellIsMarkedGrayIfKnown(thing.asCell());
|
||||
}
|
||||
|
||||
@ -610,18 +622,21 @@ ExposeGCThingToActiveJS(JS::GCCellPtr thing)
|
||||
// GC things residing in the nursery cannot be gray: they have no mark bits.
|
||||
// All live objects in the nursery are moved to tenured at the beginning of
|
||||
// each GC slice, so the gray marker never sees nursery things.
|
||||
if (IsInsideNursery(thing.asCell()))
|
||||
if (IsInsideNursery(thing.asCell())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// There's nothing to do for permanent GC things that might be owned by
|
||||
// another runtime.
|
||||
if (thing.mayBeOwnedByOtherRuntime())
|
||||
if (thing.mayBeOwnedByOtherRuntime()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsIncrementalBarrierNeededOnTenuredGCThing(thing))
|
||||
if (IsIncrementalBarrierNeededOnTenuredGCThing(thing)) {
|
||||
JS::IncrementalReadBarrier(thing);
|
||||
else if (js::gc::detail::TenuredCellIsMarkedGray(thing.asCell()))
|
||||
} else if (js::gc::detail::TenuredCellIsMarkedGray(thing.asCell())) {
|
||||
JS::UnmarkGrayGCThingRecursively(thing);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!js::gc::detail::TenuredCellIsMarkedGray(thing.asCell()));
|
||||
}
|
||||
@ -637,12 +652,14 @@ EdgeNeedsSweepUnbarriered(JSObject** objp)
|
||||
// pointers should be updated separately or replaced with
|
||||
// JS::Heap<JSObject*> which handles this automatically.
|
||||
MOZ_ASSERT(!JS::RuntimeHeapIsMinorCollecting());
|
||||
if (IsInsideNursery(reinterpret_cast<Cell*>(*objp)))
|
||||
if (IsInsideNursery(reinterpret_cast<Cell*>(*objp))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto zone = JS::shadow::Zone::asShadowZone(detail::GetGCThingZone(uintptr_t(*objp)));
|
||||
if (!zone->isGCSweepingOrCompacting())
|
||||
if (!zone->isGCSweepingOrCompacting()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return EdgeNeedsSweepUnbarrieredSlow(objp);
|
||||
}
|
||||
|
@ -151,8 +151,9 @@ static MOZ_ALWAYS_INLINE JS::GCCellPtr
|
||||
JSID_TO_GCTHING(jsid id)
|
||||
{
|
||||
void* thing = (void*)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK);
|
||||
if (JSID_IS_STRING(id))
|
||||
if (JSID_IS_STRING(id)) {
|
||||
return JS::GCCellPtr(thing, JS::TraceKind::String);
|
||||
}
|
||||
MOZ_ASSERT(JSID_IS_SYMBOL(id));
|
||||
return JS::GCCellPtr(thing, JS::TraceKind::Symbol);
|
||||
}
|
||||
@ -196,8 +197,9 @@ struct GCPolicy<jsid>
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
IdIsNotGray(jsid id)
|
||||
{
|
||||
if (!JSID_IS_GCTHING(id))
|
||||
if (!JSID_IS_GCTHING(id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return CellIsNotGray(JSID_TO_GCTHING(id).asCell());
|
||||
}
|
||||
@ -211,16 +213,19 @@ template <>
|
||||
struct BarrierMethods<jsid>
|
||||
{
|
||||
static gc::Cell* asGCThingOrNull(jsid id) {
|
||||
if (JSID_IS_STRING(id))
|
||||
if (JSID_IS_STRING(id)) {
|
||||
return reinterpret_cast<gc::Cell*>(JSID_TO_STRING(id));
|
||||
if (JSID_IS_SYMBOL(id))
|
||||
}
|
||||
if (JSID_IS_SYMBOL(id)) {
|
||||
return reinterpret_cast<gc::Cell*>(JSID_TO_SYMBOL(id));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
static void postBarrier(jsid* idp, jsid prev, jsid next) {}
|
||||
static void exposeToJS(jsid id) {
|
||||
if (JSID_IS_GCTHING(id))
|
||||
if (JSID_IS_GCTHING(id)) {
|
||||
js::gc::ExposeGCThingToActiveJS(JSID_TO_GCTHING(id));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -231,10 +236,12 @@ auto
|
||||
DispatchTyped(F f, const jsid& id, Args&&... args)
|
||||
-> decltype(f(static_cast<JSString*>(nullptr), std::forward<Args>(args)...))
|
||||
{
|
||||
if (JSID_IS_STRING(id))
|
||||
if (JSID_IS_STRING(id)) {
|
||||
return f(JSID_TO_STRING(id), std::forward<Args>(args)...);
|
||||
if (JSID_IS_SYMBOL(id))
|
||||
}
|
||||
if (JSID_IS_SYMBOL(id)) {
|
||||
return f(JSID_TO_SYMBOL(id), std::forward<Args>(args)...);
|
||||
}
|
||||
MOZ_ASSERT(!JSID_IS_GCTHING(id));
|
||||
return F::defaultValue(id);
|
||||
}
|
||||
|
@ -569,8 +569,9 @@ struct RuntimeSizes
|
||||
notableScriptSources()
|
||||
{
|
||||
allScriptSources = js_new<ScriptSourcesHashMap>();
|
||||
if (!allScriptSources)
|
||||
if (!allScriptSources) {
|
||||
MOZ_CRASH("oom");
|
||||
}
|
||||
}
|
||||
|
||||
~RuntimeSizes() {
|
||||
|
@ -366,8 +366,9 @@ class ProfilingStack final
|
||||
uint32_t line, js::ProfilingStackFrame::Category category) {
|
||||
uint32_t oldStackPointer = stackPointer;
|
||||
|
||||
if (MOZ_LIKELY(capacity > oldStackPointer) || MOZ_LIKELY(ensureCapacitySlow()))
|
||||
if (MOZ_LIKELY(capacity > oldStackPointer) || MOZ_LIKELY(ensureCapacitySlow())) {
|
||||
frames[oldStackPointer].initLabelFrame(label, dynamicString, sp, line, category);
|
||||
}
|
||||
|
||||
// This must happen at the end! The compiler will not reorder this
|
||||
// update because stackPointer is Atomic<..., ReleaseAcquire>, so any
|
||||
@ -383,8 +384,9 @@ class ProfilingStack final
|
||||
void pushSpMarkerFrame(void* sp) {
|
||||
uint32_t oldStackPointer = stackPointer;
|
||||
|
||||
if (MOZ_LIKELY(capacity > oldStackPointer) || MOZ_LIKELY(ensureCapacitySlow()))
|
||||
if (MOZ_LIKELY(capacity > oldStackPointer) || MOZ_LIKELY(ensureCapacitySlow())) {
|
||||
frames[oldStackPointer].initSpMarkerFrame(sp);
|
||||
}
|
||||
|
||||
// This must happen at the end, see the comment in pushLabelFrame.
|
||||
stackPointer = oldStackPointer + 1;
|
||||
@ -394,8 +396,9 @@ class ProfilingStack final
|
||||
jsbytecode* pc) {
|
||||
uint32_t oldStackPointer = stackPointer;
|
||||
|
||||
if (MOZ_LIKELY(capacity > oldStackPointer) || MOZ_LIKELY(ensureCapacitySlow()))
|
||||
if (MOZ_LIKELY(capacity > oldStackPointer) || MOZ_LIKELY(ensureCapacitySlow())) {
|
||||
frames[oldStackPointer].initJsFrame(label, dynamicString, script, pc);
|
||||
}
|
||||
|
||||
// This must happen at the end, see the comment in pushLabelFrame.
|
||||
stackPointer = oldStackPointer + 1;
|
||||
|
@ -392,8 +392,9 @@ struct ProxyReservedSlots
|
||||
}
|
||||
|
||||
void init(size_t nreserved) {
|
||||
for (size_t i = 0; i < nreserved; i++)
|
||||
for (size_t i = 0; i < nreserved; i++) {
|
||||
slots[i] = JS::UndefinedValue();
|
||||
}
|
||||
}
|
||||
|
||||
ProxyReservedSlots(const ProxyReservedSlots&) = delete;
|
||||
@ -477,10 +478,11 @@ SetProxyReservedSlotUnchecked(JSObject* obj, size_t n, const Value& extra)
|
||||
Value* vp = &GetProxyDataLayout(obj)->reservedSlots->slots[n];
|
||||
|
||||
// Trigger a barrier before writing the slot.
|
||||
if (vp->isGCThing() || extra.isGCThing())
|
||||
if (vp->isGCThing() || extra.isGCThing()) {
|
||||
SetValueInProxy(vp, extra);
|
||||
else
|
||||
} else {
|
||||
*vp = extra;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
@ -531,10 +533,11 @@ SetProxyPrivate(JSObject* obj, const Value& value)
|
||||
Value* vp = &detail::GetProxyDataLayout(obj)->values()->privateSlot;
|
||||
|
||||
// Trigger a barrier before writing the slot.
|
||||
if (vp->isGCThing() || value.isGCThing())
|
||||
if (vp->isGCThing() || value.isGCThing()) {
|
||||
detail::SetValueInProxy(vp, value);
|
||||
else
|
||||
} else {
|
||||
*vp = value;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool
|
||||
@ -609,8 +612,9 @@ class JS_FRIEND_API(AutoEnterPolicy)
|
||||
// * The policy set rv to false, indicating that we should throw.
|
||||
// * The caller did not instruct us to ignore exceptions.
|
||||
// * The policy did not throw itself.
|
||||
if (!allow && !rv && mayThrow)
|
||||
if (!allow && !rv && mayThrow) {
|
||||
reportErrorIfExceptionIsNotPending(cx, id);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~AutoEnterPolicy() { recordLeave(); }
|
||||
|
@ -25,8 +25,9 @@ template <>
|
||||
struct GCPolicy<Realm*> : public NonGCPointerPolicy<Realm*>
|
||||
{
|
||||
static void trace(JSTracer* trc, Realm** vp, const char* name) {
|
||||
if (*vp)
|
||||
if (*vp) {
|
||||
::js::gc::TraceRealm(trc, *vp, name);
|
||||
}
|
||||
}
|
||||
static bool needsSweep(Realm** vp) {
|
||||
return *vp && ::js::gc::RealmNeedsSweep(*vp);
|
||||
|
@ -374,8 +374,9 @@ ObjectIsMarkedGray(const JS::Heap<JSObject*>& obj)
|
||||
inline bool
|
||||
CellIsNotGray(js::gc::Cell* maybeCell)
|
||||
{
|
||||
if (!maybeCell)
|
||||
if (!maybeCell) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return js::gc::detail::CellIsNotGray(maybeCell);
|
||||
}
|
||||
@ -438,8 +439,9 @@ class TenuredHeap : public js::HeapBase<T, TenuredHeap<T>>
|
||||
void setPtr(T newPtr) {
|
||||
MOZ_ASSERT((reinterpret_cast<uintptr_t>(newPtr) & flagsMask) == 0);
|
||||
MOZ_ASSERT(js::gc::IsCellPointerValidOrNull(newPtr));
|
||||
if (newPtr)
|
||||
if (newPtr) {
|
||||
AssertGCThingMustBeTenured(newPtr);
|
||||
}
|
||||
bits = (bits & flagsMask) | reinterpret_cast<uintptr_t>(newPtr);
|
||||
}
|
||||
|
||||
@ -653,18 +655,21 @@ struct BarrierMethods<T*>
|
||||
{
|
||||
static T* initial() { return nullptr; }
|
||||
static gc::Cell* asGCThingOrNull(T* v) {
|
||||
if (!v)
|
||||
if (!v) {
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(uintptr_t(v) > 32);
|
||||
return reinterpret_cast<gc::Cell*>(v);
|
||||
}
|
||||
static void postBarrier(T** vp, T* prev, T* next) {
|
||||
if (next)
|
||||
if (next) {
|
||||
JS::AssertGCThingIsNotNurseryAllocable(reinterpret_cast<js::gc::Cell*>(next));
|
||||
}
|
||||
}
|
||||
static void exposeToJS(T* t) {
|
||||
if (t)
|
||||
if (t) {
|
||||
js::gc::ExposeGCThingToActiveJS(JS::GCCellPtr(t));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -673,8 +678,9 @@ struct BarrierMethods<JSObject*>
|
||||
{
|
||||
static JSObject* initial() { return nullptr; }
|
||||
static gc::Cell* asGCThingOrNull(JSObject* v) {
|
||||
if (!v)
|
||||
if (!v) {
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(uintptr_t(v) > 32);
|
||||
return reinterpret_cast<gc::Cell*>(v);
|
||||
}
|
||||
@ -682,8 +688,9 @@ struct BarrierMethods<JSObject*>
|
||||
JS::HeapObjectPostBarrier(vp, prev, next);
|
||||
}
|
||||
static void exposeToJS(JSObject* obj) {
|
||||
if (obj)
|
||||
if (obj) {
|
||||
JS::ExposeObjectToActiveJS(obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -692,8 +699,9 @@ struct BarrierMethods<JSFunction*>
|
||||
{
|
||||
static JSFunction* initial() { return nullptr; }
|
||||
static gc::Cell* asGCThingOrNull(JSFunction* v) {
|
||||
if (!v)
|
||||
if (!v) {
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(uintptr_t(v) > 32);
|
||||
return reinterpret_cast<gc::Cell*>(v);
|
||||
}
|
||||
@ -703,8 +711,9 @@ struct BarrierMethods<JSFunction*>
|
||||
reinterpret_cast<JSObject*>(next));
|
||||
}
|
||||
static void exposeToJS(JSFunction* fun) {
|
||||
if (fun)
|
||||
if (fun) {
|
||||
JS::ExposeObjectToActiveJS(reinterpret_cast<JSObject*>(fun));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -713,8 +722,9 @@ struct BarrierMethods<JSString*>
|
||||
{
|
||||
static JSString* initial() { return nullptr; }
|
||||
static gc::Cell* asGCThingOrNull(JSString* v) {
|
||||
if (!v)
|
||||
if (!v) {
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(uintptr_t(v) > 32);
|
||||
return reinterpret_cast<gc::Cell*>(v);
|
||||
}
|
||||
@ -722,8 +732,9 @@ struct BarrierMethods<JSString*>
|
||||
JS::HeapStringPostBarrier(vp, prev, next);
|
||||
}
|
||||
static void exposeToJS(JSString* v) {
|
||||
if (v)
|
||||
if (v) {
|
||||
js::gc::ExposeGCThingToActiveJS(JS::GCCellPtr(v));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1069,8 +1080,9 @@ GetContextRealm(const JSContext* cx)
|
||||
inline JS::Compartment*
|
||||
GetContextCompartment(const JSContext* cx)
|
||||
{
|
||||
if (JS::Realm* realm = GetContextRealm(cx))
|
||||
if (JS::Realm* realm = GetContextRealm(cx)) {
|
||||
return GetCompartmentForRealm(realm);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,9 @@ class JS_PUBLIC_API(SliceBudget)
|
||||
}
|
||||
|
||||
bool isOverBudget() {
|
||||
if (counter > 0)
|
||||
if (counter > 0) {
|
||||
return false;
|
||||
}
|
||||
return checkOverBudget();
|
||||
}
|
||||
|
||||
|
@ -88,8 +88,9 @@ class SourceBufferHolder final
|
||||
}
|
||||
|
||||
~SourceBufferHolder() {
|
||||
if (ownsChars_)
|
||||
if (ownsChars_) {
|
||||
js_free(const_cast<char16_t*>(data_));
|
||||
}
|
||||
}
|
||||
|
||||
/** Access the underlying source buffer without affecting ownership. */
|
||||
|
@ -100,8 +100,9 @@ class MOZ_STACK_CLASS JS_FRIEND_API(AutoStableStringChars) final
|
||||
/* If we own the chars, transfer ownership to the caller. */
|
||||
bool maybeGiveOwnershipToCaller() {
|
||||
MOZ_ASSERT(state_ != Uninitialized);
|
||||
if (!ownChars_.isSome() || !ownChars_->extractRawBuffer())
|
||||
if (!ownChars_.isSome() || !ownChars_->extractRawBuffer()) {
|
||||
return false;
|
||||
}
|
||||
state_ = Uninitialized;
|
||||
ownChars_.reset();
|
||||
return true;
|
||||
|
@ -450,8 +450,9 @@ class MOZ_NON_MEMMOVABLE JS_PUBLIC_API(JSStructuredCloneData) {
|
||||
|
||||
void initScope(JS::StructuredCloneScope scope) {
|
||||
MOZ_ASSERT(Size() == 0, "initScope() of nonempty JSStructuredCloneData");
|
||||
if (scope_ != JS::StructuredCloneScope::Unassigned)
|
||||
if (scope_ != JS::StructuredCloneScope::Unassigned) {
|
||||
MOZ_ASSERT(scope_ == scope, "Cannot change scope after it has been initialized");
|
||||
}
|
||||
scope_ = scope;
|
||||
}
|
||||
|
||||
@ -516,8 +517,9 @@ class MOZ_NON_MEMMOVABLE JS_PUBLIC_API(JSStructuredCloneData) {
|
||||
bool ForEachDataChunk(FunctionToApply&& function) const {
|
||||
Iterator iter = bufList_.Iter();
|
||||
while (!iter.Done()) {
|
||||
if (!function(iter.Data(), iter.RemainingInSegment()))
|
||||
if (!function(iter.Data(), iter.RemainingInSegment())) {
|
||||
return false;
|
||||
}
|
||||
iter.Advance(bufList_, iter.RemainingInSegment());
|
||||
}
|
||||
return true;
|
||||
|
@ -385,8 +385,9 @@ inline void
|
||||
TraceEdge(JSTracer* trc, JS::Heap<T>* thingp, const char* name)
|
||||
{
|
||||
MOZ_ASSERT(thingp);
|
||||
if (*thingp)
|
||||
if (*thingp) {
|
||||
js::gc::TraceExternalEdge(trc, thingp->unsafeGet(), name);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -96,8 +96,9 @@ struct BreadthFirst {
|
||||
// add it to the |visited| set. Return false on OOM.
|
||||
bool addStartVisited(Node node) {
|
||||
typename NodeMap::AddPtr ptr = visited.lookupForAdd(node);
|
||||
if (!ptr && !visited.add(ptr, node, typename Handler::NodeData()))
|
||||
if (!ptr && !visited.add(ptr, node, typename Handler::NodeData())) {
|
||||
return false;
|
||||
}
|
||||
return addStart(node);
|
||||
}
|
||||
|
||||
@ -124,8 +125,9 @@ struct BreadthFirst {
|
||||
|
||||
// Get a range containing all origin's outgoing edges.
|
||||
auto range = origin.edges(cx, wantNames);
|
||||
if (!range)
|
||||
if (!range) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Traverse each edge.
|
||||
for (; !range->empty(); range->popFront()) {
|
||||
@ -138,18 +140,21 @@ struct BreadthFirst {
|
||||
if (first) {
|
||||
// This is the first time we've reached |edge.referent|.
|
||||
// Mark it as visited.
|
||||
if (!visited.add(a, edge.referent, typename Handler::NodeData()))
|
||||
if (!visited.add(a, edge.referent, typename Handler::NodeData())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(a);
|
||||
|
||||
// Report this edge to the visitor function.
|
||||
if (!handler(*this, origin, edge, &a->value(), first))
|
||||
if (!handler(*this, origin, edge, &a->value(), first)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stopRequested)
|
||||
if (stopRequested) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Arrange to traverse this edge's referent's outgoing edges
|
||||
// later --- unless |handler| asked us not to.
|
||||
@ -157,8 +162,9 @@ struct BreadthFirst {
|
||||
// Skip the enqueue; reset flag for future iterations.
|
||||
abandonRequested = false;
|
||||
} else if (first) {
|
||||
if (!pending.append(edge.referent))
|
||||
if (!pending.append(edge.referent)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +163,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
*/
|
||||
void skip(size_t n) {
|
||||
beginPtr += n;
|
||||
if (beginPtr > endPtr)
|
||||
if (beginPtr > endPtr) {
|
||||
beginPtr = endPtr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -236,13 +237,15 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
|
||||
JS::ubi::Vector<uint32_t> dominated;
|
||||
JS::ubi::Vector<uint32_t> indices;
|
||||
if (!dominated.growBy(length) || !indices.growBy(length))
|
||||
if (!dominated.growBy(length) || !indices.growBy(length)) {
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
|
||||
// 1
|
||||
memset(indices.begin(), 0, length * sizeof(uint32_t));
|
||||
for (uint32_t i = 0; i < length; i++)
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
indices[doms[i]]++;
|
||||
}
|
||||
|
||||
// 2
|
||||
uint32_t sumOfSizes = 0;
|
||||
@ -312,10 +315,11 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
|
||||
static uint32_t intersect(JS::ubi::Vector<uint32_t>& doms, uint32_t finger1, uint32_t finger2) {
|
||||
while (finger1 != finger2) {
|
||||
if (finger1 < finger2)
|
||||
if (finger1 < finger2) {
|
||||
finger1 = doms[finger1];
|
||||
else if (finger2 < finger1)
|
||||
} else if (finger2 < finger1) {
|
||||
finger2 = doms[finger2];
|
||||
}
|
||||
}
|
||||
return finger1;
|
||||
}
|
||||
@ -328,8 +332,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
uint32_t nodeCount = 0;
|
||||
auto onNode = [&](const Node& node) {
|
||||
nodeCount++;
|
||||
if (MOZ_UNLIKELY(nodeCount == UINT32_MAX))
|
||||
if (MOZ_UNLIKELY(nodeCount == UINT32_MAX)) {
|
||||
return false;
|
||||
}
|
||||
return postOrder.append(node);
|
||||
};
|
||||
|
||||
@ -359,10 +364,12 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
MOZ_ASSERT(map.empty());
|
||||
MOZ_ASSERT(postOrder.length() < UINT32_MAX);
|
||||
uint32_t length = postOrder.length();
|
||||
if (!map.reserve(length))
|
||||
if (!map.reserve(length)) {
|
||||
return false;
|
||||
for (uint32_t i = 0; i < length; i++)
|
||||
}
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
map.putNewInfallible(postOrder[i], i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -379,8 +386,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
uint32_t length = postOrder.length();
|
||||
|
||||
MOZ_ASSERT(predecessorVectors.length() == 0);
|
||||
if (!predecessorVectors.growBy(length))
|
||||
if (!predecessorVectors.growBy(length)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < length - 1; i++) {
|
||||
auto& node = postOrder[i];
|
||||
@ -393,8 +401,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
"did we even find it.");
|
||||
|
||||
auto& predecessors = ptr->value();
|
||||
if (!predecessorVectors[i].reserve(predecessors->count()))
|
||||
if (!predecessorVectors[i].reserve(predecessors->count())) {
|
||||
return false;
|
||||
}
|
||||
for (auto range = predecessors->all(); !range.empty(); range.popFront()) {
|
||||
auto ptr = nodeToPostOrderIndex.lookup(range.front());
|
||||
MOZ_ASSERT(ptr);
|
||||
@ -410,11 +419,13 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
static MOZ_MUST_USE bool initializeDominators(JS::ubi::Vector<uint32_t>& doms,
|
||||
uint32_t length) {
|
||||
MOZ_ASSERT(doms.length() == 0);
|
||||
if (!doms.growByUninitialized(length))
|
||||
if (!doms.growByUninitialized(length)) {
|
||||
return false;
|
||||
}
|
||||
doms[length - 1] = length - 1;
|
||||
for (uint32_t i = 0; i < length - 1; i++)
|
||||
for (uint32_t i = 0; i < length - 1; i++) {
|
||||
doms[i] = UNDEFINED;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -513,8 +524,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
Create(JSContext* cx, AutoCheckCannotGC& noGC, const Node& root) {
|
||||
JS::ubi::Vector<Node> postOrder;
|
||||
PredecessorSets predecessorSets;
|
||||
if (!doTraversal(cx, noGC, root, postOrder, predecessorSets))
|
||||
if (!doTraversal(cx, noGC, root, postOrder, predecessorSets)) {
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(postOrder.length() < UINT32_MAX);
|
||||
uint32_t length = postOrder.length();
|
||||
@ -527,8 +539,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
// convert our data structures to play along first.
|
||||
|
||||
NodeToIndexMap nodeToPostOrderIndex(postOrder.length());
|
||||
if (!mapNodesToTheirIndices(postOrder, nodeToPostOrderIndex))
|
||||
if (!mapNodesToTheirIndices(postOrder, nodeToPostOrderIndex)) {
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
|
||||
JS::ubi::Vector<JS::ubi::Vector<uint32_t>> predecessorVectors;
|
||||
if (!convertPredecessorSetsToVectors(root, postOrder, predecessorSets, nodeToPostOrderIndex,
|
||||
@ -536,8 +549,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
return mozilla::Nothing();
|
||||
|
||||
JS::ubi::Vector<uint32_t> doms;
|
||||
if (!initializeDominators(doms, length))
|
||||
if (!initializeDominators(doms, length)) {
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
|
||||
bool changed = true;
|
||||
while (changed) {
|
||||
@ -570,8 +584,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
|
||||
for ( ; !range.empty(); range.popFront()) {
|
||||
auto idx = range.front();
|
||||
if (doms[idx] != UNDEFINED)
|
||||
if (doms[idx] != UNDEFINED) {
|
||||
newIDomIdx = intersect(doms, newIDomIdx, idx);
|
||||
}
|
||||
}
|
||||
|
||||
// If the immediate dominator changed, we will have to do
|
||||
@ -585,8 +600,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
}
|
||||
|
||||
auto maybeDominatedSets = DominatedSets::Create(doms);
|
||||
if (maybeDominatedSets.isNothing())
|
||||
if (maybeDominatedSets.isNothing()) {
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
|
||||
return mozilla::Some(DominatorTree(std::move(postOrder),
|
||||
std::move(nodeToPostOrderIndex),
|
||||
@ -609,8 +625,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
Node getImmediateDominator(const Node& node) const {
|
||||
assertSanity();
|
||||
auto ptr = nodeToPostOrderIndex.lookup(node);
|
||||
if (!ptr)
|
||||
if (!ptr) {
|
||||
return Node();
|
||||
}
|
||||
|
||||
auto idx = ptr->value();
|
||||
MOZ_ASSERT(idx < postOrder.length());
|
||||
@ -636,8 +653,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
mozilla::Maybe<DominatedSetRange> getDominatedSet(const Node& node) {
|
||||
assertSanity();
|
||||
auto ptr = nodeToPostOrderIndex.lookup(node);
|
||||
if (!ptr)
|
||||
if (!ptr) {
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
|
||||
auto idx = ptr->value();
|
||||
MOZ_ASSERT(idx < postOrder.length());
|
||||
@ -658,8 +676,9 @@ class JS_PUBLIC_API(DominatorTree)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (retainedSizes.isNothing() && !computeRetainedSizes(mallocSizeOf))
|
||||
if (retainedSizes.isNothing() && !computeRetainedSizes(mallocSizeOf)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto idx = ptr->value();
|
||||
MOZ_ASSERT(idx < postOrder.length());
|
||||
|
@ -93,8 +93,9 @@ struct PostOrder {
|
||||
MOZ_MUST_USE bool fillEdgesFromRange(EdgeVector& edges, js::UniquePtr<EdgeRange>& range) {
|
||||
MOZ_ASSERT(range);
|
||||
for ( ; !range->empty(); range->popFront()) {
|
||||
if (!edges.append(std::move(range->front())))
|
||||
if (!edges.append(std::move(range->front()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -126,8 +127,9 @@ struct PostOrder {
|
||||
// Add `node` as a starting point for the traversal. You may add
|
||||
// as many starting points as you like. Returns false on OOM.
|
||||
MOZ_MUST_USE bool addStart(const Node& node) {
|
||||
if (!seen.put(node))
|
||||
if (!seen.put(node)) {
|
||||
return false;
|
||||
}
|
||||
return pushForTraversing(node);
|
||||
}
|
||||
|
||||
@ -152,8 +154,9 @@ struct PostOrder {
|
||||
auto& edges = stack.back().edges;
|
||||
|
||||
if (edges.empty()) {
|
||||
if (!onNode(origin))
|
||||
if (!onNode(origin)) {
|
||||
return false;
|
||||
}
|
||||
stack.popBack();
|
||||
continue;
|
||||
}
|
||||
@ -161,13 +164,15 @@ struct PostOrder {
|
||||
Edge edge = std::move(edges.back());
|
||||
edges.popBack();
|
||||
|
||||
if (!onEdge(origin, edge))
|
||||
if (!onEdge(origin, edge)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ptr = seen.lookupForAdd(edge.referent);
|
||||
// We've already seen this node, don't follow its edges.
|
||||
if (ptr)
|
||||
if (ptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mark the referent as seen and follow its edges.
|
||||
if (!seen.add(ptr, edge.referent) ||
|
||||
|
@ -116,11 +116,13 @@ struct JS_PUBLIC_API(ShortestPaths)
|
||||
MOZ_ASSERT(origin == shortestPaths.root_ || traversal.visited.has(origin));
|
||||
MOZ_ASSERT(totalPathsRecorded < totalMaxPathsToRecord);
|
||||
|
||||
if (first && !back->init(origin, edge))
|
||||
if (first && !back->init(origin, edge)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!shortestPaths.targets_.has(edge.referent))
|
||||
if (!shortestPaths.targets_.has(edge.referent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If `first` is true, then we moved the edge's name into `back` in
|
||||
// the above call to `init`. So clone that back edge to get the
|
||||
@ -131,14 +133,17 @@ struct JS_PUBLIC_API(ShortestPaths)
|
||||
|
||||
if (first) {
|
||||
BackEdgeVector paths;
|
||||
if (!paths.reserve(shortestPaths.maxNumPaths_))
|
||||
if (!paths.reserve(shortestPaths.maxNumPaths_)) {
|
||||
return false;
|
||||
}
|
||||
auto cloned = back->clone();
|
||||
if (!cloned)
|
||||
if (!cloned) {
|
||||
return false;
|
||||
}
|
||||
paths.infallibleAppend(std::move(cloned));
|
||||
if (!shortestPaths.paths_.putNew(edge.referent, std::move(paths)))
|
||||
if (!shortestPaths.paths_.putNew(edge.referent, std::move(paths))) {
|
||||
return false;
|
||||
}
|
||||
totalPathsRecorded++;
|
||||
} else {
|
||||
auto ptr = shortestPaths.paths_.lookup(edge.referent);
|
||||
@ -149,16 +154,18 @@ struct JS_PUBLIC_API(ShortestPaths)
|
||||
|
||||
if (ptr->value().length() < shortestPaths.maxNumPaths_) {
|
||||
auto thisBackEdge = js::MakeUnique<BackEdge>();
|
||||
if (!thisBackEdge || !thisBackEdge->init(origin, edge))
|
||||
if (!thisBackEdge || !thisBackEdge->init(origin, edge)) {
|
||||
return false;
|
||||
}
|
||||
ptr->value().infallibleAppend(std::move(thisBackEdge));
|
||||
totalPathsRecorded++;
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(totalPathsRecorded <= totalMaxPathsToRecord);
|
||||
if (totalPathsRecorded == totalMaxPathsToRecord)
|
||||
if (totalPathsRecorded == totalMaxPathsToRecord) {
|
||||
traversal.stop();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -247,8 +254,9 @@ struct JS_PUBLIC_API(ShortestPaths)
|
||||
Handler handler(paths);
|
||||
Traversal traversal(cx, handler, noGC);
|
||||
traversal.wantNames = true;
|
||||
if (!traversal.addStart(root) || !traversal.traverse())
|
||||
if (!traversal.addStart(root) || !traversal.traverse()) {
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
|
||||
// Take ownership of the back edges we created while traversing the
|
||||
// graph so that we can follow them from `paths_` and don't
|
||||
@ -284,8 +292,9 @@ struct JS_PUBLIC_API(ShortestPaths)
|
||||
auto ptr = paths_.lookup(target);
|
||||
|
||||
// We didn't find any paths to this target, so nothing to do here.
|
||||
if (!ptr)
|
||||
if (!ptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(ptr->value().length() <= maxNumPaths_);
|
||||
|
||||
@ -293,8 +302,9 @@ struct JS_PUBLIC_API(ShortestPaths)
|
||||
for (const auto& backEdge : ptr->value()) {
|
||||
path.clear();
|
||||
|
||||
if (!path.append(backEdge.get()))
|
||||
if (!path.append(backEdge.get())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Node here = backEdge->predecessor();
|
||||
MOZ_ASSERT(here);
|
||||
@ -302,16 +312,18 @@ struct JS_PUBLIC_API(ShortestPaths)
|
||||
while (here != root_) {
|
||||
auto p = backEdges_.lookup(here);
|
||||
MOZ_ASSERT(p);
|
||||
if (!path.append(&p->value()))
|
||||
if (!path.append(&p->value())) {
|
||||
return false;
|
||||
}
|
||||
here = p->value().predecessor();
|
||||
MOZ_ASSERT(here);
|
||||
}
|
||||
|
||||
path.reverse();
|
||||
|
||||
if (!func(path))
|
||||
if (!func(path)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -156,8 +156,9 @@ IsSimulatedOOMAllocation()
|
||||
inline bool
|
||||
ShouldFailWithOOM()
|
||||
{
|
||||
if (!IsThreadSimulatingOOM())
|
||||
if (!IsThreadSimulatingOOM()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
counter++;
|
||||
if (IsSimulatedOOMAllocation()) {
|
||||
@ -203,8 +204,9 @@ IsSimulatedStackOOMCheck()
|
||||
inline bool
|
||||
ShouldFailWithStackOOM()
|
||||
{
|
||||
if (!IsThreadSimulatingStackOOM())
|
||||
if (!IsThreadSimulatingStackOOM()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
stackCheckCounter++;
|
||||
if (IsSimulatedStackOOMCheck()) {
|
||||
@ -251,8 +253,9 @@ IsSimulatedInterruptCheck()
|
||||
inline bool
|
||||
ShouldFailWithInterrupt()
|
||||
{
|
||||
if (!IsThreadSimulatingInterrupt())
|
||||
if (!IsThreadSimulatingInterrupt()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
interruptCheckCounter++;
|
||||
if (IsSimulatedInterruptCheck()) {
|
||||
@ -579,8 +582,9 @@ static MOZ_ALWAYS_INLINE T*
|
||||
js_pod_arena_malloc(arena_id_t arena, size_t numElems)
|
||||
{
|
||||
size_t bytes;
|
||||
if (MOZ_UNLIKELY(!js::CalculateAllocSize<T>(numElems, &bytes)))
|
||||
if (MOZ_UNLIKELY(!js::CalculateAllocSize<T>(numElems, &bytes))) {
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<T*>(js_arena_malloc(arena, bytes));
|
||||
}
|
||||
|
||||
@ -596,8 +600,9 @@ static MOZ_ALWAYS_INLINE T*
|
||||
js_pod_arena_calloc(arena_id_t arena, size_t numElems)
|
||||
{
|
||||
size_t bytes;
|
||||
if (MOZ_UNLIKELY(!js::CalculateAllocSize<T>(numElems, &bytes)))
|
||||
if (MOZ_UNLIKELY(!js::CalculateAllocSize<T>(numElems, &bytes))) {
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<T*>(js_arena_calloc(arena, bytes, 1));
|
||||
}
|
||||
|
||||
@ -614,8 +619,9 @@ js_pod_realloc(T* prior, size_t oldSize, size_t newSize)
|
||||
{
|
||||
MOZ_ASSERT(!(oldSize & mozilla::tl::MulOverflowMask<sizeof(T)>::value));
|
||||
size_t bytes;
|
||||
if (MOZ_UNLIKELY(!js::CalculateAllocSize<T>(newSize, &bytes)))
|
||||
if (MOZ_UNLIKELY(!js::CalculateAllocSize<T>(newSize, &bytes))) {
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<T*>(js_realloc(prior, bytes));
|
||||
}
|
||||
|
||||
|
@ -265,8 +265,9 @@ GenericNaN()
|
||||
static inline double
|
||||
CanonicalizeNaN(double d)
|
||||
{
|
||||
if (MOZ_UNLIKELY(mozilla::IsNaN(d)))
|
||||
if (MOZ_UNLIKELY(mozilla::IsNaN(d))) {
|
||||
return GenericNaN();
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
@ -542,10 +543,11 @@ union MOZ_NON_PARAM alignas(8) Value
|
||||
}
|
||||
|
||||
void setObjectOrNull(JSObject* arg) {
|
||||
if (arg)
|
||||
if (arg) {
|
||||
setObject(*arg);
|
||||
else
|
||||
} else {
|
||||
setNull();
|
||||
}
|
||||
}
|
||||
|
||||
void swap(Value& rhs) {
|
||||
@ -706,11 +708,13 @@ union MOZ_NON_PARAM alignas(8) Value
|
||||
"Value type tags must correspond with JS::TraceKinds.");
|
||||
static_assert((JSVAL_TAG_OBJECT & 0x03) == size_t(JS::TraceKind::Object),
|
||||
"Value type tags must correspond with JS::TraceKinds.");
|
||||
if (MOZ_UNLIKELY(isPrivateGCThing()))
|
||||
if (MOZ_UNLIKELY(isPrivateGCThing())) {
|
||||
return JS::GCThingTraceKind(toGCThing());
|
||||
}
|
||||
#ifdef ENABLE_BIGINT
|
||||
if (MOZ_UNLIKELY(isBigInt()))
|
||||
if (MOZ_UNLIKELY(isBigInt())) {
|
||||
return JS::TraceKind::BigInt;
|
||||
}
|
||||
#endif
|
||||
return JS::TraceKind(toTag() & 0x03);
|
||||
}
|
||||
@ -948,8 +952,9 @@ ExposeValueToActiveJS(const Value& v)
|
||||
Value tmp = v;
|
||||
MOZ_ASSERT(!js::gc::EdgeNeedsSweepUnbarrieredSlow(&tmp));
|
||||
#endif
|
||||
if (v.isGCThing())
|
||||
if (v.isGCThing()) {
|
||||
js::gc::ExposeGCThingToActiveJS(GCCellPtr(v));
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
@ -993,8 +998,9 @@ CanonicalizedDoubleValue(double d)
|
||||
static inline bool
|
||||
IsCanonicalized(double d)
|
||||
{
|
||||
if (mozilla::IsInfinite(d) || mozilla::IsFinite(d))
|
||||
if (mozilla::IsInfinite(d) || mozilla::IsFinite(d)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t bits;
|
||||
mozilla::BitwiseCast<uint64_t>(d, &bits);
|
||||
@ -1155,10 +1161,11 @@ class MakeNumberValue
|
||||
static inline Value create(const T t)
|
||||
{
|
||||
Value v;
|
||||
if (JSVAL_INT_MIN <= t && t <= JSVAL_INT_MAX)
|
||||
if (JSVAL_INT_MIN <= t && t <= JSVAL_INT_MAX) {
|
||||
v.setInt32(int32_t(t));
|
||||
else
|
||||
} else {
|
||||
v.setDouble(double(t));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
@ -1171,10 +1178,11 @@ class MakeNumberValue<false>
|
||||
static inline Value create(const T t)
|
||||
{
|
||||
Value v;
|
||||
if (t <= JSVAL_INT_MAX)
|
||||
if (t <= JSVAL_INT_MAX) {
|
||||
v.setInt32(int32_t(t));
|
||||
else
|
||||
} else {
|
||||
v.setDouble(double(t));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
@ -1414,10 +1422,11 @@ class HeapBase<JS::Value, Wrapper> : public WrappedPtrOperations<JS::Value, Wrap
|
||||
}
|
||||
|
||||
void setObjectOrNull(JSObject* arg) {
|
||||
if (arg)
|
||||
if (arg) {
|
||||
setObject(*arg);
|
||||
else
|
||||
} else {
|
||||
setNull();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1480,8 +1489,9 @@ namespace JS {
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
ValueIsNotGray(const Value& value)
|
||||
{
|
||||
if (!value.isGCThing())
|
||||
if (!value.isGCThing()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return CellIsNotGray(value.toGCThing());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user