Fix ancient duplicated Install object global and "sub-global" prob exposed by recent JS engine assertion (336695, r/sr=dveditz).

This commit is contained in:
brendan%mozilla.org 2006-05-31 03:10:31 +00:00
parent ba7825ee28
commit 27e1a01c1c
2 changed files with 24 additions and 30 deletions

View File

@ -1929,7 +1929,6 @@ static JSFunctionSpec InstallMethods[] =
JSObject * InitXPInstallObjects(JSContext *jscontext,
JSObject *global,
nsIFile* jarfile,
const PRUnichar* url,
const PRUnichar* args,
@ -1937,33 +1936,25 @@ JSObject * InitXPInstallObjects(JSContext *jscontext,
CHROMEREG_IFACE* reg,
nsIZipReader * theJARFile)
{
JSObject *installObject = nsnull;
JSObject *installObject;
nsInstall *nativeInstallObject;
if (global == nsnull)
{
//we are the global
// new global object
global = JS_NewObject(jscontext, &InstallClass, nsnull, nsnull);
}
installObject = JS_InitClass( jscontext, // context
global, // global object
nsnull, // parent proto
&InstallClass, // JSClass
nsnull, // JSNative ctor
0, // ctor args
nsnull, // proto props
nsnull, // proto funcs
InstallProperties, // ctor props (static)
InstallMethods); // ctor funcs (static)
if (nsnull == installObject)
{
// new global object
installObject = JS_NewObject(jscontext, &InstallClass, nsnull, nsnull);
if (!installObject)
return nsnull;
}
if ( PR_FALSE == JS_DefineConstDoubles(jscontext, installObject, install_constants) )
if (!JS_DefineProperty(jscontext, installObject, InstallClass.name,
OBJECT_TO_JSVAL(installObject), NULL, NULL, 0))
return nsnull;
if (!JS_DefineProperties(jscontext, installObject, InstallProperties))
return nsnull;
if (!JS_DefineFunctions(jscontext, installObject, InstallMethods))
return nsnull;
if (!JS_DefineConstDoubles(jscontext, installObject, install_constants))
return nsnull;
nativeInstallObject = new nsInstall(theJARFile);
@ -1983,7 +1974,7 @@ JSObject * InitXPInstallObjects(JSContext *jscontext,
//
// Initialize and create the FileOp object
//
if(NS_OK != InitXPFileOpObjectPrototype(jscontext, global, &gFileOpProto))
if(NS_OK != InitXPFileOpObjectPrototype(jscontext, installObject, &gFileOpProto))
{
return nsnull;
}
@ -1995,7 +1986,7 @@ JSObject * InitXPInstallObjects(JSContext *jscontext,
JS_SetPrivate(jscontext, gFileOpObject, nativeInstallObject);
if (!JS_DefineProperty (jscontext,
installObject,
installObject,
"File",
OBJECT_TO_JSVAL(gFileOpObject),
JS_PropertyStub,
@ -2019,13 +2010,13 @@ JSObject * InitXPInstallObjects(JSContext *jscontext,
JSObject *winRegPrototype = nsnull;
JSObject *winProfilePrototype = nsnull;
if(NS_OK != InitWinRegPrototype(jscontext, global, &winRegPrototype))
if(NS_OK != InitWinRegPrototype(jscontext, installObject, &winRegPrototype))
{
return nsnull;
}
nativeInstallObject->SaveWinRegPrototype(winRegPrototype);
if(NS_OK != InitWinProfilePrototype(jscontext, global, &winProfilePrototype))
if(NS_OK != InitWinProfilePrototype(jscontext, installObject, &winProfilePrototype))
{
return nsnull;
}

View File

@ -77,7 +77,7 @@
static NS_DEFINE_CID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID);
extern JSObject *InitXPInstallObjects(JSContext *jscontext, JSObject *global,
extern JSObject *InitXPInstallObjects(JSContext *jscontext,
nsIFile* jarfile, const PRUnichar* url,
const PRUnichar* args, PRUint32 flags,
CHROMEREG_IFACE* registry,
@ -399,9 +399,12 @@ static nsresult SetupInstallContext(nsIZipReader* hZip,
JS_SetErrorReporter(cx, XPInstallErrorReporter);
JS_BeginRequest(cx);
glob = InitXPInstallObjects(cx, nsnull, jarFile, url, args, flags, reg, hZip);
glob = InitXPInstallObjects(cx, jarFile, url, args, flags, reg, hZip);
if (!glob)
{
JS_DestroyContext(cx);
return NS_ERROR_OUT_OF_MEMORY;
}
// Init standard classes
JS_InitStandardClasses(cx, glob);