mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 529328 - Return undefined for out-of-bounds access through nsStringArraySH; r=smaug
This patch has no effect on CSSStyleDeclaration, as that never returns a void DOMString.
This commit is contained in:
parent
b82a4df32f
commit
999f948236
@ -165,22 +165,17 @@ function testClassList(e) {
|
||||
|
||||
// item() method
|
||||
|
||||
// TODO out of bounds array indexing should return undefined according to the
|
||||
// WebIDL spec. They are returning an empty string at the moment. (bug 529328)
|
||||
var OOB_VALUE = "";
|
||||
todo_is(OOB_VALUE, undefined, "Wrong out of bounds value");
|
||||
|
||||
e.setAttribute("class", "a");
|
||||
is(e.classList.item(-1), null, "wrong classList.item() result");
|
||||
is(e.classList[-1], OOB_VALUE, "wrong classList[] result");
|
||||
is(e.classList[-1], undefined, "wrong classList[] result");
|
||||
is(e.classList.item(0), "a", "wrong classList.item() result");
|
||||
is(e.classList[0], "a", "wrong classList.item() result");
|
||||
is(e.classList[0], "a", "wrong classList[] result");
|
||||
is(e.classList.item(1), null, "wrong classList.item() result");
|
||||
is(e.classList[1], OOB_VALUE, "wrong classList.item() result");
|
||||
is(e.classList[1], undefined, "wrong classList[] result");
|
||||
|
||||
e.setAttribute("class", "aa AA aa");
|
||||
is(e.classList.item(-1), null, "wrong classList.item() result");
|
||||
is(e.classList[-1], OOB_VALUE, "wrong classList[] result");
|
||||
is(e.classList[-1], undefined, "wrong classList[] result");
|
||||
is(e.classList.item(0), "aa", "wrong classList.item() result");
|
||||
is(e.classList[0], "aa", "wrong classList[] result");
|
||||
is(e.classList.item(1), "AA", "wrong classList.item() result");
|
||||
@ -188,22 +183,21 @@ function testClassList(e) {
|
||||
is(e.classList.item(2), "aa", "wrong classList.item() result");
|
||||
is(e.classList[2], "aa", "wrong classList[] result");
|
||||
is(e.classList.item(3), null, "wrong classList.item() result");
|
||||
is(e.classList[3], OOB_VALUE, "wrong classList[] result");
|
||||
is(e.classList[3], undefined, "wrong classList[] result");
|
||||
is(e.classList.item(0xffffffff), null, "wrong classList.item() result");
|
||||
// XXX returns undefined for index >= 0xffffffff
|
||||
todo_is(e.classList[0xffffffff], OOB_VALUE, "wrong classList[] result");
|
||||
is(e.classList[0xffffffff], undefined, "wrong classList[] result");
|
||||
is(e.classList.item(0xfffffffe), null, "wrong classList.item() result");
|
||||
is(e.classList[0xffffffe], OOB_VALUE, "wrong classList[] result");
|
||||
is(e.classList[0xffffffe], undefined, "wrong classList[] result");
|
||||
|
||||
e.setAttribute("class", "a b");
|
||||
is(e.classList.item(-1), null, "wrong classList.item() result");
|
||||
is(e.classList[-1], OOB_VALUE, "wrong classList[] result");
|
||||
is(e.classList[-1], undefined, "wrong classList[] result");
|
||||
is(e.classList.item(0), "a", "wrong classList.item() result");
|
||||
is(e.classList[0], "a", "wrong classList[] result");
|
||||
is(e.classList.item(1), "b", "wrong classList.item() result");
|
||||
is(e.classList[1], "b", "wrong classList[] result");
|
||||
is(e.classList.item(2), null, "wrong classList.item() result");
|
||||
is(e.classList[2], OOB_VALUE, "wrong classList[] result");
|
||||
is(e.classList[2], undefined, "wrong classList[] result");
|
||||
|
||||
// contains() method
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Johnny Stenback <jst@netscape.com> (original author)
|
||||
* Ms2ger <ms2ger@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
@ -8320,7 +8321,15 @@ nsStringListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
|
||||
nsCOMPtr<nsIDOMDOMStringList> list(do_QueryInterface(aNative));
|
||||
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
|
||||
|
||||
return list->Item(aIndex, aResult);
|
||||
nsresult rv = list->Item(aIndex, aResult);
|
||||
#ifdef DEBUG
|
||||
if (DOMStringIsNull(aResult)) {
|
||||
PRUint32 length = 0;
|
||||
list->GetLength(&length);
|
||||
NS_ASSERTION(PRUint32(aIndex) >= length, "Item should only return null for out-of-bounds access");
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -8333,7 +8342,15 @@ nsDOMTokenListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
|
||||
nsCOMPtr<nsIDOMDOMTokenList> list(do_QueryInterface(aNative));
|
||||
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
|
||||
|
||||
return list->Item(aIndex, aResult);
|
||||
nsresult rv = list->Item(aIndex, aResult);
|
||||
#ifdef DEBUG
|
||||
if (DOMStringIsNull(aResult)) {
|
||||
PRUint32 length = 0;
|
||||
list->GetLength(&length);
|
||||
NS_ASSERTION(PRUint32(aIndex) >= length, "Item should only return null for out-of-bounds access");
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -10382,14 +10399,16 @@ nsStringArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
nsresult rv = GetStringAt(GetNative(wrapper, obj), n, val);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// XXX: Null strings?
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
nsStringBuffer* sharedBuffer = nsnull;
|
||||
*vp = XPCStringConvert::ReadableToJSVal(cx, val, &sharedBuffer);
|
||||
if (sharedBuffer) {
|
||||
val.ForgetSharedBuffer();
|
||||
if (DOMStringIsNull(val)) {
|
||||
*vp = JSVAL_VOID;
|
||||
} else {
|
||||
nsStringBuffer* sharedBuffer = nsnull;
|
||||
*vp = XPCStringConvert::ReadableToJSVal(cx, val, &sharedBuffer);
|
||||
if (sharedBuffer) {
|
||||
val.ForgetSharedBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
return NS_SUCCESS_I_DID_SOMETHING;
|
||||
@ -10438,7 +10457,15 @@ nsHistorySH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
|
||||
|
||||
nsCOMPtr<nsIDOMHistory> history(do_QueryInterface(aNative));
|
||||
|
||||
return history->Item(aIndex, aResult);
|
||||
nsresult rv = history->Item(aIndex, aResult);
|
||||
#ifdef DEBUG
|
||||
if (DOMStringIsNull(aResult)) {
|
||||
PRInt32 length = 0;
|
||||
history->GetLength(&length);
|
||||
NS_ASSERTION(aIndex >= length, "Item should only return null for out-of-bounds access");
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -10454,7 +10481,15 @@ nsMediaListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
|
||||
|
||||
nsCOMPtr<nsIDOMMediaList> media_list(do_QueryInterface(aNative));
|
||||
|
||||
return media_list->Item(PRUint32(aIndex), aResult);
|
||||
nsresult rv = media_list->Item(PRUint32(aIndex), aResult);
|
||||
#ifdef DEBUG
|
||||
if (DOMStringIsNull(aResult)) {
|
||||
PRUint32 length = 0;
|
||||
media_list->GetLength(&length);
|
||||
NS_ASSERTION(PRUint32(aIndex) >= length, "Item should only return null for out-of-bounds access");
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -10517,7 +10552,15 @@ nsCSSStyleDeclSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
|
||||
|
||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> style_decl(do_QueryInterface(aNative));
|
||||
|
||||
return style_decl->Item(PRUint32(aIndex), aResult);
|
||||
nsresult rv = style_decl->Item(PRUint32(aIndex), aResult);
|
||||
#ifdef DEBUG
|
||||
if (DOMStringIsNull(aResult)) {
|
||||
PRUint32 length = 0;
|
||||
style_decl->GetLength(&length);
|
||||
NS_ASSERTION(PRUint32(aIndex) >= length, "Item should only return null for out-of-bounds access");
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -11138,7 +11181,15 @@ nsOfflineResourceListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
|
||||
nsCOMPtr<nsIDOMOfflineResourceList> list(do_QueryInterface(aNative));
|
||||
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
|
||||
|
||||
return list->MozItem(aIndex, aResult);
|
||||
nsresult rv = list->MozItem(aIndex, aResult);
|
||||
#ifdef DEBUG
|
||||
if (DOMStringIsNull(aResult)) {
|
||||
PRUint32 length = 0;
|
||||
list->GetMozLength(&length);
|
||||
NS_ASSERTION(PRUint32(aIndex) >= length, "MozItem should only return null for out-of-bounds access");
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
// nsFileListSH
|
||||
|
@ -108,6 +108,7 @@ _TEST_FILES = \
|
||||
child_bug260264.html \
|
||||
grandchild_bug260264.html \
|
||||
utils_bug260264.js \
|
||||
test_bug529328.html \
|
||||
test_bug531176.html \
|
||||
test_bug531542.html \
|
||||
test_bug456151.html \
|
||||
|
143
dom/tests/mochitest/bugs/test_bug529328.html
Normal file
143
dom/tests/mochitest/bugs/test_bug529328.html
Normal file
@ -0,0 +1,143 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=529328
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 529328</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/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=529328">Mozilla Bug 529328</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
/** Test for Bug 529328 **/
|
||||
function testDOMTokenList() {
|
||||
is(document.body.classList[-1], undefined, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList[0], undefined, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList[1], undefined, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList[2], undefined, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList.item(-1), null, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList.item(0), null, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList.item(1), null, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList.item(2), null, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
|
||||
document.body.className = "a b";
|
||||
is(document.body.classList[-1], undefined, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList[0], "a", "Wrong value for in bounds access (DOMTokenList)");
|
||||
is(document.body.classList[1], "b", "Wrong value for in bounds access (DOMTokenList)");
|
||||
is(document.body.classList[2], undefined, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList.item(-1), null, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
is(document.body.classList.item(0), "a", "Wrong value for in bounds access (DOMTokenList)");
|
||||
is(document.body.classList.item(1), "b", "Wrong value for in bounds access (DOMTokenList)");
|
||||
is(document.body.classList.item(2), null, "Wrong value for out of bounds access (DOMTokenList)");
|
||||
}
|
||||
|
||||
function testDOMStringList() {
|
||||
is(document.styleSheetSets[-1], undefined, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets[0], undefined, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets[1], undefined, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets[2], undefined, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets.item(-1), null, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets.item(0), null, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets.item(1), null, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets.item(2), null, "Wrong value for out of bounds access (DOMStringList)");
|
||||
|
||||
var s = document.createElement("style");
|
||||
s.title = "a";
|
||||
document.head.appendChild(s);
|
||||
s = document.createElement("style");
|
||||
s.title = "b";
|
||||
document.head.appendChild(s);
|
||||
|
||||
is(document.styleSheetSets[-1], undefined, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets[0], "a", "Wrong value for in bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets[1], "b", "Wrong value for in bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets[2], undefined, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets.item(-1), null, "Wrong value for out of bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets.item(0), "a", "Wrong value for in bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets.item(1), "b", "Wrong value for in bounds access (DOMStringList)");
|
||||
is(document.styleSheetSets.item(2), null, "Wrong value for out of bounds access (DOMStringList)");
|
||||
}
|
||||
|
||||
function testMediaList() {
|
||||
var s = document.createElement("style");
|
||||
document.head.appendChild(s);
|
||||
try {
|
||||
is(s.sheet.media[-1], undefined, "Wrong value for out of bounds access (MediaList)");
|
||||
todo(true, "Didn't throw");
|
||||
} catch (e) {
|
||||
todo(false, "Shouldn't throw");
|
||||
}
|
||||
is(s.sheet.media[0], undefined, "Wrong value for out of bounds access (MediaList)");
|
||||
is(s.sheet.media[1], undefined, "Wrong value for out of bounds access (MediaList)");
|
||||
is(s.sheet.media[2], undefined, "Wrong value for out of bounds access (MediaList) (MediaList)");
|
||||
is(s.sheet.media.item(-1), null, "Wrong value for out of bounds access (MediaList)");
|
||||
is(s.sheet.media.item(0), null, "Wrong value for out of bounds access (MediaList)");
|
||||
is(s.sheet.media.item(1), null, "Wrong value for out of bounds access (MediaList)");
|
||||
is(s.sheet.media.item(2), null, "Wrong value for out of bounds access (MediaList) (MediaList)");
|
||||
|
||||
s.setAttribute("media", "a, b");
|
||||
|
||||
try {
|
||||
is(s.sheet.media[-1], undefined, "Wrong value for out of bounds access (MediaList)");
|
||||
todo(true, "Didn't throw");
|
||||
} catch (e) {
|
||||
todo(false, "Shouldn't throw");
|
||||
}
|
||||
is(s.sheet.media[0], "a", "Wrong value for in bounds access (MediaList)");
|
||||
is(s.sheet.media[1], "b", "Wrong value for in bounds access (MediaList)");
|
||||
is(s.sheet.media[2], undefined, "Wrong value for out of bounds access (MediaList) (MediaList)");
|
||||
is(s.sheet.media.item(-1), null, "Wrong value for out of bounds access (MediaList)");
|
||||
is(s.sheet.media.item(0), "a", "Wrong value for in bounds access (MediaList)");
|
||||
is(s.sheet.media.item(1), "b", "Wrong value for in bounds access (MediaList)");
|
||||
is(s.sheet.media.item(2), null, "Wrong value for out of bounds access (MediaList) (MediaList)");
|
||||
}
|
||||
|
||||
function testCSSStyleDeclaration() {
|
||||
var s = document.createElement("span");
|
||||
|
||||
try {
|
||||
is(s.style[-1], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
todo(true, "Didn't throw");
|
||||
} catch (e) {
|
||||
todo(false, "Shouldn't throw");
|
||||
}
|
||||
is(s.style[0], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
is(s.style[1], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
is(s.style[2], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
is(s.style.item(-1), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
is(s.style.item(0), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
is(s.style.item(1), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
is(s.style.item(2), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
|
||||
s.setAttribute("style", "color: blue; z-index: 42;");
|
||||
|
||||
try {
|
||||
is(s.style[-1], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
todo(true, "Didn't throw");
|
||||
} catch (e) {
|
||||
todo(false, "Shouldn't throw");
|
||||
}
|
||||
is(s.style[0], "color", "Wrong value for in bounds access (CSSStyleDeclaration)");
|
||||
is(s.style[1], "z-index", "Wrong value for in bounds access (CSSStyleDeclaration)");
|
||||
is(s.style[2], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
is(s.style.item(-1), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
is(s.style.item(0), "color", "Wrong value for in bounds access (CSSStyleDeclaration)");
|
||||
is(s.style.item(1), "z-index", "Wrong value for in bounds access (CSSStyleDeclaration)");
|
||||
is(s.style.item(2), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
|
||||
}
|
||||
|
||||
testDOMTokenList();
|
||||
testDOMStringList();
|
||||
testMediaList();
|
||||
testCSSStyleDeclaration();
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user