Bug 1041646. Don't assume mStack is non-null in JSStackFrame, since people sometimes operate on them after unlinking. r=khuey

This commit is contained in:
Boris Zbarsky 2014-07-26 01:41:18 -04:00
parent 5e6d105dec
commit 4bf1640106
4 changed files with 67 additions and 6 deletions

View File

@ -71,7 +71,8 @@ public:
void GetName(nsString& retval);
// The XPCOM GetFilename does the right thing.
// The XPCOM GetFilename does the right thing. It might throw, but we want to
// return an empty filename in that case anyway, instead of throwing.
uint32_t LineNumber() const;

View File

@ -359,7 +359,9 @@ NS_IMETHODIMP JSStackFrame::GetLanguageName(nsACString& aLanguageName)
/* readonly attribute AString filename; */
NS_IMETHODIMP JSStackFrame::GetFilename(nsAString& aFilename)
{
if (!mFilenameInitialized) {
// We can get called after unlink; in that case we can't do much
// about producing a useful value.
if (!mFilenameInitialized && mStack) {
ThreadsafeAutoJSContext cx;
JS::Rooted<JSObject*> stack(cx, mStack);
JS::ExposeObjectToActiveJS(mStack);
@ -395,7 +397,9 @@ NS_IMETHODIMP StackFrame::GetFilename(nsAString& aFilename)
/* readonly attribute AString name; */
NS_IMETHODIMP JSStackFrame::GetName(nsAString& aFunction)
{
if (!mFunnameInitialized) {
// We can get called after unlink; in that case we can't do much
// about producing a useful value.
if (!mFunnameInitialized && mStack) {
ThreadsafeAutoJSContext cx;
JS::Rooted<JSObject*> stack(cx, mStack);
JS::ExposeObjectToActiveJS(mStack);
@ -435,7 +439,9 @@ NS_IMETHODIMP StackFrame::GetName(nsAString& aFunction)
nsresult
JSStackFrame::GetLineno(int32_t* aLineNo)
{
if (!mLinenoInitialized) {
// We can get called after unlink; in that case we can't do much
// about producing a useful value.
if (!mLinenoInitialized && mStack) {
ThreadsafeAutoJSContext cx;
JS::Rooted<JSObject*> stack(cx, mStack);
JS::ExposeObjectToActiveJS(mStack);
@ -468,7 +474,9 @@ NS_IMETHODIMP StackFrame::GetSourceLine(nsACString& aSourceLine)
/* readonly attribute nsIStackFrame caller; */
NS_IMETHODIMP JSStackFrame::GetCaller(nsIStackFrame** aCaller)
{
if (!mCallerInitialized) {
// We can get called after unlink; in that case we can't do much
// about producing a useful value.
if (!mCallerInitialized && mStack) {
ThreadsafeAutoJSContext cx;
JS::Rooted<JSObject*> stack(cx, mStack);
JS::ExposeObjectToActiveJS(mStack);
@ -501,7 +509,9 @@ NS_IMETHODIMP StackFrame::GetCaller(nsIStackFrame** aCaller)
NS_IMETHODIMP JSStackFrame::GetFormattedStack(nsAString& aStack)
{
if (!mFormattedStackInitialized) {
// We can get called after unlink; in that case we can't do much
// about producing a useful value.
if (!mFormattedStackInitialized && mStack) {
ThreadsafeAutoJSContext cx;
JS::Rooted<JS::Value> stack(cx, JS::ObjectValue(*mStack));
JS::ExposeObjectToActiveJS(mStack);

View File

@ -21,6 +21,7 @@ support-files =
# where we have our test component. So this should become skip-if = debug == false.
[test_bug923904.html]
skip-if = true
[test_bug1041646.html]
[test_barewordGetsWindow.html]
[test_callback_default_thisval.html]
[test_cloneAndImportNode.html]

View File

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1041646
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1041646</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1041646 **/
// We need to reject the promise with a DOMException, so make sure we have
// something that produces one.
function throwException() {
document.createTextNode("").appendChild(document);
}
try {
throwException();
} catch (e) {
ok(e instanceof DOMException, "This test won't test what it should be testing");
}
SimpleTest.waitForExplicitFinish();
// We want a new DOMException each time here.
for (var i = 0; i < 100; ++i) {
new Promise(throwException);
}
// Now make sure we wait for all those promises above to reject themselves
Promise.resolve(1).then(function() {
SpecialPowers.gc(); // This should not assert or crash
SimpleTest.finish();
});
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1041646">Mozilla Bug 1041646</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>