Closed
Bug 1010760
Opened 10 years ago
Closed 10 years ago
Add nsINode::IsText, AsText like for Element
Categories
(Core :: DOM: Core & HTML, enhancement)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla34
People
(Reporter: ayg, Assigned: ayg)
Details
Attachments
(1 file, 1 obsolete file)
6.42 KB,
patch
|
smaug
:
review+
|
Details | Diff | Splinter Review |
It's better to call AsElement than cast to Element, because it asserts that it actually is an element. Likewise it would be good to have for Text and nsIContent. IsText() is a lot easier to type and read than IsNodeOfType(nsINode::eTEXT).
Comment 1•10 years ago
|
||
We have IsContent and AsContent
Assignee | ||
Updated•10 years ago
|
Summary: Add nsINode::IsText, AsText, IsContent, AsContent like for Element → Add nsINode::IsText, AsText like for Element
Assignee | ||
Comment 2•10 years ago
|
||
Attachment #8471546 -
Flags: review?(bugs)
Comment 3•10 years ago
|
||
Comment on attachment 8471546 [details] [diff] [review] Patch IsContent and IsElement are non-virtual and inlined. It would be odd if IsText() behaved significantly slower. We need a bool flag.
Attachment #8471546 -
Flags: review?(bugs) → review-
Assignee | ||
Comment 4•10 years ago
|
||
Do you actually want me to add a bool flag? I don't imagine there would be enough callers to justify it. If not, what would you prefer instead? The code pattern we have right now is if (node->IsNodeOfType(nsINode::eTEXT)) { nsCOMPtr<Text> textNode = static_cast<Text>(node); // . . . which is bad because a) it's long to type, and b) the static_cast has no safety check in debug builds. If you would prefer, I could add just AsText() and not IsText(), which would solve (b), although the asymmetry in the API would be confusing.
Flags: needinfo?(bugs)
Comment 5•10 years ago
|
||
I want IsFoo methods to have same performance characteristics, so bool flag would be needed. Would GetAsText() work? That hints that it may return null, and implementation could be then something like. Text* GetAsText() { return IsNodeOfType(nsINode::eTEXT) ? static_cast<Text*>(this) : nullptr; }
Flags: needinfo?(bugs)
Assignee | ||
Comment 6•10 years ago
|
||
Attachment #8471546 -
Attachment is obsolete: true
Attachment #8472311 -
Flags: review?(bugs)
Updated•10 years ago
|
Attachment #8472311 -
Flags: review?(bugs) → review+
Assignee | ||
Comment 7•10 years ago
|
||
Try: https://tbpl.mozilla.org/?tree=Try&rev=52ee018a8367 http://hg.mozilla.org/integration/mozilla-inbound/rev/1ebef29c93f6
Flags: in-testsuite-
Comment 8•10 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/1ebef29c93f6
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
Updated•5 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•