Bug 918373 - GC: Handlify various public APIs r=sfink r=bholley r=smaug

This commit is contained in:
Jon Coppeard 2013-09-20 10:22:59 +01:00
Родитель 7ff6b4f343
Коммит 7f7a4918ef
25 изменённых файлов: 81 добавлений и 81 удалений

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

@ -480,7 +480,7 @@ nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction(JSContext *cx)
unsigned lineNum = 0; unsigned lineNum = 0;
NS_NAMED_LITERAL_STRING(scriptSample, "call to eval() or related function blocked by CSP"); NS_NAMED_LITERAL_STRING(scriptSample, "call to eval() or related function blocked by CSP");
JSScript *script; JS::RootedScript script(cx);
if (JS_DescribeScriptedCaller(cx, &script, &lineNum)) { if (JS_DescribeScriptedCaller(cx, &script, &lineNum)) {
if (const char *file = JS_GetScriptFilename(cx, script)) { if (const char *file = JS_GetScriptFilename(cx, script)) {
CopyUTF8toUTF16(nsDependentCString(file), fileName); CopyUTF8toUTF16(nsDependentCString(file), fileName);

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

@ -671,7 +671,7 @@ WebSocket::Init(JSContext* aCx,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
unsigned lineno; unsigned lineno;
JSScript* script; JS::RootedScript script(aCx);
if (JS_DescribeScriptedCaller(aCx, &script, &lineno)) { if (JS_DescribeScriptedCaller(aCx, &script, &lineno)) {
mScriptFile = JS_GetScriptFilename(aCx, script); mScriptFile = JS_GetScriptFilename(aCx, script);
mScriptLine = lineno; mScriptLine = lineno;

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

@ -9437,7 +9437,7 @@ nsGlobalWindow::ShowSlowScriptDialog()
// Check if we should offer the option to debug // Check if we should offer the option to debug
JS::RootedScript script(cx); JS::RootedScript script(cx);
unsigned lineno; unsigned lineno;
bool hasFrame = JS_DescribeScriptedCaller(cx, script.address(), &lineno); bool hasFrame = JS_DescribeScriptedCaller(cx, &script, &lineno);
bool debugPossible = hasFrame && js::CanCallContextDebugHandler(cx); bool debugPossible = hasFrame && js::CanCallContextDebugHandler(cx);
#ifdef MOZ_JSDEBUGGER #ifdef MOZ_JSDEBUGGER

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

@ -509,7 +509,8 @@ NS_ScriptErrorReporter(JSContext *cx,
// absence of werror are swallowed whole, so report those now. // absence of werror are swallowed whole, so report those now.
if (!JSREPORT_IS_WARNING(report->flags)) { if (!JSREPORT_IS_WARNING(report->flags)) {
nsIXPConnect* xpc = nsContentUtils::XPConnect(); nsIXPConnect* xpc = nsContentUtils::XPConnect();
if (JS_DescribeScriptedCaller(cx, nullptr, nullptr)) { JS::RootedScript script(cx);
if (JS_DescribeScriptedCaller(cx, &script, nullptr)) {
xpc->MarkErrorUnreported(cx); xpc->MarkErrorUnreported(cx);
return; return;
} }

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

@ -31,7 +31,7 @@ bool
nsJSUtils::GetCallingLocation(JSContext* aContext, const char* *aFilename, nsJSUtils::GetCallingLocation(JSContext* aContext, const char* *aFilename,
uint32_t* aLineno) uint32_t* aLineno)
{ {
JSScript* script = nullptr; JS::RootedScript script(aContext);
unsigned lineno = 0; unsigned lineno = 0;
if (!JS_DescribeScriptedCaller(aContext, &script, &lineno)) { if (!JS_DescribeScriptedCaller(aContext, &script, &lineno)) {

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

@ -387,7 +387,7 @@ EventListenerManager::DispatchEvent(JSContext* aCx, const EventTarget& aTarget,
JS::Rooted<JS::Value> listenerVal(aCx, listeners[index]); JS::Rooted<JS::Value> listenerVal(aCx, listeners[index]);
JS::Rooted<JSObject*> listenerObj(aCx); JS::Rooted<JSObject*> listenerObj(aCx);
if (!JS_ValueToObject(aCx, listenerVal, listenerObj.address())) { if (!JS_ValueToObject(aCx, listenerVal, &listenerObj)) {
if (!JS_ReportPendingException(aCx)) { if (!JS_ReportPendingException(aCx)) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return false; return false;

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

@ -698,7 +698,7 @@ ContentSecurityPolicyAllows(JSContext* aCx)
nsString fileName; nsString fileName;
uint32_t lineNum = 0; uint32_t lineNum = 0;
JSScript* script; JS::RootedScript script(aCx);
const char* file; const char* file;
if (JS_DescribeScriptedCaller(aCx, &script, &lineNum) && if (JS_DescribeScriptedCaller(aCx, &script, &lineNum) &&
(file = JS_GetScriptFilename(aCx, script))) { (file = JS_GetScriptFilename(aCx, script))) {

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

@ -232,7 +232,7 @@ private:
MOZ_ASSERT(worker); MOZ_ASSERT(worker);
JS::Rooted<JSObject*> listener(aCx); JS::Rooted<JSObject*> listener(aCx);
if (!JS_ValueToObject(aCx, aArgs.get(0), listener.address())) { if (!JS_ValueToObject(aCx, aArgs.get(0), &listener)) {
return false; return false;
} }

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

@ -2687,7 +2687,7 @@ WorkerPrivate::Create(JSContext* aCx, JS::Handle<JSObject*> aObj, WorkerPrivate*
// We're being created outside of a window. Need to figure out the script // We're being created outside of a window. Need to figure out the script
// that is creating us in order for us to use relative URIs later on. // that is creating us in order for us to use relative URIs later on.
JSScript *script; JS::RootedScript script(aCx);
if (JS_DescribeScriptedCaller(aCx, &script, nullptr)) { if (JS_DescribeScriptedCaller(aCx, &script, nullptr)) {
if (NS_FAILED(NS_NewURI(getter_AddRefs(baseURI), if (NS_FAILED(NS_NewURI(getter_AddRefs(baseURI),
JS_GetScriptFilename(aCx, script)))) { JS_GetScriptFilename(aCx, script)))) {

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

@ -572,7 +572,8 @@ jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval)
obj = js::UncheckedUnwrap(JSVAL_TO_OBJECT(jsdval->val)); obj = js::UncheckedUnwrap(JSVAL_TO_OBJECT(jsdval->val));
JSAutoCompartment ac(cx, obj); JSAutoCompartment ac(cx, obj);
fun = JS_ValueToFunction(cx, OBJECT_TO_JSVAL(obj)); JS::RootedValue funval(cx, JS::ObjectValue(*obj));
fun = JS_ValueToFunction(cx, funval);
return fun; return fun;
} }

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

@ -3974,7 +3974,7 @@ PointerType::ConstructData(JSContext* cx,
thisObj = NULL; thisObj = NULL;
} else if (!JSVAL_IS_PRIMITIVE(args[1])) { } else if (!JSVAL_IS_PRIMITIVE(args[1])) {
thisObj = &args[1].toObject(); thisObj = &args[1].toObject();
} else if (!JS_ValueToObject(cx, args[1], thisObj.address())) { } else if (!JS_ValueToObject(cx, args[1], &thisObj)) {
return false; return false;
} }
} }

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

@ -122,7 +122,8 @@ BEGIN_TEST(test_cloneScriptWithPrincipals)
CHECK(cloned = JS_CloneFunctionObject(cx, obj, B)); CHECK(cloned = JS_CloneFunctionObject(cx, obj, B));
JSFunction *fun; JSFunction *fun;
CHECK(fun = JS_ValueToFunction(cx, JS::ObjectValue(*cloned))); JS::RootedValue clonedValue(cx, JS::ObjectValue(*cloned));
CHECK(fun = JS_ValueToFunction(cx, clonedValue));
JSScript *script; JSScript *script;
CHECK(script = JS_GetFunctionScript(cx, fun)); CHECK(script = JS_GetFunctionScript(cx, fun));

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

@ -254,7 +254,7 @@ BEGIN_TEST(testDebugger_singleStepThrow)
static bool static bool
setStepMode(JSContext *cx, unsigned argc, jsval *vp) setStepMode(JSContext *cx, unsigned argc, jsval *vp)
{ {
JSScript *script; JS::RootedScript script(cx);
JS_DescribeScriptedCaller(cx, &script, NULL); JS_DescribeScriptedCaller(cx, &script, NULL);
JS_ASSERT(script); JS_ASSERT(script);

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

@ -312,9 +312,8 @@ JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, const char *for
} }
JS_PUBLIC_API(bool) JS_PUBLIC_API(bool)
JS_ConvertValue(JSContext *cx, jsval valueArg, JSType type, jsval *vp) JS_ConvertValue(JSContext *cx, HandleValue value, JSType type, MutableHandleValue vp)
{ {
RootedValue value(cx, valueArg);
bool ok; bool ok;
RootedObject obj(cx); RootedObject obj(cx);
JSString *str; JSString *str;
@ -325,32 +324,32 @@ JS_ConvertValue(JSContext *cx, jsval valueArg, JSType type, jsval *vp)
assertSameCompartment(cx, value); assertSameCompartment(cx, value);
switch (type) { switch (type) {
case JSTYPE_VOID: case JSTYPE_VOID:
*vp = JSVAL_VOID; vp.setUndefined();
ok = true; ok = true;
break; break;
case JSTYPE_OBJECT: case JSTYPE_OBJECT:
ok = js_ValueToObjectOrNull(cx, value, &obj); ok = js_ValueToObjectOrNull(cx, value, &obj);
if (ok) if (ok)
*vp = OBJECT_TO_JSVAL(obj); vp.setObjectOrNull(obj);
break; break;
case JSTYPE_FUNCTION: case JSTYPE_FUNCTION:
*vp = value; vp.set(value);
obj = ReportIfNotFunction(cx, *vp); obj = ReportIfNotFunction(cx, vp);
ok = (obj != NULL); ok = (obj != NULL);
break; break;
case JSTYPE_STRING: case JSTYPE_STRING:
str = ToString<CanGC>(cx, value); str = ToString<CanGC>(cx, value);
ok = (str != NULL); ok = (str != NULL);
if (ok) if (ok)
*vp = STRING_TO_JSVAL(str); vp.setString(str);
break; break;
case JSTYPE_NUMBER: case JSTYPE_NUMBER:
ok = JS_ValueToNumber(cx, value, &d); ok = JS_ValueToNumber(cx, value, &d);
if (ok) if (ok)
*vp = DOUBLE_TO_JSVAL(d); vp.setDouble(d);
break; break;
case JSTYPE_BOOLEAN: case JSTYPE_BOOLEAN:
*vp = BooleanValue(ToBoolean(value)); vp.setBoolean(ToBoolean(value));
return true; return true;
default: { default: {
char numBuf[12]; char numBuf[12];
@ -364,23 +363,17 @@ JS_ConvertValue(JSContext *cx, jsval valueArg, JSType type, jsval *vp)
} }
JS_PUBLIC_API(bool) JS_PUBLIC_API(bool)
JS_ValueToObject(JSContext *cx, jsval valueArg, JSObject **objpArg) JS_ValueToObject(JSContext *cx, HandleValue value, MutableHandleObject objp)
{ {
RootedValue value(cx, valueArg);
RootedObject objp(cx, *objpArg);
AssertHeapIsIdle(cx); AssertHeapIsIdle(cx);
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
assertSameCompartment(cx, value); assertSameCompartment(cx, value);
if (!js_ValueToObjectOrNull(cx, value, &objp)) return js_ValueToObjectOrNull(cx, value, objp);
return false;
*objpArg = objp;
return true;
} }
JS_PUBLIC_API(JSFunction *) JS_PUBLIC_API(JSFunction *)
JS_ValueToFunction(JSContext *cx, jsval valueArg) JS_ValueToFunction(JSContext *cx, HandleValue value)
{ {
RootedValue value(cx, valueArg);
AssertHeapIsIdle(cx); AssertHeapIsIdle(cx);
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
assertSameCompartment(cx, value); assertSameCompartment(cx, value);
@ -388,9 +381,8 @@ JS_ValueToFunction(JSContext *cx, jsval valueArg)
} }
JS_PUBLIC_API(JSFunction *) JS_PUBLIC_API(JSFunction *)
JS_ValueToConstructor(JSContext *cx, jsval valueArg) JS_ValueToConstructor(JSContext *cx, HandleValue value)
{ {
RootedValue value(cx, valueArg);
AssertHeapIsIdle(cx); AssertHeapIsIdle(cx);
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
assertSameCompartment(cx, value); assertSameCompartment(cx, value);
@ -6159,10 +6151,9 @@ JS_IsIdentifier(JSContext *cx, HandleString str, bool *isIdentifier)
} }
JS_PUBLIC_API(bool) JS_PUBLIC_API(bool)
JS_DescribeScriptedCaller(JSContext *cx, JSScript **script, unsigned *lineno) JS_DescribeScriptedCaller(JSContext *cx, MutableHandleScript script, unsigned *lineno)
{ {
if (script) script.set(NULL);
*script = NULL;
if (lineno) if (lineno)
*lineno = 0; *lineno = 0;
@ -6170,8 +6161,7 @@ JS_DescribeScriptedCaller(JSContext *cx, JSScript **script, unsigned *lineno)
if (i.done()) if (i.done())
return false; return false;
if (script) script.set(i.script());
*script = i.script();
if (lineno) if (lineno)
*lineno = js::PCToLineNumber(i.script(), i.pc()); *lineno = js::PCToLineNumber(i.script(), i.pc());
return true; return true;
@ -6230,7 +6220,7 @@ JS::AssertArgumentsAreSane(JSContext *cx, HandleValue value)
#endif /* DEBUG */ #endif /* DEBUG */
JS_PUBLIC_API(void *) JS_PUBLIC_API(void *)
JS_EncodeScript(JSContext *cx, JSScript *scriptArg, uint32_t *lengthp) JS_EncodeScript(JSContext *cx, HandleScript scriptArg, uint32_t *lengthp)
{ {
XDREncoder encoder(cx); XDREncoder encoder(cx);
RootedScript script(cx, scriptArg); RootedScript script(cx, scriptArg);
@ -6240,7 +6230,7 @@ JS_EncodeScript(JSContext *cx, JSScript *scriptArg, uint32_t *lengthp)
} }
JS_PUBLIC_API(void *) JS_PUBLIC_API(void *)
JS_EncodeInterpretedFunction(JSContext *cx, JSObject *funobjArg, uint32_t *lengthp) JS_EncodeInterpretedFunction(JSContext *cx, HandleObject funobjArg, uint32_t *lengthp)
{ {
XDREncoder encoder(cx); XDREncoder encoder(cx);
RootedObject funobj(cx, funobjArg); RootedObject funobj(cx, funobjArg);

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

@ -1024,16 +1024,16 @@ JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv,
#endif #endif
extern JS_PUBLIC_API(bool) extern JS_PUBLIC_API(bool)
JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp); JS_ConvertValue(JSContext *cx, JS::HandleValue v, JSType type, JS::MutableHandleValue vp);
extern JS_PUBLIC_API(bool) extern JS_PUBLIC_API(bool)
JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp); JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp);
extern JS_PUBLIC_API(JSFunction *) extern JS_PUBLIC_API(JSFunction *)
JS_ValueToFunction(JSContext *cx, jsval v); JS_ValueToFunction(JSContext *cx, JS::HandleValue v);
extern JS_PUBLIC_API(JSFunction *) extern JS_PUBLIC_API(JSFunction *)
JS_ValueToConstructor(JSContext *cx, jsval v); JS_ValueToConstructor(JSContext *cx, JS::HandleValue v);
extern JS_PUBLIC_API(JSString *) extern JS_PUBLIC_API(JSString *)
JS_ValueToString(JSContext *cx, jsval v); JS_ValueToString(JSContext *cx, jsval v);
@ -4214,7 +4214,8 @@ JS_IsConstructing(JSContext *cx, const jsval *vp)
#ifdef DEBUG #ifdef DEBUG
JSObject *callee = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)); JSObject *callee = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
if (JS_ObjectIsFunction(cx, callee)) { if (JS_ObjectIsFunction(cx, callee)) {
JSFunction *fun = JS_ValueToFunction(cx, JS_CALLEE(cx, vp)); JS::RootedValue calleeValue(cx, JS_CALLEE(cx, vp));
JSFunction *fun = JS_ValueToFunction(cx, calleeValue);
JS_ASSERT(JS_IsConstructor(fun)); JS_ASSERT(JS_IsConstructor(fun));
} else { } else {
JS_ASSERT(JS_GetClass(callee)->construct != NULL); JS_ASSERT(JS_GetClass(callee)->construct != NULL);
@ -4294,7 +4295,7 @@ JS_IsIdentifier(JSContext *cx, JS::HandleString str, bool *isIdentifier);
* frame. Returns true if a scripted frame was found, false otherwise. * frame. Returns true if a scripted frame was found, false otherwise.
*/ */
extern JS_PUBLIC_API(bool) extern JS_PUBLIC_API(bool)
JS_DescribeScriptedCaller(JSContext *cx, JSScript **script, unsigned *lineno); JS_DescribeScriptedCaller(JSContext *cx, JS::MutableHandleScript script, unsigned *lineno);
/* /*
@ -4302,10 +4303,10 @@ JS_DescribeScriptedCaller(JSContext *cx, JSScript **script, unsigned *lineno);
*/ */
extern JS_PUBLIC_API(void *) extern JS_PUBLIC_API(void *)
JS_EncodeScript(JSContext *cx, JSScript *script, uint32_t *lengthp); JS_EncodeScript(JSContext *cx, JS::HandleScript script, uint32_t *lengthp);
extern JS_PUBLIC_API(void *) extern JS_PUBLIC_API(void *)
JS_EncodeInterpretedFunction(JSContext *cx, JSObject *funobj, uint32_t *lengthp); JS_EncodeInterpretedFunction(JSContext *cx, JS::HandleObject funobj, uint32_t *lengthp);
extern JS_PUBLIC_API(JSScript *) extern JS_PUBLIC_API(JSScript *)
JS_DecodeScript(JSContext *cx, const void *data, uint32_t length, JS_DecodeScript(JSContext *cx, const void *data, uint32_t length,

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

@ -1,4 +1,4 @@
define hookpost-run afe9b1f9b180define hookpost-run
if ($sigaction) if ($sigaction)
call free($sigaction) call free($sigaction)
set $sigaction = 0 set $sigaction = 0

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

@ -645,7 +645,7 @@ static JSScript *
GetTopScript(JSContext *cx) GetTopScript(JSContext *cx)
{ {
RootedScript script(cx); RootedScript script(cx);
JS_DescribeScriptedCaller(cx, script.address(), NULL); JS_DescribeScriptedCaller(cx, &script, NULL);
return script; return script;
} }
@ -1417,8 +1417,9 @@ AssertEq(JSContext *cx, unsigned argc, jsval *vp)
} }
static JSScript * static JSScript *
ValueToScript(JSContext *cx, jsval v, JSFunction **funp = NULL) ValueToScript(JSContext *cx, jsval vArg, JSFunction **funp = NULL)
{ {
RootedValue v(cx, vArg);
RootedFunction fun(cx, JS_ValueToFunction(cx, v)); RootedFunction fun(cx, JS_ValueToFunction(cx, v));
if (!fun) if (!fun)
return NULL; return NULL;
@ -2332,7 +2333,7 @@ Clone(JSContext *cx, unsigned argc, jsval *vp)
} }
if (argc > 1) { if (argc > 1) {
if (!JS_ValueToObject(cx, args[1], parent.address())) if (!JS_ValueToObject(cx, args[1], &parent))
return false; return false;
} else { } else {
parent = JS_GetParent(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))); parent = JS_GetParent(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
@ -2353,17 +2354,18 @@ GetPDA(JSContext *cx, unsigned argc, jsval *vp)
JSPropertyDescArray pda; JSPropertyDescArray pda;
JSPropertyDesc *pd; JSPropertyDesc *pd;
if (!JS_ValueToObject(cx, argc == 0 ? UndefinedValue() : vp[2], vobj.address())) CallArgs args = CallArgsFromVp(argc, vp);
if (!JS_ValueToObject(cx, args[0], &vobj))
return false; return false;
if (!vobj) { if (!vobj) {
JS_SET_RVAL(cx, vp, UndefinedValue()); args.rval().setUndefined();
return true; return true;
} }
RootedObject aobj(cx, JS_NewArrayObject(cx, 0, NULL)); RootedObject aobj(cx, JS_NewArrayObject(cx, 0, NULL));
if (!aobj) if (!aobj)
return false; return false;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(aobj)); args.rval().setObject(*aobj);
ok = !!JS_GetPropertyDescArray(cx, vobj, &pda); ok = !!JS_GetPropertyDescArray(cx, vobj, &pda);
if (!ok) if (!ok)
@ -2552,7 +2554,7 @@ EvalInContext(JSContext *cx, unsigned argc, jsval *vp)
RootedScript script(cx); RootedScript script(cx);
unsigned lineno; unsigned lineno;
JS_DescribeScriptedCaller(cx, script.address(), &lineno); JS_DescribeScriptedCaller(cx, &script, &lineno);
RootedValue rval(cx); RootedValue rval(cx);
{ {
Maybe<JSAutoCompartment> ac; Maybe<JSAutoCompartment> ac;
@ -3464,7 +3466,7 @@ DecompileThisScript(JSContext *cx, unsigned argc, Value *vp)
{ {
CallArgs args = CallArgsFromVp(argc, vp); CallArgs args = CallArgsFromVp(argc, vp);
RootedScript script (cx); RootedScript script (cx);
if (!JS_DescribeScriptedCaller(cx, script.address(), NULL)) { if (!JS_DescribeScriptedCaller(cx, &script, NULL)) {
args.rval().setString(cx->runtime()->emptyString); args.rval().setString(cx->runtime()->emptyString);
return true; return true;
} }
@ -3480,7 +3482,7 @@ ThisFilename(JSContext *cx, unsigned argc, Value *vp)
{ {
CallArgs args = CallArgsFromVp(argc, vp); CallArgs args = CallArgsFromVp(argc, vp);
RootedScript script (cx); RootedScript script (cx);
if (!JS_DescribeScriptedCaller(cx, script.address(), NULL) || !script->filename()) { if (!JS_DescribeScriptedCaller(cx, &script, NULL) || !script->filename()) {
args.rval().setString(cx->runtime()->emptyString); args.rval().setString(cx->runtime()->emptyString);
return true; return true;
} }
@ -4170,7 +4172,8 @@ Exec(JSContext *cx, unsigned argc, jsval *vp)
JS_SET_RVAL(cx, vp, UndefinedValue()); JS_SET_RVAL(cx, vp, UndefinedValue());
fun = JS_ValueToFunction(cx, vp[0]); RootedValue arg(cx, vp[0]);
fun = JS_ValueToFunction(cx, arg);
if (!fun) if (!fun)
return false; return false;
if (!fun->atom) if (!fun->atom)

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

@ -513,7 +513,7 @@ mozJSComponentLoader::LoadModule(FileLocation &aFile)
} }
RootedObject jsGetFactoryObj(cx); RootedObject jsGetFactoryObj(cx);
if (!JS_ValueToObject(cx, NSGetFactory_val, jsGetFactoryObj.address()) || if (!JS_ValueToObject(cx, NSGetFactory_val, &jsGetFactoryObj) ||
!jsGetFactoryObj) { !jsGetFactoryObj) {
/* XXX report error properly */ /* XXX report error properly */
return NULL; return NULL;
@ -776,8 +776,7 @@ mozJSComponentLoader::ObjectForLocation(nsIFile *aComponentFile,
if (cache) { if (cache) {
if (!mReuseLoaderGlobal) { if (!mReuseLoaderGlobal) {
rv = ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, rv = ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, &script);
script.address());
} else { } else {
rv = ReadCachedFunction(cache, cachePath, cx, mSystemPrincipal, rv = ReadCachedFunction(cache, cachePath, cx, mSystemPrincipal,
function.address()); function.address());

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

@ -11,6 +11,7 @@
#include "mozilla/scache/StartupCache.h" #include "mozilla/scache/StartupCache.h"
using namespace JS;
using namespace mozilla::scache; using namespace mozilla::scache;
// We only serialize scripts with system principals. So we don't serialize the // We only serialize scripts with system principals. So we don't serialize the
@ -18,7 +19,7 @@ using namespace mozilla::scache;
// principals to the system principals. // principals to the system principals.
nsresult nsresult
ReadCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, ReadCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx,
nsIPrincipal *systemPrincipal, JSScript **scriptp) nsIPrincipal *systemPrincipal, MutableHandleScript scriptp)
{ {
nsAutoArrayPtr<char> buf; nsAutoArrayPtr<char> buf;
uint32_t len; uint32_t len;
@ -27,10 +28,9 @@ ReadCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx,
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; // don't warn since NOT_AVAILABLE is an ok error return rv; // don't warn since NOT_AVAILABLE is an ok error
JSScript *script = JS_DecodeScript(cx, buf, len, nsJSPrincipals::get(systemPrincipal), nullptr); scriptp.set(JS_DecodeScript(cx, buf, len, nsJSPrincipals::get(systemPrincipal), nullptr));
if (!script) if (!scriptp)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
*scriptp = script;
return NS_OK; return NS_OK;
} }
@ -57,7 +57,7 @@ ReadCachedFunction(StartupCache* cache, nsACString &uri, JSContext *cx,
nsresult nsresult
WriteCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx, WriteCachedScript(StartupCache* cache, nsACString &uri, JSContext *cx,
nsIPrincipal *systemPrincipal, JSScript *script) nsIPrincipal *systemPrincipal, HandleScript script)
{ {
MOZ_ASSERT(JS_GetScriptPrincipals(script) == nsJSPrincipals::get(systemPrincipal)); MOZ_ASSERT(JS_GetScriptPrincipals(script) == nsJSPrincipals::get(systemPrincipal));
MOZ_ASSERT(JS_GetScriptOriginPrincipals(script) == nsJSPrincipals::get(systemPrincipal)); MOZ_ASSERT(JS_GetScriptOriginPrincipals(script) == nsJSPrincipals::get(systemPrincipal));

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

@ -19,7 +19,7 @@ class StartupCache;
nsresult nsresult
ReadCachedScript(mozilla::scache::StartupCache* cache, nsACString &uri, ReadCachedScript(mozilla::scache::StartupCache* cache, nsACString &uri,
JSContext *cx, nsIPrincipal *systemPrincipal, JSContext *cx, nsIPrincipal *systemPrincipal,
JSScript **script); JS::MutableHandleScript scriptp);
nsresult nsresult
ReadCachedFunction(mozilla::scache::StartupCache* cache, nsACString &uri, ReadCachedFunction(mozilla::scache::StartupCache* cache, nsACString &uri,
@ -29,7 +29,7 @@ ReadCachedFunction(mozilla::scache::StartupCache* cache, nsACString &uri,
nsresult nsresult
WriteCachedScript(mozilla::scache::StartupCache* cache, nsACString &uri, WriteCachedScript(mozilla::scache::StartupCache* cache, nsACString &uri,
JSContext *cx, nsIPrincipal *systemPrincipal, JSContext *cx, nsIPrincipal *systemPrincipal,
JSScript *script); JS::HandleScript script);
nsresult nsresult
WriteCachedFunction(mozilla::scache::StartupCache* cache, nsACString &uri, WriteCachedFunction(mozilla::scache::StartupCache* cache, nsACString &uri,
JSContext *cx, nsIPrincipal *systemPrincipal, JSContext *cx, nsIPrincipal *systemPrincipal,

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

@ -160,10 +160,10 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *targetObj
NS_IMETHODIMP NS_IMETHODIMP
mozJSSubScriptLoader::LoadSubScript(const nsAString& url, mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
const JS::Value& target, const Value& targetArg,
const nsAString& charset, const nsAString& charset,
JSContext* cx, JSContext* cx,
JS::Value* retval) Value* retval)
{ {
/* /*
* Loads a local url and evals it into the current cx * Loads a local url and evals it into the current cx
@ -199,8 +199,9 @@ mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
// We base reusingGlobal off of what the loader told us, but we may not // We base reusingGlobal off of what the loader told us, but we may not
// actually be using that object. // actually be using that object.
RootedValue target(cx, targetArg);
RootedObject passedObj(cx); RootedObject passedObj(cx);
if (!JS_ValueToObject(cx, target, passedObj.address())) if (!JS_ValueToObject(cx, target, &passedObj))
return NS_ERROR_ILLEGAL_VALUE; return NS_ERROR_ILLEGAL_VALUE;
if (passedObj) if (passedObj)
@ -235,7 +236,7 @@ mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
RootedScript script(cx); RootedScript script(cx);
// Figure out who's calling us // Figure out who's calling us
if (!JS_DescribeScriptedCaller(cx, script.address(), nullptr)) { if (!JS_DescribeScriptedCaller(cx, &script, nullptr)) {
// No scripted frame means we don't know who's calling, bail. // No scripted frame means we don't know who's calling, bail.
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -292,7 +293,7 @@ mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
RootedFunction function(cx); RootedFunction function(cx);
script = nullptr; script = nullptr;
if (cache) if (cache)
rv = ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, script.address()); rv = ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, &script);
if (!script) { if (!script) {
rv = ReadScript(uri, cx, targetObj, charset, rv = ReadScript(uri, cx, targetObj, charset,
static_cast<const char*>(uriStr.get()), serv, static_cast<const char*>(uriStr.get()), serv,

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

@ -143,7 +143,7 @@ GetLocationProperty(JSContext *cx, HandleObject obj, HandleId id, MutableHandleV
//XXX: your platform should really implement this //XXX: your platform should really implement this
return false; return false;
#else #else
JSScript *script; JS::RootedScript script(cx);
JS_DescribeScriptedCaller(cx, &script, NULL); JS_DescribeScriptedCaller(cx, &script, NULL);
const char *filename = JS_GetScriptFilename(cx, script); const char *filename = JS_GetScriptFilename(cx, script);

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

@ -147,7 +147,8 @@ SandboxImport(JSContext *cx, unsigned argc, Value *vp)
JSAutoCompartment ac(cx, funobj); JSAutoCompartment ac(cx, funobj);
JSFunction *fun = JS_ValueToFunction(cx, ObjectValue(*funobj)); RootedValue funval(cx, ObjectValue(*funobj));
JSFunction *fun = JS_ValueToFunction(cx, funval);
if (!fun) { if (!fun) {
XPCThrower::Throw(NS_ERROR_INVALID_ARG, cx); XPCThrower::Throw(NS_ERROR_INVALID_ARG, cx);
return false; return false;
@ -308,7 +309,7 @@ ExportFunction(JSContext *cx, unsigned argc, jsval *vp)
static bool static bool
GetFilenameAndLineNumber(JSContext *cx, nsACString &filename, unsigned &lineno) GetFilenameAndLineNumber(JSContext *cx, nsACString &filename, unsigned &lineno)
{ {
JSScript *script; JS::RootedScript script(cx);
if (JS_DescribeScriptedCaller(cx, &script, &lineno)) { if (JS_DescribeScriptedCaller(cx, &script, &lineno)) {
if (const char *cfilename = JS_GetScriptFilename(cx, script)) { if (const char *cfilename = JS_GetScriptFilename(cx, script)) {
filename.Assign(nsDependentCString(cfilename)); filename.Assign(nsDependentCString(cfilename));

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

@ -2697,7 +2697,7 @@ nsXPCComponents_Utils::ReportError(const JS::Value &errorArg, JSContext *cx)
/* void evalInSandbox(in AString source, in nativeobj sandbox); */ /* void evalInSandbox(in AString source, in nativeobj sandbox); */
NS_IMETHODIMP NS_IMETHODIMP
nsXPCComponents_Utils::EvalInSandbox(const nsAString& source, nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
const JS::Value& sandboxVal, const JS::Value& sandboxValArg,
const JS::Value& version, const JS::Value& version,
const JS::Value& filenameVal, const JS::Value& filenameVal,
int32_t lineNumber, int32_t lineNumber,
@ -2705,8 +2705,9 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
uint8_t optionalArgc, uint8_t optionalArgc,
JS::Value *retval) JS::Value *retval)
{ {
RootedValue sandboxVal(cx, sandboxValArg);
RootedObject sandbox(cx); RootedObject sandbox(cx);
if (!JS_ValueToObject(cx, sandboxVal, sandbox.address()) || !sandbox) if (!JS_ValueToObject(cx, sandboxVal, &sandbox) || !sandbox)
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
// Optional third argument: JS version, as a string. // Optional third argument: JS version, as a string.

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

@ -293,7 +293,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx,
} }
if (success) if (success)
success = JS_ValueToObject(cx, retval, retObj.address()); success = JS_ValueToObject(cx, retval, &retObj);
return success ? retObj.get() : nullptr; return success ? retObj.get() : nullptr;
} }
@ -978,7 +978,8 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
// Finally, check to see if this is the last JS frame on the // Finally, check to see if this is the last JS frame on the
// stack. If so then we always want to report it. // stack. If so then we always want to report it.
if (!reportable) { if (!reportable) {
reportable = !JS_DescribeScriptedCaller(cx, nullptr, nullptr); RootedScript ignored(cx);
reportable = !JS_DescribeScriptedCaller(cx, &ignored, nullptr);
} }
// Ugly special case for GetInterface. It's "special" in the // Ugly special case for GetInterface. It's "special" in the