Bug 814102: Make the 'this' object used when compartment sharing a FakeBackstagePass. r=mrbkap

This commit is contained in:
Kyle Huey 2012-11-26 14:41:59 -08:00
parent e5a7452bf5
commit 7ba6475e09

View File

@ -72,6 +72,22 @@ using namespace mozilla;
using namespace mozilla::scache;
using namespace xpc;
// This JSClass exists to trick silly code that expects toString()ing the
// global in a component scope to return something with "BackstagePass" in it
// to continue working.
static JSClass kFakeBackstagePassJSClass =
{
"FakeBackstagePass",
0,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub
};
static const char kJSRuntimeServiceContractID[] = "@mozilla.org/js/xpc/RuntimeService;1";
static const char kXPConnectServiceContractID[] = "@mozilla.org/js/xpc/XPConnect;1";
static const char kObserverServiceContractID[] = "@mozilla.org/observer-service;1";
@ -472,7 +488,7 @@ mozJSComponentLoader::LoadModule(FileLocation &aFile)
ModuleEntry* mod;
if (mModules.Get(spec, &mod))
return mod;
return mod;
nsAutoPtr<ModuleEntry> entry(new ModuleEntry);
@ -717,7 +733,8 @@ mozJSComponentLoader::PrepareObjectForLocation(JSCLContextHelper& aCx,
if (aReuseLoaderGlobal) {
// If we're reusing the loader global, we don't actually use the
// global, but rather we use a different object as the 'this' object.
JSObject* newObj = JS_NewObject(aCx, nullptr, nullptr, nullptr);
JSObject* newObj = JS_NewObject(aCx, &kFakeBackstagePassJSClass,
nullptr, nullptr);
NS_ENSURE_TRUE(newObj, nullptr);
obj = newObj;