diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 93c2727b6679..cb20e780c6be 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -2234,19 +2234,23 @@ IsContextOnStack(nsIJSContextStack *aStack, JSContext *aContext) return PR_FALSE; if (ctx == aContext) return PR_TRUE; - + nsCOMPtr iterator(do_CreateInstance("@mozilla.org/js/xpc/ContextStackIterator;1")); NS_ENSURE_TRUE(iterator, PR_FALSE); nsresult rv = iterator->Reset(aStack); NS_ENSURE_SUCCESS(rv, PR_FALSE); - + PRBool done; while (NS_SUCCEEDED(iterator->Done(&done)) && !done) { rv = iterator->Prev(&ctx); NS_ASSERTION(NS_SUCCEEDED(rv), "Broken iterator implementation"); + if (!ctx) { + continue; + } + if (nsJSUtils::GetDynamicScriptContext(ctx) && ctx == aContext) return PR_TRUE; } diff --git a/dom/src/base/nsLocation.cpp b/dom/src/base/nsLocation.cpp index 99933f9b39b1..edfd3739c09d 100644 --- a/dom/src/base/nsLocation.cpp +++ b/dom/src/base/nsLocation.cpp @@ -82,12 +82,17 @@ GetContextFromStack(nsIJSContextStack *aStack, JSContext **aContext) nsresult rv = iterator->Reset(aStack); NS_ENSURE_SUCCESS(rv, rv); - + PRBool done; while (NS_SUCCEEDED(iterator->Done(&done)) && !done) { rv = iterator->Prev(aContext); NS_ASSERTION(NS_SUCCEEDED(rv), "Broken iterator implementation"); + // Consider a null context the end of the line. + if (!*aContext) { + break; + } + if (nsJSUtils::GetDynamicScriptContext(*aContext)) { return NS_OK; }