Add explicit rooting API to ctypes

NEW
Unassigned

Status

()

6 years ago
a year ago

People

(Reporter: benjamin, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
ctypes clients want to do this:

callCFunction(arg, function() {
  ... callback
});

This is obviously rooting-unsafe if the function is asynchronous. But unfortunately the alternatives are often pretty gross. In particular, you'd need to save the callback in something accessible from a global variable.

I'd like to propose that we add an explicit rooting API to ctypes to make this case easier:

var cb = function() {
  ... callback
  ctypes.unroot(cb);
};
ctypes.root(cb);
callCFunction(arg, cb);

You could even add some JS decoration (assuming the callback is once-only).
You need to log in before you can comment on or make changes to this bug.