Bug 430276, new XMLHttpRequest() after document.write throws an exception, r+sr=jst, a=beltzner

This commit is contained in:
Olli.Pettay@helsinki.fi 2008-04-25 02:45:58 -07:00
Родитель 8e466b347b
Коммит 9f4571d377
4 изменённых файлов: 71 добавлений и 6 удалений

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

@ -4999,14 +4999,19 @@ nsDOMConstructor::Create(const PRUnichar* aName,
nsDOMConstructor** aResult)
{
*aResult = nsnull;
if (!aOwner->IsOuterWindow()) {
*aResult = new nsDOMConstructor(aName, aNameStruct, aOwner);
} else if (!nsContentUtils::CanCallerAccess(aOwner)) {
// Prevent creating a constructor if
// - aOwner is inner window which doesn't have outer window or
// - outer window doesn't have inner window or
// - caller can't access outer window's inner window.
nsPIDOMWindow* outerWindow = aOwner->GetOuterWindow();
nsPIDOMWindow* currentInner =
outerWindow ? outerWindow->GetCurrentInnerWindow() : nsnull;
if (!currentInner ||
(aOwner != currentInner &&
!nsContentUtils::CanCallerAccess(currentInner))) {
return NS_ERROR_DOM_SECURITY_ERR;
} else {
*aResult =
new nsDOMConstructor(aName, aNameStruct, aOwner->GetCurrentInnerWindow());
}
*aResult = new nsDOMConstructor(aName, aNameStruct, currentInner);
NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(*aResult);
return NS_OK;

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

@ -74,6 +74,8 @@ _TEST_FILES = \
iframe_bug409349.html \
test_bug411103.html \
test_bug414291.html \
test_bug430276.html \
iframe_bug430276.html \
$(NULL)
libs:: $(_TEST_FILES)

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

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="application/javascript">
function runTest() {
document.write("<body>");
var succeeded = true;
try {
new XMLHttpRequest();
} catch(e) {
succeeded = false;
}
window.parent.ok(succeeded, "Creating XMLHttpRequest failed!");
window.parent.SimpleTest.finish();
}
</script>
</head>
<body onload="runTest()">
</body>
</html>

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

@ -0,0 +1,37 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=430276
-->
<head>
<title>Test for Bug 430276</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=430276">Mozilla Bug 430276</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 430276 **/
function startTest() {
document.getElementById("testFrame")
.setAttribute("src", "iframe_bug430276.html");
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(startTest);
</script>
</pre>
<iframe id="testFrame">
</body>
</html>