зеркало из https://github.com/mozilla/pjs.git
bug 599503 - Return true compartment info from JSObject::getCompartment(). r=jorendorff/gregor/gal
This commit is contained in:
Родитель
4af43e19cf
Коммит
f56da5a5ac
|
@ -1184,7 +1184,7 @@ bool
|
|||
JSAutoEnterCompartment::enter(JSContext *cx, JSObject *target)
|
||||
{
|
||||
JS_ASSERT(!call);
|
||||
if (cx->compartment == target->getCompartment(cx))
|
||||
if (cx->compartment == target->getCompartment())
|
||||
return true;
|
||||
call = JS_EnterCrossCompartmentCall(cx, target);
|
||||
return call != NULL;
|
||||
|
@ -1236,7 +1236,7 @@ JS_TransplantWrapper(JSContext *cx, JSObject *wrapper, JSObject *target)
|
|||
* need to "move" the window from wrapper's compartment to target's
|
||||
* compartment.
|
||||
*/
|
||||
JSCompartment *destination = target->getCompartment(cx);
|
||||
JSCompartment *destination = target->getCompartment();
|
||||
|
||||
JSObject *obj;
|
||||
WrapperMap &map = destination->crossCompartmentWrappers;
|
||||
|
@ -1302,7 +1302,7 @@ JS_SetGlobalObject(JSContext *cx, JSObject *obj)
|
|||
|
||||
cx->globalObject = obj;
|
||||
if (!cx->maybefp())
|
||||
cx->compartment = obj ? obj->getCompartment(cx) : cx->runtime->defaultCompartment;
|
||||
cx->compartment = obj ? obj->getCompartment() : cx->runtime->defaultCompartment;
|
||||
}
|
||||
|
||||
class AutoResolvingEntry {
|
||||
|
@ -2976,13 +2976,10 @@ JS_NewGlobalObject(JSContext *cx, JSClass *clasp)
|
|||
CHECK_REQUEST(cx);
|
||||
JS_ASSERT(clasp->flags & JSCLASS_IS_GLOBAL);
|
||||
JSObject *obj = NewNonFunction<WithProto::Given>(cx, Valueify(clasp), NULL, NULL);
|
||||
if (!obj ||
|
||||
!js_SetReservedSlot(cx, obj, JSRESERVED_GLOBAL_COMPARTMENT,
|
||||
PrivateValue(cx->compartment))) {
|
||||
if (!obj)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* FIXME: comment. */
|
||||
/* Construct a regexp statics object for this global object. */
|
||||
JSObject *res = regexp_statics_construct(cx);
|
||||
if (!res ||
|
||||
!js_SetReservedSlot(cx, obj, JSRESERVED_GLOBAL_REGEXP_STATICS,
|
||||
|
|
|
@ -1721,9 +1721,8 @@ struct JSClass {
|
|||
#define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4))
|
||||
|
||||
/* Additional global reserved slots, beyond those for standard prototypes. */
|
||||
#define JSRESERVED_GLOBAL_SLOTS_COUNT 4
|
||||
#define JSRESERVED_GLOBAL_COMPARTMENT (JSProto_LIMIT * 3)
|
||||
#define JSRESERVED_GLOBAL_THIS (JSRESERVED_GLOBAL_COMPARTMENT + 1)
|
||||
#define JSRESERVED_GLOBAL_SLOTS_COUNT 3
|
||||
#define JSRESERVED_GLOBAL_THIS (JSProto_LIMIT * 3)
|
||||
#define JSRESERVED_GLOBAL_THROWTYPEERROR (JSRESERVED_GLOBAL_THIS + 1)
|
||||
#define JSRESERVED_GLOBAL_REGEXP_STATICS (JSRESERVED_GLOBAL_THROWTYPEERROR + 1)
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "jsstaticcheck.h"
|
||||
#include "jsxml.h"
|
||||
#include "jsregexp.h"
|
||||
#include "jsgc.h"
|
||||
|
||||
inline js::RegExpStatics *
|
||||
JSContext::regExpStatics()
|
||||
|
@ -525,7 +526,7 @@ class CompartmentChecker
|
|||
|
||||
void check(JSObject *obj) {
|
||||
if (obj)
|
||||
check(obj->getCompartment(context));
|
||||
check(obj->getCompartment());
|
||||
}
|
||||
|
||||
void check(const js::Value &v) {
|
||||
|
|
|
@ -153,7 +153,7 @@ JSCompartment::wrap(JSContext *cx, Value *vp)
|
|||
}
|
||||
|
||||
/* If the wrapped object is already in this compartment, we are done. */
|
||||
if (obj->getCompartment(cx) == this)
|
||||
if (obj->compartment() == this)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ class SwitchToCompartment : public PreserveCompartment {
|
|||
}
|
||||
|
||||
SwitchToCompartment(JSContext *cx, JSObject *target) : PreserveCompartment(cx) {
|
||||
cx->compartment = target->getCompartment(cx);
|
||||
cx->compartment = target->getCompartment();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1636,7 +1636,7 @@ fun_getProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp)
|
|||
JSObject &caller = vp->toObject();
|
||||
|
||||
/* Censor the caller if it is from another compartment. */
|
||||
if (caller.getCompartment(cx) != cx->compartment) {
|
||||
if (caller.getCompartment() != cx->compartment) {
|
||||
vp->setNull();
|
||||
} else if (caller.isFunction() && caller.getFunctionPrivate()->inStrictMode()) {
|
||||
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL,
|
||||
|
|
|
@ -1037,4 +1037,10 @@ NewCompartment(JSContext *cx, JSPrincipals *principals);
|
|||
} /* namespace js */
|
||||
} /* namespace gc */
|
||||
|
||||
inline JSCompartment *
|
||||
JSObject::getCompartment() const
|
||||
{
|
||||
return ((Cell *)this)->compartment();
|
||||
}
|
||||
|
||||
#endif /* jsgc_h___ */
|
||||
|
|
|
@ -6207,7 +6207,7 @@ js_TraceObject(JSTracer *trc, JSObject *obj)
|
|||
(void) clasp->mark(cx, obj, trc);
|
||||
}
|
||||
if (clasp->flags & JSCLASS_IS_GLOBAL) {
|
||||
JSCompartment *compartment = obj->getCompartment(cx);
|
||||
JSCompartment *compartment = obj->getCompartment();
|
||||
compartment->marked = true;
|
||||
}
|
||||
|
||||
|
@ -6326,41 +6326,6 @@ js_ReportGetterOnlyAssignment(JSContext *cx)
|
|||
JSMSG_GETTER_ONLY);
|
||||
}
|
||||
|
||||
JSCompartment *
|
||||
JSObject::getCompartment(JSContext *cx)
|
||||
{
|
||||
JSObject *obj = getGlobal();
|
||||
|
||||
Class *clasp = obj->getClass();
|
||||
if (!(clasp->flags & JSCLASS_IS_GLOBAL)) {
|
||||
#if JS_HAS_XML_SUPPORT
|
||||
// The magic AnyName object is runtime-wide.
|
||||
if (clasp == &js_AnyNameClass)
|
||||
return cx->runtime->defaultCompartment;
|
||||
|
||||
// The magic function namespace object is runtime-wide.
|
||||
if (clasp == &js_NamespaceClass &&
|
||||
obj->getNameURI() == ATOM_TO_JSVAL(cx->runtime->
|
||||
atomState.functionNamespaceURIAtom)) {
|
||||
return cx->runtime->defaultCompartment;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Script objects and compile-time Function, Block, RegExp objects
|
||||
* are not parented.
|
||||
*/
|
||||
if (clasp == &js_FunctionClass || clasp == &js_BlockClass || clasp == &js_RegExpClass ||
|
||||
clasp == &js_ScriptClass) {
|
||||
// This is a bogus answer, but it'll do for now.
|
||||
return cx->runtime->defaultCompartment;
|
||||
}
|
||||
JS_NOT_REACHED("non-global object at end of scope chain");
|
||||
}
|
||||
const Value &v = obj->getReservedSlot(JSRESERVED_GLOBAL_COMPARTMENT);
|
||||
return (JSCompartment *)v.toPrivate();
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSBool)
|
||||
js_GetterOnlyPropertyStub(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
{
|
||||
|
|
|
@ -1117,7 +1117,7 @@ struct JSObject : js::gc::Cell {
|
|||
|
||||
inline void dropProperty(JSContext *cx, JSProperty *prop);
|
||||
|
||||
JS_FRIEND_API(JSCompartment *) getCompartment(JSContext *cx);
|
||||
inline JSCompartment *getCompartment() const;
|
||||
|
||||
inline JSObject *getThrowTypeError() const;
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ AutoCompartment::AutoCompartment(JSContext *cx, JSObject *target)
|
|||
: context(cx),
|
||||
origin(cx->compartment),
|
||||
target(target),
|
||||
destination(target->getCompartment(cx)),
|
||||
destination(target->getCompartment()),
|
||||
input(cx),
|
||||
entered(false)
|
||||
{
|
||||
|
|
|
@ -1010,7 +1010,7 @@ xpc_CreateGlobalObject(JSContext *cx, JSClass *clasp,
|
|||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
|
||||
*global = tempGlobal;
|
||||
*compartment = tempGlobal->getCompartment(cx);
|
||||
*compartment = tempGlobal->getCompartment();
|
||||
|
||||
js::SwitchToCompartment sc(cx, *compartment);
|
||||
|
||||
|
|
|
@ -1193,8 +1193,8 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
|
|||
}
|
||||
else if(IS_SLIM_WRAPPER_OBJECT(flat))
|
||||
{
|
||||
if(flat->getCompartment(cx) ==
|
||||
xpcscope->GetGlobalJSObject()->getCompartment(cx))
|
||||
if(flat->getCompartment() ==
|
||||
xpcscope->GetGlobalJSObject()->getCompartment())
|
||||
{
|
||||
*d = OBJECT_TO_JSVAL(flat);
|
||||
return JS_TRUE;
|
||||
|
|
|
@ -258,7 +258,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(XPCCallContext& ccx,
|
|||
// interface (i.e. whether the interface is scriptable) and most content
|
||||
// objects don't have QI implementations anyway. Also see bug 503926.
|
||||
if(XPCPerThreadData::IsMainThread(ccx) &&
|
||||
!xpc::AccessCheck::isChrome(jsobj->getCompartment(ccx)))
|
||||
!xpc::AccessCheck::isChrome(jsobj->getCompartment()))
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
@ -1328,7 +1328,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
|
|||
if(ssm)
|
||||
{
|
||||
nsIPrincipal *objPrincipal =
|
||||
xpc::AccessCheck::getPrincipal(obj->getCompartment(ccx));
|
||||
xpc::AccessCheck::getPrincipal(obj->getCompartment());
|
||||
if(objPrincipal)
|
||||
{
|
||||
JSStackFrame* fp = nsnull;
|
||||
|
|
|
@ -519,8 +519,8 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
|||
nsCOMPtr<nsIXPConnectWrappedJS> wrappedjs(do_QueryInterface(Object));
|
||||
JSObject *obj;
|
||||
wrappedjs->GetJSObject(&obj);
|
||||
if(xpc::AccessCheck::isChrome(obj->getCompartment(ccx)) &&
|
||||
!xpc::AccessCheck::isChrome(Scope->GetGlobalJSObject()->getCompartment(ccx)))
|
||||
if(xpc::AccessCheck::isChrome(obj->getCompartment()) &&
|
||||
!xpc::AccessCheck::isChrome(Scope->GetGlobalJSObject()->getCompartment()))
|
||||
{
|
||||
needsCOW = JS_TRUE;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ CrossOriginWrapper::enter(JSContext *cx, JSObject *wrapper, jsid id, Action act)
|
|||
return true;
|
||||
}
|
||||
JSStackFrame *fp = NULL;
|
||||
nsIPrincipal *principal = GetCompartmentPrincipal(wrappedObject(wrapper)->getCompartment(cx));
|
||||
nsIPrincipal *principal = GetCompartmentPrincipal(wrappedObject(wrapper)->getCompartment());
|
||||
nsresult rv = ssm->PushContextPrincipal(cx, JS_FrameIterator(cx, &fp), principal);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Not allowing call because we're out of memory");
|
||||
|
|
|
@ -80,7 +80,7 @@ WrapperFactory::Rewrap(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSO
|
|||
if (!obj)
|
||||
return nsnull;
|
||||
|
||||
JSCompartment *origin = obj->getCompartment(cx);
|
||||
JSCompartment *origin = obj->getCompartment();
|
||||
JSCompartment *target = cx->compartment;
|
||||
JSObject *xrayHolder = nsnull;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче