Bug 959787 - Handlify remaining JS APIs r=terrence r=bz r=bholley
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 30 Apr 2014 10:10:33 +0100
changeset 181358 c9c1e001452bbdc054460038021bc928ee95e91b
parent 181357 e0679448fd3ba60750ae9e427468a6cff631c5bb
child 181359 4b91913320effd4aa0efc72f10ab21e777441588
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersterrence, bz, bholley
bugs959787
milestone32.0a1
Bug 959787 - Handlify remaining JS APIs r=terrence r=bz r=bholley
caps/src/nsSecurityManagerFactory.cpp
content/base/src/nsDocument.cpp
content/html/document/src/HTMLAllCollection.cpp
content/media/webaudio/AudioBuffer.cpp
dom/base/Console.cpp
dom/base/nsDOMClassInfo.cpp
dom/bindings/Codegen.py
dom/file/ArchiveRequest.cpp
dom/indexedDB/KeyPath.cpp
dom/plugins/base/nsJSNPRuntime.cpp
dom/promise/Promise.cpp
dom/src/notification/Notification.cpp
dom/system/OSFileConstants.cpp
dom/xbl/nsXBLProtoImplField.cpp
dom/xbl/nsXBLProtoImplMethod.cpp
dom/xbl/nsXBLProtoImplProperty.cpp
gfx/src/nsScriptableRegion.cpp
js/ipc/JavaScriptChild.cpp
js/ipc/JavaScriptShared.cpp
js/public/Value.h
js/src/builtin/TestingFunctions.cpp
js/src/ctypes/CTypes.cpp
js/src/jsapi-tests/testAddPropertyPropcache.cpp
js/src/jsapi-tests/testLookup.cpp
js/src/jsapi-tests/testPropCache.cpp
js/src/jsapi-tests/testResolveRecursion.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jsfriendapi.h
js/src/jsobj.cpp
js/src/jsproxy.cpp
js/src/shell/js.cpp
js/src/vm/ArrayBufferObject.cpp
js/src/vm/ScopeObject.cpp
js/src/vm/SelfHosting.cpp
js/src/vm/Value.cpp
js/xpconnect/src/Sandbox.cpp
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCJSID.cpp
js/xpconnect/src/XPCShellImpl.cpp
js/xpconnect/src/XPCWrappedNativeJSOps.cpp
js/xpconnect/src/XPCWrappedNativeScope.cpp
js/xpconnect/wrappers/XrayWrapper.cpp
storage/src/mozStorageAsyncStatementParams.cpp
storage/src/mozStorageStatementParams.cpp
storage/src/mozStorageStatementRow.cpp
toolkit/components/places/History.cpp
toolkit/components/telemetry/Telemetry.cpp
--- a/caps/src/nsSecurityManagerFactory.cpp
+++ b/caps/src/nsSecurityManagerFactory.cpp
@@ -94,36 +94,34 @@ nsSecurityNameSet::InitializeNameSet(nsI
          * "security" property.
          */
         obj = &v.toObject();
         if (!JS_GetProperty(cx, obj, "security", &v) || !v.isObject())
             return NS_ERROR_FAILURE;
         securityObj = &v.toObject();
     } else {
         /* define netscape.security object */
-        obj = JS_DefineObject(cx, global, "netscape", objectClass, nullptr, 0);
+        obj = JS_DefineObject(cx, global, "netscape", objectClass);
         if (obj == nullptr)
             return NS_ERROR_FAILURE;
-        securityObj = JS_DefineObject(cx, obj, "security", objectClass,
-                                      nullptr, 0);
+        securityObj = JS_DefineObject(cx, obj, "security", objectClass);
         if (securityObj == nullptr)
             return NS_ERROR_FAILURE;
     }
 
     // We hide enablePrivilege behind a pref because it has been altered in a
     // way that makes it fundamentally insecure to use in production. Mozilla
     // uses this pref during automated testing to support legacy test code that
     // uses enablePrivilege. If you're not doing test automation, you _must_ not
     // flip this pref, or you will be exposing all your users to security
     // vulnerabilities.
     if (!Preferences::GetBool("security.turn_off_all_security_so_that_viruses_can_take_over_this_computer"))
         return NS_OK;
 
     /* Define PrivilegeManager object with the necessary "static" methods. */
-    obj = JS_DefineObject(cx, securityObj, "PrivilegeManager", objectClass,
-                          nullptr, 0);
+    obj = JS_DefineObject(cx, securityObj, "PrivilegeManager", objectClass);
     if (obj == nullptr)
         return NS_ERROR_FAILURE;
 
     return JS_DefineFunctions(cx, obj, PrivilegeManager_static_methods)
            ? NS_OK
            : NS_ERROR_FAILURE;
 }
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -12150,20 +12150,21 @@ nsIDocument::WrapObject(JSContext *aCx)
                                            false);
   if (NS_FAILED(rv)) {
     Throw(aCx, rv);
     return nullptr;
   }
 
   NS_NAMED_LITERAL_STRING(doc_str, "document");
 
-  if (!JS_DefineUCProperty(aCx, winVal.toObjectOrNull(), doc_str.get(),
-                           doc_str.Length(), JS::ObjectValue(*obj),
-                           JS_PropertyStub, JS_StrictPropertyStub,
-                           JSPROP_READONLY | JSPROP_ENUMERATE)) {
+  JS::Rooted<JSObject*> winObj(aCx, &winVal.toObject());
+  if (!JS_DefineUCProperty(aCx, winObj, doc_str.get(),
+                           doc_str.Length(), obj,
+                           JSPROP_READONLY | JSPROP_ENUMERATE,
+                           JS_PropertyStub, JS_StrictPropertyStub)) {
     return nullptr;
   }
 
   return obj;
 }
 
 XPathEvaluator*
 nsIDocument::XPathEvaluator()
--- a/content/html/document/src/HTMLAllCollection.cpp
+++ b/content/html/document/src/HTMLAllCollection.cpp
@@ -317,17 +317,17 @@ nsHTMLDocumentSH::DocumentAllNewResolve(
     if (!DocumentAllGetProperty(cx, obj, id, &v)) {
       return false;
     }
   }
 
   bool ok = true;
 
   if (v.get() != JSVAL_VOID) {
-    ok = ::JS_DefinePropertyById(cx, obj, id, v, nullptr, nullptr, 0);
+    ok = ::JS_DefinePropertyById(cx, obj, id, v, 0);
     objp.set(obj);
   }
 
   return ok;
 }
 
 void
 nsHTMLDocumentSH::ReleaseDocument(JSFreeOp *fop, JSObject *obj)
--- a/content/media/webaudio/AudioBuffer.cpp
+++ b/content/media/webaudio/AudioBuffer.cpp
@@ -191,18 +191,19 @@ AudioBuffer::GetChannelData(JSContext* a
 
 static already_AddRefed<ThreadSharedFloatArrayBufferList>
 StealJSArrayDataIntoThreadSharedFloatArrayBufferList(JSContext* aJSContext,
                                                      const nsTArray<JSObject*>& aJSArrays)
 {
   nsRefPtr<ThreadSharedFloatArrayBufferList> result =
     new ThreadSharedFloatArrayBufferList(aJSArrays.Length());
   for (uint32_t i = 0; i < aJSArrays.Length(); ++i) {
+    JS::Rooted<JSObject*> arrayBufferView(aJSContext, aJSArrays[i]);
     JS::Rooted<JSObject*> arrayBuffer(aJSContext,
-                                      JS_GetArrayBufferViewBuffer(aJSContext, aJSArrays[i]));
+                                      JS_GetArrayBufferViewBuffer(aJSContext, arrayBufferView));
     uint8_t* stolenData = arrayBuffer
                           ? (uint8_t*) JS_StealArrayBufferContents(aJSContext, arrayBuffer)
                           : nullptr;
     if (stolenData) {
       result->SetData(i, stolenData, reinterpret_cast<float*>(stolenData));
     } else {
       return nullptr;
     }
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -290,19 +290,20 @@ private:
     JSAutoCompartment ac(aCx, mCallData->mGlobal);
 
     JS::Rooted<JSObject*> arguments(aCx,
       JS_NewArrayObject(aCx, mCallData->mArguments.Length()));
     if (!arguments) {
       return false;
     }
 
+    JS::Rooted<JS::Value> arg(aCx);
     for (uint32_t i = 0; i < mCallData->mArguments.Length(); ++i) {
-      if (!JS_DefineElement(aCx, arguments, i, mCallData->mArguments[i],
-                            nullptr, nullptr, JSPROP_ENUMERATE)) {
+      arg = mCallData->mArguments[i];
+      if (!JS_DefineElement(aCx, arguments, i, arg, JSPROP_ENUMERATE)) {
         return false;
       }
     }
 
     JS::Rooted<JS::Value> value(aCx, JS::ObjectValue(*arguments));
 
     if (!mArguments.write(aCx, value, &gConsoleCallbacks, &mStrings)) {
       return false;
@@ -400,19 +401,20 @@ private:
     JSAutoCompartment ac(aCx, global);
 
     JS::Rooted<JSObject*> arguments(aCx,
       JS_NewArrayObject(aCx, mArguments.Length()));
     if (!arguments) {
       return false;
     }
 
+    JS::Rooted<JS::Value> arg(aCx);
     for (uint32_t i = 0; i < mArguments.Length(); ++i) {
-      if (!JS_DefineElement(aCx, arguments, i, mArguments[i], nullptr, nullptr,
-                            JSPROP_ENUMERATE)) {
+      arg = mArguments[i];
+      if (!JS_DefineElement(aCx, arguments, i, arg, JSPROP_ENUMERATE)) {
         return false;
       }
     }
 
     JS::Rooted<JS::Value> value(aCx, JS::ObjectValue(*arguments));
 
     if (!mBuffer.write(aCx, value, &gConsoleCallbacks, &mStrings)) {
       return false;
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -1429,18 +1429,19 @@ nsDOMClassInfo::ResolveConstructor(JSCon
   }
 
   if (!val.isPrimitive()) {
     // If val is not an (non-null) object there either is no
     // constructor for this class, or someone messed with
     // window.classname, just fall through and let the JS engine
     // return the Object constructor.
 
-    if (!::JS_DefinePropertyById(cx, obj, sConstructor_id, val, JS_PropertyStub,
-                                 JS_StrictPropertyStub, JSPROP_ENUMERATE)) {
+    JS::Rooted<jsid> id(cx, sConstructor_id);
+    if (!::JS_DefinePropertyById(cx, obj, id, val, JSPROP_ENUMERATE,
+                                 JS_PropertyStub, JS_StrictPropertyStub)) {
       return NS_ERROR_UNEXPECTED;
     }
 
     *objp = obj;
   }
 
   return NS_OK;
 }
@@ -1665,18 +1666,18 @@ nsDOMClassInfo::PostCreatePrototype(JSCo
   JS::Rooted<JSPropertyDescriptor> desc(cx);
   nsresult rv = ResolvePrototype(sXPConnect, win, cx, global, mData->mNameUTF16,
                                  mData, nullptr, nameSpaceManager, proto,
                                  &desc);
   NS_ENSURE_SUCCESS(rv, rv);
   if (!contentDefinedProperty && desc.object() && !desc.value().isUndefined() &&
       !JS_DefineUCProperty(cx, global, mData->mNameUTF16,
                            NS_strlen(mData->mNameUTF16),
-                           desc.value(), desc.getter(), desc.setter(),
-                           desc.attributes())) {
+                           desc.value(), desc.attributes(),
+                           desc.getter(), desc.setter())) {
     return NS_ERROR_UNEXPECTED;
   }
 
   return NS_OK;
 }
 
 // static
 nsIClassInfo *
@@ -3258,19 +3259,19 @@ nsWindowSH::NewResolve(nsIXPConnectWrapp
     nsCOMPtr<nsIDOMLocation> location;
     nsresult rv = win->GetLocation(getter_AddRefs(location));
     NS_ENSURE_SUCCESS(rv, rv);
 
     JS::Rooted<JS::Value> v(cx);
     rv = WrapNative(cx, location, &NS_GET_IID(nsIDOMLocation), true, &v);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    bool ok = JS_DefinePropertyById(cx, obj, id, v, JS_PropertyStub,
-                                    LocationSetterUnwrapper,
-                                    JSPROP_PERMANENT | JSPROP_ENUMERATE);
+    bool ok = JS_DefinePropertyById(cx, obj, id, v,
+                                    JSPROP_PERMANENT | JSPROP_ENUMERATE,
+                                    JS_PropertyStub, LocationSetterUnwrapper);
 
     if (!ok) {
       return NS_ERROR_FAILURE;
     }
 
     *objp = obj;
 
     return NS_OK;
@@ -3286,19 +3287,20 @@ nsWindowSH::NewResolve(nsIXPConnectWrapp
 
     JS::Rooted<JS::Value> v(cx);
     js::AssertSameCompartment(cx, obj);
     rv = WrapNative(cx, top, &NS_GET_IID(nsIDOMWindow), true, &v);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Hold on to the top window object as a global property so we
     // don't need to worry about losing expando properties etc.
-    if (!JS_DefinePropertyById(cx, obj, id, v, JS_PropertyStub, JS_StrictPropertyStub,
+    if (!JS_DefinePropertyById(cx, obj, id, v,
                                JSPROP_READONLY | JSPROP_PERMANENT |
-                               JSPROP_ENUMERATE)) {
+                               JSPROP_ENUMERATE,
+                               JS_PropertyStub, JS_StrictPropertyStub)) {
       return NS_ERROR_FAILURE;
     }
     *objp = obj;
 
     return NS_OK;
   }
 
   if (isXray) {
@@ -3317,36 +3319,36 @@ nsWindowSH::NewResolve(nsIXPConnectWrapp
     if (!win->DoNewResolve(cx, global, id, &desc)) {
       return NS_ERROR_FAILURE;
     }
     // If we have an object here, that means we resolved the property.
     // But if the value is undefined, that means that GlobalResolve
     // also already defined it, so we don't have to.
     if (desc.object() && !desc.value().isUndefined() &&
         !JS_DefinePropertyById(cx, global, id, desc.value(),
-                               desc.getter(), desc.setter(),
-                               desc.attributes())) {
+                               desc.attributes(),
+                               desc.getter(), desc.setter())) {
       return NS_ERROR_FAILURE;
     }
   }
 
   JS::Rooted<JSPropertyDescriptor> desc(cx);
   if (!win->DoNewResolve(cx, obj, id, &desc)) {
     return NS_ERROR_FAILURE;
   }
   if (desc.object()) {
     // If we have an object here, that means we resolved the property.
     // But if the value is undefined, that means that GlobalResolve
     // also already defined it, so we don't have to.  Note that in the
     // Xray case we should never see undefined.
     MOZ_ASSERT_IF(isXray, !desc.value().isUndefined());
     if (!desc.value().isUndefined() &&
         !JS_DefinePropertyById(cx, obj, id, desc.value(),
-                               desc.getter(), desc.setter(),
-                               desc.attributes())) {
+                               desc.attributes(),
+                               desc.getter(), desc.setter())) {
       return NS_ERROR_FAILURE;
     }
 
     *objp = obj;
     return NS_OK;
   }
 
   if (sDocument_id == id) {
@@ -3522,17 +3524,17 @@ nsGenericArraySH::NewResolve(nsIXPConnec
     // it doesn't provide one.
 
     uint32_t length;
     nsresult rv = GetLength(wrapper, cx, obj, &length);
     NS_ENSURE_SUCCESS(rv, rv);
 
     uint32_t index = uint32_t(n);
     if (index < length) {
-      *_retval = ::JS_DefineElement(cx, obj, index, JSVAL_VOID, nullptr, nullptr,
+      *_retval = ::JS_DefineElement(cx, obj, index, JS::UndefinedHandleValue,
                                     JSPROP_ENUMERATE | JSPROP_SHARED);
       *objp = obj;
     }
   }
 
   return NS_OK;
 }
 
@@ -3583,17 +3585,17 @@ nsGenericArraySH::Enumerate(nsIXPConnect
 
   JS::Rooted<JS::Value> len_val(cx);
   bool ok = ::JS_GetProperty(cx, obj, "length", &len_val);
 
   if (ok && len_val.isInt32()) {
     int32_t length = len_val.toInt32();
 
     for (int32_t i = 0; ok && i < length; ++i) {
-      ok = ::JS_DefineElement(cx, obj, i, JSVAL_VOID, nullptr, nullptr,
+      ok = ::JS_DefineElement(cx, obj, i, JS::UndefinedHandleValue,
                               JSPROP_ENUMERATE | JSPROP_SHARED);
     }
   }
 
   sCurrentlyEnumerating = false;
 
   return ok ? NS_OK : NS_ERROR_UNEXPECTED;
 }
@@ -3714,18 +3716,18 @@ nsStorage2SH::NewResolve(nsIXPConnectWra
 
   // GetItem() will return null if the caller can't access the session
   // storage item.
   nsAutoString data;
   nsresult rv = storage->GetItem(depStr, data);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!DOMStringIsNull(data)) {
-    if (!::JS_DefinePropertyById(cx, realObj, id, JSVAL_VOID, nullptr,
-                                 nullptr, JSPROP_ENUMERATE)) {
+    if (!::JS_DefinePropertyById(cx, realObj, id, JS::UndefinedHandleValue,
+                                 JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
 
     *objp = realObj;
   }
 
   return NS_OK;
 }
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -5039,17 +5039,17 @@ def getWrapTemplateForType(type, descrip
               JS::Rooted<JS::Value> tmp(cx);
               for (uint32_t ${index} = 0; ${index} < length; ++${index}) {
                 // Control block to let us common up the JS_DefineElement calls when there
                 // are different ways to succeed at wrapping the object.
                 do {
                   $*{innerTemplate}
                 } while (0);
                 if (!JS_DefineElement(cx, returnArray, ${index}, tmp,
-                                      nullptr, nullptr, JSPROP_ENUMERATE)) {
+                                      JSPROP_ENUMERATE)) {
                   $*{exceptionCode}
                 }
               }
             }
             $*{set}
             """,
             result=result,
             exceptionCode=exceptionCode,
@@ -6782,18 +6782,18 @@ class CGNewResolveHook(CGAbstractBinding
             if (!desc.object()) {
               return true;
             }
             // If desc.value() is undefined, then the DoNewResolve call
             // has already defined it on the object.  Don't try to also
             // define it.
             if (!desc.value().isUndefined() &&
                 !JS_DefinePropertyById(cx, obj, id, desc.value(),
-                                       desc.getter(), desc.setter(),
-                                       desc.attributes())) {
+                                       desc.attributes(),
+                                       desc.getter(), desc.setter())) {
               return false;
             }
             objp.set(obj);
             return true;
             """)))
 
     def definition_body(self):
         if self.descriptor.interface.getExtendedAttribute("Global"):
@@ -8683,18 +8683,18 @@ class CGResolveOwnPropertyViaNewresolve(
                 return false;
               }
               // If desc.value() is undefined, then the DoNewResolve call
               // has already defined the property on the object.  Don't
               // try to also define it.
               if (objDesc.object() &&
                   !objDesc.value().isUndefined() &&
                   !JS_DefinePropertyById(cx, obj, id, objDesc.value(),
-                                         objDesc.getter(), objDesc.setter(),
-                                         objDesc.attributes())) {
+                                         objDesc.attributes(),
+                                         objDesc.getter(), objDesc.setter())) {
                 return false;
               }
             }
             return self->DoNewResolve(cx, wrapper, id, desc);
             """)))
 
 
 class CGEnumerateOwnProperties(CGAbstractStaticMethod):
@@ -10565,17 +10565,17 @@ class CGDictionary(CGThing):
                             "a property of Object.prototype, and Xrays to "
                             "Object can't handle that.\n"
                             "%s" %
                             (member.identifier.name,
                              self.dictionary.identifier.name,
                              member.location))
 
         propDef = (
-            'JS_DefinePropertyById(cx, obj, atomsCache->%s, temp, nullptr, nullptr, JSPROP_ENUMERATE)' %
+            'JS_DefinePropertyById(cx, obj, atomsCache->%s, temp, JSPROP_ENUMERATE)' %
             self.makeIdName(member.identifier.name))
 
         innerTemplate = wrapForType(
             member.type, self.descriptorProvider,
             {
                 'result': "currentValue",
                 'successCode': ("if (!%s) {\n"
                                 "  return false;\n"
--- a/dom/file/ArchiveRequest.cpp
+++ b/dom/file/ArchiveRequest.cpp
@@ -190,18 +190,17 @@ ArchiveRequest::GetFilenamesResult(JSCon
     nsString filename;
     rv = file->GetName(filename);
     NS_ENSURE_SUCCESS(rv, rv);
 
     str = JS_NewUCStringCopyZ(aCx, filename.get());
     NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
 
     if (NS_FAILED(rv) ||
-        !JS_DefineElement(aCx, array, i, JS::StringValue(str), nullptr, nullptr,
-                          JSPROP_ENUMERATE)) {
+        !JS_DefineElement(aCx, array, i, str, JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   if (!JS_FreezeObject(aCx, array)) {
     return NS_ERROR_FAILURE;
   }
 
@@ -242,18 +241,17 @@ ArchiveRequest::GetFilesResult(JSContext
 
   for (uint32_t i = 0; i < aFileList.Length(); ++i) {
     nsCOMPtr<nsIDOMFile> file = aFileList[i];
 
     JS::Rooted<JS::Value> value(aCx);
     nsresult rv = nsContentUtils::WrapNative(aCx, file, &NS_GET_IID(nsIDOMFile),
                                              &value);
     if (NS_FAILED(rv) ||
-        !JS_DefineElement(aCx, array, i, value, nullptr, nullptr,
-                          JSPROP_ENUMERATE)) {
+        !JS_DefineElement(aCx, array, i, value, JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   aValue.setObject(*array);
   return NS_OK;
 }
 
--- a/dom/indexedDB/KeyPath.cpp
+++ b/dom/indexedDB/KeyPath.cpp
@@ -164,19 +164,17 @@ GetJSValFromKeyPathString(JSContext* aCx
                                                       JS::NullPtr()));
         if (!dummy) {
           IDB_REPORT_INTERNAL_ERR();
           rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
           break;
         }
 
         if (!JS_DefineUCProperty(aCx, obj, token.BeginReading(),
-                                 token.Length(),
-                                 OBJECT_TO_JSVAL(dummy), nullptr, nullptr,
-                                 JSPROP_ENUMERATE)) {
+                                 token.Length(), dummy, JSPROP_ENUMERATE)) {
           IDB_REPORT_INTERNAL_ERR();
           rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
           break;
         }
 
         obj = dummy;
       }
       else {
@@ -184,18 +182,17 @@ GetJSValFromKeyPathString(JSContext* aCx
                                                       JS::NullPtr(), JS::NullPtr()));
         if (!dummy) {
           IDB_REPORT_INTERNAL_ERR();
           rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
           break;
         }
 
         if (!JS_DefineUCProperty(aCx, obj, token.BeginReading(),
-                                 token.Length(), OBJECT_TO_JSVAL(dummy),
-                                 nullptr, nullptr, JSPROP_ENUMERATE)) {
+                                 token.Length(), dummy, JSPROP_ENUMERATE)) {
           IDB_REPORT_INTERNAL_ERR();
           rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
           break;
         }
 
         obj = dummy;
       }
     }
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -1540,18 +1540,18 @@ NPObjWrapper_NewResolve(JSContext *cx, J
 
   bool hasProperty = npobj->_class->hasProperty(npobj, identifier);
   if (!ReportExceptionIfPending(cx))
     return false;
 
   if (hasProperty) {
     NS_ASSERTION(JSID_IS_STRING(id) || JSID_IS_INT(id),
                  "id must be either string or int!\n");
-    if (!::JS_DefinePropertyById(cx, obj, id, JSVAL_VOID, nullptr,
-                                 nullptr, JSPROP_ENUMERATE | JSPROP_SHARED)) {
+    if (!::JS_DefinePropertyById(cx, obj, id, JS::UndefinedHandleValue,
+                                 JSPROP_ENUMERATE | JSPROP_SHARED)) {
         return false;
     }
 
     objp.set(obj);
 
     return true;
   }
 
--- a/dom/promise/Promise.cpp
+++ b/dom/promise/Promise.cpp
@@ -621,19 +621,19 @@ public:
     MOZ_ASSERT(mCountdown > 0);
 
     ThreadsafeAutoSafeJSContext cx;
     JSAutoCompartment ac(cx, mValues);
     {
 
       AutoDontReportUncaught silenceReporting(cx);
       JS::Rooted<JS::Value> value(cx, aValue);
+      JS::Rooted<JSObject*> values(cx, mValues);
       if (!JS_WrapValue(cx, &value) ||
-          !JS_DefineElement(cx, mValues, index, value, nullptr, nullptr,
-                            JSPROP_ENUMERATE)) {
+          !JS_DefineElement(cx, values, index, value, JSPROP_ENUMERATE)) {
         MOZ_ASSERT(JS_IsExceptionPending(cx));
         JS::Rooted<JS::Value> exn(cx);
         JS_GetPendingException(cx, &exn);
 
         mPromise->MaybeReject(cx, exn);
       }
     }
 
--- a/dom/src/notification/Notification.cpp
+++ b/dom/src/notification/Notification.cpp
@@ -71,18 +71,18 @@ public:
     nsRefPtr<Notification> notification = Notification::CreateInternal(mWindow,
                                                                        aID,
                                                                        aTitle,
                                                                        options);
     JSAutoCompartment ac(aCx, mGlobal);
     JS::Rooted<JSObject*> element(aCx, notification->WrapObject(aCx));
     NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
 
-    if (!JS_DefineElement(aCx, mNotifications, mCount++,
-                          JS::ObjectValue(*element), nullptr, nullptr, 0)) {
+    JS::Rooted<JSObject*> notifications(aCx, mNotifications);
+    if (!JS_DefineElement(aCx, notifications, mCount++, element, 0)) {
       return NS_ERROR_FAILURE;
     }
     return NS_OK;
   }
 
   NS_IMETHOD Done(JSContext* aCx)
   {
     JSAutoCompartment ac(aCx, mGlobal);
--- a/dom/system/OSFileConstants.cpp
+++ b/dom/system/OSFileConstants.cpp
@@ -765,17 +765,17 @@ JSObject *GetOrCreateObjectProperty(JSCo
     if (val.isObject()) {
       return &val.toObject();
     }
 
     JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr,
       JSMSG_UNEXPECTED_TYPE, aProperty, "not an object");
     return nullptr;
   }
-  return JS_DefineObject(cx, aObject, aProperty, nullptr, nullptr,
+  return JS_DefineObject(cx, aObject, aProperty, nullptr, JS::NullPtr(),
                          JSPROP_ENUMERATE);
 }
 
 /**
  * Set a property of an object from a nsString.
  *
  * If the nsString is void (i.e. IsVoid is true), do nothing.
  */
--- a/dom/xbl/nsXBLProtoImplField.cpp
+++ b/dom/xbl/nsXBLProtoImplField.cpp
@@ -360,20 +360,20 @@ nsXBLProtoImplField::InstallAccessors(JS
   // them there.
   JSAutoCompartment ac2(aCx, aTargetClassObject);
   if (!JS_WrapObject(aCx, &get) || !JS_WrapObject(aCx, &set) ||
       !JS_WrapId(aCx, &id))
   {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  if (!::JS_DefinePropertyById(aCx, aTargetClassObject, id, JS::UndefinedValue(),
+  if (!::JS_DefinePropertyById(aCx, aTargetClassObject, id, JS::UndefinedHandleValue,
+                               AccessorAttributes(),
                                JS_DATA_TO_FUNC_PTR(JSPropertyOp, get.get()),
-                               JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, set.get()),
-                               AccessorAttributes())) {
+                               JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, set.get()))) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsXBLProtoImplField::InstallField(JS::Handle<JSObject*> aBoundNode,
@@ -439,18 +439,17 @@ nsXBLProtoImplField::InstallField(JS::Ha
 
   // Now, enter the node's compartment, wrap the eval result, and define it on
   // the bound node.
   JSAutoCompartment ac2(cx, aBoundNode);
   nsDependentString name(mName);
   if (!JS_WrapValue(cx, &result) ||
       !::JS_DefineUCProperty(cx, aBoundNode,
                              reinterpret_cast<const jschar*>(mName),
-                             name.Length(), result, nullptr, nullptr,
-                             mJSAttributes)) {
+                             name.Length(), result, mJSAttributes)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   *aDidInstall = true;
   return NS_OK;
 }
 
 nsresult
--- a/dom/xbl/nsXBLProtoImplMethod.cpp
+++ b/dom/xbl/nsXBLProtoImplMethod.cpp
@@ -109,21 +109,20 @@ nsXBLProtoImplMethod::InstallMember(JSCo
 
   JS::Rooted<JSObject*> jsMethodObject(aCx, GetCompiledMethod());
   if (jsMethodObject) {
     nsDependentString name(mName);
 
     JS::Rooted<JSObject*> method(aCx, JS_CloneFunctionObject(aCx, jsMethodObject, globalObject));
     NS_ENSURE_TRUE(method, NS_ERROR_OUT_OF_MEMORY);
 
-    JS::Rooted<JS::Value> value(aCx, JS::ObjectValue(*method));
     if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
                                static_cast<const jschar*>(mName),
-                               name.Length(), value,
-                               nullptr, nullptr, JSPROP_ENUMERATE)) {
+                               name.Length(), method,
+                               JSPROP_ENUMERATE)) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
   return NS_OK;
 }
 
 nsresult
 nsXBLProtoImplMethod::CompileMember(const nsCString& aClassStr,
--- a/dom/xbl/nsXBLProtoImplProperty.cpp
+++ b/dom/xbl/nsXBLProtoImplProperty.cpp
@@ -143,20 +143,19 @@ nsXBLProtoImplProperty::InstallMember(JS
     if (setter) {
       if (!(setter = ::JS_CloneFunctionObject(aCx, setter, globalObject)))
         return NS_ERROR_OUT_OF_MEMORY;
     }
 
     nsDependentString name(mName);
     if (!::JS_DefineUCProperty(aCx, aTargetClassObject,
                                static_cast<const jschar*>(mName),
-                               name.Length(), JSVAL_VOID,
+                               name.Length(), JS::UndefinedHandleValue, mJSAttributes,
                                JS_DATA_TO_FUNC_PTR(JSPropertyOp, getter.get()),
-                               JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, setter.get()),
-                               mJSAttributes))
+                               JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, setter.get())))
       return NS_ERROR_OUT_OF_MEMORY;
   }
   return NS_OK;
 }
 
 nsresult
 nsXBLProtoImplProperty::CompileMember(const nsCString& aClassStr,
                                       JS::Handle<JSObject*> aClassObject)
--- a/gfx/src/nsScriptableRegion.cpp
+++ b/gfx/src/nsScriptableRegion.cpp
@@ -143,19 +143,19 @@ NS_IMETHODIMP nsScriptableRegion::GetRec
 
   aRects.setObject(*destArray);
 
   uint32_t n = 0;
   nsIntRegionRectIterator iter(mRegion);
   const nsIntRect *rect;
 
   while ((rect = iter.Next())) {
-    if (!JS_DefineElement(aCx, destArray, n, INT_TO_JSVAL(rect->x), nullptr, nullptr, JSPROP_ENUMERATE) ||
-        !JS_DefineElement(aCx, destArray, n + 1, INT_TO_JSVAL(rect->y), nullptr, nullptr, JSPROP_ENUMERATE) ||
-        !JS_DefineElement(aCx, destArray, n + 2, INT_TO_JSVAL(rect->width), nullptr, nullptr, JSPROP_ENUMERATE) ||
-        !JS_DefineElement(aCx, destArray, n + 3, INT_TO_JSVAL(rect->height), nullptr, nullptr, JSPROP_ENUMERATE)) {
+    if (!JS_DefineElement(aCx, destArray, n, rect->x, JSPROP_ENUMERATE) ||
+        !JS_DefineElement(aCx, destArray, n + 1, rect->y, JSPROP_ENUMERATE) ||
+        !JS_DefineElement(aCx, destArray, n + 2, rect->width, JSPROP_ENUMERATE) ||
+        !JS_DefineElement(aCx, destArray, n + 3, rect->height, JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
     n += 4;
   }
 
   return NS_OK;
 }
--- a/js/ipc/JavaScriptChild.cpp
+++ b/js/ipc/JavaScriptChild.cpp
@@ -252,24 +252,24 @@ JavaScriptChild::AnswerDefineProperty(co
     RootedId internedId(cx);
     if (!convertGeckoStringToId(cx, id, &internedId))
         return fail(cx, rs);
 
     Rooted<JSPropertyDescriptor> desc(cx);
     if (!toDescriptor(cx, descriptor, &desc))
         return false;
 
-    if (!js::CheckDefineProperty(cx, obj, internedId, desc.value(), desc.getter(),
-                                 desc.setter(), desc.attributes()))
+    if (!js::CheckDefineProperty(cx, obj, internedId, desc.value(), desc.attributes(),
+                                 desc.getter(), desc.setter()))
     {
         return fail(cx, rs);
     }
 
-    if (!JS_DefinePropertyById(cx, obj, internedId, desc.value(), desc.getter(),
-                               desc.setter(), desc.attributes()))
+    if (!JS_DefinePropertyById(cx, obj, internedId, desc.value(), desc.attributes(),
+                               desc.getter(), desc.setter()))
     {
         return fail(cx, rs);
     }
 
     return ok(rs);
 }
 
 bool
--- a/js/ipc/JavaScriptShared.cpp
+++ b/js/ipc/JavaScriptShared.cpp
@@ -450,18 +450,16 @@ JavaScriptShared::Unwrap(JSContext *cx, 
         if (!toValue(cx, aCpows[i].value(), &v))
             return false;
 
         if (!JS_DefineUCProperty(cx,
                                  obj,
                                  name.BeginReading(),
                                  name.Length(),
                                  v,
-                                 nullptr,
-                                 nullptr,
                                  JSPROP_ENUMERATE))
         {
             return false;
         }
     }
 
     objp.set(obj);
     return true;
--- a/js/public/Value.h
+++ b/js/public/Value.h
@@ -1892,15 +1892,17 @@ extern JS_PUBLIC_DATA(const jsval) JSVAL
 extern JS_PUBLIC_DATA(const jsval) JSVAL_FALSE;
 extern JS_PUBLIC_DATA(const jsval) JSVAL_TRUE;
 extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID;
 
 namespace JS {
 
 extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue;
 extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue;
+extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue;
+extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue;
 
 }
 
 #undef JS_VALUE_IS_CONSTEXPR
 #undef JS_RETURN_LAYOUT_FROM_BITS
 
 #endif /* js_Value_h */
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -1122,20 +1122,24 @@ ShellObjectMetadataCallback(JSContext *c
 
     if (!JS_DefineProperty(cx, obj, "stack", stack, 0,
                            JS_PropertyStub, JS_StrictPropertyStub))
     {
         return false;
     }
 
     int stackIndex = 0;
+    RootedId id(cx);
+    RootedValue callee(cx);
     for (NonBuiltinScriptFrameIter iter(cx); !iter.done(); ++iter) {
         if (iter.isFunctionFrame() && iter.compartment() == cx->compartment()) {
-            if (!JS_DefinePropertyById(cx, stack, INT_TO_JSID(stackIndex), ObjectValue(*iter.callee()),
-                                       JS_PropertyStub, JS_StrictPropertyStub, 0))
+            id = INT_TO_JSID(stackIndex);
+            RootedObject callee(cx, iter.callee());
+            if (!JS_DefinePropertyById(cx, stack, id, callee, 0,
+                                       JS_PropertyStub, JS_StrictPropertyStub))
             {
                 return false;
             }
             stackIndex++;
         }
     }
 
     *pmetadata = obj;
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -4696,17 +4696,17 @@ AddFieldToArray(JSContext* cx,
   RootedObject fieldObj(cx, JS_NewObject(cx, nullptr, NullPtr(), NullPtr()));
   if (!fieldObj)
     return false;
 
   *element = OBJECT_TO_JSVAL(fieldObj);
 
   if (!JS_DefineUCProperty(cx, fieldObj,
          name->chars(), name->length(),
-         OBJECT_TO_JSVAL(typeObj), nullptr, nullptr,
+         typeObj,
          JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT))
     return false;
 
   return JS_FreezeObject(cx, fieldObj);
 }
 
 bool
 StructType::Create(JSContext* cx, unsigned argc, jsval* vp)
@@ -4828,19 +4828,19 @@ StructType::DefineInternal(JSContext* cx
       FieldInfoHash::AddPtr entryPtr = fields->lookupForAdd(name);
       if (entryPtr) {
         JS_ReportError(cx, "struct fields must have unique names");
         return false;
       }
 
       // Add the field to the StructType's 'prototype' property.
       if (!JS_DefineUCProperty(cx, prototype,
-             name->chars(), name->length(), JSVAL_VOID,
-             StructType::FieldGetter, StructType::FieldSetter,
-             JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT))
+             name->chars(), name->length(), UndefinedHandleValue,
+             JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT,
+             StructType::FieldGetter, StructType::FieldSetter))
         return false;
 
       size_t fieldSize = CType::GetSize(fieldType);
       size_t fieldAlign = CType::GetAlignment(fieldType);
       size_t fieldOffset = Align(structSize, fieldAlign);
       // Check for overflow. Since we hold invariant that fieldSize % fieldAlign
       // be zero, we can safely check fieldOffset + fieldSize without first
       // checking fieldOffset for overflow.
--- a/js/src/jsapi-tests/testAddPropertyPropcache.cpp
+++ b/js/src/jsapi-tests/testAddPropertyPropcache.cpp
@@ -44,24 +44,22 @@ BEGIN_TEST(testAddPropertyHook)
 
     obj = JS_NewArrayObject(cx, 0);
     CHECK(obj);
     JS::RootedValue arr(cx, OBJECT_TO_JSVAL(obj));
 
     CHECK(JS_DefineProperty(cx, global, "arr", arr, JSPROP_ENUMERATE,
                             JS_PropertyStub, JS_StrictPropertyStub));
 
+    JS::RootedObject arrObj(cx, &arr.toObject());
     for (int i = 0; i < ExpectedCount; ++i) {
         obj = JS_NewObject(cx, &AddPropertyClass, JS::NullPtr(), JS::NullPtr());
         CHECK(obj);
-        JS::RootedValue vobj(cx, OBJECT_TO_JSVAL(obj));
-        JS::RootedObject arrObj(cx, arr.toObjectOrNull());
-        CHECK(JS_DefineElement(cx, arrObj, i, vobj,
-                               JS_PropertyStub, JS_StrictPropertyStub,
-                               JSPROP_ENUMERATE));
+        CHECK(JS_DefineElement(cx, arrObj, i, obj, JSPROP_ENUMERATE,
+                               JS_PropertyStub, JS_StrictPropertyStub));
     }
 
     // Now add a prop to each of the objects, but make sure to do
     // so at the same bytecode location so we can hit the propcache.
     EXEC("'use strict';                                     \n"
          "for (var i = 0; i < arr.length; ++i)              \n"
          "  arr[i].prop = 42;                               \n"
          );
--- a/js/src/jsapi-tests/testLookup.cpp
+++ b/js/src/jsapi-tests/testLookup.cpp
@@ -63,17 +63,17 @@ document_resolve(JSContext *cx, JS::Hand
         if (!flatStr)
             return false;
         if (JS_FlatStringEqualsAscii(flatStr, "all")) {
             JS::Rooted<JSObject*> docAll(cx,
                                          JS_NewObject(cx, &DocumentAllClass, JS::NullPtr(), JS::NullPtr()));
             if (!docAll)
                 return false;
             JS::Rooted<JS::Value> allValue(cx, ObjectValue(*docAll));
-            bool ok = JS_DefinePropertyById(cx, obj, id, allValue, nullptr, nullptr, 0);
+            bool ok = JS_DefinePropertyById(cx, obj, id, allValue, 0);
             objp.set(ok ? obj.get() : nullptr);
             return ok;
         }
     }
     objp.set(nullptr);
     return true;
 }
 
--- a/js/src/jsapi-tests/testPropCache.cpp
+++ b/js/src/jsapi-tests/testPropCache.cpp
@@ -22,16 +22,16 @@ static const JSClass CounterClass = {
     CounterAdd, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub
 };
 
 BEGIN_TEST(testPropCache_bug505798)
 {
     g_counter = 0;
     EXEC("var x = {};");
-    CHECK(JS_DefineObject(cx, global, "y", &CounterClass, nullptr, JSPROP_ENUMERATE));
+    CHECK(JS_DefineObject(cx, global, "y", &CounterClass, JS::NullPtr(), JSPROP_ENUMERATE));
     EXEC("var arr = [x, y];\n"
          "for (var i = 0; i < arr.length; i++)\n"
          "    arr[i].p = 1;\n");
     CHECK_EQUAL(g_counter, 1);
     return true;
 }
 END_TEST(testPropCache_bug505798)
--- a/js/src/jsapi-tests/testResolveRecursion.cpp
+++ b/js/src/jsapi-tests/testResolveRecursion.cpp
@@ -91,29 +91,29 @@ doResolve(JS::HandleObject obj, JS::Hand
     CHECK(str);
     JS::RootedValue v(cx);
     if (JS_FlatStringEqualsAscii(str, "x")) {
         if (obj == obj1) {
             /* First resolve hook invocation. */
             CHECK_EQUAL(resolveEntryCount, 1);
             EVAL("obj2.y = true", &v);
             CHECK_SAME(v, JSVAL_TRUE);
-            CHECK(JS_DefinePropertyById(cx, obj, id, JSVAL_FALSE, nullptr, nullptr, 0));
+            CHECK(JS_DefinePropertyById(cx, obj, id, JS::FalseHandleValue, 0));
             objp.set(obj);
             return true;
         }
         if (obj == obj2) {
             CHECK_EQUAL(resolveEntryCount, 4);
             objp.set(nullptr);
             return true;
         }
     } else if (JS_FlatStringEqualsAscii(str, "y")) {
         if (obj == obj2) {
             CHECK_EQUAL(resolveEntryCount, 2);
-            CHECK(JS_DefinePropertyById(cx, obj, id, JSVAL_NULL, nullptr, nullptr, 0));
+            CHECK(JS_DefinePropertyById(cx, obj, id, JS::NullHandleValue, 0));
             EVAL("obj1.x", &v);
             CHECK(v.isUndefined());
             EVAL("obj1.y", &v);
             CHECK_SAME(v, JSVAL_ZERO);
             objp.set(obj);
             return true;
         }
         if (obj == obj1) {
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -2969,42 +2969,132 @@ DefinePropertyById(JSContext *cx, Handle
                             (attrs & JSPROP_SETTER)
                             ? JS_FUNC_TO_DATA_PTR(JSObject *, setter)
                             : nullptr);
 
     return JSObject::defineGeneric(cx, obj, id, value, getter, setter, attrs);
 }
 
 JS_PUBLIC_API(bool)
-JS_DefinePropertyById(JSContext *cx, JSObject *objArg, jsid idArg, jsval valueArg,
-                      JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs)
-{
-    RootedObject obj(cx, objArg);
-    RootedId id(cx, idArg);
-    RootedValue value(cx, valueArg);
+JS_DefinePropertyById(JSContext *cx, HandleObject obj, HandleId id, HandleValue value,
+                      unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    return DefinePropertyById(cx, obj, id, value, GetterWrapper(getter), SetterWrapper(setter),
+                              attrs, 0);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefinePropertyById(JSContext *cx, HandleObject obj, HandleId id, HandleObject valueArg,
+                      unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    RootedValue value(cx, ObjectValue(*valueArg));
+    return DefinePropertyById(cx, obj, id, value, GetterWrapper(getter), SetterWrapper(setter),
+                              attrs, 0);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefinePropertyById(JSContext *cx, HandleObject obj, HandleId id, HandleString valueArg,
+                      unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    RootedValue value(cx, StringValue(valueArg));
     return DefinePropertyById(cx, obj, id, value, GetterWrapper(getter), SetterWrapper(setter),
                               attrs, 0);
 }
 
 JS_PUBLIC_API(bool)
-JS_DefineElement(JSContext *cx, JSObject *objArg, uint32_t index, jsval valueArg,
-                 JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs)
-{
-    RootedObject obj(cx, objArg);
-    RootedValue value(cx, valueArg);
+JS_DefinePropertyById(JSContext *cx, HandleObject obj, HandleId id, int32_t valueArg,
+                      unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    Value value = Int32Value(valueArg);
+    return DefinePropertyById(cx, obj, id, HandleValue::fromMarkedLocation(&value),
+                              GetterWrapper(getter), SetterWrapper(setter), attrs, 0);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefinePropertyById(JSContext *cx, HandleObject obj, HandleId id, uint32_t valueArg,
+                      unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    Value value = UINT_TO_JSVAL(valueArg);
+    return DefinePropertyById(cx, obj, id, HandleValue::fromMarkedLocation(&value),
+                              GetterWrapper(getter), SetterWrapper(setter), attrs, 0);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefinePropertyById(JSContext *cx, HandleObject obj, HandleId id, double valueArg,
+                      unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    Value value = NumberValue(valueArg);
+    return DefinePropertyById(cx, obj, id, HandleValue::fromMarkedLocation(&value),
+                              GetterWrapper(getter), SetterWrapper(setter), attrs, 0);
+}
+
+static bool
+DefineElement(JSContext *cx, HandleObject obj, uint32_t index, HandleValue value,
+              unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
     AutoRooterGetterSetter gsRoot(cx, attrs, &getter, &setter);
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     RootedId id(cx);
     if (!IndexToId(cx, index, &id))
         return false;
     return DefinePropertyById(cx, obj, id, value, GetterWrapper(getter), SetterWrapper(setter),
                               attrs, 0);
 }
 
+JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, HandleObject obj, uint32_t index, HandleValue value,
+                 unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    return DefineElement(cx, obj, index, value, attrs, getter, setter);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, HandleObject obj, uint32_t index, HandleObject valueArg,
+                 unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    RootedValue value(cx, ObjectValue(*valueArg));
+    return DefineElement(cx, obj, index, value, attrs, getter, setter);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, HandleObject obj, uint32_t index, HandleString valueArg,
+                 unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    RootedValue value(cx, StringValue(valueArg));
+    return DefineElement(cx, obj, index, value, attrs, getter, setter);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, HandleObject obj, uint32_t index, int32_t valueArg,
+                 unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    Value value = Int32Value(valueArg);
+    return DefineElement(cx, obj, index, HandleValue::fromMarkedLocation(&value),
+                         attrs, getter, setter);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, HandleObject obj, uint32_t index, uint32_t valueArg,
+                 unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    Value value = UINT_TO_JSVAL(valueArg);
+    return DefineElement(cx, obj, index, HandleValue::fromMarkedLocation(&value),
+                         attrs, getter, setter);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, HandleObject obj, uint32_t index, double valueArg,
+                 unsigned attrs, JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    Value value = NumberValue(valueArg);
+    return DefineElement(cx, obj, index, HandleValue::fromMarkedLocation(&value),
+                         attrs, getter, setter);
+}
+
 static bool
 DefineProperty(JSContext *cx, HandleObject obj, const char *name, HandleValue value,
                const JSPropertyOpWrapper &getter, const JSStrictPropertyOpWrapper &setter,
                unsigned attrs, unsigned flags)
 {
     AutoRooterGetterSetter gsRoot(cx, attrs, const_cast<JSPropertyOp *>(&getter.op),
                                   const_cast<JSStrictPropertyOp *>(&setter.op));
 
@@ -3142,40 +3232,85 @@ DefineUCProperty(JSContext *cx, HandleOb
     if (!atom)
         return false;
     RootedId id(cx, AtomToId(atom));
     return DefinePropertyById(cx, obj, id, value, GetterWrapper(getter), SetterWrapper(setter),
                               attrs, flags);
 }
 
 JS_PUBLIC_API(bool)
-JS_DefineUCProperty(JSContext *cx, JSObject *objArg, const jschar *name, size_t namelen,
-                    jsval valueArg, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs)
-{
-    RootedObject obj(cx, objArg);
-    RootedValue value(cx, valueArg);
+JS_DefineUCProperty(JSContext *cx, HandleObject obj, const jschar *name, size_t namelen,
+                    HandleValue value, unsigned attrs,
+                    JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    return DefineUCProperty(cx, obj, name, namelen, value, getter, setter, attrs, 0);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, HandleObject obj, const jschar *name, size_t namelen,
+                    HandleObject valueArg, unsigned attrs,
+                    JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    RootedValue value(cx, ObjectValue(*valueArg));
+    return DefineUCProperty(cx, obj, name, namelen, value, getter, setter, attrs, 0);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, HandleObject obj, const jschar *name, size_t namelen,
+                    HandleString valueArg, unsigned attrs,
+                    JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    RootedValue value(cx, StringValue(valueArg));
     return DefineUCProperty(cx, obj, name, namelen, value, getter, setter, attrs, 0);
 }
 
 JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, HandleObject obj, const jschar *name, size_t namelen,
+                    int32_t valueArg, unsigned attrs,
+                    JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    Value value = Int32Value(valueArg);
+    return DefineUCProperty(cx, obj, name, namelen, HandleValue::fromMarkedLocation(&value),
+                            getter, setter, attrs, 0);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, HandleObject obj, const jschar *name, size_t namelen,
+                    uint32_t valueArg, unsigned attrs,
+                    JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    Value value = UINT_TO_JSVAL(valueArg);
+    return DefineUCProperty(cx, obj, name, namelen, HandleValue::fromMarkedLocation(&value),
+                            getter, setter, attrs, 0);
+}
+
+JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, HandleObject obj, const jschar *name, size_t namelen,
+                    double valueArg, unsigned attrs,
+                    JSPropertyOp getter, JSStrictPropertyOp setter)
+{
+    Value value = NumberValue(valueArg);
+    return DefineUCProperty(cx, obj, name, namelen, HandleValue::fromMarkedLocation(&value),
+                            getter, setter, attrs, 0);
+}
+
+JS_PUBLIC_API(bool)
 JS_DefineOwnProperty(JSContext *cx, HandleObject obj, HandleId id, HandleValue descriptor, bool *bp)
 {
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, obj, id, descriptor);
 
     return DefineOwnProperty(cx, obj, id, descriptor, bp);
 }
 
 JS_PUBLIC_API(JSObject *)
-JS_DefineObject(JSContext *cx, JSObject *objArg, const char *name, const JSClass *jsclasp,
-                JSObject *protoArg, unsigned attrs)
-{
-    RootedObject obj(cx, objArg);
-    RootedObject proto(cx, protoArg);
+JS_DefineObject(JSContext *cx, HandleObject obj, const char *name, const JSClass *jsclasp,
+                HandleObject proto, unsigned attrs)
+{
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, obj, proto);
 
     const Class *clasp = Valueify(jsclasp);
     if (!clasp)
         clasp = &JSObject::class_;    /* default class is Object */
 
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -2781,18 +2781,19 @@ JS_FreezeObject(JSContext *cx, JS::Handl
 
 extern JS_PUBLIC_API(bool)
 JS_PreventExtensions(JSContext *cx, JS::HandleObject obj);
 
 extern JS_PUBLIC_API(JSObject *)
 JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args);
 
 extern JS_PUBLIC_API(JSObject *)
-JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, const JSClass *clasp,
-                JSObject *proto, unsigned attrs);
+JS_DefineObject(JSContext *cx, JS::HandleObject obj, const char *name,
+                const JSClass *clasp = nullptr, JS::HandleObject proto = JS::NullPtr(),
+                unsigned attrs = 0);
 
 extern JS_PUBLIC_API(bool)
 JS_DefineConstDoubles(JSContext *cx, JS::HandleObject obj, const JSConstDoubleSpec *cds);
 
 extern JS_PUBLIC_API(bool)
 JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps);
 
 extern JS_PUBLIC_API(bool)
@@ -2821,18 +2822,44 @@ JS_DefineProperty(JSContext *cx, JS::Han
                   JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
 
 extern JS_PUBLIC_API(bool)
 JS_DefineProperty(JSContext *cx, JS::HandleObject obj, const char *name, double value,
                   unsigned attrs,
                   JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
 
 extern JS_PUBLIC_API(bool)
-JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value,
-                      JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
+JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value,
+                      unsigned attrs,
+                      JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject value,
+                      unsigned attrs,
+                      JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleString value,
+                      unsigned attrs,
+                      JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, int32_t value,
+                      unsigned attrs,
+                      JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, uint32_t value,
+                      unsigned attrs,
+                      JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefinePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, double value,
+                      unsigned attrs,
+                      JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
 
 extern JS_PUBLIC_API(bool)
 JS_DefineOwnProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
                      JS::HandleValue descriptor, bool *bp);
 
 extern JS_PUBLIC_API(bool)
 JS_AlreadyHasOwnProperty(JSContext *cx, JS::HandleObject obj, const char *name,
                          bool *foundp);
@@ -3043,20 +3070,44 @@ JS_DeleteProperty2(JSContext *cx, JS::Ha
 
 extern JS_PUBLIC_API(bool)
 JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id);
 
 extern JS_PUBLIC_API(bool)
 JS_DeletePropertyById2(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded);
 
 extern JS_PUBLIC_API(bool)
-JS_DefineUCProperty(JSContext *cx, JSObject *obj,
-                    const jschar *name, size_t namelen, jsval value,
-                    JSPropertyOp getter, JSStrictPropertyOp setter,
-                    unsigned attrs);
+JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen,
+                    JS::HandleValue value, unsigned attrs,
+                    JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen,
+                    JS::HandleObject value, unsigned attrs,
+                    JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen,
+                    JS::HandleString value, unsigned attrs,
+                    JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen,
+                    int32_t value, unsigned attrs,
+                    JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen,
+                    uint32_t value, unsigned attrs,
+                    JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name, size_t namelen,
+                    double value, unsigned attrs,
+                    JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
 
 extern JS_PUBLIC_API(bool)
 JS_AlreadyHasOwnUCProperty(JSContext *cx, JS::HandleObject obj, const jschar *name,
                            size_t namelen, bool *foundp);
 
 extern JS_PUBLIC_API(bool)
 JS_HasUCProperty(JSContext *cx, JS::HandleObject obj,
                  const jschar *name, size_t namelen,
@@ -3095,18 +3146,44 @@ JS_IsArrayObject(JSContext *cx, JS::Hand
 
 extern JS_PUBLIC_API(bool)
 JS_GetArrayLength(JSContext *cx, JS::Handle<JSObject*> obj, uint32_t *lengthp);
 
 extern JS_PUBLIC_API(bool)
 JS_SetArrayLength(JSContext *cx, JS::Handle<JSObject*> obj, uint32_t length);
 
 extern JS_PUBLIC_API(bool)
-JS_DefineElement(JSContext *cx, JSObject *obj, uint32_t index, jsval value,
-                 JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
+JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue value,
+                 unsigned attrs,
+                 JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value,
+                 unsigned attrs,
+                 JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value,
+                 unsigned attrs,
+                 JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value,
+                 unsigned attrs,
+                 JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t value,
+                 unsigned attrs,
+                 JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
+
+extern JS_PUBLIC_API(bool)
+JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value,
+                 unsigned attrs,
+                 JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
 
 extern JS_PUBLIC_API(bool)
 JS_AlreadyHasOwnElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp);
 
 extern JS_PUBLIC_API(bool)
 JS_HasElement(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp);
 
 extern JS_PUBLIC_API(bool)
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -1439,17 +1439,17 @@ extern JS_FRIEND_API(void *)
 JS_GetArrayBufferViewData(JSObject *obj);
 
 /*
  * Return the ArrayBuffer underlying an ArrayBufferView. If the buffer has been
  * neutered, this will still return the neutered buffer. |obj| must be an
  * object that would return true for JS_IsArrayBufferViewObject().
  */
 extern JS_FRIEND_API(JSObject *)
-JS_GetArrayBufferViewBuffer(JSContext *cx, JSObject *obj);
+JS_GetArrayBufferViewBuffer(JSContext *cx, JS::HandleObject obj);
 
 typedef enum {
     ChangeData,
     KeepData
 } NeuterDataDisposition;
 
 /*
  * Set an ArrayBuffer's length to 0 and neuter all of its views.
@@ -2055,17 +2055,18 @@ DefaultValue(JSContext *cx, JS::HandleOb
  * but only if obj is native.
  *
  * The reason for the messiness here is that ES5 uses [[DefineOwnProperty]] as
  * a sort of extension point, but there is no hook in js::Class,
  * js::ProxyHandler, or the JSAPI with precisely the right semantics for it.
  */
 extern JS_FRIEND_API(bool)
 CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value,
-                    JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
+                    unsigned attrs,
+                    JSPropertyOp getter = nullptr, JSStrictPropertyOp setter = nullptr);
 
 } /* namespace js */
 
 extern JS_FRIEND_API(bool)
 js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg,
                      JS::Handle<JSPropertyDescriptor> descriptor, bool *bp);
 
 extern JS_FRIEND_API(bool)
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -502,17 +502,17 @@ Reject(JSContext *cx, HandleId id, unsig
 }
 
 // See comments on CheckDefineProperty in jsobj.h.
 //
 // DefinePropertyOnObject has its own implementation of these checks.
 //
 JS_FRIEND_API(bool)
 js::CheckDefineProperty(JSContext *cx, HandleObject obj, HandleId id, HandleValue value,
-                        PropertyOp getter, StrictPropertyOp setter, unsigned attrs)
+                        unsigned attrs, PropertyOp getter, StrictPropertyOp setter)
 {
     if (!obj->isNative())
         return true;
 
     // ES5 8.12.9 Step 1. Even though we know obj is native, we use generic
     // APIs for shorter, more readable code.
     Rooted<PropertyDescriptor> desc(cx);
     if (!GetOwnPropertyDescriptor(cx, obj, id, &desc))
--- a/js/src/jsproxy.cpp
+++ b/js/src/jsproxy.cpp
@@ -404,18 +404,18 @@ DirectProxyHandler::getOwnPropertyDescri
 
 bool
 DirectProxyHandler::defineProperty(JSContext *cx, HandleObject proxy, HandleId id,
                                    MutableHandle<PropertyDescriptor> desc)
 {
     assertEnteredPolicy(cx, proxy, id, SET);
     RootedObject target(cx, proxy->as<ProxyObject>().target());
     RootedValue v(cx, desc.value());
-    return CheckDefineProperty(cx, target, id, v, desc.getter(), desc.setter(), desc.attributes()) &&
-           JS_DefinePropertyById(cx, target, id, v, desc.getter(), desc.setter(), desc.attributes());
+    return CheckDefineProperty(cx, target, id, v, desc.attributes(), desc.getter(), desc.setter()) &&
+           JS_DefinePropertyById(cx, target, id, v, desc.attributes(), desc.getter(), desc.setter());
 }
 
 bool
 DirectProxyHandler::getOwnPropertyNames(JSContext *cx, HandleObject proxy,
                                         AutoIdVector &props)
 {
     assertEnteredPolicy(cx, proxy, JSID_VOID, ENUMERATE);
     RootedObject target(cx, proxy->as<ProxyObject>().target());
@@ -1472,18 +1472,18 @@ TrapDefineOwnProperty(JSContext *cx, Han
     if (!JSObject::getProperty(cx, handler, handler, cx->names().defineProperty, &trap))
         return false;
 
     // step 4
     if (trap.isUndefined()) {
         Rooted<PropertyDescriptor> desc(cx);
         if (!ParsePropertyDescriptorObject(cx, proxy, vp, &desc))
             return false;
-        return JS_DefinePropertyById(cx, target, id, desc.value(), desc.getter(), desc.setter(),
-                                     desc.attributes());
+        return JS_DefinePropertyById(cx, target, id, desc.value(), desc.attributes(),
+                                     desc.getter(), desc.setter());
     }
 
     // step 5
     RootedValue normalizedDesc(cx, vp);
     if (!NormalizePropertyDescriptor(cx, &normalizedDesc))
         return false;
 
     // step 6
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -5774,20 +5774,20 @@ BindScriptArgs(JSContext *cx, JSObject *
     if (!scriptArgs)
         return false;
 
     if (!JS_DefineProperty(cx, obj, "scriptArgs", scriptArgs, 0))
         return false;
 
     for (size_t i = 0; !msr.empty(); msr.popFront(), ++i) {
         const char *scriptArg = msr.front();
-        JSString *str = JS_NewStringCopyZ(cx, scriptArg);
+        JS::RootedString str(cx, JS_NewStringCopyZ(cx, scriptArg));
         if (!str ||
-            !JS_DefineElement(cx, scriptArgs, i, STRING_TO_JSVAL(str), nullptr, nullptr,
-                              JSPROP_ENUMERATE)) {
+            !JS_DefineElement(cx, scriptArgs, i, str, JSPROP_ENUMERATE))
+        {
             return false;
         }
     }
 
     return true;
 }
 
 // This function is currently only called from "#if defined(JS_ION)" chunks,
@@ -6035,17 +6035,17 @@ Shell(JSContext *cx, OptionParser *op, c
     options.setVersion(JSVERSION_LATEST);
     glob = NewGlobalObject(cx, options, nullptr);
     if (!glob)
         return 1;
 
     JSAutoCompartment ac(cx, glob);
     js::SetDefaultObjectForContext(cx, glob);
 
-    JSObject *envobj = JS_DefineObject(cx, glob, "environment", &env_class, nullptr, 0);
+    JSObject *envobj = JS_DefineObject(cx, glob, "environment", &env_class);
     if (!envobj)
         return 1;
     JS_SetPrivate(envobj, envp);
 
     int result = ProcessArgs(cx, glob, op);
 
     if (enableDisassemblyDumps)
         JS_DumpCompartmentPCCounts(cx);
--- a/js/src/vm/ArrayBufferObject.cpp
+++ b/js/src/vm/ArrayBufferObject.cpp
@@ -1128,19 +1128,19 @@ JS_GetArrayBufferViewData(JSObject *obj)
     obj = CheckedUnwrap(obj);
     if (!obj)
         return nullptr;
     return obj->is<DataViewObject>() ? obj->as<DataViewObject>().dataPointer()
                                      : obj->as<TypedArrayObject>().viewData();
 }
 
 JS_FRIEND_API(JSObject *)
-JS_GetArrayBufferViewBuffer(JSContext *cx, JSObject *obj)
+JS_GetArrayBufferViewBuffer(JSContext *cx, HandleObject objArg)
 {
-    obj = CheckedUnwrap(obj);
+    JSObject *obj = CheckedUnwrap(objArg);
     if (!obj)
         return nullptr;
     Rooted<ArrayBufferViewObject *> viewObject(cx, &obj->as<ArrayBufferViewObject>());
     return ArrayBufferViewObject::bufferObject(cx, viewObject);
 }
 
 JS_FRIEND_API(uint32_t)
 JS_GetArrayBufferViewByteLength(JSObject *obj)
--- a/js/src/vm/ScopeObject.cpp
+++ b/js/src/vm/ScopeObject.cpp
@@ -1399,18 +1399,17 @@ class DebugScopeProxy : public BaseProxy
         Rooted<ScopeObject*> scope(cx, &proxy->as<DebugScopeObject>().scope());
 
         bool found;
         if (!has(cx, proxy, id, &found))
             return false;
         if (found)
             return Throw(cx, id, JSMSG_CANT_REDEFINE_PROP);
 
-        return JS_DefinePropertyById(cx, scope, id, desc.value(), desc.getter(), desc.setter(),
-                                     desc.attributes());
+        return JS_DefinePropertyById(cx, scope, id, desc.value(), desc.attributes(), desc.getter(), desc.setter());
     }
 
     bool getScopePropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props,
                                unsigned flags)
     {
         Rooted<ScopeObject*> scope(cx, &proxy->as<DebugScopeObject>().scope());
 
         if (isMissingArgumentsBinding(*scope)) {
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -1080,17 +1080,17 @@ CloneProperties(JSContext *cx, HandleObj
     RootedId id(cx);
     RootedValue val(cx);
     RootedValue selfHostedValue(cx);
     for (uint32_t i = 0; i < ids.length(); i++) {
         id = ids[i];
         if (!GetUnclonedValue(cx, selfHostedObject, id, &selfHostedValue))
             return false;
         if (!CloneValue(cx, selfHostedValue, &val) ||
-            !JS_DefinePropertyById(cx, clone, id, val.get(), nullptr, nullptr, 0))
+            !JS_DefinePropertyById(cx, clone, id, val, 0))
         {
             return false;
         }
     }
 
     return true;
 }
 
--- a/js/src/vm/Value.cpp
+++ b/js/src/vm/Value.cpp
@@ -12,10 +12,12 @@ const jsval JSVAL_ONE   = IMPL_TO_JSVAL(
 const jsval JSVAL_FALSE = IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_BOOLEAN,   false));
 const jsval JSVAL_TRUE  = IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_BOOLEAN,   true));
 const jsval JSVAL_VOID  = IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0));
 
 namespace JS {
 
 const HandleValue NullHandleValue = HandleValue::fromMarkedLocation(&JSVAL_NULL);
 const HandleValue UndefinedHandleValue = HandleValue::fromMarkedLocation(&JSVAL_VOID);
+const HandleValue TrueHandleValue = HandleValue::fromMarkedLocation(&JSVAL_TRUE);
+const HandleValue FalseHandleValue = HandleValue::fromMarkedLocation(&JSVAL_FALSE);
 
 } // namespace JS
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -316,19 +316,18 @@ ExportFunction(JSContext *cx, HandleValu
             JS_ReportError(cx, "Exporting function failed");
             return false;
         }
 
         // We have the forwarder function in the target compartment. If
         // defineAs was set, we also need to define it as a property on
         // the target.
         if (!JSID_IS_VOID(options.defineAs)) {
-            if (!JS_DefinePropertyById(cx, targetScope, id, rval,
-                                       JS_PropertyStub, JS_StrictPropertyStub,
-                                       JSPROP_ENUMERATE)) {
+            if (!JS_DefinePropertyById(cx, targetScope, id, rval, JSPROP_ENUMERATE,
+                                       JS_PropertyStub, JS_StrictPropertyStub)) {
                 return false;
             }
         }
     }
 
     // Finally we have to re-wrap the exported function back to the caller compartment.
     if (!JS_WrapValue(cx, rval))
         return false;
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -318,19 +318,17 @@ nsXPCComponents_Interfaces::NewResolve(n
                                              static_cast<nsIJSIID*>(nsid),
                                              NS_GET_IID(nsIJSIID),
                                              getter_AddRefs(holder)))) {
                 RootedObject idobj(cx);
                 if (holder &&
                     // Assign, not compare
                     (idobj = holder->GetJSObject())) {
                     *objp = obj;
-                    *_retval = JS_DefinePropertyById(cx, obj, id,
-                                                     OBJECT_TO_JSVAL(idobj),
-                                                     nullptr, nullptr,
+                    *_retval = JS_DefinePropertyById(cx, obj, id, idobj,
                                                      JSPROP_ENUMERATE |
                                                      JSPROP_READONLY |
                                                      JSPROP_PERMANENT);
                 }
             }
         }
     }
     return NS_OK;
@@ -574,19 +572,17 @@ nsXPCComponents_InterfacesByID::NewResol
                                             NS_GET_IID(nsIJSIID),
                                             getter_AddRefs(holder)))) {
             RootedObject idobj(cx);
             if (holder &&
                 // Assign, not compare
                 (idobj = holder->GetJSObject())) {
                 *objp = obj;
                 *_retval =
-                    JS_DefinePropertyById(cx, obj, id,
-                                          OBJECT_TO_JSVAL(idobj),
-                                          nullptr, nullptr,
+                    JS_DefinePropertyById(cx, obj, id, idobj,
                                           JSPROP_ENUMERATE |
                                           JSPROP_READONLY |
                                           JSPROP_PERMANENT);
             }
         }
     }
     return NS_OK;
 }
@@ -816,19 +812,17 @@ nsXPCComponents_Classes::NewResolve(nsIX
                                              static_cast<nsIJSCID*>(nsid),
                                              NS_GET_IID(nsIJSCID),
                                              getter_AddRefs(holder)))) {
                 RootedObject idobj(cx);
                 if (holder &&
                     // Assign, not compare
                         (idobj = holder->GetJSObject())) {
                     *objp = obj;
-                    *_retval = JS_DefinePropertyById(cx, obj, id,
-                                                     OBJECT_TO_JSVAL(idobj),
-                                                     nullptr, nullptr,
+                    *_retval = JS_DefinePropertyById(cx, obj, id, idobj,
                                                      JSPROP_ENUMERATE |
                                                      JSPROP_READONLY |
                                                      JSPROP_PERMANENT);
                 }
             }
         }
     }
     return NS_OK;
@@ -1077,19 +1071,17 @@ nsXPCComponents_ClassesByID::NewResolve(
                                              static_cast<nsIJSCID*>(nsid),
                                              NS_GET_IID(nsIJSCID),
                                              getter_AddRefs(holder)))) {
                 RootedObject idobj(cx);
                 if (holder &&
                     // Assign, not compare
                     (idobj = holder->GetJSObject())) {
                     *objp = obj;
-                    *_retval = JS_DefinePropertyById(cx, obj, id,
-                                                     ObjectValue(*idobj),
-                                                     nullptr, nullptr,
+                    *_retval = JS_DefinePropertyById(cx, obj, id, idobj,
                                                      JSPROP_ENUMERATE |
                                                      JSPROP_READONLY |
                                                      JSPROP_PERMANENT);
                 }
             }
         }
     }
     return NS_OK;
@@ -1298,21 +1290,18 @@ nsXPCComponents_Results::NewResolve(nsIX
     JSAutoByteString name;
 
     if (JSID_IS_STRING(id) && name.encodeLatin1(cx, JSID_TO_STRING(id))) {
         const char* rv_name;
         const void* iter = nullptr;
         nsresult rv;
         while (nsXPCException::IterateNSResults(&rv, &rv_name, nullptr, &iter)) {
             if (!strcmp(name.ptr(), rv_name)) {
-                jsval val = JS_NumberValue((double)rv);
-
                 *objp = obj;
-                if (!JS_DefinePropertyById(cx, obj, id, val,
-                                           nullptr, nullptr,
+                if (!JS_DefinePropertyById(cx, obj, id, (uint32_t)rv,
                                            JSPROP_ENUMERATE |
                                            JSPROP_READONLY |
                                            JSPROP_PERMANENT)) {
                     return NS_ERROR_UNEXPECTED;
                 }
             }
         }
     }
@@ -2957,19 +2946,18 @@ xpc::CreateObjectIn(JSContext *cx, Handl
     RootedObject obj(cx);
     {
         JSAutoCompartment ac(cx, scope);
         obj = JS_NewObject(cx, nullptr, JS::NullPtr(), scope);
         if (!obj)
             return false;
 
         if (define) {
-            if (!JS_DefinePropertyById(cx, scope, options.defineAs, ObjectValue(*obj),
-                                       JS_PropertyStub, JS_StrictPropertyStub,
-                                       JSPROP_ENUMERATE))
+            if (!JS_DefinePropertyById(cx, scope, options.defineAs, obj, JSPROP_ENUMERATE,
+                                       JS_PropertyStub, JS_StrictPropertyStub))
                 return false;
         }
     }
 
     rval.setObject(*obj);
     if (!WrapperFactory::WaiveXrayAndWrap(cx, rval))
         return false;
 
--- a/js/xpconnect/src/XPCJSID.cpp
+++ b/js/xpconnect/src/XPCJSID.cpp
@@ -402,17 +402,17 @@ nsJSIID::NewResolve(nsIXPConnectWrappedN
 
     XPCNativeMember* member = iface->FindMember(id);
     if (member && member->IsConstant()) {
         RootedValue val(cx);
         if (!member->GetConstantValue(ccx, iface, val.address()))
             return NS_ERROR_OUT_OF_MEMORY;
 
         *objp = obj;
-        *_retval = JS_DefinePropertyById(cx, obj, id, val, nullptr, nullptr,
+        *_retval = JS_DefinePropertyById(cx, obj, id, val,
                                          JSPROP_ENUMERATE | JSPROP_READONLY |
                                          JSPROP_PERMANENT);
     }
 
     return NS_OK;
 }
 
 /* bool enumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); */
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -824,35 +824,34 @@ env_enumerate(JSContext *cx, HandleObjec
     reflected = true;
     return true;
 }
 
 static bool
 env_resolve(JSContext *cx, HandleObject obj, HandleId id,
             JS::MutableHandleObject objp)
 {
-    JSString *idstr, *valstr;
+    JSString *idstr;
 
     RootedValue idval(cx);
     if (!JS_IdToValue(cx, id, &idval))
         return false;
 
     idstr = ToString(cx, idval);
     if (!idstr)
         return false;
     JSAutoByteString name(cx, idstr);
     if (!name)
         return false;
     const char *value = getenv(name.ptr());
     if (value) {
-        valstr = JS_NewStringCopyZ(cx, value);
+        RootedString valstr(cx, JS_NewStringCopyZ(cx, value));
         if (!valstr)
             return false;
-        if (!JS_DefinePropertyById(cx, obj, id, STRING_TO_JSVAL(valstr),
-                                   nullptr, nullptr, JSPROP_ENUMERATE)) {
+        if (!JS_DefinePropertyById(cx, obj, id, valstr, JSPROP_ENUMERATE)) {
             return false;
         }
         objp.set(obj);
     }
     return true;
 }
 
 static const JSClass env_class = {
@@ -1089,21 +1088,19 @@ ProcessArgs(JSContext *cx, JS::Handle<JS
      */
     argsObj = JS_NewArrayObject(cx, 0);
     if (!argsObj)
         return 1;
     if (!JS_DefineProperty(cx, obj, "arguments", argsObj, 0))
         return 1;
 
     for (size_t j = 0, length = argc - i; j < length; j++) {
-        JSString *str = JS_NewStringCopyZ(cx, argv[i++]);
-        if (!str)
-            return 1;
-        if (!JS_DefineElement(cx, argsObj, j, STRING_TO_JSVAL(str),
-                              nullptr, nullptr, JSPROP_ENUMERATE)) {
+        RootedString str(cx, JS_NewStringCopyZ(cx, argv[i++]));
+        if (!str ||
+            !JS_DefineElement(cx, argsObj, j, str, JSPROP_ENUMERATE)) {
             return 1;
         }
     }
 
     for (i = 0; i < argc; i++) {
         if (argv[i][0] != '-' || argv[i][1] == '\0') {
             filename = argv[i++];
             isInteractive = false;
@@ -1567,17 +1564,17 @@ XRE_XPCShellMain(int argc, char **argv, 
 
             if (!JS_DefineFunctions(cx, glob, glob_functions) ||
                 !JS_DefineProfilingFunctions(cx, glob)) {
                 JS_EndRequest(cx);
                 return 1;
             }
 
             JS::Rooted<JSObject*> envobj(cx);
-            envobj = JS_DefineObject(cx, glob, "environment", &env_class, nullptr, 0);
+            envobj = JS_DefineObject(cx, glob, "environment", &env_class);
             if (!envobj) {
                 JS_EndRequest(cx);
                 return 1;
             }
 
             JS_SetPrivate(envobj, envp);
 
             nsAutoString workingDirectory;
--- a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp
@@ -243,19 +243,18 @@ DefinePropertyIfFound(XPCCallContext& cc
                 if (!fun) {
                     JS_ReportOutOfMemory(ccx);
                     return false;
                 }
 
                 AutoResolveName arn(ccx, id);
                 if (resolved)
                     *resolved = true;
-                return JS_DefinePropertyById(ccx, obj, id,
-                                             OBJECT_TO_JSVAL(JS_GetFunctionObject(fun)),
-                                             nullptr, nullptr,
+                RootedObject value(ccx, JS_GetFunctionObject(fun));
+                return JS_DefinePropertyById(ccx, obj, id, value,
                                              propFlags & ~JSPROP_ENUMERATE);
             }
         }
         // This *might* be a tearoff name that is not yet part of our
         // set. Let's lookup the name and see if it is the name of an
         // interface. Then we'll see if the object actually *does* this
         // interface and add a tearoff as necessary.
 
@@ -272,18 +271,17 @@ DefinePropertyIfFound(XPCCallContext& cc
                 nullptr != (to = wrapperToReflectInterfaceNames->
                            FindTearOff(iface2, true, &rv)) &&
                 nullptr != (jso = to->GetJSObject()))
 
             {
                 AutoResolveName arn(ccx, id);
                 if (resolved)
                     *resolved = true;
-                return JS_DefinePropertyById(ccx, obj, id, OBJECT_TO_JSVAL(jso),
-                                             nullptr, nullptr,
+                return JS_DefinePropertyById(ccx, obj, id, jso,
                                              propFlags & ~JSPROP_ENUMERATE);
             } else if (NS_FAILED(rv) && rv != NS_ERROR_NO_INTERFACE) {
                 return Throw(rv, ccx);
             }
         }
 
         // This *might* be a double wrapped JSObject
         if (wrapperToReflectDoubleWrap &&
@@ -308,20 +306,19 @@ DefinePropertyIfFound(XPCCallContext& cc
                 return false;
 
             propFlags |= JSPROP_GETTER;
             propFlags &= ~JSPROP_ENUMERATE;
 
             AutoResolveName arn(ccx, id);
             if (resolved)
                 *resolved = true;
-            return JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID,
-                                         JS_DATA_TO_FUNC_PTR(JSPropertyOp,
-                                                             funobj.get()),
-                                         nullptr, propFlags);
+            return JS_DefinePropertyById(ccx, obj, id, UndefinedHandleValue, propFlags,
+                                         JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj.get()),
+                                         nullptr);
         }
 
         if (resolved)
             *resolved = false;
         return true;
     }
 
     if (!member) {
@@ -333,33 +330,31 @@ DefinePropertyIfFound(XPCCallContext& cc
                 return false;
             RootedObject jso(ccx, to->GetJSObject());
             if (!jso)
                 return false;
 
             AutoResolveName arn(ccx, id);
             if (resolved)
                 *resolved = true;
-            return JS_DefinePropertyById(ccx, obj, id, OBJECT_TO_JSVAL(jso),
-                                         nullptr, nullptr,
+            return JS_DefinePropertyById(ccx, obj, id, jso,
                                          propFlags & ~JSPROP_ENUMERATE);
         }
         if (resolved)
             *resolved = false;
         return true;
     }
 
     if (member->IsConstant()) {
         RootedValue val(ccx);
         AutoResolveName arn(ccx, id);
         if (resolved)
             *resolved = true;
         return member->GetConstantValue(ccx, iface, val.address()) &&
-               JS_DefinePropertyById(ccx, obj, id, val, nullptr, nullptr,
-                                     propFlags);
+               JS_DefinePropertyById(ccx, obj, id, val, propFlags);
     }
 
     if (id == rt->GetStringID(XPCJSRuntime::IDX_TO_STRING) ||
         id == rt->GetStringID(XPCJSRuntime::IDX_TO_SOURCE) ||
         (scriptableInfo &&
          scriptableInfo->GetFlags().DontEnumQueryInterface() &&
          id == rt->GetStringID(XPCJSRuntime::IDX_QUERY_INTERFACE)))
         propFlags &= ~JSPROP_ENUMERATE;
@@ -367,18 +362,17 @@ DefinePropertyIfFound(XPCCallContext& cc
     RootedValue funval(ccx);
     if (!member->NewFunctionObject(ccx, iface, obj, funval.address()))
         return false;
 
     if (member->IsMethod()) {
         AutoResolveName arn(ccx, id);
         if (resolved)
             *resolved = true;
-        return JS_DefinePropertyById(ccx, obj, id, funval, nullptr, nullptr,
-                                     propFlags);
+        return JS_DefinePropertyById(ccx, obj, id, funval, propFlags);
     }
 
     // else...
 
     MOZ_ASSERT(member->IsAttribute(), "way broken!");
 
     propFlags |= JSPROP_GETTER | JSPROP_SHARED;
     JSObject* funobj = funval.toObjectOrNull();
@@ -391,18 +385,17 @@ DefinePropertyIfFound(XPCCallContext& cc
     } else {
         setter = js_GetterOnlyPropertyStub;
     }
 
     AutoResolveName arn(ccx, id);
     if (resolved)
         *resolved = true;
 
-    return JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID, getter, setter,
-                                 propFlags);
+    return JS_DefinePropertyById(ccx, obj, id, UndefinedHandleValue, propFlags, getter, setter);
 }
 
 /***************************************************************************/
 /***************************************************************************/
 
 static bool
 XPC_WN_OnlyIWrite_AddPropertyStub(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue vp)
 {
--- a/js/xpconnect/src/XPCWrappedNativeScope.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp
@@ -178,18 +178,18 @@ XPCWrappedNativeScope::AttachComponentsO
     RootedObject components(aCx, GetComponentsJSObject());
     if (!components)
         return false;
 
     RootedObject global(aCx, GetGlobalJSObject());
     MOZ_ASSERT(js::IsObjectInContextCompartment(global, aCx));
 
     RootedId id(aCx, XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS));
-    return JS_DefinePropertyById(aCx, global, id, ObjectValue(*components),
-                                 nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY);
+    return JS_DefinePropertyById(aCx, global, id, components,
+                                 JSPROP_PERMANENT | JSPROP_READONLY);
 }
 
 JSObject*
 XPCWrappedNativeScope::EnsureXBLScope(JSContext *cx)
 {
     JS::RootedObject global(cx, GetGlobalJSObject());
     MOZ_ASSERT(js::IsObjectInContextCompartment(global, cx));
     MOZ_ASSERT(!mIsXBLScope);
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -470,19 +470,18 @@ JSXrayTraits::resolveOwnProperty(JSConte
                                                    0, wrapper, id));
     if (!fun)
         return false;
 
     // The generic Xray machinery only defines non-own properties on the holder.
     // This is broken, and will be fixed at some point, but for now we need to
     // cache the value explicitly. See the corresponding call to
     // JS_GetPropertyById at the top of this function.
-    return JS_DefinePropertyById(cx, holder, id,
-                                 ObjectValue(*JS_GetFunctionObject(fun)),
-                                 nullptr, nullptr, 0) &&
+    RootedValue value(cx, ObjectValue(*JS_GetFunctionObject(fun)));
+    return JS_DefinePropertyById(cx, holder, id, value, 0) &&
            JS_GetPropertyDescriptorById(cx, holder, id, desc);
 }
 
 bool
 JSXrayTraits::enumerateNames(JSContext *cx, HandleObject wrapper, unsigned flags,
                              AutoIdVector &props)
 {
     RootedObject holder(cx, ensureHolder(cx, wrapper));
@@ -1097,18 +1096,18 @@ XPCWrappedNativeXrayTraits::resolveNativ
         return false;
 
     if (desc.hasGetterObject())
         desc.setGetterObject(&fval.toObject());
     if (desc.hasSetterObject())
         desc.setSetterObject(&fval.toObject());
 
     // Define the property.
-    return JS_DefinePropertyById(cx, holder, id, desc.value(),
-                                 desc.getter(), desc.setter(), desc.attributes());
+    return JS_DefinePropertyById(cx, holder, id, desc.value(), desc.attributes(),
+                                 desc.getter(), desc.setter());
 }
 
 static bool
 wrappedJSObject_getter(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp)
 {
     if (!IsWrapper(wrapper) || !WrapperFactory::IsXrayWrapper(wrapper)) {
         JS_ReportError(cx, "Unexpected object");
         return false;
@@ -1169,19 +1168,19 @@ XrayTraits::resolveOwnProperty(JSContext
 
     // Handle .wrappedJSObject for subsuming callers. This should move once we
     // sort out own-ness for the holder.
     if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_WRAPPED_JSOBJECT) &&
         AccessCheck::wrapperSubsumes(wrapper))
     {
         if (!JS_AlreadyHasOwnPropertyById(cx, holder, id, &found))
             return false;
-        if (!found && !JS_DefinePropertyById(cx, holder, id, UndefinedValue(),
-                                             wrappedJSObject_getter, nullptr,
-                                             JSPROP_ENUMERATE | JSPROP_SHARED)) {
+        if (!found && !JS_DefinePropertyById(cx, holder, id, UndefinedHandleValue,
+                                             JSPROP_ENUMERATE | JSPROP_SHARED,
+                                             wrappedJSObject_getter)) {
             return false;
         }
         if (!JS_GetPropertyDescriptorById(cx, holder, id, desc))
             return false;
         desc.object().set(wrapper);
         return true;
     }
 
@@ -1279,28 +1278,28 @@ XPCWrappedNativeXrayTraits::resolveOwnPr
 }
 
 bool
 XPCWrappedNativeXrayTraits::defineProperty(JSContext *cx, HandleObject wrapper, HandleId id,
                                            MutableHandle<JSPropertyDescriptor> desc,
                                            Handle<JSPropertyDescriptor> existingDesc, bool *defined)
 {
     *defined = false;
-    JSObject *holder = singleton.ensureHolder(cx, wrapper);
+    RootedObject holder(cx, singleton.ensureHolder(cx, wrapper));
     if (isResolving(cx, holder, id)) {
         if (!desc.hasAttributes(JSPROP_GETTER | JSPROP_SETTER)) {
             if (!desc.getter())
                 desc.setGetter(holder_get);
             if (!desc.setter())
                 desc.setSetter(holder_set);
         }
 
         *defined = true;
-        return JS_DefinePropertyById(cx, holder, id, desc.value(), desc.getter(), desc.setter(),
-                                     desc.attributes());
+        return JS_DefinePropertyById(cx, holder, id, desc.value(), desc.attributes(),
+                                     desc.getter(), desc.setter());
     }
 
     // Check for an indexed property on a Window.  If that's happening, do
     // nothing but claim we defined it so it won't get added as an expando.
     int32_t index = GetArrayIndexFromId(cx, id);
     if (IsArrayIndex(index) && IsWindow(cx, wrapper)) {
         *defined = true;
         return true;
@@ -1883,18 +1882,18 @@ XrayWrapper<Base, Traits>::getPropertyDe
             return false;
         DEBUG_CheckXBLLookup(cx, desc.address());
     }
 
     // If we still have nothing, we're done.
     if (!desc.object())
         return true;
 
-    if (!JS_DefinePropertyById(cx, holder, id, desc.value(), desc.getter(),
-                               desc.setter(), desc.attributes()) ||
+    if (!JS_DefinePropertyById(cx, holder, id, desc.value(), desc.attributes(),
+                               desc.getter(), desc.setter()) ||
         !JS_GetPropertyDescriptorById(cx, holder, id, desc))
     {
         return false;
     }
     MOZ_ASSERT(desc.object());
     desc.object().set(wrapper);
     return true;
 }
@@ -2016,18 +2015,18 @@ XrayWrapper<Base, Traits>::definePropert
     if (!JS_WrapPropertyDescriptor(cx, &wrappedDesc))
         return false;
 
     // Fix up Xray waivers.
     if (!RecreateLostWaivers(cx, desc.address(), &wrappedDesc))
         return false;
 
     return JS_DefinePropertyById(cx, expandoObject, id, wrappedDesc.value(),
-                                 wrappedDesc.getter(), wrappedDesc.setter(),
-                                 wrappedDesc.get().attrs);
+                                 wrappedDesc.get().attrs,
+                                 wrappedDesc.getter(), wrappedDesc.setter());
 }
 
 template <typename Base, typename Traits>
 bool
 XrayWrapper<Base, Traits>::getOwnPropertyNames(JSContext *cx, HandleObject wrapper,
                                                AutoIdVector &props)
 {
     assertEnteredPolicy(cx, wrapper, JSID_VOID, BaseProxyHandler::ENUMERATE);
--- a/storage/src/mozStorageAsyncStatementParams.cpp
+++ b/storage/src/mozStorageAsyncStatementParams.cpp
@@ -99,26 +99,25 @@ AsyncStatementParams::NewResolve(
   // prototype chain to be checked for the property.
 
   bool resolved = false;
   bool ok = true;
   if (JSID_IS_INT(aId)) {
     uint32_t idx = JSID_TO_INT(aId);
     // All indexes are good because we don't know how many parameters there
     // really are.
-    ok = ::JS_DefineElement(aCtx, scopeObj, idx, JSVAL_VOID, nullptr,
-                            nullptr, 0);
+    ok = ::JS_DefineElement(aCtx, scopeObj, idx, JS::UndefinedHandleValue, 0);
     resolved = true;
   }
   else if (JSID_IS_STRING(aId)) {
     // We are unable to tell if there's a parameter with this name and so
     // we must assume that there is.  This screws the rest of the prototype
     // chain, but people really shouldn't be depending on this anyways.
-    ok = ::JS_DefinePropertyById(aCtx, scopeObj, aId, JSVAL_VOID, nullptr,
-                                 nullptr, 0);
+    JS::Rooted<jsid> id(aCtx, aId);
+    ok = ::JS_DefinePropertyById(aCtx, scopeObj, id, JS::UndefinedHandleValue, 0);
     resolved = true;
   }
 
   *_retval = ok;
   *_objp = resolved && ok ? scopeObj.get() : nullptr;
   return NS_OK;
 }
 
--- a/storage/src/mozStorageStatementParams.cpp
+++ b/storage/src/mozStorageStatementParams.cpp
@@ -172,34 +172,32 @@ StatementParams::NewResolve(nsIXPConnect
   if (JSID_IS_INT(id)) {
     uint32_t idx = JSID_TO_INT(id);
 
     // Ensure that our index is within range.  We do not care about the
     // prototype chain being checked here.
     if (idx >= mParamCount)
       return NS_ERROR_INVALID_ARG;
 
-    ok = ::JS_DefineElement(aCtx, scope, idx, JSVAL_VOID, nullptr,
-                            nullptr, JSPROP_ENUMERATE);
+    ok = ::JS_DefineElement(aCtx, scope, idx, JS::UndefinedHandleValue, JSPROP_ENUMERATE);
     resolved = true;
   }
   else if (JSID_IS_STRING(id)) {
     JSString *str = JSID_TO_STRING(id);
     size_t nameLength;
     const jschar *nameChars = JS_GetStringCharsAndLength(aCtx, str, &nameLength);
     NS_ENSURE_TRUE(nameChars, NS_ERROR_UNEXPECTED);
 
     // Check to see if there's a parameter with this name, and if not, let
     // the rest of the prototype chain be checked.
     NS_ConvertUTF16toUTF8 name(nameChars, nameLength);
     uint32_t idx;
     nsresult rv = mStatement->GetParameterIndex(name, &idx);
     if (NS_SUCCEEDED(rv)) {
-      ok = ::JS_DefinePropertyById(aCtx, scope, id, JSVAL_VOID, nullptr,
-                                   nullptr, JSPROP_ENUMERATE);
+      ok = ::JS_DefinePropertyById(aCtx, scope, id, JS::UndefinedHandleValue, JSPROP_ENUMERATE);
       resolved = true;
     }
   }
 
   *_retval = ok;
   *_objp = resolved && ok ? scope.get() : nullptr;
   return NS_OK;
 }
--- a/storage/src/mozStorageStatementRow.cpp
+++ b/storage/src/mozStorageStatementRow.cpp
@@ -136,18 +136,18 @@ StatementRow::NewResolve(nsIXPConnectWra
     if (NS_FAILED(rv)) {
       // It's highly likely that the name doesn't exist, so let the JS engine
       // check the prototype chain and throw if that doesn't have the property
       // either.
       *_objp = nullptr;
       return NS_OK;
     }
 
-    *_retval = ::JS_DefinePropertyById(aCtx, scopeObj, aId, JSVAL_VOID,
-                                     nullptr, nullptr, 0);
+    JS::Rooted<jsid> id(aCtx, aId);
+    *_retval = ::JS_DefinePropertyById(aCtx, scopeObj, id, JS::UndefinedHandleValue, 0);
     *_objp = scopeObj;
     return NS_OK;
   }
 
   return NS_OK;
 }
 
 } // namespace storage
--- a/toolkit/components/places/History.cpp
+++ b/toolkit/components/places/History.cpp
@@ -246,17 +246,17 @@ GetJSArrayFromJSValue(JS::Handle<JS::Val
   }
 
   // Build a temporary array to store this one item so the code below can
   // just loop.
   *_arrayLength = 1;
   _array.set(JS_NewArrayObject(aCtx, 0));
   NS_ENSURE_TRUE(_array, NS_ERROR_OUT_OF_MEMORY);
 
-  bool rc = JS_DefineElement(aCtx, _array, 0, aValue, nullptr, nullptr, 0);
+  bool rc = JS_DefineElement(aCtx, _array, 0, aValue, 0);
   NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
   return NS_OK;
 }
 
 /**
  * Attemps to convert a given js value to a nsIURI object.
  * @param aCtx
  *        The JSContext for aValue.
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -511,26 +511,25 @@ bool TelemetryIOInterposeObserver::Refle
     JS::RootedObject jsStats(cx, JS_NewArrayObject(cx, stats));
     if (!jsStats) {
       continue;
     }
 
     stages[s].setObject(*jsStats);
   }
 
-  JS::RootedObject jsEntry(cx, JS_NewArrayObject(cx, stages));
+  JS::Rooted<JSObject*> jsEntry(cx, JS_NewArrayObject(cx, stages));
   if (!jsEntry) {
     return false;
   }
 
   // Add jsEntry to top-level dictionary
   const nsAString& key = entry->GetKey();
   return JS_DefineUCProperty(cx, obj, key.Data(), key.Length(),
-                             OBJECT_TO_JSVAL(jsEntry), nullptr, nullptr,
-                             JSPROP_ENUMERATE | JSPROP_READONLY);
+                             jsEntry, JSPROP_ENUMERATE | JSPROP_READONLY);
 }
 
 bool TelemetryIOInterposeObserver::ReflectIntoJS(JSContext *cx,
                                                  JS::Handle<JSObject*> rootObj)
 {
   return mFileStats.ReflectIntoJS(ReflectFileStats, cx, rootObj);
 }
 
@@ -801,17 +800,17 @@ GetHistogramByEnumId(Telemetry::ID id, H
 }
 
 bool
 FillRanges(JSContext *cx, JS::Handle<JSObject*> array, Histogram *h)
 {
   JS::Rooted<JS::Value> range(cx);
   for (size_t i = 0; i < h->bucket_count(); i++) {
     range = INT_TO_JSVAL(h->ranges(i));
-    if (!JS_DefineElement(cx, array, i, range, nullptr, nullptr, JSPROP_ENUMERATE))
+    if (!JS_DefineElement(cx, array, i, range, JSPROP_ENUMERATE))
       return false;
   }
   return true;
 }
 
 enum reflectStatus {
   REFLECT_OK,
   REFLECT_CORRUPT,
@@ -865,18 +864,17 @@ ReflectHistogramAndSamples(JSContext *cx
   JS::Rooted<JSObject*> counts_array(cx, JS_NewArrayObject(cx, count));
   if (!counts_array) {
     return REFLECT_FAILURE;
   }
   if (!JS_DefineProperty(cx, obj, "counts", counts_array, JSPROP_ENUMERATE)) {
     return REFLECT_FAILURE;
   }
   for (size_t i = 0; i < count; i++) {
-    if (!JS_DefineElement(cx, counts_array, i, INT_TO_JSVAL(ss.counts(i)),
-                          nullptr, nullptr, JSPROP_ENUMERATE)) {
+    if (!JS_DefineElement(cx, counts_array, i, ss.counts(i), JSPROP_ENUMERATE)) {
       return REFLECT_FAILURE;
     }
   }
 
   return REFLECT_OK;
 }
 
 enum reflectStatus