Bug 885388 - Alter the newGlobal API in the shell to take an extensible options object. r=jimb

Originally, this thing took a string ('same-compartment' or 'new-compartment'),
which became unused with CPG, though is still passed by a number of tests. Then
it looks like billm made it take an object in bug 852228, for sameZoneAs, but
bugzilla and grep indicate that it never got used. Let's switch it to something
extensible, though we should also make sure to let Jesse, decoder, gwk, and any
other fuzzing folk know about it.
This commit is contained in:
Bobby Holley 2013-08-01 18:38:45 -07:00
parent e964ea9e66
commit 8996645ea6

View File

@ -3544,16 +3544,26 @@ Deserialize(JSContext *cx, unsigned argc, jsval *vp)
}
static JSObject *
NewGlobalObject(JSContext *cx, JSObject *sameZoneAs);
NewGlobalObject(JSContext *cx, JS::CompartmentOptions &options);
static JSBool
NewGlobal(JSContext *cx, unsigned argc, jsval *vp)
{
JSObject *sameZoneAs = NULL;
if (argc == 1 && JS_ARGV(cx, vp)[0].isObject())
sameZoneAs = UncheckedUnwrap(&JS_ARGV(cx, vp)[0].toObject());
JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST);
RootedObject global(cx, NewGlobalObject(cx, sameZoneAs));
CallArgs args = CallArgsFromVp(argc, vp);
if (argc == 1 && args[0].isObject()) {
RootedObject opts(cx, &args[0].toObject());
RootedValue v(cx);
if (!JS_GetProperty(cx, opts, "sameZoneAs", &v))
return false;
if (v.isObject())
options.zoneSpec = JS::SameZoneAs(UncheckedUnwrap(&v.toObject()));
}
RootedObject global(cx, NewGlobalObject(cx, options));
if (!global)
return false;
@ -3901,9 +3911,10 @@ static const JSFunctionSpecWithHelp shell_functions[] = {
" Deserialize data generated by serialize."),
JS_FN_HELP("newGlobal", NewGlobal, 1, 0,
"newGlobal([obj])",
" Return a new global object in a new compartment. If obj\n"
" is given, the compartment will be in the same zone as obj."),
"newGlobal([options])",
" Return a new global object in a new compartment. If options\n"
" is given, it may have any of the following properties:\n"
" sameZoneAs: the compartment will be in the same zone as the given object (defaults to a new zone)"),
JS_FN_HELP("enableStackWalkingAssertion", EnableStackWalkingAssertion, 1, 0,
"enableStackWalkingAssertion(enabled)",
@ -4865,11 +4876,8 @@ DestroyContext(JSContext *cx, bool withGC)
}
static JSObject *
NewGlobalObject(JSContext *cx, JSObject *sameZoneAs)
NewGlobalObject(JSContext *cx, JS::CompartmentOptions &options)
{
JS::CompartmentOptions options;
options.setZone(sameZoneAs ? JS::SameZoneAs(sameZoneAs) : JS::FreshZone)
.setVersion(JSVERSION_LATEST);
RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, NULL, options));
if (!glob)
return NULL;
@ -5205,7 +5213,9 @@ Shell(JSContext *cx, OptionParser *op, char **envp)
fuzzingSafe = true;
RootedObject glob(cx);
glob = NewGlobalObject(cx, NULL);
JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST);
glob = NewGlobalObject(cx, options);
if (!glob)
return 1;