Bug 892203 - Minor cleanups in sandbox.cpp. r=bholley

This commit is contained in:
Gabor Krizsanits 2013-09-04 12:15:50 +02:00
parent 6ef4bd043b
commit 398aaa2927
2 changed files with 29 additions and 31 deletions

View File

@ -960,14 +960,14 @@ xpc::CreateSandboxObject(JSContext *cx, jsval *vp, nsISupports *prinOrSop, Sandb
// Pass on ownership of sbp to |sandbox|. // Pass on ownership of sbp to |sandbox|.
JS_SetPrivate(sandbox, sbp.forget().get()); JS_SetPrivate(sandbox, sbp.forget().get());
bool allowComponents = nsContentUtils::IsSystemPrincipal(principal) || bool allowComponents = nsContentUtils::IsSystemPrincipal(principal) ||
nsContentUtils::IsExpandedPrincipal(principal); nsContentUtils::IsExpandedPrincipal(principal);
if (options.wantComponents && allowComponents && if (options.wantComponents && allowComponents &&
!nsXPCComponents::AttachComponentsObject(cx, GetObjectScope(sandbox))) !nsXPCComponents::AttachComponentsObject(cx, GetObjectScope(sandbox)))
return NS_ERROR_XPC_UNEXPECTED; return NS_ERROR_XPC_UNEXPECTED;
if (!XPCNativeWrapper::AttachNewConstructorObject(cx, sandbox)) if (!XPCNativeWrapper::AttachNewConstructorObject(cx, sandbox))
return NS_ERROR_XPC_UNEXPECTED; return NS_ERROR_XPC_UNEXPECTED;
if (!JS_DefineFunctions(cx, sandbox, SandboxFunctions)) if (!JS_DefineFunctions(cx, sandbox, SandboxFunctions))
return NS_ERROR_XPC_UNEXPECTED; return NS_ERROR_XPC_UNEXPECTED;
@ -1037,7 +1037,7 @@ nsXPCComponents_utils_Sandbox::Construct(nsIXPConnectWrappedNative *wrapper, JSC
* For sandbox constructor the first argument can be a URI string in which case * For sandbox constructor the first argument can be a URI string in which case
* we use the related Codebase Principal for the sandbox. * we use the related Codebase Principal for the sandbox.
*/ */
nsresult static nsresult
GetPrincipalFromString(JSContext *cx, HandleString codebase, nsIPrincipal **principal) GetPrincipalFromString(JSContext *cx, HandleString codebase, nsIPrincipal **principal)
{ {
MOZ_ASSERT(principal); MOZ_ASSERT(principal);
@ -1063,10 +1063,10 @@ GetPrincipalFromString(JSContext *cx, HandleString codebase, nsIPrincipal **prin
} }
/* /*
* For sandbox constructor the first argument can be a principal object or * For sandbox constructor the first argument can be a principal object or
* a script object principal (Document, Window). * a script object principal (Document, Window).
*/ */
nsresult static nsresult
GetPrincipalOrSOP(JSContext *cx, HandleObject from, nsISupports **out) GetPrincipalOrSOP(JSContext *cx, HandleObject from, nsISupports **out)
{ {
MOZ_ASSERT(out); MOZ_ASSERT(out);
@ -1095,7 +1095,7 @@ GetPrincipalOrSOP(JSContext *cx, HandleObject from, nsISupports **out)
* The first parameter of the sandbox constructor might be an array of principals, either in string * The first parameter of the sandbox constructor might be an array of principals, either in string
* format or actual objects (see GetPrincipalOrSOP) * format or actual objects (see GetPrincipalOrSOP)
*/ */
nsresult static nsresult
GetExpandedPrincipal(JSContext *cx, HandleObject arrayObj, nsIExpandedPrincipal **out) GetExpandedPrincipal(JSContext *cx, HandleObject arrayObj, nsIExpandedPrincipal **out)
{ {
MOZ_ASSERT(out); MOZ_ASSERT(out);
@ -1159,38 +1159,39 @@ GetExpandedPrincipal(JSContext *cx, HandleObject arrayObj, nsIExpandedPrincipal
/* /*
* Helper that tries to get a property form the options object. * Helper that tries to get a property form the options object.
*/ */
nsresult static nsresult
GetPropFromOptions(JSContext *cx, HandleObject from, const char *name, MutableHandleValue prop, GetPropFromOptions(JSContext *cx, HandleObject from, const char *name, MutableHandleValue prop,
bool *found) bool *found)
{ {
if (!JS_HasProperty(cx, from, name, found)) MOZ_ASSERT(found);
return NS_ERROR_INVALID_ARG; bool ok = JS_HasProperty(cx, from, name, found);
NS_ENSURE_TRUE(ok, NS_ERROR_INVALID_ARG);
if (*found && !JS_GetProperty(cx, from, name, prop)) if (!*found)
return NS_ERROR_INVALID_ARG; return NS_OK;
ok = JS_GetProperty(cx, from, name, prop);
NS_ENSURE_TRUE(ok, NS_ERROR_INVALID_ARG);
return NS_OK; return NS_OK;
} }
/* /*
* Helper that tries to get a boolean property form the options object. * Helper that tries to get a boolean property form the options object.
*/ */
nsresult static nsresult
GetBoolPropFromOptions(JSContext *cx, HandleObject from, const char *name, bool *prop) GetBoolPropFromOptions(JSContext *cx, HandleObject from, const char *name, bool *prop)
{ {
MOZ_ASSERT(prop); MOZ_ASSERT(prop);
RootedValue value(cx); RootedValue value(cx);
bool found; bool found;
if (NS_FAILED(GetPropFromOptions(cx, from, name, &value, &found))) nsresult rv = GetPropFromOptions(cx, from, name, &value, &found);
return NS_ERROR_INVALID_ARG; NS_ENSURE_SUCCESS(rv, rv);
if (!found) if (!found)
return NS_OK; return NS_OK;
if (!value.isBoolean()) NS_ENSURE_TRUE(value.isBoolean(), NS_ERROR_INVALID_ARG);
return NS_ERROR_INVALID_ARG;
*prop = value.toBoolean(); *prop = value.toBoolean();
return NS_OK; return NS_OK;
@ -1199,24 +1200,22 @@ GetBoolPropFromOptions(JSContext *cx, HandleObject from, const char *name, bool
/* /*
* Helper that tries to get an object property form the options object. * Helper that tries to get an object property form the options object.
*/ */
nsresult static nsresult
GetObjPropFromOptions(JSContext *cx, HandleObject from, const char *name, JSObject **prop) GetObjPropFromOptions(JSContext *cx, HandleObject from, const char *name, JSObject **prop)
{ {
MOZ_ASSERT(prop); MOZ_ASSERT(prop);
RootedValue value(cx); RootedValue value(cx);
bool found; bool found;
if (NS_FAILED(GetPropFromOptions(cx, from, name, &value, &found))) nsresult rv = GetPropFromOptions(cx, from, name, &value, &found);
return NS_ERROR_INVALID_ARG; NS_ENSURE_SUCCESS(rv, rv);
if (!found) { if (!found) {
*prop = NULL; *prop = NULL;
return NS_OK; return NS_OK;
} }
if (!value.isObject()) NS_ENSURE_TRUE(value.isObject(), NS_ERROR_INVALID_ARG);
return NS_ERROR_INVALID_ARG;
*prop = &value.toObject(); *prop = &value.toObject();
return NS_OK; return NS_OK;
} }
@ -1224,7 +1223,7 @@ GetObjPropFromOptions(JSContext *cx, HandleObject from, const char *name, JSObje
/* /*
* Helper that tries to get a string property form the options object. * Helper that tries to get a string property form the options object.
*/ */
nsresult static nsresult
GetStringPropFromOptions(JSContext *cx, HandleObject from, const char *name, nsCString &prop) GetStringPropFromOptions(JSContext *cx, HandleObject from, const char *name, nsCString &prop)
{ {
RootedValue value(cx); RootedValue value(cx);
@ -1246,7 +1245,7 @@ GetStringPropFromOptions(JSContext *cx, HandleObject from, const char *name, nsC
/* /*
* Helper that parsing the sandbox options object (from) and sets the fields of the incoming options struct (options). * Helper that parsing the sandbox options object (from) and sets the fields of the incoming options struct (options).
*/ */
nsresult static nsresult
ParseOptionsObject(JSContext *cx, jsval from, SandboxOptions &options) ParseOptionsObject(JSContext *cx, jsval from, SandboxOptions &options)
{ {
NS_ENSURE_TRUE(from.isObject(), NS_ERROR_INVALID_ARG); NS_ENSURE_TRUE(from.isObject(), NS_ERROR_INVALID_ARG);

View File

@ -242,7 +242,6 @@ XPCWrappedNativeScope::EnsureXBLScope(JSContext *cx)
SandboxOptions options(cx); SandboxOptions options(cx);
options.wantXrays = true; options.wantXrays = true;
options.wantComponents = true; options.wantComponents = true;
options.wantXHRConstructor = false;
options.proto = global; options.proto = global;
options.sameZoneAs = global; options.sameZoneAs = global;