Bug 809666: Define ctypes and perf properties on the 'this' object, not the global, when sharing globals. r=mrbkap
This commit is contained in:
@@ -26,6 +26,10 @@ CPPSRCS = \
|
||||
ctypes.cpp \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES := \
|
||||
-I$(topsrcdir)/js/xpconnect/loader \
|
||||
$(NULL)
|
||||
|
||||
TEST_DIRS += tests
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "nsString.h"
|
||||
#include "nsNativeCharsetUtils.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozJSComponentLoader.h"
|
||||
|
||||
#define JSCTYPES_CONTRACTID \
|
||||
"@mozilla.org/jsctypes;1"
|
||||
@@ -69,6 +70,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;
|
||||
@@ -91,10 +97,6 @@ InitAndSealCTypesClass(JSContext* cx, JSObject* global)
|
||||
|
||||
JS_SetCTypesCallbacks(JSVAL_TO_OBJECT(ctypes), &sCallbacks);
|
||||
|
||||
// Can't freeze our global if it's shared.
|
||||
if (Preferences::GetBool("jsloader.reuseGlobal"))
|
||||
return true;
|
||||
|
||||
// Seal up Object, Function, Array and Error and their prototypes. (This
|
||||
// single object instance is shared amongst everyone who imports the ctypes
|
||||
// module.)
|
||||
@@ -118,11 +120,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 = InitAndSealCTypesClass(cx, global);
|
||||
mozJSComponentLoader* loader = mozJSComponentLoader::Get();
|
||||
nsresult rv = loader->FindTargetObject(cx, &targetObj);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*_retval = InitAndSealCTypesClass(cx, targetObj);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ CPPSRCS = \
|
||||
PerfMeasurement.cpp \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES := \
|
||||
-I$(topsrcdir)/js/xpconnect/loader \
|
||||
$(NULL)
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
MOCHITEST_CHROME_FILES = \
|
||||
test_pm.xul \
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user