Bug 752226 - Remove any use of JSVAL_IS_OBJECT. r=luke,Ms2ger
authorTom Schuster <evilpies@gmail.com>
Fri, 11 May 2012 17:46:26 +0200
changeset 93858 366ab61b0af74eba87742c3495c32bda388f5cb6
parent 93857 3e0f7b9a39d7300abf1e3bb048e8c17b9db0c0b4
child 93859 2eaba70259bf3b5d2c9c3cf0ae41245a719a5496
push id761
push usertim.taubert@gmx.de
push dateMon, 14 May 2012 21:35:34 +0000
treeherderfx-team@0c78207fc93f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke, Ms2ger
bugs752226
milestone15.0a1
Bug 752226 - Remove any use of JSVAL_IS_OBJECT. r=luke,Ms2ger
caps/src/nsSecurityManagerFactory.cpp
content/base/src/nsDOMBlobBuilder.cpp
content/base/src/nsDOMFile.cpp
content/base/src/nsDOMParser.cpp
content/base/src/nsFrameMessageManager.cpp
content/base/src/nsWebSocket.cpp
content/canvas/src/CustomQS_WebGL.h
content/html/content/src/nsHTMLCanvasElement.cpp
dom/base/nsDOMClassInfo.cpp
dom/src/json/nsJSON.cpp
dom/workers/WorkerPrivate.cpp
dom/workers/WorkerScope.cpp
js/jsd/jsd_val.c
js/jsd/jsd_xpc.cpp
js/src/ctypes/CTypes.cpp
js/src/jsapi-tests/testBindCallable.cpp
js/src/jsapi-tests/testConservativeGC.cpp
js/src/jsapi-tests/testLookup.cpp
js/src/jsapi-tests/testTrap.cpp
js/src/shell/js.cpp
js/src/shell/jsheaptools.cpp
js/src/shell/jsworkers.cpp
js/xpconnect/loader/mozJSComponentLoader.cpp
js/xpconnect/public/nsAutoJSValHolder.h
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCConvert.cpp
js/xpconnect/src/XPCDebug.cpp
js/xpconnect/src/XPCQuickStubs.cpp
js/xpconnect/src/XPCVariant.cpp
js/xpconnect/src/XPCWrappedJSClass.cpp
js/xpconnect/src/XPCWrappedNative.cpp
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/wrappers/AccessCheck.cpp
storage/src/mozStoragePrivateHelpers.cpp
--- a/caps/src/nsSecurityManagerFactory.cpp
+++ b/caps/src/nsSecurityManagerFactory.cpp
@@ -159,29 +159,30 @@ nsSecurityNameSet::InitializeNameSet(nsI
      */
     JSObject *obj = global;
     JSObject *proto;
     JSAutoRequest ar(cx);
     while ((proto = JS_GetPrototype(obj)) != nsnull)
         obj = proto;
     JSClass *objectClass = JS_GetClass(obj);
 
-    jsval v;
+    JS::Value v;
     if (!JS_GetProperty(cx, global, "netscape", &v))
         return NS_ERROR_FAILURE;
+
     JSObject *securityObj;
-    if (JSVAL_IS_OBJECT(v)) {
+    if (v.isObject()) {
         /*
          * "netscape" property of window object exists; get the
          * "security" property.
          */
-        obj = JSVAL_TO_OBJECT(v);
-        if (!JS_GetProperty(cx, obj, "security", &v) || !JSVAL_IS_OBJECT(v))
+        obj = &v.toObject();
+        if (!JS_GetProperty(cx, obj, "security", &v) || !v.isObject())
             return NS_ERROR_FAILURE;
-        securityObj = JSVAL_TO_OBJECT(v);
+        securityObj = &v.toObject();
     } else {
         /* define netscape.security object */
         obj = JS_DefineObject(cx, global, "netscape", objectClass, nsnull, 0);
         if (obj == nsnull)
             return NS_ERROR_FAILURE;
         securityObj = JS_DefineObject(cx, obj, "security", objectClass,
                                       nsnull, 0);
         if (securityObj == nsnull)
--- a/content/base/src/nsDOMBlobBuilder.cpp
+++ b/content/base/src/nsDOMBlobBuilder.cpp
@@ -399,28 +399,28 @@ nsDOMBlobBuilder::GetFile(const nsAStrin
   blobs.Clear();
 
   return NS_OK;
 }
 
 /* [implicit_jscontext] void append (in jsval data,
                                      [optional] in DOMString endings); */
 NS_IMETHODIMP
-nsDOMBlobBuilder::Append(const jsval& aData,
+nsDOMBlobBuilder::Append(const JS::Value& aData,
                          const nsAString& aEndings, JSContext* aCx)
 {
   // We need to figure out what our jsval is
 
+  // Just return for null
+  if (aData.isNull())
+    return NS_OK;
+
   // Is it an object?
-  if (JSVAL_IS_OBJECT(aData)) {
-    JSObject* obj = JSVAL_TO_OBJECT(aData);
-    if (!obj) {
-      // We got passed null.  Just do nothing.
-      return NS_OK;
-    }
+  if (aData.isObject()) {
+    JSObject* obj = &aData.toObject();
 
     // Is it a Blob?
     nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(
       nsContentUtils::XPConnect()->
         GetNativeOfWrapper(aCx, obj));
     if (blob) {
       // Flatten so that multipart blobs will never nest
       nsDOMFileBase* file = static_cast<nsDOMFileBase*>(
--- a/content/base/src/nsDOMFile.cpp
+++ b/content/base/src/nsDOMFile.cpp
@@ -512,40 +512,39 @@ nsDOMFileFile::GetInternalStream(nsIInpu
                                       -1, -1, sFileStreamFlags);
 }
 
 NS_IMETHODIMP
 nsDOMFileFile::Initialize(nsISupports* aOwner,
                           JSContext* aCx,
                           JSObject* aObj,
                           PRUint32 aArgc,
-                          jsval* aArgv)
+                          JS::Value* aArgv)
 {
   nsresult rv;
 
   NS_ASSERTION(!mImmutable, "Something went wrong ...");
   NS_ENSURE_TRUE(!mImmutable, NS_ERROR_UNEXPECTED);
 
   if (!nsContentUtils::IsCallerChrome()) {
     return NS_ERROR_DOM_SECURITY_ERR; // Real short trip
   }
 
   NS_ENSURE_TRUE(aArgc > 0, NS_ERROR_UNEXPECTED);
 
   // We expect to get a path to represent as a File object,
   // or an nsIFile
   nsCOMPtr<nsIFile> file;
-  if (!JSVAL_IS_STRING(aArgv[0])) {
+  if (!aArgv[0].isString()) {
     // Lets see if it's an nsIFile
-    if (!JSVAL_IS_OBJECT(aArgv[0])) {
+    if (!aArgv[0].isObject()) {
       return NS_ERROR_UNEXPECTED; // We're not interested
     }
 
-    JSObject* obj = JSVAL_TO_OBJECT(aArgv[0]);
-    NS_ASSERTION(obj, "This is a bit odd");
+    JSObject* obj = &aArgv[0].toObject();
 
     // Is it an nsIFile
     file = do_QueryInterface(
       nsContentUtils::XPConnect()->
         GetNativeOfWrapper(aCx, obj));
     if (!file)
       return NS_ERROR_UNEXPECTED;
   } else {
--- a/content/base/src/nsDOMParser.cpp
+++ b/content/base/src/nsDOMParser.cpp
@@ -321,26 +321,26 @@ nsDOMParser::Init(nsIPrincipal* principa
 
   NS_POSTCONDITION(mPrincipal, "Must have principal");
   NS_POSTCONDITION(mOriginalPrincipal, "Must have original principal");
   NS_POSTCONDITION(mDocumentURI, "Must have document URI");
   return NS_OK;
 }
   
 static nsQueryInterface
-JSvalToInterface(JSContext* cx, jsval val, nsIXPConnect* xpc, bool* wasNull)
+JSvalToInterface(JSContext* cx, JS::Value val, nsIXPConnect* xpc, bool* wasNull)
 {
-  if (val == JSVAL_NULL) {
+  if (val.isNull()) {
     *wasNull = true;
     return nsQueryInterface(nsnull);
   }
   
   *wasNull = false;
-  if (JSVAL_IS_OBJECT(val)) {
-    JSObject* arg = JSVAL_TO_OBJECT(val);
+  if (val.isObject()) {
+    JSObject* arg = &val.toObject();
 
     nsCOMPtr<nsIXPConnectWrappedNative> native;
     xpc->GetWrappedNativeOfJSObject(cx, arg, getter_AddRefs(native));
 
     // do_QueryWrappedNative is not null-safe
     if (native) {
       return do_QueryWrappedNative(native);
     }
--- a/content/base/src/nsFrameMessageManager.cpp
+++ b/content/base/src/nsFrameMessageManager.cpp
@@ -448,41 +448,41 @@ nsFrameMessageManager::ReceiveMessage(ns
                           STRING_TO_JSVAL(jsMessage), NULL, NULL, JSPROP_ENUMERATE);
         JS_DefineProperty(ctx, param, "sync",
                           BOOLEAN_TO_JSVAL(aSync), NULL, NULL, JSPROP_ENUMERATE);
         JS_DefineProperty(ctx, param, "json", json, NULL, NULL, JSPROP_ENUMERATE);
         JS_DefineProperty(ctx, param, "objects", objectsv.jsval_value(), NULL, NULL, JSPROP_ENUMERATE);
 
         jsval thisValue = JSVAL_VOID;
 
-        jsval funval = JSVAL_VOID;
+        JS::Value funval;
         if (JS_ObjectIsCallable(ctx, object)) {
           // If the listener is a JS function:
-          funval = OBJECT_TO_JSVAL(object);
+          funval.setObject(*object);
 
           // A small hack to get 'this' value right on content side where
           // messageManager is wrapped in TabChildGlobal.
           nsCOMPtr<nsISupports> defaultThisValue;
           if (mChrome) {
             defaultThisValue = do_QueryObject(this);
           } else {
             defaultThisValue = aTarget;
           }
           nsContentUtils::WrapNative(ctx,
                                      JS_GetGlobalForObject(ctx, object),
                                      defaultThisValue, &thisValue, nsnull, true);
         } else {
           // If the listener is a JS object which has receiveMessage function:
-          NS_ENSURE_STATE(JS_GetProperty(ctx, object, "receiveMessage",
-                                         &funval) &&
-                          JSVAL_IS_OBJECT(funval) &&
-                          !JSVAL_IS_NULL(funval));
-          JSObject* funobject = JSVAL_TO_OBJECT(funval);
-          NS_ENSURE_STATE(JS_ObjectIsCallable(ctx, funobject));
-          thisValue = OBJECT_TO_JSVAL(object);
+          if (!JS_GetProperty(ctx, object, "receiveMessage", &funval) ||
+              !funval.isObject())
+            return NS_ERROR_UNEXPECTED;
+
+          // Check if the object is even callable.
+          NS_ENSURE_STATE(JS_ObjectIsCallable(ctx, &funval.toObject()));
+          thisValue.setObject(*object);
         }
 
         jsval rval = JSVAL_VOID;
 
         JS::AutoValueRooter argv(ctx);
         argv.set(OBJECT_TO_JSVAL(param));
 
         {
--- a/content/base/src/nsWebSocket.cpp
+++ b/content/base/src/nsWebSocket.cpp
@@ -557,17 +557,17 @@ nsWebSocket::DisconnectFromOwner()
  * an array of strings. It also initializes the principal, the script context and
  * the window owner.
  */
 NS_IMETHODIMP
 nsWebSocket::Initialize(nsISupports* aOwner,
                         JSContext* aContext,
                         JSObject* aObject,
                         PRUint32 aArgc,
-                        jsval* aArgv)
+                        JS::Value* aArgv)
 {
   NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
   nsAutoString urlParam;
 
   if (!PrefEnabled()) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
@@ -603,21 +603,20 @@ nsWebSocket::Initialize(nsISupports* aOw
   nsCOMPtr<nsIScriptObjectPrincipal> scriptPrincipal(do_QueryInterface(aOwner));
   NS_ENSURE_STATE(scriptPrincipal);
   nsCOMPtr<nsIPrincipal> principal = scriptPrincipal->GetPrincipal();
   NS_ENSURE_STATE(principal);
 
   nsTArray<nsString> protocolArray;
 
   if (aArgc == 2) {
-    JSObject *jsobj;
+    if (aArgv[1].isObject() &&
+        JS_IsArrayObject(aContext, &aArgv[1].toObject())) {
+      JSObject* jsobj = &aArgv[1].toObject();
 
-    if (JSVAL_IS_OBJECT(aArgv[1]) &&
-        (jsobj = JSVAL_TO_OBJECT(aArgv[1])) &&
-        JS_IsArrayObject(aContext, jsobj)) {
       uint32_t len;
       JS_GetArrayLength(aContext, jsobj, &len);
       
       for (PRUint32 index = 0; index < len; ++index) {
         jsval value;
 
         if (!JS_GetElement(aContext, jsobj, index, &value))
           return NS_ERROR_DOM_SYNTAX_ERR;
--- a/content/canvas/src/CustomQS_WebGL.h
+++ b/content/canvas/src/CustomQS_WebGL.h
@@ -188,43 +188,43 @@ nsIDOMWebGLRenderingContext_TexImage2D(J
     xpc_qsSelfRef selfref;
     JS::AutoValueRooter tvr(cx);
     if (!xpc_qsUnwrapThis(cx, obj, &self, &selfref.ptr, tvr.jsval_addr(), nsnull))
         return JS_FALSE;
 
     if (argc < 6 || argc == 7 || argc == 8)
         return xpc_qsThrow(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
 
-    jsval *argv = JS_ARGV(cx, vp);
+    JS::Value* argv = JS_ARGV(cx, vp);
 
     // arguments common to all cases
     GET_UINT32_ARG(argv0, 0);
     GET_INT32_ARG(argv1, 1);
     GET_UINT32_ARG(argv2, 2);
 
-    if (argc > 5 && !JSVAL_IS_PRIMITIVE(argv[5])) {
+    if (argc > 5 && argv[5].isObject()) {
         // implement the variants taking a DOMElement as argv[5]
         GET_UINT32_ARG(argv3, 3);
         GET_UINT32_ARG(argv4, 4);
 
         CallTexImage2D selfCaller(self, argv0, argv1, argv2, argv3, argv4);
         if (!TexImage2DImageDataOrElement(cx, selfCaller, argv + 5)) {
             return false;
         }
         rv = NS_OK;
-    } else if (argc > 8 && JSVAL_IS_OBJECT(argv[8])) {
+    } else if (argc > 8 && argv[8].isObjectOrNull()) {
         // here, we allow null !
         // implement the variants taking a buffer/array as argv[8]
         GET_INT32_ARG(argv3, 3);
         GET_INT32_ARG(argv4, 4);
         GET_INT32_ARG(argv5, 5);
         GET_UINT32_ARG(argv6, 6);
         GET_UINT32_ARG(argv7, 7);
 
-        JSObject *argv8 = JSVAL_TO_OBJECT(argv[8]);
+        JSObject* argv8 = argv[8].toObjectOrNull();
 
         // then try to grab either a js::TypedArray, or null
         if (argv8 == nsnull) {
             rv = self->TexImage2D_array(argv0, argv1, argv2, argv3,
                                         argv4, argv5, argv6, argv7,
                                         nsnull, cx);
         } else if (JS_IsTypedArrayObject(argv8, cx)) {
             rv = self->TexImage2D_array(argv0, argv1, argv2, argv3,
--- a/content/html/content/src/nsHTMLCanvasElement.cpp
+++ b/content/html/content/src/nsHTMLCanvasElement.cpp
@@ -493,17 +493,17 @@ nsHTMLCanvasElement::GetContextHelper(co
 
   ctx.forget(aContext);
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
-                                const jsval& aContextOptions,
+                                const JS::Value& aContextOptions,
                                 nsISupports **aContext)
 {
   nsresult rv;
 
   bool forceThebes = false;
 
   while (mCurrentContextId.IsEmpty()) {
     rv = GetContextHelper(aContextId, forceThebes, getter_AddRefs(mCurrentContext));
@@ -516,62 +516,61 @@ nsHTMLCanvasElement::GetContext(const ns
     // CC participant from QI doesn't addref.
     nsXPCOMCycleCollectionParticipant *cp = nsnull;
     CallQueryInterface(mCurrentContext, &cp);
     if (!cp) {
       mCurrentContext = nsnull;
       return NS_ERROR_FAILURE;
     }
 
+    // note: if any contexts end up supporting something other
+    // than objects, e.g. plain strings, then we'll need to expand
+    // this to know how to create nsISupportsStrings etc.
+
     nsCOMPtr<nsIWritablePropertyBag2> contextProps;
-    if (!JSVAL_IS_NULL(aContextOptions) &&
-        !JSVAL_IS_VOID(aContextOptions))
+    if (aContextOptions.isObject())
     {
       JSContext *cx = nsContentUtils::GetCurrentJSContext();
 
-      // note: if any contexts end up supporting something other
-      // than objects, e.g. plain strings, then we'll need to expand
-      // this to know how to create nsISupportsStrings etc.
-      if (JSVAL_IS_OBJECT(aContextOptions)) {
-        contextProps = do_CreateInstance("@mozilla.org/hash-property-bag;1");
+      contextProps = do_CreateInstance("@mozilla.org/hash-property-bag;1");
+
+      JSObject *opts = &aContextOptions.toObject();
+      JS::AutoIdArray props(cx, JS_Enumerate(cx, opts));
+      for (size_t i = 0; !!props && i < props.length(); ++i) {
+        jsid propid = props[i];
+        jsval propname, propval;
+        if (!JS_IdToValue(cx, propid, &propname) ||
+            !JS_GetPropertyById(cx, opts, propid, &propval)) {
+          continue;
+        }
 
-        JSObject *opts = JSVAL_TO_OBJECT(aContextOptions);
-        JS::AutoIdArray props(cx, JS_Enumerate(cx, opts));
-        for (size_t i = 0; !!props && i < props.length(); ++i) {
-          jsid propid = props[i];
-          jsval propname, propval;
-          if (!JS_IdToValue(cx, propid, &propname) ||
-              !JS_GetPropertyById(cx, opts, propid, &propval)) {
-            continue;
-          }
+        JSString *propnameString = JS_ValueToString(cx, propname);
+        nsDependentJSString pstr;
+        if (!propnameString || !pstr.init(cx, propnameString)) {
+          mCurrentContext = nsnull;
+          return NS_ERROR_FAILURE;
+        }
 
-          JSString *propnameString = JS_ValueToString(cx, propname);
-          nsDependentJSString pstr;
-          if (!propnameString || !pstr.init(cx, propnameString)) {
+        if (JSVAL_IS_BOOLEAN(propval)) {
+          contextProps->SetPropertyAsBool(pstr, JSVAL_TO_BOOLEAN(propval));
+        } else if (JSVAL_IS_INT(propval)) {
+          contextProps->SetPropertyAsInt32(pstr, JSVAL_TO_INT(propval));
+        } else if (JSVAL_IS_DOUBLE(propval)) {
+          contextProps->SetPropertyAsDouble(pstr, JSVAL_TO_DOUBLE(propval));
+        } else if (JSVAL_IS_STRING(propval)) {
+          JSString *propvalString = JS_ValueToString(cx, propval);
+          nsDependentJSString vstr;
+          if (!propvalString || !vstr.init(cx, propvalString)) {
             mCurrentContext = nsnull;
             return NS_ERROR_FAILURE;
           }
 
-          if (JSVAL_IS_BOOLEAN(propval)) {
-            contextProps->SetPropertyAsBool(pstr, JSVAL_TO_BOOLEAN(propval));
-          } else if (JSVAL_IS_INT(propval)) {
-            contextProps->SetPropertyAsInt32(pstr, JSVAL_TO_INT(propval));
-          } else if (JSVAL_IS_DOUBLE(propval)) {
-            contextProps->SetPropertyAsDouble(pstr, JSVAL_TO_DOUBLE(propval));
-          } else if (JSVAL_IS_STRING(propval)) {
-            JSString *propvalString = JS_ValueToString(cx, propval);
-            nsDependentJSString vstr;
-            if (!propvalString || !vstr.init(cx, propvalString)) {
-              mCurrentContext = nsnull;
-              return NS_ERROR_FAILURE;
-            }
+          contextProps->SetPropertyAsAString(pstr, vstr);
+        }
 
-            contextProps->SetPropertyAsAString(pstr, vstr);
-          }
-        }
       }
     }
 
     rv = UpdateContext(contextProps);
     if (NS_FAILED(rv)) {
       if (!forceThebes) {
         // Try again with a Thebes context
         forceThebes = true;
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -2082,29 +2082,29 @@ CreateExceptionFromResult(JSContext *cx,
   }
 
   nsCOMPtr<nsIException> exception;
   rv = xm->GetExceptionFromProvider(aResult, 0, getter_AddRefs(exception));
   if (NS_FAILED(rv) || !exception) {
     return NS_ERROR_FAILURE;
   }
 
-  jsval jv;
+  JS::Value jv;
   nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
   rv = WrapNative(cx, ::JS_GetGlobalObject(cx), exception,
                   &NS_GET_IID(nsIException), false, &jv,
                   getter_AddRefs(holder));
-  if (NS_FAILED(rv) || JSVAL_IS_NULL(jv)) {
+  if (NS_FAILED(rv) || jv.isNull()) {
     return NS_ERROR_FAILURE;
   }
 
   JSAutoEnterCompartment ac;
 
-  if (JSVAL_IS_OBJECT(jv)) {
-    if (!ac.enter(cx, JSVAL_TO_OBJECT(jv))) {
+  if (jv.isObject()) {
+    if (!ac.enter(cx, &jv.toObject())) {
       return NS_ERROR_UNEXPECTED;
     }
   }
 
   JS_SetPendingException(cx, jv);
   return NS_OK;
 }
 
@@ -6487,36 +6487,33 @@ ResolvePrototype(nsIXPConnect *aXPConnec
   }
 
   {
     JSObject *winobj = aWin->FastGetGlobalJSObject();
 
     JSObject *proto = nsnull;
 
     if (class_parent_name) {
-      jsval val;
-
       JSAutoEnterCompartment ac;
       if (!ac.enter(cx, winobj)) {
         return NS_ERROR_UNEXPECTED;
       }
 
-      if (!::JS_LookupProperty(cx, winobj, CutPrefix(class_parent_name), &val)) {
+      JS::Value val;
+      if (!JS_LookupProperty(cx, winobj, CutPrefix(class_parent_name), &val)) {
         return NS_ERROR_UNEXPECTED;
       }
 
-      JSObject *tmp = JSVAL_IS_OBJECT(val) ? JSVAL_TO_OBJECT(val) : nsnull;
-
-      if (tmp) {
-        if (!::JS_LookupProperty(cx, tmp, "prototype", &val)) {
+      if (val.isObject()) {
+        if (!JS_LookupProperty(cx, &val.toObject(), "prototype", &val)) {
           return NS_ERROR_UNEXPECTED;
         }
 
-        if (JSVAL_IS_OBJECT(val)) {
-          proto = JSVAL_TO_OBJECT(val);
+        if (val.isObject()) {
+          proto = &val.toObject();
         }
       }
     }
 
     if (dot_prototype) {
       JSAutoEnterCompartment ac;
       if (!ac.enter(cx, dot_prototype)) {
         return NS_ERROR_UNEXPECTED;
@@ -8951,18 +8948,19 @@ nsHTMLDocumentSH::CallToGetPropMapper(JS
   JSString *str = ::JS_ValueToString(cx, JS_ARGV(cx, vp)[0]);
   if (!str) {
     return JS_FALSE;
   }
 
   // If we are called via document.all(id) instead of document.all.item(i) or
   // another method, use the document.all callee object as self.
   JSObject *self;
-  if (JSVAL_IS_OBJECT(JS_CALLEE(cx, vp)) &&
-      ::JS_GetClass(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))) == &sHTMLDocumentAllClass) {
+  JS::Value callee = JS_CALLEE(cx, vp);
+  if (callee.isObject() &&
+  	  JS_GetClass(&callee.toObject()) == &sHTMLDocumentAllClass) {
     self = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
   } else {
     self = JS_THIS_OBJECT(cx, vp);
     if (!self)
       return JS_FALSE;
   }
 
   size_t length;
@@ -8996,17 +8994,17 @@ static inline PRUint32
 PrivateToFlags(void *priv)
 {
   JS_ASSERT(size_t(priv) <= PR_UINT32_MAX && (size_t(priv) & 1) == 0);
   return (PRUint32)(size_t(priv) >> 1);
 }
 
 JSBool
 nsHTMLDocumentSH::DocumentAllHelperGetProperty(JSContext *cx, JSObject *obj,
-                                               jsid id, jsval *vp)
+                                               jsid id, JS::Value *vp)
 {
   if (id != nsDOMClassInfo::sAll_id) {
     return JS_TRUE;
   }
 
   JSObject *helper = GetDocumentAllHelper(obj);
 
   if (!helper) {
@@ -9019,22 +9017,22 @@ nsHTMLDocumentSH::DocumentAllHelperGetPr
 
   PRUint32 flags = PrivateToFlags(::JS_GetPrivate(helper));
 
   if (flags & JSRESOLVE_DETECTING || !(flags & JSRESOLVE_QUALIFIED)) {
     // document.all is either being detected, e.g. if (document.all),
     // or it was not being resolved with a qualified name. Claim that
     // document.all is undefined.
 
-    *vp = JSVAL_VOID;
+    vp->setUndefined();
   } else {
     // document.all is not being detected, and it resolved with a
     // qualified name. Expose the document.all collection.
 
-    if (!JSVAL_IS_OBJECT(*vp)) {
+    if (!vp->isObjectOrNull()) { 
       // First time through, create the collection, and set the
       // document as its private nsISupports data.
       nsresult rv;
       nsCOMPtr<nsIHTMLDocument> doc = do_QueryWrapper(cx, obj, &rv);
       if (NS_FAILED(rv)) {
         nsDOMClassInfo::ThrowJSException(cx, rv);
 
         return JS_FALSE;
@@ -9046,17 +9044,17 @@ nsHTMLDocumentSH::DocumentAllHelperGetPr
         return JS_FALSE;
       }
 
       // Let the JSObject take over ownership of doc.
       ::JS_SetPrivate(all, doc);
 
       doc.forget();
 
-      *vp = OBJECT_TO_JSVAL(all);
+      vp->setObject(*all);
     }
   }
 
   return JS_TRUE;
 }
 
 JSBool
 nsHTMLDocumentSH::DocumentAllHelperNewResolve(JSContext *cx, JSObject *obj,
@@ -9490,35 +9488,30 @@ nsHTMLSelectElementSH::GetProperty(nsIXP
     }
   }
 
   return NS_OK;
 }
 
 // static
 nsresult
-nsHTMLSelectElementSH::SetOption(JSContext *cx, jsval *vp, PRUint32 aIndex,
+nsHTMLSelectElementSH::SetOption(JSContext *cx, JS::Value *vp, PRUint32 aIndex,
                                  nsIDOMHTMLOptionsCollection *aOptCollection)
 {
   JSAutoRequest ar(cx);
 
   // vp must refer to an object
-  if (!JSVAL_IS_OBJECT(*vp) && !::JS_ConvertValue(cx, *vp, JSTYPE_OBJECT, vp)) {
+  if (!vp->isObject()) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  nsCOMPtr<nsIDOMHTMLOptionElement> new_option;
-
-  if (!JSVAL_IS_NULL(*vp)) {
-    new_option = do_QueryWrapper(cx, JSVAL_TO_OBJECT(*vp));
-    if (!new_option) {
-      // Someone is trying to set an option to a non-option object.
-
-      return NS_ERROR_UNEXPECTED;
-    }
+  nsCOMPtr<nsIDOMHTMLOptionElement> new_option = do_QueryWrapper(cx, &vp->toObject());
+  if (!new_option) {
+    // Someone is trying to set an option to a non-option object.
+    return NS_ERROR_UNEXPECTED;
   }
 
   return aOptCollection->SetOption(aIndex, new_option);
 }
 
 NS_IMETHODIMP
 nsHTMLSelectElementSH::SetProperty(nsIXPConnectWrappedNative *wrapper,
                                    JSContext *cx, JSObject *obj, jsid id,
--- a/dom/src/json/nsJSON.cpp
+++ b/dom/src/json/nsJSON.cpp
@@ -199,27 +199,27 @@ WriteCallback(const jschar *buf, uint32_
   nsresult rv =  writer->Write((const PRUnichar*)buf, (PRUint32)len);
   if (NS_FAILED(rv))
     return JS_FALSE;
 
   return JS_TRUE;
 }
 
 NS_IMETHODIMP
-nsJSON::EncodeFromJSVal(jsval *value, JSContext *cx, nsAString &result)
+nsJSON::EncodeFromJSVal(JS::Value *value, JSContext *cx, nsAString &result)
 {
   result.Truncate();
 
   // Begin a new request
   JSAutoRequest ar(cx);
 
   JSAutoEnterCompartment ac;
-  JSObject *obj;
   nsIScriptSecurityManager *ssm = nsnull;
-  if (JSVAL_IS_OBJECT(*value) && (obj = JSVAL_TO_OBJECT(*value))) {
+  if (value->isObject()) {
+    JSObject *obj = &value->toObject();
     if (!ac.enter(cx, obj)) {
       return NS_ERROR_FAILURE;
     }
 
     nsCOMPtr<nsIPrincipal> principal;
     ssm = nsContentUtils::GetSecurityManager();
     nsresult rv = ssm->GetObjectPrincipal(cx, obj, getter_AddRefs(principal));
     NS_ENSURE_SUCCESS(rv, rv);
@@ -249,24 +249,21 @@ nsJSON::EncodeFromJSVal(jsval *value, JS
 
 nsresult
 nsJSON::EncodeInternal(JSContext* cx, const JS::Value& aValue, nsJSONWriter* writer)
 {
   JSAutoRequest ar(cx);
 
   // Backward compatibility:
   // nsIJSON does not allow to serialize anything other than objects
-  if (!JSVAL_IS_OBJECT(aValue)) {
+  if (!aValue.isObject()) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  JSObject* obj = JSVAL_TO_OBJECT(aValue);
-  if (!obj) {
-    return NS_ERROR_INVALID_ARG;
-  }
+  JSObject* obj = &aValue.toObject();
 
   JS::Value val = aValue;
 
   /* Backward compatibility:
    * Manually call toJSON if implemented by the object and check that
    * the result is still an object
    * Note: It is perfectly fine to not implement toJSON, so it is
    * perfectly fine for GetMethod to fail
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -1841,17 +1841,17 @@ WorkerRunnable::NotifyScriptExecutedIfNe
       mWorkerPrivate->GetScriptNotify()->ScriptExecuted();
     }
   }
 }
 
 struct WorkerPrivate::TimeoutInfo
 {
   TimeoutInfo()
-  : mTimeoutVal(JSVAL_VOID), mLineNumber(0), mId(0), mIsInterval(false),
+  : mTimeoutVal(JS::UndefinedValue()), mLineNumber(0), mId(0), mIsInterval(false),
     mCanceled(false)
   {
     MOZ_COUNT_CTOR(mozilla::dom::workers::WorkerPrivate::TimeoutInfo);
   }
 
   ~TimeoutInfo()
   {
     MOZ_COUNT_DTOR(mozilla::dom::workers::WorkerPrivate::TimeoutInfo);
@@ -1862,17 +1862,17 @@ struct WorkerPrivate::TimeoutInfo
     return mTargetTime == aOther.mTargetTime;
   }
 
   bool operator<(const TimeoutInfo& aOther)
   {
     return mTargetTime < aOther.mTargetTime;
   }
 
-  jsval mTimeoutVal;
+  JS::Value mTimeoutVal;
   nsTArray<jsval> mExtraArgVals;
   mozilla::TimeStamp mTargetTime;
   mozilla::TimeDuration mInterval;
   nsCString mFilename;
   PRUint32 mLineNumber;
   PRUint32 mId;
   bool mIsInterval;
   bool mCanceled;
@@ -3614,60 +3614,60 @@ WorkerPrivate::SetTimeout(JSContext* aCx
   newInfo->mIsInterval = aIsInterval;
   newInfo->mId = timerId;
 
   if (NS_UNLIKELY(timerId == PR_UINT32_MAX)) {
     NS_WARNING("Timeout ids overflowed!");
     mNextTimeoutId = 1;
   }
 
-  jsval* argv = JS_ARGV(aCx, aVp);
+  JS::Value* argv = JS_ARGV(aCx, aVp);
 
   // Take care of the main argument.
-  if (JSVAL_IS_OBJECT(argv[0])) {
-    if (JS_ObjectIsCallable(aCx, JSVAL_TO_OBJECT(argv[0]))) {
+  if (argv[0].isObject()) {
+    if (JS_ObjectIsCallable(aCx, &argv[0].toObject())) {
       newInfo->mTimeoutVal = argv[0];
     }
     else {
       JSString* timeoutStr = JS_ValueToString(aCx, argv[0]);
       if (!timeoutStr) {
         return false;
       }
-      newInfo->mTimeoutVal = STRING_TO_JSVAL(timeoutStr);
+      newInfo->mTimeoutVal.setString(timeoutStr);
     }
   }
-  else if (JSVAL_IS_STRING(argv[0])) {
+  else if (argv[0].isString()) {
     newInfo->mTimeoutVal = argv[0];
   }
   else {
     JS_ReportError(aCx, "Useless %s call (missing quotes around argument?)",
                    aIsInterval ? "setInterval" : "setTimeout");
     return false;
   }
 
   // See if any of the optional arguments were passed.
   if (aArgc > 1) {
     double intervalMS = 0;
     if (!JS_ValueToNumber(aCx, argv[1], &intervalMS)) {
       return false;
     }
     newInfo->mInterval = TimeDuration::FromMilliseconds(intervalMS);
 
-    if (aArgc > 2 && JSVAL_IS_OBJECT(newInfo->mTimeoutVal)) {
+    if (aArgc > 2 && newInfo->mTimeoutVal.isObject()) {
       nsTArray<jsval> extraArgVals(aArgc - 2);
       for (unsigned index = 2; index < aArgc; index++) {
         extraArgVals.AppendElement(argv[index]);
       }
       newInfo->mExtraArgVals.SwapElements(extraArgVals);
     }
   }
 
   newInfo->mTargetTime = TimeStamp::Now() + newInfo->mInterval;
 
-  if (JSVAL_IS_STRING(newInfo->mTimeoutVal)) {
+  if (newInfo->mTimeoutVal.isString()) {
     const char* filenameChars;
     PRUint32 lineNumber;
     if (nsJSUtils::GetCallingLocation(aCx, &filenameChars, &lineNumber)) {
       newInfo->mFilename = filenameChars;
       newInfo->mLineNumber = lineNumber;
     }
     else {
       NS_WARNING("Failed to get calling location!");
@@ -3781,18 +3781,18 @@ WorkerPrivate::RunExpiredTimeouts(JSCont
     if (info->mCanceled) {
       continue;
     }
 
     // Always call JS_ReportPendingException if something fails, and if
     // JS_ReportPendingException returns false (i.e. uncatchable exception) then
     // break out of the loop.
 
-    if (JSVAL_IS_STRING(info->mTimeoutVal)) {
-      JSString* expression = JSVAL_TO_STRING(info->mTimeoutVal);
+    if (info->mTimeoutVal.isString()) {
+      JSString* expression = info->mTimeoutVal.toString();
 
       size_t stringLength;
       const jschar* string = JS_GetStringCharsAndLength(aCx, expression,
                                                         &stringLength);
 
       if ((!string ||
            !JS_EvaluateUCScriptForPrincipals(aCx, global, principal, string,
                                              stringLength,
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -292,29 +292,28 @@ private:
 
     *aVp = scope->mSlots[SLOT_location];
     return true;
   }
 
   static JSBool
   UnwrapErrorEvent(JSContext* aCx, unsigned aArgc, jsval* aVp)
   {
-    JS_ASSERT(JSVAL_IS_OBJECT(JS_CALLEE(aCx, aVp)));
     JS_ASSERT(aArgc == 1);
-    JS_ASSERT(JSVAL_IS_OBJECT(JS_ARGV(aCx, aVp)[0]));
+    JS_ASSERT((JS_ARGV(aCx, aVp)[0]).isObject());
 
-    JSObject* wrapper = JSVAL_TO_OBJECT(JS_CALLEE(aCx, aVp));
+    JSObject* wrapper = &JS_CALLEE(aCx, aVp).toObject();
     JS_ASSERT(JS_ObjectIsFunction(aCx, wrapper));
 
     jsval scope = js::GetFunctionNativeReserved(wrapper, SLOT_wrappedScope);
     jsval listener = js::GetFunctionNativeReserved(wrapper, SLOT_wrappedFunction);
 
-    JS_ASSERT(JSVAL_IS_OBJECT(scope));
+    JS_ASSERT(scope.isObject());
 
-    JSObject* event = JSVAL_TO_OBJECT(JS_ARGV(aCx, aVp)[0]);
+    JSObject* event = &JS_ARGV(aCx, aVp)[0].toObject();
 
     jsval argv[3] = { JSVAL_VOID, JSVAL_VOID, JSVAL_VOID };
     if (!JS_GetProperty(aCx, event, "message", &argv[0]) ||
         !JS_GetProperty(aCx, event, "filename", &argv[1]) ||
         !JS_GetProperty(aCx, event, "lineno", &argv[2])) {
       return false;
     }
 
--- a/js/jsd/jsd_val.c
+++ b/js/jsd/jsd_val.c
@@ -46,17 +46,17 @@
 #ifdef DEBUG
 void JSD_ASSERT_VALID_VALUE(JSDValue* jsdval)
 {
     JS_ASSERT(jsdval);
     JS_ASSERT(jsdval->nref > 0);
     if(!JS_CLIST_IS_EMPTY(&jsdval->props))
     {
         JS_ASSERT(CHECK_BIT_FLAG(jsdval->flags, GOT_PROPS));
-        JS_ASSERT(JSVAL_IS_OBJECT(jsdval->val));
+        JS_ASSERT(!JSVAL_IS_PRIMITIVE(jsdval->val));
     }
 
     if(jsdval->proto)
     {
         JS_ASSERT(CHECK_BIT_FLAG(jsdval->flags, GOT_PROTO));
         JS_ASSERT(jsdval->proto->nref > 0);
     }
     if(jsdval->parent)
@@ -82,17 +82,17 @@ void JSD_ASSERT_VALID_PROPERTY(JSDProper
         JS_ASSERT(jsdprop->alias->nref > 0);
 }
 #endif
 
 
 JSBool
 jsd_IsValueObject(JSDContext* jsdc, JSDValue* jsdval)
 {
-    return JSVAL_IS_OBJECT(jsdval->val);
+    return !JSVAL_IS_PRIMITIVE(jsdval->val) || JSVAL_IS_NULL(jsdval->val);
 }
 
 JSBool
 jsd_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval)
 {
     return JSVAL_IS_NUMBER(jsdval->val);
 }
 
@@ -444,17 +444,17 @@ static JSBool _buildProps(JSDContext* js
     JSContext* cx = jsdc->dumbContext;
     JSObject *obj;
     JSPropertyDescArray pda;
     unsigned i;
     JSCrossCompartmentCall *call = NULL;
 
     JS_ASSERT(JS_CLIST_IS_EMPTY(&jsdval->props));
     JS_ASSERT(!(CHECK_BIT_FLAG(jsdval->flags, GOT_PROPS)));
-    JS_ASSERT(JSVAL_IS_OBJECT(jsdval->val));
+    JS_ASSERT(!JSVAL_IS_PRIMITIVE(jsdval->val));
 
     if(JSVAL_IS_PRIMITIVE(jsdval->val))
         return JS_FALSE;
 
     obj = JSVAL_TO_OBJECT(jsdval->val);
 
     JS_BeginRequest(cx);
     call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
@@ -670,26 +670,26 @@ jsd_GetValueProperty(JSDContext* jsdc, J
  * Retrieve a JSFunction* from a JSDValue*. This differs from
  * JS_ValueToFunction by fully unwrapping the object first.
  */
 JSFunction*
 jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval)
 {
     JSObject *obj;
     JSFunction *fun;
+
     JSCrossCompartmentCall *call = NULL;
-    if (!JSVAL_IS_OBJECT(jsdval->val))
+    if (JSVAL_IS_PRIMITIVE(jsdval->val))
         return NULL;
-    if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
-        return NULL;
-    obj = JS_UnwrapObject(obj);
 
+    obj = JS_UnwrapObject(JSVAL_TO_OBJECT(jsdval->val));
     call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
     if (!call)
         return NULL;
+
     fun = JS_ValueToFunction(jsdc->dumbContext, OBJECT_TO_JSVAL(obj));
     JS_LeaveCrossCompartmentCall(call);
 
     return fun;
 }
 
 JSDValue*
 jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval)
@@ -697,20 +697,19 @@ jsd_GetValuePrototype(JSDContext* jsdc, 
     JSCrossCompartmentCall *call = NULL;
 
     if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_PROTO)))
     {
         JSObject* obj;
         JSObject* proto;
         JS_ASSERT(!jsdval->proto);
         SET_BIT_FLAG(jsdval->flags, GOT_PROTO);
-        if(!JSVAL_IS_OBJECT(jsdval->val))
+        if(JSVAL_IS_PRIMITIVE(jsdval->val))
             return NULL;
-        if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
-            return NULL;
+        obj = JSVAL_TO_OBJECT(jsdval->val);
         proto = JS_GetPrototype(obj);
         if(!proto)
             return NULL;
         jsdval->proto = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(proto));
     }
     if(jsdval->proto)
         jsdval->proto->nref++;
     return jsdval->proto;
@@ -722,20 +721,19 @@ jsd_GetValueParent(JSDContext* jsdc, JSD
     JSCrossCompartmentCall *call = NULL;
 
     if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_PARENT)))
     {
         JSObject* obj;
         JSObject* parent;
         JS_ASSERT(!jsdval->parent);
         SET_BIT_FLAG(jsdval->flags, GOT_PARENT);
-        if(!JSVAL_IS_OBJECT(jsdval->val))
+        if(JSVAL_IS_PRIMITIVE(jsdval->val))
             return NULL;
-        if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
-            return NULL;
+        obj = JSVAL_TO_OBJECT(jsdval->val);
         JS_BeginRequest(jsdc->dumbContext);
         call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
         if(!call) {
             JS_EndRequest(jsdc->dumbContext);
 
             return NULL;
         }
         parent = JS_GetParentOrScopeChain(jsdc->dumbContext,obj);
@@ -757,20 +755,19 @@ jsd_GetValueConstructor(JSDContext* jsdc
 
     if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_CTOR)))
     {
         JSObject* obj;
         JSObject* proto;
         JSObject* ctor;
         JS_ASSERT(!jsdval->ctor);
         SET_BIT_FLAG(jsdval->flags, GOT_CTOR);
-        if(!JSVAL_IS_OBJECT(jsdval->val))
+        if(JSVAL_IS_PRIMITIVE(jsdval->val))
             return NULL;
-        if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
-            return NULL;
+        obj = JSVAL_TO_OBJECT(jsdval->val);
         proto = JS_GetPrototype(obj);
         if(!proto)
             return NULL;
         JS_BeginRequest(jsdc->dumbContext);
         call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
         if(!call) {
             JS_EndRequest(jsdc->dumbContext);
 
@@ -789,21 +786,19 @@ jsd_GetValueConstructor(JSDContext* jsdc
 }
 
 const char*
 jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval)
 {
     jsval val = jsdval->val;
     JSCrossCompartmentCall *call = NULL;
 
-    if(!jsdval->className && JSVAL_IS_OBJECT(val))
+    if(!jsdval->className && !JSVAL_IS_PRIMITIVE(val))
     {
-        JSObject* obj;
-        if(!(obj = JSVAL_TO_OBJECT(val)))
-            return NULL;
+        JSObject* obj = JSVAL_TO_OBJECT(val);
         JS_BeginRequest(jsdc->dumbContext);
         call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
         if(!call) {
             JS_EndRequest(jsdc->dumbContext);
 
             return NULL;
         }
         jsdval->className = JS_GetClass(obj)->name;
--- a/js/jsd/jsd_xpc.cpp
+++ b/js/jsd/jsd_xpc.cpp
@@ -2235,17 +2235,17 @@ jsdValue::GetJsType (PRUint32 *_rval)
     else if (JSVAL_IS_INT(val))
         *_rval = TYPE_INT;
     else if (JSVAL_IS_STRING(val))
         *_rval = TYPE_STRING;
     else if (JSVAL_IS_VOID(val))
         *_rval = TYPE_VOID;
     else if (JSD_IsValueFunction (mCx, mValue))
         *_rval = TYPE_FUNCTION;
-    else if (JSVAL_IS_OBJECT(val))
+    else if (!JSVAL_IS_PRIMITIVE(val))
         *_rval = TYPE_OBJECT;
     else
         NS_ASSERTION (0, "Value has no discernible type.");
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -3628,18 +3628,18 @@ PointerType::ConstructData(JSContext* cx
   //
   if (argc == 0)
     return JS_TRUE;
 
   // Analyze the arguments a bit to decide what to do next.
   jsval* argv = JS_ARGV(cx, vp);
   JSObject* baseObj = PointerType::GetBaseType(obj);
   bool looksLikeClosure = CType::GetTypeCode(baseObj) == TYPE_function &&
-                          JSVAL_IS_OBJECT(argv[0]) &&
-                          JS_ObjectIsCallable(cx, JSVAL_TO_OBJECT(argv[0]));
+                          argv[0].isObject() &&
+                          JS_ObjectIsCallable(cx, &argv[0].toObject());
 
   //
   // Case 2 - Initialized pointer
   //
   if (!looksLikeClosure) {
     if (argc != 1) {
       JS_ReportError(cx, "first argument must be a function");
       return JS_FALSE;
@@ -3651,17 +3651,19 @@ PointerType::ConstructData(JSContext* cx
   // Case 3 - Closure
   //
 
   // The second argument is an optional 'this' parameter with which to invoke
   // the given js function. Callers may leave this blank, or pass null if they
   // wish to pass the third argument.
   JSObject* thisObj = NULL;
   if (argc >= 2) {
-    if (JSVAL_IS_OBJECT(argv[1])) {
+    if (JSVAL_IS_NULL(argv[1])) {
+      thisObj = NULL;
+    } else if (!JSVAL_IS_PRIMITIVE(argv[1])) {
       thisObj = JSVAL_TO_OBJECT(argv[1]);
     } else if (!JS_ValueToObject(cx, argv[1], &thisObj)) {
       return JS_FALSE;
     }
   }
 
   // The third argument is an optional error sentinel that js-ctypes will return
   // if an exception is raised while executing the closure. The type must match
@@ -3691,17 +3693,17 @@ PointerType::TargetTypeGetter(JSContext*
                               jsval* vp)
 {
   if (!CType::IsCType(obj) || CType::GetTypeCode(obj) != TYPE_pointer) {
     JS_ReportError(cx, "not a PointerType");
     return JS_FALSE;
   }
 
   *vp = JS_GetReservedSlot(obj, SLOT_TARGET_T);
-  JS_ASSERT(JSVAL_IS_OBJECT(*vp));
+  JS_ASSERT(vp->isObject());
   return JS_TRUE;
 }
 
 JSBool
 PointerType::IsNull(JSContext* cx, unsigned argc, jsval* vp)
 {
   JSObject* obj = JS_THIS_OBJECT(cx, vp);
   if (!obj)
@@ -6525,22 +6527,22 @@ CDataFinalizer::Construct(JSContext* cx,
   }
 
   if (argc != 2) {
     JS_ReportError(cx, "CDataFinalizer takes 2 arguments");
     return JS_FALSE;
   }
 
   jsval* argv = JS_ARGV(cx, vp);
-  jsval valCodePtr = argv[1];
-  if (!JSVAL_IS_OBJECT(valCodePtr) || JSVAL_IS_NULL(valCodePtr)) {
+  JS::Value valCodePtr = argv[1];
+  if (!valCodePtr.isObject()) {
     return TypeError(cx, "_a CData object_ of a function pointer type",
                      valCodePtr);
   }
-  JSObject *objCodePtr = JSVAL_TO_OBJECT(valCodePtr);
+  JSObject *objCodePtr = &valCodePtr.toObject();
 
   //Note: Using a custom argument formatter here would be awkward (requires
   //a destructor just to uninstall the formatter).
 
   // 2. Extract argument type of |objCodePtr|
   if (!CData::IsCData(objCodePtr)) {
     return TypeError(cx, "a _CData_ object of a function pointer type",
                      valCodePtr);
--- a/js/src/jsapi-tests/testBindCallable.cpp
+++ b/js/src/jsapi-tests/testBindCallable.cpp
@@ -1,27 +1,27 @@
 #include "tests.h"
 
 BEGIN_TEST(test_BindCallable)
 {
   jsval v;
   EVAL("({ somename : 1717 })", &v);
-  CHECK(JSVAL_IS_OBJECT(v));
+  CHECK(v.isObject());
 
   jsval func;
   EVAL("(function() { return this.somename; })", &func);
-  CHECK(JSVAL_IS_OBJECT(func));
+  CHECK(func.isObject());
 
   JSObject* newCallable = JS_BindCallable(cx, JSVAL_TO_OBJECT(func),
-					  JSVAL_TO_OBJECT(v));
+                                          JSVAL_TO_OBJECT(v));
   CHECK(newCallable);
 
   jsval retval;
   bool called = JS_CallFunctionValue(cx, NULL, OBJECT_TO_JSVAL(newCallable),
-				     0, NULL, &retval);
+                                     0, NULL, &retval);
   CHECK(called);
 
   CHECK(JSVAL_IS_INT(retval));
 
   CHECK(JSVAL_TO_INT(retval) == 1717);
   return true;
 }
 END_TEST(test_BindCallable)
--- a/js/src/jsapi-tests/testConservativeGC.cpp
+++ b/js/src/jsapi-tests/testConservativeGC.cpp
@@ -1,29 +1,29 @@
 #include "tests.h"
 #include "jsobj.h"
 #include "vm/String.h"
 
 BEGIN_TEST(testConservativeGC)
 {
     jsval v2;
     EVAL("({foo: 'bar'});", &v2);
-    CHECK(JSVAL_IS_OBJECT(v2));
+    CHECK(v2.isObject());
     char objCopy[sizeof(JSObject)];
     js_memcpy(&objCopy, JSVAL_TO_OBJECT(v2), sizeof(JSObject));
 
     jsval v3;
     EVAL("String(Math.PI);", &v3);
     CHECK(JSVAL_IS_STRING(v3));
     char strCopy[sizeof(JSString)];
     js_memcpy(&strCopy, JSVAL_TO_STRING(v3), sizeof(JSString));
 
     jsval tmp;
     EVAL("({foo2: 'bar2'});", &tmp);
-    CHECK(JSVAL_IS_OBJECT(tmp));
+    CHECK(tmp.isObject());
     JSObject *obj2 = JSVAL_TO_OBJECT(tmp);
     char obj2Copy[sizeof(JSObject)];
     js_memcpy(&obj2Copy, obj2, sizeof(JSObject));
 
     EVAL("String(Math.sqrt(3));", &tmp);
     CHECK(JSVAL_IS_STRING(tmp));
     JSString *str2 = JSVAL_TO_STRING(tmp);
     char str2Copy[sizeof(JSString)];
--- a/js/src/jsapi-tests/testLookup.cpp
+++ b/js/src/jsapi-tests/testLookup.cpp
@@ -19,18 +19,18 @@ BEGIN_TEST(testLookup_bug522590)
 
     // Now make x.f a method.
     EVAL("mkobj()", x.addr());
     JSObject *xobj = JSVAL_TO_OBJECT(x);
 
     // This lookup must not return an internal function object.
     jsvalRoot r(cx);
     CHECK(JS_LookupProperty(cx, xobj, "f", r.addr()));
-    CHECK(JSVAL_IS_OBJECT(r));
-    JSObject *funobj = JSVAL_TO_OBJECT(r);
+    CHECK(r.value().isObject());
+    JSObject *funobj = &r.value().toObject();
     CHECK(funobj->isFunction());
     CHECK(!js::IsInternalFunctionObject(funobj));
 
     return true;
 }
 END_TEST(testLookup_bug522590)
 
 JSBool
--- a/js/src/jsapi-tests/testTrap.cpp
+++ b/js/src/jsapi-tests/testTrap.cpp
@@ -31,17 +31,17 @@ BEGIN_TEST(testTrap_gc)
 
     // compile
     JSScript *script = JS_CompileScript(cx, global, source, strlen(source), __FILE__, 1);
     CHECK(script);
 
     // execute
     jsvalRoot v2(cx);
     CHECK(JS_ExecuteScript(cx, global, script, v2.addr()));
-    CHECK(JSVAL_IS_OBJECT(v2));
+    CHECK(v2.value().isObject());
     CHECK_EQUAL(emptyTrapCallCount, 0);
 
     // Enable debug mode
     CHECK(JS_SetDebugMode(cx, JS_TRUE));
 
     static const char trapClosureText[] = "some trap closure";
 
     // scope JSScript  usage to make sure that it is not used after
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2691,28 +2691,24 @@ EvalInFrame(JSContext *cx, unsigned argc
 
     if (saved)
         JS_RestoreFrameChain(cx);
 
     return ok;
 }
 
 static JSBool
-ShapeOf(JSContext *cx, unsigned argc, jsval *vp)
+ShapeOf(JSContext *cx, unsigned argc, JS::Value *vp)
 {
-    jsval v;
-    if (argc < 1 || !JSVAL_IS_OBJECT(v = JS_ARGV(cx, vp)[0])) {
+    JS::Value v;
+    if (argc < 1 || !((v = JS_ARGV(cx, vp)[0]).isObject())) {
         JS_ReportError(cx, "shapeOf: object expected");
         return JS_FALSE;
     }
-    JSObject *obj = JSVAL_TO_OBJECT(v);
-    if (!obj) {
-        *vp = JSVAL_ZERO;
-        return JS_TRUE;
-    }
+    JSObject *obj = &v.toObject();
     return JS_NewNumberValue(cx, (double) ((uintptr_t)obj->lastProperty() >> 3), vp);
 }
 
 /*
  * If referent has an own property named id, copy that property to obj[id].
  * Since obj is native, this isn't totally transparent; properties of a
  * non-native referent may be simplified to data properties.
  */
@@ -3851,23 +3847,23 @@ Help(JSContext *cx, unsigned argc, jsval
         AutoIdArray ida(cx, JS_Enumerate(cx, global));
         if (!ida)
             return false;
 
         for (size_t i = 0; i < ida.length(); i++) {
             jsval v;
             if (!JS_LookupPropertyById(cx, global, ida[i], &v))
                 return false;
-            if (JSVAL_IS_OBJECT(v) && !PrintHelp(cx, JSVAL_TO_OBJECT(v)))
+            if (!JSVAL_IS_PRIMITIVE(v) && !PrintHelp(cx, JSVAL_TO_OBJECT(v)))
                 return false;
         }
     } else {
         jsval *argv = JS_ARGV(cx, vp);
         for (unsigned i = 0; i < argc; i++) {
-            if (JSVAL_IS_OBJECT(argv[i]) && !PrintHelp(cx, JSVAL_TO_OBJECT(argv[i])))
+            if (!JSVAL_IS_PRIMITIVE(argv[i]) && !PrintHelp(cx, JSVAL_TO_OBJECT(argv[i])))
                 return false;
         }
     }
 
     JS_SET_RVAL(cx, vp, JSVAL_VOID);
     return true;
 }
 
--- a/js/src/shell/jsheaptools.cpp
+++ b/js/src/shell/jsheaptools.cpp
@@ -511,31 +511,30 @@ ReferenceFinder::addReferrer(jsval refer
     char *pathName = path->computeName(context);
     if (!pathName)
         return false;
     AutoReleasePtr releasePathName(context, pathName);
 
     Root<jsval> referrerRoot(context, &referrer);
 
     /* Find the property of the results object named |pathName|. */
-    jsval v;
+    JS::Value v;
     if (!JS_GetProperty(context, result, pathName, &v))
         return false;
-    if (JSVAL_IS_VOID(v)) {
+    if (v.isUndefined()) {
         /* Create an array to accumulate referents under this path. */
         JSObject *array = JS_NewArrayObject(context, 1, &referrer);
         if (!array)
             return false;
-        v = OBJECT_TO_JSVAL(array);
+        v.setObject(*array);
         return !!JS_SetProperty(context, result, pathName, &v);
     }
 
     /* The property's value had better be an array. */
-    JS_ASSERT(JSVAL_IS_OBJECT(v) && !JSVAL_IS_NULL(v));
-    RootedVarObject array(context, JSVAL_TO_OBJECT(v));
+    RootedVarObject array(context, &v.toObject());
     JS_ASSERT(JS_IsArrayObject(context, array));
 
     /* Append our referrer to this array. */
     uint32_t length;
     return JS_GetArrayLength(context, array, &length) &&
            JS_SetElement(context, array, length, &referrer);
 }
 
@@ -556,31 +555,31 @@ JSBool
 FindReferences(JSContext *cx, unsigned argc, jsval *vp)
 {
     if (argc < 1) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
                              "findReferences", "0", "s");
         return false;
     }
 
-    jsval target = JS_ARGV(cx, vp)[0];
-    if (!JSVAL_IS_OBJECT(target) || JSVAL_IS_NULL(target)) {
+    JS::Value target = JS_ARGV(cx, vp)[0];
+    if (!target.isObject()) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_UNEXPECTED_TYPE,
                              "argument", "not an object");
         return false;
     }
 
     /* Walk the JSRuntime, producing a reversed map of the heap. */
     HeapReverser reverser(cx);
     if (!reverser.init() || !reverser.reverseHeap())
         return false;
 
     /* Given the reversed map, find the referents of target. */
     ReferenceFinder finder(cx, reverser);
-    JSObject *references = finder.findReferences(RootedVarObject(cx, JSVAL_TO_OBJECT(target)));
+    JSObject *references = finder.findReferences(RootedVarObject(cx, &target.toObject()));
     if (!references)
         return false;
     
     JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(references));
     return true;
 }
 
 #endif /* DEBUG */
--- a/js/src/shell/jsworkers.cpp
+++ b/js/src/shell/jsworkers.cpp
@@ -966,30 +966,30 @@ class UpMessageEvent : public Event
     }
 };
 
 class ErrorEvent : public Event
 {
   public:
     static ErrorEvent *create(JSContext *cx, Worker *child) {
         JSString *data = NULL;
-        jsval exc;
+        JS::Value exc;
         if (JS_GetPendingException(cx, &exc)) {
             AutoValueRooter tvr(cx, exc);
             JS_ClearPendingException(cx);
 
             // Determine what error message to put in the error event.
             // If exc.message is a string, use that; otherwise use String(exc).
             // (This is a little different from what web workers do.)
-            if (JSVAL_IS_OBJECT(exc)) {
-                jsval msg;
-                if (!JS_GetProperty(cx, JSVAL_TO_OBJECT(exc), "message", &msg))
+            if (exc.isObject()) {
+                JS::Value msg;
+                if (!JS_GetProperty(cx, &exc.toObject(), "message", &msg))
                     JS_ClearPendingException(cx);
-                else if (JSVAL_IS_STRING(msg))
-                    data = JSVAL_TO_STRING(msg);
+                else if (msg.isString())
+                    data = msg.toString();
             }
             if (!data) {
                 data = JS_ValueToString(cx, exc);
                 if (!data)
                     return NULL;
             }
         }
         return createEvent<ErrorEvent>(cx, child->getParent(), child,
--- a/js/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/xpconnect/loader/mozJSComponentLoader.cpp
@@ -1008,21 +1008,22 @@ mozJSComponentLoader::Import(const nsACS
                          __LINE__, registryLocation.BeginReading());
 
     JSAutoRequest ar(cx);
 
     JSObject *targetObject = nsnull;
 
     if (optionalArgc) {
         // The caller passed in the optional second argument. Get it.
-        if (!JSVAL_IS_OBJECT(targetObj)) {
+        if (targetObj.isObjectOrNull()) {
+            targetObject = targetObj.toObjectOrNull();
+        } else {
             return ReportOnCaller(cx, ERROR_SCOPE_OBJ,
-                                  PromiseFlatCString(registryLocation).get());
+                                  PromiseFlatCString(registryLocation).get());            
         }
-        targetObject = JSVAL_TO_OBJECT(targetObj);
     } else {
         // Our targetObject is the caller's global object. Find it by
         // walking the calling object's parent chain.
         nsresult rv;
         nsCOMPtr<nsIXPConnect> xpc =
             do_GetService(kXPConnectServiceContractID, &rv);
         NS_ENSURE_SUCCESS(rv, rv);
 
@@ -1166,38 +1167,38 @@ mozJSComponentLoader::ImportInto(const n
         }
 
         mod = newEntry;
     }
 
     NS_ASSERTION(mod->global, "Import table contains entry with no global");
     *_retval = mod->global;
 
-    jsval symbols;
     if (targetObj) {
         JSCLContextHelper cxhelper(this);
 
         JSAutoEnterCompartment ac;
         if (!ac.enter(mContext, mod->global))
             return NS_ERROR_FAILURE;
 
+        JS::Value symbols;
         if (!JS_GetProperty(mContext, mod->global,
                             "EXPORTED_SYMBOLS", &symbols)) {
             return ReportOnCaller(cxhelper, ERROR_NOT_PRESENT,
                                   PromiseFlatCString(aLocation).get());
         }
 
-        JSObject *symbolsObj = nsnull;
-        if (!JSVAL_IS_OBJECT(symbols) ||
-            !(symbolsObj = JSVAL_TO_OBJECT(symbols)) ||
-            !JS_IsArrayObject(mContext, symbolsObj)) {
+        if (!symbols.isObject() ||
+            !JS_IsArrayObject(mContext, &symbols.toObject())) {
             return ReportOnCaller(cxhelper, ERROR_NOT_AN_ARRAY,
                                   PromiseFlatCString(aLocation).get());
         }
 
+        JSObject *symbolsObj = &symbols.toObject();
+
         // Iterate over symbols array, installing symbols on targetObj:
 
         uint32_t symbolCount = 0;
         if (!JS_GetArrayLength(mContext, symbolsObj, &symbolCount)) {
             return ReportOnCaller(cxhelper, ERROR_GETTING_ARRAY_LENGTH,
                                   PromiseFlatCString(aLocation).get());
         }
 
--- a/js/xpconnect/public/nsAutoJSValHolder.h
+++ b/js/xpconnect/public/nsAutoJSValHolder.h
@@ -130,18 +130,18 @@ public:
   bool IsHeld() const {
     return !!mRt;
   }
 
   /**
    * Explicit JSObject* conversion.
    */
   JSObject* ToJSObject() const {
-    return JSVAL_IS_OBJECT(mVal)
-         ? JSVAL_TO_OBJECT(mVal)
+    return mVal.isObject()
+         ? &mVal.toObject()
          : nsnull;
   }
 
   jsval* ToJSValPtr() {
     return &mVal;
   }
 
   /**
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -3310,30 +3310,30 @@ nsXPCComponents_utils_Sandbox::Construct
 {
     return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
 }
 
 // static
 nsresult
 nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
                                                JSContext * cx, JSObject * obj,
-                                               PRUint32 argc, jsval * argv,
+                                               PRUint32 argc, JS::Value * argv,
                                                jsval * vp, bool *_retval)
 {
     if (argc < 1)
         return ThrowAndFail(NS_ERROR_XPC_NOT_ENOUGH_ARGS, cx, _retval);
 
     nsresult rv;
 
     // Make sure to set up principals on the sandbox before initing classes
     nsCOMPtr<nsIScriptObjectPrincipal> sop;
     nsCOMPtr<nsIPrincipal> principal;
     nsISupports *prinOrSop = nsnull;
-    if (JSVAL_IS_STRING(argv[0])) {
-        JSString *codebaseStr = JSVAL_TO_STRING(argv[0]);
+    if (argv[0].isString()) {
+        JSString *codebaseStr = argv[0].toString();
         size_t codebaseLength;
         const jschar *codebaseChars = JS_GetStringCharsAndLength(cx, codebaseStr,
                                                                  &codebaseLength);
         if (!codebaseChars) {
             return ThrowAndFail(NS_ERROR_FAILURE, cx, _retval);
         }
 
         nsAutoString codebase(codebaseChars, codebaseLength);
@@ -3351,22 +3351,22 @@ nsXPCComponents_utils_Sandbox::CallOrCon
             !principal) {
             if (NS_SUCCEEDED(rv))
                 rv = NS_ERROR_FAILURE;
             return ThrowAndFail(rv, cx, _retval);
         }
 
         prinOrSop = principal;
     } else {
-        if (!JSVAL_IS_PRIMITIVE(argv[0])) {
+        if (argv[0].isObject()) {
             nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
             if (!xpc)
                 return NS_ERROR_XPC_UNEXPECTED;
             nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
-            xpc->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(argv[0]),
+            xpc->GetWrappedNativeOfJSObject(cx, &argv[0].toObject(),
                                             getter_AddRefs(wrapper));
 
             if (wrapper) {
                 sop = do_QueryWrappedNative(wrapper);
                 if (sop) {
                     prinOrSop = sop;
                 } else {
                     principal = do_QueryWrappedNative(wrapper);
@@ -3379,57 +3379,57 @@ nsXPCComponents_utils_Sandbox::CallOrCon
             return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
     }
 
     JSObject *proto = nsnull;
     bool wantXrays = true;
     nsCString sandboxName;
 
     if (argc > 1) {
-        if (!JSVAL_IS_OBJECT(argv[1]))
+        if (!argv[1].isObject())
             return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
 
-        JSObject *optionsObject = JSVAL_TO_OBJECT(argv[1]);
+        JSObject *optionsObject = &argv[1].toObject();
         jsval option;
 
         JSBool found;
         if (!JS_HasProperty(cx, optionsObject, "sandboxPrototype", &found))
             return NS_ERROR_INVALID_ARG;
 
         if (found) {
             if (!JS_GetProperty(cx, optionsObject, "sandboxPrototype", &option) ||
-                !JSVAL_IS_OBJECT(option)) {
+                !option.isObject()) {
                 return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
             }
 
-            proto = JSVAL_TO_OBJECT(option);
+            proto = &option.toObject();
         }
 
         if (!JS_HasProperty(cx, optionsObject, "wantXrays", &found))
             return NS_ERROR_INVALID_ARG;
 
         if (found) {
             if (!JS_GetProperty(cx, optionsObject, "wantXrays", &option) ||
-                !JSVAL_IS_BOOLEAN(option)) {
+                !option.isBoolean()) {
                 return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
             }
 
-            wantXrays = JSVAL_TO_BOOLEAN(option);
+            wantXrays = option.toBoolean();
         }
 
         if (!JS_HasProperty(cx, optionsObject, "sandboxName", &found))
             return NS_ERROR_INVALID_ARG;
 
         if (found) {
             if (!JS_GetProperty(cx, optionsObject, "sandboxName", &option) ||
-                !JSVAL_IS_STRING(option)) {
+                !option.isString()) {
                 return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
             }
 
-            char *tmp = JS_EncodeString(cx, JSVAL_TO_STRING(option));
+            char *tmp = JS_EncodeString(cx, option.toString());
             if (!tmp) {
                 return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
             }
 
             sandboxName.Adopt(tmp, strlen(tmp));
         }
     }
 
@@ -3864,28 +3864,28 @@ NS_IMETHODIMP
 nsXPCComponents_Utils::SchedulePreciseShrinkingGC(ScheduledGCCallback* aCallback)
 {
     nsRefPtr<PreciseGCRunnable> event = new PreciseGCRunnable(aCallback, true);
     return NS_DispatchToMainThread(event);
 }
 
 /* [implicit_jscontext] jsval nondeterministicGetWeakMapKeys(in jsval aMap); */
 NS_IMETHODIMP
-nsXPCComponents_Utils::NondeterministicGetWeakMapKeys(const jsval &aMap,
+nsXPCComponents_Utils::NondeterministicGetWeakMapKeys(const JS::Value &aMap,
                                                       JSContext *aCx,
-                                                      jsval *aKeys)
+                                                      JS::Value *aKeys)
 {
-    if (!JSVAL_IS_OBJECT(aMap)) {
-        *aKeys = JSVAL_VOID;
+    if (!aMap.isObject()) {
+        aKeys->setUndefined();
         return NS_OK; 
     }
     JSObject *objRet;
-    if (!JS_NondeterministicGetWeakMapKeys(aCx, JSVAL_TO_OBJECT(aMap), &objRet))
+    if (!JS_NondeterministicGetWeakMapKeys(aCx, &aMap.toObject(), &objRet))
         return NS_ERROR_OUT_OF_MEMORY;
-    *aKeys = objRet ? OBJECT_TO_JSVAL(objRet) : JSVAL_VOID;
+    *aKeys = objRet ? ObjectValue(*objRet) : UndefinedValue();
     return NS_OK;
 }
 
 /* void getDebugObject(); */
 NS_IMETHODIMP
 nsXPCComponents_Utils::GetJSTestingFunctions(JSContext *cx,
                                              JS::Value *retval)
 {
@@ -3956,18 +3956,19 @@ nsXPCComponents_Utils::CreateObjectIn(co
         return NS_ERROR_FAILURE;
     *rval = OBJECT_TO_JSVAL(obj);
     return NS_OK;
 }
 
 JSBool
 FunctionWrapper(JSContext *cx, unsigned argc, jsval *vp)
 {
-    jsval v = js::GetFunctionNativeReserved(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)), 0);
-    NS_ASSERTION(JSVAL_IS_OBJECT(v), "weird function");
+    JSObject *callee = &JS_CALLEE(cx, vp).toObject();
+    JS::Value v = js::GetFunctionNativeReserved(callee, 0);
+    NS_ASSERTION(v.isObject(), "weird function");
 
     JSObject *obj = JS_THIS_OBJECT(cx, vp);
     if (!obj) {
         return JS_FALSE;
     }
     return JS_CallFunctionValue(cx, obj, v, argc, JS_ARGV(cx, vp), vp);
 }
 
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -524,29 +524,27 @@ XPCConvert::JSData2Native(XPCCallContext
 
         switch (type.TagPart()) {
         case nsXPTType::T_VOID:
             XPC_LOG_ERROR(("XPCConvert::JSData2Native : void* params not supported"));
             NS_ERROR("void* params not supported");
             return false;
         case nsXPTType::T_IID:
         {
-            JSObject* obj;
-            const nsID* pid=nsnull;
+            const nsID* pid = nsnull;
 
             // There's no good reason to pass a null IID.
-            if (JSVAL_IS_VOID(s) || JSVAL_IS_NULL(s)) {
+            if (s.isNullOrUndefined()) {
                 if (pErr)
-                  *pErr = NS_ERROR_XPC_BAD_CONVERT_JS;
+                    *pErr = NS_ERROR_XPC_BAD_CONVERT_JS;
                 return false;
             }
 
-            if (!JSVAL_IS_OBJECT(s) ||
-                (!(obj = JSVAL_TO_OBJECT(s))) ||
-                (!(pid = xpc_JSObjectToID(cx, obj))) ||
+            if (!s.isObject() ||
+                (!(pid = xpc_JSObjectToID(cx, &s.toObject()))) ||
                 (!(pid = (const nsID*) nsMemory::Clone(pid, sizeof(nsID))))) {
                 return false;
             }
             *((const nsID**)d) = pid;
             return true;
         }
 
         case nsXPTType::T_ASTRING:
@@ -791,17 +789,16 @@ XPCConvert::JSData2Native(XPCCallContext
             JS_EncodeStringToBuffer(str, rs->BeginWriting(), length);
 
             return true;
         }
 
         case nsXPTType::T_INTERFACE:
         case nsXPTType::T_INTERFACE_IS:
         {
-            JSObject* obj;
             NS_ASSERTION(iid,"can't do interface conversions without iid");
 
             if (iid->Equals(NS_GET_IID(nsIVariant))) {
                 XPCVariant* variant = XPCVariant::newVariant(ccx, s);
                 if (!variant)
                     return false;
                 *((nsISupports**)d) = static_cast<nsIVariant*>(variant);
                 return true;
@@ -820,29 +817,29 @@ XPCConvert::JSData2Native(XPCCallContext
                                                                 chars + length));
                 if (!atom && pErr)
                     *pErr = NS_ERROR_OUT_OF_MEMORY;
                 *((nsISupports**)d) = atom;
                 return atom != nsnull;
             }
             //else ...
 
-            if (JSVAL_IS_VOID(s) || JSVAL_IS_NULL(s)) {
+            if (s.isNullOrUndefined()) {
                 *((nsISupports**)d) = nsnull;
                 return true;
             }
 
             // only wrap JSObjects
-            if (!JSVAL_IS_OBJECT(s) || !(obj = JSVAL_TO_OBJECT(s))) {
-                if (pErr && JSVAL_IS_INT(s) && 0 == JSVAL_TO_INT(s))
+            if (!s.isObject()) {
+                if (pErr && s.isInt32() && 0 == s.toInt32())
                     *pErr = NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL;
                 return false;
             }
 
-            return JSObject2NativeInterface(ccx, (void**)d, obj, iid,
+            return JSObject2NativeInterface(ccx, (void**)d, &s.toObject(), iid,
                                             nsnull, pErr);
         }
         default:
             NS_ERROR("bad type");
             return false;
         }
     }
     return true;
@@ -1738,56 +1735,46 @@ XPCConvert::JSTypedArray2Native(XPCCallC
     if (pErr)
         *pErr = NS_OK;
 
     return true;
 }
 
 // static
 JSBool
-XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, jsval s,
+XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, JS::Value s,
                            uint32_t count, const nsXPTType& type,
                            const nsID* iid, nsresult* pErr)
 {
     NS_ABORT_IF_FALSE(d, "bad param");
 
     JSContext* cx = ccx.GetJSContext();
 
-    // No Action, FRee memory, RElease object
-    enum CleanupMode {na, fr, re};
-
-    CleanupMode cleanupMode;
-
-    JSObject* jsarray = nsnull;
-    void* array = nsnull;
-    uint32_t initedCount;
-    jsval current;
-
     // XXX add support for getting chars from strings
 
     // XXX add support to indicate *which* array element was not convertable
 
-    if (JSVAL_IS_VOID(s) || JSVAL_IS_NULL(s)) {
+    if (s.isNullOrUndefined()) {
         if (0 != count) {
             if (pErr)
                 *pErr = NS_ERROR_XPC_NOT_ENOUGH_ELEMENTS_IN_ARRAY;
             return false;
         }
 
         *d = nsnull;
         return true;
     }
 
-    if (!JSVAL_IS_OBJECT(s)) {
+    if (!s.isObject()) {
         if (pErr)
             *pErr = NS_ERROR_XPC_CANT_CONVERT_PRIMITIVE_TO_ARRAY;
         return false;
     }
 
-    jsarray = JSVAL_TO_OBJECT(s);
+    JSObject* jsarray = &s.toObject();
 
     // If this is a typed array, then try a fast conversion with memcpy.
     if (JS_IsTypedArrayObject(jsarray, cx)) {
         return JSTypedArray2Native(ccx, d, jsarray, count, type, pErr);
     }
 
     if (!JS_IsArrayObject(cx, jsarray)) {
         if (pErr)
@@ -1818,19 +1805,26 @@ XPCConvert::JSArray2Native(XPCCallContex
         for (initedCount = 0; initedCount < count; initedCount++) {           \
             if (!JS_GetElement(cx, jsarray, initedCount, &current) ||         \
                 !JSData2Native(ccx, ((_t*)array)+initedCount, current, type,  \
                                true, iid, pErr))                              \
                 goto failure;                                                 \
         }                                                                     \
     PR_END_MACRO
 
+    // No Action, FRee memory, RElease object
+    enum CleanupMode {na, fr, re};
+
+    CleanupMode cleanupMode;
+
+    void *array = nsnull;
+    uint32_t initedCount;
+    jsval current;
 
     // XXX check IsPtr - esp. to handle array of nsID (as opposed to nsID*)
-
     // XXX make extra space at end of char* and wchar* and null termintate
 
     switch (type.TagPart()) {
     case nsXPTType::T_I8            : POPULATE(na, int8_t);         break;
     case nsXPTType::T_I16           : POPULATE(na, int16_t);        break;
     case nsXPTType::T_I32           : POPULATE(na, int32_t);        break;
     case nsXPTType::T_I64           : POPULATE(na, int64_t);        break;
     case nsXPTType::T_U8            : POPULATE(na, uint8_t);        break;
--- a/js/xpconnect/src/XPCDebug.cpp
+++ b/js/xpconnect/src/XPCDebug.cpp
@@ -74,17 +74,16 @@ static char* FormatJSFrame(JSContext* cx
     jsval thisVal;
     JSObject* callObj = nsnull;
     JSString* funname = nsnull;
     JSAutoByteString funbytes;
     const char* filename = nsnull;
     PRInt32 lineno = 0;
     JSFunction* fun = nsnull;
     uint32_t namedArgCount = 0;
-    jsval val;
     JSBool isString;
 
     // get the info for this stack frame
 
     JSScript* script = JS_GetFrameScript(cx, fp);
     jsbytecode* pc = JS_GetFramePC(cx, fp);
 
     JSAutoRequest ar(cx);
@@ -147,21 +146,21 @@ static char* FormatJSFrame(JSContext* cx
                                         value ? value : "?unknown?",
                                         isString ? "\"" : "");
                 if (!buf) goto out;
                 namedArgCount++;
             }
         }
 
         // print any unnamed trailing args (found in 'arguments' object)
-
+        JS::Value val;
         if (JS_GetProperty(cx, callObj, "arguments", &val) &&
-            JSVAL_IS_OBJECT(val)) {
+            val.isObject()) {
             uint32_t argCount;
-            JSObject* argsObj = JSVAL_TO_OBJECT(val);
+            JSObject* argsObj = &val.toObject();
             if (JS_GetProperty(cx, argsObj, "length", &val) &&
                 JS_ValueToECMAUint32(cx, val, &argCount) &&
                 argCount > namedArgCount) {
                 for (uint32_t k = namedArgCount; k < argCount; k++) {
                     char number[8];
                     JS_snprintf(number, 8, "%d", (int) k);
 
                     if (JS_GetProperty(cx, argsObj, number, &val)) {
--- a/js/xpconnect/src/XPCQuickStubs.cpp
+++ b/js/xpconnect/src/XPCQuickStubs.cpp
@@ -816,34 +816,34 @@ xpc_qsUnwrapThisFromCcxImpl(XPCCallConte
                             ccx.GetFlattenedJSObject(), iid, ppThis, pThisRef,
                             vp);
     if (NS_FAILED(rv))
         return xpc_qsThrow(ccx.GetJSContext(), rv);
     return true;
 }
 
 JSObject*
-xpc_qsUnwrapObj(jsval v, nsISupports **ppArgRef, nsresult *rv)
+xpc_qsUnwrapObj(JS::Value v, nsISupports **ppArgRef, nsresult *rv)
 {
-    if (JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v)) {
+    if (v.isNullOrUndefined()) {
         *ppArgRef = nsnull;
         *rv = NS_OK;
         return nsnull;
     }
 
-    if (!JSVAL_IS_OBJECT(v)) {
+    if (!v.isObject()) {
         *ppArgRef = nsnull;
-        *rv = ((JSVAL_IS_INT(v) && JSVAL_TO_INT(v) == 0)
+        *rv = ((v.isInt32() && v.toInt32() == 0)
                ? NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL
                : NS_ERROR_XPC_BAD_CONVERT_JS);
         return nsnull;
     }
 
     *rv = NS_OK;
-    return JSVAL_TO_OBJECT(v);
+    return &v.toObject();
 }
 
 nsresult
 xpc_qsUnwrapArgImpl(JSContext *cx,
                     jsval v,
                     const nsIID &iid,
                     void **ppArg,
                     nsISupports **ppArgRef,
--- a/js/xpconnect/src/XPCVariant.cpp
+++ b/js/xpconnect/src/XPCVariant.cpp
@@ -112,39 +112,39 @@ void XPCTraceableVariant::TraceJS(JSTrac
 void
 XPCTraceableVariant::PrintTraceName(JSTracer* trc, char *buf, size_t bufsize)
 {
     JS_snprintf(buf, bufsize, "XPCVariant[0x%p].mJSVal", trc->debugPrintArg);
 }
 #endif
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(XPCVariant)
-    jsval val = tmp->GetJSValPreserveColor();
-    if (JSVAL_IS_OBJECT(val)) {
+    JS::Value val = tmp->GetJSValPreserveColor();
+    if (val.isObjectOrNull()) {
         NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mJSVal");
         cb.NoteJSChild(JSVAL_TO_OBJECT(val));
     }
 
     nsVariant::Traverse(tmp->mData, cb);
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant)
-    jsval val = tmp->GetJSValPreserveColor();
+    JS::Value val = tmp->GetJSValPreserveColor();
 
     // We're sharing val's buffer, clear the pointer to it so Cleanup() won't
     // try to delete it
-    if (JSVAL_IS_STRING(val))
+    if (val.isString())
         tmp->mData.u.wstr.mWStringValue = nsnull;
     nsVariant::Cleanup(&tmp->mData);
 
-    if (JSVAL_IS_TRACEABLE(val)) {
+    if (val.isMarkable()) {
         XPCTraceableVariant *v = static_cast<XPCTraceableVariant*>(tmp);
         v->RemoveFromRootSet(nsXPConnect::GetRuntimeInstance()->GetMapLock());
     }
-    tmp->mJSVal = JSVAL_NULL;
+    tmp->mJSVal = JS::NullValue();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 // static
 XPCVariant* XPCVariant::newVariant(XPCCallContext& ccx, jsval aJSVal)
 {
     XPCVariant* variant;
 
     if (!JSVAL_IS_TRACEABLE(aJSVal))
@@ -216,36 +216,36 @@ JSBool
 XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
                                      uint32_t length,
                                      nsXPTType* resultType, nsID* resultID)
 {
     Type state = tUnk;
     Type type;
 
     for (uint32_t i = 0; i < length; i++) {
-        jsval val;
+        JS::Value val;
         if (!JS_GetElement(ccx, array, i, &val))
             return false;
 
-        if (JSVAL_IS_INT(val))
+        if (val.isInt32()) {
             type = tInt;
-        else if (JSVAL_IS_DOUBLE(val))
+        } else if (val.isDouble()) {
             type = tDbl;
-        else if (JSVAL_IS_BOOLEAN(val))
+        } else if (val.isBoolean()) {
             type = tBool;
-        else if (JSVAL_IS_VOID(val)) {
+        } else if (val.isUndefined()) { 
             state = tVar;
             break;
-        } else if (JSVAL_IS_NULL(val))
+        } else if (val.isNull()) {
             type = tNull;
-        else if (JSVAL_IS_STRING(val))
+        } else if (val.isString()) {
             type = tStr;
-        else {
-            NS_ASSERTION(JSVAL_IS_OBJECT(val), "invalid type of jsval!");
-            JSObject* jsobj = JSVAL_TO_OBJECT(val);
+        } else {
+            NS_ASSERTION(val.isObject(), "invalid type of jsval!");
+            JSObject* jsobj = &val.toObject();
             if (JS_IsArrayObject(ccx, jsobj))
                 type = tArr;
             else if (xpc_JSObjectIsID(ccx, jsobj))
                 type = tID;
             else
                 type = tISup;
         }
 
@@ -301,34 +301,32 @@ XPCArrayHomogenizer::GetTypeForArray(XPC
     }
     return true;
 }
 
 JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
 {
     JS_CHECK_RECURSION(ccx.GetJSContext(), return false);
 
-    jsval val = GetJSVal();
+    JS::Value val = GetJSVal();
 
-    if (JSVAL_IS_INT(val))
-        return NS_SUCCEEDED(nsVariant::SetFromInt32(&mData, JSVAL_TO_INT(val)));
-    if (JSVAL_IS_DOUBLE(val))
-        return NS_SUCCEEDED(nsVariant::SetFromDouble(&mData,
-                                                     JSVAL_TO_DOUBLE(val)));
-    if (JSVAL_IS_BOOLEAN(val))
-        return NS_SUCCEEDED(nsVariant::SetFromBool(&mData,
-                                                   JSVAL_TO_BOOLEAN(val)));
-    if (JSVAL_IS_VOID(val))
+    if (val.isInt32())
+        return NS_SUCCEEDED(nsVariant::SetFromInt32(&mData, val.toInt32()));
+    if (val.isDouble())
+        return NS_SUCCEEDED(nsVariant::SetFromDouble(&mData, val.toDouble()));
+    if (val.isBoolean())
+        return NS_SUCCEEDED(nsVariant::SetFromBool(&mData, val.toBoolean()));
+    if (val.isUndefined())
         return NS_SUCCEEDED(nsVariant::SetToVoid(&mData));
-    if (JSVAL_IS_NULL(val))
+    if (val.isNull())
         return NS_SUCCEEDED(nsVariant::SetToEmpty(&mData));
-    if (JSVAL_IS_STRING(val)) {
+    if (val.isString()) {
         // Make our string immutable.  This will also ensure null-termination,
         // which nsVariant assumes for its PRUnichar* stuff.
-        JSString* str = JSVAL_TO_STRING(val);
+        JSString* str = val.toString();
         if (!JS_MakeStringImmutable(ccx, str))
             return false;
 
         // Don't use nsVariant::SetFromWStringWithSize, because that will copy
         // the data.  Just handle this ourselves.  Note that it's ok to not
         // copy because we added mJSVal as a GC root.
         NS_ASSERTION(mData.mType == nsIDataType::VTYPE_EMPTY,
                      "Why do we already have data?");
@@ -345,19 +343,19 @@ JSBool XPCVariant::InitializeData(XPCCal
         // PRUint32 is not valid on some platforms.
         mData.u.wstr.mWStringLength = (PRUint32)length;
         mData.mType = nsIDataType::VTYPE_WSTRING_SIZE_IS;
 
         return true;
     }
 
     // leaving only JSObject...
-    NS_ASSERTION(JSVAL_IS_OBJECT(val), "invalid type of jsval!");
+    NS_ASSERTION(val.isObject(), "invalid type of jsval!");
 
-    JSObject* jsobj = JSVAL_TO_OBJECT(val);
+    JSObject* jsobj = &val.toObject();
 
     // Let's see if it is a xpcJSID.
 
     const nsID* id = xpc_JSObjectToID(ccx, jsobj);
     if (id)
         return NS_SUCCEEDED(nsVariant::SetFromID(&mData, *id));
 
     // Let's see if it is a js array object.
--- a/js/xpconnect/src/XPCWrappedJSClass.cpp
+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
@@ -303,24 +303,24 @@ nsXPCWrappedJSClass::CallQueryInterfaceO
             NS_ASSERTION(JS_IsExceptionPending(cx),
                          "JS failed without setting an exception!");
 
             jsval jsexception = JSVAL_NULL;
             AUTO_MARK_JSVAL(ccx, &jsexception);
 
             if (JS_GetPendingException(cx, &jsexception)) {
                 nsresult rv;
-                if (JSVAL_IS_OBJECT(jsexception)) {
+                if (jsexception.isObject()) {
                     // XPConnect may have constructed an object to represent a
                     // C++ QI failure. See if that is the case.
                     nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
 
                     nsXPConnect::GetXPConnect()->
                         GetWrappedNativeOfJSObject(ccx,
-                                                   JSVAL_TO_OBJECT(jsexception),
+                                                   &jsexception.toObject(),
                                                    getter_AddRefs(wrapper));
 
                     if (wrapper) {
                         nsCOMPtr<nsIException> exception =
                             do_QueryWrappedNative(wrapper);
                         if (exception &&
                             NS_SUCCEEDED(exception->GetResult(&rv)) &&
                             rv == NS_NOINTERFACE) {
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -2639,19 +2639,19 @@ CallMethodHelper::GatherAndConvertResult
                 return false;
             }
         }
 
         if (paramInfo.IsRetval()) {
             mCallContext.SetRetVal(v);
         } else if (i < mArgc) {
             // we actually assured this before doing the invoke
-            NS_ASSERTION(JSVAL_IS_OBJECT(mArgv[i]), "out var is not object");
+            NS_ASSERTION(mArgv[i].isObject(), "out var is not object");
             if (!JS_SetPropertyById(mCallContext,
-                                    JSVAL_TO_OBJECT(mArgv[i]),
+                                    &mArgv[i].toObject(),
                                     mIdxValueId, &v)) {
                 ThrowBadParam(NS_ERROR_XPC_CANT_SET_OUT_VAL, i, mCallContext);
                 return false;
             }
         } else {
             NS_ASSERTION(paramInfo.IsOptional(),
                          "Expected either enough arguments or an optional argument");
         }
@@ -2665,21 +2665,24 @@ CallMethodHelper::QueryInterfaceFastPath
 {
     NS_ASSERTION(mVTableIndex == 0,
                  "Using the QI fast-path for a method other than QueryInterface");
 
     if (mArgc < 1) {
         Throw(NS_ERROR_XPC_NOT_ENOUGH_ARGS, mCallContext);
         return false;
     }
-    const nsID* iid;
-    JSObject* obj;
-    if (!JSVAL_IS_OBJECT(mArgv[0]) ||
-        (!(obj = JSVAL_TO_OBJECT(mArgv[0]))) ||
-        (!(iid = xpc_JSObjectToID(mCallContext, obj)))) {
+    
+    if (!mArgv[0].isObject()) {
+        ThrowBadParam(NS_ERROR_XPC_BAD_CONVERT_JS, 0, mCallContext);
+        return false;
+    }
+
+    const nsID* iid = xpc_JSObjectToID(mCallContext, &mArgv[0].toObject());
+    if (!iid) {
         ThrowBadParam(NS_ERROR_XPC_BAD_CONVERT_JS, 0, mCallContext);
         return false;
     }
 
     nsresult invokeResult;
     nsISupports* qiresult = nsnull;
     if (XPCPerThreadData::IsMainThread(mCallContext)) {
         invokeResult = mCallee->QueryInterface(*iid, (void**) &qiresult);
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -2885,39 +2885,38 @@ JS_EXPORT_API(void) DumpJSEval(PRUint32 
         printf("failed to get XPConnect service!\n");
 }
 
 JS_EXPORT_API(void) DumpJSObject(JSObject* obj)
 {
     xpc_DumpJSObject(obj);
 }
 
-JS_EXPORT_API(void) DumpJSValue(jsval val)
+JS_EXPORT_API(void) DumpJSValue(JS::Value val)
 {
-    printf("Dumping 0x%llu.\n", (long long) JSVAL_TO_IMPL(val).asBits);
-    if (JSVAL_IS_NULL(val)) {
+    printf("Dumping 0x%llu.\n", (long long) val.asRawBits());
+    if (val.isNull()) {
         printf("Value is null\n");
-    } else if (JSVAL_IS_OBJECT(val) || JSVAL_IS_NULL(val)) {
+    } else if (val.isObject()) {
         printf("Value is an object\n");
-        JSObject* obj = JSVAL_TO_OBJECT(val);
-        DumpJSObject(obj);
-    } else if (JSVAL_IS_NUMBER(val)) {
+        DumpJSObject(&val.toObject());
+    } else if (val.isNumber()) {
         printf("Value is a number: ");
-        if (JSVAL_IS_INT(val))
-          printf("Integer %i\n", JSVAL_TO_INT(val));
-        else if (JSVAL_IS_DOUBLE(val))
-          printf("Floating-point value %f\n", JSVAL_TO_DOUBLE(val));
-    } else if (JSVAL_IS_STRING(val)) {
+        if (val.isInt32())
+          printf("Integer %i\n", val.toInt32());
+        else if (val.isDouble())
+          printf("Floating-point value %f\n", val.toDouble());
+    } else if (val.isString()) {
         printf("Value is a string: ");
         putc('<', stdout);
-        JS_FileEscapedString(stdout, JSVAL_TO_STRING(val), 0);
+        JS_FileEscapedString(stdout, val.toString(), 0);
         fputs(">\n", stdout);
-    } else if (JSVAL_IS_BOOLEAN(val)) {
+    } else if (val.isBoolean()) {
         printf("Value is boolean: ");
-        printf(JSVAL_TO_BOOLEAN(val) ? "true" : "false");
-    } else if (JSVAL_IS_VOID(val)) {
+        printf(val.isTrue() ? "true" : "false");
+    } else if (val.isUndefined()) {
         printf("Value is undefined\n");
     } else {
         printf("No idea what this value is.\n");
     }
 }
 JS_END_EXTERN_C
 
--- a/js/xpconnect/wrappers/AccessCheck.cpp
+++ b/js/xpconnect/wrappers/AccessCheck.cpp
@@ -528,30 +528,30 @@ ExposedPropertiesOnly::check(JSContext *
     }
 
     if (id == JSID_VOID) {
         // This will force the caller to call us back for individual property accesses.
         perm = PermitPropertyAccess;
         return true;
     }
 
-    jsval exposedProps;
+    JS::Value exposedProps;
     if (!JS_LookupPropertyById(cx, wrappedObject, exposedPropsId, &exposedProps))
         return false;
 
-    if (JSVAL_IS_VOID(exposedProps) || JSVAL_IS_NULL(exposedProps)) {
+    if (exposedProps.isNullOrUndefined()) {
         return PermitIfUniversalXPConnect(cx, id, act, perm); // Deny
     }
 
-    if (!JSVAL_IS_OBJECT(exposedProps)) {
+    if (!exposedProps.isObject()) {
         JS_ReportError(cx, "__exposedProps__ must be undefined, null, or an Object");
         return false;
     }
 
-    JSObject *hallpass = JSVAL_TO_OBJECT(exposedProps);
+    JSObject *hallpass = &exposedProps.toObject();
 
     Access access = NO_ACCESS;
 
     JSPropertyDescriptor desc;
     if (!JS_GetPropertyDescriptorById(cx, hallpass, id, JSRESOLVE_QUALIFIED, &desc)) {
         return false; // Error
     }
     if (desc.obj == NULL || !(desc.attrs & JSPROP_ENUMERATE)) {
--- a/storage/src/mozStoragePrivateHelpers.cpp
+++ b/storage/src/mozStoragePrivateHelpers.cpp
@@ -142,40 +142,39 @@ checkAndLogStatementPerformance(sqlite3_
   message.Append("'.  See https://developer.mozilla.org/En/Storage/Warnings "
                  "details.");
   NS_WARNING(message.get());
 }
 
 nsIVariant *
 convertJSValToVariant(
   JSContext *aCtx,
-  jsval aValue)
+  JS::Value aValue)
 {
-  if (JSVAL_IS_INT(aValue))
-    return new IntegerVariant(JSVAL_TO_INT(aValue));
+  if (aValue.isInt32())
+    return new IntegerVariant(aValue.toInt32());
 
-  if (JSVAL_IS_DOUBLE(aValue))
-    return new FloatVariant(JSVAL_TO_DOUBLE(aValue));
+  if (aValue.isDouble())
+    return new FloatVariant(aValue.toDouble());
 
-  if (JSVAL_IS_STRING(aValue)) {
-    JSString *str = JSVAL_TO_STRING(aValue);
+  if (aValue.isString()) {
     nsDependentJSString value;
-    if (!value.init(aCtx, str))
+    if (!value.init(aCtx, aValue))
         return nsnull;
     return new TextVariant(value);
   }
 
-  if (JSVAL_IS_BOOLEAN(aValue))
-    return new IntegerVariant((aValue == JSVAL_TRUE) ? 1 : 0);
+  if (aValue.isBoolean())
+    return new IntegerVariant(aValue.isTrue() ? 1 : 0);
 
-  if (JSVAL_IS_NULL(aValue))
+  if (aValue.isNull())
     return new NullVariant();
 
-  if (JSVAL_IS_OBJECT(aValue)) {
-    JSObject *obj = JSVAL_TO_OBJECT(aValue);
+  if (aValue.isObject()) {
+    JSObject* obj = &aValue.toObject();
     // We only support Date instances, all others fail.
     if (!::js_DateIsValid(aCtx, obj))
       return nsnull;
 
     double msecd = ::js_DateGetMsecSinceEpoch(aCtx, obj);
     msecd *= 1000.0;
     PRInt64 msec;
     LL_D2L(msec, msecd);