IT翻訳 Nobuyuki の仕事部屋

ボランティアでソフトウエアーローカライズのために翻訳をしている。

JavaScript-DOM Prototypes in Mozilla 草稿化 6

2006-03-19 20:16:43 | InDraft

原文青色表示
訳文黒色表示
注記/訂正: 赤色表示

So how does all this work in the mozilla DOM code?

It all happens in XPConnect and nsDOMClassInfo.{cpp,h} in the DOM code. During startup, the nsDOMClassInfo code registers two different types of "global names", these are names of properties of the global object with special meaning to the DOM code. The two types of "global names" are, class constructor names and class prototype names. What's the difference? Class constructor names are names of real classes, and class prototype names are names of "classes" that are inherited by real classes, but are not real classes. A few examples of class constructor names would be HTMLImageElement, HTMLDocument, Element, NodeList, and a few examples of class prototype names would be Node, CharacterData. This registration is done with the nsScriptNameSpaceManager, which is in charge of keeping track of what names are registerd in the global namespace, and what kinds of names those names are (i.e. class constructor name, class prototype name). When a class constructor name is registerd (nsGlobalNameStruct::eTypeClassConstructor), the nsScriptNameSpaceManager is given a DOM class info ID, this is a 32 bit ID that identifies class info defined in nsDOMClassInfo. When a class prototype name is registered (nsGlobalNameStruct::eTypeClassProto), the nsScriptNameSpaceManager is given the nsIID of the interface that's inherited by the class of which the registerd name is a prototype (i.e. NS_GET_IID(nsIDOMNode) for Node). nsScriptNameSpaceManager also deals with other types of names, but those are unrelated to the DOM object prototype setup, so we'll ignore those here.



それでは、これらはすべて Mozilla の DOM コードでどう機能するのでしょう?

XPConnect や DOM コードの nsDOMClassInfo.{cpp,h} で上記はいつも発生します。起動中に nsDOMClassInfo コードは 2 つの異なる型の”グローバルな名前”を登録しますが、これらは DOM コードに対し特別な意味を備えたグローバルオブジェクトのプロパティの名前です。2 つの型の”グローバルな名前”とは、クラスコンストラクタの名前とクラスプロトタイプの名前です。その違いは何でしょうか?クラスコンストラクタの名前は実クラスの名前ですが、クラスプロトタイプの名前は実クラスによって継承される実クラスではない”クラス”の名前です。いくつかのクラスコンストラクタの名前を挙げると HTMLImageElement、HTMLDocument、Element、NodeList となり、またクラスプロトタイプの名前は Node、CharacterData となります。登録は nsScriptNameSpaceManager によってされ、その役割はグローバルな名前スペースに登録された名前とその名前の型(例えばクラスコンストラクタ名やクラスプロトタイプ名)を記録することです。クラスコンストラクタの名前 (nsGlobalNameStruct::eTypeClassConstructor) が登録される時、nsScriptNameSpaceManager は DOM class info ID を受け取りますが、これは nsDOMClassInfo で定義された class info を識別する 32 ビットの ID です。クラスプロトタイプの名前(nsGlobalNameStruct::eTypeClassProto) が登録される時、nsScriptNameSpaceManager はインターフェイスの nsIID を受け取りますが、このインターフェイスは、登録されたクラス名がプロトタイプであるクラスによって継承されます(例えば Node 用の NS_GET_IID(nsIDOMNode))。nsScriptNameSpaceManager は他の名前の型も処理しますが、それらは DOM オブジェクトのプロトタイプの設定には関係ありませんので、ここでは考慮しません。