-
-
Notifications
You must be signed in to change notification settings - Fork 916
[feature] document.parent
should exist
#3466
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
Comments
@doriantaylor I'm not opposed to this in principle. Would you be willing to draft a pull request and seeing what (if any) tests are failing? And maybe seeing what's involved to get them to pass? |
document.parent
fails with NoMethodError
document.parent
should exist
Can you say more about your use case? I've never really run into a situation where I didn't know the object was a Document as opposed to a non-document Node. If you could share some real-world code it would help me understand your motivation. |
While libxml2 also sets a document's parent to the document itself, I consider that a design mistake. Conceptually, the chain of ancestors should be a linked list and setting while node
...
node = node.parent
end |
You're right; my original use case was a function that took an arbitrary node as an argument but didn't have to care about what kind of node it was, and had logic to orient itself, but I had written it with I went and double-checked the DOM spec (well, MDN because WHATWG is a dog's breakfast) the following turns out to be the case for |
@doriantaylor Again, I'm open to changing this behavior if we agree (following the advice of @nwellnhof who's the libxml2 maintainer above) that the desired behavior is for |
I've created #3481 for this change. |
@doriantaylor I also just want to respond to the fact that you (twice!) mentioned that Official docs, generated by rdoc, do not currently include |
Uh oh!
There was an error while loading. Please reload this page.
IMO this should work for parity when the node type is unknown:
document.parent == document
.Consider the following:
Expected behavior
It shouldn't crash (indeed, the documentation says the method is there).
document.parent
should just be a no-op that returnsself
.Environment
The text was updated successfully, but these errors were encountered: