Bug 824864 - Fix Ms2ger nits. r=me

This commit is contained in:
Bobby Holley 2013-01-16 18:50:27 -08:00
parent fe9b482b3b
commit 7a0d54fa07
4 changed files with 13 additions and 11 deletions

View File

@ -861,8 +861,9 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
JS::CompileOptions options(context->GetNativeContext()); JS::CompileOptions options(context->GetNativeContext());
options.setFileAndLine(url.get(), aRequest->mLineNo) options.setFileAndLine(url.get(), aRequest->mLineNo)
.setVersion(JSVersion(aRequest->mJSVersion)); .setVersion(JSVersion(aRequest->mJSVersion));
if (aRequest->mOriginPrincipal) if (aRequest->mOriginPrincipal) {
options.setOriginPrincipals(nsJSPrincipals::get(aRequest->mOriginPrincipal)); options.setOriginPrincipals(nsJSPrincipals::get(aRequest->mOriginPrincipal));
}
JS::Value ignored; JS::Value ignored;
rv = context->EvaluateString(aScript, *globalObject->GetGlobalJSObject(), rv = context->EvaluateString(aScript, *globalObject->GetGlobalJSObject(),
options, /* aCoerceToString = */ false, &ignored); options, /* aCoerceToString = */ false, &ignored);

View File

@ -1273,10 +1273,10 @@ nsJSContext::EvaluateString(const nsAString& aScript,
ok = JS::Evaluate(mContext, rootedScope, aOptions, ok = JS::Evaluate(mContext, rootedScope, aOptions,
PromiseFlatString(aScript).get(), PromiseFlatString(aScript).get(),
aScript.Length(), aRetValue); aScript.Length(), aRetValue);
if (ok && !JSVAL_IS_VOID(*aRetValue) && aCoerceToString) { if (ok && !aRetValue->isUndefined() && aCoerceToString) {
JSString* str = JS_ValueToString(mContext, *aRetValue); JSString* str = JS_ValueToString(mContext, *aRetValue);
ok = !!str; ok = !!str;
*aRetValue = ok ? JS::StringValue(str) : JSVAL_VOID; *aRetValue = ok ? JS::StringValue(str) : JS::UndefinedValue();
} }
--mExecuteDepth; --mExecuteDepth;
} }
@ -1395,13 +1395,15 @@ nsJSContext::ExecuteScript(JSScript* aScriptObject,
// not be a GC root currently, provided we run the GC only from the // not be a GC root currently, provided we run the GC only from the
// operation callback or from ScriptEvaluated. // operation callback or from ScriptEvaluated.
jsval val; jsval val;
if (!JS_ExecuteScript(mContext, aScopeObject, aScriptObject, &val)) if (!JS_ExecuteScript(mContext, aScopeObject, aScriptObject, &val)) {
ReportPendingException(); ReportPendingException();
}
--mExecuteDepth; --mExecuteDepth;
// Pop here, after JS_ValueToString and any other possible evaluation. // Pop here, after JS_ValueToString and any other possible evaluation.
if (NS_FAILED(stack->Pop(nullptr))) if (NS_FAILED(stack->Pop(nullptr))) {
rv = NS_ERROR_FAILURE; rv = NS_ERROR_FAILURE;
}
// ScriptEvaluated needs to come after we pop the stack // ScriptEvaluated needs to come after we pop the stack
ScriptEvaluated(true); ScriptEvaluated(true);

View File

@ -159,13 +159,13 @@ nsJSUtils::CompileFunction(JSContext* aCx,
JSObject** aFunctionObject) JSObject** aFunctionObject)
{ {
MOZ_ASSERT(js::GetEnterCompartmentDepth(aCx) > 0); MOZ_ASSERT(js::GetEnterCompartmentDepth(aCx) > 0);
MOZ_ASSERT(!aTarget || js::IsObjectInContextCompartment(aTarget, aCx)); MOZ_ASSERT_IF(aTarget, js::IsObjectInContextCompartment(aTarget, aCx));
MOZ_ASSERT_IF(aOptions.versionSet, aOptions.version != JSVERSION_UNKNOWN); MOZ_ASSERT_IF(aOptions.versionSet, aOptions.version != JSVERSION_UNKNOWN);
// Since aTarget and aCx are same-compartment, there should be no distinction // Since aTarget and aCx are same-compartment, there should be no distinction
// between the object principal and the cx principal. // between the object principal and the cx principal.
// However, aTarget may be null in the wacky aShared case. So use the cx. // However, aTarget may be null in the wacky aShared case. So use the cx.
JSPrincipals *p = JS_GetCompartmentPrincipals(js::GetContextCompartment(aCx)); JSPrincipals* p = JS_GetCompartmentPrincipals(js::GetContextCompartment(aCx));
aOptions.setPrincipals(p); aOptions.setPrincipals(p);
// Do the junk Gecko is supposed to do before calling into JSAPI. // Do the junk Gecko is supposed to do before calling into JSAPI.
@ -177,8 +177,7 @@ nsJSUtils::CompileFunction(JSContext* aCx,
aArgCount, aArgArray, aArgCount, aArgArray,
PromiseFlatString(aBody).get(), PromiseFlatString(aBody).get(),
aBody.Length()); aBody.Length());
if (!fun) NS_ENSURE_TRUE(fun, NS_ERROR_FAILURE);
return NS_ERROR_FAILURE;
*aFunctionObject = JS_GetFunctionObject(fun); *aFunctionObject = JS_GetFunctionObject(fun);
return NS_OK; return NS_OK;

View File

@ -255,7 +255,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
useSandbox = !subsumes; useSandbox = !subsumes;
} }
JS::Value v = JSVAL_VOID; JS::Value v = JS::UndefinedValue();
// Finally, we have everything needed to evaluate the expression. // Finally, we have everything needed to evaluate the expression.
JSContext *cx = scriptContext->GetNativeContext(); JSContext *cx = scriptContext->GetNativeContext();
@ -348,7 +348,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
} }
else { else {
nsDependentJSString result; nsDependentJSString result;
if (!result.init(cx, JSVAL_TO_STRING(v))) { if (!result.init(cx, v)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }