Skip to content

Add DOMNode::compareDocumentPosition() #12146

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

Merged
merged 2 commits into from
Sep 8, 2023

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Sep 6, 2023

Comment on lines +34 to +39
. Added constant DOMNode::DOCUMENT_POSITION_DISCONNECTED.
. Added constant DOMNode::DOCUMENT_POSITION_PRECEDING.
. Added constant DOMNode::DOCUMENT_POSITION_FOLLOWING.
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINS.
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY.
. Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC.
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to make this an enum?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about that too. The problem is that they're bitflags, so they might be OR'ed with eachother. That's something not supported with enums right now.

Copy link
Member

Choose a reason for hiding this comment

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

Enum sets would be nice to have indeed :(

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.

LGTM, just minor questions

Comment on lines +34 to +39
. Added constant DOMNode::DOCUMENT_POSITION_DISCONNECTED.
. Added constant DOMNode::DOCUMENT_POSITION_PRECEDING.
. Added constant DOMNode::DOCUMENT_POSITION_FOLLOWING.
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINS.
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY.
. Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC.
Copy link
Member

Choose a reason for hiding this comment

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

Enum sets would be nice to have indeed :(

ext/dom/node.c Outdated

/* Special case: comparing children and attributes.
* They belong to a different tree and are therefore hard to compare, but spec demands attributes to precede children
* according to the pre-order DFS numbering.
Copy link
Member

Choose a reason for hiding this comment

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

DFS?

Copy link
Member Author

Choose a reason for hiding this comment

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

Depth-first search. I'll write it out in full.

Comment on lines 23 to 35
--EXPECT--
--- Compare 0 and 1 ---
int(36)
--- Compare 0 and 2 ---
int(36)
--- Compare 1 and 2 ---
int(36)
--- Compare 1 and 0 ---
int(34)
--- Compare 2 and 0 ---
int(34)
--- Compare 2 and 1 ---
int(34)
Copy link
Member

Choose a reason for hiding this comment

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

Are the values meaningful?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll clean it up so it's easier to understand.

Comment on lines +36 to +38
echo "--- strong & bar ---\n";
var_dump($bar->nextElementSibling->compareDocumentPosition($bar) === DOMNode::DOCUMENT_POSITION_PRECEDING);
var_dump($bar->compareDocumentPosition($bar->nextElementSibling) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
Copy link
Member

Choose a reason for hiding this comment

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

How would the two strong tags compare?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a test for this.

@nielsdos nielsdos merged commit 880faa3 into php:master Sep 8, 2023
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.

3 participants