Changes

Jump to: navigation, search

Gecko:Overview

959 bytes added, 18:36, 9 May 2019
More details on reflectors
=== Reflectors ===
Whether using [https://wiki.mozilla.org/Gecko:Overview#XPConnect XPConnect] or [https://wiki.mozilla.org/Gecko:Overview#WebIDL_Bindings Web IDL], the basic idea is that there is a JSObject called a '''reflector''' that represents some C++ object. The JSObject ensures that the C++ object remains alive while the JSObject is alive. The C++ object does ''not'' necessarily keep the JSObject alive; this allows the JSObject to be garbage-collected as needed. If this happens, the next time JS needs access to that C++ object a new reflector is created. If something happens that requires that the actual object identity of the JSObject be preserved even though it's not explicitly reachable, the C++ object will start keeping the JSObject alive as well. After this point, the cycle collector would be the only way for the pair of objects to be deallocated. Examples of operations that require identity-preservation are adding a property to the object, giving the object a non-default prototype, using the object as a weakmap key or weakset member.
 
In the XPConnect case, reflectors are created by XPCWrappedNative::GetNewOrUsed. This finds the right JSClass to use for the object, depending on information provided by the C++ object via the nsIClassInfo interface about special class hooks it might need. If the C++ object has no clasinfo, XPC_WN_NoHelper_JSClass is used. GetNewOrUsed also determines the right global to use for the reflector, again based on nsIClassInfo information, with a fallback to the JSContext's current global.
 
In the Web IDL case, reflectors are created by the Wrap method that the binding code generator spits out for the relevant Web IDL interface. So for the Document interface, the relevant method is mozilla::dom::Document_Binding::Wrap. The JSClass that is used is also created by the code generator, as part of the DOMJSClass struct it outputs. Web IDL objects provide a GetParentObject() method that is used to determine the right global to use for the reflector.
=== Security ===
308
edits

Navigation menu