зеркало из https://github.com/mozilla/pjs.git
Backed out changeset 9b18eada106e (bug 531303) on suspicion of orange
This commit is contained in:
Родитель
3a59faabe6
Коммит
7d9b0d15ae
|
@ -303,8 +303,7 @@ class JSCLContextHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JSCLContextHelper(mozJSComponentLoader* loader);
|
JSCLContextHelper(mozJSComponentLoader* loader);
|
||||||
~JSCLContextHelper();
|
~JSCLContextHelper() { Pop(); }
|
||||||
JSBool ok();
|
|
||||||
|
|
||||||
JSContext* Pop();
|
JSContext* Pop();
|
||||||
|
|
||||||
|
@ -320,13 +319,6 @@ private:
|
||||||
const JSCLContextHelper& operator=(const JSCLContextHelper &); // not implemented
|
const JSCLContextHelper& operator=(const JSCLContextHelper &); // not implemented
|
||||||
};
|
};
|
||||||
|
|
||||||
JSCLContextHelper::~JSCLContextHelper()
|
|
||||||
{
|
|
||||||
if (mContext) {
|
|
||||||
Pop();
|
|
||||||
JS_DestroyContext(mContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class JSCLAutoErrorReporterSetter
|
class JSCLAutoErrorReporterSetter
|
||||||
{
|
{
|
||||||
|
@ -570,10 +562,6 @@ mozJSComponentLoader::~mozJSComponentLoader()
|
||||||
UnloadModules();
|
UnloadModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mContext) {
|
|
||||||
JS_DestroyContext(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_ASSERTION(!mFastLoadTimer,
|
NS_ASSERTION(!mFastLoadTimer,
|
||||||
"Fastload file should have been closed via xpcom-shutdown");
|
"Fastload file should have been closed via xpcom-shutdown");
|
||||||
|
|
||||||
|
@ -588,12 +576,6 @@ NS_IMPL_ISUPPORTS3(mozJSComponentLoader,
|
||||||
xpcIJSModuleLoader,
|
xpcIJSModuleLoader,
|
||||||
nsIObserver)
|
nsIObserver)
|
||||||
|
|
||||||
JSBool
|
|
||||||
JSCLContextHelper::ok()
|
|
||||||
{
|
|
||||||
return !!mContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
mozJSComponentLoader::ReallyInit()
|
mozJSComponentLoader::ReallyInit()
|
||||||
{
|
{
|
||||||
|
@ -610,15 +592,38 @@ mozJSComponentLoader::ReallyInit()
|
||||||
NS_FAILED(rv = mRuntimeService->GetRuntime(&mRuntime)))
|
NS_FAILED(rv = mRuntimeService->GetRuntime(&mRuntime)))
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
// This context is for use by UnloadModules
|
|
||||||
mContext = JS_NewContext(mozJSComponentLoader::sSelf->mRuntime, 256);
|
|
||||||
if (!mContext)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
mContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
|
mContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
|
// Create our compilation context.
|
||||||
|
mContext = JS_NewContext(mRuntime, 256);
|
||||||
|
if (!mContext)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
uint32 options = JS_GetOptions(mContext);
|
||||||
|
JS_SetOptions(mContext, options | JSOPTION_XML);
|
||||||
|
|
||||||
|
// Always use the latest js version
|
||||||
|
JS_SetVersion(mContext, JSVERSION_LATEST);
|
||||||
|
|
||||||
|
// Limit C stack consumption to a reasonable 512K
|
||||||
|
int stackDummy;
|
||||||
|
const jsuword kStackSize = 0x80000;
|
||||||
|
jsuword stackLimit, currentStackAddr = (jsuword)&stackDummy;
|
||||||
|
|
||||||
|
#if JS_STACK_GROWTH_DIRECTION < 0
|
||||||
|
stackLimit = (currentStackAddr > kStackSize)
|
||||||
|
? currentStackAddr - kStackSize
|
||||||
|
: 0;
|
||||||
|
#else
|
||||||
|
stackLimit = (currentStackAddr + kStackSize > currentStackAddr)
|
||||||
|
? currentStackAddr + kStackSize
|
||||||
|
: (jsuword) -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
JS_SetThreadStackLimit(mContext, stackLimit);
|
||||||
|
|
||||||
#ifndef XPCONNECT_STANDALONE
|
#ifndef XPCONNECT_STANDALONE
|
||||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
|
||||||
|
@ -719,8 +724,6 @@ mozJSComponentLoader::LoadModule(nsILocalFile* aComponentFile,
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
JSCLContextHelper cx(this);
|
JSCLContextHelper cx(this);
|
||||||
if (!cx.ok())
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
JSObject* cm_jsobj;
|
JSObject* cm_jsobj;
|
||||||
nsCOMPtr<nsIXPConnectJSObjectHolder> cm_holder;
|
nsCOMPtr<nsIXPConnectJSObjectHolder> cm_holder;
|
||||||
|
@ -1112,14 +1115,12 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponent,
|
||||||
|
|
||||||
JSPrincipals* jsPrincipals = nsnull;
|
JSPrincipals* jsPrincipals = nsnull;
|
||||||
JSCLContextHelper cx(this);
|
JSCLContextHelper cx(this);
|
||||||
if (!cx.ok())
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
#ifndef XPCONNECT_STANDALONE
|
#ifndef XPCONNECT_STANDALONE
|
||||||
rv = mSystemPrincipal->GetJSPrincipals(cx, &jsPrincipals);
|
rv = mSystemPrincipal->GetJSPrincipals(cx, &jsPrincipals);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
JSPrincipalsHolder princHolder(cx, jsPrincipals);
|
JSPrincipalsHolder princHolder(mContext, jsPrincipals);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nsCOMPtr<nsIXPCScriptable> backstagePass;
|
nsCOMPtr<nsIXPCScriptable> backstagePass;
|
||||||
|
@ -1409,7 +1410,9 @@ mozJSComponentLoader::UnloadModules()
|
||||||
mImports.Clear();
|
mImports.Clear();
|
||||||
mModules.Clear();
|
mModules.Clear();
|
||||||
|
|
||||||
// XXX We want to force a GC.
|
// Destroying our context will force a GC.
|
||||||
|
JS_DestroyContext(mContext);
|
||||||
|
mContext = nsnull;
|
||||||
|
|
||||||
mRuntimeService = nsnull;
|
mRuntimeService = nsnull;
|
||||||
mContextStack = nsnull;
|
mContextStack = nsnull;
|
||||||
|
@ -1581,29 +1584,27 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
|
||||||
|
|
||||||
jsval symbols;
|
jsval symbols;
|
||||||
if (targetObj) {
|
if (targetObj) {
|
||||||
JSCLContextHelper cx(this);
|
JSCLContextHelper cxhelper(this);
|
||||||
if (!cx.ok())
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
if (!JS_GetProperty(cx, mod->global,
|
if (!JS_GetProperty(mContext, mod->global,
|
||||||
"EXPORTED_SYMBOLS", &symbols)) {
|
"EXPORTED_SYMBOLS", &symbols)) {
|
||||||
return ReportOnCaller(cx, ERROR_NOT_PRESENT,
|
return ReportOnCaller(cxhelper, ERROR_NOT_PRESENT,
|
||||||
PromiseFlatCString(aLocation).get());
|
PromiseFlatCString(aLocation).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
JSObject *symbolsObj = nsnull;
|
JSObject *symbolsObj = nsnull;
|
||||||
if (!JSVAL_IS_OBJECT(symbols) ||
|
if (!JSVAL_IS_OBJECT(symbols) ||
|
||||||
!(symbolsObj = JSVAL_TO_OBJECT(symbols)) ||
|
!(symbolsObj = JSVAL_TO_OBJECT(symbols)) ||
|
||||||
!JS_IsArrayObject(cx, symbolsObj)) {
|
!JS_IsArrayObject(mContext, symbolsObj)) {
|
||||||
return ReportOnCaller(cx, ERROR_NOT_AN_ARRAY,
|
return ReportOnCaller(cxhelper, ERROR_NOT_AN_ARRAY,
|
||||||
PromiseFlatCString(aLocation).get());
|
PromiseFlatCString(aLocation).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over symbols array, installing symbols on targetObj:
|
// Iterate over symbols array, installing symbols on targetObj:
|
||||||
|
|
||||||
jsuint symbolCount = 0;
|
jsuint symbolCount = 0;
|
||||||
if (!JS_GetArrayLength(cx, symbolsObj, &symbolCount)) {
|
if (!JS_GetArrayLength(mContext, symbolsObj, &symbolCount)) {
|
||||||
return ReportOnCaller(cx, ERROR_GETTING_ARRAY_LENGTH,
|
return ReportOnCaller(cxhelper, ERROR_GETTING_ARRAY_LENGTH,
|
||||||
PromiseFlatCString(aLocation).get());
|
PromiseFlatCString(aLocation).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1615,23 +1616,23 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
|
||||||
jsval val;
|
jsval val;
|
||||||
JSString *symbolName;
|
JSString *symbolName;
|
||||||
|
|
||||||
if (!JS_GetElement(cx, symbolsObj, i, &val) ||
|
if (!JS_GetElement(mContext, symbolsObj, i, &val) ||
|
||||||
!JSVAL_IS_STRING(val)) {
|
!JSVAL_IS_STRING(val)) {
|
||||||
return ReportOnCaller(cx, ERROR_ARRAY_ELEMENT,
|
return ReportOnCaller(cxhelper, ERROR_ARRAY_ELEMENT,
|
||||||
PromiseFlatCString(aLocation).get(), i);
|
PromiseFlatCString(aLocation).get(), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
symbolName = JSVAL_TO_STRING(val);
|
symbolName = JSVAL_TO_STRING(val);
|
||||||
if (!JS_GetProperty(cx, mod->global,
|
if (!JS_GetProperty(mContext, mod->global,
|
||||||
JS_GetStringBytes(symbolName), &val)) {
|
JS_GetStringBytes(symbolName), &val)) {
|
||||||
return ReportOnCaller(cx, ERROR_GETTING_SYMBOL,
|
return ReportOnCaller(cxhelper, ERROR_GETTING_SYMBOL,
|
||||||
PromiseFlatCString(aLocation).get(),
|
PromiseFlatCString(aLocation).get(),
|
||||||
JS_GetStringBytes(symbolName));
|
JS_GetStringBytes(symbolName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!JS_SetProperty(cx, targetObj,
|
if (!JS_SetProperty(mContext, targetObj,
|
||||||
JS_GetStringBytes(symbolName), &val)) {
|
JS_GetStringBytes(symbolName), &val)) {
|
||||||
return ReportOnCaller(cx, ERROR_SETTING_SYMBOL,
|
return ReportOnCaller(cxhelper, ERROR_SETTING_SYMBOL,
|
||||||
PromiseFlatCString(aLocation).get(),
|
PromiseFlatCString(aLocation).get(),
|
||||||
JS_GetStringBytes(symbolName));
|
JS_GetStringBytes(symbolName));
|
||||||
}
|
}
|
||||||
|
@ -1683,38 +1684,9 @@ mozJSComponentLoader::Observe(nsISupports *subject, const char *topic,
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
JSCLContextHelper::JSCLContextHelper(mozJSComponentLoader *loader)
|
JSCLContextHelper::JSCLContextHelper(mozJSComponentLoader *loader)
|
||||||
: mContextThread(0),
|
: mContext(loader->mContext), mContextThread(0),
|
||||||
mContextStack(loader->mContextStack)
|
mContextStack(loader->mContextStack)
|
||||||
{
|
{
|
||||||
// Create our compilation context.
|
|
||||||
mContext = JS_NewContext(mozJSComponentLoader::sSelf->mRuntime, 256);
|
|
||||||
if (!mContext)
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint32 options = JS_GetOptions(mContext);
|
|
||||||
JS_SetOptions(mContext, options | JSOPTION_XML);
|
|
||||||
|
|
||||||
// Always use the latest js version
|
|
||||||
JS_SetVersion(mContext, JSVERSION_LATEST);
|
|
||||||
|
|
||||||
// Limit C stack consumption to a reasonable 512K
|
|
||||||
int stackDummy;
|
|
||||||
const jsuword kStackSize = 0x80000;
|
|
||||||
|
|
||||||
jsuword stackLimit, currentStackAddr = (jsuword)&stackDummy;
|
|
||||||
|
|
||||||
#if JS_STACK_GROWTH_DIRECTION < 0
|
|
||||||
stackLimit = (currentStackAddr > kStackSize)
|
|
||||||
? currentStackAddr - kStackSize
|
|
||||||
: 0;
|
|
||||||
#else
|
|
||||||
stackLimit = (currentStackAddr + kStackSize > currentStackAddr)
|
|
||||||
? currentStackAddr + kStackSize
|
|
||||||
: (jsuword) -1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
JS_SetThreadStackLimit(mContext, stackLimit);
|
|
||||||
|
|
||||||
mContextStack->Push(mContext);
|
mContextStack->Push(mContext);
|
||||||
mContextThread = JS_GetContextThread(mContext);
|
mContextThread = JS_GetContextThread(mContext);
|
||||||
if (mContextThread) {
|
if (mContextThread) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче