mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 625199 - s/JSAutoEnterCompartment/JSAutoCompartment/ and make it infallible (r=bholley)
--HG-- extra : rebase_source : 12acf2288285f5caefd7fecea8207de3a47eab5b
This commit is contained in:
parent
18c0268620
commit
94264a0bc8
@ -1775,10 +1775,7 @@ nsContentUtils::GetDocumentFromCaller()
|
||||
sXPConnect->GetCaller(&cx, &obj);
|
||||
NS_ASSERTION(cx && obj, "Caller ensures something is running");
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj)) {
|
||||
return nullptr;
|
||||
}
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> win =
|
||||
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(cx, obj));
|
||||
@ -6887,10 +6884,7 @@ nsContentUtils::JSArrayToAtomArray(JSContext* aCx, const JS::Value& aJSArray,
|
||||
}
|
||||
|
||||
JSObject* obj = &aJSArray.toObject();
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(aCx, obj)) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
JSAutoCompartment ac(aCx, obj);
|
||||
|
||||
uint32_t length;
|
||||
if (!JS_IsArrayObject(aCx, obj) || !JS_GetArrayLength(aCx, obj, &length)) {
|
||||
|
@ -416,10 +416,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
||||
NS_ENSURE_STATE(pusher.Push(ctx, false));
|
||||
|
||||
JSAutoRequest ar(ctx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(ctx, object))
|
||||
return NS_ERROR_FAILURE;
|
||||
JSAutoCompartment ac(ctx, object);
|
||||
|
||||
// The parameter for the listener function.
|
||||
JSObject* param = JS_NewObject(ctx, NULL, NULL, NULL);
|
||||
@ -501,12 +498,10 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
||||
argv.set(OBJECT_TO_JSVAL(param));
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment tac;
|
||||
|
||||
JSObject* thisObject = JSVAL_TO_OBJECT(thisValue);
|
||||
|
||||
if (!tac.enter(ctx, thisObject) ||
|
||||
!JS_WrapValue(ctx, argv.jsval_addr()))
|
||||
JSAutoCompartment tac(ctx, thisObject);
|
||||
if (!JS_WrapValue(ctx, argv.jsval_addr()))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
JS_CallFunctionValue(ctx, thisObject,
|
||||
@ -830,8 +825,8 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
|
||||
JSAutoRequest ar(mCx);
|
||||
JSObject* global = nullptr;
|
||||
mGlobal->GetJSObject(&global);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (global && ac.enter(mCx, global)) {
|
||||
if (global) {
|
||||
JSAutoCompartment ac(mCx, global);
|
||||
uint32_t oldopts = JS_GetOptions(mCx);
|
||||
JS_SetOptions(mCx, oldopts | JSOPTION_NO_SCRIPT_RVAL);
|
||||
|
||||
|
@ -2665,8 +2665,7 @@ GetRequestBody(nsIVariant* aBody, nsIInputStream** aResult,
|
||||
// ArrayBuffer?
|
||||
jsval realVal;
|
||||
nsCxPusher pusher;
|
||||
JSAutoEnterCompartment ac;
|
||||
JSObject* obj;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
|
||||
// If there's a context on the stack, we can just use it. Otherwise, we need
|
||||
// to use the safe js context (and push it into the stack, so that it's
|
||||
@ -2680,12 +2679,13 @@ GetRequestBody(nsIVariant* aBody, nsIInputStream** aResult,
|
||||
}
|
||||
|
||||
nsresult rv = aBody->GetAsJSVal(&realVal);
|
||||
if (NS_SUCCEEDED(rv) && !JSVAL_IS_PRIMITIVE(realVal) &&
|
||||
(obj = JSVAL_TO_OBJECT(realVal)) &&
|
||||
ac.enter(cx, obj) &&
|
||||
(JS_IsArrayBufferObject(obj, cx))) {
|
||||
ArrayBuffer buf(cx, obj);
|
||||
return GetRequestBody(&buf, aResult, aContentType, aCharset);
|
||||
if (NS_SUCCEEDED(rv) && !JSVAL_IS_PRIMITIVE(realVal)) {
|
||||
JSObject *obj = JSVAL_TO_OBJECT(realVal);
|
||||
ac.construct(cx, obj);
|
||||
if (JS_IsArrayBufferObject(obj, cx)) {
|
||||
ArrayBuffer buf(cx, obj);
|
||||
return GetRequestBody(&buf, aResult, aContentType, aCharset);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (dataType == nsIDataType::VTYPE_VOID ||
|
||||
|
@ -1039,10 +1039,7 @@ nsEventListenerManager::SetJSEventListenerToJsval(nsIAtom *aEventName,
|
||||
}
|
||||
|
||||
// Now ensure that we're working in the compartment of aScope from now on.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, aScope)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
JSAutoCompartment ac(cx, aScope);
|
||||
|
||||
// Rewrap the handler into the new compartment, if needed.
|
||||
jsval tempVal = v;
|
||||
|
@ -67,15 +67,16 @@ NS_IMPL_ISUPPORTS1(nsEventListenerService, nsIEventListenerService)
|
||||
|
||||
// Caller must root *aJSVal!
|
||||
bool
|
||||
nsEventListenerInfo::GetJSVal(JSContext* aCx, JSAutoEnterCompartment& aAc, jsval* aJSVal)
|
||||
nsEventListenerInfo::GetJSVal(JSContext* aCx, mozilla::Maybe<JSAutoCompartment>& aAc, jsval* aJSVal)
|
||||
{
|
||||
*aJSVal = JSVAL_NULL;
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS = do_QueryInterface(mListener);
|
||||
if (wrappedJS) {
|
||||
JSObject* object = nullptr;
|
||||
if (NS_FAILED(wrappedJS->GetJSObject(&object)) || !aAc.enter(aCx, object)) {
|
||||
if (NS_FAILED(wrappedJS->GetJSObject(&object))) {
|
||||
return false;
|
||||
}
|
||||
aAc.construct(aCx, object);
|
||||
*aJSVal = OBJECT_TO_JSVAL(object);
|
||||
return true;
|
||||
}
|
||||
@ -84,9 +85,7 @@ nsEventListenerInfo::GetJSVal(JSContext* aCx, JSAutoEnterCompartment& aAc, jsval
|
||||
if (jsl) {
|
||||
JSObject *handler = jsl->GetHandler();
|
||||
if (handler) {
|
||||
if (!aAc.enter(aCx, handler)) {
|
||||
return false;
|
||||
}
|
||||
aAc.construct(aCx, handler);
|
||||
*aJSVal = OBJECT_TO_JSVAL(handler);
|
||||
return true;
|
||||
}
|
||||
@ -107,7 +106,7 @@ nsEventListenerInfo::ToSource(nsAString& aResult)
|
||||
{
|
||||
// Extra block to finish the auto request before calling pop
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
mozilla::Maybe<JSAutoCompartment> ac;
|
||||
jsval v = JSVAL_NULL;
|
||||
if (GetJSVal(cx, ac, &v)) {
|
||||
JSString* str = JS_ValueToSource(cx, v);
|
||||
@ -149,7 +148,7 @@ nsEventListenerInfo::GetDebugObject(nsISupports** aRetVal)
|
||||
{
|
||||
// Extra block to finish the auto request before calling pop
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
mozilla::Maybe<JSAutoCompartment> ac;
|
||||
jsval v = JSVAL_NULL;
|
||||
if (GetJSVal(cx, ac, &v)) {
|
||||
nsCOMPtr<jsdIValue> jsdValue;
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsEventListenerInfo)
|
||||
NS_DECL_NSIEVENTLISTENERINFO
|
||||
protected:
|
||||
bool GetJSVal(JSContext* aCx, JSAutoEnterCompartment& aAc, jsval* aJSVal);
|
||||
bool GetJSVal(JSContext* aCx, mozilla::Maybe<JSAutoCompartment>& aAc, jsval* aJSVal);
|
||||
|
||||
nsString mType;
|
||||
// nsReftPtr because that is what nsListenerStruct uses too.
|
||||
|
@ -171,10 +171,7 @@ nsresult nsDOMStringMap::RemovePropInternal(nsIAtom* aAttr)
|
||||
this, &val);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, JSVAL_TO_OBJECT(val))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(val));
|
||||
|
||||
// Guard against infinite recursion. Prevents the stack from looking like
|
||||
// ...
|
||||
|
@ -169,10 +169,7 @@ InstallXBLField(JSContext* cx,
|
||||
nsXBLPrototypeBinding* protoBinding;
|
||||
nsDependentJSString fieldName;
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, callee)) {
|
||||
return false;
|
||||
}
|
||||
JSAutoCompartment ac(cx, callee);
|
||||
|
||||
JS::Rooted<JSObject*> xblProto(cx);
|
||||
xblProto = &js::GetFunctionNativeReserved(callee, XBLPROTO_SLOT).toObject();
|
||||
@ -1217,10 +1214,7 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen
|
||||
JSObject* base = scriptObject;
|
||||
JSObject* proto;
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, scriptObject)) {
|
||||
return;
|
||||
}
|
||||
JSAutoCompartment ac(cx, scriptObject);
|
||||
|
||||
for ( ; true; base = proto) { // Will break out on null proto
|
||||
proto = ::JS_GetPrototype(base);
|
||||
@ -1348,10 +1342,7 @@ nsXBLBinding::DoInitJSClass(JSContext *cx, JSObject *global, JSObject *obj,
|
||||
JSObject* parent_proto = nullptr; // If we have an "obj" we can set this
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, global)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, global);
|
||||
|
||||
if (obj) {
|
||||
// Retrieve the current prototype of obj.
|
||||
|
@ -118,11 +118,7 @@ nsXBLProtoImplMethod::InstallMember(nsIScriptContext* aContext,
|
||||
if (mJSMethodObject && aTargetClassObject) {
|
||||
nsDependentString name(mName);
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, globalObject)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
JSAutoCompartment ac(cx, globalObject);
|
||||
|
||||
JSObject * method = ::JS_CloneFunctionObject(cx, mJSMethodObject, globalObject);
|
||||
if (!method) {
|
||||
@ -310,10 +306,7 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
|
||||
JSObject* thisObject = JSVAL_TO_OBJECT(v);
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, thisObject))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
JSAutoCompartment ac(cx, thisObject);
|
||||
|
||||
// Clone the function object, using thisObject as the parent so "this" is in
|
||||
// the scope chain of the resulting function (for backwards compat to the
|
||||
|
@ -155,10 +155,7 @@ nsXBLProtoImplProperty::InstallMember(nsIScriptContext* aContext,
|
||||
if ((mJSGetterObject || mJSSetterObject) && aTargetClassObject) {
|
||||
JSObject * getter = nullptr;
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, globalObject))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
JSAutoCompartment ac(cx, globalObject);
|
||||
|
||||
if (mJSGetterObject)
|
||||
if (!(getter = ::JS_CloneFunctionObject(cx, mJSGetterObject, globalObject)))
|
||||
|
@ -5733,11 +5733,7 @@ BaseStubConstructor(nsIWeakReference* aWeakOwner,
|
||||
NS_ENSURE_STATE(pusher.Push(cx, false));
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, object)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, object);
|
||||
|
||||
JS::Value thisValue = JSVAL_VOID;
|
||||
JS::Value funval;
|
||||
@ -6536,11 +6532,7 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
|
||||
const char *class_parent_name = nullptr;
|
||||
|
||||
if (!primary_iid->Equals(NS_GET_IID(nsISupports))) {
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, class_obj)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, class_obj);
|
||||
|
||||
rv = DefineInterfaceConstants(cx, class_obj, primary_iid);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -6606,10 +6598,7 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
|
||||
JSObject *proto = nullptr;
|
||||
|
||||
if (class_parent_name) {
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, winobj)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
JSAutoCompartment ac(cx, winobj);
|
||||
|
||||
JS::Value val;
|
||||
if (!JS_LookupProperty(cx, winobj, CutPrefix(class_parent_name), &val)) {
|
||||
@ -6628,11 +6617,7 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
|
||||
}
|
||||
|
||||
if (dot_prototype) {
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, dot_prototype)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
JSAutoCompartment ac(cx, dot_prototype);
|
||||
JSObject *xpc_proto_proto = ::JS_GetPrototype(dot_prototype);
|
||||
|
||||
if (proto &&
|
||||
@ -6644,11 +6629,7 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, winobj)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
JSAutoCompartment ac(cx, winobj);
|
||||
dot_prototype = ::JS_NewObject(cx, &sDOMConstructorProtoClass, proto,
|
||||
winobj);
|
||||
NS_ENSURE_TRUE(dot_prototype, NS_ERROR_OUT_OF_MEMORY);
|
||||
@ -6657,10 +6638,7 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
|
||||
|
||||
v = OBJECT_TO_JSVAL(dot_prototype);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, class_obj)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
JSAutoCompartment ac(cx, class_obj);
|
||||
|
||||
// Per ECMA, the prototype property is {DontEnum, DontDelete, ReadOnly}
|
||||
if (!JS_WrapValue(cx, &v) ||
|
||||
@ -7094,7 +7072,7 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
JS::Value exn = JSVAL_VOID;
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
|
||||
JSContext* my_cx;
|
||||
if (!my_context) {
|
||||
@ -7103,9 +7081,7 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
my_cx = my_context->GetNativeContext();
|
||||
|
||||
if (my_cx != cx) {
|
||||
if (!ac.enter(my_cx, obj)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
ac.construct(my_cx, obj);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8333,13 +8309,7 @@ nsNamedArraySH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
realObj = obj;
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, realObj)) {
|
||||
*_retval = false;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSAutoCompartment ac(cx, realObj);
|
||||
JSObject *proto = ::JS_GetPrototype(realObj);
|
||||
|
||||
if (proto) {
|
||||
@ -9710,11 +9680,7 @@ nsHTMLPluginObjElementSH::SetupProtoChain(nsIXPConnectWrappedNative *wrapper,
|
||||
}
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
|
||||
nsRefPtr<nsNPAPIPluginInstance> pi;
|
||||
nsresult rv = GetPluginInstanceIfSafe(wrapper, obj, getter_AddRefs(pi));
|
||||
@ -9960,10 +9926,7 @@ nsHTMLPluginObjElementSH::GetPluginJSObject(JSContext *cx, JSObject *obj,
|
||||
// NB: We need an AutoEnterCompartment because we can be called from
|
||||
// nsObjectFrame when the plugin loads after the JS object for our content
|
||||
// node has been created.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
|
||||
if (plugin_inst) {
|
||||
plugin_inst->GetJSObject(cx, plugin_obj);
|
||||
@ -10303,11 +10266,7 @@ nsStorage2SH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||
JSObject *realObj;
|
||||
wrapper->GetJSObject(&realObj);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, realObj)) {
|
||||
*_retval = false;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, realObj);
|
||||
|
||||
// First check to see if the property is defined on our prototype,
|
||||
// after converting id to a string if it's an integer.
|
||||
|
@ -625,11 +625,7 @@ nsOuterWindowProxy::singleton;
|
||||
static JSObject*
|
||||
NewOuterWindowProxy(JSContext *cx, JSObject *parent)
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, parent)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSAutoCompartment ac(cx, parent);
|
||||
JSObject *obj = js::Wrapper::New(cx, parent, js::GetObjectProto(parent), parent,
|
||||
&nsOuterWindowProxy::singleton);
|
||||
NS_ASSERTION(js::GetObjectClass(obj)->ext.innerObject, "bad class");
|
||||
@ -1988,11 +1984,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
|
||||
SetWrapper(mJSObject);
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, mJSObject)) {
|
||||
NS_ERROR("unable to enter a compartment");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, mJSObject);
|
||||
|
||||
JS_SetParent(cx, mJSObject, newInnerWindow->mJSObject);
|
||||
|
||||
@ -2010,11 +2002,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
|
||||
}
|
||||
|
||||
// Enter the new global's compartment.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, mJSObject)) {
|
||||
NS_ERROR("unable to enter a compartment");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, mJSObject);
|
||||
|
||||
// If we created a new inner window above, we need to do the last little bit
|
||||
// of initialization now that the dust has settled.
|
||||
@ -2040,11 +2028,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
|
||||
}
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, mJSObject)) {
|
||||
NS_ERROR("unable to enter a compartment");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, mJSObject);
|
||||
|
||||
if (!aState && !reUseInnerWindow) {
|
||||
// Loading a new page and creating a new inner window, *not*
|
||||
@ -6010,10 +5994,7 @@ nsGlobalWindow::CallerInnerWindow()
|
||||
}
|
||||
|
||||
JSObject *scope = CallerGlobal();
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, scope))
|
||||
return nullptr;
|
||||
JSAutoCompartment ac(cx, scope);
|
||||
|
||||
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
||||
nsContentUtils::XPConnect()->
|
||||
|
@ -1289,12 +1289,7 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
|
||||
if (ok && ((JSVersion)aVersion) != JSVERSION_UNKNOWN) {
|
||||
|
||||
XPCAutoRequest ar(mContext);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(mContext, aScopeObject)) {
|
||||
stack->Pop(nullptr);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(mContext, aScopeObject);
|
||||
|
||||
++mExecuteDepth;
|
||||
|
||||
@ -1493,11 +1488,7 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
// check it isn't JSVERSION_UNKNOWN.
|
||||
if (ok && JSVersion(aVersion) != JSVERSION_UNKNOWN) {
|
||||
XPCAutoRequest ar(mContext);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(mContext, aScopeObject)) {
|
||||
stack->Pop(nullptr);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(mContext, aScopeObject);
|
||||
|
||||
ok = JS_EvaluateUCScriptForPrincipalsVersionOrigin(
|
||||
mContext, aScopeObject,
|
||||
@ -1517,10 +1508,7 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
// If all went well, convert val to a string if one is wanted.
|
||||
if (ok) {
|
||||
XPCAutoRequest ar(mContext);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(mContext, aScopeObject)) {
|
||||
stack->Pop(nullptr);
|
||||
}
|
||||
JSAutoCompartment ac(mContext, aScopeObject);
|
||||
rv = JSValueToAString(mContext, val, aRetValue, aIsUndefined);
|
||||
}
|
||||
else {
|
||||
@ -1905,9 +1893,8 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, JSObject* aScope,
|
||||
|
||||
JSObject *funobj = aHandler;
|
||||
jsval funval = OBJECT_TO_JSVAL(funobj);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(mContext, funobj) ||
|
||||
!JS_WrapObject(mContext, &target)) {
|
||||
JSAutoCompartment ac(mContext, funobj);
|
||||
if (!JS_WrapObject(mContext, &target)) {
|
||||
ReportPendingException();
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -1982,21 +1969,14 @@ nsJSContext::BindCompiledEventHandler(nsISupports* aTarget, JSObject* aScope,
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(mContext, aHandler)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSAutoCompartment ac(mContext, aHandler);
|
||||
NS_ASSERTION(JS_TypeOfValue(mContext,
|
||||
OBJECT_TO_JSVAL(aHandler)) == JSTYPE_FUNCTION,
|
||||
"Event handler object not a function");
|
||||
}
|
||||
#endif
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(mContext, target)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(mContext, target);
|
||||
|
||||
JSObject* funobj;
|
||||
// Make sure the handler function is parented by its event target object
|
||||
|
@ -149,9 +149,7 @@ GetFrameDocument(JSContext *cx, JSStackFrame *fp)
|
||||
if (!scope)
|
||||
return nullptr;
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, scope))
|
||||
return nullptr;
|
||||
JSAutoCompartment ac(cx, scope);
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window =
|
||||
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(cx, scope));
|
||||
|
@ -51,8 +51,7 @@ nsStructuredCloneContainer::InitFromVariant(nsIVariant *aData, JSContext *aCx)
|
||||
|
||||
// Make sure that we serialize in the right context.
|
||||
JSAutoRequest ar(aCx);
|
||||
JSAutoEnterCompartment ac;
|
||||
NS_ENSURE_STATE(ac.enter(aCx, JS_GetGlobalObject(aCx)));
|
||||
JSAutoCompartment ac(aCx, JS_GetGlobalObject(aCx));
|
||||
JS_WrapValue(aCx, &jsData);
|
||||
|
||||
nsCxPusher cxPusher;
|
||||
|
@ -614,12 +614,10 @@ bool
|
||||
HasPropertyOnPrototype(JSContext* cx, JSObject* proxy, DOMProxyHandler* handler,
|
||||
jsid id)
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
if (xpc::WrapperFactory::IsXrayWrapper(proxy)) {
|
||||
proxy = js::UnwrapObject(proxy);
|
||||
if (!ac.enter(cx, proxy)) {
|
||||
return false;
|
||||
}
|
||||
ac.construct(cx, proxy);
|
||||
}
|
||||
MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
|
||||
|
||||
|
@ -224,7 +224,7 @@ IsArrayLike(JSContext* cx, JSObject* obj)
|
||||
// For simplicity, check for security wrappers up front. In case we
|
||||
// have a security wrapper, don't forget to enter the compartment of
|
||||
// the underlying object after unwrapping.
|
||||
JSAutoEnterCompartment ac;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
if (js::IsWrapper(obj)) {
|
||||
obj = xpc::Unwrap(cx, obj, false);
|
||||
if (!obj) {
|
||||
@ -232,9 +232,7 @@ IsArrayLike(JSContext* cx, JSObject* obj)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ac.enter(cx, obj)) {
|
||||
return false;
|
||||
}
|
||||
ac.construct(cx, obj);
|
||||
}
|
||||
|
||||
// XXXbz need to detect platform objects (including listbinding
|
||||
@ -440,14 +438,14 @@ WrapNewBindingNonWrapperCachedObject(JSContext* cx, JSObject* scope, T* value,
|
||||
// We try to wrap in the compartment of the underlying object of "scope"
|
||||
JSObject* obj;
|
||||
{
|
||||
// scope for the JSAutoEnterCompartment so that we restore the
|
||||
// compartment before we call JS_WrapValue.
|
||||
JSAutoEnterCompartment ac;
|
||||
// scope for the JSAutoCompartment so that we restore the compartment
|
||||
// before we call JS_WrapValue.
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
if (js::IsWrapper(scope)) {
|
||||
scope = xpc::Unwrap(cx, scope, false);
|
||||
if (!scope || !ac.enter(cx, scope)) {
|
||||
if (!scope)
|
||||
return false;
|
||||
}
|
||||
ac.construct(cx, scope);
|
||||
}
|
||||
|
||||
obj = value->WrapObject(cx, scope);
|
||||
|
@ -1381,13 +1381,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (js::GetGlobalForObjectCrossCompartment(parent) != aScope) {
|
||||
if (!ac.enter(aCx, parent)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
JSAutoCompartment ac(aCx, parent);
|
||||
JSObject* global = JS_GetGlobalForObject(aCx, parent);
|
||||
%s
|
||||
JSObject* proto = GetProtoObject(aCx, global, global);
|
||||
|
@ -66,11 +66,9 @@ struct TypedArray : public TypedArray_base<T,UnboxArray> {
|
||||
Create(JSContext* cx, nsWrapperCache* creator, uint32_t length,
|
||||
const T* data = NULL) {
|
||||
JSObject* creatorWrapper;
|
||||
JSAutoEnterCompartment ac;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
if (creator && (creatorWrapper = creator->GetWrapperPreserveColor())) {
|
||||
if (!ac.enter(cx, creatorWrapper)) {
|
||||
return NULL;
|
||||
}
|
||||
ac.construct(cx, creatorWrapper);
|
||||
}
|
||||
JSObject* obj = CreateNew(cx, length);
|
||||
if (!obj) {
|
||||
|
@ -21,11 +21,7 @@ mozilla::dom::bluetooth::StringArrayToJSArray(JSContext* aCx, JSObject* aGlobal,
|
||||
NS_ASSERTION(aGlobal, "Null global!");
|
||||
|
||||
JSAutoRequest ar(aCx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(aCx, aGlobal)) {
|
||||
NS_WARNING("Failed to enter compartment!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(aCx, aGlobal);
|
||||
|
||||
JSObject* arrayObj;
|
||||
|
||||
@ -71,11 +67,7 @@ mozilla::dom::bluetooth::BluetoothDeviceArrayToJSArray(JSContext* aCx, JSObject*
|
||||
NS_ASSERTION(aGlobal, "Null global!");
|
||||
|
||||
JSAutoRequest ar(aCx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(aCx, aGlobal)) {
|
||||
NS_WARNING("Failed to enter compartment!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(aCx, aGlobal);
|
||||
|
||||
JSObject* arrayObj;
|
||||
|
||||
|
@ -129,24 +129,20 @@ ArchiveRequest::ReaderReady(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
|
||||
NS_ASSERTION(global, "Failed to get global object!");
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (ac.enter(cx, global)) {
|
||||
switch (mOperation) {
|
||||
case GetFilenames:
|
||||
rv = GetFilenamesResult(cx, &result, aFileList);
|
||||
break;
|
||||
JSAutoCompartment ac(cx, global);
|
||||
|
||||
case GetFile:
|
||||
rv = GetFileResult(cx, &result, aFileList);
|
||||
break;
|
||||
}
|
||||
switch (mOperation) {
|
||||
case GetFilenames:
|
||||
rv = GetFilenamesResult(cx, &result, aFileList);
|
||||
break;
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Get*Result failed!");
|
||||
}
|
||||
} else {
|
||||
NS_WARNING("Failed to enter correct compartment!");
|
||||
rv = NS_ERROR_FAILURE;
|
||||
case GetFile:
|
||||
rv = GetFileResult(cx, &result, aFileList);
|
||||
break;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Get*Result failed!");
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -80,16 +80,11 @@ FileRequest::NotifyHelperCompleted(FileHelper* aFileHelper)
|
||||
NS_ASSERTION(global, "Failed to get global object!");
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (ac.enter(cx, global)) {
|
||||
rv = aFileHelper->GetSuccessResult(cx, &result);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("GetSuccessResult failed!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
NS_WARNING("Failed to enter correct compartment!");
|
||||
rv = NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
||||
JSAutoCompartment ac(cx, global);
|
||||
|
||||
rv = aFileHelper->GetSuccessResult(cx, &result);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("GetSuccessResult failed!");
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -238,11 +238,7 @@ IDBFactory::Create(ContentParent* aContentParent,
|
||||
// don't need a proxy here.
|
||||
global = JS_UnwrapObject(global);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, global)) {
|
||||
NS_WARNING("Failed to enter compartment!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, global);
|
||||
|
||||
nsRefPtr<IDBFactory> factory;
|
||||
rv = Create(cx, global, aContentParent, getter_AddRefs(factory));
|
||||
|
@ -109,18 +109,12 @@ IDBRequest::NotifyHelperCompleted(HelperBase* aHelper)
|
||||
NS_ASSERTION(global, "This should never be null!");
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (ac.enter(cx, global)) {
|
||||
AssertIsRooted();
|
||||
JSAutoCompartment ac(cx, global);
|
||||
AssertIsRooted();
|
||||
|
||||
rv = aHelper->GetSuccessResult(cx, &mResultVal);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("GetSuccessResult failed!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
NS_WARNING("Failed to enter correct compartment!");
|
||||
rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
rv = aHelper->GetSuccessResult(cx, &mResultVal);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("GetSuccessResult failed!");
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -624,10 +624,7 @@ nsJSObjWrapper::NP_HasMethod(NPObject *npobj, NPIdentifier id)
|
||||
|
||||
AutoCXPusher pusher(cx);
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, npjsobj->mJSObj))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, npjsobj->mJSObj);
|
||||
|
||||
AutoJSExceptionReporter reporter(cx);
|
||||
|
||||
@ -663,10 +660,7 @@ doInvoke(NPObject *npobj, NPIdentifier method, const NPVariant *args,
|
||||
|
||||
AutoCXPusher pusher(cx);
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, npjsobj->mJSObj))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, npjsobj->mJSObj);
|
||||
|
||||
AutoJSExceptionReporter reporter(cx);
|
||||
|
||||
@ -778,10 +772,7 @@ nsJSObjWrapper::NP_HasProperty(NPObject *npobj, NPIdentifier id)
|
||||
AutoCXPusher pusher(cx);
|
||||
JSAutoRequest ar(cx);
|
||||
AutoJSExceptionReporter reporter(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, npjsobj->mJSObj))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, npjsobj->mJSObj);
|
||||
|
||||
NS_ASSERTION(NPIdentifierIsInt(id) || NPIdentifierIsString(id),
|
||||
"id must be either string or int!\n");
|
||||
@ -813,10 +804,7 @@ nsJSObjWrapper::NP_GetProperty(NPObject *npobj, NPIdentifier id,
|
||||
AutoCXPusher pusher(cx);
|
||||
JSAutoRequest ar(cx);
|
||||
AutoJSExceptionReporter reporter(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, npjsobj->mJSObj))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, npjsobj->mJSObj);
|
||||
|
||||
jsval v;
|
||||
return (GetProperty(cx, npjsobj->mJSObj, id, &v) &&
|
||||
@ -848,10 +836,7 @@ nsJSObjWrapper::NP_SetProperty(NPObject *npobj, NPIdentifier id,
|
||||
AutoCXPusher pusher(cx);
|
||||
JSAutoRequest ar(cx);
|
||||
AutoJSExceptionReporter reporter(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, npjsobj->mJSObj))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, npjsobj->mJSObj);
|
||||
|
||||
jsval v = NPVariantToJSVal(npp, cx, value);
|
||||
JS::AutoValueRooter tvr(cx, v);
|
||||
@ -890,10 +875,7 @@ nsJSObjWrapper::NP_RemoveProperty(NPObject *npobj, NPIdentifier id)
|
||||
JSAutoRequest ar(cx);
|
||||
AutoJSExceptionReporter reporter(cx);
|
||||
jsval deleted = JSVAL_FALSE;
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, npjsobj->mJSObj))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, npjsobj->mJSObj);
|
||||
|
||||
NS_ASSERTION(NPIdentifierIsInt(id) || NPIdentifierIsString(id),
|
||||
"id must be either string or int!\n");
|
||||
@ -945,10 +927,7 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
|
||||
AutoCXPusher pusher(cx);
|
||||
JSAutoRequest ar(cx);
|
||||
AutoJSExceptionReporter reporter(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, npjsobj->mJSObj))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, npjsobj->mJSObj);
|
||||
|
||||
JS::AutoIdArray ida(cx, JS_Enumerate(cx, npjsobj->mJSObj));
|
||||
if (!ida) {
|
||||
@ -2065,11 +2044,9 @@ nsJSNPRuntime::OnPluginDestroy(NPP npp)
|
||||
JSObject *obj, *proto;
|
||||
holder->GetJSObject(&obj);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (obj && !ac.enter(cx, obj)) {
|
||||
// Failure to enter compartment, nothing more we can do then.
|
||||
return;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
if (obj) {
|
||||
ac.construct(cx, obj);
|
||||
}
|
||||
|
||||
// Loop over the DOM element's JS object prototype chain and remove
|
||||
|
@ -195,11 +195,7 @@ SmsManager::Send(const jsval& aNumber, const nsAString& aMessage, jsval* aReturn
|
||||
NS_ASSERTION(global, "Failed to get global object!");
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, global)) {
|
||||
NS_ERROR("Failed to enter the js compartment!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, global);
|
||||
|
||||
if (aNumber.isString()) {
|
||||
return Send(cx, global, aNumber.toString(), aMessage, aReturn);
|
||||
|
@ -159,11 +159,7 @@ SmsRequest::SetSuccessInternal(nsISupports* aObject)
|
||||
NS_ASSERTION(global, "Failed to get global object!");
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, global)) {
|
||||
SetError(nsISmsRequestManager::INTERNAL_ERROR);
|
||||
return false;
|
||||
}
|
||||
JSAutoCompartment ac(cx, global);
|
||||
|
||||
RootResult();
|
||||
|
||||
|
@ -176,12 +176,9 @@ nsJSON::EncodeFromJSVal(JS::Value *value, JSContext *cx, nsAString &result)
|
||||
// Begin a new request
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
mozilla::Maybe<JSAutoCompartment> ac;
|
||||
if (value->isObject()) {
|
||||
JSObject *obj = &value->toObject();
|
||||
if (!ac.enter(cx, obj)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
ac.construct(cx, &value->toObject());
|
||||
}
|
||||
|
||||
nsJSONWriter writer;
|
||||
|
@ -334,10 +334,7 @@ SystemWorkerManager::InitRIL(JSContext *cx)
|
||||
NS_ENSURE_TRUE(!JSVAL_IS_PRIMITIVE(workerval), NS_ERROR_UNEXPECTED);
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, JSVAL_TO_OBJECT(workerval))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(workerval));
|
||||
|
||||
WorkerCrossThreadDispatcher *wctd =
|
||||
GetWorkerCrossThreadDispatcher(cx, workerval);
|
||||
|
@ -43,11 +43,7 @@ nsTArrayToJSArray(JSContext* aCx, JSObject* aGlobal,
|
||||
NS_ASSERTION(aGlobal, "Null global!");
|
||||
|
||||
JSAutoRequest ar(aCx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(aCx, aGlobal)) {
|
||||
NS_WARNING("Failed to enter compartment!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(aCx, aGlobal);
|
||||
|
||||
JSObject* arrayObj;
|
||||
|
||||
|
@ -695,12 +695,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(aCx, global)) {
|
||||
NS_WARNING("Failed to enter compartment!");
|
||||
return false;
|
||||
}
|
||||
|
||||
JSAutoCompartment ac(aCx, global);
|
||||
JS_SetGlobalObject(aCx, global);
|
||||
|
||||
return scriptloader::LoadWorkerScript(aCx);
|
||||
@ -1686,9 +1681,9 @@ WorkerRunnable::Dispatch(JSContext* aCx)
|
||||
|
||||
JSObject* global = JS_GetGlobalObject(aCx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (global && !ac.enter(aCx, global)) {
|
||||
return false;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
if (global) {
|
||||
ac.construct(aCx, global);
|
||||
}
|
||||
|
||||
ok = PreDispatch(aCx, mWorkerPrivate);
|
||||
@ -1793,9 +1788,9 @@ WorkerRunnable::Run()
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (targetCompartmentObject && !ac.enter(cx, targetCompartmentObject)) {
|
||||
return NS_OK;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
if (targetCompartmentObject) {
|
||||
ac.construct(cx, targetCompartmentObject);
|
||||
}
|
||||
|
||||
bool result = WorkerRun(cx, mWorkerPrivate);
|
||||
|
@ -922,10 +922,7 @@ CreateDedicatedWorkerGlobalScope(JSContext* aCx)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(aCx, global)) {
|
||||
return NULL;
|
||||
}
|
||||
JSAutoCompartment ac(aCx, global);
|
||||
|
||||
// Make the private slots now so that all our instance checks succeed.
|
||||
if (!DedicatedWorkerGlobalScope::InitPrivate(aCx, global, worker)) {
|
||||
|
@ -133,9 +133,7 @@ nsresult CentralizedAdminPrefManagerInit()
|
||||
|
||||
autoconfig_glob = JS_NewGlobalObject(autoconfig_cx, &global_class, NULL);
|
||||
if (autoconfig_glob) {
|
||||
JSAutoEnterCompartment ac;
|
||||
if(!ac.enter(autoconfig_cx, autoconfig_glob))
|
||||
return NS_ERROR_FAILURE;
|
||||
JSAutoCompartment ac(autoconfig_cx, autoconfig_glob);
|
||||
if (JS_InitStandardClasses(autoconfig_cx, autoconfig_glob)) {
|
||||
// XPCONNECT enable this JS context
|
||||
rv = xpc->InitClasses(autoconfig_cx, autoconfig_glob);
|
||||
|
@ -95,11 +95,7 @@ TestShellCommandParent::RunCallback(const nsString& aResponse)
|
||||
JSObject* global = JS_GetGlobalObject(mCx);
|
||||
NS_ENSURE_TRUE(global, JS_FALSE);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(mCx, global)) {
|
||||
NS_ERROR("Failed to enter compartment!");
|
||||
return false;
|
||||
}
|
||||
JSAutoCompartment ac(mCx, global);
|
||||
|
||||
JSString* str = JS_NewUCStringCopyN(mCx, aResponse.get(), aResponse.Length());
|
||||
NS_ENSURE_TRUE(str, JS_FALSE);
|
||||
|
@ -562,12 +562,7 @@ ProcessFile(JSContext *cx,
|
||||
ungetc(ch, file);
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj)) {
|
||||
NS_ERROR("Failed to enter compartment!");
|
||||
return;
|
||||
}
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
|
||||
JSScript* script =
|
||||
JS_CompileUTF8FileHandleForPrincipals(cx, obj, filename, file,
|
||||
@ -586,12 +581,7 @@ ProcessFile(JSContext *cx,
|
||||
*bufp = '\0';
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj)) {
|
||||
NS_ERROR("Failed to enter compartment!");
|
||||
return;
|
||||
}
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
|
||||
/*
|
||||
* Accumulate lines until we get a 'compilable unit' - one that either
|
||||
@ -1115,12 +1105,7 @@ XPCShellEnvironment::Init()
|
||||
|
||||
{
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, globalObj)) {
|
||||
NS_ERROR("Failed to enter compartment!");
|
||||
return false;
|
||||
}
|
||||
JSAutoCompartment ac(cx, globalObj);
|
||||
|
||||
if (!JS_DefineFunctions(cx, globalObj, gGlobalFunctions) ||
|
||||
!JS_DefineProfilingFunctions(cx, globalObj)) {
|
||||
@ -1154,12 +1139,7 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,
|
||||
JS_ClearPendingException(mCx);
|
||||
|
||||
JSObject* global = GetGlobalObject();
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(mCx, global)) {
|
||||
NS_ERROR("Failed to enter compartment!");
|
||||
return false;
|
||||
}
|
||||
JSAutoCompartment ac(mCx, global);
|
||||
|
||||
JSScript* script =
|
||||
JS_CompileUCScriptForPrincipals(mCx, global, GetPrincipal(),
|
||||
|
@ -51,11 +51,7 @@ JSDebugger::AddClass(const JS::Value &global, JSContext* cx)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment aec;
|
||||
if (!aec.enter(cx, obj)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
if (JS_GetGlobalForObject(cx, obj) != obj) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
@ -1001,10 +1001,7 @@ jsdScript::CreatePPLineMap()
|
||||
unsigned nargs;
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, JS_GetFunctionObject(fun)))
|
||||
return nullptr;
|
||||
|
||||
JSAutoCompartment ac(cx, JS_GetFunctionObject(fun));
|
||||
nargs = JS_GetFunctionArgumentCount(cx, fun);
|
||||
if (nargs > 12)
|
||||
return nullptr;
|
||||
@ -1239,9 +1236,7 @@ jsdScript::GetParameterNames(uint32_t* count, PRUnichar*** paramNames)
|
||||
}
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, JS_GetFunctionObject(fun)))
|
||||
return NS_ERROR_FAILURE;
|
||||
JSAutoCompartment ac(cx, JS_GetFunctionObject(fun));
|
||||
|
||||
unsigned nargs;
|
||||
if (!JS_FunctionHasLocalNames(cx, fun) ||
|
||||
@ -1328,11 +1323,10 @@ jsdScript::GetFunctionSource(nsAString & aFunctionSource)
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSString *jsstr;
|
||||
JSAutoEnterCompartment ac;
|
||||
mozilla::Maybe<JSAutoCompartment> ac;
|
||||
JS::AutoEnterScriptCompartment asc;
|
||||
if (fun) {
|
||||
if (!ac.enter(cx, JS_GetFunctionObject(fun)))
|
||||
return NS_ERROR_FAILURE;
|
||||
ac.construct(cx, JS_GetFunctionObject(fun));
|
||||
jsstr = JS_DecompileFunction (cx, fun, 4);
|
||||
} else {
|
||||
JSScript *script = JSD_GetJSScript (mCx, mScript);
|
||||
|
@ -5876,10 +5876,7 @@ CClosure::ClosureStub(ffi_cif* cif, void* result, void** args, void* userData)
|
||||
JS_AbortIfWrongThread(JS_GetRuntime(cx));
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, jsfnObj))
|
||||
return;
|
||||
JSAutoCompartment ac(cx, jsfnObj);
|
||||
|
||||
// Assert that our CIFs agree.
|
||||
FunctionInfo* fninfo = FunctionType::GetFunctionInfo(typeObj);
|
||||
|
@ -29,10 +29,7 @@ OuterWrapper::singleton;
|
||||
static JSObject *
|
||||
wrap(JSContext *cx, JS::HandleObject toWrap, JS::HandleObject target)
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, target))
|
||||
return NULL;
|
||||
|
||||
JSAutoCompartment ac(cx, target);
|
||||
JS::RootedObject wrapper(cx, toWrap);
|
||||
if (!JS_WrapObject(cx, wrapper.address()))
|
||||
return NULL;
|
||||
@ -88,8 +85,7 @@ BEGIN_TEST(testBug604087)
|
||||
|
||||
JS::RootedObject next(cx);
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
CHECK(ac.enter(cx, compartment2));
|
||||
JSAutoCompartment ac(cx, compartment2);
|
||||
next = js::Wrapper::New(cx, compartment2, compartment2->getProto(), compartment2,
|
||||
&OuterWrapper::singleton);
|
||||
CHECK(next);
|
||||
|
@ -64,9 +64,7 @@ BEGIN_TEST(test_CallNonGenericMethodOnProxy)
|
||||
CHECK(globalB);
|
||||
|
||||
// ...and enter it.
|
||||
JSAutoEnterCompartment enter;
|
||||
CHECK(enter.enter(cx, globalB));
|
||||
|
||||
JSAutoCompartment enter(cx, globalB);
|
||||
JS::RootedObject customB(cx, JS_NewObject(cx, &CustomClass, NULL, NULL));
|
||||
CHECK(customB);
|
||||
JS_SetReservedSlot(customB, CUSTOM_SLOT, Int32Value(42));
|
||||
|
@ -31,14 +31,10 @@ CallTrusted(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
JSBool ok = JS_FALSE;
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
ok = ac.enter(cx, trusted_glob);
|
||||
if (!ok)
|
||||
goto out;
|
||||
JSAutoCompartment ac(cx, trusted_glob);
|
||||
ok = JS_CallFunctionValue(cx, NULL, OBJECT_TO_JSVAL(trusted_fun),
|
||||
0, NULL, vp);
|
||||
}
|
||||
out:
|
||||
JS_RestoreFrameChain(cx);
|
||||
return ok;
|
||||
}
|
||||
@ -64,8 +60,7 @@ BEGIN_TEST(testChromeBuffer)
|
||||
*/
|
||||
{
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
CHECK(ac.enter(cx, trusted_glob));
|
||||
JSAutoCompartment ac(cx, trusted_glob);
|
||||
const char *paramName = "x";
|
||||
const char *bytes = "return x ? 1 + trusted(x-1) : 0";
|
||||
JS::HandleObject global = JS::HandleObject::fromMarkedLocation(&trusted_glob);
|
||||
@ -98,8 +93,7 @@ BEGIN_TEST(testChromeBuffer)
|
||||
*/
|
||||
{
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
CHECK(ac.enter(cx, trusted_glob));
|
||||
JSAutoCompartment ac(cx, trusted_glob);
|
||||
const char *paramName = "untrusted";
|
||||
const char *bytes = "try { "
|
||||
" untrusted(); "
|
||||
@ -138,8 +132,7 @@ BEGIN_TEST(testChromeBuffer)
|
||||
*/
|
||||
{
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
CHECK(ac.enter(cx, trusted_glob));
|
||||
JSAutoCompartment ac(cx, trusted_glob);
|
||||
const char *bytes = "return 42";
|
||||
JS::HandleObject global = JS::HandleObject::fromMarkedLocation(&trusted_glob);
|
||||
CHECK(fun = JS_CompileFunctionForPrincipals(cx, global, &system_principals,
|
||||
|
@ -32,10 +32,7 @@ BEGIN_TEST(test_cloneScript)
|
||||
|
||||
// compile for A
|
||||
{
|
||||
JSAutoEnterCompartment a;
|
||||
if (!a.enter(cx, A))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment a(cx, A);
|
||||
JSFunction *fun;
|
||||
CHECK(fun = JS_CompileFunction(cx, A, "f", 0, NULL, source, strlen(source), __FILE__, 1));
|
||||
CHECK(obj = JS_GetFunctionObject(fun));
|
||||
@ -43,10 +40,7 @@ BEGIN_TEST(test_cloneScript)
|
||||
|
||||
// clone into B
|
||||
{
|
||||
JSAutoEnterCompartment b;
|
||||
if (!b.enter(cx, B))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment b(cx, B);
|
||||
CHECK(JS_CloneFunctionObject(cx, obj, B));
|
||||
}
|
||||
|
||||
@ -109,10 +103,7 @@ BEGIN_TEST(test_cloneScriptWithPrincipals)
|
||||
|
||||
// Compile in A
|
||||
{
|
||||
JSAutoEnterCompartment a;
|
||||
if (!a.enter(cx, A))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment a(cx, A);
|
||||
JSFunction *fun;
|
||||
CHECK(fun = JS_CompileFunctionForPrincipals(cx, A, principalsA, "f",
|
||||
mozilla::ArrayLength(argnames), argnames,
|
||||
@ -127,10 +118,7 @@ BEGIN_TEST(test_cloneScriptWithPrincipals)
|
||||
|
||||
// Clone into B
|
||||
{
|
||||
JSAutoEnterCompartment b;
|
||||
if (!b.enter(cx, B))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment b(cx, B);
|
||||
JS::RootedObject cloned(cx);
|
||||
CHECK(cloned = JS_CloneFunctionObject(cx, obj, B));
|
||||
|
||||
|
@ -41,8 +41,7 @@ BEGIN_TEST(testContexts_bug563735)
|
||||
JSBool ok;
|
||||
{
|
||||
JSAutoRequest req(cx2);
|
||||
JSAutoEnterCompartment ac;
|
||||
CHECK(ac.enter(cx2, global));
|
||||
JSAutoCompartment ac(cx2, global);
|
||||
jsval v = JSVAL_NULL;
|
||||
ok = JS_SetProperty(cx2, global, "x", &v);
|
||||
}
|
||||
|
@ -154,8 +154,7 @@ BEGIN_TEST(testDebugger_debuggerObjectVsDebugMode)
|
||||
CHECK(debuggee);
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ae;
|
||||
CHECK(ae.enter(cx, debuggee));
|
||||
JSAutoCompartment ae(cx, debuggee);
|
||||
CHECK(JS_SetDebugMode(cx, true));
|
||||
CHECK(JS_InitStandardClasses(cx, debuggee));
|
||||
}
|
||||
@ -174,8 +173,7 @@ BEGIN_TEST(testDebugger_debuggerObjectVsDebugMode)
|
||||
CHECK_SAME(v, JSVAL_ONE);
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ae;
|
||||
CHECK(ae.enter(cx, debuggee));
|
||||
JSAutoCompartment ae(cx, debuggee);
|
||||
CHECK(JS_SetDebugMode(cx, false));
|
||||
}
|
||||
|
||||
@ -195,8 +193,7 @@ BEGIN_TEST(testDebugger_newScriptHook)
|
||||
JS::RootedObject g(cx, JS_NewGlobalObject(cx, getGlobalClass(), NULL));
|
||||
CHECK(g);
|
||||
{
|
||||
JSAutoEnterCompartment ae;
|
||||
CHECK(ae.enter(cx, g));
|
||||
JSAutoCompartment ae(cx, g);
|
||||
CHECK(JS_InitStandardClasses(cx, g));
|
||||
}
|
||||
|
||||
@ -225,8 +222,7 @@ bool testIndirectEval(JS::HandleObject scope, const char *code)
|
||||
EXEC("hits = 0;");
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ae;
|
||||
CHECK(ae.enter(cx, scope));
|
||||
JSAutoCompartment ae(cx, scope);
|
||||
JSString *codestr = JS_NewStringCopyZ(cx, code);
|
||||
CHECK(codestr);
|
||||
jsval argv[1] = { STRING_TO_JSVAL(codestr) };
|
||||
|
@ -63,8 +63,7 @@ eval(const char *asciiChars, JSPrincipals *principals, JSPrincipals *originPrinc
|
||||
|
||||
JS::RootedObject global(cx, JS_NewGlobalObject(cx, getGlobalClass(), principals));
|
||||
CHECK(global);
|
||||
JSAutoEnterCompartment ac;
|
||||
CHECK(ac.enter(cx, global));
|
||||
JSAutoCompartment ac(cx, global);
|
||||
CHECK(JS_InitStandardClasses(cx, global));
|
||||
bool ok = JS_EvaluateUCScriptForPrincipalsVersionOrigin(cx, global,
|
||||
principals,
|
||||
|
@ -61,9 +61,7 @@ JSObject * JSAPITest::createGlobal(JSPrincipals *principals)
|
||||
JS_AddNamedObjectRoot(cx, &global, "test-global");
|
||||
JS::HandleObject globalHandle = JS::HandleObject::fromMarkedLocation(&global);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, globalHandle))
|
||||
return NULL;
|
||||
JSAutoCompartment ac(cx, globalHandle);
|
||||
|
||||
/* Populate the global object with the standard globals, like Object and
|
||||
Array. */
|
||||
|
@ -1486,30 +1486,17 @@ JS_LeaveCrossCompartmentCall(JSCrossCompartmentCall *call)
|
||||
Foreground::delete_(call);
|
||||
}
|
||||
|
||||
bool
|
||||
JSAutoEnterCompartment::enter(JSContext *cx, JSRawObject target)
|
||||
JSAutoCompartment::JSAutoCompartment(JSContext *cx, JSRawObject target)
|
||||
: cx_(cx),
|
||||
oldCompartment_(cx->compartment)
|
||||
{
|
||||
enterAndIgnoreErrors(cx, target);
|
||||
return true;
|
||||
AssertHeapIsIdleOrIterating(cx_);
|
||||
cx_->enterCompartment(target->compartment());
|
||||
}
|
||||
|
||||
void
|
||||
JSAutoEnterCompartment::enterAndIgnoreErrors(JSContext *cx, JSRawObject target)
|
||||
JSAutoCompartment::~JSAutoCompartment()
|
||||
{
|
||||
AssertHeapIsIdleOrIterating(cx);
|
||||
JS_ASSERT(!entered_);
|
||||
cx_ = cx;
|
||||
oldCompartment_ = cx->compartment;
|
||||
cx->enterCompartment(target->compartment());
|
||||
entered_ = true;
|
||||
}
|
||||
|
||||
void
|
||||
JSAutoEnterCompartment::leave()
|
||||
{
|
||||
JS_ASSERT(entered_);
|
||||
cx_->leaveCompartment(oldCompartment_);
|
||||
entered_ = false;
|
||||
}
|
||||
|
||||
bool
|
||||
@ -1651,9 +1638,9 @@ JS_TransplantObject(JSContext *cx, JSObject *origobjArg, JSObject *targetArg)
|
||||
|
||||
// Lastly, update the original object to point to the new one.
|
||||
if (origobj->compartment() != destination) {
|
||||
AutoCompartment ac(cx, origobj);
|
||||
RootedObject newIdentityWrapper(cx, newIdentity);
|
||||
if (!ac.enter() || !JS_WrapObject(cx, newIdentityWrapper.address()))
|
||||
AutoCompartment ac(cx, origobj);
|
||||
if (!JS_WrapObject(cx, newIdentityWrapper.address()))
|
||||
return NULL;
|
||||
if (!origobj->swap(cx, newIdentityWrapper))
|
||||
return NULL;
|
||||
@ -1730,8 +1717,6 @@ js_TransplantObjectWithWrapper(JSContext *cx,
|
||||
// |origobj|.
|
||||
{
|
||||
AutoCompartment ac(cx, origobj);
|
||||
if (!ac.enter())
|
||||
return NULL;
|
||||
|
||||
// We can't be sure that the reflector is completely dead. This is bad,
|
||||
// because it is in a weird state. To minimize potential harm we create
|
||||
|
@ -3318,33 +3318,13 @@ namespace js {
|
||||
class AutoCompartment;
|
||||
}
|
||||
|
||||
class JS_PUBLIC_API(JSAutoEnterCompartment)
|
||||
class JS_PUBLIC_API(JSAutoCompartment)
|
||||
{
|
||||
JSContext *cx_;
|
||||
JSCompartment *oldCompartment_;
|
||||
bool entered_;
|
||||
|
||||
public:
|
||||
JSAutoEnterCompartment() : entered_(false) {}
|
||||
|
||||
JSAutoEnterCompartment(JSContext *cx, JSRawObject target)
|
||||
: entered_(false)
|
||||
{ enter(cx, target); }
|
||||
|
||||
bool enter(JSContext *cx, JSRawObject target);
|
||||
|
||||
void enterAndIgnoreErrors(JSContext *cx, JSRawObject target);
|
||||
|
||||
bool entered() const { return entered_; }
|
||||
|
||||
/*
|
||||
* In general, consumers should try to avoid calling leave() explicitly,
|
||||
* and defer to the destructor by scoping the JSAutoEnterCompartment
|
||||
* appropriately. Sometimes, though, it's unavoidable.
|
||||
*/
|
||||
void leave();
|
||||
|
||||
~JSAutoEnterCompartment() { if (entered_) leave(); }
|
||||
JSAutoCompartment(JSContext *cx, JSRawObject target);
|
||||
~JSAutoCompartment();
|
||||
};
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
@ -510,12 +510,7 @@ JSStructuredCloneWriter::startWrite(const Value &v)
|
||||
if (!obj)
|
||||
return false;
|
||||
|
||||
// If we unwrapped above, we'll need to enter the underlying compartment.
|
||||
// Let the AutoEnterCompartment do the right thing for us.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(context(), obj))
|
||||
return false;
|
||||
|
||||
AutoCompartment ac(context(), obj);
|
||||
if (obj->isRegExp()) {
|
||||
RegExpObject &reobj = obj->asRegExp();
|
||||
return out.writePair(SCTAG_REGEXP_OBJECT, reobj.getFlags()) &&
|
||||
@ -555,12 +550,7 @@ JSStructuredCloneWriter::write(const Value &v)
|
||||
|
||||
while (!counts.empty()) {
|
||||
RootedObject obj(context(), &objs.back().toObject());
|
||||
|
||||
// The objects in |obj| can live in other compartments.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(context(), obj))
|
||||
return false;
|
||||
|
||||
AutoCompartment ac(context(), obj);
|
||||
if (counts.back()) {
|
||||
counts.back()--;
|
||||
RootedId id(context(), ids.back());
|
||||
|
@ -220,10 +220,6 @@ JSRuntime::initSelfHosting(JSContext *cx)
|
||||
return false;
|
||||
JS_SetGlobalObject(cx, selfHostedGlobal_);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, cx->global()))
|
||||
return false;
|
||||
|
||||
const char *src = selfhosted::raw_sources;
|
||||
uint32_t srcLen = selfhosted::GetRawScriptsSize();
|
||||
|
||||
@ -266,8 +262,8 @@ JSRuntime::cloneSelfHostedValueById(JSContext *cx, jsid id, HandleObject holder,
|
||||
Value funVal;
|
||||
{
|
||||
RootedObject shg(cx, selfHostedGlobal_);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, shg) || !JS_GetPropertyById(cx, shg, id, &funVal) || !funVal.isObject())
|
||||
AutoCompartment ac(cx, shg);
|
||||
if (!JS_GetPropertyById(cx, shg, id, &funVal) || !funVal.isObject())
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -483,28 +483,23 @@ class AssertCompartmentUnchanged {
|
||||
|
||||
class AutoCompartment
|
||||
{
|
||||
public:
|
||||
JSContext * const context;
|
||||
JSCompartment * const origin;
|
||||
JSCompartment * const destination;
|
||||
private:
|
||||
bool entered;
|
||||
JSContext * const cx_;
|
||||
JSCompartment * const origin_;
|
||||
|
||||
public:
|
||||
AutoCompartment(JSContext *cx, JSObject *target)
|
||||
: context(cx),
|
||||
origin(cx->compartment),
|
||||
destination(target->compartment()),
|
||||
entered(false)
|
||||
{}
|
||||
|
||||
~AutoCompartment() {
|
||||
if (entered)
|
||||
leave();
|
||||
: cx_(cx),
|
||||
origin_(cx->compartment)
|
||||
{
|
||||
cx_->enterCompartment(target->compartment());
|
||||
}
|
||||
|
||||
bool enter() { context->enterCompartment(destination); entered = true; return true; }
|
||||
void leave() { JS_ASSERT(entered); context->leaveCompartment(origin); entered = false; }
|
||||
~AutoCompartment() {
|
||||
cx_->leaveCompartment(origin_);
|
||||
}
|
||||
|
||||
JSContext *context() const { return cx_; }
|
||||
JSCompartment *origin() const { return origin_; }
|
||||
|
||||
private:
|
||||
AutoCompartment(const AutoCompartment &) MOZ_DELETE;
|
||||
@ -544,13 +539,12 @@ class AutoEnterAtomsCompartment
|
||||
*/
|
||||
class ErrorCopier
|
||||
{
|
||||
AutoCompartment ∾
|
||||
Maybe<AutoCompartment> ∾
|
||||
RootedObject scope;
|
||||
|
||||
public:
|
||||
ErrorCopier(AutoCompartment &ac, JSObject *scope) : ac(ac), scope(ac.context, scope) {
|
||||
JS_ASSERT(scope->compartment() == ac.origin);
|
||||
}
|
||||
ErrorCopier(Maybe<AutoCompartment> &ac, JSObject *scope)
|
||||
: ac(ac), scope(ac.ref().context(), scope) {}
|
||||
~ErrorCopier();
|
||||
};
|
||||
|
||||
|
@ -535,10 +535,7 @@ JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fpArg)
|
||||
{
|
||||
StackFrame *fp = Valueify(fpArg);
|
||||
JS_ASSERT(cx->stack.space().containsSlow(fp));
|
||||
js::AutoCompartment ac(cx, fp->scopeChain());
|
||||
if (!ac.enter())
|
||||
return NULL;
|
||||
|
||||
AutoCompartment ac(cx, fp->scopeChain());
|
||||
return GetDebugScopeForFrame(cx, fp);
|
||||
}
|
||||
|
||||
@ -576,11 +573,9 @@ JS_GetFrameThis(JSContext *cx, JSStackFrame *fpArg, jsval *thisv)
|
||||
StackFrame *fp = Valueify(fpArg);
|
||||
|
||||
js::AutoCompartment ac(cx, fp->scopeChain());
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
|
||||
if (!ComputeThis(cx, fp))
|
||||
return false;
|
||||
|
||||
*thisv = fp->thisValue();
|
||||
return true;
|
||||
}
|
||||
@ -731,11 +726,9 @@ JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fpArg,
|
||||
if (!env)
|
||||
return false;
|
||||
|
||||
js::AutoCompartment ac(cx, env);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
|
||||
StackFrame *fp = Valueify(fpArg);
|
||||
|
||||
js::AutoCompartment ac(cx, env);
|
||||
return EvaluateInEnv(cx, env, fp, chars, length, filename, lineno, rval);
|
||||
}
|
||||
|
||||
|
@ -3146,16 +3146,12 @@ JSObject::swap(JSContext *cx, JSObject *other)
|
||||
JSObject *otherClone;
|
||||
{
|
||||
AutoCompartment ac(cx, other);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
thisClone = JS_CloneObject(cx, this, other->getProto(), other->getParent());
|
||||
if (!thisClone || !JS_CopyPropertiesFrom(cx, thisClone, this))
|
||||
return false;
|
||||
}
|
||||
{
|
||||
AutoCompartment ac(cx, this);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
otherClone = JS_CloneObject(cx, other, other->getProto(), other->getParent());
|
||||
if (!otherClone || !JS_CopyPropertiesFrom(cx, otherClone, other))
|
||||
return false;
|
||||
|
@ -6792,11 +6792,7 @@ GetPCCountScriptContents(JSContext *cx, size_t index)
|
||||
return buf.finishString();
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
RootedObject target(cx, &script->global());
|
||||
if (!ac.enter(cx, target))
|
||||
return NULL;
|
||||
|
||||
AutoCompartment ac(cx, &script->global());
|
||||
if (!GetPCCountJSON(cx, sac, buf))
|
||||
return NULL;
|
||||
}
|
||||
|
@ -395,15 +395,12 @@ js::TransparentObjectWrapper(JSContext *cx, JSObject *objArg, JSObject *wrappedP
|
||||
|
||||
ErrorCopier::~ErrorCopier()
|
||||
{
|
||||
JSContext *cx = ac.context;
|
||||
if (cx->compartment == ac.destination &&
|
||||
ac.origin != ac.destination &&
|
||||
cx->isExceptionPending())
|
||||
{
|
||||
JSContext *cx = ac.ref().context();
|
||||
if (ac.ref().origin() != cx->compartment && cx->isExceptionPending()) {
|
||||
Value exc = cx->getPendingException();
|
||||
if (exc.isObject() && exc.toObject().isError() && exc.toObject().getPrivate()) {
|
||||
cx->clearPendingException();
|
||||
ac.leave();
|
||||
ac.destroy();
|
||||
Rooted<JSObject*> errObj(cx, &exc.toObject());
|
||||
JSObject *copyobj = js_CopyErrorObject(cx, errObj, scope);
|
||||
if (copyobj)
|
||||
@ -423,14 +420,14 @@ CrossCompartmentWrapper::~CrossCompartmentWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
#define PIERCE(cx, wrapper, mode, pre, op, post) \
|
||||
JS_BEGIN_MACRO \
|
||||
AutoCompartment call(cx, wrappedObject(wrapper)); \
|
||||
if (!call.enter()) \
|
||||
return false; \
|
||||
bool ok = (pre) && (op); \
|
||||
call.leave(); \
|
||||
return ok && (post); \
|
||||
#define PIERCE(cx, wrapper, mode, pre, op, post) \
|
||||
JS_BEGIN_MACRO \
|
||||
bool ok; \
|
||||
{ \
|
||||
AutoCompartment call(cx, wrappedObject(wrapper)); \
|
||||
ok = (pre) && (op); \
|
||||
} \
|
||||
return ok && (post); \
|
||||
JS_END_MACRO
|
||||
|
||||
#define NOTHING (true)
|
||||
@ -440,7 +437,7 @@ CrossCompartmentWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper,
|
||||
bool set, PropertyDescriptor *desc)
|
||||
{
|
||||
PIERCE(cx, wrapper, set ? SET : GET,
|
||||
call.destination->wrapId(cx, &id),
|
||||
cx->compartment->wrapId(cx, &id),
|
||||
DirectWrapper::getPropertyDescriptor(cx, wrapper, id, set, desc),
|
||||
cx->compartment->wrap(cx, desc));
|
||||
}
|
||||
@ -450,7 +447,7 @@ CrossCompartmentWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapp
|
||||
bool set, PropertyDescriptor *desc)
|
||||
{
|
||||
PIERCE(cx, wrapper, set ? SET : GET,
|
||||
call.destination->wrapId(cx, &id),
|
||||
cx->compartment->wrapId(cx, &id),
|
||||
DirectWrapper::getOwnPropertyDescriptor(cx, wrapper, id, set, desc),
|
||||
cx->compartment->wrap(cx, desc));
|
||||
}
|
||||
@ -460,7 +457,7 @@ CrossCompartmentWrapper::defineProperty(JSContext *cx, JSObject *wrapper, jsid i
|
||||
{
|
||||
AutoPropertyDescriptorRooter desc2(cx, desc);
|
||||
PIERCE(cx, wrapper, SET,
|
||||
call.destination->wrapId(cx, &id) && call.destination->wrap(cx, &desc2),
|
||||
cx->compartment->wrapId(cx, &id) && cx->compartment->wrap(cx, &desc2),
|
||||
DirectWrapper::defineProperty(cx, wrapper, id, &desc2),
|
||||
NOTHING);
|
||||
}
|
||||
@ -478,7 +475,7 @@ bool
|
||||
CrossCompartmentWrapper::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
||||
{
|
||||
PIERCE(cx, wrapper, SET,
|
||||
call.destination->wrapId(cx, &id),
|
||||
cx->compartment->wrapId(cx, &id),
|
||||
DirectWrapper::delete_(cx, wrapper, id, bp),
|
||||
NOTHING);
|
||||
}
|
||||
@ -496,7 +493,7 @@ bool
|
||||
CrossCompartmentWrapper::has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
||||
{
|
||||
PIERCE(cx, wrapper, GET,
|
||||
call.destination->wrapId(cx, &id),
|
||||
cx->compartment->wrapId(cx, &id),
|
||||
DirectWrapper::has(cx, wrapper, id, bp),
|
||||
NOTHING);
|
||||
}
|
||||
@ -505,7 +502,7 @@ bool
|
||||
CrossCompartmentWrapper::hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
||||
{
|
||||
PIERCE(cx, wrapper, GET,
|
||||
call.destination->wrapId(cx, &id),
|
||||
cx->compartment->wrapId(cx, &id),
|
||||
DirectWrapper::hasOwn(cx, wrapper, id, bp),
|
||||
NOTHING);
|
||||
}
|
||||
@ -518,7 +515,7 @@ CrossCompartmentWrapper::get(JSContext *cx, JSObject *wrapperArg, JSObject *rece
|
||||
RootedObject receiver(cx, receiverArg);
|
||||
RootedId id(cx, idArg);
|
||||
PIERCE(cx, wrapper, GET,
|
||||
call.destination->wrap(cx, receiver.address()) && call.destination->wrapId(cx, id.address()),
|
||||
cx->compartment->wrap(cx, receiver.address()) && cx->compartment->wrapId(cx, id.address()),
|
||||
DirectWrapper::get(cx, wrapper, receiver, id, vp),
|
||||
cx->compartment->wrap(cx, vp));
|
||||
}
|
||||
@ -531,9 +528,9 @@ CrossCompartmentWrapper::set(JSContext *cx, JSObject *wrapper_, JSObject *receiv
|
||||
RootedId id(cx, id_);
|
||||
RootedValue value(cx, *vp);
|
||||
PIERCE(cx, wrapper, SET,
|
||||
call.destination->wrap(cx, receiver.address()) &&
|
||||
call.destination->wrapId(cx, id.address()) &&
|
||||
call.destination->wrap(cx, value.address()),
|
||||
cx->compartment->wrap(cx, receiver.address()) &&
|
||||
cx->compartment->wrapId(cx, id.address()) &&
|
||||
cx->compartment->wrap(cx, value.address()),
|
||||
DirectWrapper::set(cx, wrapper, receiver, id, strict, value.address()),
|
||||
NOTHING);
|
||||
}
|
||||
@ -638,24 +635,21 @@ bool
|
||||
CrossCompartmentWrapper::call(JSContext *cx, JSObject *wrapper_, unsigned argc, Value *vp)
|
||||
{
|
||||
RootedObject wrapper(cx, wrapper_);
|
||||
|
||||
JSObject *wrapped = wrappedObject(wrapper);
|
||||
AutoCompartment call(cx, wrapped);
|
||||
if (!call.enter())
|
||||
return false;
|
||||
{
|
||||
AutoCompartment call(cx, wrapped);
|
||||
|
||||
vp[0] = ObjectValue(*wrapped);
|
||||
if (!call.destination->wrap(cx, &vp[1]))
|
||||
return false;
|
||||
Value *argv = JS_ARGV(cx, vp);
|
||||
for (size_t n = 0; n < argc; ++n) {
|
||||
if (!call.destination->wrap(cx, &argv[n]))
|
||||
vp[0] = ObjectValue(*wrapped);
|
||||
if (!cx->compartment->wrap(cx, &vp[1]))
|
||||
return false;
|
||||
Value *argv = JS_ARGV(cx, vp);
|
||||
for (size_t n = 0; n < argc; ++n) {
|
||||
if (!cx->compartment->wrap(cx, &argv[n]))
|
||||
return false;
|
||||
}
|
||||
if (!DirectWrapper::call(cx, wrapper, argc, vp))
|
||||
return false;
|
||||
}
|
||||
if (!DirectWrapper::call(cx, wrapper, argc, vp))
|
||||
return false;
|
||||
|
||||
call.leave();
|
||||
return cx->compartment->wrap(cx, vp);
|
||||
}
|
||||
|
||||
@ -664,19 +658,17 @@ CrossCompartmentWrapper::construct(JSContext *cx, JSObject *wrapper_, unsigned a
|
||||
Value *rval)
|
||||
{
|
||||
RootedObject wrapper(cx, wrapper_);
|
||||
JSObject *wrapped = wrappedObject(wrapper);
|
||||
{
|
||||
AutoCompartment call(cx, wrapped);
|
||||
|
||||
AutoCompartment call(cx, wrappedObject(wrapper));
|
||||
if (!call.enter())
|
||||
return false;
|
||||
|
||||
for (size_t n = 0; n < argc; ++n) {
|
||||
if (!call.destination->wrap(cx, &argv[n]))
|
||||
for (size_t n = 0; n < argc; ++n) {
|
||||
if (!cx->compartment->wrap(cx, &argv[n]))
|
||||
return false;
|
||||
}
|
||||
if (!DirectWrapper::construct(cx, wrapper, argc, argv, rval))
|
||||
return false;
|
||||
}
|
||||
if (!DirectWrapper::construct(cx, wrapper, argc, argv, rval))
|
||||
return false;
|
||||
|
||||
call.leave();
|
||||
return cx->compartment->wrap(cx, rval);
|
||||
}
|
||||
|
||||
@ -688,30 +680,28 @@ CrossCompartmentWrapper::nativeCall(JSContext *cx, IsAcceptableThis test, Native
|
||||
JS_ASSERT(srcArgs.thisv().isMagic(JS_IS_CONSTRUCTING) ||
|
||||
!UnwrapObject(wrapper)->isCrossCompartmentWrapper());
|
||||
|
||||
Rooted<JSObject*> wrapped(cx, wrappedObject(wrapper));
|
||||
AutoCompartment call(cx, wrapped);
|
||||
if (!call.enter())
|
||||
return false;
|
||||
|
||||
InvokeArgsGuard dstArgs;
|
||||
if (!cx->stack.pushInvokeArgs(cx, srcArgs.length(), &dstArgs))
|
||||
return false;
|
||||
|
||||
Value *src = srcArgs.base();
|
||||
Value *srcend = srcArgs.array() + srcArgs.length();
|
||||
Value *dst = dstArgs.base();
|
||||
for (; src < srcend; ++src, ++dst) {
|
||||
*dst = *src;
|
||||
if (!call.destination->wrap(cx, dst))
|
||||
RootedObject wrapped(cx, wrappedObject(wrapper));
|
||||
{
|
||||
AutoCompartment call(cx, wrapped);
|
||||
InvokeArgsGuard dstArgs;
|
||||
if (!cx->stack.pushInvokeArgs(cx, srcArgs.length(), &dstArgs))
|
||||
return false;
|
||||
|
||||
Value *src = srcArgs.base();
|
||||
Value *srcend = srcArgs.array() + srcArgs.length();
|
||||
Value *dst = dstArgs.base();
|
||||
for (; src < srcend; ++src, ++dst) {
|
||||
*dst = *src;
|
||||
if (!cx->compartment->wrap(cx, dst))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CallNonGenericMethod(cx, test, impl, dstArgs))
|
||||
return false;
|
||||
|
||||
srcArgs.rval().set(dstArgs.rval());
|
||||
dstArgs.pop();
|
||||
}
|
||||
|
||||
if (!CallNonGenericMethod(cx, test, impl, dstArgs))
|
||||
return false;
|
||||
|
||||
srcArgs.rval().set(dstArgs.rval());
|
||||
dstArgs.pop();
|
||||
call.leave();
|
||||
return cx->compartment->wrap(cx, srcArgs.rval().address());
|
||||
}
|
||||
|
||||
@ -719,11 +709,8 @@ bool
|
||||
CrossCompartmentWrapper::hasInstance(JSContext *cx, JSObject *wrapper, const Value *vp, bool *bp)
|
||||
{
|
||||
AutoCompartment call(cx, wrappedObject(wrapper));
|
||||
if (!call.enter())
|
||||
return false;
|
||||
|
||||
Value v = *vp;
|
||||
if (!call.destination->wrap(cx, &v))
|
||||
if (!cx->compartment->wrap(cx, &v))
|
||||
return false;
|
||||
return DirectWrapper::hasInstance(cx, wrapper, &v, bp);
|
||||
}
|
||||
@ -731,15 +718,13 @@ CrossCompartmentWrapper::hasInstance(JSContext *cx, JSObject *wrapper, const Val
|
||||
JSString *
|
||||
CrossCompartmentWrapper::obj_toString(JSContext *cx, JSObject *wrapper)
|
||||
{
|
||||
AutoCompartment call(cx, wrappedObject(wrapper));
|
||||
if (!call.enter())
|
||||
return NULL;
|
||||
|
||||
JSString *str = DirectWrapper::obj_toString(cx, wrapper);
|
||||
if (!str)
|
||||
return NULL;
|
||||
|
||||
call.leave();
|
||||
JSString *str = NULL;
|
||||
{
|
||||
AutoCompartment call(cx, wrappedObject(wrapper));
|
||||
str = DirectWrapper::obj_toString(cx, wrapper);
|
||||
if (!str)
|
||||
return NULL;
|
||||
}
|
||||
if (!cx->compartment->wrap(cx, &str))
|
||||
return NULL;
|
||||
return str;
|
||||
@ -748,15 +733,13 @@ CrossCompartmentWrapper::obj_toString(JSContext *cx, JSObject *wrapper)
|
||||
JSString *
|
||||
CrossCompartmentWrapper::fun_toString(JSContext *cx, JSObject *wrapper, unsigned indent)
|
||||
{
|
||||
AutoCompartment call(cx, wrappedObject(wrapper));
|
||||
if (!call.enter())
|
||||
return NULL;
|
||||
|
||||
JSString *str = DirectWrapper::fun_toString(cx, wrapper, indent);
|
||||
if (!str)
|
||||
return NULL;
|
||||
|
||||
call.leave();
|
||||
JSString *str = NULL;
|
||||
{
|
||||
AutoCompartment call(cx, wrappedObject(wrapper));
|
||||
str = DirectWrapper::fun_toString(cx, wrapper, indent);
|
||||
if (!str)
|
||||
return NULL;
|
||||
}
|
||||
if (!cx->compartment->wrap(cx, &str))
|
||||
return NULL;
|
||||
return str;
|
||||
@ -766,23 +749,17 @@ bool
|
||||
CrossCompartmentWrapper::regexp_toShared(JSContext *cx, JSObject *wrapper, RegExpGuard *g)
|
||||
{
|
||||
AutoCompartment call(cx, wrappedObject(wrapper));
|
||||
if (!call.enter())
|
||||
return false;
|
||||
|
||||
return DirectWrapper::regexp_toShared(cx, wrapper, g);
|
||||
}
|
||||
|
||||
bool
|
||||
CrossCompartmentWrapper::defaultValue(JSContext *cx, JSObject *wrapper, JSType hint, Value *vp)
|
||||
{
|
||||
AutoCompartment call(cx, wrappedObject(wrapper));
|
||||
if (!call.enter())
|
||||
return false;
|
||||
|
||||
if (!IndirectProxyHandler::defaultValue(cx, wrapper, hint, vp))
|
||||
return false;
|
||||
|
||||
call.leave();
|
||||
{
|
||||
AutoCompartment call(cx, wrappedObject(wrapper));
|
||||
if (!IndirectProxyHandler::defaultValue(cx, wrapper, hint, vp))
|
||||
return false;
|
||||
}
|
||||
return cx->compartment->wrap(cx, vp);
|
||||
}
|
||||
|
||||
@ -1082,9 +1059,9 @@ js::RemapWrapper(JSContext *cx, JSObject *wobj, JSObject *newTarget)
|
||||
|
||||
// First, we wrap it in the new compartment. This will return
|
||||
// a new wrapper.
|
||||
AutoCompartment ac(cx, wobj);
|
||||
JSObject *tobj = newTarget;
|
||||
if (!ac.enter() || !wcompartment->wrap(cx, &tobj))
|
||||
AutoCompartment ac(cx, wobj);
|
||||
if (!wcompartment->wrap(cx, &tobj))
|
||||
return false;
|
||||
|
||||
// Now, because we need to maintain object identity, we do a
|
||||
|
@ -896,10 +896,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
}
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment aec;
|
||||
if (!aec.enter(cx, global))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment ac(cx, global);
|
||||
uint32_t saved = JS_GetOptions(cx);
|
||||
uint32_t options = saved & ~(JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
|
||||
if (compileAndGo)
|
||||
@ -2307,13 +2304,12 @@ Clone(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
RootedObject obj(cx, JSVAL_IS_PRIMITIVE(argv[0]) ? NULL : JSVAL_TO_OBJECT(argv[0]));
|
||||
|
||||
if (obj && IsCrossCompartmentWrapper(obj)) {
|
||||
obj = UnwrapObject(obj);
|
||||
if (!ac.enter(cx, obj))
|
||||
return false;
|
||||
ac.construct(cx, obj);
|
||||
argv[0] = ObjectValue(*obj);
|
||||
}
|
||||
if (obj && obj->isFunction()) {
|
||||
@ -2540,10 +2536,7 @@ NewSandbox(JSContext *cx, bool lazy)
|
||||
return NULL;
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return NULL;
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
if (!lazy && !JS_InitStandardClasses(cx, obj))
|
||||
return NULL;
|
||||
|
||||
@ -2597,13 +2590,12 @@ EvalInContext(JSContext *cx, unsigned argc, jsval *vp)
|
||||
JS_DescribeScriptedCaller(cx, &script, &lineno);
|
||||
jsval rval;
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
unsigned flags;
|
||||
JSObject *unwrapped = UnwrapObject(sobj, true, &flags);
|
||||
if (flags & Wrapper::CROSS_COMPARTMENT) {
|
||||
sobj = unwrapped;
|
||||
if (!ac.enter(cx, sobj))
|
||||
return false;
|
||||
ac.construct(cx, sobj);
|
||||
}
|
||||
|
||||
sobj = GetInnerObject(cx, sobj);
|
||||
@ -4682,9 +4674,7 @@ NewGlobalObject(JSContext *cx)
|
||||
return NULL;
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, glob))
|
||||
return NULL;
|
||||
JSAutoCompartment ac(cx, glob);
|
||||
|
||||
#ifndef LAZY_STANDARD_CLASSES
|
||||
if (!JS_InitStandardClasses(cx, glob))
|
||||
|
@ -528,12 +528,8 @@ Debugger::slowPathOnLeaveFrame(JSContext *cx, bool frameOk)
|
||||
!frameobj->getReservedSlot(JSSLOT_DEBUGFRAME_ONPOP_HANDLER).isUndefined()) {
|
||||
RootedValue handler(cx, frameobj->getReservedSlot(JSSLOT_DEBUGFRAME_ONPOP_HANDLER));
|
||||
|
||||
AutoCompartment ac(cx, dbg->object);
|
||||
|
||||
if (!ac.enter()) {
|
||||
status = JSTRAP_ERROR;
|
||||
break;
|
||||
}
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, dbg->object);
|
||||
|
||||
Value completion;
|
||||
if (!dbg->newCompletionValue(cx, status, value, &completion)) {
|
||||
@ -726,9 +722,9 @@ Debugger::unwrapDebuggeeValue(JSContext *cx, Value *vp)
|
||||
}
|
||||
|
||||
JSTrapStatus
|
||||
Debugger::handleUncaughtException(AutoCompartment &ac, Value *vp, bool callHook)
|
||||
Debugger::handleUncaughtException(Maybe<AutoCompartment> &ac, Value *vp, bool callHook)
|
||||
{
|
||||
JSContext *cx = ac.context;
|
||||
JSContext *cx = ac.ref().context();
|
||||
if (cx->isExceptionPending()) {
|
||||
if (callHook && uncaughtExceptionHook) {
|
||||
Value fval = ObjectValue(*uncaughtExceptionHook);
|
||||
@ -744,7 +740,7 @@ Debugger::handleUncaughtException(AutoCompartment &ac, Value *vp, bool callHook)
|
||||
cx->clearPendingException();
|
||||
}
|
||||
}
|
||||
ac.leave();
|
||||
ac.destroy();
|
||||
return JSTRAP_ERROR;
|
||||
}
|
||||
|
||||
@ -811,35 +807,35 @@ Debugger::newCompletionValue(JSContext *cx, JSTrapStatus status, Value value_, V
|
||||
}
|
||||
|
||||
bool
|
||||
Debugger::receiveCompletionValue(AutoCompartment &ac, bool ok, Value val, Value *vp)
|
||||
Debugger::receiveCompletionValue(Maybe<AutoCompartment> &ac, bool ok, Value val, Value *vp)
|
||||
{
|
||||
JSContext *cx = ac.context;
|
||||
JSContext *cx = ac.ref().context();
|
||||
|
||||
JSTrapStatus status;
|
||||
Value value;
|
||||
resultToCompletion(cx, ok, val, &status, &value);
|
||||
ac.leave();
|
||||
ac.destroy();
|
||||
return newCompletionValue(cx, status, value, vp);
|
||||
}
|
||||
|
||||
JSTrapStatus
|
||||
Debugger::parseResumptionValue(AutoCompartment &ac, bool ok, const Value &rv, Value *vp,
|
||||
Debugger::parseResumptionValue(Maybe<AutoCompartment> &ac, bool ok, const Value &rv, Value *vp,
|
||||
bool callHook)
|
||||
{
|
||||
vp->setUndefined();
|
||||
if (!ok)
|
||||
return handleUncaughtException(ac, vp, callHook);
|
||||
if (rv.isUndefined()) {
|
||||
ac.leave();
|
||||
ac.destroy();
|
||||
return JSTRAP_CONTINUE;
|
||||
}
|
||||
if (rv.isNull()) {
|
||||
ac.leave();
|
||||
ac.destroy();
|
||||
return JSTRAP_ERROR;
|
||||
}
|
||||
|
||||
/* Check that rv is {return: val} or {throw: val}. */
|
||||
JSContext *cx = ac.context;
|
||||
JSContext *cx = ac.ref().context();
|
||||
Rooted<JSObject*> obj(cx);
|
||||
Shape *shape;
|
||||
jsid returnId = NameToId(cx->runtime->atomState.returnAtom);
|
||||
@ -864,7 +860,7 @@ Debugger::parseResumptionValue(AutoCompartment &ac, bool ok, const Value &rv, Va
|
||||
if (!js_NativeGet(cx, obj, obj, shape, 0, vp) || !unwrapDebuggeeValue(cx, vp))
|
||||
return handleUncaughtException(ac, vp, callHook);
|
||||
|
||||
ac.leave();
|
||||
ac.destroy();
|
||||
if (!cx->compartment->wrap(cx, vp)) {
|
||||
vp->setUndefined();
|
||||
return JSTRAP_ERROR;
|
||||
@ -894,14 +890,11 @@ Debugger::fireDebuggerStatement(JSContext *cx, Value *vp)
|
||||
JS_ASSERT(hook);
|
||||
JS_ASSERT(hook->isCallable());
|
||||
|
||||
/* Grab cx->fp() before pushing a dummy frame. */
|
||||
StackFrame *fp = cx->fp();
|
||||
AutoCompartment ac(cx, object);
|
||||
if (!ac.enter())
|
||||
return JSTRAP_ERROR;
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, object);
|
||||
|
||||
Value argv[1];
|
||||
if (!getScriptFrame(cx, fp, argv))
|
||||
if (!getScriptFrame(cx, cx->fp(), argv))
|
||||
return handleUncaughtException(ac, vp, false);
|
||||
|
||||
Value rv;
|
||||
@ -916,19 +909,17 @@ Debugger::fireExceptionUnwind(JSContext *cx, Value *vp)
|
||||
JS_ASSERT(hook);
|
||||
JS_ASSERT(hook->isCallable());
|
||||
|
||||
StackFrame *fp = cx->fp();
|
||||
RootedValue exc(cx, cx->getPendingException());
|
||||
cx->clearPendingException();
|
||||
|
||||
AutoCompartment ac(cx, object);
|
||||
if (!ac.enter())
|
||||
return JSTRAP_ERROR;
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, object);
|
||||
|
||||
Value argv[2];
|
||||
AutoValueArray avr(cx, argv, 2);
|
||||
|
||||
argv[1] = exc;
|
||||
if (!getScriptFrame(cx, fp, &argv[0]) || !wrapDebuggeeValue(cx, &argv[1]))
|
||||
if (!getScriptFrame(cx, cx->fp(), &argv[0]) || !wrapDebuggeeValue(cx, &argv[1]))
|
||||
return handleUncaughtException(ac, vp, false);
|
||||
|
||||
Value rv;
|
||||
@ -947,9 +938,8 @@ Debugger::fireEnterFrame(JSContext *cx, Value *vp)
|
||||
JS_ASSERT(hook->isCallable());
|
||||
|
||||
StackFrame *fp = cx->fp();
|
||||
AutoCompartment ac(cx, object);
|
||||
if (!ac.enter())
|
||||
return JSTRAP_ERROR;
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, object);
|
||||
|
||||
Value argv[1];
|
||||
if (!getScriptFrame(cx, fp, &argv[0]))
|
||||
@ -967,9 +957,8 @@ Debugger::fireNewScript(JSContext *cx, HandleScript script)
|
||||
JS_ASSERT(hook);
|
||||
JS_ASSERT(hook->isCallable());
|
||||
|
||||
AutoCompartment ac(cx, object);
|
||||
if (!ac.enter())
|
||||
return;
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, object);
|
||||
|
||||
JSObject *dsobj = wrapScript(cx, script);
|
||||
if (!dsobj) {
|
||||
@ -1122,9 +1111,8 @@ Debugger::onTrap(JSContext *cx, Value *vp)
|
||||
*/
|
||||
Debugger *dbg = bp->debugger;
|
||||
if (dbg->enabled && dbg->debuggees.lookup(scriptGlobal)) {
|
||||
AutoCompartment ac(cx, dbg->object);
|
||||
if (!ac.enter())
|
||||
return JSTRAP_ERROR;
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, dbg->object);
|
||||
|
||||
Value argv[1];
|
||||
AutoValueArray ava(cx, argv, 1);
|
||||
@ -1239,9 +1227,10 @@ Debugger::onSingleStep(JSContext *cx, Value *vp)
|
||||
for (JSObject **p = frames.begin(); p != frames.end(); p++) {
|
||||
JSObject *frame = *p;
|
||||
Debugger *dbg = Debugger::fromChildJSObject(frame);
|
||||
AutoCompartment ac(cx, dbg->object);
|
||||
if (!ac.enter())
|
||||
return JSTRAP_ERROR;
|
||||
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, dbg->object);
|
||||
|
||||
const Value &handler = frame->getReservedSlot(JSSLOT_DEBUGFRAME_ONSTEP_HANDLER);
|
||||
Value rval;
|
||||
bool ok = Invoke(cx, ObjectValue(*frame), handler, 0, NULL, &rval);
|
||||
@ -1897,8 +1886,6 @@ Debugger::addDebuggeeGlobal(JSContext *cx, Handle<GlobalObject*> global)
|
||||
* JSCompartment::addDebuggee enables debug mode if needed.
|
||||
*/
|
||||
AutoCompartment ac(cx, global);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
GlobalObject::DebuggerVector *v = GlobalObject::getOrCreateDebuggers(cx, global);
|
||||
if (!v || !v->append(this)) {
|
||||
js_ReportOutOfMemory(cx);
|
||||
@ -3096,8 +3083,6 @@ DebuggerFrame_getEnvironment(JSContext *cx, unsigned argc, Value *vp)
|
||||
Rooted<Env*> env(cx);
|
||||
{
|
||||
AutoCompartment ac(cx, fp->scopeChain());
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
env = GetDebugScopeForFrame(cx, fp);
|
||||
if (!env)
|
||||
return false;
|
||||
@ -3140,8 +3125,6 @@ DebuggerFrame_getThis(JSContext *cx, unsigned argc, Value *vp)
|
||||
Value thisv;
|
||||
{
|
||||
AutoCompartment ac(cx, fp->scopeChain());
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
if (!ComputeThis(cx, fp))
|
||||
return false;
|
||||
thisv = fp->thisValue();
|
||||
@ -3373,8 +3356,6 @@ DebuggerFrame_setOnStep(JSContext *cx, unsigned argc, Value *vp)
|
||||
if (delta != 0) {
|
||||
/* Try to adjust this frame's script single-step mode count. */
|
||||
AutoCompartment ac(cx, fp->scopeChain());
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
if (!fp->script()->changeStepModeCount(cx, delta))
|
||||
return false;
|
||||
}
|
||||
@ -3494,9 +3475,8 @@ DebuggerFrameEval(JSContext *cx, unsigned argc, Value *vp, EvalBindingsMode mode
|
||||
}
|
||||
}
|
||||
|
||||
AutoCompartment ac(cx, fp->scopeChain());
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, fp->scopeChain());
|
||||
|
||||
Rooted<Env *> env(cx, GetDebugScopeForFrame(cx, fp));
|
||||
if (!env)
|
||||
@ -3804,9 +3784,6 @@ DebuggerObject_getEnvironment(JSContext *cx, unsigned argc, Value *vp)
|
||||
Rooted<Env*> env(cx);
|
||||
{
|
||||
AutoCompartment ac(cx, obj);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
|
||||
env = GetDebugScopeForFunction(cx, obj->toFunction());
|
||||
if (!env)
|
||||
return false;
|
||||
@ -3827,8 +3804,9 @@ DebuggerObject_getOwnPropertyDescriptor(JSContext *cx, unsigned argc, Value *vp)
|
||||
/* Bug: This can cause the debuggee to run! */
|
||||
AutoPropertyDescriptorRooter desc(cx);
|
||||
{
|
||||
AutoCompartment ac(cx, obj);
|
||||
if (!ac.enter() || !cx->compartment->wrapId(cx, id.address()))
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, obj);
|
||||
if (!cx->compartment->wrapId(cx, id.address()))
|
||||
return false;
|
||||
|
||||
ErrorCopier ec(ac, dbg->toJSObject());
|
||||
@ -3864,10 +3842,8 @@ DebuggerObject_getOwnPropertyNames(JSContext *cx, unsigned argc, Value *vp)
|
||||
|
||||
AutoIdVector keys(cx);
|
||||
{
|
||||
AutoCompartment ac(cx, obj);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, obj);
|
||||
ErrorCopier ec(ac, dbg->toJSObject());
|
||||
if (!GetPropertyNames(cx, obj, JSITER_OWNONLY | JSITER_HIDDEN, &keys))
|
||||
return false;
|
||||
@ -3931,8 +3907,9 @@ DebuggerObject_defineProperty(JSContext *cx, unsigned argc, Value *vp)
|
||||
return false;
|
||||
RootedId wrappedId(cx);
|
||||
|
||||
AutoCompartment ac(cx, obj);
|
||||
if (!ac.enter() || !unwrappedDesc->wrapInto(cx, obj, id, wrappedId.address(), rewrappedDesc))
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, obj);
|
||||
if (!unwrappedDesc->wrapInto(cx, obj, id, wrappedId.address(), rewrappedDesc))
|
||||
return false;
|
||||
|
||||
ErrorCopier ec(ac, dbg->toJSObject());
|
||||
@ -3974,9 +3951,8 @@ DebuggerObject_defineProperties(JSContext *cx, unsigned argc, Value *vp)
|
||||
AutoIdVector rewrappedIds(cx);
|
||||
AutoPropDescArrayRooter rewrappedDescs(cx);
|
||||
|
||||
AutoCompartment ac(cx, obj);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, obj);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (!rewrappedIds.append(jsid()) || !rewrappedDescs.append())
|
||||
return false;
|
||||
@ -4009,8 +3985,9 @@ DebuggerObject_deleteProperty(JSContext *cx, unsigned argc, Value *vp)
|
||||
THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "deleteProperty", args, dbg, obj);
|
||||
Value nameArg = argc > 0 ? args[0] : UndefinedValue();
|
||||
|
||||
AutoCompartment ac(cx, obj);
|
||||
if (!ac.enter() || !cx->compartment->wrap(cx, &nameArg))
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, obj);
|
||||
if (!cx->compartment->wrap(cx, &nameArg))
|
||||
return false;
|
||||
|
||||
ErrorCopier ec(ac, dbg->toJSObject());
|
||||
@ -4024,10 +4001,8 @@ DebuggerObject_sealHelper(JSContext *cx, unsigned argc, Value *vp, SealHelperOp
|
||||
{
|
||||
THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, name, args, dbg, obj);
|
||||
|
||||
AutoCompartment ac(cx, obj);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, obj);
|
||||
ErrorCopier ec(ac, dbg->toJSObject());
|
||||
bool ok;
|
||||
if (op == Seal) {
|
||||
@ -4072,10 +4047,8 @@ DebuggerObject_isSealedHelper(JSContext *cx, unsigned argc, Value *vp, SealHelpe
|
||||
{
|
||||
THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, name, args, dbg, obj);
|
||||
|
||||
AutoCompartment ac(cx, obj);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, obj);
|
||||
ErrorCopier ec(ac, dbg->toJSObject());
|
||||
bool r;
|
||||
if (op == Seal) {
|
||||
@ -4165,8 +4138,9 @@ ApplyOrCall(JSContext *cx, unsigned argc, Value *vp, ApplyOrCallMode mode)
|
||||
* Enter the debuggee compartment and rewrap all input value for that compartment.
|
||||
* (Rewrapping always takes place in the destination compartment.)
|
||||
*/
|
||||
AutoCompartment ac(cx, obj);
|
||||
if (!ac.enter() || !cx->compartment->wrap(cx, &calleev) || !cx->compartment->wrap(cx, &thisv))
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, obj);
|
||||
if (!cx->compartment->wrap(cx, &calleev) || !cx->compartment->wrap(cx, &thisv))
|
||||
return false;
|
||||
for (unsigned i = 0; i < callArgc; i++) {
|
||||
if (!cx->compartment->wrap(cx, &callArgv[i]))
|
||||
@ -4206,8 +4180,7 @@ DebuggerObject_makeDebuggeeValue(JSContext *cx, unsigned argc, Value *vp)
|
||||
// argument as appropriate for references from there.
|
||||
{
|
||||
AutoCompartment ac(cx, referent);
|
||||
if (!ac.enter() ||
|
||||
!cx->compartment->wrap(cx, &args[0]))
|
||||
if (!cx->compartment->wrap(cx, &args[0]))
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -4430,10 +4403,8 @@ DebuggerEnv_names(JSContext *cx, unsigned argc, Value *vp)
|
||||
|
||||
AutoIdVector keys(cx);
|
||||
{
|
||||
AutoCompartment ac(cx, env);
|
||||
if (!ac.enter())
|
||||
return false;
|
||||
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, env);
|
||||
ErrorCopier ec(ac, dbg->toJSObject());
|
||||
if (!GetPropertyNames(cx, env, JSITER_HIDDEN, &keys))
|
||||
return false;
|
||||
@ -4466,8 +4437,9 @@ DebuggerEnv_find(JSContext *cx, unsigned argc, Value *vp)
|
||||
return false;
|
||||
|
||||
{
|
||||
AutoCompartment ac(cx, env);
|
||||
if (!ac.enter() || !cx->compartment->wrapId(cx, id.address()))
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, env);
|
||||
if (!cx->compartment->wrapId(cx, id.address()))
|
||||
return false;
|
||||
|
||||
/* This can trigger resolve hooks. */
|
||||
@ -4497,8 +4469,9 @@ DebuggerEnv_getVariable(JSContext *cx, unsigned argc, Value *vp)
|
||||
|
||||
RootedValue v(cx);
|
||||
{
|
||||
AutoCompartment ac(cx, env);
|
||||
if (!ac.enter() || !cx->compartment->wrapId(cx, id.address()))
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, env);
|
||||
if (!cx->compartment->wrapId(cx, id.address()))
|
||||
return false;
|
||||
|
||||
/* This can trigger getters. */
|
||||
@ -4528,13 +4501,10 @@ DebuggerEnv_setVariable(JSContext *cx, unsigned argc, Value *vp)
|
||||
return false;
|
||||
|
||||
{
|
||||
AutoCompartment ac(cx, env);
|
||||
if (!ac.enter() ||
|
||||
!cx->compartment->wrapId(cx, id.address()) ||
|
||||
!cx->compartment->wrap(cx, v.address()))
|
||||
{
|
||||
Maybe<AutoCompartment> ac;
|
||||
ac.construct(cx, env);
|
||||
if (!cx->compartment->wrapId(cx, id.address()) || !cx->compartment->wrap(cx, v.address()))
|
||||
return false;
|
||||
}
|
||||
|
||||
/* This can trigger setters. */
|
||||
ErrorCopier ec(ac, dbg->toJSObject());
|
||||
|
@ -107,7 +107,7 @@ class Debugger {
|
||||
* do some things in the debugger compartment and some things in the
|
||||
* debuggee compartment.
|
||||
*/
|
||||
JSTrapStatus handleUncaughtException(AutoCompartment &ac, Value *vp, bool callHook);
|
||||
JSTrapStatus handleUncaughtException(Maybe<AutoCompartment> &ac, Value *vp, bool callHook);
|
||||
|
||||
/*
|
||||
* Handle the result of a hook that is expected to return a resumption
|
||||
@ -134,8 +134,8 @@ class Debugger {
|
||||
* anything else - Make a new TypeError the pending exception and
|
||||
* return handleUncaughtException(ac, vp, callHook).
|
||||
*/
|
||||
JSTrapStatus parseResumptionValue(AutoCompartment &ac, bool ok, const Value &rv, Value *vp,
|
||||
bool callHook = true);
|
||||
JSTrapStatus parseResumptionValue(Maybe<AutoCompartment> &ac, bool ok, const Value &rv,
|
||||
Value *vp, bool callHook = true);
|
||||
|
||||
JSObject *unwrapDebuggeeArgument(JSContext *cx, const Value &v);
|
||||
|
||||
@ -330,7 +330,7 @@ class Debugger {
|
||||
* pending exception. (This ordinarily returns true even if the ok argument
|
||||
* is false.)
|
||||
*/
|
||||
bool receiveCompletionValue(AutoCompartment &ac, bool ok, Value val, Value *vp);
|
||||
bool receiveCompletionValue(Maybe<AutoCompartment> &ac, bool ok, Value val, Value *vp);
|
||||
|
||||
/*
|
||||
* Return the Debugger.Script object for |script|, or create a new one if
|
||||
|
@ -893,7 +893,6 @@ ContextStack::ensureOnTop(JSContext *cx, MaybeReportError report, unsigned nvars
|
||||
|
||||
if (fun) {
|
||||
AutoCompartment ac(cx, fun);
|
||||
(void) ac.enter();
|
||||
fun->script()->uninlineable = true;
|
||||
types::MarkTypeObjectFlags(cx, fun, types::OBJECT_FLAG_UNINLINEABLE);
|
||||
}
|
||||
|
@ -505,9 +505,7 @@ mozJSComponentLoader::LoadModule(FileLocation &aFile)
|
||||
return NULL;
|
||||
|
||||
JSCLContextHelper cx(this);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, entry->global))
|
||||
return NULL;
|
||||
JSAutoCompartment ac(cx, entry->global);
|
||||
|
||||
JSObject* cm_jsobj;
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> cm_holder;
|
||||
@ -655,10 +653,7 @@ mozJSComponentLoader::GlobalForLocation(nsIFile *aComponentFile,
|
||||
rv = holder->GetJSObject(&global);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, global))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
JSAutoCompartment ac(cx, global);
|
||||
if (!JS_DefineFunctions(cx, global, gGlobalFun) ||
|
||||
!JS_DefineProfilingFunctions(cx, global)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -1036,10 +1031,9 @@ mozJSComponentLoader::Import(const nsACString& registryLocation,
|
||||
targetObject = JS_GetGlobalForObject(cx, targetObject);
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (targetObject && !ac.enter(cx, targetObject)) {
|
||||
NS_ERROR("can't enter compartment");
|
||||
return NS_ERROR_FAILURE;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
if (targetObject) {
|
||||
ac.construct(cx, targetObject);
|
||||
}
|
||||
|
||||
JSObject *globalObj = nullptr;
|
||||
@ -1171,10 +1165,7 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
|
||||
|
||||
if (targetObj) {
|
||||
JSCLContextHelper cxhelper(this);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(mContext, mod->global))
|
||||
return NS_ERROR_FAILURE;
|
||||
JSAutoCompartment ac(mContext, mod->global);
|
||||
|
||||
JS::Value symbols;
|
||||
if (!JS_GetProperty(mContext, mod->global,
|
||||
@ -1223,10 +1214,9 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
|
||||
bytes.ptr());
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment target_ac;
|
||||
JSAutoCompartment target_ac(mContext, targetObj);
|
||||
|
||||
if (!target_ac.enter(mContext, targetObj) ||
|
||||
!JS_WrapValue(mContext, &val) ||
|
||||
if (!JS_WrapValue(mContext, &val) ||
|
||||
!JS_SetPropertyById(mContext, targetObj, symbolId, &val)) {
|
||||
JSAutoByteString bytes(mContext, JSID_TO_STRING(symbolId));
|
||||
if (!bytes)
|
||||
|
@ -98,8 +98,7 @@ class mozJSComponentLoader : public mozilla::ModuleLoader,
|
||||
if (global) {
|
||||
JSAutoRequest ar(sSelf->mContext);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
ac.enterAndIgnoreErrors(sSelf->mContext, global);
|
||||
JSAutoCompartment ac(sSelf->mContext, global);
|
||||
|
||||
JS_ClearScope(sSelf->mContext, global);
|
||||
JS_RemoveObjectRoot(sSelf->mContext, &global);
|
||||
|
@ -217,9 +217,7 @@ mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, targetObj))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
JSAutoCompartment ac(cx, targetObj);
|
||||
|
||||
/* load up the url. From here on, failures are reflected as ``custom''
|
||||
* js exceptions */
|
||||
@ -300,8 +298,8 @@ mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
|
||||
bool ok = JS_ExecuteScriptVersion(cx, targetObj, script, retval, version);
|
||||
|
||||
if (ok) {
|
||||
JSAutoEnterCompartment rac;
|
||||
if (!rac.enter(cx, result_obj) || !JS_WrapValue(cx, retval))
|
||||
JSAutoCompartment rac(cx, result_obj);
|
||||
if (!JS_WrapValue(cx, retval))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
|
@ -1876,11 +1876,7 @@ main(int argc, char **argv, char **envp)
|
||||
|
||||
JS_BeginRequest(cx);
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, glob)) {
|
||||
JS_EndRequest(cx);
|
||||
return 1;
|
||||
}
|
||||
JSAutoCompartment ac(cx, glob);
|
||||
|
||||
if (!JS_InitReflect(cx, glob)) {
|
||||
JS_EndRequest(cx);
|
||||
|
@ -2719,9 +2719,7 @@ nsXPCComponents_Utils::LookupMethod(const JS::Value& object,
|
||||
|
||||
{
|
||||
// Enter the target compartment.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return NS_ERROR_FAILURE;
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
|
||||
// Morph slim wrappers.
|
||||
if (IS_SLIM_WRAPPER(obj) && !MorphSlimWrapper(cx, obj))
|
||||
@ -2916,10 +2914,7 @@ SandboxImport(JSContext *cx, unsigned argc, jsval *vp)
|
||||
funobj = XPCWrapper::UnsafeUnwrapSecurityWrapper(funobj);
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, funobj)) {
|
||||
return false;
|
||||
}
|
||||
JSAutoCompartment ac(cx, funobj);
|
||||
|
||||
JSFunction *fun = JS_ValueToFunction(cx, OBJECT_TO_JSVAL(funobj));
|
||||
if (!fun) {
|
||||
@ -3273,9 +3268,7 @@ xpc_CreateSandboxObject(JSContext *cx, jsval *vp, nsISupports *prinOrSop, Sandbo
|
||||
JS::AutoObjectRooter tvr(cx, sandbox);
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, sandbox))
|
||||
return NS_ERROR_XPC_UNEXPECTED;
|
||||
JSAutoCompartment ac(cx, sandbox);
|
||||
|
||||
if (options.proto) {
|
||||
bool ok = JS_WrapObject(cx, &options.proto);
|
||||
@ -3316,9 +3309,7 @@ xpc_CreateSandboxObject(JSContext *cx, jsval *vp, nsISupports *prinOrSop, Sandbo
|
||||
return NS_ERROR_XPC_UNEXPECTED;
|
||||
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(ccx, sandbox))
|
||||
return NS_ERROR_XPC_UNEXPECTED;
|
||||
JSAutoCompartment ac(ccx, sandbox);
|
||||
XPCWrappedNativeScope* scope =
|
||||
XPCWrappedNativeScope::GetNewOrUsed(ccx, sandbox);
|
||||
|
||||
@ -3920,13 +3911,7 @@ xpc_EvalInSandbox(JSContext *cx, JSObject *sandbox, const nsAString& source,
|
||||
|
||||
{
|
||||
JSAutoRequest req(sandcx->GetJSContext());
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(sandcx->GetJSContext(), sandbox)) {
|
||||
if (stack)
|
||||
unused << stack->Pop();
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(sandcx->GetJSContext(), sandbox);
|
||||
|
||||
jsval v;
|
||||
JSString *str = nullptr;
|
||||
@ -3983,14 +3968,14 @@ xpc_EvalInSandbox(JSContext *cx, JSObject *sandbox, const nsAString& source,
|
||||
} else {
|
||||
// Convert the result into something safe for our caller.
|
||||
JSAutoRequest req(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
JSAutoCompartment ac(cx, callingScope);
|
||||
|
||||
if (str) {
|
||||
v = STRING_TO_JSVAL(str);
|
||||
}
|
||||
|
||||
CompartmentPrivate *sandboxdata = GetCompartmentPrivate(sandbox);
|
||||
if (!ac.enter(cx, callingScope) ||
|
||||
!WrapForSandbox(cx, sandboxdata->wantXrays, &v)) {
|
||||
if (!WrapForSandbox(cx, sandboxdata->wantXrays, &v)) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -4171,9 +4156,7 @@ nsXPCComponents_Utils::GetGlobalForObject(const JS::Value& object,
|
||||
JS::Rooted<JSObject*> obj(cx, JSVAL_TO_OBJECT(object));
|
||||
obj = js::UnwrapObject(obj);
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return NS_ERROR_FAILURE;
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
obj = JS_GetGlobalForObject(cx, obj);
|
||||
}
|
||||
JS_WrapObject(cx, obj.address());
|
||||
@ -4200,10 +4183,7 @@ nsXPCComponents_Utils::CreateObjectIn(const jsval &vobj, JSContext *cx, jsval *r
|
||||
JSObject *scope = js::UnwrapObject(JSVAL_TO_OBJECT(vobj));
|
||||
JSObject *obj;
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, scope))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
JSAutoCompartment ac(cx, scope);
|
||||
obj = JS_NewObject(cx, nullptr, nullptr, scope);
|
||||
if (!obj)
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -4229,10 +4209,7 @@ nsXPCComponents_Utils::CreateArrayIn(const jsval &vobj, JSContext *cx, jsval *rv
|
||||
JSObject *scope = js::UnwrapObject(JSVAL_TO_OBJECT(vobj));
|
||||
JSObject *obj;
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, scope))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
JSAutoCompartment ac(cx, scope);
|
||||
obj = JS_NewArrayObject(cx, 0, NULL);
|
||||
if (!obj)
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -4285,10 +4262,7 @@ nsXPCComponents_Utils::MakeObjectPropsNormal(const jsval &vobj, JSContext *cx)
|
||||
|
||||
JSObject *obj = js::UnwrapObject(JSVAL_TO_OBJECT(vobj));
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
JS::AutoIdArray ida(cx, JS_Enumerate(cx, obj));
|
||||
if (!ida)
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -4352,11 +4326,14 @@ nsXPCComponents_Utils::Dispatch(const jsval &runnable_, const jsval &scope,
|
||||
JSContext *cx)
|
||||
{
|
||||
// Enter the given compartment, if any, and rewrap runnable.
|
||||
JSAutoEnterCompartment ac;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
js::Value runnable = runnable_;
|
||||
if (scope.isObject()) {
|
||||
JSObject *scopeObj = js::UnwrapObject(&scope.toObject());
|
||||
if (!scopeObj || !ac.enter(cx, scopeObj) || !JS_WrapValue(cx, &runnable))
|
||||
if (!scopeObj)
|
||||
return NS_ERROR_FAILURE;
|
||||
ac.construct(cx, scopeObj);
|
||||
if (!JS_WrapValue(cx, &runnable))
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -1015,14 +1015,7 @@ XPCConvert::JSObject2NativeInterface(XPCCallContext& ccx,
|
||||
NS_ASSERTION(iid, "bad param");
|
||||
|
||||
JSContext* cx = ccx.GetJSContext();
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, src)) {
|
||||
if (pErr)
|
||||
*pErr = NS_ERROR_UNEXPECTED;
|
||||
return false;
|
||||
}
|
||||
JSAutoCompartment ac(cx, src);
|
||||
|
||||
*dest = nullptr;
|
||||
if (pErr)
|
||||
|
@ -77,9 +77,7 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
|
||||
jsbytecode* pc = JS_GetFramePC(cx, fp);
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, JS_GetGlobalForFrame(fp)))
|
||||
return buf;
|
||||
JSAutoCompartment ac(cx, JS_GetGlobalForFrame(fp));
|
||||
|
||||
if (script && pc) {
|
||||
filename = JS_GetScriptFilename(cx, script);
|
||||
|
@ -1858,27 +1858,22 @@ class XPCJSRuntimeStats : public JS::RuntimeStats
|
||||
if (JSObject *global = JS_GetGlobalForCompartmentOrNull(cx, c)) {
|
||||
// Need to enter the compartment, otherwise GetNativeOfWrapper()
|
||||
// might crash.
|
||||
JSAutoEnterCompartment aec;
|
||||
if (aec.enter(cx, global)) {
|
||||
nsISupports *native = xpc->GetNativeOfWrapper(cx, global);
|
||||
if (nsCOMPtr<nsPIDOMWindow> piwindow = do_QueryInterface(native)) {
|
||||
// The global is a |window| object. Use the path prefix that
|
||||
// we should have already created for it.
|
||||
if (mWindowPaths->Get(piwindow->WindowID(), &cJSPathPrefix)) {
|
||||
cDOMPathPrefix.Assign(cJSPathPrefix);
|
||||
cDOMPathPrefix.AppendLiteral("/dom/");
|
||||
cJSPathPrefix.AppendLiteral("/js/");
|
||||
} else {
|
||||
cJSPathPrefix.AssignLiteral("explicit/js-non-window/compartments/unknown-window-global/");
|
||||
cDOMPathPrefix.AssignLiteral("explicit/dom/?!/");
|
||||
}
|
||||
JSAutoCompartment ac(cx, global);
|
||||
nsISupports *native = xpc->GetNativeOfWrapper(cx, global);
|
||||
if (nsCOMPtr<nsPIDOMWindow> piwindow = do_QueryInterface(native)) {
|
||||
// The global is a |window| object. Use the path prefix that
|
||||
// we should have already created for it.
|
||||
if (mWindowPaths->Get(piwindow->WindowID(), &cJSPathPrefix)) {
|
||||
cDOMPathPrefix.Assign(cJSPathPrefix);
|
||||
cDOMPathPrefix.AppendLiteral("/dom/");
|
||||
cJSPathPrefix.AppendLiteral("/js/");
|
||||
} else {
|
||||
cJSPathPrefix.AssignLiteral("explicit/js-non-window/compartments/non-window-global/");
|
||||
cJSPathPrefix.AssignLiteral("explicit/js-non-window/compartments/unknown-window-global/");
|
||||
cDOMPathPrefix.AssignLiteral("explicit/dom/?!/");
|
||||
}
|
||||
} else {
|
||||
cJSPathPrefix.AssignLiteral("explicit/js-non-window/compartments/unentered/");
|
||||
cDOMPathPrefix.AssignLiteral("explicit/dom/unentered/");
|
||||
cJSPathPrefix.AssignLiteral("explicit/js-non-window/compartments/non-window-global/");
|
||||
cDOMPathPrefix.AssignLiteral("explicit/dom/?!/");
|
||||
}
|
||||
} else {
|
||||
cJSPathPrefix.AssignLiteral("explicit/js-non-window/compartments/no-global/");
|
||||
|
@ -36,8 +36,7 @@ bool AutoScriptEvaluate::StartEvaluating(JSObject *scope, JSErrorReporter errorR
|
||||
}
|
||||
|
||||
JS_BeginRequest(mJSContext);
|
||||
if (!mEnterCompartment.enter(mJSContext, scope))
|
||||
return false;
|
||||
mAutoCompartment.construct(mJSContext, scope);
|
||||
|
||||
// Saving the exception state keeps us from interfering with another script
|
||||
// that may also be running on this context. This occurred first with the
|
||||
@ -504,9 +503,7 @@ GetContextFromObject(JSObject *obj)
|
||||
if (!ccx.IsValid())
|
||||
return nullptr;
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(ccx, obj))
|
||||
return nullptr;
|
||||
JSAutoCompartment ac(ccx, obj);
|
||||
XPCWrappedNativeScope* scope =
|
||||
XPCWrappedNativeScope::FindInJSObjectScope(ccx, obj);
|
||||
XPCContext *xpcc = scope->GetContext();
|
||||
@ -1147,10 +1144,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
|
||||
JSObject *obj = wrapper->GetJSObject();
|
||||
JSObject *thisObj = obj;
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
ccx.SetScopeForNewJSObjects(obj);
|
||||
|
||||
JS::AutoValueVector args(cx);
|
||||
|
@ -323,9 +323,7 @@ XPCWrappedNative::WrapNewGlobal(XPCCallContext &ccx, xpcObjectHelper &nativeHelp
|
||||
|
||||
// Immediately enter the global's compartment, so that everything else we
|
||||
// create ends up there.
|
||||
JSAutoEnterCompartment ac;
|
||||
success = ac.enter(ccx, global);
|
||||
MOZ_ASSERT(success);
|
||||
JSAutoCompartment ac(ccx, global);
|
||||
|
||||
// If requested, immediately initialize the standard classes on the global.
|
||||
// We need to do this before creating a scope, because
|
||||
@ -519,7 +517,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
||||
JSBool needsSOW = false;
|
||||
JSBool needsCOW = false;
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
mozilla::Maybe<JSAutoCompartment> ac;
|
||||
|
||||
if (sciWrapper.GetFlags().WantPreCreate()) {
|
||||
JSObject* plannedParent = parent;
|
||||
@ -535,8 +533,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
||||
NS_ASSERTION(!xpc::WrapperFactory::IsXrayWrapper(parent),
|
||||
"Xray wrapper being used to parent XPCWrappedNative?");
|
||||
|
||||
if (!ac.enter(ccx, parent))
|
||||
return NS_ERROR_FAILURE;
|
||||
ac.construct(ccx, parent);
|
||||
|
||||
if (parent != plannedParent) {
|
||||
XPCWrappedNativeScope* betterScope =
|
||||
@ -577,8 +574,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
||||
return NS_OK;
|
||||
}
|
||||
} else {
|
||||
if (!ac.enter(ccx, parent))
|
||||
return NS_ERROR_FAILURE;
|
||||
ac.construct(ccx, parent);
|
||||
|
||||
nsISupports *Object = helper.Object();
|
||||
if (nsXPCWrappedJSClass::IsWrappedJS(Object)) {
|
||||
@ -792,11 +788,7 @@ XPCWrappedNative::Morph(XPCCallContext& ccx,
|
||||
// *seen* this happen.
|
||||
AutoMarkingWrappedNativePtr wrapperMarker(ccx, wrapper);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(ccx, existingJSObject)) {
|
||||
wrapper->mIdentity = nullptr;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(ccx, existingJSObject);
|
||||
if (!wrapper->Init(ccx, existingJSObject))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@ -1527,9 +1519,7 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(ccx, aNewScope->GetGlobalJSObject()))
|
||||
return NS_ERROR_FAILURE;
|
||||
JSAutoCompartment ac(ccx, aNewScope->GetGlobalJSObject());
|
||||
|
||||
if (aOldScope != aNewScope) {
|
||||
// Oh, so now we need to move the wrapper to a different scope.
|
||||
@ -1609,9 +1599,8 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
|
||||
// that the object might have. This forces us to take the 'WithWrapper' path
|
||||
// while transplanting that handles this stuff correctly.
|
||||
{
|
||||
JSAutoEnterCompartment innerAC;
|
||||
if (!innerAC.enter(ccx, aOldScope->GetGlobalJSObject()) ||
|
||||
!wrapper->GetSameCompartmentSecurityWrapper(ccx))
|
||||
JSAutoCompartment innerAC(ccx, aOldScope->GetGlobalJSObject());
|
||||
if (!wrapper->GetSameCompartmentSecurityWrapper(ccx))
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -3808,12 +3797,7 @@ ConstructSlimWrapper(XPCCallContext &ccx,
|
||||
return false;
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(ccx, parent)) {
|
||||
SLIM_LOG_NOT_CREATED(ccx, identityObj, "unable to enter compartment");
|
||||
|
||||
return false;
|
||||
}
|
||||
JSAutoCompartment ac(ccx, parent);
|
||||
|
||||
if (parent != plannedParent) {
|
||||
XPCWrappedNativeScope *newXpcScope =
|
||||
|
@ -144,9 +144,7 @@ GetDoubleWrappedJSObject(XPCCallContext& ccx, XPCWrappedNative* wrapper)
|
||||
jsid id = ccx.GetRuntime()->
|
||||
GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(ccx, mainObj))
|
||||
return NULL;
|
||||
JSAutoCompartment ac(ccx, mainObj);
|
||||
|
||||
jsval val;
|
||||
if (JS_GetPropertyById(ccx, mainObj, id, &val) &&
|
||||
|
@ -673,9 +673,7 @@ XPCWrappedNativeScope::FindInJSObjectScope(JSContext* cx, JSObject* obj,
|
||||
|
||||
// Else we'll have to look up the parent chain to get the scope
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
ac.enterAndIgnoreErrors(cx, obj);
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
obj = JS_GetGlobalForObject(cx, obj);
|
||||
|
||||
if (js::GetObjectClass(obj)->flags & JSCLASS_XPCONNECT_GLOBAL) {
|
||||
|
@ -421,8 +421,7 @@ def write_cpp(iface, fd):
|
||||
" NS_ENSURE_STATE(pusher.ref().Push(aCx, false));\n"
|
||||
" }\n"
|
||||
" JSAutoRequest ar(aCx);\n"
|
||||
" JSAutoEnterCompartment ac;\n"
|
||||
" NS_ENSURE_STATE(ac.enter(aCx, obj));\n")
|
||||
" JSAutoCompartment ac(aCx, obj);\n")
|
||||
|
||||
fd.write(" return %s_InitInternal(*this, aCx, obj);\n}\n\n" %
|
||||
iface.name)
|
||||
|
@ -420,12 +420,7 @@ ListBase<LC>::create(JSContext *cx, JSObject *scope, ListType *aList,
|
||||
return NULL;
|
||||
|
||||
JSObject *global = js::GetGlobalForObjectCrossCompartment(parent);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (global != scope) {
|
||||
if (!ac.enter(cx, global))
|
||||
return NULL;
|
||||
}
|
||||
JSAutoCompartment ac(cx, global);
|
||||
|
||||
JSObject *proto = getPrototype(cx, global, triedToWrap);
|
||||
if (!proto && !*triedToWrap)
|
||||
@ -831,11 +826,10 @@ template<class LC>
|
||||
bool
|
||||
ListBase<LC>::hasPropertyOnPrototype(JSContext *cx, JSObject *proxy, jsid id)
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
Maybe<JSAutoCompartment> ac;
|
||||
if (xpc::WrapperFactory::IsXrayWrapper(proxy)) {
|
||||
proxy = js::UnwrapObject(proxy);
|
||||
if (!ac.enter(cx, proxy))
|
||||
return false;
|
||||
ac.construct(cx, proxy);
|
||||
}
|
||||
JS_ASSERT(objIsList(proxy));
|
||||
|
||||
|
@ -986,9 +986,7 @@ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj)
|
||||
if (!ccx.IsValid())
|
||||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(ccx, aGlobalJSObj))
|
||||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
JSAutoCompartment ac(ccx, aGlobalJSObj);
|
||||
|
||||
XPCWrappedNativeScope* scope =
|
||||
XPCWrappedNativeScope::GetNewOrUsed(ccx, aGlobalJSObj);
|
||||
@ -1176,9 +1174,7 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
|
||||
// Grab a copy of the global and enter its compartment.
|
||||
JSObject *global = wrappedGlobal->GetFlatJSObject();
|
||||
MOZ_ASSERT(!js::GetObjectParent(global));
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(ccx, global))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
JSAutoCompartment ac(ccx, global);
|
||||
|
||||
if (!(aFlags & nsIXPConnect::OMIT_COMPONENTS_OBJECT)) {
|
||||
// XPCCallContext gives us an active request needed to save/restore.
|
||||
@ -1223,10 +1219,7 @@ NativeInterface2JSObject(XPCLazyCallContext & lccx,
|
||||
jsval *aVal,
|
||||
nsIXPConnectJSObjectHolder **aHolder)
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(lccx.GetJSContext(), aScope))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
JSAutoCompartment ac(lccx.GetJSContext(), aScope);
|
||||
lccx.SetScopeForNewJSObjects(aScope);
|
||||
|
||||
nsresult rv;
|
||||
@ -1308,11 +1301,10 @@ nsXPConnect::WrapJS(JSContext * aJSContext,
|
||||
if (!ccx.IsValid())
|
||||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
|
||||
JSAutoEnterCompartment aec;
|
||||
JSAutoCompartment ac(ccx, aJSObj);
|
||||
|
||||
nsresult rv = NS_ERROR_UNEXPECTED;
|
||||
if (!aec.enter(ccx, aJSObj) ||
|
||||
!XPCConvert::JSObject2NativeInterface(ccx, result, aJSObj,
|
||||
if (!XPCConvert::JSObject2NativeInterface(ccx, result, aJSObj,
|
||||
&aIID, nullptr, &rv))
|
||||
return rv;
|
||||
return NS_OK;
|
||||
@ -1948,9 +1940,7 @@ nsXPConnect::GetWrappedNativePrototype(JSContext * aJSContext,
|
||||
if (!ccx.IsValid())
|
||||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(aJSContext, aScope))
|
||||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
JSAutoCompartment ac(aJSContext, aScope);
|
||||
|
||||
XPCWrappedNativeScope* scope =
|
||||
XPCWrappedNativeScope::FindInJSObjectScope(ccx, aScope);
|
||||
|
@ -3872,6 +3872,7 @@ public:
|
||||
*/
|
||||
|
||||
bool StartEvaluating(JSObject *scope, JSErrorReporter errorReporter = nullptr);
|
||||
|
||||
/**
|
||||
* Does the post script evaluation and resets the error reporter
|
||||
*/
|
||||
@ -3882,7 +3883,7 @@ private:
|
||||
bool mErrorReporterSet;
|
||||
bool mEvaluated;
|
||||
intptr_t mContextHasThread;
|
||||
JSAutoEnterCompartment mEnterCompartment;
|
||||
mozilla::Maybe<JSAutoCompartment> mAutoCompartment;
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
|
||||
// No copying or assignment allowed
|
||||
|
@ -386,9 +386,7 @@ PermitIfUniversalXPConnect(JSContext *cx, jsid id, Wrapper::Action act,
|
||||
static bool
|
||||
IsInSandbox(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
JSObject *global = JS_GetGlobalForObject(cx, obj);
|
||||
return !strcmp(js::GetObjectJSClass(global)->name, "Sandbox");
|
||||
}
|
||||
@ -414,10 +412,7 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper:
|
||||
// but we need to be in the wrapper's compartment to check UniversalXPConnect.
|
||||
//
|
||||
// Unfortunately, |cx| can be in either compartment when we call ::check. :-(
|
||||
JSAutoEnterCompartment ac;
|
||||
JSAutoEnterCompartment wrapperAC;
|
||||
if (!ac.enter(cx, wrappedObject))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, wrappedObject);
|
||||
|
||||
JSBool found = false;
|
||||
if (!JS_HasPropertyById(cx, wrappedObject, exposedPropsId, &found))
|
||||
@ -434,9 +429,7 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper:
|
||||
// If no __exposedProps__ existed, deny access.
|
||||
if (!found) {
|
||||
// Everything below here needs to be done in the wrapper's compartment.
|
||||
if (!wrapperAC.enter(cx, wrapper))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment wrapperAC(cx, wrapper);
|
||||
// Make a temporary exception for objects in a chrome sandbox to help
|
||||
// out jetpack. See bug 784233.
|
||||
if (!JS_ObjectIsFunction(cx, wrappedObject) &&
|
||||
@ -471,8 +464,8 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper:
|
||||
return false;
|
||||
|
||||
if (exposedProps.isNullOrUndefined()) {
|
||||
return wrapperAC.enter(cx, wrapper) &&
|
||||
PermitIfUniversalXPConnect(cx, id, act, perm); // Deny
|
||||
JSAutoCompartment wrapperAC(cx, wrapper);
|
||||
return PermitIfUniversalXPConnect(cx, id, act, perm); // Deny
|
||||
}
|
||||
|
||||
if (!exposedProps.isObject()) {
|
||||
@ -489,8 +482,8 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper:
|
||||
return false; // Error
|
||||
}
|
||||
if (desc.obj == NULL || !(desc.attrs & JSPROP_ENUMERATE)) {
|
||||
return wrapperAC.enter(cx, wrapper) &&
|
||||
PermitIfUniversalXPConnect(cx, id, act, perm); // Deny
|
||||
JSAutoCompartment wrapperAC(cx, wrapper);
|
||||
return PermitIfUniversalXPConnect(cx, id, act, perm); // Deny
|
||||
}
|
||||
|
||||
if (!JSVAL_IS_STRING(desc.value)) {
|
||||
@ -535,8 +528,8 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper:
|
||||
|
||||
if ((act == Wrapper::SET && !(access & WRITE)) ||
|
||||
(act != Wrapper::SET && !(access & READ))) {
|
||||
return wrapperAC.enter(cx, wrapper) &&
|
||||
PermitIfUniversalXPConnect(cx, id, act, perm); // Deny
|
||||
JSAutoCompartment wrapperAC(cx, wrapper);
|
||||
return PermitIfUniversalXPConnect(cx, id, act, perm); // Deny
|
||||
}
|
||||
|
||||
perm = PermitPropertyAccess;
|
||||
@ -548,9 +541,7 @@ ComponentsObjectPolicy::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper
|
||||
Permission &perm)
|
||||
{
|
||||
perm = DenyAccess;
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, wrapper))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, wrapper);
|
||||
|
||||
if (JSID_IS_STRING(id) && act == Wrapper::GET) {
|
||||
JSFlatString *flatId = JSID_TO_FLAT_STRING(id);
|
||||
|
@ -61,9 +61,7 @@ struct OnlyIfSubjectIsSystem : public Policy {
|
||||
return true;
|
||||
}
|
||||
perm = DenyAccess;
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, wrapper))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, wrapper);
|
||||
AccessCheck::deny(cx, id);
|
||||
return false;
|
||||
}
|
||||
@ -82,9 +80,7 @@ struct CrossOriginAccessiblePropertiesOnly : public Policy {
|
||||
return true;
|
||||
}
|
||||
perm = DenyAccess;
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, wrapper))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, wrapper);
|
||||
AccessCheck::deny(cx, id);
|
||||
return false;
|
||||
}
|
||||
@ -130,9 +126,7 @@ struct LocationPolicy : public Policy {
|
||||
return true;
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, wrapper))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, wrapper);
|
||||
AccessCheck::deny(cx, id);
|
||||
return false;
|
||||
}
|
||||
|
@ -34,9 +34,8 @@ ChromeObjectWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper,
|
||||
return true;
|
||||
|
||||
// If not, try doing the lookup on the prototype.
|
||||
JSAutoEnterCompartment ac;
|
||||
return ac.enter(cx, wrapper) &&
|
||||
JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, desc);
|
||||
JSAutoCompartment ac(cx, wrapper);
|
||||
return JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, desc);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -52,13 +51,10 @@ ChromeObjectWrapper::has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
||||
return true;
|
||||
|
||||
// Try the prototype if that failed.
|
||||
JSAutoEnterCompartment ac;
|
||||
JSAutoCompartment ac(cx, wrapper);
|
||||
JSPropertyDescriptor desc;
|
||||
if (!ac.enter(cx, wrapper) ||
|
||||
!JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, &desc))
|
||||
{
|
||||
if (!JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, &desc))
|
||||
return false;
|
||||
}
|
||||
*bp = !!desc.obj;
|
||||
return true;
|
||||
}
|
||||
@ -77,9 +73,7 @@ ChromeObjectWrapper::get(JSContext *cx, JSObject *wrapper, JSObject *receiver,
|
||||
return true;
|
||||
|
||||
// Try the prototype.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, wrapper))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, wrapper);
|
||||
return js::GetGeneric(cx, wrapperProto, receiver, id, vp);
|
||||
}
|
||||
|
||||
|
@ -82,8 +82,8 @@ WrapperFactory::CreateXrayWaiver(JSContext *cx, JSObject *obj)
|
||||
return nullptr;
|
||||
|
||||
// Create the waiver.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj) || !JS_WrapObject(cx, &proto))
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
if (!JS_WrapObject(cx, &proto))
|
||||
return nullptr;
|
||||
JSObject *waiver = Wrapper::New(cx, obj, proto,
|
||||
JS_GetGlobalForObject(cx, obj),
|
||||
@ -126,10 +126,7 @@ JSObject *
|
||||
WrapperFactory::DoubleWrap(JSContext *cx, JSObject *obj, unsigned flags)
|
||||
{
|
||||
if (flags & WrapperFactory::WAIVE_XRAY_WRAPPER_FLAG) {
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return nullptr;
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
return WaiveXray(cx, obj);
|
||||
}
|
||||
return obj;
|
||||
@ -169,9 +166,7 @@ WrapperFactory::PrepareForWrapping(JSContext *cx, JSObject *scope, JSObject *obj
|
||||
|
||||
XPCWrappedNative *wn = static_cast<XPCWrappedNative *>(xpc_GetJSPrivate(obj));
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return nullptr;
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
XPCCallContext ccx(JS_CALLER, cx, obj);
|
||||
|
||||
{
|
||||
@ -398,9 +393,7 @@ WrapperFactory::Rewrap(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSO
|
||||
JSObject *unwrappedProto = NULL;
|
||||
if (wrappedProto && IsCrossCompartmentWrapper(wrappedProto) &&
|
||||
(unwrappedProto = Wrapper::wrappedObject(wrappedProto))) {
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, unwrappedProto))
|
||||
return NULL;
|
||||
JSAutoCompartment ac(cx, unwrappedProto);
|
||||
key = JS_IdentifyClassPrototype(cx, unwrappedProto);
|
||||
}
|
||||
if (key != JSProto_Null) {
|
||||
|
@ -132,12 +132,9 @@ LookupExpandoObject(JSContext *cx, JSObject *target, nsIPrincipal *origin,
|
||||
{
|
||||
// The expando object lives in the compartment of the target, so all our
|
||||
// work needs to happen there.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, target) ||
|
||||
!JS_WrapObject(cx, &exclusiveGlobal))
|
||||
{
|
||||
JSAutoCompartment ac(cx, target);
|
||||
if (!JS_WrapObject(cx, &exclusiveGlobal))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Iterate through the chain, looking for a same-origin object.
|
||||
JSObject *head = GetExpandoChain(target);
|
||||
@ -213,10 +210,7 @@ JSObject *
|
||||
EnsureExpandoObject(JSContext *cx, JSObject *wrapper, JSObject *target)
|
||||
{
|
||||
// Expando objects live in the target compartment.
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, target))
|
||||
return nullptr;
|
||||
|
||||
JSAutoCompartment ac(cx, target);
|
||||
JSObject *expandoObject = LookupExpandoObject(cx, target, wrapper);
|
||||
if (!expandoObject) {
|
||||
// If the object is a sandbox, we don't want it to share expandos with
|
||||
@ -516,9 +510,7 @@ holder_get(JSContext *cx, JSHandleObject wrapper_, JSHandleId id, JSMutableHandl
|
||||
|
||||
XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
|
||||
if (NATIVE_HAS_FLAG(wn, WantGetProperty)) {
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, holder))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, holder);
|
||||
bool retval = true;
|
||||
nsresult rv = wn->GetScriptableCallback()->GetProperty(wn, cx, wrapper,
|
||||
id, vp.address(), &retval);
|
||||
@ -543,9 +535,7 @@ holder_set(JSContext *cx, JSHandleObject wrapper_, JSHandleId id, JSBool strict,
|
||||
|
||||
XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
|
||||
if (NATIVE_HAS_FLAG(wn, WantSetProperty)) {
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, holder))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, holder);
|
||||
bool retval = true;
|
||||
nsresult rv = wn->GetScriptableCallback()->SetProperty(wn, cx, wrapper,
|
||||
id, vp.address(), &retval);
|
||||
@ -821,12 +811,9 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, js::Wrapper &jsWra
|
||||
// Check for expando properties first. Note that the expando object lives
|
||||
// in the target compartment.
|
||||
if (expando) {
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, expando) ||
|
||||
!JS_GetPropertyDescriptorById(cx, expando, id, flags, desc))
|
||||
{
|
||||
JSAutoCompartment ac(cx, expando);
|
||||
if (!JS_GetPropertyDescriptorById(cx, expando, id, flags, desc))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (desc->obj) {
|
||||
if (!JS_WrapPropertyDescriptor(cx, desc))
|
||||
@ -891,9 +878,7 @@ XPCWrappedNativeXrayTraits::defineProperty(JSContext *cx, JSObject *wrapper, jsi
|
||||
// We're placing an expando. The expando objects live in the target
|
||||
// compartment, so we need to enter it.
|
||||
JSObject *target = GetWrappedNativeObjectFromHolder(holder);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, target))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, target);
|
||||
|
||||
// Grab the relevant expando object.
|
||||
JSObject *expandoObject = EnsureExpandoObject(cx, wrapper, target);
|
||||
@ -916,15 +901,15 @@ XPCWrappedNativeXrayTraits::delete_(JSContext *cx, JSObject *wrapper, jsid id, b
|
||||
JSObject *holder = getHolderObject(wrapper);
|
||||
JSObject *target = GetWrappedNativeObjectFromHolder(holder);
|
||||
JSObject *expando = LookupExpandoObject(cx, target, wrapper);
|
||||
JSAutoEnterCompartment ac;
|
||||
JSBool b = true;
|
||||
jsval v;
|
||||
if (expando &&
|
||||
(!ac.enter(cx, expando) ||
|
||||
!JS_DeletePropertyById2(cx, expando, id, &v) ||
|
||||
!JS_ValueToBoolean(cx, v, &b)))
|
||||
{
|
||||
return false;
|
||||
if (expando) {
|
||||
JSAutoCompartment ac(cx, expando);
|
||||
jsval v;
|
||||
if (!JS_DeletePropertyById2(cx, expando, id, &v) ||
|
||||
!JS_ValueToBoolean(cx, v, &b))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
*bp = !!b;
|
||||
@ -942,12 +927,9 @@ XPCWrappedNativeXrayTraits::enumerateNames(JSContext *cx, JSObject *wrapper, uns
|
||||
JSObject *target = GetWrappedNativeObjectFromHolder(holder);
|
||||
JSObject *expando = LookupExpandoObject(cx, target, wrapper);
|
||||
if (expando) {
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, expando) ||
|
||||
!js::GetPropertyNames(cx, expando, flags, &props))
|
||||
{
|
||||
JSAutoCompartment ac(cx, expando);
|
||||
if (!js::GetPropertyNames(cx, expando, flags, &props))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!JS_WrapAutoIdVector(cx, props))
|
||||
return false;
|
||||
@ -957,9 +939,7 @@ XPCWrappedNativeXrayTraits::enumerateNames(JSContext *cx, JSObject *wrapper, uns
|
||||
{
|
||||
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, wnObject))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, wnObject);
|
||||
if (!js::GetPropertyNames(cx, wnObject, flags, &wnProps))
|
||||
return false;
|
||||
}
|
||||
@ -1246,10 +1226,7 @@ XrayWrapper<Base, Traits>::getPropertyDescriptor(JSContext *cx, JSObject *wrappe
|
||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
||||
JSObject *obj = Traits::getInnerObject(wrapper);
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
if (!JS_GetPropertyDescriptorById(cx, obj, id,
|
||||
(set ? JSRESOLVE_ASSIGNING : 0) | JSRESOLVE_QUALIFIED,
|
||||
desc)) {
|
||||
@ -1350,10 +1327,7 @@ XrayWrapper<Base, Traits>::getOwnPropertyDescriptor(JSContext *cx, JSObject *wra
|
||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
||||
JSObject *obj = Traits::getInnerObject(wrapper);
|
||||
{
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
if (!JS_GetPropertyDescriptorById(cx, obj, id,
|
||||
(set ? JSRESOLVE_ASSIGNING : 0) | JSRESOLVE_QUALIFIED,
|
||||
desc)) {
|
||||
@ -1403,10 +1377,7 @@ XrayWrapper<Base, Traits>::defineProperty(JSContext *cx, JSObject *wrapper, jsid
|
||||
// Redirect access straight to the wrapper if we should be transparent.
|
||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
||||
JSObject *obj = Traits::getInnerObject(wrapper);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
if (!JS_WrapPropertyDescriptor(cx, desc))
|
||||
return false;
|
||||
|
||||
@ -1440,9 +1411,7 @@ XrayWrapper<Base, Traits>::delete_(JSContext *cx, JSObject *wrapper, jsid id, bo
|
||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
||||
JSObject *obj = Traits::getInnerObject(wrapper);
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
|
||||
JSBool b;
|
||||
jsval v;
|
||||
@ -1463,10 +1432,7 @@ XrayWrapper<Base, Traits>::enumerate(JSContext *cx, JSObject *wrapper, unsigned
|
||||
// Redirect access straight to the wrapper if we should be transparent.
|
||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
||||
JSObject *obj = Traits::getInnerObject(wrapper);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj))
|
||||
return false;
|
||||
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
return js::GetPropertyNames(cx, obj, flags, &props);
|
||||
}
|
||||
|
||||
|
@ -2208,11 +2208,7 @@ nsCryptoRunnable::Run()
|
||||
JSContext *cx = m_args->m_cx;
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (!ac.enter(cx, m_args->m_scope)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSAutoCompartment ac(cx, m_args->m_scope);
|
||||
|
||||
// make sure the right context is on the stack. must not return w/out popping
|
||||
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
|
||||
|
@ -51,10 +51,7 @@ GetWindowOfObserver(nsIObserver* aObserver)
|
||||
NS_ENSURE_TRUE(cx, nullptr);
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
JSAutoEnterCompartment ac;
|
||||
if (!ac.enter(cx, obj)) {
|
||||
return nullptr;
|
||||
}
|
||||
JSAutoEnterCompartment ac(cx, obj);
|
||||
|
||||
JSObject* global = JS_GetGlobalForObject(cx, obj);
|
||||
NS_ENSURE_TRUE(global, nullptr);
|
||||
|
@ -525,14 +525,10 @@ public:
|
||||
// being thread safe. Bug 750989.
|
||||
t->SetPaused(true);
|
||||
if (stream.is_open()) {
|
||||
JSAutoEnterCompartment autoComp;
|
||||
if (autoComp.enter(cx, obj)) {
|
||||
JSObject* profileObj = mozilla_sampler_get_profile_data(cx);
|
||||
jsval val = OBJECT_TO_JSVAL(profileObj);
|
||||
JS_Stringify(cx, &val, nullptr, JSVAL_NULL, WriteCallback, &stream);
|
||||
} else {
|
||||
LOG("Failed to enter compartment");
|
||||
}
|
||||
JSAutoCompartment autoComp(cx, obj);
|
||||
JSObject* profileObj = mozilla_sampler_get_profile_data(cx);
|
||||
jsval val = OBJECT_TO_JSVAL(profileObj);
|
||||
JS_Stringify(cx, &val, nullptr, JSVAL_NULL, WriteCallback, &stream);
|
||||
stream.close();
|
||||
LOGF("Saved to %s", tmpPath.get());
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user