Bug 868312: Root nsDOMClassInfo.cpp, part 2 r=bz
authorDavid Zbarsky <dzbarsky@gmail.com>
Sat, 04 May 2013 03:51:53 -0400
changeset 141772 ae645c508e70ce88f86bed771a14563aad59938d
parent 141771 deea5f24e17a41ad498e1e5502d71ecb51c96413
child 141773 059b2743e8d7e955936f8c440991c8c152e7356e
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs868312
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 868312: Root nsDOMClassInfo.cpp, part 2 r=bz
content/html/document/src/nsHTMLDocument.cpp
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfo.h
dom/base/nsGlobalWindow.cpp
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -2355,17 +2355,18 @@ nsHTMLDocument::NamedGetter(JSContext* c
                             ErrorResult& rv)
 {
   nsWrapperCache* cache;
   nsISupports* supp = ResolveName(aName, &cache);
   if (!supp) {
     aFound = false;
     if (GetCompatibilityMode() == eCompatibility_NavQuirks &&
         aName.EqualsLiteral("all")) {
-      rv = nsHTMLDocumentSH::TryResolveAll(cx, this, GetWrapper());
+      JS::Rooted<JSObject*> obj(cx, GetWrapper());
+      rv = nsHTMLDocumentSH::TryResolveAll(cx, this, obj);
     }
     return nullptr;
   }
 
   JS::Rooted<JS::Value> val(cx);
   { // Scope for auto-compartment
     JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
     JSAutoCompartment ac(cx, wrapper);
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -2405,17 +2405,17 @@ nsDOMClassInfo::Init()
 
   sIsInitialized = true;
 
   return NS_OK;
 }
 
 // static
 int32_t
-nsDOMClassInfo::GetArrayIndexFromId(JSContext *cx, jsid id, bool *aIsNumber)
+nsDOMClassInfo::GetArrayIndexFromId(JSContext *cx, JS::Handle<jsid> id, bool *aIsNumber)
 {
   if (aIsNumber) {
     *aIsNumber = false;
   }
 
   int i;
   if (JSID_IS_INT(id)) {
       i = JSID_TO_INT(id);
@@ -2650,19 +2650,20 @@ nsDOMClassInfo::NewEnumerate(nsIXPConnec
                              jsval *statep, jsid *idp, bool *_retval)
 {
   NS_WARNING("nsDOMClassInfo::NewEnumerate Don't call me!");
 
   return NS_ERROR_UNEXPECTED;
 }
 
 nsresult
-nsDOMClassInfo::ResolveConstructor(JSContext *cx, JSObject *obj,
+nsDOMClassInfo::ResolveConstructor(JSContext *cx, JSObject *aObj,
                                    JSObject **objp)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
   JS::Rooted<JSObject*> global(cx, ::JS_GetGlobalForObject(cx, obj));
 
   JS::Rooted<JS::Value> val(cx);
   JSAutoRequest ar(cx);
   if (!::JS_LookupProperty(cx, global, mData->mName, val.address())) {
     return NS_ERROR_UNEXPECTED;
   }
 
@@ -2719,19 +2720,20 @@ nsDOMClassInfo::Finalize(nsIXPConnectWra
 {
   NS_WARNING("nsDOMClassInfo::Finalize Don't call me!");
 
   return NS_ERROR_UNEXPECTED;
 }
 
 NS_IMETHODIMP
 nsDOMClassInfo::CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                            JSObject *obj, jsid id, uint32_t mode,
+                            JSObject *obj, jsid aId, uint32_t mode,
                             jsval *vp, bool *_retval)
 {
+  JS::Rooted<jsid> id(cx, aId);
   uint32_t mode_type = mode & JSACC_TYPEMASK;
 
   if ((mode_type == JSACC_WATCH || mode_type == JSACC_PROTO) && sSecMan) {
     nsresult rv;
     JS::Rooted<JSObject*> real_obj(cx);
     if (wrapper) {
       rv = wrapper->GetJSObject(real_obj.address());
       NS_ENSURE_SUCCESS(rv, rv);
@@ -2824,17 +2826,17 @@ GetExternalClassInfo(nsScriptNameSpaceMa
   }
 
   return NS_OK;
 }
 
 
 static nsresult
 ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
-                 JSObject *obj, const PRUnichar *name,
+                 JS::Handle<JSObject*> obj, const PRUnichar *name,
                  const nsDOMClassInfoData *ci_data,
                  const nsGlobalNameStruct *name_struct,
                  nsScriptNameSpaceManager *nameSpaceManager,
                  JSObject *dot_prototype, bool install, bool *did_resolve);
 
 
 NS_IMETHODIMP
 nsDOMClassInfo::PostCreatePrototype(JSContext * cx, JSObject * aProto)
@@ -3250,19 +3252,21 @@ nsWindowSH::GlobalScopePolluterNewResolv
     objp.set(obj);
   }
 
   return JS_TRUE;
 }
 
 // static
 JSBool
-nsWindowSH::InvalidateGlobalScopePolluter(JSContext *cx, JSObject *obj)
+nsWindowSH::InvalidateGlobalScopePolluter(JSContext *cx,
+                                          JS::Handle<JSObject*> aObj)
 {
   JS::Rooted<JSObject*> proto(cx);
+  JS::Rooted<JSObject*> obj(cx, aObj);
 
   JSAutoRequest ar(cx);
 
   for (;;) {
     if (!::JS_GetPrototype(cx, obj, proto.address())) {
       return JS_FALSE;
     }
     if (!proto) {
@@ -3746,27 +3750,29 @@ public:
                          nsDOMConstructor** aResult);
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMDOMCONSTRUCTOR
 
   nsresult PreCreate(JSContext *cx, JSObject *globalObj, JSObject **parentObj);
 
   nsresult Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                     JSObject *obj, uint32_t argc, jsval *argv,
+                     JS::Handle<JSObject*> obj, uint32_t argc, jsval *argv,
                      jsval *vp, bool *_retval);
 
   nsresult HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                       JSObject *obj, const jsval &val, bool *bp,
+                       JS::Handle<JSObject*> obj, const jsval &val, bool *bp,
                        bool *_retval);
 
-  nsresult Install(JSContext *cx, JSObject *target, jsval thisAsVal)
+  nsresult Install(JSContext *cx, JS::Handle<JSObject*> target,
+                   JS::Handle<JS::Value> aThisAsVal)
   {
+    JS::Rooted<JS::Value> thisAsVal(cx, aThisAsVal);
     // The 'attrs' argument used to be JSPROP_PERMANENT. See bug 628612.
-    JSBool ok = JS_WrapValue(cx, &thisAsVal) &&
+    JSBool ok = JS_WrapValue(cx, thisAsVal.address()) &&
       ::JS_DefineUCProperty(cx, target,
                             reinterpret_cast<const jschar *>(mClassName),
                             NS_strlen(mClassName), thisAsVal, JS_PropertyStub,
                             JS_StrictPropertyStub, 0);
 
     return ok ? NS_OK : NS_ERROR_UNEXPECTED;
   }
 
@@ -3904,17 +3910,17 @@ nsDOMConstructor::PreCreate(JSContext *c
   }
 
   nsGlobalWindow *win = static_cast<nsGlobalWindow *>(owner.get());
   return SetParentToWindow(win, parentObj);
 }
 
 nsresult
 nsDOMConstructor::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
-                            JSObject * obj, uint32_t argc, jsval * argv,
+                            JS::Handle<JSObject*> obj, uint32_t argc, jsval * argv,
                             jsval * vp, bool *_retval)
 {
   MOZ_ASSERT(obj);
 
   const nsGlobalNameStruct *name_struct = GetNameStruct();
   NS_ENSURE_TRUE(name_struct, NS_ERROR_FAILURE);
 
   if (!IsConstructable(name_struct)) {
@@ -3922,17 +3928,17 @@ nsDOMConstructor::Construct(nsIXPConnect
     return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
   }
 
   return BaseStubConstructor(mWeakOwner, name_struct, cx, obj, argc, argv, vp);
 }
 
 nsresult
 nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper,
-                              JSContext * cx, JSObject * obj,
+                              JSContext * cx, JS::Handle<JSObject*> obj,
                               const jsval &v, bool *bp, bool *_retval)
 
 {
   // No need to look these up in the hash.
   *bp = false;
   if (JSVAL_IS_PRIMITIVE(v)) {
     return NS_OK;
   }
@@ -4200,22 +4206,23 @@ GetXPCProto(nsIXPConnect *aXPConnect, JS
   NS_IF_RELEASE(*aProto);
   return aXPConnect->HoldObject(cx, proto_obj, aProto);
 }
 
 // Either ci_data must be non-null or name_struct must be non-null and of type
 // eTypeClassProto.
 static nsresult
 ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
-                 JSObject *obj, const PRUnichar *name,
+                 JS::Handle<JSObject*> obj, const PRUnichar *name,
                  const nsDOMClassInfoData *ci_data,
                  const nsGlobalNameStruct *name_struct,
                  nsScriptNameSpaceManager *nameSpaceManager,
-                 JSObject *dot_prototype, bool install, bool *did_resolve)
-{
+                 JSObject* aDot_prototype, bool install, bool *did_resolve)
+{
+  JS::Rooted<JSObject*> dot_prototype(cx, aDot_prototype);
   NS_ASSERTION(ci_data ||
                (name_struct &&
                 name_struct->mType == nsGlobalNameStruct::eTypeClassProto),
                "Wrong type or missing ci_data!");
 
   nsRefPtr<nsDOMConstructor> constructor;
   nsresult rv = nsDOMConstructor::Create(name, ci_data, name_struct, aWin,
                                          getter_AddRefs(constructor));
@@ -4400,17 +4407,18 @@ ConstructorEnabled(const nsGlobalNameStr
   }
 
   return true;
 }
 
 // static
 nsresult
 nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
-                          JSObject *obj, JS::Handle<jsid> id, bool *did_resolve)
+                          JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
+                          bool *did_resolve)
 {
   *did_resolve = false;
 
   nsScriptNameSpaceManager *nameSpaceManager =
     nsJSRuntime::GetNameSpaceManager();
   NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
 
   nsDependentJSString name(id);
@@ -5035,30 +5043,30 @@ nsWindowSH::NewResolve(nsIXPConnectWrapp
   if (s_content_id == id) {
     // Map window._content to window.content for backwards
     // compatibility, this should spit out an message on the JS
     // console.
 
     JS::Rooted<JSObject*> windowObj(cx, js::CheckedUnwrap(obj, /* stopAtOuter = */ false));
     NS_ENSURE_TRUE(windowObj, NS_ERROR_DOM_SECURITY_ERR);
 
-    JSObject* funObj = nullptr;
+    JS::Rooted<JSObject*> funObj(cx);
     {
       JSAutoCompartment ac(cx, windowObj);
       JSFunction *fun = ::JS_NewFunction(cx, ContentWindowGetter, 0, 0,
                                          windowObj, "_content");
       if (!fun) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
       funObj = ::JS_GetFunctionObject(fun);
     }
 
-    if (!JS_WrapObject(cx, &funObj) ||
+    if (!JS_WrapObject(cx, funObj.address()) ||
         !JS_DefinePropertyById(cx, obj, id, JSVAL_VOID,
-                               JS_DATA_TO_FUNC_PTR(JSPropertyOp, funObj),
+                               JS_DATA_TO_FUNC_PTR(JSPropertyOp, funObj.get()),
                                JS_StrictPropertyStub,
                                JSPROP_ENUMERATE | JSPROP_GETTER |
                                JSPROP_SHARED)) {
       return NS_ERROR_FAILURE;
     }
 
     *objp = obj;
 
@@ -5333,19 +5341,21 @@ nsLocationSH::AddProperty(nsIXPConnectWr
 
   return NS_OK;
 }
 
 // DOM Navigator helper
 
 NS_IMETHODIMP
 nsNavigatorSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                          JSObject *obj, jsid id, uint32_t flags,
+                          JSObject *aObj, jsid aId, uint32_t flags,
                           JSObject **objp, bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   if (!JSID_IS_STRING(id)) {
     return NS_OK;
   }
 
   nsScriptNameSpaceManager *nameSpaceManager =
     nsJSRuntime::GetNameSpaceManager();
   NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED);
 
@@ -5608,18 +5618,19 @@ nsNodeSH::PreserveWrapper(nsISupports *a
   nsINode *node = static_cast<nsINode*>(aNative);
   nsContentUtils::PreserveWrapper(aNative, node);
 }
 
 // EventTarget helper
 
 NS_IMETHODIMP
 nsEventTargetSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
-                           JSObject *globalObj, JSObject **parentObj)
-{
+                           JSObject *aGlobalObj, JSObject **parentObj)
+{
+  JS::Rooted<JSObject*> globalObj(cx, aGlobalObj);
   nsDOMEventTargetHelper *target =
     nsDOMEventTargetHelper::FromSupports(nativeObj);
 
   nsCOMPtr<nsIScriptGlobalObject> native_parent;
   target->GetParentObject(getter_AddRefs(native_parent));
 
   *parentObj = native_parent ? native_parent->GetGlobalJSObject() : globalObj;
 
@@ -5644,23 +5655,24 @@ nsEventTargetSH::PreserveWrapper(nsISupp
 }
 
 // Event helper
 
 NS_IMETHODIMP
 nsEventSH::PreCreate(nsISupports* aNativeObj, JSContext* aCx,
                      JSObject* aGlobalObj, JSObject** aParentObj)
 {
+  JS::Rooted<JSObject*> globalObj(aCx, aGlobalObj);
   nsDOMEvent* event =
     nsDOMEvent::FromSupports(aNativeObj);
 
   nsCOMPtr<nsIScriptGlobalObject> native_parent;
   event->GetParentObject(getter_AddRefs(native_parent));
 
-  *aParentObj = native_parent ? native_parent->GetGlobalJSObject() : aGlobalObj;
+  *aParentObj = native_parent ? native_parent->GetGlobalJSObject() : globalObj;
 
   return *aParentObj ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsEventSH::AddProperty(nsIXPConnectWrappedNative* aWrapper, JSContext* aCx,
                        JSObject* aObj, jsid Id, jsval* aVp, bool* aRetval)
 {
@@ -5677,19 +5689,20 @@ nsEventSH::PreserveWrapper(nsISupports* 
 }
 
 // IDBEventTarget helper
 
 NS_IMETHODIMP
 IDBEventTargetSH::PreCreate(nsISupports *aNativeObj, JSContext *aCx,
                             JSObject *aGlobalObj, JSObject **aParentObj)
 {
+  JS::Rooted<JSObject*> globalObj(aCx, aGlobalObj);
   IDBWrapperCache *target = IDBWrapperCache::FromSupports(aNativeObj);
   JSObject *parent = target->GetParentObject();
-  *aParentObj = parent ? parent : aGlobalObj;
+  *aParentObj = parent ? parent : globalObj;
   return NS_OK;
 }
 
 // Element helper
 
 NS_IMETHODIMP
 nsElementSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
                        JSObject *globalObj, JSObject **parentObj)
@@ -5832,19 +5845,21 @@ nsElementSH::PostTransplant(nsIXPConnect
   return NS_OK;
 }
 
 
 // Generic array scriptable helper.
 
 NS_IMETHODIMP
 nsGenericArraySH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                             JSObject *obj, jsid id, uint32_t flags,
+                             JSObject *aObj, jsid aId, uint32_t flags,
                              JSObject **objp, bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   if (id == sLength_id) {
     // Bail early; this isn't something we're interested in
     return NS_OK;
   }
 
   bool is_number = false;
   int32_t n = GetArrayIndexFromId(cx, id, &is_number);
 
@@ -5893,22 +5908,23 @@ nsGenericArraySH::GetLength(nsIXPConnect
 
   *length = (uint32_t)slen;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGenericArraySH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                            JSObject *obj, bool *_retval)
+                            JSObject *aObj, bool *_retval)
 {
   // Recursion protection in case someone tries to be smart and call
   // the enumerate hook from a user defined .length getter, or
   // somesuch.
 
+  JS::Rooted<JSObject*> obj(cx, aObj);
   static bool sCurrentlyEnumerating;
 
   if (sCurrentlyEnumerating) {
     // Don't recurse to death.
     return NS_OK;
   }
 
   sCurrentlyEnumerating = true;
@@ -5930,18 +5946,20 @@ nsGenericArraySH::Enumerate(nsIXPConnect
 
   return ok ? NS_OK : NS_ERROR_UNEXPECTED;
 }
 
 // Array scriptable helper
 
 NS_IMETHODIMP
 nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                       JSObject *obj, jsid id, jsval *vp, bool *_retval)
-{
+                       JSObject *aObj, jsid aId, jsval *vp, bool *_retval)
+{
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   bool is_number = false;
   int32_t n = GetArrayIndexFromId(cx, id, &is_number);
 
   nsresult rv = NS_OK;
 
   if (is_number) {
     if (n < 0) {
       return NS_ERROR_DOM_INDEX_SIZE_ERR;
@@ -5988,34 +6006,36 @@ nsStringListSH::GetStringAt(nsISupports 
   return rv;
 }
 
 
 // Named Array helper
 
 NS_IMETHODIMP
 nsNamedArraySH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                           JSObject *obj, jsid id, uint32_t flags,
+                           JSObject *aObj, jsid aId, uint32_t flags,
                            JSObject **objp, bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   if ((!(JSRESOLVE_ASSIGNING & flags)) && JSID_IS_STRING(id) &&
       !ObjectIsNativeWrapper(cx, obj)) {
 
     {
       JS::Rooted<JSObject*> realObj(cx);
 
       if (wrapper) {
         wrapper->GetJSObject(realObj.address());
       } else {
         realObj = obj;
       }
 
       JSAutoCompartment ac(cx, realObj);
-      JSObject *proto;
-      if (!::JS_GetPrototype(cx, realObj, &proto)) {
+      JS::Rooted<JSObject*> proto(cx);
+      if (!::JS_GetPrototype(cx, realObj, proto.address())) {
         return NS_ERROR_FAILURE;
       }
 
       if (proto) {
         JSBool hasProp;
         if (!::JS_HasPropertyById(cx, proto, id, &hasProp)) {
           *_retval = false;
           return NS_ERROR_FAILURE;
@@ -6048,19 +6068,21 @@ nsNamedArraySH::NewResolve(nsIXPConnectW
     }
   }
 
   return nsArraySH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
 }
 
 NS_IMETHODIMP
 nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                            JSObject *obj, jsid id, jsval *vp,
+                            JSObject *aObj, jsid aId, jsval *vp,
                             bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   if (JSID_IS_STRING(id) && !ObjectIsNativeWrapper(cx, obj)) {
     nsresult rv = NS_OK;
     nsWrapperCache *cache = nullptr;
     nsISupports* item = GetNamedItem(GetNative(wrapper, obj),
                                      nsDependentJSString(id), &cache, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (item) {
@@ -6076,19 +6098,21 @@ nsNamedArraySH::GetProperty(nsIXPConnect
   }
 
   return nsArraySH::GetProperty(wrapper, cx, obj, id, vp, _retval);
 }
 
 
 NS_IMETHODIMP
 nsDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj, jsid id, uint32_t flags,
+                         JSObject *aObj, jsid aId, uint32_t flags,
                          JSObject **objp, bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   nsresult rv;
 
   if (id == sLocation_id) {
     // Define the location property on the document object itself so
     // that we can intercept getting and setting of document.location.
 
     nsCOMPtr<nsIDOMDocument> doc = do_QueryWrappedNative(wrapper, obj);
     NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
@@ -6126,18 +6150,19 @@ nsDocumentSH::GetFlags(uint32_t* aFlags)
 {
   *aFlags = DOMCLASSINFO_STANDARD_FLAGS;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocumentSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj)
-{
+                         JSObject *aObj)
+{
+  JS::Rooted<JSObject*> obj(cx, aObj);
   // If this is the current document for the window that's the script global
   // object of this document, then define this document object on the window.
   // That will make sure that the document is referenced (via window.document)
   // and prevent it from going away in GC.
   nsCOMPtr<nsIDocument> doc = do_QueryWrappedNative(wrapper);
   if (!doc) {
     return NS_ERROR_UNEXPECTED;
   }
@@ -6246,17 +6271,18 @@ static JSClass sHTMLDocumentAllTagsClass
   JS_ConvertStub,
   nsHTMLDocumentSH::ReleaseDocument,
   nullptr,                                                  /* checkAccess */
   nsHTMLDocumentSH::CallToGetPropMapper
 };
 
 // static
 JSBool
-nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
+nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx,
+                                         JS::Handle<JSObject*> obj,
                                          nsDocument *domdoc,
                                          nsContentList **nodeList)
 {
   // The document.all object is a mix of the node list returned by
   // document.getElementsByTagName("*") and a map of elements in the
   // document exposed by their id and/or name. To make access to the
   // node list part (i.e. access to elements by index) not walk the
   // document each time, we create a nsContentList and hold on to it
@@ -6522,20 +6548,21 @@ nsHTMLDocumentSH::CallToGetPropMapper(JS
     return JS_FALSE;
   }
 
   return ::JS_GetUCProperty(cx, self, chars, length, vp);
 }
 
 
 static inline bool
-GetDocumentAllHelper(JSContext *cx, JSObject *obj, JSObject **result)
-{
+GetDocumentAllHelper(JSContext *cx, JS::Handle<JSObject*> aObj, JSObject **result)
+{
+  JS::Rooted<JSObject*> obj(cx, aObj);
   while (obj && JS_GetClass(obj) != &sHTMLDocumentAllHelperClass) {
-    if (!::JS_GetPrototype(cx, obj, &obj)) {
+    if (!::JS_GetPrototype(cx, obj, obj.address())) {
       return false;
     }
   }
 
   *result = obj;
   return true;
 }
 
@@ -6647,29 +6674,29 @@ nsHTMLDocumentSH::DocumentAllTagsNewReso
     }
   }
 
   return JS_TRUE;
 }
 
 
 static nsresult
-ResolveAll(JSContext* cx, nsIDocument* doc, JSObject* obj)
-{
-  JSObject *proto;
-  if (!::JS_GetPrototype(cx, obj, &proto)) {
+ResolveAll(JSContext* cx, nsIDocument* doc, JS::Handle<JSObject*> obj)
+{
+  JS::Rooted<JSObject*> proto(cx);
+  if (!::JS_GetPrototype(cx, obj, proto.address())) {
     return NS_ERROR_FAILURE;
   }
 
-  JSObject *helper;
-  if (!GetDocumentAllHelper(cx, proto, &helper)) {
+  JS::Rooted<JSObject*> helper(cx);
+  if (!GetDocumentAllHelper(cx, proto, helper.address())) {
     return NS_ERROR_FAILURE;
   }
 
-  if (!::JS_GetPrototype(cx, helper ? helper : obj, &proto)) {
+  if (!::JS_GetPrototype(cx, helper ? helper : obj, proto.address())) {
     return NS_ERROR_FAILURE;
   }
 
   // Check if the property all is defined on obj's (or helper's
   // if obj doesn't exist) prototype, if it is, don't expose our
   // document.all helper.
 
   JSBool hasAll = JS_FALSE;
@@ -6694,17 +6721,17 @@ ResolveAll(JSContext* cx, nsIDocument* d
   }
 
   // If we don't already have a helper and "all" isn't already defined on
   // our prototype, create a helper.
   if (!helper && !hasAll) {
     // Print a warning so developers can stop using document.all
     PrintWarningOnConsole(cx, "DocumentAllUsed");
 
-    if (!::JS_GetPrototype(cx, obj, &proto)) {
+    if (!::JS_GetPrototype(cx, obj, proto.address())) {
       return NS_ERROR_UNEXPECTED;
     }
     helper = ::JS_NewObject(cx, &sHTMLDocumentAllHelperClass,
                             proto,
                             ::JS_GetGlobalForObject(cx, obj));
 
     if (!helper) {
       return NS_ERROR_OUT_OF_MEMORY;
@@ -6718,30 +6745,32 @@ ResolveAll(JSContext* cx, nsIDocument* d
     }
   }
 
   return NS_OK;
 }
 
 nsresult
 nsHTMLDocumentSH::TryResolveAll(JSContext* cx, nsHTMLDocument* doc,
-                                JSObject* obj)
+                                JS::Handle<JSObject*> obj)
 {
   if (sDisableDocumentAllSupport) {
     return NS_OK;
   }
   JSAutoCompartment ac(cx, obj);
   return ResolveAll(cx, doc, obj);
 }
 
 NS_IMETHODIMP
 nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                             JSObject *obj, jsid id, uint32_t flags,
+                             JSObject *aObj, jsid aId, uint32_t flags,
                              JSObject **objp, bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   // nsDocumentSH::NewResolve() does a security check that we'd kinda
   // want to do here too before doing anything else. But given that we
   // only define dynamic properties here before the call to
   // nsDocumentSH::NewResolve() we're ok, since once those properties
   // are accessed, we'll do the necessary security check.
 
   if (!(flags & JSRESOLVE_ASSIGNING)) {
     // For native wrappers, do not resolve random names on document
@@ -6802,21 +6831,22 @@ nsHTMLDocumentSH::GetProperty(nsIXPConne
 
   return NS_OK;
 }
 
 // HTMLFormElement helper
 
 NS_IMETHODIMP
 nsHTMLFormElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
-                                JSContext *cx, JSObject *aObj, jsid id,
+                                JSContext *cx, JSObject *aObj, jsid aId,
                                 uint32_t flags, JSObject **objp,
                                 bool *_retval)
 {
   JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   // For native wrappers, do not resolve random names on form
   if ((!(JSRESOLVE_ASSIGNING & flags)) && JSID_IS_STRING(id) &&
       (!ObjectIsNativeWrapper(cx, obj) ||
        xpc::WrapperFactory::XrayWrapperNotShadowing(obj, id))) {
     nsCOMPtr<nsIForm> form(do_QueryWrappedNative(wrapper, obj));
 
     nsDependentJSString name(id);
     nsWrapperCache* cache;
@@ -6835,19 +6865,21 @@ nsHTMLFormElementSH::NewResolve(nsIXPCon
   }
 
   return nsElementSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
 }
 
 
 NS_IMETHODIMP
 nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
-                                 JSContext *cx, JSObject *obj, jsid id,
+                                 JSContext *cx, JSObject *aObj, jsid aId,
                                  jsval *vp, bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   nsCOMPtr<nsIForm> form(do_QueryWrappedNative(wrapper, obj));
 
   if (JSID_IS_STRING(id)) {
     // For native wrappers, do not get random names on form
     nsDependentJSString name(id);
     nsWrapperCache* cache;
     nsCOMPtr<nsISupports> result =
       static_cast<nsHTMLFormElement*>(form.get())->FindNamedItem(name, &cache);
@@ -7016,19 +7048,21 @@ nsMimeTypeArraySH::GetNamedItem(nsISuppo
   return array->GetNamedItem(aName, aResult);
 }
 
 
 // StringArray helper
 
 NS_IMETHODIMP
 nsStringArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                             JSObject *obj, jsid id, jsval *vp,
+                             JSObject *aObj, jsid aId, jsval *vp,
                              bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   bool is_number = false;
   int32_t n = GetArrayIndexFromId(cx, id, &is_number);
 
   if (!is_number) {
     return NS_OK;
   }
 
   nsAutoString val;
@@ -7063,18 +7097,20 @@ nsHistorySH::PreCreate(nsISupports *nati
     return NS_ERROR_FAILURE;
   }
   return SetParentToWindow(static_cast<nsGlobalWindow *>(innerWindow.get()),
                            parentObj);
 }
 
 NS_IMETHODIMP
 nsHistorySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj, jsid id, jsval *vp, bool *_retval)
-{
+                         JSObject *aObj, jsid aId, jsval *vp, bool *_retval)
+{
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   bool is_number = false;
   GetArrayIndexFromId(cx, id, &is_number);
 
   if (!is_number) {
     return NS_OK;
   }
 
   return nsStringArraySH::GetProperty(wrapper, cx, obj, id, vp, _retval);
@@ -7227,18 +7263,20 @@ nsStorage2SH::NewResolve(nsIXPConnectWra
     *objp = realObj;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsStorage2SH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                          JSObject *obj, jsid id, jsval *vp, bool *_retval)
-{
+                          JSObject *aObj, jsid aId, jsval *vp, bool *_retval)
+{
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   nsCOMPtr<nsIDOMStorage> storage(do_QueryWrappedNative(wrapper));
   NS_ENSURE_TRUE(storage, NS_ERROR_UNEXPECTED);
 
   JSString* key = IdToString(cx, id);
   NS_ENSURE_TRUE(key, NS_ERROR_UNEXPECTED);
 
   nsDependentJSString keyStr;
   NS_ENSURE_TRUE(keyStr.init(cx, key), NS_ERROR_UNEXPECTED);
@@ -7266,19 +7304,20 @@ nsStorage2SH::GetProperty(nsIXPConnectWr
     *vp = STRING_TO_JSVAL(str);
   }
 
   return NS_SUCCESS_I_DID_SOMETHING;
 }
 
 NS_IMETHODIMP
 nsStorage2SH::SetProperty(nsIXPConnectWrappedNative *wrapper,
-                          JSContext *cx, JSObject *obj, jsid id,
+                          JSContext *cx, JSObject *obj, jsid aId,
                           jsval *vp, bool *_retval)
 {
+  JS::Rooted<jsid> id(cx, aId);
   nsCOMPtr<nsIDOMStorage> storage(do_QueryWrappedNative(wrapper));
   NS_ENSURE_TRUE(storage, NS_ERROR_UNEXPECTED);
 
   JSString *key = IdToString(cx, id);
   NS_ENSURE_TRUE(key, NS_ERROR_UNEXPECTED);
 
   nsDependentJSString keyStr;
   NS_ENSURE_TRUE(keyStr.init(cx, key), NS_ERROR_UNEXPECTED);
@@ -7294,19 +7333,20 @@ nsStorage2SH::SetProperty(nsIXPConnectWr
     rv = NS_SUCCESS_I_DID_SOMETHING;
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsStorage2SH::DelProperty(nsIXPConnectWrappedNative *wrapper,
-                          JSContext *cx, JSObject *obj, jsid id,
+                          JSContext *cx, JSObject *obj, jsid aId,
                           bool *_retval)
 {
+  JS::Rooted<jsid> id(cx, aId);
   nsCOMPtr<nsIDOMStorage> storage(do_QueryWrappedNative(wrapper));
   NS_ENSURE_TRUE(storage, NS_ERROR_UNEXPECTED);
 
   JSString *key = IdToString(cx, id);
   NS_ENSURE_TRUE(key, NS_ERROR_UNEXPECTED);
 
   nsDependentJSString keyStr;
   NS_ENSURE_TRUE(keyStr.init(cx, key), NS_ERROR_UNEXPECTED);
@@ -7391,36 +7431,39 @@ nsEventListenerThisTranslator::Translate
 
   nsCOMPtr<EventTarget> target = event->InternalDOMEvent()->GetCurrentTarget();
   *_retval = target.forget().get();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMConstructorSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
-                              JSObject *globalObj, JSObject **parentObj)
-{
+                              JSObject *aGlobalObj, JSObject **parentObj)
+{
+  JS::Rooted<JSObject*> globalObj(cx, aGlobalObj);
   nsDOMConstructor *wrapped = static_cast<nsDOMConstructor *>(nativeObj);
 
 #ifdef DEBUG
   {
     nsCOMPtr<nsIDOMDOMConstructor> is_constructor =
       do_QueryInterface(nativeObj);
     NS_ASSERTION(is_constructor, "How did we not get a constructor?");
   }
 #endif
 
   return wrapped->PreCreate(cx, globalObj, parentObj);
 }
 
 NS_IMETHODIMP
 nsDOMConstructorSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                               JSObject *obj, jsid id, uint32_t flags,
+                               JSObject *aObj, jsid aId, uint32_t flags,
                                JSObject **objp, bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
+  JS::Rooted<jsid> id(cx, aId);
   // For regular DOM constructors, we have our interface constants defined on
   // us by nsWindowSH::GlobalResolve. However, XrayWrappers can't see these
   // interface constants (as they look like expando properties) so we have to
   // specially resolve those constants here, but only for Xray wrappers.
   if (!ObjectIsNativeWrapper(cx, obj)) {
     return NS_OK;
   }
 
@@ -7465,19 +7508,20 @@ nsDOMConstructorSH::Call(nsIXPConnectWra
   }
 #endif
 
   return wrapped->Construct(wrapper, cx, obj, argc, argv, vp, _retval);
 }
 
 NS_IMETHODIMP
 nsDOMConstructorSH::Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                              JSObject *obj, uint32_t argc, jsval *argv,
+                              JSObject *aObj, uint32_t argc, jsval *argv,
                               jsval *vp, bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
   MOZ_ASSERT(obj);
 
   nsDOMConstructor *wrapped =
     static_cast<nsDOMConstructor *>(wrapper->Native());
 
 #ifdef DEBUG
   {
     nsCOMPtr<nsIDOMDOMConstructor> is_constructor =
@@ -7486,19 +7530,20 @@ nsDOMConstructorSH::Construct(nsIXPConne
   }
 #endif
 
   return wrapped->Construct(wrapper, cx, obj, argc, argv, vp, _retval);
 }
 
 NS_IMETHODIMP
 nsDOMConstructorSH::HasInstance(nsIXPConnectWrappedNative *wrapper,
-                                JSContext *cx, JSObject *obj, const jsval &val,
+                                JSContext *cx, JSObject *aObj, const jsval &val,
                                 bool *bp, bool *_retval)
 {
+  JS::Rooted<JSObject*> obj(cx, aObj);
   nsDOMConstructor *wrapped =
     static_cast<nsDOMConstructor *>(wrapper->Native());
 
 #ifdef DEBUG
   {
     nsCOMPtr<nsIDOMDOMConstructor> is_constructor =
       do_QueryWrappedNative(wrapper);
     NS_ASSERTION(is_constructor, "How did we not get a constructor?");
--- a/dom/base/nsDOMClassInfo.h
+++ b/dom/base/nsDOMClassInfo.h
@@ -152,17 +152,17 @@ protected:
   static nsresult RegisterClassProtos(int32_t aDOMClassInfoID);
   static nsresult RegisterExternalClasses();
   nsresult ResolveConstructor(JSContext *cx, JSObject *obj,
                               JSObject **objp);
 
   // Checks if id is a number and returns the number, if aIsNumber is
   // non-null it's set to true if the id is a number and false if it's
   // not a number. If id is not a number this method returns -1
-  static int32_t GetArrayIndexFromId(JSContext *cx, jsid id,
+  static int32_t GetArrayIndexFromId(JSContext *cx, JS::Handle<jsid> id,
                                      bool *aIsNumber = nullptr);
 
   static inline bool IsReadonlyReplaceable(jsid id)
   {
     return (id == sParent_id       ||
             id == sScrollbars_id   ||
             id == sContent_id      ||
             id == sMenubar_id      ||
@@ -333,17 +333,17 @@ protected:
   {
   }
 
   virtual ~nsWindowSH()
   {
   }
 
   static nsresult GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
-                                JSObject *obj, JS::Handle<jsid> id,
+                                JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
                                 bool *did_resolve);
 
 public:
   NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
                        JSObject *globalObj, JSObject **parentObj);
 #ifdef DEBUG
   NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                         JSObject *obj)
@@ -371,17 +371,18 @@ public:
   NS_IMETHOD OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
                          JSObject * obj, JSObject * *_retval);
 
   static JSBool GlobalScopePolluterNewResolve(JSContext *cx, JSHandleObject obj,
                                               JSHandleId id, unsigned flags,
                                               JS::MutableHandle<JSObject*> objp);
   static JSBool GlobalScopePolluterGetProperty(JSContext *cx, JSHandleObject obj,
                                                JSHandleId id, JSMutableHandleValue vp);
-  static JSBool InvalidateGlobalScopePolluter(JSContext *cx, JSObject* obj);
+  static JSBool InvalidateGlobalScopePolluter(JSContext *cx,
+                                              JS::Handle<JSObject*> obj);
   static nsresult InstallGlobalScopePolluter(JSContext *cx,
                                              JS::Handle<JSObject*> obj);
   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
   {
     return new nsWindowSH(aData);
   }
 };
 
@@ -630,17 +631,17 @@ protected:
   nsHTMLDocumentSH(nsDOMClassInfoData* aData) : nsDocumentSH(aData)
   {
   }
 
   virtual ~nsHTMLDocumentSH()
   {
   }
 
-  static JSBool GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
+  static JSBool GetDocumentAllNodeList(JSContext *cx, JS::Handle<JSObject*> obj,
                                        nsDocument *doc,
                                        nsContentList **nodeList);
 
 public:
   static JSBool DocumentAllGetProperty(JSContext *cx, JSHandleObject obj, JSHandleId id,
                                        JSMutableHandleValue vp);
   static JSBool DocumentAllNewResolve(JSContext *cx, JSHandleObject obj, JSHandleId id,
                                       unsigned flags, JS::MutableHandle<JSObject*> objp);
@@ -657,17 +658,17 @@ public:
 
   NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                         JSObject *obj, jsid id, uint32_t flags,
                         JSObject **objp, bool *_retval);
   NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                          JSObject *obj, jsid id, jsval *vp, bool *_retval);
 
   static nsresult TryResolveAll(JSContext* cx, nsHTMLDocument* doc,
-                                JSObject* obj);
+                                JS::Handle<JSObject*> obj);
 
   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
   {
     return new nsHTMLDocumentSH(aData);
   }
 };
 
 
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -2239,18 +2239,19 @@ nsGlobalWindow::SetNewDocument(nsIDocume
 
   if (reUseInnerWindow) {
     // We're reusing the current inner window.
     NS_ASSERTION(!currentInner->IsFrozen(),
                  "We should never be reusing a shared inner window");
     newInnerWindow = currentInner;
 
     if (aDocument != oldDoc) {
-      xpc_UnmarkGrayObject(currentInner->mJSObject);
-      if (!nsWindowSH::InvalidateGlobalScopePolluter(cx, currentInner->mJSObject)) {
+      JS::Rooted<JSObject*> obj(cx, currentInner->mJSObject);
+      xpc_UnmarkGrayObject(obj);
+      if (!nsWindowSH::InvalidateGlobalScopePolluter(cx, obj)) {
         return NS_ERROR_FAILURE;
       }
     }
 
     // We're reusing the inner window, but this still counts as a navigation,
     // so all expandos and such defined on the outer window should go away. Force
     // all Xray wrappers to be recomputed.
     xpc_UnmarkGrayObject(mJSObject);