Bug 1257919 part 10. Make the caller and formattedStack getters on JSStackFrame take an explicit JSContext. r=khuey

This commit is contained in:
Boris Zbarsky 2016-03-22 13:50:35 -04:00
parent dde5cae5bb
commit bc347a401b
8 changed files with 22 additions and 22 deletions

View File

@ -1080,7 +1080,7 @@ ReifyStack(JSContext* aCx, nsIStackFrame* aStack,
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStackFrame> caller;
rv = stack->GetCaller(getter_AddRefs(caller));
rv = stack->GetCaller(aCx, getter_AddRefs(caller));
NS_ENSURE_SUCCESS(rv, rv);
if (!caller) {

View File

@ -508,10 +508,10 @@ Exception::GetData() const
}
void
Exception::GetStack(nsAString& aStack, ErrorResult& aRv) const
Exception::GetStack(JSContext* aCx, nsAString& aStack, ErrorResult& aRv) const
{
if (mLocation) {
aRv = mLocation->GetFormattedStack(aStack);
aRv = mLocation->GetFormattedStack(aCx, aStack);
}
}

View File

@ -86,7 +86,7 @@ public:
already_AddRefed<nsISupports> GetData() const;
void GetStack(nsAString& aStack, ErrorResult& aRv) const;
void GetStack(JSContext* aCx, nsAString& aStack, ErrorResult& aRv) const;
void Stringify(JSContext* aCx, nsString& retval);

View File

@ -249,7 +249,7 @@ class BlobURLsReporter final : public nsIMemoryReporter
}
nsCOMPtr<nsIStackFrame> caller;
nsresult rv = frame->GetCaller(getter_AddRefs(caller));
nsresult rv = frame->GetCaller(cx, getter_AddRefs(caller));
NS_ENSURE_SUCCESS_VOID(rv);
caller.swap(frame);
}

View File

@ -409,7 +409,7 @@ DOMInterfaces = {
'binaryNames': {
'message': 'messageMoz',
},
'implicitJSContext': [ 'filename', 'lineNumber' ],
'implicitJSContext': [ 'filename', 'lineNumber', 'stack' ],
},
'DOMMatrixReadOnly': {
@ -479,7 +479,7 @@ DOMInterfaces = {
'binaryNames': {
'message': 'messageMoz',
},
'implicitJSContext': [ '__stringifier', 'filename', 'lineNumber' ],
'implicitJSContext': [ '__stringifier', 'filename', 'lineNumber', 'stack' ],
},
'ExtendableEvent': {

View File

@ -544,17 +544,16 @@ NS_IMETHODIMP JSStackFrame::GetAsyncCaller(JSContext* aCx,
return NS_OK;
}
NS_IMETHODIMP JSStackFrame::GetCaller(nsIStackFrame** aCaller)
NS_IMETHODIMP JSStackFrame::GetCaller(JSContext* aCx, nsIStackFrame** aCaller)
{
if (!mStack) {
*aCaller = nullptr;
return NS_OK;
}
ThreadsafeAutoJSContext cx;
JS::Rooted<JSObject*> callerObj(cx);
JS::Rooted<JSObject*> callerObj(aCx);
bool canCache = false, useCachedValue = false;
GetValueIfNotCached(cx, mStack, JS::GetSavedFrameParent, mCallerInitialized,
GetValueIfNotCached(aCx, mStack, JS::GetSavedFrameParent, mCallerInitialized,
&canCache, &useCachedValue, &callerObj);
if (useCachedValue) {
@ -574,7 +573,7 @@ NS_IMETHODIMP JSStackFrame::GetCaller(nsIStackFrame** aCaller)
return NS_OK;
}
NS_IMETHODIMP JSStackFrame::GetFormattedStack(nsAString& aStack)
NS_IMETHODIMP JSStackFrame::GetFormattedStack(JSContext* aCx, nsAString& aStack)
{
if (!mStack) {
aStack.Truncate();
@ -585,30 +584,29 @@ NS_IMETHODIMP JSStackFrame::GetFormattedStack(nsAString& aStack)
// returns bool, not JS::SavedFrameResult. Maybe it's possible to
// make the templates more complicated to deal, but in the meantime
// let's just inline GetValueIfNotCached here.
ThreadsafeAutoJSContext cx;
// Allow caching if cx and stack are same-compartment. Otherwise take the
// Allow caching if aCx and stack are same-compartment. Otherwise take the
// slow path.
bool canCache =
js::GetContextCompartment(cx) == js::GetObjectCompartment(mStack);
js::GetContextCompartment(aCx) == js::GetObjectCompartment(mStack);
if (canCache && mFormattedStackInitialized) {
aStack = mFormattedStack;
return NS_OK;
}
JS::ExposeObjectToActiveJS(mStack);
JS::Rooted<JSObject*> stack(cx, mStack);
JS::Rooted<JSObject*> stack(aCx, mStack);
JS::Rooted<JSString*> formattedStack(cx);
if (!JS::BuildStackString(cx, stack, &formattedStack)) {
JS_ClearPendingException(cx);
JS::Rooted<JSString*> formattedStack(aCx);
if (!JS::BuildStackString(aCx, stack, &formattedStack)) {
JS_ClearPendingException(aCx);
aStack.Truncate();
return NS_OK;
}
nsAutoJSString str;
if (!str.init(cx, formattedStack)) {
JS_ClearPendingException(cx);
if (!str.init(aCx, formattedStack)) {
JS_ClearPendingException(aCx);
aStack.Truncate();
return NS_OK;
}

View File

@ -71,7 +71,7 @@ SandboxLogJSStack(void)
}
nsCOMPtr<nsIStackFrame> nextFrame;
nsresult rv = frame->GetCaller(getter_AddRefs(nextFrame));
nsresult rv = frame->GetCaller(cx, getter_AddRefs(nextFrame));
NS_ENSURE_SUCCESS_VOID(rv);
frame = nextFrame;
}

View File

@ -30,11 +30,13 @@ interface nsIStackFrame : nsISupports
readonly attribute AString asyncCause;
[implicit_jscontext]
readonly attribute nsIStackFrame asyncCaller;
[implicit_jscontext]
readonly attribute nsIStackFrame caller;
// Returns a formatted stack string that looks like the sort of
// string that would be returned by .stack on JS Error objects.
// Only works on JS-language stack frames.
[implicit_jscontext]
readonly attribute AString formattedStack;
// Returns the underlying SavedFrame object for native JavaScript stacks,