Many thanks for the hints! Yes, webkit has an auto-reflection layer from C/Qt/Objective-C runtime objects to JS, in Qt, they use Q_Property and slots to expose interfaces. Is XPCOM can also be used as runtime objects that can be "new" in codes, for in my limited knowledge, XPCOM are all .so shared objects that are transparently loaded by browser and then bridged to JS via XPConnect.
On Thu, Jun 4, 2009 at 9:42 AM, Boris Zbarsky <bzbar...@mit.edu> wrote: > Harry Zhang wrote: > >> Thanks for the hint, I know that XPCOM component can be used as script >> object in webpage, but actually what i mean is somehow as: >> >> Object* object = new CustomizedObject(); /* customizedobject class has a >> slot named "test" */ >> webframe::addToJavascriptWindowObject("foo", object); >> >> then in webpage, we can use "foo.test()" to invoke the method of a runtime >> C >> object. >> > > You'd need to have the object implement some scriptable interface (it > doesn't have to be an XPCOM component in the sense of being registered with > the component manager or anything). > > That is, sounds like webkit has an auto-reflection layer from QT objects to > JS. We have an auto-reflection layer from XPCOM objects to JS. XPCOM > objects don't have quite the same reflection setup that QT objects seem to, > so you have to explicitly declare your methods/properties. > > Of course you could always use JSAPI directly and just create a JSObject > with various properties stuck on it; that's what XPConnect ends up doing for > you with an XPCOM object that implements a scriptable interface. > > > -Boris > _______________________________________________ > dev-embedding mailing list > dev-embedding@lists.mozilla.org > https://lists.mozilla.org/listinfo/dev-embedding > _______________________________________________ dev-embedding mailing list dev-embedding@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-embedding