diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
commit | fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch) | |
tree | 4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /js/xpconnect/loader/nsImportModule.h | |
parent | Releasing progress-linux version 124.0.1-1~progress7.99u1. (diff) | |
download | firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect/loader/nsImportModule.h')
-rw-r--r-- | js/xpconnect/loader/nsImportModule.h | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/js/xpconnect/loader/nsImportModule.h b/js/xpconnect/loader/nsImportModule.h index 31f6f8c7c1..16a5c40a88 100644 --- a/js/xpconnect/loader/nsImportModule.h +++ b/js/xpconnect/loader/nsImportModule.h @@ -16,124 +16,12 @@ namespace mozilla { namespace loader { -nsresult ImportModule(const char* aURI, const char* aExportName, - const nsIID& aIID, void** aResult, bool aInfallible); - nsresult ImportESModule(const char* aURI, const char* aExportName, const nsIID& aIID, void** aResult, bool aInfallible); } // namespace loader } // namespace mozilla -class MOZ_STACK_CLASS nsImportModule final : public nsCOMPtr_helper { - public: - nsImportModule(const char* aURI, const char* aExportName, nsresult* aErrorPtr, - bool aInfallible) - : mURI(aURI), - mExportName(aExportName), - mErrorPtr(aErrorPtr), - mInfallible(aInfallible) { - MOZ_ASSERT_IF(mErrorPtr, !mInfallible); - } - - virtual nsresult NS_FASTCALL operator()(const nsIID& aIID, - void** aResult) const override { - nsresult rv = ::mozilla::loader::ImportModule(mURI, mExportName, aIID, - aResult, mInfallible); - if (mErrorPtr) { - *mErrorPtr = rv; - } - return rv; - } - - private: - const char* mURI; - const char* mExportName; - nsresult* mErrorPtr; - bool mInfallible; -}; - -/** - * These helpers make it considerably easier for C++ code to import a JS module - * and wrap it in an appropriately-defined XPIDL interface for its exports. - * Typical usage is something like: - * - * Foo.jsm: - * - * var EXPORTED_SYMBOLS = ["foo"]; - * - * function foo(bar) { - * return bar.toString(); - * } - * - * mozIFoo.idl: - * - * interface mozIFoo : nsISupports { - * AString foo(double meh); - * } - * - * Thing.cpp: - * - * nsCOMPtr<mozIFoo> foo = do_ImportModule( - * "resource://meh/Foo.jsm"); - * - * MOZ_TRY(foo->Foo(42)); - * - * For JS modules which export all fields within a single named object, a second - * argument can be passed naming that object. - * - * Foo.jsm: - * - * var EXPORTED_SYMBOLS = ["Foo"]; - * - * var Foo = { - * function foo(bar) { - * return bar.toString(); - * } - * }; - * - * Thing.cpp: - * - * nsCOMPtr<mozIFoo> foo = do_ImportModule( - * "resource:://meh/Foo.jsm", "Foo"); - */ - -template <size_t N> -inline nsImportModule do_ImportModule(const char (&aURI)[N]) { - return {aURI, nullptr, nullptr, /* infallible */ true}; -} - -template <size_t N> -inline nsImportModule do_ImportModule(const char (&aURI)[N], - const mozilla::fallible_t&) { - return {aURI, nullptr, nullptr, /* infallible */ false}; -} - -template <size_t N> -inline nsImportModule do_ImportModule(const char (&aURI)[N], nsresult* aRv) { - return {aURI, nullptr, aRv, /* infallible */ false}; -} - -template <size_t N, size_t N2> -inline nsImportModule do_ImportModule(const char (&aURI)[N], - const char (&aExportName)[N2]) { - return {aURI, aExportName, nullptr, /* infallible */ true}; -} - -template <size_t N, size_t N2> -inline nsImportModule do_ImportModule(const char (&aURI)[N], - const char (&aExportName)[N2], - const mozilla::fallible_t&) { - return {aURI, aExportName, nullptr, /* infallible */ false}; -} - -template <size_t N, size_t N2> -inline nsImportModule do_ImportModule(const char (&aURI)[N], - const char (&aExportName)[N2], - nsresult* aRv) { - return {aURI, aExportName, aRv, /* infallible */ false}; -} - class MOZ_STACK_CLASS nsImportESModule final : public nsCOMPtr_helper { public: nsImportESModule(const char* aURI, const char* aExportName, |