Bug 1438121: Final Part 1: Change JS::CopyAsyncStack's maxFrameCount to be a Maybe, and use that type throughout. r=tromey

I botched another patch in this series because I was confused about when zero
meant "no limit" and when it actually just meant zero, so I figured I'd fix this.

MozReview-Commit-ID: 5vgzKGSKL8F

--HG--
extra : rebase_source : dc57c22b08455a1867eeaa139b3045d2ae181cef
extra : histedit_source : e82898f74e8568bbbd10f7589427f5fbbcfe24fa
This commit is contained in:
Jim Blandy 2018-03-06 21:52:31 -08:00
Родитель ee0860e862
Коммит 9120910ea9
5 изменённых файлов: 17 добавлений и 13 удалений

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

@ -8,6 +8,9 @@
#define mozilla_JavascriptTimelineMarker_h_
#include "TimelineMarker.h"
#include "mozilla/Maybe.h"
#include "mozilla/dom/ProfileTimelineMarkerBinding.h"
#include "mozilla/dom/RootedDictionary.h"
#include "mozilla/dom/ToJSValue.h"
@ -63,7 +66,7 @@ public:
}
if (JS::IsSavedFrame(asyncStack) &&
!JS::CopyAsyncStack(aCx, asyncStack, asyncCause, &parentFrame, 0)) {
!JS::CopyAsyncStack(aCx, asyncStack, asyncCause, &parentFrame, mozilla::Nothing())) {
JS_ClearPendingException(aCx);
} else {
stackFrame.mAsyncParent = parentFrame;

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

@ -7761,7 +7761,7 @@ JS::CaptureCurrentStack(JSContext* cx, JS::MutableHandleObject stackp,
JS_PUBLIC_API(bool)
JS::CopyAsyncStack(JSContext* cx, JS::HandleObject asyncStack,
JS::HandleString asyncCause, JS::MutableHandleObject stackp,
unsigned maxFrameCount)
const Maybe<size_t>& maxFrameCount)
{
AssertHeapIsIdle();
CHECK_REQUEST(cx);

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

@ -6507,14 +6507,14 @@ CaptureCurrentStack(JSContext* cx, MutableHandleObject stackp,
* Here |asyncStack| is the async stack to prepare. It is copied into
* |cx|'s current compartment, and the newest frame is given
* |asyncCause| as its asynchronous cause. If |maxFrameCount| is
* non-zero, capture at most the youngest |maxFrameCount| frames. The
* |Some(n)|, capture at most the youngest |n| frames. The
* new stack object is written to |stackp|. Returns true on success,
* or sets an exception and returns |false| on error.
*/
extern JS_PUBLIC_API(bool)
CopyAsyncStack(JSContext* cx, HandleObject asyncStack,
HandleString asyncCause, MutableHandleObject stackp,
unsigned maxFrameCount);
const mozilla::Maybe<size_t>& maxFrameCount);
/*
* Accessors for working with SavedFrame JSObjects

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

@ -1190,7 +1190,8 @@ SavedStacks::saveCurrentStack(JSContext* cx, MutableHandleSavedFrame frame,
bool
SavedStacks::copyAsyncStack(JSContext* cx, HandleObject asyncStack, HandleString asyncCause,
MutableHandleSavedFrame adoptedStack, uint32_t maxFrameCount)
MutableHandleSavedFrame adoptedStack,
const Maybe<size_t>& maxFrameCount)
{
MOZ_ASSERT(initialized());
MOZ_RELEASE_ASSERT(cx->compartment());
@ -1411,10 +1412,10 @@ SavedStacks::insertFrames(JSContext* cx, FrameIter& iter, MutableHandleSavedFram
// rest of the synchronous stack chain.
RootedSavedFrame parentFrame(cx, cachedFrame);
if (asyncStack && !capture.is<JS::FirstSubsumedFrame>()) {
uint32_t maxAsyncFrames = capture.is<JS::MaxFrames>()
size_t maxAsyncFrames = capture.is<JS::MaxFrames>()
? capture.as<JS::MaxFrames>().maxFrames
: ASYNC_STACK_MAX_FRAME_COUNT;
if (!adoptAsyncStack(cx, asyncStack, asyncCause, &parentFrame, maxAsyncFrames))
if (!adoptAsyncStack(cx, asyncStack, asyncCause, &parentFrame, Some(maxAsyncFrames)))
return false;
}
@ -1442,17 +1443,17 @@ bool
SavedStacks::adoptAsyncStack(JSContext* cx, HandleSavedFrame asyncStack,
HandleString asyncCause,
MutableHandleSavedFrame adoptedStack,
uint32_t maxFrameCount)
const Maybe<size_t>& maxFrameCount)
{
RootedAtom asyncCauseAtom(cx, AtomizeString(cx, asyncCause));
if (!asyncCauseAtom)
return false;
// If maxFrameCount is zero, the caller asked for an unlimited number of
// If maxFrameCount is Nothing, the caller asked for an unlimited number of
// stack frames, but async stacks are not limited by the available stack
// memory, so we need to set an arbitrary limit when collecting them. We
// still don't enforce an upper limit if the caller requested more frames.
uint32_t maxFrames = maxFrameCount > 0 ? maxFrameCount : ASYNC_STACK_MAX_FRAME_COUNT;
size_t maxFrames = maxFrameCount.valueOr(ASYNC_STACK_MAX_FRAME_COUNT);
// Accumulate the vector of Lookup objects in |stackChain|.
SavedFrame::AutoLookupVector stackChain(cx);
@ -1485,7 +1486,7 @@ SavedStacks::adoptAsyncStack(JSContext* cx, HandleSavedFrame asyncStack,
// existing chain and change the asyncCause on the younger frame.
oldestFramePosition = 1;
parentFrame = firstSavedFrameParent;
} else if (maxFrameCount == 0 &&
} else if (maxFrameCount.isNothing() &&
oldestFramePosition == ASYNC_STACK_MAX_FRAME_COUNT) {
// If we captured the maximum number of frames and the caller requested
// no specific limit, we only return half of them. This means that for

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

@ -170,7 +170,7 @@ class SavedStacks {
MOZ_MUST_USE bool copyAsyncStack(JSContext* cx, HandleObject asyncStack,
HandleString asyncCause,
MutableHandleSavedFrame adoptedStack,
uint32_t maxFrameCount = 0);
const Maybe<size_t>& maxFrameCount);
void sweep();
void trace(JSTracer* trc);
uint32_t count();
@ -226,7 +226,7 @@ class SavedStacks {
MOZ_MUST_USE bool adoptAsyncStack(JSContext* cx, HandleSavedFrame asyncStack,
HandleString asyncCause,
MutableHandleSavedFrame adoptedStack,
uint32_t maxFrameCount);
const Maybe<size_t>& maxFrameCount);
SavedFrame* getOrCreateSavedFrame(JSContext* cx, SavedFrame::HandleLookup lookup);
SavedFrame* createFrameFromLookup(JSContext* cx, SavedFrame::HandleLookup lookup);