mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 672893 - Don't #include jscompartment.h in xpconnect. r=cdleary.
This commit is contained in:
parent
4ac70e6801
commit
37a2d699c6
@ -60,9 +60,6 @@
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
|
||||
/* XXX private JS headers. */
|
||||
#include "jscompartment.h"
|
||||
|
||||
/*
|
||||
* defining CAUTIOUS_SCRIPTHOOK makes jsds disable GC while calling out to the
|
||||
* script hook. This was a hack to avoid some js engine problems that should
|
||||
|
@ -220,7 +220,6 @@ INSTALLED_HEADERS = \
|
||||
jscell.h \
|
||||
jsgcchunk.h \
|
||||
jsgcstats.h \
|
||||
jscompartment.h \
|
||||
jshash.h \
|
||||
jsinterp.h \
|
||||
jsinttypes.h \
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "jsfriendapi.h"
|
||||
|
||||
using namespace js;
|
||||
using namespace JS;
|
||||
|
||||
JS_FRIEND_API(JSString *)
|
||||
JS_GetAnonymousString(JSRuntime *rt)
|
||||
@ -81,6 +82,55 @@ JS_GetFrameScopeChainRaw(JSStackFrame *fp)
|
||||
return &Valueify(fp)->scopeChain();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSPrincipals *)
|
||||
JS_GetCompartmentPrincipals(JSCompartment *compartment)
|
||||
{
|
||||
return compartment->principals;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ClearDebugModeForCompartment(JSCompartment *compartment)
|
||||
{
|
||||
compartment->debugMode = false;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_WrapPropertyDescriptor(JSContext *cx, js::PropertyDescriptor *desc)
|
||||
{
|
||||
return cx->compartment->wrap(cx, desc);
|
||||
}
|
||||
|
||||
AutoPreserveCompartment::AutoPreserveCompartment(JSContext *cx
|
||||
JS_GUARD_OBJECT_NOTIFIER_PARAM_NO_INIT)
|
||||
: cx(cx), oldCompartment(cx->compartment)
|
||||
{
|
||||
}
|
||||
|
||||
AutoPreserveCompartment::~AutoPreserveCompartment()
|
||||
{
|
||||
cx->compartment = oldCompartment;
|
||||
}
|
||||
|
||||
AutoSwitchCompartment::AutoSwitchCompartment(JSContext *cx, JSCompartment *newCompartment
|
||||
JS_GUARD_OBJECT_NOTIFIER_PARAM_NO_INIT)
|
||||
: cx(cx), oldCompartment(cx->compartment)
|
||||
{
|
||||
cx->compartment = newCompartment;
|
||||
}
|
||||
|
||||
AutoSwitchCompartment::AutoSwitchCompartment(JSContext *cx, JSObject *target
|
||||
JS_GUARD_OBJECT_NOTIFIER_PARAM_NO_INIT)
|
||||
: cx(cx), oldCompartment(cx->compartment)
|
||||
{
|
||||
cx->compartment = target->compartment();
|
||||
}
|
||||
|
||||
AutoSwitchCompartment::~AutoSwitchCompartment()
|
||||
{
|
||||
cx->compartment = oldCompartment;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The below code is for temporary telemetry use. It can be removed when
|
||||
* sufficient data has been harvested.
|
||||
|
@ -66,6 +66,48 @@ JS_SetProtoCalled(JSContext *cx);
|
||||
extern JS_FRIEND_API(size_t)
|
||||
JS_GetCustomIteratorCount(JSContext *cx);
|
||||
|
||||
extern JS_PUBLIC_API(JSPrincipals *)
|
||||
JS_GetCompartmentPrincipals(JSCompartment *compartment);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ClearDebugModeForCompartment(JSCompartment *comp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_WrapPropertyDescriptor(JSContext *cx, js::PropertyDescriptor *desc);
|
||||
|
||||
#endif
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace JS {
|
||||
|
||||
class JS_PUBLIC_API(AutoPreserveCompartment) {
|
||||
private:
|
||||
JSContext *cx;
|
||||
JSCompartment *oldCompartment;
|
||||
public:
|
||||
AutoPreserveCompartment(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM);
|
||||
~AutoPreserveCompartment();
|
||||
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
class JS_PUBLIC_API(AutoSwitchCompartment) {
|
||||
private:
|
||||
JSContext *cx;
|
||||
JSCompartment *oldCompartment;
|
||||
public:
|
||||
AutoSwitchCompartment(JSContext *cx, JSCompartment *newCompartment
|
||||
JS_GUARD_OBJECT_NOTIFIER_PARAM);
|
||||
AutoSwitchCompartment(JSContext *cx, JSObject *target JS_GUARD_OBJECT_NOTIFIER_PARAM);
|
||||
~AutoSwitchCompartment();
|
||||
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* jsfriendapi_h___ */
|
||||
|
@ -74,7 +74,6 @@
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsDOMFile.h"
|
||||
#include "jsxdrapi.h"
|
||||
#include "jscompartment.h"
|
||||
#include "jsprf.h"
|
||||
// For reporting errors with the console service
|
||||
#include "nsIScriptError.h"
|
||||
@ -763,8 +762,8 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
|
||||
JSCLContextHelper cx(this);
|
||||
|
||||
// preserve caller's compartment
|
||||
js::PreserveCompartment pc(cx);
|
||||
|
||||
JS::AutoPreserveCompartment pc(cx);
|
||||
|
||||
rv = mSystemPrincipal->GetJSPrincipals(cx, &jsPrincipals);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -1059,7 +1059,7 @@ CreateNewCompartment(JSContext *cx, JSClass *clasp, nsIPrincipal *principal,
|
||||
*global = tempGlobal;
|
||||
*compartment = tempGlobal->compartment();
|
||||
|
||||
js::SwitchToCompartment sc(cx, *compartment);
|
||||
JS::AutoSwitchCompartment sc(cx, *compartment);
|
||||
JS_SetCompartmentPrivate(cx, *compartment, priv_holder.forget());
|
||||
return true;
|
||||
}
|
||||
@ -1091,7 +1091,7 @@ xpc_CreateGlobalObject(JSContext *cx, JSClass *clasp,
|
||||
}
|
||||
else
|
||||
{
|
||||
js::SwitchToCompartment sc(cx, *compartment);
|
||||
JS::AutoSwitchCompartment sc(cx, *compartment);
|
||||
|
||||
JSObject *tempGlobal = JS_NewGlobalObject(cx, clasp);
|
||||
if(!tempGlobal)
|
||||
@ -1128,7 +1128,7 @@ xpc_CreateMTGlobalObject(JSContext *cx, JSClass *clasp,
|
||||
}
|
||||
else
|
||||
{
|
||||
js::SwitchToCompartment sc(cx, *compartment);
|
||||
JS::AutoSwitchCompartment sc(cx, *compartment);
|
||||
|
||||
JSObject *tempGlobal = JS_NewGlobalObject(cx, clasp);
|
||||
if(!tempGlobal)
|
||||
@ -2559,7 +2559,7 @@ nsXPConnect::CheckForDebugMode(JSRuntime *rt) {
|
||||
js::CompartmentVector &vector = rt->compartments;
|
||||
for (JSCompartment **p = vector.begin(); p != vector.end(); ++p) {
|
||||
JSCompartment *comp = *p;
|
||||
if (!comp->principals) {
|
||||
if (!JS_GetCompartmentPrincipals(comp)) {
|
||||
/* Ignore special compartments (atoms, JSD compartments) */
|
||||
continue;
|
||||
}
|
||||
@ -2576,7 +2576,7 @@ nsXPConnect::CheckForDebugMode(JSRuntime *rt) {
|
||||
* Existing scripts will continue to call JSD callbacks,
|
||||
* which will have no effect.
|
||||
*/
|
||||
comp->debugMode = JS_FALSE;
|
||||
JS_ClearDebugModeForCompartment(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +105,8 @@ WrappedJSDyingJSObjectFinder(JSDHashTable *table, JSDHashEntryHdr *hdr,
|
||||
{
|
||||
if(wrapper->IsSubjectToFinalization())
|
||||
{
|
||||
js::SwitchToCompartment sc(data->cx,
|
||||
wrapper->GetJSObjectPreserveColor());
|
||||
JS::AutoSwitchCompartment sc(data->cx,
|
||||
wrapper->GetJSObjectPreserveColor());
|
||||
if(JS_IsAboutToBeFinalized(data->cx,
|
||||
wrapper->GetJSObjectPreserveColor()))
|
||||
data->array->AppendElement(wrapper);
|
||||
|
@ -58,8 +58,8 @@
|
||||
#include "jsinterp.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsdbgapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "jsgc.h"
|
||||
#include "jscompartment.h"
|
||||
#include "nscore.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
@ -442,7 +442,7 @@ XPCWrappedNativeScope::FinishedMarkPhaseOfGC(JSContext* cx, XPCJSRuntime* rt)
|
||||
{
|
||||
XPCWrappedNativeScope* next = cur->mNext;
|
||||
|
||||
js::SwitchToCompartment sc(cx, cur->mGlobalJSObject);
|
||||
JS::AutoSwitchCompartment sc(cx, cur->mGlobalJSObject);
|
||||
|
||||
if(cur->mGlobalJSObject &&
|
||||
JS_IsAboutToBeFinalized(cx, cur->mGlobalJSObject))
|
||||
|
@ -53,10 +53,11 @@
|
||||
|
||||
namespace xpc {
|
||||
|
||||
static nsIPrincipal *
|
||||
nsIPrincipal *
|
||||
GetCompartmentPrincipal(JSCompartment *compartment)
|
||||
{
|
||||
return compartment->principals ? static_cast<nsJSPrincipals *>(compartment->principals)->nsIPrincipalPtr : 0;
|
||||
JSPrincipals *prin = JS_GetCompartmentPrincipals(compartment);
|
||||
return prin ? static_cast<nsJSPrincipals *>(prin)->nsIPrincipalPtr : nsnull;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -44,6 +44,9 @@ class nsIPrincipal;
|
||||
|
||||
namespace xpc {
|
||||
|
||||
nsIPrincipal *
|
||||
GetCompartmentPrincipal(JSCompartment *compartment);
|
||||
|
||||
class AccessCheck {
|
||||
public:
|
||||
static bool isSameOrigin(JSCompartment *a, JSCompartment *b);
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "XPCWrapper.h"
|
||||
|
||||
#include "CrossOriginWrapper.h"
|
||||
#include "AccessCheck.h"
|
||||
#include "WrapperFactory.h"
|
||||
|
||||
namespace xpc {
|
||||
@ -62,12 +63,6 @@ CrossOriginWrapper::~CrossOriginWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
static nsIPrincipal *
|
||||
GetCompartmentPrincipal(JSCompartment *compartment)
|
||||
{
|
||||
return static_cast<nsJSPrincipals *>(compartment->principals)->nsIPrincipalPtr;
|
||||
}
|
||||
|
||||
bool
|
||||
CrossOriginWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
|
||||
bool set, js::PropertyDescriptor *desc)
|
||||
|
@ -265,7 +265,8 @@ WrapperFactory::Rewrap(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSO
|
||||
JSObject *xrayHolder = nsnull;
|
||||
|
||||
JSWrapper *wrapper;
|
||||
CompartmentPrivate *targetdata = static_cast<CompartmentPrivate *>(target->data);
|
||||
CompartmentPrivate *targetdata =
|
||||
static_cast<CompartmentPrivate *>(JS_GetCompartmentPrivate(cx, target));
|
||||
if (AccessCheck::isChrome(target)) {
|
||||
if (AccessCheck::isChrome(origin)) {
|
||||
wrapper = &JSCrossCompartmentWrapper::singleton;
|
||||
|
@ -556,7 +556,7 @@ XrayWrapper<Base>::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid
|
||||
|
||||
if (desc->obj)
|
||||
desc->obj = wrapper;
|
||||
return cx->compartment->wrap(cx, desc_in);
|
||||
return JS_WrapPropertyDescriptor(cx, desc_in);
|
||||
}
|
||||
|
||||
if (!this->resolveOwnProperty(cx, wrapper, id, set, desc_in))
|
||||
@ -627,7 +627,7 @@ XrayWrapper<Base>::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, js
|
||||
}
|
||||
|
||||
desc->obj = (desc->obj == wnObject) ? wrapper : nsnull;
|
||||
return cx->compartment->wrap(cx, desc_in);
|
||||
return JS_WrapPropertyDescriptor(cx, desc_in);
|
||||
}
|
||||
|
||||
return this->resolveOwnProperty(cx, wrapper, id, set, desc_in);
|
||||
@ -649,7 +649,7 @@ XrayWrapper<Base>::defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
|
||||
if (!ac.enter(cx, wnObject))
|
||||
return false;
|
||||
|
||||
if (!cx->compartment->wrap(cx, desc))
|
||||
if (!JS_WrapPropertyDescriptor(cx, desc))
|
||||
return false;
|
||||
|
||||
return JS_DefinePropertyById(cx, wnObject, id, jsdesc->value, jsdesc->getter, jsdesc->setter,
|
||||
|
Loading…
Reference in New Issue
Block a user