mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1490600 - Always use braces for if/for/while statements in js/xpconnect/src, part 4. r=kmag
Depends on D5654 Differential Revision: https://phabricator.services.mozilla.com/D5655 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
d1f407756a
commit
d51d2cab4b
@ -46,10 +46,11 @@ ToStringGuts(XPCCallContext& ccx)
|
||||
UniqueChars sz;
|
||||
XPCWrappedNative* wrapper = ccx.GetWrapper();
|
||||
|
||||
if (wrapper)
|
||||
if (wrapper) {
|
||||
sz.reset(wrapper->ToString(ccx.GetTearOff()));
|
||||
else
|
||||
} else {
|
||||
sz = JS_smprintf("[xpconnect wrapped native prototype]");
|
||||
}
|
||||
|
||||
if (!sz) {
|
||||
JS_ReportOutOfMemory(ccx);
|
||||
@ -57,8 +58,9 @@ ToStringGuts(XPCCallContext& ccx)
|
||||
}
|
||||
|
||||
JSString* str = JS_NewStringCopyZ(ccx, sz.get());
|
||||
if (!str)
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ccx.SetRetVal(JS::StringValue(str));
|
||||
return true;
|
||||
@ -72,12 +74,14 @@ XPC_WN_Shared_ToString(JSContext* cx, unsigned argc, Value* vp)
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
RootedObject obj(cx);
|
||||
if (!args.computeThis(cx, &obj))
|
||||
if (!args.computeThis(cx, &obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
XPCCallContext ccx(cx, obj);
|
||||
if (!ccx.IsValid())
|
||||
if (!ccx.IsValid()) {
|
||||
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
|
||||
}
|
||||
ccx.SetName(ccx.GetContext()->GetStringID(XPCJSContext::IDX_TO_STRING));
|
||||
ccx.SetArgsAndResultPtr(args.length(), args.array(), vp);
|
||||
return ToStringGuts(ccx);
|
||||
@ -89,8 +93,9 @@ XPC_WN_Shared_ToSource(JSContext* cx, unsigned argc, Value* vp)
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
static const char empty[] = "({})";
|
||||
JSString* str = JS_NewStringCopyN(cx, empty, sizeof(empty)-1);
|
||||
if (!str)
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
args.rval().setString(str);
|
||||
|
||||
return true;
|
||||
@ -102,15 +107,17 @@ XPC_WN_Shared_toPrimitive(JSContext* cx, unsigned argc, Value* vp)
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
RootedObject obj(cx);
|
||||
if (!JS_ValueToObject(cx, args.thisv(), &obj))
|
||||
if (!JS_ValueToObject(cx, args.thisv(), &obj)) {
|
||||
return false;
|
||||
}
|
||||
XPCCallContext ccx(cx, obj);
|
||||
XPCWrappedNative* wrapper = ccx.GetWrapper();
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
|
||||
|
||||
JSType hint;
|
||||
if (!GetFirstArgumentAsTypeHint(cx, args, &hint))
|
||||
if (!GetFirstArgumentAsTypeHint(cx, args, &hint)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hint == JSTYPE_NUMBER) {
|
||||
args.rval().set(JS_GetNaNValue(cx));
|
||||
@ -123,11 +130,13 @@ XPC_WN_Shared_toPrimitive(JSContext* cx, unsigned argc, Value* vp)
|
||||
|
||||
XPCNativeMember* member = ccx.GetMember();
|
||||
if (member && member->IsMethod()) {
|
||||
if (!XPCWrappedNative::CallMethod(ccx))
|
||||
if (!XPCWrappedNative::CallMethod(ccx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.rval().isPrimitive())
|
||||
if (args.rval().isPrimitive()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// else...
|
||||
@ -243,10 +252,11 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
propFlags |= JSPROP_RESOLVING;
|
||||
|
||||
if (set) {
|
||||
if (iface)
|
||||
if (iface) {
|
||||
found = true;
|
||||
else
|
||||
} else {
|
||||
found = set->FindMember(id, &member, &iface);
|
||||
}
|
||||
} else
|
||||
found = (nullptr != (member = iface->FindMember(id)));
|
||||
|
||||
@ -276,8 +286,9 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
}
|
||||
|
||||
AutoResolveName arn(ccx, id);
|
||||
if (resolved)
|
||||
if (resolved) {
|
||||
*resolved = true;
|
||||
}
|
||||
RootedObject value(ccx, JS_GetFunctionObject(fun));
|
||||
return JS_DefinePropertyById(ccx, obj, id, value,
|
||||
propFlags & ~JSPROP_ENUMERATE);
|
||||
@ -297,32 +308,38 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
|
||||
bool defineProperty = false;
|
||||
do {
|
||||
if (!JSID_IS_STRING(id))
|
||||
if (!JSID_IS_STRING(id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
name = JS_EncodeStringToLatin1(ccx, JSID_TO_STRING(id));
|
||||
if (!name)
|
||||
if (!name) {
|
||||
break;
|
||||
}
|
||||
|
||||
iface2 = XPCNativeInterface::GetNewOrUsed(name.get());
|
||||
if (!iface2)
|
||||
if (!iface2) {
|
||||
break;
|
||||
}
|
||||
|
||||
to = wrapperToReflectInterfaceNames->FindTearOff(iface2, true, &rv);
|
||||
if (!to)
|
||||
if (!to) {
|
||||
break;
|
||||
}
|
||||
|
||||
jso = to->GetJSObject();
|
||||
if (!jso)
|
||||
if (!jso) {
|
||||
break;
|
||||
}
|
||||
|
||||
defineProperty = true;
|
||||
} while (false);
|
||||
|
||||
if (defineProperty) {
|
||||
AutoResolveName arn(ccx, id);
|
||||
if (resolved)
|
||||
if (resolved) {
|
||||
*resolved = true;
|
||||
}
|
||||
return JS_DefinePropertyById(ccx, obj, id, jso,
|
||||
propFlags & ~JSPROP_ENUMERATE);
|
||||
} else if (NS_FAILED(rv) && rv != NS_ERROR_NO_INTERFACE) {
|
||||
@ -345,24 +362,28 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
fun = JS_NewFunction(ccx, XPC_WN_DoubleWrappedGetter,
|
||||
0, 0, name);
|
||||
|
||||
if (!fun)
|
||||
if (!fun) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject funobj(ccx, JS_GetFunctionObject(fun));
|
||||
if (!funobj)
|
||||
if (!funobj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
propFlags |= JSPROP_GETTER;
|
||||
propFlags &= ~JSPROP_ENUMERATE;
|
||||
|
||||
AutoResolveName arn(ccx, id);
|
||||
if (resolved)
|
||||
if (resolved) {
|
||||
*resolved = true;
|
||||
}
|
||||
return JS_DefinePropertyById(ccx, obj, id, funobj, nullptr, propFlags);
|
||||
}
|
||||
|
||||
if (resolved)
|
||||
if (resolved) {
|
||||
*resolved = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -371,28 +392,33 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
XPCWrappedNativeTearOff* to =
|
||||
wrapperToReflectInterfaceNames->FindTearOff(iface, true);
|
||||
|
||||
if (!to)
|
||||
if (!to) {
|
||||
return false;
|
||||
}
|
||||
RootedObject jso(ccx, to->GetJSObject());
|
||||
if (!jso)
|
||||
if (!jso) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoResolveName arn(ccx, id);
|
||||
if (resolved)
|
||||
if (resolved) {
|
||||
*resolved = true;
|
||||
}
|
||||
return JS_DefinePropertyById(ccx, obj, id, jso,
|
||||
propFlags & ~JSPROP_ENUMERATE);
|
||||
}
|
||||
if (resolved)
|
||||
if (resolved) {
|
||||
*resolved = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (member->IsConstant()) {
|
||||
RootedValue val(ccx);
|
||||
AutoResolveName arn(ccx, id);
|
||||
if (resolved)
|
||||
if (resolved) {
|
||||
*resolved = true;
|
||||
}
|
||||
return member->GetConstantValue(ccx, iface, val.address()) &&
|
||||
JS_DefinePropertyById(ccx, obj, id, val, propFlags);
|
||||
}
|
||||
@ -405,13 +431,15 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
propFlags &= ~JSPROP_ENUMERATE;
|
||||
|
||||
RootedValue funval(ccx);
|
||||
if (!member->NewFunctionObject(ccx, iface, obj, funval.address()))
|
||||
if (!member->NewFunctionObject(ccx, iface, obj, funval.address())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (member->IsMethod()) {
|
||||
AutoResolveName arn(ccx, id);
|
||||
if (resolved)
|
||||
if (resolved) {
|
||||
*resolved = true;
|
||||
}
|
||||
return JS_DefinePropertyById(ccx, obj, id, funval, propFlags);
|
||||
}
|
||||
|
||||
@ -429,8 +457,9 @@ DefinePropertyIfFound(XPCCallContext& ccx,
|
||||
}
|
||||
|
||||
AutoResolveName arn(ccx, id);
|
||||
if (resolved)
|
||||
if (resolved) {
|
||||
*resolved = true;
|
||||
}
|
||||
|
||||
return JS_DefinePropertyById(ccx, obj, id, funobjGetter, funobjSetter, propFlags);
|
||||
}
|
||||
@ -446,8 +475,9 @@ XPC_WN_OnlyIWrite_AddPropertyStub(JSContext* cx, HandleObject obj, HandleId id,
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
|
||||
|
||||
// Allow only XPConnect to add/set the property
|
||||
if (ccx.GetResolveName() == id)
|
||||
if (ccx.GetResolveName() == id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Throw(NS_ERROR_XPC_CANT_MODIFY_PROP_ON_WN, cx);
|
||||
}
|
||||
@ -475,8 +505,9 @@ XPC_WN_Shared_Enumerate(JSContext* cx, HandleObject obj)
|
||||
|
||||
// Since we aren't going to enumerate tearoff names and the prototype
|
||||
// handles non-mutated members, we can do this potential short-circuit.
|
||||
if (!wrapper->HasMutatedSet())
|
||||
if (!wrapper->HasMutatedSet()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
XPCNativeSet* set = wrapper->GetSet();
|
||||
XPCNativeSet* protoSet = wrapper->HasProto() ?
|
||||
@ -496,8 +527,9 @@ XPC_WN_Shared_Enumerate(JSContext* cx, HandleObject obj)
|
||||
if (protoSet &&
|
||||
protoSet->FindMember(name, nullptr, &index) && index == i)
|
||||
continue;
|
||||
if (!xpc_ForcePropertyResolve(cx, obj, name))
|
||||
if (!xpc_ForcePropertyResolve(cx, obj, name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -518,12 +550,14 @@ WrappedNativeFinalize(js::FreeOp* fop, JSObject* obj, WNHelperType helperType)
|
||||
mozilla::dom::DestroyProtoAndIfaceCache(obj);
|
||||
}
|
||||
nsISupports* p = static_cast<nsISupports*>(xpc_GetJSPrivate(obj));
|
||||
if (!p)
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
|
||||
XPCWrappedNative* wrapper = static_cast<XPCWrappedNative*>(p);
|
||||
if (helperType == WN_HELPER)
|
||||
if (helperType == WN_HELPER) {
|
||||
wrapper->GetScriptable()->Finalize(wrapper, js::CastToJSFreeOp(fop), obj);
|
||||
}
|
||||
wrapper->FlatJSObjectFinalized();
|
||||
}
|
||||
|
||||
@ -531,8 +565,9 @@ static size_t
|
||||
WrappedNativeObjectMoved(JSObject* obj, JSObject* old)
|
||||
{
|
||||
nsISupports* p = static_cast<nsISupports*>(xpc_GetJSPrivate(obj));
|
||||
if (!p)
|
||||
if (!p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
XPCWrappedNative* wrapper = static_cast<XPCWrappedNative*>(p);
|
||||
wrapper->FlatJSObjectMoved(obj, old);
|
||||
@ -563,8 +598,9 @@ XPCWrappedNative::Trace(JSTracer* trc, JSObject* obj)
|
||||
MOZ_ASSERT(IS_WN_CLASS(clazz));
|
||||
|
||||
XPCWrappedNative* wrapper = XPCWrappedNative::Get(obj);
|
||||
if (wrapper && wrapper->IsValid())
|
||||
if (wrapper && wrapper->IsValid()) {
|
||||
wrapper->TraceInside(trc);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -581,12 +617,14 @@ XPC_WN_NoHelper_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* reso
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
|
||||
|
||||
XPCNativeSet* set = ccx.GetSet();
|
||||
if (!set)
|
||||
if (!set) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Don't resolve properties that are on our prototype.
|
||||
if (ccx.GetInterface() && !ccx.GetStaticMemberIsLocal())
|
||||
if (ccx.GetInterface() && !ccx.GetStaticMemberIsLocal()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return DefinePropertyIfFound(ccx, obj, id,
|
||||
set, nullptr, nullptr, wrapper->GetScope(),
|
||||
@ -638,8 +676,9 @@ XPC_WN_MaybeResolvingPropertyStub(JSContext* cx, HandleObject obj, HandleId id,
|
||||
XPCWrappedNative* wrapper = ccx.GetWrapper();
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
|
||||
|
||||
if (ccx.GetResolvingWrapper() == wrapper)
|
||||
if (ccx.GetResolvingWrapper() == wrapper) {
|
||||
return true;
|
||||
}
|
||||
return Throw(NS_ERROR_XPC_CANT_MODIFY_PROP_ON_WN, cx);
|
||||
}
|
||||
|
||||
@ -687,8 +726,9 @@ XPC_WN_Helper_Call(JSContext* cx, unsigned argc, Value* vp)
|
||||
|
||||
XPCCallContext ccx(cx, obj, nullptr, JSID_VOIDHANDLE, args.length(),
|
||||
args.array(), args.rval().address());
|
||||
if (!ccx.IsValid())
|
||||
if (!ccx.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PRE_HELPER_STUB
|
||||
Call(wrapper, cx, obj, args, &retval);
|
||||
@ -700,13 +740,15 @@ XPC_WN_Helper_Construct(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
RootedObject obj(cx, &args.callee());
|
||||
if (!obj)
|
||||
if (!obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
XPCCallContext ccx(cx, obj, nullptr, JSID_VOIDHANDLE, args.length(),
|
||||
args.array(), args.rval().address());
|
||||
if (!ccx.IsValid())
|
||||
if (!ccx.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PRE_HELPER_STUB
|
||||
Construct(wrapper, cx, obj, args, &retval);
|
||||
@ -746,13 +788,15 @@ XPC_WN_Helper_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolv
|
||||
XPCWrappedNative* oldResolvingWrapper;
|
||||
bool allowPropMods = scr->AllowPropModsDuringResolve();
|
||||
|
||||
if (allowPropMods)
|
||||
if (allowPropMods) {
|
||||
oldResolvingWrapper = ccx.SetResolvingWrapper(wrapper);
|
||||
}
|
||||
|
||||
rv = scr->Resolve(wrapper, cx, obj, id, &resolved, &retval);
|
||||
|
||||
if (allowPropMods)
|
||||
if (allowPropMods) {
|
||||
(void)ccx.SetResolvingWrapper(oldResolvingWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
old = ccx.SetResolveName(old);
|
||||
@ -805,16 +849,19 @@ XPC_WN_Helper_Enumerate(JSContext* cx, HandleObject obj)
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
|
||||
|
||||
nsCOMPtr<nsIXPCScriptable> scr = wrapper->GetScriptable();
|
||||
if (!scr || !scr->WantEnumerate())
|
||||
if (!scr || !scr->WantEnumerate()) {
|
||||
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
|
||||
}
|
||||
|
||||
if (!XPC_WN_Shared_Enumerate(cx, obj))
|
||||
if (!XPC_WN_Shared_Enumerate(cx, obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool retval = true;
|
||||
nsresult rv = scr->Enumerate(wrapper, cx, obj, &retval);
|
||||
if (NS_FAILED(rv))
|
||||
if (NS_FAILED(rv)) {
|
||||
return Throw(rv, cx);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -829,16 +876,19 @@ XPC_WN_NewEnumerate(JSContext* cx, HandleObject obj, AutoIdVector& properties,
|
||||
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
|
||||
|
||||
nsCOMPtr<nsIXPCScriptable> scr = wrapper->GetScriptable();
|
||||
if (!scr || !scr->WantNewEnumerate())
|
||||
if (!scr || !scr->WantNewEnumerate()) {
|
||||
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
|
||||
}
|
||||
|
||||
if (!XPC_WN_Shared_Enumerate(cx, obj))
|
||||
if (!XPC_WN_Shared_Enumerate(cx, obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool retval = true;
|
||||
nsresult rv = scr->NewEnumerate(wrapper, cx, obj, properties, &retval);
|
||||
if (NS_FAILED(rv))
|
||||
if (NS_FAILED(rv)) {
|
||||
return Throw(rv, cx);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -893,8 +943,9 @@ XPC_WN_CallMethod(JSContext* cx, unsigned argc, Value* vp)
|
||||
RootedObject funobj(cx, &args.callee());
|
||||
|
||||
RootedObject obj(cx);
|
||||
if (!args.computeThis(cx, &obj))
|
||||
if (!args.computeThis(cx, &obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
obj = FixUpThisIfBroken(obj, funobj);
|
||||
XPCCallContext ccx(cx, obj, funobj, JSID_VOIDHANDLE, args.length(),
|
||||
@ -905,8 +956,9 @@ XPC_WN_CallMethod(JSContext* cx, unsigned argc, Value* vp)
|
||||
RefPtr<XPCNativeInterface> iface;
|
||||
XPCNativeMember* member;
|
||||
|
||||
if (!XPCNativeMember::GetCallInfo(funobj, &iface, &member))
|
||||
if (!XPCNativeMember::GetCallInfo(funobj, &iface, &member)) {
|
||||
return Throw(NS_ERROR_XPC_CANT_GET_METHOD_INFO, cx);
|
||||
}
|
||||
ccx.SetCallInfo(iface, member, false);
|
||||
return XPCWrappedNative::CallMethod(ccx);
|
||||
}
|
||||
@ -933,14 +985,16 @@ XPC_WN_GetterSetter(JSContext* cx, unsigned argc, Value* vp)
|
||||
RefPtr<XPCNativeInterface> iface;
|
||||
XPCNativeMember* member;
|
||||
|
||||
if (!XPCNativeMember::GetCallInfo(funobj, &iface, &member))
|
||||
if (!XPCNativeMember::GetCallInfo(funobj, &iface, &member)) {
|
||||
return Throw(NS_ERROR_XPC_CANT_GET_METHOD_INFO, cx);
|
||||
}
|
||||
|
||||
if (args.length() != 0 && member->IsWritableAttribute()) {
|
||||
ccx.SetCallInfo(iface, member, true);
|
||||
bool retval = XPCWrappedNative::SetAttribute(ccx);
|
||||
if (retval)
|
||||
if (retval) {
|
||||
args.rval().set(args[0]);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
// else...
|
||||
@ -958,16 +1012,19 @@ XPC_WN_Proto_Enumerate(JSContext* cx, HandleObject obj)
|
||||
"bad proto");
|
||||
XPCWrappedNativeProto* self =
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if (!self)
|
||||
if (!self) {
|
||||
return false;
|
||||
}
|
||||
|
||||
XPCNativeSet* set = self->GetSet();
|
||||
if (!set)
|
||||
if (!set) {
|
||||
return false;
|
||||
}
|
||||
|
||||
XPCCallContext ccx(cx);
|
||||
if (!ccx.IsValid())
|
||||
if (!ccx.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t interface_count = set->GetInterfaceCount();
|
||||
XPCNativeInterface** interfaceArray = set->GetInterfaceArray();
|
||||
@ -976,8 +1033,9 @@ XPC_WN_Proto_Enumerate(JSContext* cx, HandleObject obj)
|
||||
uint16_t member_count = iface->GetMemberCount();
|
||||
|
||||
for (uint16_t k = 0; k < member_count; k++) {
|
||||
if (!xpc_ForcePropertyResolve(cx, obj, iface->GetMemberAt(k)->GetName()))
|
||||
if (!xpc_ForcePropertyResolve(cx, obj, iface->GetMemberAt(k)->GetName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -989,8 +1047,9 @@ XPC_WN_Proto_Finalize(js::FreeOp* fop, JSObject* obj)
|
||||
{
|
||||
// This can be null if xpc shutdown has already happened
|
||||
XPCWrappedNativeProto* p = (XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if (p)
|
||||
if (p) {
|
||||
p->JSProtoObjectFinalized(fop, obj);
|
||||
}
|
||||
}
|
||||
|
||||
static size_t
|
||||
@ -998,8 +1057,9 @@ XPC_WN_Proto_ObjectMoved(JSObject* obj, JSObject* old)
|
||||
{
|
||||
// This can be null if xpc shutdown has already happened
|
||||
XPCWrappedNativeProto* p = (XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if (!p)
|
||||
if (!p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
p->JSProtoObjectMoved(obj, old);
|
||||
return 0;
|
||||
@ -1011,8 +1071,9 @@ XPC_WN_Proto_Trace(JSTracer* trc, JSObject* obj)
|
||||
// This can be null if xpc shutdown has already happened
|
||||
XPCWrappedNativeProto* p =
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if (p)
|
||||
if (p) {
|
||||
p->TraceInside(trc);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************/
|
||||
@ -1026,16 +1087,19 @@ XPC_WN_OnlyIWrite_Proto_AddPropertyStub(JSContext* cx, HandleObject obj, HandleI
|
||||
|
||||
XPCWrappedNativeProto* self =
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if (!self)
|
||||
if (!self) {
|
||||
return false;
|
||||
}
|
||||
|
||||
XPCCallContext ccx(cx);
|
||||
if (!ccx.IsValid())
|
||||
if (!ccx.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow XPConnect to add the property only
|
||||
if (ccx.GetResolveName() == id)
|
||||
if (ccx.GetResolveName() == id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
|
||||
}
|
||||
@ -1048,12 +1112,14 @@ XPC_WN_Proto_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolve
|
||||
|
||||
XPCWrappedNativeProto* self =
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if (!self)
|
||||
if (!self) {
|
||||
return false;
|
||||
}
|
||||
|
||||
XPCCallContext ccx(cx);
|
||||
if (!ccx.IsValid())
|
||||
if (!ccx.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXPCScriptable> scr = self->GetScriptable();
|
||||
|
||||
@ -1106,13 +1172,15 @@ XPC_WN_TearOff_Enumerate(JSContext* cx, HandleObject obj)
|
||||
XPCWrappedNativeTearOff* to = ccx.GetTearOff();
|
||||
XPCNativeInterface* iface;
|
||||
|
||||
if (!to || nullptr == (iface = to->GetInterface()))
|
||||
if (!to || nullptr == (iface = to->GetInterface())) {
|
||||
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
|
||||
}
|
||||
|
||||
uint16_t member_count = iface->GetMemberCount();
|
||||
for (uint16_t k = 0; k < member_count; k++) {
|
||||
if (!xpc_ForcePropertyResolve(cx, obj, iface->GetMemberAt(k)->GetName()))
|
||||
if (!xpc_ForcePropertyResolve(cx, obj, iface->GetMemberAt(k)->GetName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -1128,8 +1196,9 @@ XPC_WN_TearOff_Resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resol
|
||||
XPCWrappedNativeTearOff* to = ccx.GetTearOff();
|
||||
XPCNativeInterface* iface;
|
||||
|
||||
if (!to || nullptr == (iface = to->GetInterface()))
|
||||
if (!to || nullptr == (iface = to->GetInterface())) {
|
||||
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
|
||||
}
|
||||
|
||||
return DefinePropertyIfFound(ccx, obj, id, nullptr, iface, nullptr,
|
||||
wrapper->GetScope(),
|
||||
@ -1144,8 +1213,9 @@ XPC_WN_TearOff_Finalize(js::FreeOp* fop, JSObject* obj)
|
||||
{
|
||||
XPCWrappedNativeTearOff* p = (XPCWrappedNativeTearOff*)
|
||||
xpc_GetJSPrivate(obj);
|
||||
if (!p)
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
p->JSObjectFinalized();
|
||||
}
|
||||
|
||||
@ -1154,8 +1224,9 @@ XPC_WN_TearOff_ObjectMoved(JSObject* obj, JSObject* old)
|
||||
{
|
||||
XPCWrappedNativeTearOff* p = (XPCWrappedNativeTearOff*)
|
||||
xpc_GetJSPrivate(obj);
|
||||
if (!p)
|
||||
if (!p) {
|
||||
return 0;
|
||||
}
|
||||
p->JSObjectMoved(obj, old);
|
||||
return 0;
|
||||
}
|
||||
|
@ -122,12 +122,14 @@ XPCWrappedNativeProto::GetNewOrUsed(XPCWrappedNativeScope* scope,
|
||||
|
||||
map = scope->GetWrappedNativeProtoMap();
|
||||
proto = map->Find(classInfo);
|
||||
if (proto)
|
||||
if (proto) {
|
||||
return proto;
|
||||
}
|
||||
|
||||
RefPtr<XPCNativeSet> set = XPCNativeSet::GetNewOrUsed(classInfo);
|
||||
if (!set)
|
||||
if (!set) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
proto = new XPCWrappedNativeProto(scope, classInfo, set.forget());
|
||||
|
||||
|
@ -36,18 +36,21 @@ RemoteXULForbidsXBLScope(nsIPrincipal* aPrincipal, HandleObject aGlobal)
|
||||
// to call into AllowXULXBLForPrincipal. We never create XBL scopes for
|
||||
// sandboxes anway, and certainly not for these singleton scopes. So we just
|
||||
// short-circuit here.
|
||||
if (IsSandbox(aGlobal))
|
||||
if (IsSandbox(aGlobal)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// AllowXULXBLForPrincipal will return true for system principal, but we
|
||||
// don't want that here.
|
||||
MOZ_ASSERT(nsContentUtils::IsInitialized());
|
||||
if (nsContentUtils::IsSystemPrincipal(aPrincipal))
|
||||
if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If this domain isn't whitelisted, we're done.
|
||||
if (!nsContentUtils::AllowXULXBLForPrincipal(aPrincipal))
|
||||
if (!nsContentUtils::AllowXULXBLForPrincipal(aPrincipal)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the pref to determine how we should behave.
|
||||
return !Preferences::GetBool("dom.use_xbl_scopes_for_remote_xul", false);
|
||||
@ -69,8 +72,9 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(JSContext* cx,
|
||||
JSCLASS_HAS_PRIVATE) ||
|
||||
mozilla::dom::IsDOMClass(clasp));
|
||||
#ifdef DEBUG
|
||||
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
|
||||
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
|
||||
MOZ_ASSERT(aGlobal != cur->GetGlobalJSObjectPreserveColor(), "dup object");
|
||||
}
|
||||
#endif
|
||||
|
||||
mNext = gScopes;
|
||||
@ -113,8 +117,9 @@ bool
|
||||
XPCWrappedNativeScope::IsDyingScope(XPCWrappedNativeScope* scope)
|
||||
{
|
||||
for (XPCWrappedNativeScope* cur = gDyingScopes; cur; cur = cur->mNext) {
|
||||
if (scope == cur)
|
||||
if (scope == cur) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -134,17 +139,20 @@ XPCWrappedNativeScope::GetComponentsJSObject(JS::MutableHandleObject obj)
|
||||
xpcObjectHelper helper(mComponents);
|
||||
bool ok = XPCConvert::NativeInterface2JSObject(&val, helper, nullptr,
|
||||
false, nullptr);
|
||||
if (NS_WARN_IF(!ok))
|
||||
if (NS_WARN_IF(!ok)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(!val.isObject()))
|
||||
if (NS_WARN_IF(!val.isObject())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The call to wrap() here is necessary even though the object is same-
|
||||
// compartment, because it applies our security wrapper.
|
||||
obj.set(&val.toObject());
|
||||
if (NS_WARN_IF(!JS_WrapObject(cx, obj)))
|
||||
if (NS_WARN_IF(!JS_WrapObject(cx, obj))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -152,8 +160,9 @@ void
|
||||
XPCWrappedNativeScope::ForcePrivilegedComponents()
|
||||
{
|
||||
nsCOMPtr<nsIXPCComponents> c = do_QueryInterface(mComponents);
|
||||
if (!c)
|
||||
if (!c) {
|
||||
mComponents = new nsXPCComponents(this);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -168,8 +177,9 @@ DefineSubcomponentProperty(JSContext* aCx,
|
||||
if (!XPCConvert::NativeInterface2JSObject(&subcompVal, helper,
|
||||
aIID, false, nullptr))
|
||||
return false;
|
||||
if (NS_WARN_IF(!subcompVal.isObject()))
|
||||
if (NS_WARN_IF(!subcompVal.isObject())) {
|
||||
return false;
|
||||
}
|
||||
RootedId id(aCx, XPCJSContext::Get()->GetStringID(aStringIndex));
|
||||
return JS_DefinePropertyById(aCx, aGlobal, id, subcompVal, 0);
|
||||
}
|
||||
@ -178,8 +188,9 @@ bool
|
||||
XPCWrappedNativeScope::AttachComponentsObject(JSContext* aCx)
|
||||
{
|
||||
RootedObject components(aCx);
|
||||
if (!GetComponentsJSObject(&components))
|
||||
if (!GetComponentsJSObject(&components)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject global(aCx, GetGlobalJSObject());
|
||||
MOZ_ASSERT(js::IsObjectInContextCompartment(global, aCx));
|
||||
@ -189,12 +200,14 @@ XPCWrappedNativeScope::AttachComponentsObject(JSContext* aCx)
|
||||
// enableUniversalXPConnect can upgrade it later.
|
||||
unsigned attrs = JSPROP_READONLY | JSPROP_RESOLVING;
|
||||
nsCOMPtr<nsIXPCComponents> c = do_QueryInterface(mComponents);
|
||||
if (c)
|
||||
if (c) {
|
||||
attrs |= JSPROP_PERMANENT;
|
||||
}
|
||||
|
||||
RootedId id(aCx, XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS));
|
||||
if (!JS_DefinePropertyById(aCx, global, id, components, attrs))
|
||||
if (!JS_DefinePropertyById(aCx, global, id, components, attrs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// _iid can be nullptr if the object implements classinfo.
|
||||
#define DEFINE_SUBCOMPONENT_PROPERTY(_comp, _type, _iid, _id) \
|
||||
@ -208,8 +221,9 @@ XPCWrappedNativeScope::AttachComponentsObject(JSContext* aCx)
|
||||
DEFINE_SUBCOMPONENT_PROPERTY(mComponents, Interfaces, nullptr, CI)
|
||||
DEFINE_SUBCOMPONENT_PROPERTY(mComponents, Results, nullptr, CR)
|
||||
|
||||
if (!c)
|
||||
if (!c) {
|
||||
return true;
|
||||
}
|
||||
|
||||
DEFINE_SUBCOMPONENT_PROPERTY(c, Classes, nullptr, CC)
|
||||
DEFINE_SUBCOMPONENT_PROPERTY(c, Utils, &NS_GET_IID(nsIXPCComponents_Utils), CU)
|
||||
@ -229,12 +243,14 @@ XPCWrappedNativeScope::EnsureContentXBLScope(JSContext* cx)
|
||||
"nsXBLPrototypeScript compilation scope"));
|
||||
|
||||
// If we already have a special XBL scope object, we know what to use.
|
||||
if (mContentXBLScope)
|
||||
if (mContentXBLScope) {
|
||||
return mContentXBLScope;
|
||||
}
|
||||
|
||||
// If this scope doesn't need an XBL scope, just return the global.
|
||||
if (!mUseContentXBLScope)
|
||||
if (!mUseContentXBLScope) {
|
||||
return global;
|
||||
}
|
||||
|
||||
// Set up the sandbox options. Note that we use the DOM global as the
|
||||
// sandboxPrototype so that the XBL scope can access all the DOM objects
|
||||
@ -364,15 +380,17 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope()
|
||||
|
||||
// This should not be necessary, since the Components object should die
|
||||
// with the scope but just in case.
|
||||
if (mComponents)
|
||||
if (mComponents) {
|
||||
mComponents->mScope = nullptr;
|
||||
}
|
||||
|
||||
// XXX we should assert that we are dead or that xpconnect has shutdown
|
||||
// XXX might not want to do this at xpconnect shutdown time???
|
||||
mComponents = nullptr;
|
||||
|
||||
if (mXrayExpandos.initialized())
|
||||
if (mXrayExpandos.initialized()) {
|
||||
mXrayExpandos.destroy();
|
||||
}
|
||||
|
||||
JSContext* cx = dom::danger::GetJSContext();
|
||||
mGlobalJSObject.finalize(cx);
|
||||
@ -388,8 +406,9 @@ XPCWrappedNativeScope::TraceWrappedNativesInAllScopes(JSTracer* trc)
|
||||
for (auto i = cur->mWrappedNativeMap->Iter(); !i.Done(); i.Next()) {
|
||||
auto entry = static_cast<Native2WrappedNativeMap::Entry*>(i.Get());
|
||||
XPCWrappedNative* wrapper = entry->value;
|
||||
if (wrapper->HasExternalReference() && !wrapper->IsWrapperExpired())
|
||||
if (wrapper->HasExternalReference() && !wrapper->IsWrapperExpired()) {
|
||||
wrapper->TraceSelf(trc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -448,11 +467,13 @@ void
|
||||
XPCWrappedNativeScope::UpdateWeakPointersAfterGC()
|
||||
{
|
||||
// Sweep waivers.
|
||||
if (mWaiverWrapperMap)
|
||||
if (mWaiverWrapperMap) {
|
||||
mWaiverWrapperMap->Sweep();
|
||||
}
|
||||
|
||||
if (!js::IsObjectZoneSweepingOrCompacting(mGlobalJSObject.unbarrieredGet()))
|
||||
if (!js::IsObjectZoneSweepingOrCompacting(mGlobalJSObject.unbarrieredGet())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update our pointer to the global object in case it was moved or
|
||||
// finalized.
|
||||
@ -487,8 +508,9 @@ XPCWrappedNativeScope::UpdateWeakPointersAfterGC()
|
||||
JS_UpdateWeakPointerAfterGCUnbarriered(&obj);
|
||||
MOZ_ASSERT(!obj || obj == wrapper->GetFlatJSObjectPreserveColor());
|
||||
AssertSameCompartment(comp, obj);
|
||||
if (!obj)
|
||||
if (!obj) {
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Sweep mWrappedNativeProtoMap for dying prototype JSObjects. Moving has
|
||||
@ -499,8 +521,9 @@ XPCWrappedNativeScope::UpdateWeakPointersAfterGC()
|
||||
JS_UpdateWeakPointerAfterGCUnbarriered(&obj);
|
||||
AssertSameCompartment(comp, obj);
|
||||
MOZ_ASSERT(!obj || obj == entry->value->GetJSProtoObjectPreserveColor());
|
||||
if (!obj)
|
||||
if (!obj) {
|
||||
i.Remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -523,8 +546,9 @@ XPCWrappedNativeScope::KillDyingScopes()
|
||||
XPCWrappedNativeScope* cur = gDyingScopes;
|
||||
while (cur) {
|
||||
XPCWrappedNativeScope* next = cur->mNext;
|
||||
if (cur->mGlobalJSObject)
|
||||
if (cur->mGlobalJSObject) {
|
||||
RealmPrivate::Get(cur->mGlobalJSObject)->scope = nullptr;
|
||||
}
|
||||
delete cur;
|
||||
cur = next;
|
||||
}
|
||||
@ -557,8 +581,9 @@ XPCWrappedNativeScope::SystemIsBeingShutDown()
|
||||
|
||||
for (cur = gDyingScopes; cur; cur = cur->mNext) {
|
||||
// Give the Components object a chance to try to clean up.
|
||||
if (cur->mComponents)
|
||||
if (cur->mComponents) {
|
||||
cur->mComponents->SystemIsBeingShutDown();
|
||||
}
|
||||
|
||||
// Walk the protos first. Wrapper shutdown can leave dangling
|
||||
// proto pointers in the proto map.
|
||||
@ -591,8 +616,9 @@ JSObject*
|
||||
XPCWrappedNativeScope::GetExpandoChain(HandleObject target)
|
||||
{
|
||||
MOZ_ASSERT(ObjectScope(target) == this);
|
||||
if (!mXrayExpandos.initialized())
|
||||
if (!mXrayExpandos.initialized()) {
|
||||
return nullptr;
|
||||
}
|
||||
return mXrayExpandos.lookup(target);
|
||||
}
|
||||
|
||||
@ -600,8 +626,9 @@ JSObject*
|
||||
XPCWrappedNativeScope::DetachExpandoChain(HandleObject target)
|
||||
{
|
||||
MOZ_ASSERT(ObjectScope(target) == this);
|
||||
if (!mXrayExpandos.initialized())
|
||||
if (!mXrayExpandos.initialized()) {
|
||||
return nullptr;
|
||||
}
|
||||
return mXrayExpandos.removeValue(target);
|
||||
}
|
||||
|
||||
@ -612,8 +639,9 @@ XPCWrappedNativeScope::SetExpandoChain(JSContext* cx, HandleObject target,
|
||||
MOZ_ASSERT(ObjectScope(target) == this);
|
||||
MOZ_ASSERT(js::IsObjectInContextCompartment(target, cx));
|
||||
MOZ_ASSERT_IF(chain, ObjectScope(chain) == this);
|
||||
if (!mXrayExpandos.initialized() && !mXrayExpandos.init(cx))
|
||||
if (!mXrayExpandos.initialized() && !mXrayExpandos.init(cx)) {
|
||||
return false;
|
||||
}
|
||||
return mXrayExpandos.put(cx, target, chain);
|
||||
}
|
||||
|
||||
@ -630,15 +658,18 @@ XPCWrappedNativeScope::DebugDumpAllScopes(int16_t depth)
|
||||
// get scope count.
|
||||
int count = 0;
|
||||
XPCWrappedNativeScope* cur;
|
||||
for (cur = gScopes; cur; cur = cur->mNext)
|
||||
for (cur = gScopes; cur; cur = cur->mNext) {
|
||||
count++ ;
|
||||
}
|
||||
|
||||
XPC_LOG_ALWAYS(("chain of %d XPCWrappedNativeScope(s)", count));
|
||||
XPC_LOG_INDENT();
|
||||
XPC_LOG_ALWAYS(("gDyingScopes @ %p", gDyingScopes));
|
||||
if (depth)
|
||||
for (cur = gScopes; cur; cur = cur->mNext)
|
||||
if (depth) {
|
||||
for (cur = gScopes; cur; cur = cur->mNext) {
|
||||
cur->DebugDump(depth);
|
||||
}
|
||||
}
|
||||
XPC_LOG_OUTDENT();
|
||||
#endif
|
||||
}
|
||||
@ -685,8 +716,9 @@ XPCWrappedNativeScope::DebugDump(int16_t depth)
|
||||
void
|
||||
XPCWrappedNativeScope::AddSizeOfAllScopesIncludingThis(ScopeSizeInfo* scopeSizeInfo)
|
||||
{
|
||||
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
|
||||
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
|
||||
cur->AddSizeOfIncludingThis(scopeSizeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -143,10 +143,12 @@ nsXPConnect::InitStatics()
|
||||
MOZ_RELEASE_ASSERT(gSystemPrincipal);
|
||||
|
||||
JSContext* cx = XPCJSContext::Get()->Context();
|
||||
if (!JS::InitSelfHostedCode(cx))
|
||||
if (!JS::InitSelfHostedCode(cx)) {
|
||||
MOZ_CRASH("InitSelfHostedCode failed");
|
||||
if (!gSelf->mRuntime->InitializeStrings(cx))
|
||||
}
|
||||
if (!gSelf->mRuntime->InitializeStrings(cx)) {
|
||||
MOZ_CRASH("InitializeStrings failed");
|
||||
}
|
||||
|
||||
// Initialize our singleton scopes.
|
||||
gSelf->mRuntime->InitSingletonScopes();
|
||||
@ -181,10 +183,11 @@ nsXPConnect::IsISupportsDescendant(const nsXPTInterfaceInfo* info)
|
||||
void
|
||||
xpc::ErrorBase::Init(JSErrorBase* aReport)
|
||||
{
|
||||
if (!aReport->filename)
|
||||
if (!aReport->filename) {
|
||||
mFileName.SetIsVoid(true);
|
||||
else
|
||||
} else {
|
||||
CopyUTF8toUTF16(mozilla::MakeStringSpan(aReport->filename), mFileName);
|
||||
}
|
||||
|
||||
mLineNumber = aReport->lineno;
|
||||
mColumn = aReport->column;
|
||||
@ -225,8 +228,9 @@ xpc::ErrorReport::Init(JSErrorReport* aReport, const char* aToStringResult,
|
||||
mIsMuted = aReport->isMuted;
|
||||
|
||||
if (aReport->notes) {
|
||||
if (!mNotes.SetLength(aReport->notes->length(), fallible))
|
||||
if (!mNotes.SetLength(aReport->notes->length(), fallible)) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
for (auto&& note : *aReport->notes) {
|
||||
@ -271,8 +275,9 @@ xpc::ErrorBase::AppendErrorDetailsTo(nsCString& error)
|
||||
void
|
||||
xpc::ErrorNote::LogToStderr()
|
||||
{
|
||||
if (!DOMPrefs::DumpEnabled())
|
||||
if (!DOMPrefs::DumpEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoCString error;
|
||||
error.AssignLiteral("JavaScript note: ");
|
||||
@ -285,17 +290,20 @@ xpc::ErrorNote::LogToStderr()
|
||||
void
|
||||
xpc::ErrorReport::LogToStderr()
|
||||
{
|
||||
if (!DOMPrefs::DumpEnabled())
|
||||
if (!DOMPrefs::DumpEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoCString error;
|
||||
error.AssignLiteral("JavaScript ");
|
||||
if (JSREPORT_IS_STRICT(mFlags))
|
||||
if (JSREPORT_IS_STRICT(mFlags)) {
|
||||
error.AppendLiteral("strict ");
|
||||
if (JSREPORT_IS_WARNING(mFlags))
|
||||
}
|
||||
if (JSREPORT_IS_WARNING(mFlags)) {
|
||||
error.AppendLiteral("warning: ");
|
||||
else
|
||||
} else {
|
||||
error.AppendLiteral("error: ");
|
||||
}
|
||||
AppendErrorDetailsTo(error);
|
||||
|
||||
fprintf(stderr, "%s\n", error.get());
|
||||
@ -320,8 +328,9 @@ xpc::ErrorReport::LogToConsoleWithStack(JS::HandleObject aStack,
|
||||
{
|
||||
// Don't log failures after diverging from a recording during replay, as
|
||||
// this will cause the associated debugger operation to fail.
|
||||
if (recordreplay::HasDivergedFromRecording())
|
||||
if (recordreplay::HasDivergedFromRecording()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aStack) {
|
||||
MOZ_ASSERT(aStackGlobal);
|
||||
@ -382,8 +391,9 @@ xpc::ErrorNote::ErrorNoteToMessageString(JSErrorNotes::Note* aNote,
|
||||
nsAString& aString)
|
||||
{
|
||||
aString.Truncate();
|
||||
if (aNote->message())
|
||||
if (aNote->message()) {
|
||||
aString.Append(NS_ConvertUTF8toUTF16(aNote->message().c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
@ -430,15 +440,17 @@ static inline T UnexpectedFailure(T rv)
|
||||
void
|
||||
xpc::TraceXPCGlobal(JSTracer* trc, JSObject* obj)
|
||||
{
|
||||
if (js::GetObjectClass(obj)->flags & JSCLASS_DOM_GLOBAL)
|
||||
if (js::GetObjectClass(obj)->flags & JSCLASS_DOM_GLOBAL) {
|
||||
mozilla::dom::TraceProtoAndIfaceCache(trc, obj);
|
||||
}
|
||||
|
||||
// We might be called from a GC during the creation of a global, before we've
|
||||
// been able to set up the compartment private or the XPCWrappedNativeScope,
|
||||
// so we need to null-check those.
|
||||
xpc::RealmPrivate* realmPrivate = xpc::RealmPrivate::Get(obj);
|
||||
if (realmPrivate && realmPrivate->scope)
|
||||
if (realmPrivate && realmPrivate->scope) {
|
||||
realmPrivate->scope->TraceInside(trc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -457,8 +469,9 @@ CreateGlobalObject(JSContext* cx, const JSClass* clasp, nsIPrincipal* principal,
|
||||
RootedObject global(cx,
|
||||
JS_NewGlobalObject(cx, clasp, nsJSPrincipals::get(principal),
|
||||
JS::DontFireOnNewGlobalHook, aOptions));
|
||||
if (!global)
|
||||
if (!global) {
|
||||
return nullptr;
|
||||
}
|
||||
JSAutoRealm ar(cx, global);
|
||||
|
||||
// The constructor automatically attaches the scope to the compartment private
|
||||
@ -473,8 +486,7 @@ CreateGlobalObject(JSContext* cx, const JSClass* clasp, nsIPrincipal* principal,
|
||||
// thing. Also note that we only check this for JSCLASS_DOM_GLOBAL
|
||||
// classes because xpc::TraceXPCGlobal won't call
|
||||
// TraceProtoAndIfaceCache unless that flag is set.
|
||||
if (!((const js::Class*)clasp)->isWrappedNative())
|
||||
{
|
||||
if (!((const js::Class*)clasp)->isWrappedNative()) {
|
||||
VerifyTraceProtoAndIfaceCacheCalledTracer trc(cx);
|
||||
TraceChildren(&trc, GCCellPtr(global.get()));
|
||||
MOZ_ASSERT(trc.ok, "Trace hook on global needs to call TraceXPCGlobal for XPConnect compartments.");
|
||||
@ -514,8 +526,9 @@ InitGlobalObjectOptions(JS::RealmOptions& aOptions,
|
||||
}
|
||||
|
||||
if (extraWarningsForSystemJS) {
|
||||
if (isSystem)
|
||||
if (isSystem) {
|
||||
aOptions.behaviors().extraWarningsOverride().set(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -537,8 +550,9 @@ InitGlobalObject(JSContext* aJSContext, JS::Handle<JSObject*> aGlobal, uint32_t
|
||||
}
|
||||
}
|
||||
|
||||
if (!(aFlags & xpc::DONT_FIRE_ONNEWGLOBALHOOK))
|
||||
if (!(aFlags & xpc::DONT_FIRE_ONNEWGLOBALHOOK)) {
|
||||
JS_FireOnNewGlobalObject(aJSContext, aGlobal);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -579,8 +593,9 @@ InitClassesWithNewWrappedGlobal(JSContext* aJSContext,
|
||||
RootedObject global(aJSContext, wrappedGlobal->GetFlatJSObject());
|
||||
MOZ_ASSERT(JS_IsGlobalObject(global));
|
||||
|
||||
if (!InitGlobalObject(aJSContext, global, aFlags))
|
||||
if (!InitGlobalObject(aJSContext, global, aFlags)) {
|
||||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
aNewGlobal.set(global);
|
||||
return NS_OK;
|
||||
@ -601,8 +616,9 @@ NativeInterface2JSObject(HandleObject aScope,
|
||||
|
||||
nsresult rv;
|
||||
xpcObjectHelper helper(aCOMObj, aCache);
|
||||
if (!XPCConvert::NativeInterface2JSObject(aVal, helper, aIID, aAllowWrapping, &rv))
|
||||
if (!XPCConvert::NativeInterface2JSObject(aVal, helper, aIID, aAllowWrapping, &rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(aAllowWrapping || !xpc::WrapperFactory::IsXrayWrapper(&aVal.toObject()),
|
||||
"Shouldn't be returning a xray wrapper here");
|
||||
@ -625,11 +641,13 @@ nsXPConnect::WrapNative(JSContext * aJSContext,
|
||||
RootedValue v(aJSContext);
|
||||
nsresult rv = NativeInterface2JSObject(aScope, aCOMObj, nullptr, &aIID,
|
||||
true, &v);
|
||||
if (NS_FAILED(rv))
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!v.isObjectOrNull())
|
||||
if (!v.isObjectOrNull()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
*aRetVal = v.toObjectOrNull();
|
||||
return NS_OK;
|
||||
@ -736,14 +754,16 @@ xpc::UnwrapReflectorToISupports(JSObject* reflector)
|
||||
{
|
||||
// Unwrap security wrappers, if allowed.
|
||||
reflector = js::CheckedUnwrap(reflector, /* stopAtWindowProxy = */ false);
|
||||
if (!reflector)
|
||||
if (!reflector) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Try XPCWrappedNatives.
|
||||
if (IS_WN_REFLECTOR(reflector)) {
|
||||
XPCWrappedNative* wn = XPCWrappedNative::Get(reflector);
|
||||
if (!wn)
|
||||
if (!wn) {
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsISupports> native = wn->Native();
|
||||
return native.forget();
|
||||
}
|
||||
@ -780,8 +800,9 @@ nsXPConnect::EvalInSandboxObject(const nsAString& source, const char* filename,
|
||||
JSContext* cx, JSObject* sandboxArg,
|
||||
MutableHandleValue rval)
|
||||
{
|
||||
if (!sandboxArg)
|
||||
if (!sandboxArg) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
RootedObject sandbox(cx, sandboxArg);
|
||||
nsCString filenameStr;
|
||||
@ -812,8 +833,9 @@ NS_IMETHODIMP
|
||||
nsXPConnect::DebugDumpObject(nsISupports* p, int16_t depth)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (!depth)
|
||||
if (!depth) {
|
||||
return NS_OK;
|
||||
}
|
||||
if (!p) {
|
||||
XPC_LOG_ALWAYS(("*** Cound not dump object with NULL address"));
|
||||
return NS_OK;
|
||||
@ -870,8 +892,9 @@ nsXPConnect::VariantToJS(JSContext* ctx, JSObject* scopeArg, nsIVariant* value,
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (!XPCVariant::VariantDataToJS(value, &rv, _retval)) {
|
||||
if (NS_FAILED(rv))
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -886,8 +909,9 @@ nsXPConnect::JSToVariant(JSContext* ctx, HandleValue value, nsIVariant** _retval
|
||||
|
||||
RefPtr<XPCVariant> variant = XPCVariant::newVariant(ctx, value);
|
||||
variant.forget(_retval);
|
||||
if (!(*_retval))
|
||||
if (!(*_retval)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -911,8 +935,9 @@ Base64Encode(JSContext* cx, HandleValue val, MutableHandleValue out)
|
||||
}
|
||||
|
||||
JSString* str = JS_NewStringCopyN(cx, result.get(), result.Length());
|
||||
if (!str)
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
out.setString(str);
|
||||
return true;
|
||||
@ -935,8 +960,9 @@ Base64Decode(JSContext* cx, HandleValue val, MutableHandleValue out)
|
||||
}
|
||||
|
||||
JSString* str = JS_NewStringCopyN(cx, result.get(), result.Length());
|
||||
if (!str)
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
out.setString(str);
|
||||
return true;
|
||||
@ -973,33 +999,38 @@ WriteScriptOrFunction(nsIObjectOutputStream* stream, JSContext* cx,
|
||||
|
||||
uint8_t flags = 0; // We don't have flags anymore.
|
||||
nsresult rv = stream->Write8(flags);
|
||||
if (NS_FAILED(rv))
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
TranscodeBuffer buffer;
|
||||
TranscodeResult code;
|
||||
{
|
||||
if (functionObj)
|
||||
if (functionObj) {
|
||||
code = EncodeInterpretedFunction(cx, buffer, functionObj);
|
||||
else
|
||||
} else {
|
||||
code = EncodeScript(cx, buffer, script);
|
||||
}
|
||||
}
|
||||
|
||||
if (code != TranscodeResult_Ok) {
|
||||
if ((code & TranscodeResult_Failure) != 0)
|
||||
if ((code & TranscodeResult_Failure) != 0) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
MOZ_ASSERT((code & TranscodeResult_Throw) != 0);
|
||||
JS_ClearPendingException(cx);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
size_t size = buffer.length();
|
||||
if (size > UINT32_MAX)
|
||||
if (size > UINT32_MAX) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
rv = stream->Write32(size);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = stream->WriteBytes(reinterpret_cast<char*>(buffer.begin()), size);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
@ -1013,8 +1044,9 @@ ReadScriptOrFunction(nsIObjectInputStream* stream, JSContext* cx,
|
||||
|
||||
uint8_t flags;
|
||||
nsresult rv = stream->Read8(&flags);
|
||||
if (NS_FAILED(rv))
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// We don't serialize mutedError-ness of scripts, which is fine as long as
|
||||
// we only serialize system and XUL-y things. We can detect this by checking
|
||||
@ -1028,13 +1060,15 @@ ReadScriptOrFunction(nsIObjectInputStream* stream, JSContext* cx,
|
||||
|
||||
uint32_t size;
|
||||
rv = stream->Read32(&size);
|
||||
if (NS_FAILED(rv))
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
char* data;
|
||||
rv = stream->ReadBytes(size, &data);
|
||||
if (NS_FAILED(rv))
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
TranscodeBuffer buffer;
|
||||
buffer.replaceRawBuffer(reinterpret_cast<uint8_t*>(data), size);
|
||||
@ -1044,18 +1078,21 @@ ReadScriptOrFunction(nsIObjectInputStream* stream, JSContext* cx,
|
||||
if (scriptp) {
|
||||
Rooted<JSScript*> script(cx);
|
||||
code = DecodeScript(cx, buffer, &script);
|
||||
if (code == TranscodeResult_Ok)
|
||||
if (code == TranscodeResult_Ok) {
|
||||
*scriptp = script.get();
|
||||
}
|
||||
} else {
|
||||
Rooted<JSFunction*> funobj(cx);
|
||||
code = DecodeInterpretedFunction(cx, buffer, &funobj);
|
||||
if (code == TranscodeResult_Ok)
|
||||
if (code == TranscodeResult_Ok) {
|
||||
*functionObjp = JS_GetFunctionObject(funobj.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (code != TranscodeResult_Ok) {
|
||||
if ((code & TranscodeResult_Failure) != 0)
|
||||
if ((code & TranscodeResult_Failure) != 0) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
MOZ_ASSERT((code & TranscodeResult_Throw) != 0);
|
||||
JS_ClearPendingException(cx);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
@ -1149,8 +1186,9 @@ bool
|
||||
Atob(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (!args.length())
|
||||
if (!args.length()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return xpc::Base64Decode(cx, args[0], args.rval());
|
||||
}
|
||||
@ -1159,8 +1197,9 @@ bool
|
||||
Btoa(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (!args.length())
|
||||
if (!args.length()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return xpc::Base64Encode(cx, args[0], args.rval());
|
||||
}
|
||||
|
@ -41,8 +41,9 @@ public:
|
||||
|
||||
nsIClassInfo* GetClassInfo()
|
||||
{
|
||||
if (!mClassInfo)
|
||||
if (!mClassInfo) {
|
||||
mClassInfo = do_QueryInterface(mObject);
|
||||
}
|
||||
return mClassInfo;
|
||||
}
|
||||
|
||||
|
@ -880,10 +880,12 @@ public:
|
||||
}
|
||||
|
||||
void TraceInside(JSTracer* trc) {
|
||||
if (mContentXBLScope)
|
||||
if (mContentXBLScope) {
|
||||
mContentXBLScope.trace(trc, "XPCWrappedNativeScope::mXBLScope");
|
||||
if (mXrayExpandos.initialized())
|
||||
}
|
||||
if (mXrayExpandos.initialized()) {
|
||||
mXrayExpandos.trace(trc);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1316,8 +1318,9 @@ public:
|
||||
void DebugDump(int16_t depth);
|
||||
|
||||
void TraceSelf(JSTracer* trc) {
|
||||
if (mJSProtoObject)
|
||||
if (mJSProtoObject) {
|
||||
mJSProtoObject.trace(trc, "XPCWrappedNativeProto::mJSProtoObject");
|
||||
}
|
||||
}
|
||||
|
||||
void TraceInside(JSTracer* trc) {
|
||||
@ -1331,8 +1334,9 @@ public:
|
||||
|
||||
void WriteBarrierPre(JSContext* cx)
|
||||
{
|
||||
if (JS::IsIncrementalBarrierNeeded(cx) && mJSProtoObject)
|
||||
if (JS::IsIncrementalBarrierNeeded(cx) && mJSProtoObject) {
|
||||
mJSProtoObject.writeBarrierPre(cx);
|
||||
}
|
||||
}
|
||||
|
||||
// NOP. This is just here to make the AutoMarkingPtr code compile.
|
||||
@ -1576,10 +1580,11 @@ public:
|
||||
void Mark() const {}
|
||||
|
||||
inline void TraceInside(JSTracer* trc) {
|
||||
if (HasProto())
|
||||
if (HasProto()) {
|
||||
GetProto()->TraceSelf(trc);
|
||||
else
|
||||
} else {
|
||||
GetScope()->TraceSelf(trc);
|
||||
}
|
||||
|
||||
JSObject* obj = mFlatJSObject.unbarrieredGetPtr();
|
||||
if (obj && JS_IsGlobalObject(obj)) {
|
||||
@ -1848,8 +1853,9 @@ public:
|
||||
nsXPCWrappedJS* FindInherited(REFNSIID aIID);
|
||||
nsXPCWrappedJS* FindOrFindInherited(REFNSIID aIID) {
|
||||
nsXPCWrappedJS* wrapper = Find(aIID);
|
||||
if (wrapper)
|
||||
if (wrapper) {
|
||||
return wrapper;
|
||||
}
|
||||
return FindInherited(aIID);
|
||||
}
|
||||
|
||||
@ -2386,13 +2392,15 @@ class AutoMarkingPtr
|
||||
}
|
||||
|
||||
void TraceJSAll(JSTracer* trc) {
|
||||
for (AutoMarkingPtr* cur = this; cur; cur = cur->mNext)
|
||||
for (AutoMarkingPtr* cur = this; cur; cur = cur->mNext) {
|
||||
cur->TraceJS(trc);
|
||||
}
|
||||
}
|
||||
|
||||
void MarkAfterJSFinalizeAll() {
|
||||
for (AutoMarkingPtr* cur = this; cur; cur = cur->mNext)
|
||||
for (AutoMarkingPtr* cur = this; cur; cur = cur->mNext) {
|
||||
cur->MarkAfterJSFinalize();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -2428,8 +2436,9 @@ class TypedAutoMarkingPtr : public AutoMarkingPtr
|
||||
|
||||
virtual void MarkAfterJSFinalize() override
|
||||
{
|
||||
if (mPtr)
|
||||
if (mPtr) {
|
||||
mPtr->Mark();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2758,14 +2767,16 @@ public:
|
||||
|
||||
JSObject* ToJSObject(JSContext* cx) {
|
||||
JS::RootedObject obj(cx, JS_NewObjectWithGivenProto(cx, nullptr, nullptr));
|
||||
if (!obj)
|
||||
if (!obj) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JS::RootedValue val(cx);
|
||||
unsigned attrs = JSPROP_READONLY | JSPROP_PERMANENT;
|
||||
val = JS::BooleanValue(allowCrossOriginArguments);
|
||||
if (!JS_DefineProperty(cx, obj, "allowCrossOriginArguments", val, attrs))
|
||||
if (!JS_DefineProperty(cx, obj, "allowCrossOriginArguments", val, attrs)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
@ -3091,17 +3102,21 @@ public:
|
||||
}
|
||||
|
||||
void SetLocation(const nsACString& aLocation) {
|
||||
if (aLocation.IsEmpty())
|
||||
if (aLocation.IsEmpty()) {
|
||||
return;
|
||||
if (!location.IsEmpty() || locationURI)
|
||||
}
|
||||
if (!location.IsEmpty() || locationURI) {
|
||||
return;
|
||||
}
|
||||
location = aLocation;
|
||||
}
|
||||
void SetLocationURI(nsIURI* aLocationURI) {
|
||||
if (!aLocationURI)
|
||||
if (!aLocationURI) {
|
||||
return;
|
||||
if (locationURI)
|
||||
}
|
||||
if (locationURI) {
|
||||
return;
|
||||
}
|
||||
locationURI = aLocationURI;
|
||||
}
|
||||
|
||||
|
@ -118,8 +118,9 @@ inline JSObject*
|
||||
GetXBLScopeOrGlobal(JSContext* cx, JSObject* obj)
|
||||
{
|
||||
MOZ_ASSERT(!js::IsCrossCompartmentWrapper(obj));
|
||||
if (IsInContentXBLScope(obj))
|
||||
if (IsInContentXBLScope(obj)) {
|
||||
return JS::GetNonCCWObjectGlobal(obj);
|
||||
}
|
||||
return GetXBLScope(cx, obj);
|
||||
}
|
||||
|
||||
@ -276,8 +277,9 @@ public:
|
||||
bool ignored;
|
||||
JSString* str = JS_NewMaybeExternalString(cx, literal, length,
|
||||
&sLiteralFinalizer, &ignored);
|
||||
if (!str)
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
rval.setString(str);
|
||||
return true;
|
||||
}
|
||||
@ -291,8 +293,9 @@ public:
|
||||
atom->GetLength(),
|
||||
&sDynamicAtomFinalizer,
|
||||
&sharedAtom);
|
||||
if (!str)
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
if (sharedAtom) {
|
||||
// We only have non-owning atoms in DOMString for now.
|
||||
// nsDynamicAtom::AddRef is always-inline and defined in a
|
||||
|
Loading…
Reference in New Issue
Block a user