From 06d4a1efb72e0d0470521a55eec26bca07f4fae8 Mon Sep 17 00:00:00 2001 From: "rginda%netscape.com" Date: Wed, 16 Feb 2000 06:26:21 +0000 Subject: [PATCH] Fix for 26725, r=jband --- .../xpconnect/loader/mozJSComponentLoader.cpp | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/js/src/xpconnect/loader/mozJSComponentLoader.cpp index b46dc171c34..454b3366dd3 100644 --- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp @@ -33,6 +33,8 @@ #include "nsIAllocator.h" #include "nsIRegistry.h" #include "nsXPIDLString.h" +#include "nsIScriptSecurityManager.h" + const char mozJSComponentLoaderProgID[] = "moz.jsloader.1"; const char jsComponentTypeName[] = "text/javascript"; /* XXX export properly from libxpcom, for now this will let Mac build */ @@ -636,6 +638,21 @@ mozJSComponentLoader::GlobalForLocation(const char *aLocation, NS_FAILED(ReallyInit())) return nsnull; + nsresult rv; + NS_WITH_SERVICE(nsIScriptSecurityManager, secman, NS_SCRIPTSECURITYMANAGER_PROGID, &rv); + if(NS_FAILED(rv) || !secman) + return nsnull; + + nsCOMPtr iPrincipals; + rv = secman->GetSystemPrincipal(getter_AddRefs(iPrincipals)); + if(NS_FAILED(rv) || !iPrincipals) + return nsnull; + + JSPrincipals* jsPrincipals; + rv = iPrincipals->GetJSPrincipals(&jsPrincipals); + if(NS_FAILED(rv) || !jsPrincipals) + return nsnull; + obj = JS_NewObject(mContext, &gGlobalClass, mSuperGlobal, NULL); if (!obj) return nsnull; @@ -647,7 +664,6 @@ mozJSComponentLoader::GlobalForLocation(const char *aLocation, needRelease = PR_TRUE; } - nsresult rv; NS_WITH_SERVICE(nsIJSContextStack, cxstack, kJSContextStackProgID, &rv); if (NS_FAILED(rv) || NS_FAILED(cxstack->Push(mContext))) @@ -669,7 +685,10 @@ mozJSComponentLoader::GlobalForLocation(const char *aLocation, if (NS_FAILED(rv)) return nsnull; - JSScript *script = JS_CompileFileHandle(mContext, obj, (const char *)displayPath, fileHandle); + JSScript *script = + JS_CompileFileHandleForPrincipals(mContext, obj, + (const char *)displayPath, + fileHandle, jsPrincipals); /* JS will close the filehandle after compilation is complete. */