Closed Bug 1611933 Opened 4 years ago Closed 4 years ago

Consider supporting [infallible] on XPCOM methods

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
82 Branch
Tracking Status
firefox82 --- fixed

People

(Reporter: nika, Assigned: emilio)

Details

Attachments

(1 file, 1 obsolete file)

The [infallible] method is currently supported on xpidl attributes, and causes a non-virtual overload which directly returns the value. It is only supported for builtinclass types, due to JS always being fallible.

It may be nice to also support this attribute on xpidl methods.

To be clear, we'd just return the return value directly, rather than through an outparam?

Yes. Nika and I were thinking of effectively desugaring something like this:

  [infallible] returnType method(args);

into:

  // For C++ callers
  [notxpcom,nostdcall,binaryName="Method"] returnType binaryMethod(args);
  // For JS callers
  [binaryName="ScriptableMethod"] returnType method(args);

where the latter can be skipped if the interface or method is noscript. Not literally desugaring, since we'd need to implement at least part of this in the code generator; see below.

If the latter is not skipped, the codegen would spit out something like this for it in the interface's .h file:

  NS_IMETHOD ScriptableMethod(args, returnType* aOut) final {
    *aOut = BinaryMethod(args);
    return NS_OK;
  }

Modulo complications here around what happens if the returnType leads to a reference param, not a pointer, of course.

I've wanted to use this recently for a couple things. This uses the
same scheme and even templates we use for attributes, so it's mostly
moving code around...

Inverting the code generation so that the implementation is infallible,
and we actually generate the NS_IMETHOD goop inline somehow could be
potentially desirable, though that causes an extra virtual call for
non-C++ callers I guess, so maybe it's not such a great trade-off. Plus
it seems more complicated...

Explicitly forbid mixing infallible with notxpcom (as it doesn't make
sense), and similarly forbid infallible + returning void (as C++ doesn't
allow us to overload a function that differs only on its return type).

Assignee: nobody → emilio
Status: NEW → ASSIGNED
Attachment #9176186 - Attachment is obsolete: true
Pushed by ealvarez@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/f0615307a2f9
Support infallible xpcom methods, and use it for nsIURI.schemeIs. r=nika,xpcom-reviewers
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 82 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: