Bug 809666: Define ctypes and perf properties on the 'this' object, not the global, when sharing globals. r=mrbkap

This commit is contained in:
Kyle Huey
2012-11-13 08:57:46 -08:00
parent 49f876f20d
commit 27cecbd39a
4 changed files with 34 additions and 16 deletions

View File

@@ -8,6 +8,7 @@
#include "mozilla/ModuleUtils.h"
#include "nsMemory.h"
#include "mozilla/Preferences.h"
#include "mozJSComponentLoader.h"
#define JSPERF_CONTRACTID \
"@mozilla.org/jsperf;1"
@@ -44,6 +45,11 @@ SealObjectAndPrototype(JSContext* cx, JSObject* parent, const char* name)
if (!JS_GetProperty(cx, parent, name, &prop))
return false;
if (prop.isUndefined()) {
// Pretend we sealed the object.
return true;
}
JSObject* obj = JSVAL_TO_OBJECT(prop);
if (!JS_GetProperty(cx, obj, "prototype", &prop))
return false;
@@ -59,10 +65,6 @@ InitAndSealPerfMeasurementClass(JSContext* cx, JSObject* global)
if (!JS::RegisterPerfMeasurement(cx, global))
return false;
// Can't freeze our global if it's shared.
if (Preferences::GetBool("jsloader.reuseGlobal"))
return true;
// Seal up Object, Function, and Array and their prototypes. (This single
// object instance is shared amongst everyone who imports the jsperf module.)
if (!SealObjectAndPrototype(cx, global, "Object") ||
@@ -84,11 +86,14 @@ Module::Call(nsIXPConnectWrappedNative* wrapper,
jsval* vp,
bool* _retval)
{
JSObject* global = JS_GetGlobalForScopeChain(cx);
if (!global)
return NS_ERROR_NOT_AVAILABLE;
bool reusingGlobal = Preferences::GetBool("jsloader.reuseGlobal");
JSObject* targetObj = nullptr;
*_retval = InitAndSealPerfMeasurementClass(cx, global);
mozJSComponentLoader* loader = mozJSComponentLoader::Get();
nsresult rv = loader->FindTargetObject(cx, &targetObj);
NS_ENSURE_SUCCESS(rv, rv);
*_retval = InitAndSealPerfMeasurementClass(cx, targetObj);
return NS_OK;
}