Protect against null contexts. bug 340602, r+sr=roc

This commit is contained in:
mrbkap%gmail.com 2006-06-07 17:15:51 +00:00
parent efa80a10a5
commit 8f01b34f73
2 changed files with 12 additions and 3 deletions

View File

@ -2234,19 +2234,23 @@ IsContextOnStack(nsIJSContextStack *aStack, JSContext *aContext)
return PR_FALSE;
if (ctx == aContext)
return PR_TRUE;
nsCOMPtr<nsIJSContextStackIterator>
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;
}

View File

@ -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;
}