Bug 1401827 - Baldr: make Fifo::pop infallible (r=lth)

MozReview-Commit-ID: Sc3Vuo97yZ

--HG--
extra : rebase_source : b32f9b2f148e0189026151d7355487f6adb9586e
This commit is contained in:
Luke Wagner 2017-09-27 09:31:59 -05:00
Родитель 9b266759c8
Коммит 6ffaf6b9b2
5 изменённых файлов: 14 добавлений и 48 удалений

Просмотреть файл

@ -46,19 +46,11 @@ class Fifo
private:
// Maintain invariants after adding or removing entries.
bool fixup() {
if (!front_.empty())
return true;
if (!front_.reserve(rear_.length()))
return false;
while (!rear_.empty()) {
front_.infallibleAppend(mozilla::Move(rear_.back()));
rear_.popBack();
void fixup() {
if (front_.empty() && !rear_.empty()) {
front_.swap(rear_);
Reverse(front_.begin(), front_.end());
}
return true;
}
public:
@ -98,10 +90,7 @@ class Fifo
MOZ_MUST_USE bool pushBack(U&& u) {
if (!rear_.append(mozilla::Forward<U>(u)))
return false;
if (!fixup()) {
rear_.popBack();
return false;
}
fixup();
return true;
}
@ -110,10 +99,7 @@ class Fifo
MOZ_MUST_USE bool emplaceBack(Args&&... args) {
if (!rear_.emplaceBack(mozilla::Forward<Args>(args)...))
return false;
if (!fixup()) {
rear_.popBack();
return false;
}
fixup();
return true;
}
@ -128,20 +114,10 @@ class Fifo
}
// Remove the front element from the queue.
MOZ_MUST_USE bool popFront() {
void popFront() {
MOZ_ASSERT(!empty());
T t(mozilla::Move(front()));
front_.popBack();
if (!fixup()) {
// Attempt to remain in a valid state by reinserting the element
// back at the front. If we can't remain in a valid state in the
// face of OOMs, crash.
AutoEnterOOMUnsafeRegion oomUnsafe;
if (!front_.append(mozilla::Move(t)))
oomUnsafe.crash("js::Fifo::popFront");
return false;
}
return true;
fixup();
}
// Clear all elements from the queue.

Просмотреть файл

@ -79,7 +79,7 @@ class MutableWrappedPtrOperations<TraceableFifo<T, Capacity, AllocPolicy>, Wrapp
return fifo().emplaceBack(mozilla::Forward<Args...>(args...));
}
bool popFront() { return fifo().popFront(); }
void popFront() { fifo().popFront(); }
void clear() { fifo().clear(); }
};

Просмотреть файл

@ -323,7 +323,7 @@ BEGIN_TEST(testTraceableFifo)
bool match;
CHECK(JS_StringEqualsAscii(cx, JSID_TO_STRING(shapes.front()->propid()), buffer, &match));
CHECK(match);
CHECK(shapes.popFront());
shapes.popFront();
}
CHECK(shapes.empty());

Просмотреть файл

@ -2298,10 +2298,7 @@ Debugger::appendAllocationSite(JSContext* cx, HandleObject obj, HandleSavedFrame
}
if (allocationsLog.length() > maxAllocationsLogLength) {
if (!allocationsLog.popFront()) {
ReportOutOfMemory(cx);
return false;
}
allocationsLog.popFront();
MOZ_ASSERT(allocationsLog.length() == maxAllocationsLogLength);
allocationsLogOverflowed = true;
}

Просмотреть файл

@ -238,10 +238,7 @@ DebuggerMemory::drainAllocationsLog(JSContext* cx, unsigned argc, Value* vp)
// Pop the front queue entry, and delete it immediately, so that the GC
// sees the AllocationsLogEntry's HeapPtr barriers run atomically with
// the change to the graph (the queue link).
if (!dbg->allocationsLog.popFront()) {
ReportOutOfMemory(cx);
return false;
}
dbg->allocationsLog.popFront();
}
dbg->allocationsLogOverflowed = false;
@ -278,12 +275,8 @@ DebuggerMemory::setMaxAllocationsLogLength(JSContext* cx, unsigned argc, Value*
Debugger* dbg = memory->getDebugger();
dbg->maxAllocationsLogLength = max;
while (dbg->allocationsLog.length() > dbg->maxAllocationsLogLength) {
if (!dbg->allocationsLog.popFront()) {
ReportOutOfMemory(cx);
return false;
}
}
while (dbg->allocationsLog.length() > dbg->maxAllocationsLogLength)
dbg->allocationsLog.popFront();
args.rval().setUndefined();
return true;