![]() |
XPConnect Scriptable proposal
IntroductionXPConnect supports reflection into JavaScript of the methods, attributes, and constants as statically declared in each given xpcom interface's xpidl declaration. This is very useful, but it does not yet support the style of dynamically aggregated properties that make JavaScript so powerful and which are required to fully support such modules as the DOM and SmartUpdate. This proposal suggests a system to remedy this problem.
DefinitionsI speak here about three sorts of properties (where 'property' means both methods and attributes):
ProposalI propose to declare an interface callednsIXPCScriptable. Any
xpcom object can implement that interface and expose it via
QueryInterface if it so chooses. When XPConnect wraps any xpcom
object it will query for nsIXPCScriptable and act accordingly if
that interface is supported by the object.
These methods will include:
lookupProperty
defineProperty
getPropertyById
setPropertyById
getAttributes
setAttributes
deleteProperty
defaultValue
newEnumerate
checkAccess
construct
call
convert
In addition to the normal params of these JS methods we'll also pass a reference
to the wrapper itself. These methods will return a value indicating one of:
Some addtional methods will be added to this interface. For instance, the xpcom
object implementing An example...
Suppose that the call order is set to: "static, dynamic, arbitrary" and a
The IssuesMy prefered scheme for doing all this is to implement the WrappedNative JS class such that it supports both the low level jsObjectOps and also forwards to the 'standard' handlers via the js_ObjectOps 'vtbl'; i.e.js_ObjectOps.xxx();. I've played with this and it works, but there
may be cases where it will blow up. There is a discussion on
news://news.mozilla.org/netscape.public.mozilla.jseng
regarding whether or not this approach is viable.
One alternative is to not use the jsObjectOps at all and instead do everything through the classic jsclass interface. This would likely be a real performance limitation on the static reflection of xpcom objects (the main thing that XPConnect lives to do).
Another alternative I considered is to use the jsObjectOps and the
ConclusionsI'm not sure how clear this all is. The goal is to allow XPCOM objects to customize their reflection into JavaScript where necessary while still doing most of the grunt work in XPConnect. Much of the commonly used code (like converting a jsval param to the xpcom object it may wrap) can be made into XPConnect library funcions. Most objects reflected into JS will not need support for dynamic and arbitrary properties and will be able to ignore all of this. Those object that do need such support need only implement one interface to get the functionality.I would very much like to hear feedback, ideas, and requirements. Please respond to: news://news.mozilla.org/netscape.public.mozilla.xpcom document history...
|
|||||||
| Copyright © 1998-1999 The Mozilla Organization. | |||||||