Open Bug 878849 Opened 11 years ago Updated 2 years ago

Add a JSAutoCompartment overload using Value

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect

Tracking

()

People

(Reporter: bzbarsky, Unassigned)

References

Details

Right now, if I have a Value and a JSContext whose compartment may not match that of Value and I want to make sure the JSContext is in the Value's compartment I have to do games like this:

  Maybe<JSAutoCompartment> ac;
  if (val.isObject()) {
    JS::Rooted<JSObject*> rooted(cx, &val.toObject());
    ac.construct(cx, rooted);
  }

and while _I_ know how to do this (though I almost forgot the Rooted!), most people do not and should not need to.

In a sane world (insofar as one can be had with compartments), the above would look like this:

  JSAutoCompartment ac(cx, val);
So this is blocking futures work, afaict.  We have a JSContext and a Value and we need to make sure they're safe to use together.  But the JS engine will assert if the Value is a string that's not in the right zone... and there is no way to enter the right zone.

Note that this also means the code in comment 0 is wrong.

Further note that there are already instances of code like comment 0 in the tree....
Blocks: promises
Assignee: general → nobody
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.