Closed Bug 1513366 Opened 5 years ago Closed 5 years ago

Add C++ helper for importing a JS module and wrapping in an XPIDL interface.

Categories

(Core :: XPConnect, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla66
Tracking Status
firefox66 --- fixed

People

(Reporter: kmag, Assigned: kmag)

Details

Attachments

(6 files)

This should allow us to simply define XPIDL interfaces for the symbols exported from a JSM and then import those modules directly, rather than go through all of the mess and overhead of registering them as components.
This helper makes 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));
This makes the code much simpler, and also likely much more efficient, since
it does not involve creating a sandbox, and the resulting copies and
cross-compartment-wrapper overhead.
Priority: -- → P2
This simplifies things all around, and gets rid of one more unnecessary
component registration.
It makes things much simpler.

Differential Revision: https://phabricator.services.mozilla.com/D14210
Attachment #9031577 - Flags: review?(erahm)
Pushed by richard.marti@gmail.com:
https://hg.mozilla.org/comm-central/rev/03ca21bafc5f
Port bug 1513366 - remove extension-process-script.js from package manifest. rs=bustage-fix DONTBUILD
Attachment #9031577 - Flags: review?(erahm)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: