Commit Graph

1 Commits

Author SHA1 Message Date
Kris Maglione
3e8d266e8a Bug 1513366: Part 1 - Add do_ImportModule helper for importing JS modules. r=mccr8
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));

Differential Revision: https://phabricator.services.mozilla.com/D14209

--HG--
extra : rebase_source : 4d518205b173fc210908235b42ddace590e6b7e5
2018-12-11 13:28:20 -08:00