Skip to content

Implement DOMNode::isConnected and DOMNameSpaceNode::isConnected #11677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

nielsdos
Copy link
Member

@nielsdos
Copy link
Member Author

Note: Test failures are related to recent ext/date changes, unrelated to this PR.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sensible to me, other the minor thing that requires some clarification.

@theseer do you want to verify the test output?

Comment on lines +326 to +328
/** @readonly */
public bool $isConnected;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a new property, I think you can just use the normal keyword. @kocsismate is my assumption correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, absolutely, if the implementation is in line with readonly! :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is more like a calculated field than a real readonly property (the value can change multiple times even though it's not possible to write by users), so the @readonly is correct here!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Máté, for clarifying!

Comment on lines +418 to +419
/** @readonly */
public bool $isConnected;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@theseer
Copy link
Contributor

theseer commented Jul 12, 2023

I can only give feedback on the added testcase ext/dom/tests/DOMNode_DOMNameSpaceNode_isConnected.phpt. While the other test changes seem to make sense, I'm not feeling qualified to judge here.

The behavior outlined in the new ext/dom/tests/DOMNode_DOMNameSpaceNode_isConnected.phpt though is what I would have expected and seems according to the standard as I understand it.

I do have a question though: I'm not fully convinced that DomDocument::isConnected ever should return true. Unfortunately, I cannot find anything in that regard in the spec.

My reasoning: As it's the document itself, I'd say it logically cannot be connected to anything. The "highest" level I'd expect to be connectable (if that's a word) would be documentElement / docType and friends, all properties of DomDocument. Again, I couldn't find anything in the specs to support this notion. Nor the opposite. But maybe I just missed that.

@nielsdos
Copy link
Member Author

Thx for having a look.

I do have a question though: I'm not fully convinced that DomDocument::isConnected ever should return true. Unfortunately, I cannot find anything in that regard in the spec.

From https://dom.spec.whatwg.org/#connected:

An element is connected if its shadow-including root is a document.

And from https://dom.spec.whatwg.org/#concept-tree-root:

The root of an object is itself, if its parent is null, or else it is the root of its parent. The root of a tree is any object participating in that tree whose parent is null.

Since document's parent is null, the root it itself. Therefore, isConnected must be true.
You can also enter this in a JS console in a browser and see that it's true: console.log(document.isConnected).

@theseer
Copy link
Contributor

theseer commented Jul 12, 2023

So I indeed missed that. Thanks for the clarification, @nielsdos :)

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

Successfully merging this pull request may close these issues.

4 participants