Re: How mapping of JS objects methods with native function name is done

View: New views
1 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: How mapping of JS objects methods with native function name is done

by Jason Orendorff-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/08/2009 07:31 AM, kailas wrote:
> Hi,
> I am new to Firefox.
> I want to know how the JS engine after executing the Javascript make the
> call to appropriate function. For example, if javascript code is
> document.write "hello"
> then how JS engine calls the function nsHTMLDocument::Write(const
> nsAString& aText) in Firefox.
 >
 > I want to know how or where the mapping of JS object method with Firefox
 > native function name is done, such as mapping of document.write to
 > nsHTMLDocument::Write.

You need to know about XPIDL, XPCOM, XPConnect, and "quick stubs".

In brief, for each C++ object we want to expose to JS, there's an IDL file:

http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/html/nsIDOMHTMLDocument.idl#52

This IDL describes the interface between the document object itself
(which is implemented in C++) and all the code that uses it (both C++
and JS). Several tools use the IDL.


For example, there's a program called xpidl that takes the IDL and
autogenerates a C++ header with an abstract base class. C++ code uses
(and implements) the interface via that header file. You can see where
nsHTMLDocument does #include "nsIDOMHTMLDocument.h" here:

http://mxr.mozilla.org/mozilla-central/source/content/html/document/src/nsHTMLDocument.h#43

That's an xpidl-generated header; you won't find it anywhere in our
source tree.


Another tool (or maybe it's xpidl with a different command-line option,
I forget) takes the IDL and spits out metadata that the XPConnect
library uses at run time to map JS methods and properties to C++ methods.

...But it turns out XPConnect is slow, so we have a third tool,
qsgen.py, that takes the IDL and spits out faster custom C++ code for
selected JS methods and properties, including document.write. For
details see:

http://mxr.mozilla.org/mozilla-central/source/js/src/xpconnect/src/qsgen.py#41

-j
_______________________________________________
dev-tech-js-engine mailing list
dev-tech-js-engine@...
https://lists.mozilla.org/listinfo/dev-tech-js-engine