xpcIJSModuleLoader.idl 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsISupports.idl"
  6. [ptr] native nsAXPCNativeCallContextPtr(nsAXPCNativeCallContext);
  7. %{C++
  8. #include "js/TypeDecls.h"
  9. class nsAXPCNativeCallContext;
  10. %}
  11. [ptr] native JSObjectPtr(JSObject);
  12. [scriptable, uuid(4f94b21f-2920-4bd9-8251-5fb60fb054b2)]
  13. interface xpcIJSModuleLoader : nsISupports
  14. {
  15. /**
  16. * To be called from JavaScript only.
  17. *
  18. * Synchronously loads and evaluates the js file located at
  19. * aResourceURI with a new, fully privileged global object.
  20. *
  21. * If 'targetObj' is specified and equal to null, returns the
  22. * module's global object. Otherwise (if 'targetObj' is not
  23. * specified, or 'targetObj' is != null) looks for a property
  24. * 'EXPORTED_SYMBOLS' on the new global object. 'EXPORTED_SYMBOLS'
  25. * is expected to be an array of strings identifying properties on
  26. * the global object. These properties will be installed as
  27. * properties on 'targetObj', or, if 'targetObj' is not specified,
  28. * on the caller's global object. If 'EXPORTED_SYMBOLS' is not
  29. * found, an error is thrown.
  30. *
  31. * @param resourceURI A resource:// URI string to load the module from.
  32. * @param targetObj the object to install the exported properties on.
  33. * If this parameter is a primitive value, this method throws
  34. * an exception.
  35. * @returns the module code's global object.
  36. *
  37. * The implementation maintains a hash of registryLocation->global obj.
  38. * Subsequent invocations of importModule with 'registryLocation'
  39. * pointing to the same file will not cause the module to be re-evaluated,
  40. * but the symbols in EXPORTED_SYMBOLS will be exported into the
  41. * specified target object and the global object returned as above.
  42. *
  43. * (This comment is duplicated to nsIXPCComponents_Utils.)
  44. */
  45. [implicit_jscontext,optional_argc]
  46. jsval import(in AUTF8String aResourceURI, [optional] in jsval targetObj);
  47. /**
  48. * Imports the JS module at aResourceURI to the JS object
  49. * 'targetObj' (if != null) as described for importModule() and
  50. * returns the module's global object.
  51. */
  52. [noscript] JSObjectPtr importInto(in AUTF8String aResourceURI,
  53. in JSObjectPtr targetObj,
  54. in nsAXPCNativeCallContextPtr cc);
  55. /**
  56. * Unloads the JS module at aResourceURI. Existing references to the module
  57. * will continue to work but any subsequent import of the module will
  58. * reload it and give new reference. If the JS module hasn't yet been imported
  59. * then this method will do nothing.
  60. */
  61. void unload(in AUTF8String aResourceURI);
  62. /**
  63. * Returns true if the js file located at 'registryLocation' location has
  64. * been loaded previously via the import method above. Returns false
  65. * otherwise.
  66. *
  67. * @param resourceURI A resource:// URI string representing the location of
  68. * the js file to be checked if it is already loaded or not.
  69. * @returns boolean, true if the js file has been loaded via import. false
  70. * otherwise
  71. */
  72. boolean isModuleLoaded(in AUTF8String aResourceURI);
  73. };