Bug 368459 - Test for XML.prototype.normalize() in E4X test suite is wrong; also fix the bug the buggy testcase was hiding. r=brendan
git-svn-id: svn://10.0.0.236/trunk@219067 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
84a2931a30
commit
e5e23c59f9
@ -6581,25 +6581,6 @@ NormalizingDelete(JSContext *cx, JSObject *obj, JSXML *xml, jsval id)
|
||||
return DeleteByIndex(cx, xml, id, &junk);
|
||||
}
|
||||
|
||||
/*
|
||||
* Erratum? the testcase js/tests/e4x/XML/13.4.4.26.js wants all-whitespace
|
||||
* text between tags to be removed by normalize.
|
||||
*/
|
||||
static JSBool
|
||||
IsXMLSpace(JSString *str)
|
||||
{
|
||||
const jschar *cp, *end;
|
||||
|
||||
cp = JSSTRING_CHARS(str);
|
||||
end = cp + JSSTRING_LENGTH(str);
|
||||
while (cp < end) {
|
||||
if (!JS_ISXMLSPACE(*cp))
|
||||
return JS_FALSE;
|
||||
++cp;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* XML and XMLList */
|
||||
static JSBool
|
||||
xml_normalize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
@ -6640,7 +6621,7 @@ xml_normalize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
n = xml->xml_kids.length;
|
||||
kid->xml_value = str;
|
||||
}
|
||||
if (IS_EMPTY(kid->xml_value) || IsXMLSpace(kid->xml_value)) {
|
||||
if (IS_EMPTY(kid->xml_value)) {
|
||||
if (!NormalizingDelete(cx, obj, xml, INT_TO_JSVAL(i)))
|
||||
return JS_FALSE;
|
||||
n = xml->xml_kids.length;
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
* Igor Bukanov
|
||||
* Ethan Hugg
|
||||
* Milen Nankov
|
||||
* Jeff Walden <jwalden+code@mit.edu>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -47,19 +48,89 @@ TEST(1, true, XML.prototype.hasOwnProperty("normalize"));
|
||||
XML.ignoreWhitespace = false;
|
||||
XML.prettyPrinting = false;
|
||||
|
||||
x =
|
||||
<alpha> <bravo> one </bravo> </alpha>;
|
||||
var x = <alpha> <bravo> one </bravo> </alpha>;
|
||||
|
||||
TEST_XML(2, "<alpha> <bravo> one </bravo> </alpha>", x);
|
||||
x.normalize();
|
||||
TEST_XML(3, "<alpha><bravo> one </bravo></alpha>", x);
|
||||
TEST_XML(3, "<alpha> <bravo> one </bravo> </alpha>", x);
|
||||
|
||||
x =
|
||||
<alpha>
|
||||
<bravo> one </bravo>
|
||||
</alpha>;
|
||||
|
||||
// First, test text node coalescing
|
||||
|
||||
delete x.bravo[0];
|
||||
|
||||
TEST_XML(4, "<alpha> </alpha>", x);
|
||||
TEST(5, 2, x.children().length());
|
||||
|
||||
x.normalize();
|
||||
TEST_XML(5, "<alpha><bravo> one </bravo></alpha>", x);
|
||||
|
||||
END();
|
||||
TEST_XML(6, "<alpha> </alpha>", x);
|
||||
TEST(7, 1, x.children().length());
|
||||
|
||||
// check that nodes are inserted in the right place after a normalization
|
||||
|
||||
x.appendChild(<bravo> fun </bravo>);
|
||||
|
||||
TEST_XML(8, "<alpha> <bravo> fun </bravo></alpha>", x);
|
||||
TEST(9, 2, x.children().length());
|
||||
|
||||
// recursive nature
|
||||
|
||||
var y = <charlie> <delta/> </charlie>;
|
||||
|
||||
TEST(10, 3, y.children().length());
|
||||
|
||||
x.appendChild(y);
|
||||
delete y.delta[0];
|
||||
|
||||
TEST(11, 2, y.children().length());
|
||||
|
||||
x.normalize();
|
||||
|
||||
TEST(12, 1, y.children().length());
|
||||
TEST(13, 1, x.charlie.children().length());
|
||||
|
||||
|
||||
|
||||
// Second, test empty text node removal
|
||||
|
||||
x = <alpha><beta/></alpha>;
|
||||
|
||||
TEST_XML(14, "<alpha><beta/></alpha>", x);
|
||||
TEST(15, 1, x.children().length());
|
||||
|
||||
x.appendChild(XML());
|
||||
|
||||
TEST_XML(16, "<alpha><beta/></alpha>", x);
|
||||
TEST(17, 2, x.children().length());
|
||||
|
||||
x.normalize();
|
||||
|
||||
TEST_XML(18, "<alpha><beta/></alpha>", x);
|
||||
TEST(19, 1, x.children().length());
|
||||
|
||||
x.appendChild(XML(" "));
|
||||
|
||||
TEST_XML(20, "<alpha><beta/> </alpha>", x);
|
||||
TEST(21, 2, x.children().length());
|
||||
|
||||
x.normalize();
|
||||
|
||||
// normalize does not remove whitespace-only text nodes
|
||||
TEST_XML(22, "<alpha><beta/> </alpha>", x);
|
||||
TEST(23, 2, x.children().length());
|
||||
|
||||
y = <foo/>;
|
||||
y.appendChild(XML());
|
||||
|
||||
TEST(24, 1, y.children().length());
|
||||
|
||||
x.appendChild(y);
|
||||
|
||||
// check recursive nature
|
||||
|
||||
x.normalize();
|
||||
|
||||
TEST(25, 0, y.children().length());
|
||||
|
||||
END();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user