Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

nsHTMLElement.cpp 裡的 NS_NewHTMLElement 是多餘的?

9 views
Skip to first unread message

Kang-Hao (Kenny) Lu

unread,
Jun 19, 2012, 9:27:03 AM6/19/12
to "Mozilla 開發(mozilla.dev.general.zh)"
nsHTMLElement.cpp 裡面有一個函數是

nsGenericHTMLElement* NS_NewHTMLElement(already_AddRefed<nsINodeInfo>
aNodeInfo, FromParser aFromParser);

這,造成了我讀程式碼一個很不小的困擾。document.createElement() 的路徑看
起來是這樣的:

nsDocument::createElement → nsDocument::createElem →
NS_NewElement(nsNamespaceManager.cpp)→
NS_NewHTMLElement(nsHTMLContentSink.cpp)→ CreateHTMLElement

其中,NS_NewHTMLElement 這個名字很不幸的重複了,其特徵是:

nsresult NS_NewHTMLElement(nsIContent** aResult,
already_AddRefed<nsINodeInfo> aNodeInfo, FromParser aFromParser)

(我有把一些這部份記到 DOM4 實作註解[1]上)

仔細搜了一下,發現到 nsHTMLElement.cpp 裡的那個 NS_NewHTMLElement 應該是
完全沒用的,它還留了一個註解:

// Here, we expand 'NS_IMPL_NS_NEW_HTML_ELEMENT()' by hand.
// (Calling the macro directly (with no args) produces compiler warnings.)

但是總之我沒有發現有 NS_NewHTML##name##Element 而其中 name 會是空字串的
情形,也就是,怎麼看都是殭屍代碼。

但是我沒有很確定,所以有興趣的人可以把這塊,還有 nsGenericHTMLElement.h
的那塊拿掉編譯看看。因為我不確定這是對的,就不把這個當作我的 mentored
bug 了。(我還有兩個還沒被撿走的 mentored bug,有興趣來捧場一下 :p。)

(從現在開始,與其把這些有的沒有的記在小本子裡,我會試著丟過來,下次再介
紹我的那兩個 mentored bug。)

[1] http://www.w3.org/html/ig/zh/wiki/DOM4/impl#dom-document-createelement


以上

Kenny
0 new messages