Open Bug 873152 Opened 11 years ago Updated 2 years ago

Add explicit rooting API to ctypes

Categories

(Core :: js-ctypes, defect)

x86_64
Linux
defect

Tracking

()

People

(Reporter: benjamin, Unassigned)

References

(Blocks 1 open bug)

Details

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).
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.