Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Node.contains() works contrary to specs #11479

Closed
csillag opened this issue Jul 15, 2013 · 11 comments
Closed

Node.contains() works contrary to specs #11479

csillag opened this issue Jul 15, 2013 · 11 comments
Assignees

Comments

@csillag
Copy link

csillag commented Jul 15, 2013

According to the DOM Level 4 specs, Node.contains() should return True when called on itself.

Both Firefox and Chrome follows this specification, but PhantomJS does not seem to.

Check this:
var text = document.createTextNode("This is a test text");
console.log(text.contains(text));

This returns False in PhantomJS, while it's True everywhere else.

I think this is wrong.

@nickstenning
Copy link

This probably isn't a bug in Phantom. It appears to be a known bug in WebKit: [1], [2].

@csillag
Copy link
Author

csillag commented Jul 15, 2013

According the the referenced article, the relevant WebKit bug was fixed in 522. I am running PhantomJS 1.9.1, which is based on Webkit 534.34, so I'm not sure if this is really the same bug.

@csillag
Copy link
Author

csillag commented Jul 15, 2013

Actually, it behaves even weirder than I described originally.

See this test code:

var div1 = document.createElement("div");
var div2 = document.createElement("div");
var text = document.createTextNode("This is a test text");
div1.appendChild(div2);
div2.appendChild(text);
console.log(div1.outerHTML);
console.log("div1 -> div1: " + div1.contains(div1)); // Should be true
console.log("div1 -> div2: " + div1.contains(div2)); // Should be true
console.log("div2 -> div1: " + div2.contains(div1)); // Should be false
console.log("div1 -> text: " + div1.contains(text)); // Should be true
console.log("div2 -> div2: " + div1.contains(div2)); // Should be true
console.log("div2 -> text: " + div2.contains(text)); // should be true
console.log("text -> text: " + text.contains(text)); // should be true
phantom.exit();

For me, output is:

< div >< div >This is a test text< /div >< /div > ok
div1 -> div1: true ok
div1 -> div2: true ok
div2 -> div1: false ok
div1 -> text: false Why?
div2 -> div2: true ok
div2 -> text: false Why?
TypeError: 'undefined' is not a function (evaluating 'text.contains(text)') this is flat out an internal error, not even a wrong return value

@JamesMGreene
Copy link
Collaborator

Your test results suggests that the currently used version of WebKit has an implementation of Element#contains rather than Node#contains. Element#contains was indeed the original implementation but it was supposedly moved to Node#contains in WebKit 528.

I don't see any pertinent bugs listed for this in the WebKit tracker, though. 😕

@csillag
Copy link
Author

csillag commented Jul 15, 2013

Other WebKit-based browsers (for example, Chrome) don't seem to have this problem.

@JamesMGreene
Copy link
Collaborator

This is true of many of the problems that PhantomJS has but almost all of them are directly related to the old version of WebKit that we are currently using until PhantomJS 2.0 is released.

@csillag
Copy link
Author

csillag commented Jul 15, 2013

So basically, this will be fixed by solving #10031, right?

@JamesMGreene
Copy link
Collaborator

Tackling #10031 ("Bleeding-edge WebKit") is more of a long term goal, so #10448 ("Switch to Qt 5") is the one you'll want to keep an eye on in the short term.

@csillag
Copy link
Author

csillag commented Jul 15, 2013

I see. Thanks for the info. (No ETA in the foreseeable future, right?)

@JamesMGreene
Copy link
Collaborator

We were hoping for late September but we haven't been able to dedicate much time to it yet. 😕

@vitallium
Copy link
Collaborator

FIxed in 2.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants