Confirmed users, Bureaucrats and Sysops emeriti
419
edits
| Line 127: | Line 127: | ||
This would be achieved by: | This would be achieved by: | ||
// A new helper xpcom service for cross-language work. | |||
[scriptable, uuid(...)] | |||
interface nsIDOMScriptObjectHelper: nsISupports | |||
{ | |||
// Compile a function using the specified language. Returns | |||
// an nsIScriptable that can be directly called (ie, by passing | |||
// DISPID_DEFAULT). |glob| must be the global window in | |||
// which the returned function will execute when called. | |||
// Generally you pass |this|. | |||
nsIScriptable compileFunction(in nsISupports glob, | |||
in PRUint32 langID, | |||
in DOMString aCode, | |||
[array] in DOMString argNames); | |||
// Execute arbitrary code. | |||
void execute(PRUint32 langID, in DOMString aCode); | |||
// Takes a script-type ID (which is presumably the ID for | |||
// a language other than the one being executed), and nsISupports | |||
// |glob| (which must be the global object for the currently | |||
// executing language) and returns an nsIScriptable, which is | |||
// the global scope object for the requested language. | |||
nsIScriptable getLanguageGlobal(in PRUint32 aRequestedLanguage, in nsISupports glob); | |||
}; | |||
And the JS code implementing dialog.xml would change to: | And the JS code implementing dialog.xml would change to: | ||
var lang_id = node.scriptTypeID; // new attribute on nsIDOMNSEventTarget. | |||
var s = components.classes["@mozilla.org/scriptobjectfactory"].getService(); | |||
var func = s.compileFunction(this, lang_id, handler, "event"); | |||
// |func| is an nsIScriptable -- call it. | |||
var returned = func(event); | |||
==== Contrived dialog widget ==== | ==== Contrived dialog widget ==== | ||