Bug 981218 - Remove default compartment objects. r=luke
\o/
This commit is contained in:
@@ -1572,10 +1572,6 @@ public:
|
||||
static nsresult CheckSameOrigin(nsIChannel *aOldChannel, nsIChannel *aNewChannel);
|
||||
static nsIInterfaceRequestor* GetSameOriginChecker();
|
||||
|
||||
// Trace the safe JS context.
|
||||
static void TraceSafeJSContext(JSTracer* aTrc);
|
||||
|
||||
|
||||
/**
|
||||
* Get the Origin of the passed in nsIPrincipal or nsIURI. If the passed in
|
||||
* nsIURI or the URI of the passed in nsIPrincipal does not have a host, the
|
||||
|
||||
@@ -484,7 +484,4 @@ mozilla::dom::TraceBlackJS(JSTracer* aTrc, uint32_t aGCNumber, bool aIsShutdownG
|
||||
if (windowsById) {
|
||||
windowsById->Enumerate(TraceActiveWindowGlobal, &closure);
|
||||
}
|
||||
|
||||
// Mark the safe context black
|
||||
nsContentUtils::TraceSafeJSContext(aTrc);
|
||||
}
|
||||
|
||||
@@ -1936,21 +1936,6 @@ nsContentUtils::InProlog(nsINode *aNode)
|
||||
return !root || doc->IndexOf(aNode) < doc->IndexOf(root);
|
||||
}
|
||||
|
||||
//static
|
||||
void
|
||||
nsContentUtils::TraceSafeJSContext(JSTracer* aTrc)
|
||||
{
|
||||
JSContext* cx = GetSafeJSContext();
|
||||
if (!cx) {
|
||||
return;
|
||||
}
|
||||
if (JSObject* global = js::DefaultObjectForContextOrNull(cx)) {
|
||||
JS::AssertGCThingMustBeTenured(global);
|
||||
JS_CallUnbarrieredObjectTracer(aTrc, &global, "safe context");
|
||||
MOZ_ASSERT(global == js::DefaultObjectForContextOrNull(cx));
|
||||
}
|
||||
}
|
||||
|
||||
nsIDocument*
|
||||
nsContentUtils::GetDocumentFromCaller()
|
||||
{
|
||||
|
||||
@@ -741,8 +741,7 @@ nsJSContext::nsJSContext(bool aGCOnDestruction,
|
||||
::JS_SetContextPrivate(mContext, static_cast<nsIScriptContext *>(this));
|
||||
|
||||
// Make sure the new context gets the default context options
|
||||
JS::ContextOptionsRef(mContext).setPrivateIsNSISupports(true)
|
||||
.setNoDefaultCompartmentObject(true);
|
||||
JS::ContextOptionsRef(mContext).setPrivateIsNSISupports(true);
|
||||
|
||||
// Watch for the JS boolean options
|
||||
Preferences::RegisterCallback(JSOptionChangedCallback,
|
||||
|
||||
@@ -1139,7 +1139,6 @@ JS_InitStandardClasses(JSContext *cx, HandleObject obj)
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
cx->setDefaultCompartmentObjectIfUnset(obj);
|
||||
assertSameCompartment(cx, obj);
|
||||
|
||||
Rooted<GlobalObject*> global(cx, &obj->global());
|
||||
|
||||
@@ -1530,8 +1530,7 @@ class JS_PUBLIC_API(ContextOptions) {
|
||||
public:
|
||||
ContextOptions()
|
||||
: privateIsNSISupports_(false),
|
||||
dontReportUncaught_(false),
|
||||
noDefaultCompartmentObject_(false)
|
||||
dontReportUncaught_(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1555,20 +1554,9 @@ class JS_PUBLIC_API(ContextOptions) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool noDefaultCompartmentObject() const { return noDefaultCompartmentObject_; }
|
||||
ContextOptions &setNoDefaultCompartmentObject(bool flag) {
|
||||
noDefaultCompartmentObject_ = flag;
|
||||
return *this;
|
||||
}
|
||||
ContextOptions &toggleNoDefaultCompartmentObject() {
|
||||
noDefaultCompartmentObject_ = !noDefaultCompartmentObject_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
bool privateIsNSISupports_ : 1;
|
||||
bool dontReportUncaught_ : 1;
|
||||
bool noDefaultCompartmentObject_ : 1;
|
||||
};
|
||||
|
||||
JS_PUBLIC_API(ContextOptions &)
|
||||
|
||||
@@ -1103,7 +1103,6 @@ JSContext::JSContext(JSRuntime *rt)
|
||||
resolvingList(nullptr),
|
||||
generatingError(false),
|
||||
savedFrameChains_(),
|
||||
defaultCompartmentObject_(nullptr),
|
||||
cycleDetectorSet(MOZ_THIS_IN_INITIALIZER_LIST()),
|
||||
errorReporter(nullptr),
|
||||
data(nullptr),
|
||||
@@ -1300,8 +1299,6 @@ JSContext::mark(JSTracer *trc)
|
||||
/* Stack frames and slots are traced by StackSpace::mark. */
|
||||
|
||||
/* Mark other roots-by-definition in the JSContext. */
|
||||
if (defaultCompartmentObject_)
|
||||
MarkObjectRoot(trc, &defaultCompartmentObject_, "default compartment object");
|
||||
if (isExceptionPending())
|
||||
MarkValueRoot(trc, &unwrappedException_, "unwrapped exception");
|
||||
|
||||
|
||||
@@ -455,21 +455,7 @@ struct JSContext : public js::ExclusiveContext,
|
||||
bool saveFrameChain();
|
||||
void restoreFrameChain();
|
||||
|
||||
/*
|
||||
* When no compartments have been explicitly entered, the context's
|
||||
* compartment will be set to the compartment of the "default compartment
|
||||
* object".
|
||||
*/
|
||||
private:
|
||||
JSObject *defaultCompartmentObject_;
|
||||
public:
|
||||
inline void setDefaultCompartmentObject(JSObject *obj);
|
||||
inline void setDefaultCompartmentObjectIfUnset(JSObject *obj);
|
||||
JSObject *maybeDefaultCompartmentObject() const {
|
||||
JS_ASSERT(!options().noDefaultCompartmentObject());
|
||||
return defaultCompartmentObject_;
|
||||
}
|
||||
|
||||
/* State for object and array toSource conversion. */
|
||||
js::ObjectSet cycleDetectorSet;
|
||||
|
||||
|
||||
@@ -380,23 +380,6 @@ JSContext::runningWithTrustedPrincipals() const
|
||||
return !compartment() || compartment()->principals == runtime()->trustedPrincipals();
|
||||
}
|
||||
|
||||
inline void
|
||||
JSContext::setDefaultCompartmentObject(JSObject *obj)
|
||||
{
|
||||
JS_ASSERT(!options().noDefaultCompartmentObject());
|
||||
defaultCompartmentObject_ = obj;
|
||||
}
|
||||
|
||||
inline void
|
||||
JSContext::setDefaultCompartmentObjectIfUnset(JSObject *obj)
|
||||
{
|
||||
if (!options().noDefaultCompartmentObject() &&
|
||||
!defaultCompartmentObject_)
|
||||
{
|
||||
setDefaultCompartmentObject(obj);
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
js::ExclusiveContext::enterCompartment(JSCompartment *c)
|
||||
{
|
||||
|
||||
@@ -416,20 +416,6 @@ js::AssertSameCompartment(JSObject *objA, JSObject *objB)
|
||||
}
|
||||
#endif
|
||||
|
||||
JS_FRIEND_API(JSObject *)
|
||||
js::DefaultObjectForContextOrNull(JSContext *cx)
|
||||
{
|
||||
if (cx->options().noDefaultCompartmentObject())
|
||||
return nullptr;
|
||||
return cx->maybeDefaultCompartmentObject();
|
||||
}
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
js::SetDefaultObjectForContext(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
cx->setDefaultCompartmentObject(obj);
|
||||
}
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
js::NotifyAnimationActivity(JSObject *obj)
|
||||
{
|
||||
|
||||
@@ -721,13 +721,6 @@ AssertSameCompartment(JSObject *objA, JSObject *objB);
|
||||
inline void AssertSameCompartment(JSObject *objA, JSObject *objB) {}
|
||||
#endif
|
||||
|
||||
// For legacy consumers only. This whole concept is going away soon.
|
||||
JS_FRIEND_API(JSObject *)
|
||||
DefaultObjectForContextOrNull(JSContext *cx);
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
SetDefaultObjectForContext(JSContext *cx, JSObject *obj);
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
NotifyAnimationActivity(JSObject *obj);
|
||||
|
||||
|
||||
@@ -96,7 +96,6 @@ static JSObject *
|
||||
CreateObjectPrototype(JSContext *cx, JSProtoKey key)
|
||||
{
|
||||
Rooted<GlobalObject*> self(cx, cx->global());
|
||||
cx->setDefaultCompartmentObjectIfUnset(self);
|
||||
|
||||
JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
|
||||
JS_ASSERT(self->isNative());
|
||||
|
||||
@@ -986,10 +986,6 @@ JSRuntime::initSelfHosting(JSContext *cx)
|
||||
*/
|
||||
JS::AutoDisableGenerationalGC disable(cx->runtime());
|
||||
|
||||
bool receivesDefaultObject = !cx->options().noDefaultCompartmentObject();
|
||||
RootedObject savedGlobal(cx, receivesDefaultObject
|
||||
? js::DefaultObjectForContextOrNull(cx)
|
||||
: nullptr);
|
||||
JS::CompartmentOptions compartmentOptions;
|
||||
compartmentOptions.setDiscardSource(true);
|
||||
if (!(selfHostingGlobal_ = JS_NewGlobalObject(cx, &self_hosting_global_class,
|
||||
@@ -997,8 +993,6 @@ JSRuntime::initSelfHosting(JSContext *cx)
|
||||
compartmentOptions)))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, selfHostingGlobal_);
|
||||
if (receivesDefaultObject)
|
||||
js::SetDefaultObjectForContext(cx, selfHostingGlobal_);
|
||||
Rooted<GlobalObject*> shg(cx, &selfHostingGlobal_->as<GlobalObject>());
|
||||
selfHostingGlobal_->compartment()->isSelfHosting = true;
|
||||
selfHostingGlobal_->compartment()->isSystem = true;
|
||||
@@ -1047,8 +1041,6 @@ JSRuntime::initSelfHosting(JSContext *cx)
|
||||
ok = Evaluate(cx, shg, options, src, srcLen, &rv);
|
||||
}
|
||||
JS_SetErrorReporter(cx, oldReporter);
|
||||
if (receivesDefaultObject)
|
||||
js::SetDefaultObjectForContext(cx, savedGlobal);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,6 @@ XPCJSContextStack::InitSafeJSContext()
|
||||
mSafeJSContext = JS_NewContext(XPCJSRuntime::Get()->Runtime(), 8192);
|
||||
if (!mSafeJSContext)
|
||||
MOZ_CRASH();
|
||||
ContextOptionsRef(mSafeJSContext).setNoDefaultCompartmentObject(true);
|
||||
JS_SetErrorReporter(mSafeJSContext, xpc::SystemErrorReporter);
|
||||
return mSafeJSContext;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user