From this thread, it sounds like one problem is that the JSAPI is
requiring users to deal with weird things called "compartments" that
are absolutely meaningless to the calling code. It's JSContexts all
over again. "Why are they needed? What are they for? Can't the engine
just figure it out?" All good questions.
Accordingly, a quick-fix would be to "rename" JSAutoCompartment to
something like xpconnect::AutoSecurityContextOf or something. It
doesn't help people like smaug or bz, but at least reading the code
makes more sense when it refers to a concept that actually means
something to Gecko.
Then, would it help to add a ::enter() or ::switch() member that
changes compartment again, but still restores the (original) original
compartment on destruction? Or, if nested scopes are really needed, it
could be ::push() and ::pop(), which would do the same thing as nested
RAII guards would.
In skimming some relevant compartment-using code in dom/base, the most
confusing part to me is the wrapping. In the (few) examples I looked
at, I'd prefer to eliminate JS_WrapObject(cx, &obj) and friends, and
instead require explicitly specifying the destination compartment. It
could either assert if you're not within the appropriate compartment
already, or enter it for you if we're ok with the runtime check. Right
now, when you see JS_Wrap*() you have to read backwards to figure out
what compartment you're wrapping into.
On the other hand, that means making a wrapping API that takes two
objects, and uses one of them for its compartment. It'll be confusing
to figure out which is which. I suppose we could make it even more
verbose:
JS_WrapObject(cx, &obj2, JS::CompartmentOf(obj1)); // or is that
JS::SecurityContextOf?
Can someone point to a good example of code where the JSAPI is a
nuisance with respect to compartments? It would help to have a concrete
example to beat on.
_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals