backing out jst's fix for bug 408301 because it seems to have turned some tinderboxen red, others orange, and caused web content regressions

This commit is contained in:
myk@mozilla.org 2008-01-11 17:56:21 -08:00
Родитель 8eb96a90ea
Коммит 3db3cf881d
4 изменённых файлов: 31 добавлений и 118 удалений

Просмотреть файл

@ -1151,7 +1151,6 @@ extern JSClass XPC_WN_NoMods_NoCall_Proto_JSClass;
extern JSClass XPC_WN_ModsAllowed_WithCall_Proto_JSClass; extern JSClass XPC_WN_ModsAllowed_WithCall_Proto_JSClass;
extern JSClass XPC_WN_ModsAllowed_NoCall_Proto_JSClass; extern JSClass XPC_WN_ModsAllowed_NoCall_Proto_JSClass;
extern JSClass XPC_WN_Tearoff_JSClass; extern JSClass XPC_WN_Tearoff_JSClass;
extern JSClass XPC_WN_NoHelper_Proto_JSClass;
extern JSObjectOps * JS_DLL_CALLBACK extern JSObjectOps * JS_DLL_CALLBACK
XPC_WN_GetObjectOpsNoCall(JSContext *cx, JSClass *clazz); XPC_WN_GetObjectOpsNoCall(JSContext *cx, JSClass *clazz);
@ -1159,9 +1158,6 @@ XPC_WN_GetObjectOpsNoCall(JSContext *cx, JSClass *clazz);
extern JSObjectOps * JS_DLL_CALLBACK extern JSObjectOps * JS_DLL_CALLBACK
XPC_WN_GetObjectOpsWithCall(JSContext *cx, JSClass *clazz); XPC_WN_GetObjectOpsWithCall(JSContext *cx, JSClass *clazz);
extern JSObjectOps * JS_DLL_CALLBACK
XPC_WN_Proto_GetObjectOps(JSContext *cx, JSClass *clazz);
extern JSBool JS_DLL_CALLBACK extern JSBool JS_DLL_CALLBACK
XPC_WN_CallMethod(JSContext *cx, JSObject *obj, XPC_WN_CallMethod(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *vp); uintN argc, jsval *argv, jsval *vp);
@ -1219,11 +1215,6 @@ public:
JSObject* JSObject*
GetPrototypeJSObject() const {return mPrototypeJSObject;} GetPrototypeJSObject() const {return mPrototypeJSObject;}
// Getter for the prototype that we use for wrappers that have no
// helper.
JSObject*
GetPrototypeNoHelper(XPCCallContext& ccx);
#ifndef XPCONNECT_STANDALONE #ifndef XPCONNECT_STANDALONE
nsIPrincipal* nsIPrincipal*
GetPrincipal() const GetPrincipal() const
@ -1317,13 +1308,8 @@ private:
// unless a PreCreate hook overrides it. Note that this _may_ be null (see // unless a PreCreate hook overrides it. Note that this _may_ be null (see
// constructor). // constructor).
JSObject* mGlobalJSObject; JSObject* mGlobalJSObject;
// Cached value of Object.prototype
JSObject* mPrototypeJSObject; JSObject* mPrototypeJSObject;
// Cached value of Function.prototype
JSObject* mPrototypeJSFunction; JSObject* mPrototypeJSFunction;
// Prototype to use for wrappers with no helper.
JSObject* mPrototypeNoHelper;
#ifndef XPCONNECT_STANDALONE #ifndef XPCONNECT_STANDALONE
// The script object principal instance corresponding to our current global // The script object principal instance corresponding to our current global

Просмотреть файл

@ -868,11 +868,7 @@ XPCWrappedNative::Init(XPCCallContext& ccx, JSObject* parent, JSBool isGlobal,
JSObject* protoJSObject = HasProto() ? JSObject* protoJSObject = HasProto() ?
GetProto()->GetJSProtoObject() : GetProto()->GetJSProtoObject() :
GetScope()->GetPrototypeNoHelper(ccx); GetScope()->GetPrototypeJSObject();
if (!protoJSObject) {
return JS_FALSE;
}
mFlatJSObject = xpc_NewSystemInheritingJSObject(ccx, jsclazz, protoJSObject, mFlatJSObject = xpc_NewSystemInheritingJSObject(ccx, jsclazz, protoJSObject,
parent); parent);

Просмотреть файл

@ -899,7 +899,7 @@ JSExtendedClass XPC_WN_NoHelper_JSClass = {
XPC_WN_NoHelper_Finalize, // finalize; XPC_WN_NoHelper_Finalize, // finalize;
/* Optionally non-null members start here. */ /* Optionally non-null members start here. */
XPC_WN_GetObjectOpsNoCall, // getObjectOps; nsnull, // getObjectOps;
nsnull, // checkAccess; nsnull, // checkAccess;
nsnull, // call; nsnull, // call;
nsnull, // construct; nsnull, // construct;
@ -1186,11 +1186,9 @@ JS_STATIC_DLL_CALLBACK(JSBool)
XPC_WN_JSOp_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, XPC_WN_JSOp_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
jsval *statep, jsid *idp) jsval *statep, jsid *idp)
{ {
JSClass *clazz = JS_GET_CLASS(cx, obj); if(!IS_WRAPPER_CLASS(JS_GET_CLASS(cx, obj)))
if(!IS_WRAPPER_CLASS(clazz) || clazz == &XPC_WN_NoHelper_JSClass.base)
{ {
// obj must be a prototype object or a wrapper w/o a // obj must be a prototype object. Short circuit this call to
// helper. Short circuit this call to
// js_ObjectOps.enumerate(). // js_ObjectOps.enumerate().
return js_ObjectOps.enumerate(cx, obj, enum_op, statep, idp); return js_ObjectOps.enumerate(cx, obj, enum_op, statep, idp);
@ -1635,8 +1633,7 @@ XPC_WN_Proto_GetObjectOps(JSContext *cx, JSClass *clazz)
return &XPC_WN_WithCall_JSOps; return &XPC_WN_WithCall_JSOps;
NS_ASSERTION(clazz == &XPC_WN_ModsAllowed_NoCall_Proto_JSClass || NS_ASSERTION(clazz == &XPC_WN_ModsAllowed_NoCall_Proto_JSClass ||
clazz == &XPC_WN_NoMods_NoCall_Proto_JSClass || clazz == &XPC_WN_NoMods_NoCall_Proto_JSClass,
clazz == &XPC_WN_NoHelper_Proto_JSClass,
"bad proto"); "bad proto");
return &XPC_WN_NoCall_JSOps; return &XPC_WN_NoCall_JSOps;

Просмотреть файл

@ -119,12 +119,11 @@ XPCWrappedNativeScope::GetNewOrUsed(XPCCallContext& ccx, JSObject* aGlobal)
scope = new XPCWrappedNativeScope(ccx, aGlobal); scope = new XPCWrappedNativeScope(ccx, aGlobal);
else else
{ {
// We need to call SetGlobal in order to refresh our cached // We need to call SetGlobal in order to refresh our cached
// mPrototypeJSObject and mPrototypeJSFunction and to clear // mPrototypeJSObject and mPrototypeJSFunction in the case where
// mPrototypeNoHelper (so we get a new one if requested in the // the global object is being reused (JS_ClearScope has been
// new scope) in the case where the global object is being // called).
// reused (JS_ClearScope has been called). NOTE: We are only // NOTE: We are only called by nsXPConnect::InitClasses.
// called by nsXPConnect::InitClasses.
scope->SetGlobal(ccx, aGlobal); scope->SetGlobal(ccx, aGlobal);
} }
return scope; return scope;
@ -140,8 +139,7 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(XPCCallContext& ccx,
mNext(nsnull), mNext(nsnull),
mGlobalJSObject(nsnull), mGlobalJSObject(nsnull),
mPrototypeJSObject(nsnull), mPrototypeJSObject(nsnull),
mPrototypeJSFunction(nsnull), mPrototypeJSFunction(nsnull)
mPrototypeNoHelper(nsnull)
{ {
// add ourselves to the scopes list // add ourselves to the scopes list
{ // scoped lock { // scoped lock
@ -183,41 +181,6 @@ XPCWrappedNativeScope::SetComponents(nsXPCComponents* aComponents)
mComponents = aComponents; mComponents = aComponents;
} }
// Dummy JS class to let wrappers w/o an xpc prototype share
// scopes. By doing this we avoid allocating a new scope for every
// wrapper on creation of the wrapper, and most wrappers won't need
// their own scope at all for the lifetime of the wrapper.
// JSCLASS_HAS_PRIVATE is key here (even though there's never anything
// in the private data slot in these prototypes), as the number of
// reserved slots in this class needs to match that of the wrappers
// for the JS engine to share scopes.
JSClass XPC_WN_NoHelper_Proto_JSClass = {
"XPC_WN_NoHelper_Proto_JSClass",// name;
JSCLASS_HAS_PRIVATE, // flags;
/* Mandatory non-null function pointer members. */
JS_PropertyStub, // addProperty;
JS_PropertyStub, // delProperty;
JS_PropertyStub, // getProperty;
JS_PropertyStub, // setProperty;
JS_EnumerateStub, // enumerate;
JS_ResolveStub, // resolve;
JS_ConvertStub, // convert;
JS_FinalizeStub, // finalize;
/* Optionally non-null members start here. */
XPC_WN_Proto_GetObjectOps, // getObjectOps;
nsnull, // checkAccess;
nsnull, // call;
nsnull, // construct;
nsnull, // xdrObject;
nsnull, // hasInstance;
nsnull, // mark/trace;
nsnull // spare;
};
void void
XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal) XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal)
{ {
@ -228,24 +191,25 @@ XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal)
#ifndef XPCONNECT_STANDALONE #ifndef XPCONNECT_STANDALONE
mScriptObjectPrincipal = nsnull; mScriptObjectPrincipal = nsnull;
// Now init our script object principal, if the new global has one // Now init our script object principal, if the new global has one
if (aGlobal)
JSContext* cx = ccx.GetJSContext();
const JSClass* jsClass = JS_GetClass(cx, aGlobal);
if(!(~jsClass->flags & (JSCLASS_HAS_PRIVATE |
JSCLASS_PRIVATE_IS_NSISUPPORTS)))
{ {
// Our global has an nsISupports native pointer. Let's JSContext* cx = ccx.GetJSContext();
// see whether it's what we want. const JSClass* jsClass = JS_GetClass(cx, aGlobal);
nsISupports* priv = (nsISupports*)JS_GetPrivate(cx, aGlobal); if (jsClass && !(~jsClass->flags & (JSCLASS_HAS_PRIVATE |
nsCOMPtr<nsIXPConnectWrappedNative> native = JSCLASS_PRIVATE_IS_NSISUPPORTS)))
do_QueryInterface(priv);
if(native)
{ {
mScriptObjectPrincipal = do_QueryWrappedNative(native); // Our global has an nsISupports native pointer. Let's
} // see whether it's what we want.
if(!mScriptObjectPrincipal) nsISupports* priv = (nsISupports*)JS_GetPrivate(cx, aGlobal);
{ nsCOMPtr<nsIXPConnectWrappedNative> native =
mScriptObjectPrincipal = do_QueryInterface(priv); do_QueryInterface(priv);
if (native)
{
mScriptObjectPrincipal = do_QueryWrappedNative(native);
}
if (!mScriptObjectPrincipal) {
mScriptObjectPrincipal = do_QueryInterface(priv);
}
} }
} }
#endif #endif
@ -283,10 +247,6 @@ XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal)
NS_ERROR("Can't get globalObject.Function.prototype"); NS_ERROR("Can't get globalObject.Function.prototype");
} }
} }
// Clear the no helper wrapper prototype object so that a new one
// gets created if needed.
mPrototypeNoHelper = nsnull;
} }
XPCWrappedNativeScope::~XPCWrappedNativeScope() XPCWrappedNativeScope::~XPCWrappedNativeScope()
@ -319,25 +279,6 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope()
NS_IF_RELEASE(mComponents); NS_IF_RELEASE(mComponents);
} }
JSObject *
XPCWrappedNativeScope::GetPrototypeNoHelper(XPCCallContext& ccx)
{
// We could create this prototype in SetGlobal(), but all scopes
// don't need one, so we save ourselves a bit of space if we
// create these when they're needed.
if(!mPrototypeNoHelper)
{
mPrototypeNoHelper =
xpc_NewSystemInheritingJSObject(ccx, &XPC_WN_NoHelper_Proto_JSClass,
mPrototypeJSObject,
mGlobalJSObject);
NS_ASSERTION(mPrototypeNoHelper,
"Failed to create prototype for wrappers w/o a helper");
}
return mPrototypeNoHelper;
}
JS_STATIC_DLL_CALLBACK(JSDHashOperator) JS_STATIC_DLL_CALLBACK(JSDHashOperator)
WrappedNativeJSGCThingTracer(JSDHashTable *table, JSDHashEntryHdr *hdr, WrappedNativeJSGCThingTracer(JSDHashTable *table, JSDHashEntryHdr *hdr,
@ -466,11 +407,6 @@ XPCWrappedNativeScope::FinishedMarkPhaseOfGC(JSContext* cx, XPCJSRuntime* rt)
{ {
cur->mPrototypeJSFunction = nsnull; cur->mPrototypeJSFunction = nsnull;
} }
if(cur->mPrototypeNoHelper &&
JS_IsAboutToBeFinalized(cx, cur->mPrototypeNoHelper))
{
cur->mPrototypeNoHelper = nsnull;
}
} }
if(cur) if(cur)
prev = cur; prev = cur;
@ -701,12 +637,11 @@ GetScopeOfObject(JSContext* cx, JSObject* obj)
{ {
#ifdef DEBUG #ifdef DEBUG
{ {
if(!(~clazz->flags & (JSCLASS_HAS_PRIVATE | if(clazz->flags & JSCLASS_HAS_PRIVATE &&
JSCLASS_PRIVATE_IS_NSISUPPORTS)) && clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS)
(supports = (nsISupports*) JS_GetPrivate(cx, obj)))
{ {
nsCOMPtr<nsIXPConnectWrappedNative> iface = nsCOMPtr<nsIXPConnectWrappedNative> iface =
do_QueryInterface(supports); do_QueryInterface((nsISupports*) JS_GetPrivate(cx, obj));
NS_ASSERTION(!iface, "Uh, how'd this happen?"); NS_ASSERTION(!iface, "Uh, how'd this happen?");
} }
@ -926,7 +861,6 @@ XPCWrappedNativeScope::DebugDump(PRInt16 depth)
XPC_LOG_ALWAYS(("mGlobalJSObject @ %x", mGlobalJSObject)); XPC_LOG_ALWAYS(("mGlobalJSObject @ %x", mGlobalJSObject));
XPC_LOG_ALWAYS(("mPrototypeJSObject @ %x", mPrototypeJSObject)); XPC_LOG_ALWAYS(("mPrototypeJSObject @ %x", mPrototypeJSObject));
XPC_LOG_ALWAYS(("mPrototypeJSFunction @ %x", mPrototypeJSFunction)); XPC_LOG_ALWAYS(("mPrototypeJSFunction @ %x", mPrototypeJSFunction));
XPC_LOG_ALWAYS(("mPrototypeNoHelper @ %x", mPrototypeNoHelper));
XPC_LOG_ALWAYS(("mWrappedNativeMap @ %x with %d wrappers(s)", \ XPC_LOG_ALWAYS(("mWrappedNativeMap @ %x with %d wrappers(s)", \
mWrappedNativeMap, \ mWrappedNativeMap, \