Bug 868312: Various dom rooting fixes, part 2 r=bz

This commit is contained in:
David Zbarsky 2013-05-04 03:53:00 -04:00
parent b7033dea1a
commit cff213613e
6 changed files with 81 additions and 74 deletions

View File

@ -51,20 +51,20 @@ public:
}
static JSObject*
InitClass(JSContext* aCx, JSObject* aObj, bool aMainRuntime)
InitClass(JSContext* aCx, JS::Handle<JSObject*> aObj, bool aMainRuntime)
{
JSObject* parentProto = NULL;
JS::Rooted<JSObject*> parentProto(aCx);
if (aMainRuntime) {
jsval windowPropVal;
if (!JS_GetProperty(aCx, aObj, sClass.name, &windowPropVal)) {
JS::Rooted<JS::Value> windowPropVal(aCx);
if (!JS_GetProperty(aCx, aObj, sClass.name, windowPropVal.address())) {
return NULL;
}
if (!JSVAL_IS_PRIMITIVE(windowPropVal)) {
jsval protoVal;
JS::Rooted<JS::Value> protoVal(aCx);
if (!JS_GetProperty(aCx, JSVAL_TO_OBJECT(windowPropVal), "prototype",
&protoVal)) {
protoVal.address())) {
return NULL;
}
@ -76,9 +76,9 @@ public:
JSClass* clasp = parentProto ? &sMainRuntimeClass : &sClass;
JSObject* proto = JS_InitClass(aCx, aObj, parentProto, clasp, Construct, 0,
sProperties, sFunctions, sStaticProperties,
NULL);
JS::Rooted<JSObject*> proto(aCx, JS_InitClass(aCx, aObj, parentProto, clasp, Construct, 0,
sProperties, sFunctions, sStaticProperties,
nullptr));
if (proto && !JS_DefineProperties(aCx, proto, sStaticProperties)) {
return NULL;
}
@ -285,7 +285,7 @@ private:
static JSBool
PreventDefault(JSContext* aCx, unsigned aArgc, jsval* aVp)
{
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
if (!obj) {
return false;
}
@ -305,7 +305,7 @@ private:
static JSBool
InitEvent(JSContext* aCx, unsigned aArgc, jsval* aVp)
{
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
if (!obj) {
return false;
}
@ -315,9 +315,9 @@ private:
return false;
}
JSString* type;
JS::Rooted<JSString*> type(aCx);
JSBool bubbles, cancelable;
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "Sbb", &type,
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "Sbb", type.address(),
&bubbles, &cancelable)) {
return false;
}
@ -414,14 +414,14 @@ public:
Create(JSContext* aCx, JSObject* aParent, JSAutoStructuredCloneBuffer& aData,
nsTArray<nsCOMPtr<nsISupports> >& aClonedObjects, bool aMainRuntime)
{
JSString* type = JS_InternString(aCx, "message");
JS::Rooted<JSString*> type(aCx, JS_InternString(aCx, "message"));
if (!type) {
return NULL;
}
JSClass* clasp = aMainRuntime ? &sMainRuntimeClass : &sClass;
JSObject* obj = JS_NewObject(aCx, clasp, NULL, aParent);
JS::Rooted<JSObject*> obj(aCx, JS_NewObject(aCx, clasp, NULL, aParent));
if (!obj) {
return NULL;
}
@ -540,8 +540,8 @@ private:
nsTArray<nsCOMPtr<nsISupports> > clonedObjects;
clonedObjects.SwapElements(event->mClonedObjects);
jsval data;
if (!buffer.read(aCx, &data,
JS::Rooted<JS::Value> data(aCx);
if (!buffer.read(aCx, data.address(),
WorkerStructuredCloneCallbacks(event->mMainRuntime))) {
return false;
}
@ -558,7 +558,7 @@ private:
static JSBool
InitMessageEvent(JSContext* aCx, unsigned aArgc, jsval* aVp)
{
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
if (!obj) {
return false;
}
@ -568,11 +568,12 @@ private:
return false;
}
JSString* type, *data, *origin;
JS::Rooted<JSString*> type(aCx), data(aCx), origin(aCx);
JSBool bubbles, cancelable;
JSObject* source;
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "SbbSSo", &type,
&bubbles, &cancelable, &data, &origin, &source)) {
JS::Rooted<JSObject*> source(aCx);
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "SbbSSo", type.address(),
&bubbles, &cancelable, data.address(),
origin.address(), source.address())) {
return false;
}
@ -639,14 +640,14 @@ public:
Create(JSContext* aCx, JSObject* aParent, JSString* aMessage,
JSString* aFilename, uint32_t aLineNumber, bool aMainRuntime)
{
JSString* type = JS_InternString(aCx, "error");
JS::Rooted<JSString*> type(aCx, JS_InternString(aCx, "error"));
if (!type) {
return NULL;
}
JSClass* clasp = aMainRuntime ? &sMainRuntimeClass : &sClass;
JSObject* obj = JS_NewObject(aCx, clasp, NULL, aParent);
JS::Rooted<JSObject*> obj(aCx, JS_NewObject(aCx, clasp, NULL, aParent));
if (!obj) {
return NULL;
}
@ -743,7 +744,7 @@ private:
static JSBool
InitErrorEvent(JSContext* aCx, unsigned aArgc, jsval* aVp)
{
JSObject* obj = JS_THIS_OBJECT(aCx, aVp);
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
if (!obj) {
return false;
}
@ -753,12 +754,12 @@ private:
return false;
}
JSString* type, *message, *filename;
JS::Rooted<JSString*> type(aCx), message(aCx), filename(aCx);
JSBool bubbles, cancelable;
uint32_t lineNumber;
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "SbbSSu", &type,
&bubbles, &cancelable, &message, &filename,
&lineNumber)) {
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "SbbSSu", type.address(),
&bubbles, &cancelable, message.address(),
filename.address(), &lineNumber)) {
return false;
}
@ -820,12 +821,12 @@ public:
Create(JSContext* aCx, JSObject* aParent, JSString* aType,
bool aLengthComputable, double aLoaded, double aTotal)
{
JSString* type = JS_InternJSString(aCx, aType);
JS::Rooted<JSString*> type(aCx, JS_InternJSString(aCx, aType));
if (!type) {
return NULL;
}
JSObject* obj = JS_NewObject(aCx, &sClass, NULL, aParent);
JS::Rooted<JSObject*> obj(aCx, JS_NewObject(aCx, &sClass, NULL, aParent));
if (!obj) {
return NULL;
}
@ -933,10 +934,10 @@ private:
return false;
}
JSString* type;
JS::Rooted<JSString*> type(aCx);
JSBool bubbles, cancelable, lengthComputable;
double loaded, total;
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "Sbbbdd", &type,
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "Sbbbdd", type.address(),
&bubbles, &cancelable, &lengthComputable, &loaded,
&total)) {
return false;
@ -992,9 +993,9 @@ BEGIN_WORKERS_NAMESPACE
namespace events {
bool
InitClasses(JSContext* aCx, JSObject* aGlobal, bool aMainRuntime)
InitClasses(JSContext* aCx, JS::Handle<JSObject*> aGlobal, bool aMainRuntime)
{
JSObject* eventProto = Event::InitClass(aCx, aGlobal, aMainRuntime);
JS::Rooted<JSObject*> eventProto(aCx, Event::InitClass(aCx, aGlobal, aMainRuntime));
if (!eventProto) {
return false;
}
@ -1076,9 +1077,9 @@ DispatchEventToTarget(JSContext* aCx, JSObject* aTarget, JSObject* aEvent,
JSBool preventDefaultCalled = false;
if (hasProperty) {
jsval argv[] = { OBJECT_TO_JSVAL(aEvent) };
jsval rval = JSVAL_VOID;
JS::Rooted<JS::Value> rval(aCx, JS::UndefinedValue());
if (!JS_CallFunctionName(aCx, aTarget, kFunctionName, ArrayLength(argv),
argv, &rval) ||
argv, rval.address()) ||
!JS_ValueToBoolean(aCx, rval, &preventDefaultCalled)) {
return false;
}

View File

@ -15,7 +15,7 @@ BEGIN_WORKERS_NAMESPACE
namespace events {
bool
InitClasses(JSContext* aCx, JSObject* aGlobal, bool aMainRuntime);
InitClasses(JSContext* aCx, JS::Handle<JSObject*> aGlobal, bool aMainRuntime);
JSObject*
CreateGenericEvent(JSContext* aCx, JSString* aType, bool aBubbles,

View File

@ -112,7 +112,7 @@ protected:
return false;
}
JSString* scriptURL = JS_ValueToString(aCx, JS_ARGV(aCx, aVp)[0]);
JS::Rooted<JSString*> scriptURL(aCx, JS_ValueToString(aCx, JS_ARGV(aCx, aVp)[0]));
if (!scriptURL) {
return false;
}
@ -137,7 +137,7 @@ protected:
parent->AssertIsOnWorkerThread();
}
JSObject* obj = JS_NewObject(aCx, aClass, nullptr, nullptr);
JS::Rooted<JSObject*> obj(aCx, JS_NewObject(aCx, aClass, nullptr, nullptr));
if (!obj) {
return false;
}
@ -285,10 +285,10 @@ private:
return !JS_IsExceptionPending(aCx);
}
jsval message;
jsval transferable = JSVAL_VOID;
JS::Rooted<JS::Value> message(aCx);
JS::Rooted<JS::Value> transferable(aCx, JS::UndefinedValue());
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v/v",
&message, &transferable)) {
message.address(), transferable.address())) {
return false;
}

View File

@ -195,9 +195,9 @@ struct WorkerStructuredCloneCallbacks
// Read the information out of the stream.
uint32_t width, height;
JS::Value dataArray;
JS::Rooted<JS::Value> dataArray(aCx);
if (!JS_ReadUint32Pair(aReader, &width, &height) ||
!JS_ReadTypedArray(aReader, &dataArray))
!JS_ReadTypedArray(aReader, dataArray.address()))
{
return nullptr;
}
@ -697,7 +697,7 @@ public:
bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
{
JSObject* global = CreateDedicatedWorkerGlobalScope(aCx);
JS::Rooted<JSObject*> global(aCx, CreateDedicatedWorkerGlobalScope(aCx));
if (!global) {
NS_WARNING("Failed to make global!");
return false;
@ -721,7 +721,7 @@ public:
bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
{
JSObject* target = JS_GetGlobalObject(aCx);
JS::Rooted<JSObject*> target(aCx, JS_GetGlobalObject(aCx));
NS_ASSERTION(target, "This must never be null!");
aWorkerPrivate->CloseHandlerStarted();
@ -785,7 +785,7 @@ public:
mDataByteCount = 0;
bool mainRuntime;
JSObject* target;
JS::Rooted<JSObject*> target(aCx);
if (mTarget == ParentThread) {
// Don't fire this event if the JS object has been disconnected from the
// private object.
@ -946,7 +946,7 @@ public:
return true;
}
JSObject* target = aWorkerPrivate->GetJSObject();
JS::Rooted<JSObject*> target(aCx, aWorkerPrivate->GetJSObject());
uint64_t innerWindowId;
@ -994,14 +994,14 @@ public:
AssertIsOnMainThread();
}
JSString* message = JS_NewUCStringCopyN(aCx, aMessage.get(),
aMessage.Length());
JS::Rooted<JSString*> message(aCx, JS_NewUCStringCopyN(aCx, aMessage.get(),
aMessage.Length()));
if (!message) {
return false;
}
JSString* filename = JS_NewUCStringCopyN(aCx, aFilename.get(),
aFilename.Length());
JS::Rooted<JSString*> filename(aCx, JS_NewUCStringCopyN(aCx, aFilename.get(),
aFilename.Length()));
if (!filename) {
return false;
}
@ -1602,20 +1602,16 @@ NS_IMETHODIMP
WorkerRunnable::Run()
{
JSContext* cx;
JSObject* targetCompartmentObject;
nsCxPusher pusher;
nsRefPtr<WorkerPrivate> kungFuDeathGrip;
nsCxPusher pusher;
if (mTarget == WorkerThread) {
mWorkerPrivate->AssertIsOnWorkerThread();
cx = mWorkerPrivate->GetJSContext();
targetCompartmentObject = JS_GetGlobalObject(cx);
} else {
kungFuDeathGrip = mWorkerPrivate;
mWorkerPrivate->AssertIsOnParentThread();
cx = mWorkerPrivate->ParentJSContext();
targetCompartmentObject = mWorkerPrivate->GetJSObject();
if (!mWorkerPrivate->GetParent()) {
AssertIsOnMainThread();
@ -1623,6 +1619,14 @@ WorkerRunnable::Run()
}
}
JS::Rooted<JSObject*> targetCompartmentObject(cx);
if (mTarget == WorkerThread) {
targetCompartmentObject = JS_GetGlobalObject(cx);
} else {
targetCompartmentObject = mWorkerPrivate->GetJSObject();
}
NS_ASSERTION(cx, "Must have a context!");
JSAutoRequest ar(cx);
@ -2147,8 +2151,8 @@ WorkerPrivateParent<Derived>::ForgetMainThreadObjects(
template <class Derived>
bool
WorkerPrivateParent<Derived>::PostMessage(JSContext* aCx,
JS::Value aMessage,
JS::Value aTransferable)
JS::Handle<JS::Value> aMessage,
JS::Handle<JS::Value> aTransferable)
{
AssertIsOnParentThread();
@ -2413,8 +2417,8 @@ WorkerPrivate::~WorkerPrivate()
// static
already_AddRefed<WorkerPrivate>
WorkerPrivate::Create(JSContext* aCx, JSObject* aObj, WorkerPrivate* aParent,
JSString* aScriptURL, bool aIsChromeWorker)
WorkerPrivate::Create(JSContext* aCx, JS::Handle<JSObject*> aObj, WorkerPrivate* aParent,
JS::Handle<JSString*> aScriptURL, bool aIsChromeWorker)
{
nsCString domain;
nsCOMPtr<nsIURI> baseURI;
@ -3519,8 +3523,9 @@ WorkerPrivate::DestroySyncLoop(uint32_t aSyncLoopKey)
}
bool
WorkerPrivate::PostMessageToParent(JSContext* aCx, jsval aMessage,
jsval aTransferable)
WorkerPrivate::PostMessageToParent(JSContext* aCx,
JS::Handle<JS::Value> aMessage,
JS::Handle<JS::Value> aTransferable)
{
AssertIsOnWorkerThread();
@ -3967,10 +3972,10 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
}
}
else {
jsval rval;
JS::Rooted<JS::Value> rval(aCx);
if (!JS_CallFunctionValue(aCx, global, info->mTimeoutVal,
info->mExtraArgVals.Length(),
info->mExtraArgVals.Elements(), &rval) &&
info->mExtraArgVals.Elements(), rval.address()) &&
!JS_ReportPendingException(aCx)) {
retval = false;
break;

View File

@ -383,7 +383,8 @@ public:
ForgetMainThreadObjects(nsTArray<nsCOMPtr<nsISupports> >& aDoomed);
bool
PostMessage(JSContext* aCx, JS::Value aMessage, JS::Value aTransferable);
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
JS::Handle<JS::Value> aTransferable);
uint64_t
GetInnerWindowId();
@ -692,8 +693,8 @@ public:
~WorkerPrivate();
static already_AddRefed<WorkerPrivate>
Create(JSContext* aCx, JSObject* aObj, WorkerPrivate* aParent,
JSString* aScriptURL, bool aIsChromeWorker);
Create(JSContext* aCx, JS::Handle<JSObject*> aObj, WorkerPrivate* aParent,
JS::Handle<JSString*> aScriptURL, bool aIsChromeWorker);
void
DoRunLoop(JSContext* aCx);
@ -777,8 +778,8 @@ public:
DestroySyncLoop(uint32_t aSyncLoopKey);
bool
PostMessageToParent(JSContext* aCx, jsval aMessage,
jsval transferable);
PostMessageToParent(JSContext* aCx, JS::Handle<JS::Value> aMessage,
JS::Handle<JS::Value> transferable);
bool
NotifyInternal(JSContext* aCx, Status aStatus);

View File

@ -860,10 +860,10 @@ private:
return false;
}
jsval message;
jsval transferable = JSVAL_VOID;
JS::Rooted<JS::Value> message(aCx);
JS::Rooted<JS::Value> transferable(aCx, JSVAL_VOID);
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "v/v",
&message, &transferable)) {
message.address(), transferable.address())) {
return false;
}