mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 711859 - Add an IsObjectInContextCompartment API; seems-better-than-the-alternative-all-things-considered=Waldo
This commit is contained in:
parent
6aaac66913
commit
3483b813ea
@ -214,6 +214,12 @@ js::GetObjectSlotSpan(const JSObject *obj)
|
||||
return obj->slotSpan();
|
||||
}
|
||||
|
||||
JS_FRIEND_API(bool)
|
||||
js::IsObjectInContextCompartment(const JSObject *obj, const JSContext *cx)
|
||||
{
|
||||
return obj->compartment() == cx->compartment;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(bool)
|
||||
js::IsOriginalScriptFunction(JSFunction *fun)
|
||||
{
|
||||
|
@ -411,6 +411,9 @@ StringIsArrayIndex(JSLinearString *str, jsuint *indexp);
|
||||
JS_FRIEND_API(void)
|
||||
SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback);
|
||||
|
||||
JS_FRIEND_API(bool)
|
||||
IsObjectInContextCompartment(const JSObject *obj, const JSContext *cx);
|
||||
|
||||
/*
|
||||
* NB: these flag bits are encoded into the bytecode stream in the immediate
|
||||
* operand of JSOP_ITER, so don't change them without advancing jsxdrapi.h's
|
||||
|
@ -160,7 +160,7 @@ XPCConvert::NativeData2JS(XPCLazyCallContext& lccx, jsval* d, const void* s,
|
||||
// Allow wrong compartment or unset ScopeForNewObject when the caller knows
|
||||
// the value is primitive (viz., XPCNativeMember::GetConstantValue).
|
||||
NS_ABORT_IF_FALSE(type.IsArithmetic() ||
|
||||
cx->compartment == js::GetObjectCompartment(lccx.GetScopeForNewJSObjects()),
|
||||
js::IsObjectInContextCompartment(lccx.GetScopeForNewJSObjects(), cx),
|
||||
"bad scope for new JSObjects");
|
||||
|
||||
if (pErr)
|
||||
@ -933,7 +933,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
|
||||
// optimal -- we could detect this and roll the functionality into a
|
||||
// single wrapper, but the current solution is good enough for now.
|
||||
JSContext* cx = lccx.GetJSContext();
|
||||
NS_ABORT_IF_FALSE(js::GetObjectCompartment(lccx.GetScopeForNewJSObjects()) == cx->compartment,
|
||||
NS_ABORT_IF_FALSE(js::IsObjectInContextCompartment(lccx.GetScopeForNewJSObjects(), cx),
|
||||
"bad scope for new JSObjects");
|
||||
|
||||
JSObject *jsscope = lccx.GetScopeForNewJSObjects();
|
||||
@ -979,7 +979,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
|
||||
if (!flat) {
|
||||
tryConstructSlimWrapper = true;
|
||||
} else if (IS_SLIM_WRAPPER_OBJECT(flat)) {
|
||||
if (js::GetObjectCompartment(flat) == cx->compartment) {
|
||||
if (js::IsObjectInContextCompartment(flat, cx)) {
|
||||
*d = OBJECT_TO_JSVAL(flat);
|
||||
return true;
|
||||
}
|
||||
@ -1150,7 +1150,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
|
||||
} else {
|
||||
flat = JS_ObjectToOuterObject(cx, flat);
|
||||
NS_ASSERTION(flat, "bad outer object hook!");
|
||||
NS_ASSERTION(js::GetObjectCompartment(flat) == cx->compartment,
|
||||
NS_ASSERTION(js::IsObjectInContextCompartment(flat, cx),
|
||||
"bad compartment");
|
||||
}
|
||||
}
|
||||
@ -1584,7 +1584,7 @@ XPCConvert::NativeArray2JS(XPCLazyCallContext& lccx,
|
||||
return false;
|
||||
|
||||
JSContext* cx = ccx.GetJSContext();
|
||||
NS_ABORT_IF_FALSE(js::GetObjectCompartment(lccx.GetScopeForNewJSObjects()) == cx->compartment,
|
||||
NS_ABORT_IF_FALSE(js::IsObjectInContextCompartment(lccx.GetScopeForNewJSObjects(), cx),
|
||||
"bad scope for new JSObjects");
|
||||
|
||||
// XXX add support for putting chars in a string rather than an array
|
||||
|
@ -164,7 +164,7 @@ inline void
|
||||
XPCCallContext::SetScopeForNewJSObjects(JSObject *scope)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(mState == HAVE_CONTEXT, "wrong call context state");
|
||||
NS_ABORT_IF_FALSE(js::GetObjectCompartment(scope) == mJSContext->compartment, "wrong compartment");
|
||||
NS_ABORT_IF_FALSE(js::IsObjectInContextCompartment(scope, mJSContext), "wrong compartment");
|
||||
mScopeForNewJSObjects = scope;
|
||||
mState = HAVE_SCOPE;
|
||||
}
|
||||
|
@ -466,7 +466,7 @@ XPCVariant::VariantDataToJS(XPCLazyCallContext& lccx,
|
||||
JSBool success;
|
||||
|
||||
JSContext* cx = lccx.GetJSContext();
|
||||
NS_ABORT_IF_FALSE(js::GetObjectCompartment(lccx.GetScopeForNewJSObjects()) == cx->compartment,
|
||||
NS_ABORT_IF_FALSE(js::IsObjectInContextCompartment(lccx.GetScopeForNewJSObjects(), cx),
|
||||
"bad scope for new JSObjects");
|
||||
|
||||
switch (type) {
|
||||
|
@ -3683,7 +3683,7 @@ ConstructSlimWrapper(XPCCallContext &ccx,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ccx.GetJSContext()->compartment != js::GetObjectCompartment(parent)) {
|
||||
if (!js::IsObjectInContextCompartment(parent, ccx.GetJSContext())) {
|
||||
SLIM_LOG_NOT_CREATED(ccx, identityObj, "wrong compartment");
|
||||
|
||||
return false;
|
||||
|
@ -437,7 +437,7 @@ WrapperFactory::WaiveXrayAndWrap(JSContext *cx, jsval *vp)
|
||||
|
||||
JSObject *obj = js::UnwrapObject(JSVAL_TO_OBJECT(*vp));
|
||||
obj = GetCurrentOuter(cx, obj);
|
||||
if (js::GetObjectCompartment(obj) == cx->compartment) {
|
||||
if (js::IsObjectInContextCompartment(obj, cx)) {
|
||||
*vp = OBJECT_TO_JSVAL(obj);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user