Backout Bug 810987.

This commit is contained in:
Kyle Huey 2012-11-13 10:27:37 -08:00
parent a43ac37b08
commit d77f59d91d
4 changed files with 41 additions and 70 deletions

View File

@ -431,7 +431,6 @@ mozJSComponentLoader::ReallyInit()
mModules.Init(32);
mImports.Init(32);
mInProgressImports.Init(32);
mThisObjects.Init(32);
nsCOMPtr<nsIObserverService> obsSvc =
do_GetService(kObserverServiceContractID, &rv);
@ -579,52 +578,6 @@ mozJSComponentLoader::LoadModule(FileLocation &aFile)
return entry.forget();
}
nsresult
mozJSComponentLoader::FindTargetObject(JSContext* aCx,
JSObject** aTargetObject)
{
JSObject* targetObject = nullptr;
*aTargetObject = nullptr;
if (mReuseLoaderGlobal) {
JSScript* script =
js::GetOutermostEnclosingFunctionOfScriptedCaller(aCx);
if (script) {
targetObject = mThisObjects.Get(script);
}
}
// The above could fail, even if mReuseLoaderGlobal, if the scripted
// caller is not a component/JSM (it could be a DOM scope, for
// instance).
if (!targetObject) {
// Our targetObject is the caller's global object. Let's get it.
nsresult rv;
nsCOMPtr<nsIXPConnect> xpc =
do_GetService(kXPConnectServiceContractID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsAXPCNativeCallContext *cc = nullptr;
rv = xpc->GetCurrentNativeCallContext(&cc);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIXPConnectWrappedNative> wn;
rv = cc->GetCalleeWrapper(getter_AddRefs(wn));
NS_ENSURE_SUCCESS(rv, rv);
wn->GetJSObject(&targetObject);
if (!targetObject) {
NS_ERROR("null calling object");
return NS_ERROR_FAILURE;
}
targetObject = JS_GetGlobalForObject(aCx, targetObject);
}
*aTargetObject = targetObject;
return NS_OK;
}
// Some stack based classes for cleaning up on early return
#ifdef HAVE_PR_MEMMAP
class FileAutoCloser
@ -1024,14 +977,6 @@ mozJSComponentLoader::ObjectForLocation(nsIFile *aComponentFile,
// See bug 384168.
*aObject = obj;
JSScript* tableScript = script;
if (!tableScript) {
tableScript = JS_GetFunctionScript(cx, function);
MOZ_ASSERT(tableScript);
}
mThisObjects.Put(tableScript, obj);
uint32_t oldopts = JS_GetOptions(cx);
JS_SetOptions(cx, oldopts |
(exception ? JSOPTION_DONT_REPORT_UNCAUGHT : 0));
@ -1095,7 +1040,6 @@ mozJSComponentLoader::UnloadModules()
mInProgressImports.Clear();
mImports.Clear();
mThisObjects.Clear();
mModules.Enumerate(ClearModules, NULL);
@ -1145,8 +1089,28 @@ mozJSComponentLoader::Import(const nsACString& registryLocation,
PromiseFlatCString(registryLocation).get());
}
} else {
nsresult rv = FindTargetObject(cx, &targetObject);
// Our targetObject is the caller's global object. Find it by
// walking the calling object's parent chain.
nsresult rv;
nsCOMPtr<nsIXPConnect> xpc =
do_GetService(kXPConnectServiceContractID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsAXPCNativeCallContext *cc = nullptr;
rv = xpc->GetCurrentNativeCallContext(&cc);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIXPConnectWrappedNative> wn;
rv = cc->GetCalleeWrapper(getter_AddRefs(wn));
NS_ENSURE_SUCCESS(rv, rv);
wn->GetJSObject(&targetObject);
if (!targetObject) {
NS_ERROR("null calling object");
return NS_ERROR_FAILURE;
}
targetObject = JS_GetGlobalForObject(cx, targetObject);
}
Maybe<JSAutoCompartment> ac;

View File

@ -50,10 +50,6 @@ class mozJSComponentLoader : public mozilla::ModuleLoader,
// ModuleLoader
const mozilla::Module* LoadModule(mozilla::FileLocation &aFile);
nsresult FindTargetObject(JSContext* aCx, JSObject** aTargetObject);
static mozJSComponentLoader* Get() { return sSelf; }
protected:
static mozJSComponentLoader* sSelf;
@ -140,7 +136,6 @@ class mozJSComponentLoader : public mozilla::ModuleLoader,
nsClassHashtable<nsCStringHashKey, ModuleEntry> mImports;
nsDataHashtable<nsCStringHashKey, ModuleEntry*> mInProgressImports;
nsDataHashtable<nsPtrHashKey<JSScript>, JSObject*> mThisObjects;
bool mInitialized;
bool mReuseLoaderGlobal;

View File

@ -6,7 +6,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozJSSubScriptLoader.h"
#include "mozJSComponentLoader.h"
#include "mozJSLoaderUtils.h"
#include "nsIServiceManager.h"
@ -180,10 +179,23 @@ mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
if (!targetObj) {
// If the user didn't provide an object to eval onto, find one.
mozJSComponentLoader* loader = mozJSComponentLoader::Get();
rv = loader->FindTargetObject(cx, &targetObj);
NS_ENSURE_SUCCESS(rv, rv);
// If the user didn't provide an object to eval onto, find the global
// object by walking the parent chain of the calling object.
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
NS_ENSURE_TRUE(xpc, NS_ERROR_FAILURE);
nsAXPCNativeCallContext *cc = nullptr;
rv = xpc->GetCurrentNativeCallContext(&cc);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
nsCOMPtr<nsIXPConnectWrappedNative> wn;
rv = cc->GetCalleeWrapper(getter_AddRefs(wn));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
rv = wn->GetJSObject(&targetObj);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
targetObj = JS_GetGlobalForObject(cx, targetObj);
}
// Remember an object out of the calling compartment so that we

View File

@ -7,17 +7,17 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
this.EXPORTED_SYMBOLS = ['ContentPrefInstance'];
var EXPORTED_SYMBOLS = ['ContentPrefInstance'];
// This is a wrapper for nsIContentPrefService that alleviates the need to pass
// an nsILoadContext argument to every method. Pass the context to the constructor
// instead and continue on your way in blissful ignorance.
this.ContentPrefInstance = function ContentPrefInstance(aContext) {
function ContentPrefInstance(aContext) {
this._contentPrefSvc = Cc["@mozilla.org/content-pref/service;1"].
getService(Ci.nsIContentPrefService);
this._context = aContext;
};
}
ContentPrefInstance.prototype = {
getPref: function ContentPrefInstance_init(aName, aGroup, aCallback) {