New nsIScriptable interface: Difference between revisions

Jump to navigation Jump to search
Line 127: Line 127:
This would be achieved by:
This would be achieved by:


    // A new helper xpcom service for cross-language work.
  // A new helper xpcom service for cross-language work.
    [scriptable, uuid(...)]
  [scriptable, uuid(...)]
    interface nsIDOMScriptObjectHelper: nsISupports
  interface nsIDOMScriptObjectHelper: nsISupports
    {
  {
        // Compile a function using the specified language.  Returns
      // Compile a function using the specified language.  Returns
        // an nsIScriptable that can be directly called (ie, by passing
      // an nsIScriptable that can be directly called (ie, by passing
        // DISPID_DEFAULT).  |glob| must be the global window in
      // DISPID_DEFAULT).  |glob| must be the global window in
        // which the returned function will execute when called.
      // which the returned function will execute when called.
        // Generally you pass |this|.
      // Generally you pass |this|.
        nsIScriptable compileFunction(in nsISupports glob,
      nsIScriptable compileFunction(in nsISupports glob,
                                      in PRUint32 langID,  
                                    in PRUint32 langID,  
                                      in DOMString aCode,  
                                    in DOMString aCode,  
                                      [array] in DOMString argNames);
                                    [array] in DOMString argNames);
   
 
        // Execute arbitrary code.
      // Execute arbitrary code.
        void execute(PRUint32 langID, in DOMString aCode);
      void execute(PRUint32 langID, in DOMString aCode);
   
 
        // Takes a script-type ID (which is presumably the ID for
      // Takes a script-type ID (which is presumably the ID for
        // a language other than the one being executed), and nsISupports  
      // a language other than the one being executed), and nsISupports  
        // |glob| (which must be the global object for the currently
      // |glob| (which must be the global object for the currently
        // executing language) and returns an nsIScriptable, which is  
      // executing language) and returns an nsIScriptable, which is  
        // the namespace for the requested language.
      // the global scope object for the requested language.
        nsIScriptable getLanguageGlobal(in PRUint32 aRequestedLanguage, in nsISupports glob);
      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 lang_id = node.scriptTypeID; // new attribute on nsIDOMNSEventTarget.
    var s = components.classes["@mozilla.org/scriptobjectfactory"].getService();
  var s = components.classes["@mozilla.org/scriptobjectfactory"].getService();
      
      
    var func = s.compileFunction(this, lang_id, handler, "event");
  var func = s.compileFunction(this, lang_id, handler, "event");
    // |func| is an nsIScriptable - call it.
  // |func| is an nsIScriptable -- call it.
    var returned = func(event)
  var returned = func(event);


==== Contrived dialog widget ====
==== Contrived dialog widget ====
Confirmed users, Bureaucrats and Sysops emeriti
419

edits

Navigation menu