Open Bug 1070222 Opened 10 years ago Updated 2 years ago

Investigate if we could statically check "correct" compartment usage

Categories

(Core :: JavaScript Engine, defect)

34 Branch
x86_64
Linux
defect

Tracking

()

People

(Reporter: smaug, Unassigned)

Details

Compartment usage is close to black magic, and it is _very_ easy to get
compartment mismatches. We have been getting better, but mismatches do still happen.
Either we need to change JSAPI so that one _must_ think about the right
compartment whenever touching any JS stuff, or, if possible, some static checking to
at least prevent common compartment mismatches.
Interesting - any concrete suggestions?
(Note that things are getting better with AutoJSAPI and friends, since they automatically enter the correct initial compartment).
One thing that would be worth doing would be to rename AutoSafeJSContext to DeprecatedAutoSafeJSContext and forbid adding new instances to the tree.
AutoJSAPI doesn't exactly force one to use itself.

I guess all the JSAPI-y things should take a pointer to a compartment or so to force developer to think about compartments. But that might affect to performance.

Even better would be if it was somehow possible to automatically enter the right compartment,
but I don't see how that could be doable.
(In reply to Olli Pettay [:smaug] from comment #4)
> I guess all the JSAPI-y things should take a pointer to a compartment or so
> to force developer to think about compartments. But that might affect to
> performance.

This would be annoying for writing code,
but the main issue with compartments is that they are something which
happen mostly hidden in the background. And given that they are so crucial for many things, they
really shouldn't be hidden.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.