[ htmlunit-Bugs-1409087 ] NodeImpl jsxFunction_insertBefore return null

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ htmlunit-Bugs-1409087 ] NodeImpl jsxFunction_insertBefore return null

SourceForge.net
Bugs item #1409087, was opened at 2006-01-18 15:44
Message generated for change (Comment added) made by mguillem
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=448266&aid=1409087&group_id=47038

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: Latest code in SVN
Status: Open
Resolution: None
Priority: 5
Submitted By: Jerome Jeanjean (dje77)
Assigned to: Nobody/Anonymous (nobody)
Summary: NodeImpl jsxFunction_insertBefore return null

Initial Comment:
When using the JavaScript function insertBefore
without a second argument (as stated in the
Javascript reference), the function  
jsxFunction_insertBefore has a bad behavior.

The input argument refChildObject of the function
jsxFunction_insertBefore is not sent as null (not
sure why) and so the test "if(refChildObject !=
null)" is not effective.
When this object is used in "refChildNode =
((NodeImpl) refChildObject).getDomNodeOrDie();" the
test crashes.
Modifying the test with "if(refChildObject != null &&
refChildObject instanceof NodeImpl)" solves this
problem.
But, after that, the object refChildNode is null and
the object appendedChild is not initialized before
the return.

Here is the modified code for the function
jsxFunction_insertBefore.

    public Object jsxFunction_insertBefore(
            final Object newChildObject, final Object
refChildObject) {
        Object appendedChild = null;

        if (newChildObject instanceof NodeImpl) {

            final DomNode newChildNode =
                ((NodeImpl)
newChildObject).getDomNodeOrDie();

            final DomNode refChildNode;
            if(refChildObject != null &&
refChildObject instanceof NodeImpl) {
                refChildNode = ((NodeImpl)
refChildObject).getDomNodeOrDie();
            }
            else {
                refChildNode = null;
            }
            appendedChild = newChildObject;
           
            // Append the child to the parent node
            if (refChildNode != null ) {
                refChildNode.insertBefore
(newChildNode);
               
            }
            else {
                getDomNodeOrDie().appendChild
(newChildNode);
            }
        }
        return appendedChild;
    }


Here is the code of NodeImplTest to test this new
implementation:

    public void test_insertBefore_nullRef() throws
Exception {
        final String content
= "<html><head><title>test_insertBefore</title>"
                        + "<script>"
                        + "function doTest() {"
                        //+ "var nodeToInsert =
document.getElementById('nodeToInsert');"
                        + "var nodeToInsert =
document.createElement(\"h2\");"
                        + "var aNode =
document.getElementById('myNode');"
                        //+ "aNode.insertBefore
(nodeToInsert, null);"
                        + "var newNode =
aNode.insertBefore(nodeToInsert);"
                        // Addition
                        + "newNode.text=\"Bottom\";"
                        + "alert
(aNode.childNodes.length);"
                        + "alert(aNode.childNodes
[2].nodeName);"
                        //Addition
                        + "alert(aNode.childNodes
[2].text);"
                        + "}"
                        + "</script>"
                        + "</head><body onload='doTest
()'>"
                        //+ "<h2
id='nodeToInsert'>Bottom</h2>"
                        + "<div
id='myNode'><span>Child Node 1-A</span>"
                        + "<h1>Child Node 2-
A</h1></div>"
                        + "</body></html>";

        final List collectedAlerts = new ArrayList();

        //final List expectedAlerts = Arrays.asList
(new String[] { "3", "H2" });
        final List expectedAlerts = Arrays.asList(new
String[] { "3", "H2", "Bottom" });
        createTestPageForRealBrowserIfNeeded(content,
expectedAlerts);

        final HtmlPage page = loadPage(content,
collectedAlerts);
        assertEquals("test_insertBefore",
page.getTitleText());
        assertEquals(expectedAlerts, collectedAlerts);
    }

----------------------------------------------------------------------

>Comment By: Marc Guillemot (mguillem)
Date: 2006-09-11 14:33

Message:
Logged In: YES
user_id=402164

My FF  throws:
Error: Not enough arguments
[nsIDOMHTMLDivElement.insertBefore] =
NS_ERROR_XPC_NOT_ENOUGH_ARGS
Source file: file:///tmp/test40501.html
Line: 64

when insertBefore is called with only one arg. For which
browser is your description valid?

PS: please attach your fixes as patches in unified diff
format, it makes committer job really easier (and faster ;-))

----------------------------------------------------------------------

Comment By: Jerome Jeanjean (dje77)
Date: 2006-01-19 19:04

Message:
Logged In: YES
user_id=1423123

Diff between the old NodeImpl and the new one:

182c182
<             if(refChildObject != null) {
---
>             if(refChildObject != null && refChildObject
instanceof NodeImpl) {

188c188,189
<
---
>             appendedChild = newChildObject;
>
192c193
<                 appendedChild = newChildObject;
---
>


Diff between the old and the NodeImplTest

319a320,353
>
>     /**
>      * Test to verify that insertBefore correctly appends
>      * the new child object when there is only one
argument and that null is n
ot returned.
>      * @throws Exception if the test fails
>      */
>     public void test_insertBefore_one_arg() throws
Exception {
>         final String content
= "<html><head><title>test_insertBefore_one_arg</
title>"
>                         + "<script>"
>                         + "function doTest() {"
>                         + "var nodeToInsert =
document.createElement(\"h2\");"

>                         + "var aNode =
document.getElementById('myNode');"
>                         + "var newNode =
aNode.insertBefore(nodeToInsert);"
>                         + "newNode.text=\"Bottom\";"
>                         + "alert
(aNode.childNodes.length);"
>                         + "alert(aNode.childNodes
[2].nodeName);"
>                         + "alert(aNode.childNodes
[2].text);"
>                         + "}"
>                         + "</script>"
>                         + "</head><body onload='doTest
()'>"
>                         + "<div id='myNode'><span>Child
Node 1-A</span>"
>                         + "<h1>Child Node 2-A</h1></div>"
>                         + "</body></html>";
>
>         final List collectedAlerts = new ArrayList();
>
>         final List expectedAlerts = Arrays.asList(new
String[] { "3", "H2", "B
ottom" });
>         createTestPageForRealBrowserIfNeeded(content,
expectedAlerts);
>
>         final HtmlPage page = loadPage(content,
collectedAlerts);
>         assertEquals("test_insertBefore_one_arg",
page.getTitleText());
>         assertEquals(expectedAlerts, collectedAlerts);
>     }
>

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=448266&aid=1409087&group_id=47038

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop