Bug 609141 - Compartments mismatch in jsdScript::GetFunctionSource. r=sayrer

This commit is contained in:
Blake Kaplan 2010-11-03 18:04:22 -07:00
Родитель e0f6235585
Коммит d21e32b8fa
2 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -60,6 +60,9 @@
#include "nsIScriptContext.h"
#include "nsIJSContextStack.h"
/* XXX private JS headers. */
#include "jscompartment.h"
/*
* defining CAUTIOUS_SCRIPTHOOK makes jsds disable GC while calling out to the
* script hook. This was a hack to avoid some js engine problems that should
@ -1319,10 +1322,14 @@ jsdScript::GetFunctionSource(nsAString & aFunctionSource)
JSAutoRequest ar(cx);
JSString *jsstr;
if (fun)
if (fun) {
JSAutoEnterCompartment ac;
if (!ac.enter(cx, JS_GetFunctionObject(fun)))
return NS_ERROR_FAILURE;
jsstr = JS_DecompileFunction (cx, fun, 4);
else {
} else {
JSScript *script = JSD_GetJSScript (mCx, mScript);
js::SwitchToCompartment sc(cx, script->compartment);
jsstr = JS_DecompileScript (cx, script, "ppscript", 4);
}
if (!jsstr)

Просмотреть файл

@ -4744,7 +4744,10 @@ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, uintN inde
JSString *str;
CHECK_REQUEST(cx);
assertSameCompartment(cx, script);
#ifdef DEBUG
if (cx->compartment != script->compartment)
CompartmentChecker::fail(cx->compartment, script->compartment);
#endif
jp = js_NewPrinter(cx, name, NULL,
indent & ~JS_DONT_PRETTY_PRINT,
!(indent & JS_DONT_PRETTY_PRINT),