Bug 905017 (part 1) - Minimize inclusions of JS engine headers in .h and .idl files. r=billm.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sat, 17 Aug 2013 15:50:18 -0700
changeset 157698 dba0f0715b188190b2fe9a924f613ea02af9bf3e
parent 157648 493cd772def771176cc9e59ccfadc2c78ed03198
child 157699 b43d38c5c456e95690c1b4c41d0a37a79dc1eab4
push id407
push userlsblakk@mozilla.com
push dateTue, 03 Dec 2013 03:32:50 +0000
treeherdermozilla-release@babf8c9ebc52 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs905017
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 905017 (part 1) - Minimize inclusions of JS engine headers in .h and .idl files. r=billm.
caps/include/nsScriptSecurityManager.h
content/base/public/nsIDOMFile.idl
content/base/public/nsIXMLHttpRequest.idl
content/base/src/WebSocket.h
content/base/src/nsFrameMessageManager.h
content/base/src/nsInProcessTabChildGlobal.h
content/base/src/nsXMLHttpRequest.h
content/canvas/src/ImageData.h
content/canvas/src/WebGLActiveInfo.h
content/events/src/nsDOMMessageEvent.h
content/events/src/nsEventListenerManager.h
content/html/content/src/HTMLPropertiesCollection.h
content/html/content/src/nsDOMStringMap.h
content/html/document/src/nsHTMLDocument.h
content/xbl/src/nsXBLBinding.h
content/xbl/src/nsXBLMaybeCompiled.h
content/xbl/src/nsXBLProtoImplMember.h
content/xbl/src/nsXBLProtoImplMethod.h
content/xbl/src/nsXBLProtoImplProperty.h
content/xbl/src/nsXBLPrototypeHandler.h
content/xbl/src/nsXBLSerialize.h
content/xul/content/src/nsXULElement.h
content/xul/document/src/nsXULPrototypeCache.h
dom/base/StructuredCloneTags.h
dom/base/WindowNamedPropertiesHandler.h
dom/base/nsDOMClassInfo.h
dom/base/nsDOMJSUtils.h
dom/base/nsGlobalWindow.cpp
dom/base/nsIJSEventListener.h
dom/base/nsIJSNativeInitializer.h
dom/base/nsIScriptContext.h
dom/base/nsJSEnvironment.h
dom/base/nsPIDOMWindow.h
dom/base/nsStructuredCloneContainer.cpp
dom/base/nsStructuredCloneContainer.h
dom/base/nsWrapperCache.h
dom/base/nsWrapperCacheInlines.h
dom/bindings/BindingDeclarations.h
dom/bindings/BindingUtils.cpp
dom/bindings/CallbackObject.h
dom/bindings/DOMJSClass.h
dom/bindings/DOMJSProxyHandler.h
dom/bindings/TypedArray.h
dom/camera/ICameraControl.h
dom/interfaces/html/nsIDOMHTMLCanvasElement.idl
dom/interfaces/json/nsIJSON.idl
dom/ipc/StructuredCloneUtils.h
dom/ipc/TabChild.h
dom/ipc/TabParent.h
dom/mobilemessage/src/MmsMessage.h
dom/mobilemessage/src/MobileMessageThread.h
dom/mobilemessage/src/SmsMessage.h
dom/plugins/base/nsJSNPRuntime.h
dom/plugins/base/nsNPAPIPlugin.h
dom/plugins/ipc/PluginScriptableObjectParent.h
dom/src/events/nsJSEventListener.h
dom/src/json/nsJSON.h
dom/system/OSFileConstants.h
dom/workers/Exceptions.h
dom/workers/File.h
dom/workers/Location.h
dom/workers/Principal.h
dom/workers/RuntimeService.h
dom/workers/ScriptLoader.h
dom/workers/Worker.h
dom/workers/WorkerPrivate.h
embedding/components/windowwatcher/src/nsWindowWatcher.h
ipc/glue/SyncChannel.h
ipc/testshell/TestShellParent.h
js/ipc/JavaScriptParent.cpp
js/ipc/JavaScriptParent.h
js/ipc/JavaScriptShared.h
js/jsd/jsd.h
js/jsd/jsd_text.cpp
js/jsd/jsd_xpc.cpp
js/jsd/jsdebug.h
js/jsd/jshash.h
js/public/GCAPI.h
js/src/jsfriendapi.cpp
js/src/jspubtd.h
js/xpconnect/idl/nsIJSRuntimeService.idl
js/xpconnect/idl/nsIXPConnect.idl
js/xpconnect/idl/xpcexception.idl
js/xpconnect/loader/mozJSComponentLoader.h
js/xpconnect/loader/mozJSLoaderUtils.h
js/xpconnect/loader/mozJSSubScriptLoader.h
js/xpconnect/public/nsAXPCNativeCallContext.h
js/xpconnect/public/nsAutoJSValHolder.h
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCConvert.cpp
js/xpconnect/src/XPCDebug.cpp
js/xpconnect/src/XPCException.cpp
js/xpconnect/src/XPCInlines.h
js/xpconnect/src/XPCJSRuntime.cpp
js/xpconnect/src/XPCMaps.h
js/xpconnect/src/XPCQuickStubs.cpp
js/xpconnect/src/XPCStack.cpp
js/xpconnect/src/XPCThrower.cpp
js/xpconnect/src/XPCVariant.cpp
js/xpconnect/src/XPCWrappedJS.cpp
js/xpconnect/src/XPCWrappedJSClass.cpp
js/xpconnect/src/XPCWrappedNative.cpp
js/xpconnect/src/XPCWrappedNativeInfo.cpp
js/xpconnect/src/XPCWrappedNativeJSOps.cpp
js/xpconnect/src/XPCWrapper.h
js/xpconnect/src/nsScriptError.cpp
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcprivate.h
js/xpconnect/src/xpcpublic.h
js/xpconnect/tests/components/native/xpctest_params.cpp
js/xpconnect/tests/components/native/xpctest_private.h
js/xpconnect/wrappers/AccessCheck.h
js/xpconnect/wrappers/WaiveXrayWrapper.h
js/xpconnect/wrappers/WrapperFactory.h
js/xpconnect/wrappers/XrayWrapper.cpp
js/xpconnect/wrappers/XrayWrapper.h
layout/style/nsNthIndexCache.h
media/webrtc/signaling/src/peerconnection/MediaStreamList.h
netwerk/base/src/ArrayBufferInputStream.h
netwerk/base/src/ProxyAutoConfig.h
security/manager/ssl/src/nsCrypto.h
storage/src/mozStorageAsyncStatementJSHelper.h
storage/src/mozStorageAsyncStatementParams.cpp
storage/src/mozStoragePrivateHelpers.h
storage/src/mozStorageStatementJSHelper.h
storage/src/mozStorageStatementParams.cpp
toolkit/components/ctypes/tests/jsctypes-test-errno.h
toolkit/components/ctypes/tests/jsctypes-test-finalizer.h
toolkit/components/ctypes/tests/jsctypes-test.h
toolkit/components/places/Helpers.h
toolkit/components/places/PlaceInfo.cpp
toolkit/components/places/mozIAsyncHistory.idl
toolkit/components/places/mozIAsyncLivemarks.idl
tools/profiler/GeckoProfiler.h
tools/profiler/GeckoProfilerFunc.h
tools/profiler/GeckoProfilerImpl.h
tools/profiler/JSObjectBuilder.h
tools/profiler/SaveProfileTask.h
xpcom/base/CycleCollectedJSRuntime.h
xpcom/build/mozPoisonWriteMac.cpp
xpcom/reflect/xptcall/public/xptcall.h
xpcom/tests/TestHarness.h
--- a/caps/include/nsScriptSecurityManager.h
+++ b/caps/include/nsScriptSecurityManager.h
@@ -4,30 +4,32 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsScriptSecurityManager_h__
 #define nsScriptSecurityManager_h__
 
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrincipal.h"
-#include "jsapi.h"
-#include "jsdbgapi.h"
 #include "nsIXPCSecurityManager.h"
 #include "nsInterfaceHashtable.h"
 #include "nsHashtable.h"
 #include "nsCOMPtr.h"
 #include "nsIChannelEventSink.h"
 #include "nsIObserver.h"
 #include "pldhash.h"
 #include "plstr.h"
 #include "nsIScriptExternalNameSet.h"
 
 #include <stdint.h>
 
+namespace JS {
+template <typename T> class Handle;
+template <typename T> class MutableHandle;
+}
 class nsIDocShell;
 class nsString;
 class nsIClassInfo;
 class nsIIOService;
 class nsIStringBundle;
 class nsSystemPrincipal;
 struct ClassPolicy;
 class ClassInfoData;
--- a/content/base/public/nsIDOMFile.idl
+++ b/content/base/public/nsIDOMFile.idl
@@ -1,18 +1,16 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "domstubs.idl"
 
 %{C++
-#include "jsapi.h"
-
 namespace mozilla {
 namespace dom {
 namespace indexedDB {
 class FileInfo;
 class FileManager;
 }
 }
 }
--- a/content/base/public/nsIXMLHttpRequest.idl
+++ b/content/base/public/nsIXMLHttpRequest.idl
@@ -11,21 +11,16 @@ interface nsIDOMEventListener;
 interface nsIPrincipal;
 interface nsIScriptContext;
 interface nsIURI;
 interface nsIVariant;
 interface nsIGlobalObject;
 interface nsIInputStream;
 interface nsIDOMBlob;
 
-%{C++
-// for jsval
-#include "jsapi.h"
-%}
-
 [scriptable, builtinclass, uuid(ac97e161-9f1d-4163-adc9-e9a59e18682c)]
 interface nsIXMLHttpRequestEventTarget : nsIDOMEventTarget {
   // event handler attributes
   [implicit_jscontext] attribute jsval onabort;
   [implicit_jscontext] attribute jsval onerror;
   [implicit_jscontext] attribute jsval onload;
   [implicit_jscontext] attribute jsval onloadstart;
   [implicit_jscontext] attribute jsval onprogress;
--- a/content/base/src/WebSocket.h
+++ b/content/base/src/WebSocket.h
@@ -17,17 +17,16 @@
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/TypedArray.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/EventHandlerBinding.h"
 
 // Need this for BinaryType.
 #include "mozilla/dom/WebSocketBinding.h"
 
-#include "jsfriendapi.h"
 #include "nsISupportsUtils.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsIPrincipal.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIDOMEventListener.h"
 #include "nsDOMEventTargetHelper.h"
 #include "nsAutoPtr.h"
--- a/content/base/src/nsFrameMessageManager.h
+++ b/content/base/src/nsFrameMessageManager.h
@@ -18,16 +18,17 @@
 #include "nsIPrincipal.h"
 #include "nsIXPConnect.h"
 #include "nsDataHashtable.h"
 #include "mozilla/Services.h"
 #include "nsIObserverService.h"
 #include "nsThreadUtils.h"
 #include "nsWeakPtr.h"
 #include "mozilla/Attributes.h"
+#include "js/RootingAPI.h"
 
 namespace mozilla {
 namespace dom {
 
 class ContentParent;
 class ContentChild;
 struct StructuredCloneData;
 class ClonedMessageData;
@@ -130,17 +131,17 @@ class MOZ_STACK_CLASS SameProcessCpowHol
     SameProcessCpowHolder(JSRuntime *aRuntime, JS::Handle<JSObject *> aObj)
       : mObj(aRuntime, aObj)
     {
     }
 
     bool ToObject(JSContext* aCx, JSObject** aObjp);
 
   private:
-    JS::RootedObject mObj;
+    JS::Rooted<JSObject*> mObj;
 };
 
 class nsFrameMessageManager MOZ_FINAL : public nsIContentFrameMessageManager,
                                         public nsIMessageBroadcaster,
                                         public nsIFrameScriptLoader,
                                         public nsIProcessChecker
 {
   typedef mozilla::dom::StructuredCloneData StructuredCloneData;
--- a/content/base/src/nsInProcessTabChildGlobal.h
+++ b/content/base/src/nsInProcessTabChildGlobal.h
@@ -10,17 +10,16 @@
 #include "mozilla/Attributes.h"
 #include "nsCOMPtr.h"
 #include "nsFrameMessageManager.h"
 #include "nsIScriptContext.h"
 #include "nsDOMEventTargetHelper.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIScriptContext.h"
 #include "nsIClassInfo.h"
-#include "jsapi.h"
 #include "nsIDocShell.h"
 #include "nsIDOMElement.h"
 #include "nsCOMArray.h"
 #include "nsThreadUtils.h"
 #include "nsIGlobalObject.h"
 #include "nsWeakReference.h"
 
 class nsInProcessTabChildGlobal : public nsDOMEventTargetHelper,
--- a/content/base/src/nsXMLHttpRequest.h
+++ b/content/base/src/nsXMLHttpRequest.h
@@ -12,17 +12,16 @@
 #include "nsISupportsUtils.h"
 #include "nsString.h"
 #include "nsIURI.h"
 #include "nsIHttpChannel.h"
 #include "nsIJARChannel.h"
 #include "nsIDocument.h"
 #include "nsIStreamListener.h"
 #include "nsWeakReference.h"
-#include "jsapi.h"
 #include "nsIScriptContext.h"
 #include "nsIChannelEventSink.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIHttpHeaderVisitor.h"
 #include "nsIProgressEventSink.h"
 #include "nsCOMArray.h"
 #include "nsJSUtils.h"
--- a/content/canvas/src/ImageData.h
+++ b/content/canvas/src/ImageData.h
@@ -11,18 +11,16 @@
 
 #include "mozilla/Attributes.h"
 #include <stdint.h>
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsTraceRefcnt.h"
 #include "xpcpublic.h"
 
-#include "jsapi.h"
-
 namespace mozilla {
 namespace dom {
 
 class ImageData MOZ_FINAL : public nsISupports
 {
 public:
   ImageData(uint32_t aWidth, uint32_t aHeight, JSObject& aData)
     : mWidth(aWidth)
--- a/content/canvas/src/WebGLActiveInfo.h
+++ b/content/canvas/src/WebGLActiveInfo.h
@@ -4,17 +4,22 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef WEBGLACTIVEINFO_H_
 #define WEBGLACTIVEINFO_H_
 
 #include "WebGLTypes.h"
 #include "nsISupports.h"
 #include "nsString.h"
-#include "jsapi.h"
+
+struct JSContext;
+class JSObject;
+namespace JS {
+template <typename T> class Handle;
+}
 
 namespace mozilla {
 
 class WebGLActiveInfo MOZ_FINAL
     : public nsISupports
 {
 public:
     WebGLActiveInfo(WebGLint size, WebGLenum type, const nsACString& name) :
--- a/content/events/src/nsDOMMessageEvent.h
+++ b/content/events/src/nsDOMMessageEvent.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsDOMMessageEvent_h__
 #define nsDOMMessageEvent_h__
 
 #include "nsIDOMMessageEvent.h"
 #include "nsDOMEvent.h"
 #include "nsCycleCollectionParticipant.h"
-#include "jsapi.h"
 #include "mozilla/dom/MessageEventBinding.h"
 
 /**
  * Implements the MessageEvent event, used for cross-document messaging and
  * server-sent events.
  *
  * See http://www.whatwg.org/specs/web-apps/current-work/#messageevent for
  * further details.
--- a/content/events/src/nsEventListenerManager.h
+++ b/content/events/src/nsEventListenerManager.h
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsEventListenerManager_h__
 #define nsEventListenerManager_h__
 
-#include "jsapi.h"
 #include "mozilla/dom/EventListenerBinding.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "nsCOMPtr.h"
 #include "nsCxPusher.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsGkAtoms.h"
--- a/content/html/content/src/HTMLPropertiesCollection.h
+++ b/content/html/content/src/HTMLPropertiesCollection.h
@@ -14,17 +14,16 @@
 #include "nsCOMArray.h"
 #include "nsIMutationObserver.h"
 #include "nsStubMutationObserver.h"
 #include "nsBaseHashtable.h"
 #include "nsINodeList.h"
 #include "nsIHTMLCollection.h"
 #include "nsHashKeys.h"
 #include "nsRefPtrHashtable.h"
-#include "jsapi.h"
 
 class nsGenericHTMLElement;
 class nsIDocument;
 class nsINode;
 
 namespace mozilla {
 namespace dom {
 
--- a/content/html/content/src/nsDOMStringMap.h
+++ b/content/html/content/src/nsDOMStringMap.h
@@ -8,17 +8,16 @@
 #define nsDOMStringMap_h
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsWrapperCache.h"
 #include "nsGenericHTMLElement.h"
-#include "jsfriendapi.h"
 
 namespace mozilla {
 class ErrorResult;
 }
 
 class nsDOMStringMap : public nsStubMutationObserver,
                        public nsWrapperCache
 {
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -7,17 +7,16 @@
 #define nsHTMLDocument_h___
 
 #include "mozilla/Attributes.h"
 #include "nsDocument.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMHTMLCollection.h"
 #include "nsIScriptElement.h"
-#include "jsapi.h"
 #include "nsTArray.h"
 
 #include "pldhash.h"
 #include "nsIHttpChannel.h"
 #include "nsHTMLStyleSheet.h"
 
 #include "nsICommandManager.h"
 #include "mozilla/dom/HTMLSharedElement.h"
--- a/content/xbl/src/nsXBLBinding.h
+++ b/content/xbl/src/nsXBLBinding.h
@@ -10,17 +10,16 @@
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsINodeList.h"
 #include "nsIStyleRuleProcessor.h"
 #include "nsClassHashtable.h"
 #include "nsTArray.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsISupportsImpl.h"
-#include "jsapi.h"
 
 class nsXBLPrototypeBinding;
 class nsIContent;
 class nsIAtom;
 class nsIDocument;
 class nsIScriptContext;
 
 namespace mozilla {
--- a/content/xbl/src/nsXBLMaybeCompiled.h
+++ b/content/xbl/src/nsXBLMaybeCompiled.h
@@ -1,18 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsXBLMaybeCompiled_h__
 #define nsXBLMaybeCompiled_h__
 
-#include "js/RootingAPI.h"
-
 /*
  * A union containing either a pointer representing uncompiled source or a
  * JSObject* representing the compiled result.  The class is templated on the
  * source object type.
  *
  * The purpose of abstracting this as a separate class is to allow it to be
  * wrapped in a JS::Heap<T> to correctly handle post-barriering of the JSObject
  * pointer, when present.
--- a/content/xbl/src/nsXBLProtoImplMember.h
+++ b/content/xbl/src/nsXBLProtoImplMember.h
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsXBLProtoImplMember_h__
 #define nsXBLProtoImplMember_h__
 
 #include "nsIAtom.h"
 #include "nsString.h"
-#include "jsapi.h"
 #include "nsString.h"
 #include "nsIServiceManager.h"
 #include "nsContentUtils.h" // For NS_CONTENT_DELETE_LIST_MEMBER.
 #include "nsCycleCollectionParticipant.h"
 
 class nsIContent;
 class nsIObjectOutputStream;
 
--- a/content/xbl/src/nsXBLProtoImplMethod.h
+++ b/content/xbl/src/nsXBLProtoImplMethod.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsXBLProtoImplMethod_h__
 #define nsXBLProtoImplMethod_h__
 
 #include "mozilla/Attributes.h"
 #include "nsIAtom.h"
 #include "nsString.h"
-#include "jsapi.h"
 #include "nsString.h"
 #include "nsXBLMaybeCompiled.h"
 #include "nsXBLProtoImplMember.h"
 #include "nsXBLSerialize.h"
 
 class nsIContent;
 
 struct nsXBLParameter {
--- a/content/xbl/src/nsXBLProtoImplProperty.h
+++ b/content/xbl/src/nsXBLProtoImplProperty.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsXBLProtoImplProperty_h__
 #define nsXBLProtoImplProperty_h__
 
 #include "mozilla/Attributes.h"
 #include "nsIAtom.h"
 #include "nsString.h"
-#include "jsapi.h"
 #include "nsString.h"
 #include "nsXBLSerialize.h"
 #include "nsXBLMaybeCompiled.h"
 #include "nsXBLProtoImplMember.h"
 
 class nsXBLProtoImplProperty: public nsXBLProtoImplMember
 {
 public:
--- a/content/xbl/src/nsXBLPrototypeHandler.h
+++ b/content/xbl/src/nsXBLPrototypeHandler.h
@@ -11,28 +11,30 @@
 #include "nsCOMPtr.h"
 #include "nsIController.h"
 #include "nsAutoPtr.h"
 #include "nsXBLEventHandler.h"
 #include "nsIWeakReference.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsCycleCollectionParticipant.h"
 
-#include "js/RootingAPI.h"
-
 class JSObject;
 class nsIDOMEvent;
 class nsIContent;
 class nsIDOMUIEvent;
 class nsIDOMKeyEvent;
 class nsIDOMMouseEvent;
 class nsIObjectInputStream;
 class nsIObjectOutputStream;
 class nsXBLPrototypeBinding;
 
+namespace JS {
+template <typename T> class MutableHandle;
+}
+
 namespace mozilla {
 namespace dom {
 class EventTarget;
 }
 }
 
 #define NS_HANDLER_TYPE_XBL_JS              (1 << 0)
 #define NS_HANDLER_TYPE_XBL_COMMAND         (1 << 1)
--- a/content/xbl/src/nsXBLSerialize.h
+++ b/content/xbl/src/nsXBLSerialize.h
@@ -1,22 +1,25 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsXBLSerialize_h__
 #define nsXBLSerialize_h__
 
-#include "jsapi.h"
-
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsINameSpaceManager.h"
 
+namespace JS {
+template <typename T> class Handle;
+template <typename T> class MutableHandle;
+}
+
 typedef uint8_t XBLBindingSerializeDetails;
 
 // A version number to ensure we don't load cached data in a different
 // file format.
 #define XBLBinding_Serialize_Version 0x00000001
 
 // Set for the first binding in a document
 #define XBLBinding_Serialize_IsFirstBinding 1
--- a/content/xul/content/src/nsXULElement.h
+++ b/content/xul/content/src/nsXULElement.h
@@ -29,17 +29,16 @@
 #include "nsIXULTemplateBuilder.h"
 #include "nsIBoxObject.h"
 #include "nsLayoutCID.h"
 #include "nsAttrAndChildArray.h"
 #include "nsGkAtoms.h"
 #include "nsAutoPtr.h"
 #include "nsStyledElement.h"
 #include "nsIFrameLoader.h"
-#include "jspubtd.h"
 #include "nsFrameLoader.h"
 
 class nsIDocument;
 class nsString;
 class nsIDocShell;
 class nsXULPrototypeDocument;
 
 class nsIObjectInputStream;
--- a/content/xul/document/src/nsXULPrototypeCache.h
+++ b/content/xul/document/src/nsXULPrototypeCache.h
@@ -12,21 +12,18 @@
 #include "nsJSThingHashtable.h"
 #include "nsInterfaceHashtable.h"
 #include "nsRefPtrHashtable.h"
 #include "nsURIHashKey.h"
 #include "nsXULPrototypeDocument.h"
 #include "nsIInputStream.h"
 #include "nsIStorageStream.h"
 
-#include "jspubtd.h"
-
 #include "mozilla/scache/StartupCache.h"
 
-
 class nsCSSStyleSheet;
 
 /**
  * The XUL prototype cache can be used to store and retrieve shared data for
  * XUL documents, style sheets, XBL, and scripts.
  *
  * The cache has two levels:
  *  1. In-memory hashtables
--- a/dom/base/StructuredCloneTags.h
+++ b/dom/base/StructuredCloneTags.h
@@ -1,17 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef StructuredCloneTags_h__
 #define StructuredCloneTags_h__
 
-#include "jsapi.h"
-
 namespace mozilla {
 namespace dom {
 
 // CHANGING THE ORDER/PLACEMENT OF EXISTING ENUM VALUES MAY BREAK INDEXEDDB.
 // PROCEED WITH EXTREME CAUTION.
 enum StructuredCloneTags {
   SCTAG_BASE = JS_SCTAG_USER_MIN,
 
--- a/dom/base/WindowNamedPropertiesHandler.h
+++ b/dom/base/WindowNamedPropertiesHandler.h
@@ -2,17 +2,16 @@
 /* vim: set ts=2 sw=2 et tw=78: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_WindowNamedPropertiesHandler_h
 #define mozilla_dom_WindowNamedPropertiesHandler_h
 
-#include "jsproxy.h"
 #include "mozilla/dom/DOMJSProxyHandler.h"
 
 namespace mozilla {
 namespace dom {
 
 class WindowNamedPropertiesHandler : public BaseDOMProxyHandler
 {
 public:
--- a/dom/base/nsDOMClassInfo.h
+++ b/dom/base/nsDOMClassInfo.h
@@ -261,17 +261,17 @@ protected:
 
   virtual ~nsEventTargetSH()
   {
   }
 public:
   NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
                        JSObject *globalObj, JSObject **parentObj) MOZ_OVERRIDE;
   NS_IMETHOD AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj, jsid id, jsval *vp, bool *_retval) MOZ_OVERRIDE;
+                         JSObject *obj, jsid id, JS::Value *vp, bool *_retval) MOZ_OVERRIDE;
 
   virtual void PreserveWrapper(nsISupports *aNative) MOZ_OVERRIDE;
 
   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
   {
     return new nsEventTargetSH(aData);
   }
 };
@@ -350,22 +350,22 @@ protected:
 
   virtual ~nsLocationSH()
   {
   }
 
 public:
   NS_IMETHOD CheckAccess(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                          JSObject *obj, jsid id, uint32_t mode,
-                         jsval *vp, bool *_retval) MOZ_OVERRIDE;
+                         JS::Value *vp, bool *_retval) MOZ_OVERRIDE;
 
   NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
                        JSObject *globalObj, JSObject **parentObj) MOZ_OVERRIDE;
   NS_IMETHODIMP AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                            JSObject *obj, jsid id, jsval *vp, bool *_retval);
+                            JSObject *obj, jsid id, JS::Value *vp, bool *_retval);
 
   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
   {
     return new nsLocationSH(aData);
   }
 };
 
 
@@ -414,17 +414,17 @@ protected:
 
   // Subclasses need to override this, if the implementation can't fail it's
   // allowed to not set *aResult.
   virtual nsISupports* GetItemAt(nsISupports *aNative, uint32_t aIndex,
                                  nsWrapperCache **aCache, nsresult *aResult) = 0;
 
 public:
   NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj, jsid id, jsval *vp, bool *_retval) MOZ_OVERRIDE;
+                         JSObject *obj, jsid id, JS::Value *vp, bool *_retval) MOZ_OVERRIDE;
 
 private:
   // Not implemented, nothing should create an instance of this class.
   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData);
 };
 
 
 // HTMLAllCollection
@@ -438,17 +438,17 @@ protected:
                                      nsDocument *doc,
                                      nsContentList **nodeList);
 public:
   static bool DocumentAllGetProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
                                      JS::MutableHandle<JS::Value> vp);
   static bool DocumentAllNewResolve(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
                                     unsigned flags, JS::MutableHandle<JSObject*> objp);
   static void ReleaseDocument(JSFreeOp *fop, JSObject *obj);
-  static bool CallToGetPropMapper(JSContext *cx, unsigned argc, jsval *vp);
+  static bool CallToGetPropMapper(JSContext *cx, unsigned argc, JS::Value *vp);
 };
 
 
 // String array helper
 
 class nsStringArraySH : public nsGenericArraySH
 {
 protected:
@@ -460,17 +460,17 @@ protected:
   {
   }
 
   virtual nsresult GetStringAt(nsISupports *aNative, int32_t aIndex,
                                nsAString& aResult) = 0;
 
 public:
   NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj, jsid id, jsval *vp, bool *_retval) MOZ_OVERRIDE;
+                         JSObject *obj, jsid id, JS::Value *vp, bool *_retval) MOZ_OVERRIDE;
 };
 
 
 // History helper
 
 class nsHistorySH : public nsStringArraySH
 {
 protected:
@@ -484,17 +484,17 @@ protected:
 
   virtual nsresult GetStringAt(nsISupports *aNative, int32_t aIndex,
                                nsAString& aResult) MOZ_OVERRIDE;
 
 public:
   NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
                        JSObject *globalObj, JSObject **parentObj) MOZ_OVERRIDE;
   NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj, jsid id, jsval *vp, bool *_retval) MOZ_OVERRIDE;
+                         JSObject *obj, jsid id, JS::Value *vp, bool *_retval) MOZ_OVERRIDE;
 
   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
   {
     return new nsHistorySH(aData);
   }
 };
 
 // StringList scriptable helper
@@ -606,23 +606,23 @@ protected:
   virtual ~nsStorage2SH()
   {
   }
 
   NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                         JSObject *obj, jsid id, uint32_t flags,
                         JSObject **objp, bool *_retval) MOZ_OVERRIDE;
   NS_IMETHOD SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj, jsid id, jsval *vp, bool *_retval) MOZ_OVERRIDE;
+                         JSObject *obj, jsid id, JS::Value *vp, bool *_retval) MOZ_OVERRIDE;
   NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj, jsid id, jsval *vp, bool *_retval) MOZ_OVERRIDE;
+                         JSObject *obj, jsid id, JS::Value *vp, bool *_retval) MOZ_OVERRIDE;
   NS_IMETHOD DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                          JSObject *obj, jsid id, bool *_retval) MOZ_OVERRIDE;
   NS_IMETHOD NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                          JSObject *obj, uint32_t enum_op, jsval *statep,
+                          JSObject *obj, uint32_t enum_op, JS::Value *statep,
                           jsid *idp, bool *_retval) MOZ_OVERRIDE;
 
 public:
   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
   {
     return new nsStorage2SH(aData);
   }
 };
@@ -671,17 +671,17 @@ public:
                         JSObject **objp, bool *_retval) MOZ_OVERRIDE;
   NS_IMETHOD Call(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                   JSObject *obj, const JS::CallArgs &args, bool *_retval) MOZ_OVERRIDE;
 
   NS_IMETHOD Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                        JSObject *obj, const JS::CallArgs &args, bool *_retval) MOZ_OVERRIDE;
 
   NS_IMETHOD HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                         JSObject *obj, const jsval &val, bool *bp,
+                         JSObject *obj, const JS::Value &val, bool *bp,
                          bool *_retval);
 
   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
   {
     return new nsDOMConstructorSH(aData);
   }
 };
 
--- a/dom/base/nsDOMJSUtils.h
+++ b/dom/base/nsDOMJSUtils.h
@@ -1,17 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 #ifndef nsDOMJSUtils_h__
 #define nsDOMJSUtils_h__
 
-#include "jsapi.h"
 #include "nsIScriptContext.h"
 
 class nsIJSArgArray;
 
 // seems like overkill for just this 1 function - but let's see what else
 // falls out first.
 inline nsIScriptContext *
 GetScriptContextFromJSContext(JSContext *cx)
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -178,16 +178,17 @@
 #include "mozIThirdPartyUtil.h"
 
 #ifdef MOZ_LOGGING
 // so we can get logging even in release builds
 #define FORCE_PR_LOG 1
 #endif
 #include "prlog.h"
 #include "prenv.h"
+#include "prprf.h"
 
 #include "mozilla/dom/indexedDB/IDBFactory.h"
 #include "mozilla/dom/quota/QuotaManager.h"
 
 #include "mozilla/dom/StructuredCloneTags.h"
 
 #ifdef MOZ_GAMEPAD
 #include "mozilla/dom/GamepadService.h"
--- a/dom/base/nsIJSEventListener.h
+++ b/dom/base/nsIJSEventListener.h
@@ -2,17 +2,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsIJSEventListener_h__
 #define nsIJSEventListener_h__
 
 #include "nsIScriptContext.h"
-#include "jsapi.h"
 #include "xpcpublic.h"
 #include "nsIDOMEventListener.h"
 #include "nsIAtom.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/EventHandlerBinding.h"
 
 #define NS_IJSEVENTLISTENER_IID \
 { 0x92f9212b, 0xa6aa, 0x4867, \
--- a/dom/base/nsIJSNativeInitializer.h
+++ b/dom/base/nsIJSNativeInitializer.h
@@ -2,17 +2,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsIJSNativeInitializer_h__
 #define nsIJSNativeInitializer_h__
 
 #include "nsISupports.h"
-#include "jsapi.h"
 
 #define NS_IJSNATIVEINITIALIZER_IID \
 { 0xdb48eee5, 0x89a4, 0x4f18,       \
   { 0x86, 0xd0, 0x4c, 0x4e, 0x9d, 0x4b, 0xf8, 0x7e } }
 
 
 /**
  * A JavaScript specific interface used to initialize new
--- a/dom/base/nsIScriptContext.h
+++ b/dom/base/nsIScriptContext.h
@@ -6,17 +6,16 @@
 #ifndef nsIScriptContext_h__
 #define nsIScriptContext_h__
 
 #include "nscore.h"
 #include "nsStringGlue.h"
 #include "nsISupports.h"
 #include "nsCOMPtr.h"
 #include "nsIProgrammingLanguage.h"
-#include "jsfriendapi.h"
 #include "jspubtd.h"
 #include "js/GCAPI.h"
 
 class nsIScriptGlobalObject;
 class nsIScriptSecurityManager;
 class nsIPrincipal;
 class nsIAtom;
 class nsIArray;
--- a/dom/base/nsJSEnvironment.h
+++ b/dom/base/nsJSEnvironment.h
@@ -3,18 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef nsJSEnvironment_h
 #define nsJSEnvironment_h
 
 #include "nsIScriptContext.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsCOMPtr.h"
-#include "jsapi.h"
-#include "jsfriendapi.h"
 #include "nsIObserver.h"
 #include "prtime.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIXPConnect.h"
 #include "nsIArray.h"
 #include "mozilla/Attributes.h"
 
 class nsICycleCollectorListener;
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -14,17 +14,16 @@
 #include "nsIDOMXULCommandDispatcher.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMDocument.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "nsIURI.h"
 #include "mozilla/dom/EventTarget.h"
-#include "js/RootingAPI.h"
 
 #define DOM_WINDOW_DESTROYED_TOPIC "dom-window-destroyed"
 #define DOM_WINDOW_FROZEN_TOPIC "dom-window-frozen"
 #define DOM_WINDOW_THAWED_TOPIC "dom-window-thawed"
 
 class nsIIdleObserver;
 class nsIPrincipal;
 class nsPerformance;
--- a/dom/base/nsStructuredCloneContainer.cpp
+++ b/dom/base/nsStructuredCloneContainer.cpp
@@ -8,16 +8,17 @@
 #include "nsStructuredCloneContainer.h"
 
 #include "nsCOMPtr.h"
 #include "nsIScriptContext.h"
 #include "nsIVariant.h"
 #include "nsIXPConnect.h"
 #include "nsServiceManagerUtils.h"
 #include "nsContentUtils.h"
+#include "jsapi.h"
 
 #include "mozilla/Base64.h"
 
 using namespace mozilla;
 
 NS_IMPL_ADDREF(nsStructuredCloneContainer)
 NS_IMPL_RELEASE(nsStructuredCloneContainer)
 
--- a/dom/base/nsStructuredCloneContainer.h
+++ b/dom/base/nsStructuredCloneContainer.h
@@ -4,17 +4,16 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsStructuredCloneContainer_h__
 #define nsStructuredCloneContainer_h__
 
 #include "nsIStructuredCloneContainer.h"
-#include "jsapi.h"
 #include "mozilla/Attributes.h"
 
 #define NS_STRUCTUREDCLONECONTAINER_CONTRACTID \
   "@mozilla.org/docshell/structured-clone-container;1"
 #define NS_STRUCTUREDCLONECONTAINER_CID \
 { /* 38bd0634-0fd4-46f0-b85f-13ced889eeec */       \
   0x38bd0634,                                      \
   0x0fd4,                                          \
--- a/dom/base/nsWrapperCache.h
+++ b/dom/base/nsWrapperCache.h
@@ -3,17 +3,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsWrapperCache_h___
 #define nsWrapperCache_h___
 
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Assertions.h"
-#include "js/Value.h"
+#include "js/Value.h"       // must come before js/RootingAPI.h
+#include "js/RootingAPI.h"
 
 struct JSTracer;
 class JSObject;
 struct JSContext;
 class XPCWrappedNativeScope;
 
 namespace mozilla {
 namespace dom {
--- a/dom/base/nsWrapperCacheInlines.h
+++ b/dom/base/nsWrapperCacheInlines.h
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsWrapperCacheInline_h___
 #define nsWrapperCacheInline_h___
 
 #include "nsWrapperCache.h"
 #include "xpcpublic.h"
-#include "jsapi.h"
 
 inline JSObject*
 nsWrapperCache::GetWrapper() const
 {
     JSObject* obj = GetWrapperPreserveColor();
     xpc_UnmarkGrayObject(obj);
     return obj;
 }
--- a/dom/bindings/BindingDeclarations.h
+++ b/dom/bindings/BindingDeclarations.h
@@ -9,24 +9,27 @@
  * might need.  The idea is to make binding implementation headers safe to
  * include anywhere without running into include hell like we do with
  * BindingUtils.h
  */
 #ifndef mozilla_dom_BindingDeclarations_h__
 #define mozilla_dom_BindingDeclarations_h__
 
 #include "nsStringGlue.h"
-#include "jsapi.h"
+#include "js/Value.h"
+#include "js/RootingAPI.h"
 #include "mozilla/Util.h"
 #include "nsCOMPtr.h"
 #include "nsDOMString.h"
 #include "nsStringBuffer.h"
 #include "nsTArray.h"
 #include "nsAutoPtr.h" // for nsRefPtr member variables
 
+struct JSContext;
+class JSObject;
 class nsWrapperCache;
 
 // nsGlobalWindow implements nsWrapperCache, but doesn't always use it. Don't
 // try to use it without fixing that first.
 class nsGlobalWindow;
 
 namespace mozilla {
 namespace dom {
@@ -67,17 +70,17 @@ public:
   }
 
   bool Failed() const
   {
     return !Get();
   }
 
 private:
-  JS::RootedObject mGlobalJSObject;
+  JS::Rooted<JSObject*> mGlobalJSObject;
   nsISupports* mGlobalObject;
   nsCOMPtr<nsISupports> mGlobalObjectRef;
 };
 
 class MOZ_STACK_CLASS WorkerGlobalObject
 {
 public:
   WorkerGlobalObject(JSContext* aCx, JSObject* aObject);
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -19,16 +19,17 @@
 #include "jsfriendapi.h"
 #include "nsIDOMGlobalPropertyInitializer.h"
 #include "nsIXPConnect.h"
 #include "WrapperFactory.h"
 #include "xpcprivate.h"
 #include "XPCQuickStubs.h"
 #include "XrayWrapper.h"
 #include "nsPrintfCString.h"
+#include "prprf.h"
 
 #include "mozilla/dom/HTMLObjectElement.h"
 #include "mozilla/dom/HTMLObjectElementBinding.h"
 #include "mozilla/dom/HTMLSharedObjectElement.h"
 #include "mozilla/dom/HTMLEmbedElementBinding.h"
 #include "mozilla/dom/HTMLAppletElementBinding.h"
 
 namespace mozilla {
--- a/dom/bindings/CallbackObject.h
+++ b/dom/bindings/CallbackObject.h
@@ -15,28 +15,26 @@
  */
 
 #ifndef mozilla_dom_CallbackObject_h
 #define mozilla_dom_CallbackObject_h
 
 #include "nsISupports.h"
 #include "nsISupportsImpl.h"
 #include "nsCycleCollectionParticipant.h"
-#include "jsapi.h"
 #include "jswrapper.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/Util.h"
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
 #include "nsWrapperCache.h"
 #include "nsJSEnvironment.h"
 #include "xpcpublic.h"
 #include "nsLayoutStatics.h"
-#include "js/RootingAPI.h"
 
 namespace mozilla {
 namespace dom {
 
 #define DOM_CALLBACKOBJECT_IID \
 { 0xbe74c190, 0x6d76, 0x4991, \
  { 0x84, 0xb9, 0x65, 0x06, 0x99, 0xe6, 0x93, 0x2b } }
 
--- a/dom/bindings/DOMJSClass.h
+++ b/dom/bindings/DOMJSClass.h
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_DOMJSClass_h
 #define mozilla_dom_DOMJSClass_h
 
-#include "jsapi.h"
 #include "jsfriendapi.h"
 #include "mozilla/Assertions.h"
 
 #include "mozilla/dom/PrototypeList.h" // auto-generated
 
 class nsCycleCollectionParticipant;
 
 // We use slot 0 for holding the raw object.  This is safe for both
--- a/dom/bindings/DOMJSProxyHandler.h
+++ b/dom/bindings/DOMJSProxyHandler.h
@@ -4,19 +4,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_DOMJSProxyHandler_h
 #define mozilla_dom_DOMJSProxyHandler_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/Likely.h"
 
-#include "jsapi.h"
-#include "jsfriendapi.h"
-#include "jsproxy.h"
 #include "xpcpublic.h"
 #include "nsStringGlue.h"
 
 #define DOM_PROXY_OBJECT_SLOT js::PROXY_PRIVATE_SLOT
 
 namespace mozilla {
 namespace dom {
 
--- a/dom/bindings/TypedArray.h
+++ b/dom/bindings/TypedArray.h
@@ -3,17 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_TypedArray_h
 #define mozilla_dom_TypedArray_h
 
 #include "jsfriendapi.h"
-#include "js/RootingAPI.h"
 #include "jsapi.h"
 #include "mozilla/dom/BindingDeclarations.h"
 
 namespace mozilla {
 namespace dom {
 
 /*
  * Various typed array classes for argument conversion.  We have a base class
--- a/dom/camera/ICameraControl.h
+++ b/dom/camera/ICameraControl.h
@@ -1,16 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef DOM_CAMERA_ICAMERACONTROL_H
 #define DOM_CAMERA_ICAMERACONTROL_H
 
-#include "jsapi.h"
 #include "nsIFile.h"
 #include "nsIDOMCameraManager.h"
 #include "DictionaryHelpers.h"
 #include "CameraCommon.h"
 
 namespace mozilla {
 
 
--- a/dom/interfaces/html/nsIDOMHTMLCanvasElement.idl
+++ b/dom/interfaces/html/nsIDOMHTMLCanvasElement.idl
@@ -1,20 +1,15 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsIDOMHTMLElement.idl"
 
-%{C++
-// for jsval
-#include "jsapi.h"
-%}
-
 /**
  * The nsIDOMHTMLCanvasElement interface is the interface to a HTML
  * <canvas> element.
  *
  * For more information on this interface, please see
  * http://www.whatwg.org/specs/web-apps/current-work/#graphics
  *
  * @status UNDER_DEVELOPMENT
--- a/dom/interfaces/json/nsIJSON.idl
+++ b/dom/interfaces/json/nsIJSON.idl
@@ -4,19 +4,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "domstubs.idl"
 
 interface nsIInputStream;
 interface nsIOutputStream;
 interface nsIScriptGlobalObject;
 
-[ptr] native JSValPtr(jsval);
+[ptr] native JSValPtr(JS::Value);
 [ptr] native JSContext(JSContext);
 
+%{C++
+namespace JS { class Value; }
+%}
+
 /**
  * Don't use this!  Use JSON.parse and JSON.stringify directly.
  */
 [scriptable, uuid(083aebb0-7790-43b2-ae81-9e404e626236)]
 interface nsIJSON : nsISupports
 {
   /**
    * New users should use JSON.stringify!
--- a/dom/ipc/StructuredCloneUtils.h
+++ b/dom/ipc/StructuredCloneUtils.h
@@ -2,21 +2,22 @@
 /* vim: set sw=4 ts=8 et tw=80 : */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_StructuredCloneUtils_h
 #define mozilla_dom_StructuredCloneUtils_h
 
-#include "jsapi.h"
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsIDOMFile.h"
 
+#include "jsapi.h"
+
 namespace mozilla {
 
 struct SerializedStructuredCloneBuffer;
 
 namespace dom {
 
 struct
 StructuredCloneClosure
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -17,17 +17,16 @@
 #include "nsEventDispatcher.h"
 #include "nsIWebBrowserChrome2.h"
 #include "nsIEmbeddingSiteWindow.h"
 #include "nsIWebBrowserChromeFocus.h"
 #include "nsIWidget.h"
 #include "nsIDOMEventListener.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIWindowProvider.h"
-#include "jsapi.h"
 #include "nsIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIDocument.h"
 #include "nsNetUtil.h"
 #include "nsFrameMessageManager.h"
 #include "nsIWebProgressListener.h"
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_tabs_TabParent_h
 #define mozilla_tabs_TabParent_h
 
 #include "base/basictypes.h"
 
-#include "jsapi.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/PBrowserParent.h"
 #include "mozilla/dom/PContentDialogParent.h"
 #include "mozilla/dom/TabContext.h"
 #include "mozilla/ipc/GeckoChildProcessHost.h"
 #include "nsCOMPtr.h"
 #include "nsIAuthPromptProvider.h"
 #include "nsIBrowserDOMWindow.h"
--- a/dom/mobilemessage/src/MmsMessage.h
+++ b/dom/mobilemessage/src/MmsMessage.h
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_mobilemessage_MmsMessage_h
 #define mozilla_dom_mobilemessage_MmsMessage_h
 
 #include "nsIDOMMozMmsMessage.h"
 #include "nsString.h"
-#include "jspubtd.h"
 #include "mozilla/dom/mobilemessage/Types.h"
 #include "mozilla/Attributes.h"
 #include "DictionaryHelpers.h"
 
 namespace mozilla {
 namespace dom {
 
 namespace mobilemessage {
--- a/dom/mobilemessage/src/MobileMessageThread.h
+++ b/dom/mobilemessage/src/MobileMessageThread.h
@@ -5,17 +5,16 @@
 
 #ifndef mozilla_dom_mobilemessage_MobileMessageThread_h
 #define mozilla_dom_mobilemessage_MobileMessageThread_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/mobilemessage/SmsTypes.h"
 #include "nsIDOMMozMobileMessageThread.h"
 #include "nsString.h"
-#include "jspubtd.h"
 
 namespace mozilla {
 namespace dom {
 
 class MobileMessageThread MOZ_FINAL : public nsIDOMMozMobileMessageThread
 {
 private:
   typedef mobilemessage::ThreadData ThreadData;
--- a/dom/mobilemessage/src/SmsMessage.h
+++ b/dom/mobilemessage/src/SmsMessage.h
@@ -4,17 +4,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_mobilemessage_SmsMessage_h
 #define mozilla_dom_mobilemessage_SmsMessage_h
 
 #include "mozilla/dom/mobilemessage/SmsTypes.h"
 #include "nsIDOMMozSmsMessage.h"
 #include "nsString.h"
-#include "jspubtd.h"
 #include "mozilla/dom/mobilemessage/Types.h"
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 namespace dom {
 
 class SmsMessage MOZ_FINAL : public nsIDOMMozSmsMessage
 {
--- a/dom/plugins/base/nsJSNPRuntime.h
+++ b/dom/plugins/base/nsJSNPRuntime.h
@@ -2,17 +2,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsJSNPRuntime_h_
 #define nsJSNPRuntime_h_
 
 #include "nscore.h"
-#include "jsapi.h"
 #include "npapi.h"
 #include "npruntime.h"
 #include "pldhash.h"
 
 class nsJSNPRuntime
 {
 public:
   static void OnPluginDestroy(NPP npp);
--- a/dom/plugins/base/nsNPAPIPlugin.h
+++ b/dom/plugins/base/nsNPAPIPlugin.h
@@ -5,17 +5,16 @@
 
 #ifndef nsNPAPIPlugin_h_
 #define nsNPAPIPlugin_h_
 
 #include "prlink.h"
 #include "npfunctions.h"
 #include "nsPluginHost.h"
 
-#include "jsapi.h"
 #include "nsCxPusher.h"
 
 #include "mozilla/PluginLibrary.h"
 
 /*
  * Use this macro before each exported function
  * (between the return address and the function
  * itself), to ensure that the function has the
--- a/dom/plugins/ipc/PluginScriptableObjectParent.h
+++ b/dom/plugins/ipc/PluginScriptableObjectParent.h
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef dom_plugins_PluginScriptableObjectParent_h
 #define dom_plugins_PluginScriptableObjectParent_h 1
 
 #include "mozilla/plugins/PPluginScriptableObjectParent.h"
 
-#include "jsapi.h"
 #include "npfunctions.h"
 #include "npruntime.h"
 
 namespace mozilla {
 namespace plugins {
 
 class PluginInstanceParent;
 class PluginScriptableObjectParent;
--- a/dom/src/events/nsJSEventListener.h
+++ b/dom/src/events/nsJSEventListener.h
@@ -6,17 +6,16 @@
 #ifndef nsJSEventListener_h__
 #define nsJSEventListener_h__
 
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsIJSEventListener.h"
 #include "nsIDOMEventListener.h"
-#include "jsapi.h"
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsIScriptContext.h"
 #include "nsCycleCollectionParticipant.h"
 
 // nsJSEventListener interface
 // misnamed - JS no longer has exclusive rights over this interface!
 class nsJSEventListener : public nsIJSEventListener
--- a/dom/src/json/nsJSON.h
+++ b/dom/src/json/nsJSON.h
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsJSON_h__
 #define nsJSON_h__
 
-#include "jsapi.h"
 #include "nsIJSON.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsIOutputStream.h"
 #include "nsIUnicodeEncoder.h"
 #include "nsIUnicodeDecoder.h"
 #include "nsIRequestObserver.h"
 #include "nsIStreamListener.h"
--- a/dom/system/OSFileConstants.h
+++ b/dom/system/OSFileConstants.h
@@ -1,16 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_osfileconstants_h__
 #define mozilla_osfileconstants_h__
 
-#include "jspubtd.h"
 #include "nsIOSFileConstantsService.h"
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 
 /**
  * Perform initialization of this module.
  *
--- a/dom/workers/Exceptions.h
+++ b/dom/workers/Exceptions.h
@@ -4,18 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_workers_exceptions_h__
 #define mozilla_dom_workers_exceptions_h__
 
 #include "Workers.h"
 
-#include "jspubtd.h"
-
 // DOMException Codes.
 #define INDEX_SIZE_ERR 1
 #define DOMSTRING_SIZE_ERR 2
 #define HIERARCHY_REQUEST_ERR 3
 #define WRONG_DOCUMENT_ERR 4
 #define INVALID_CHARACTER_ERR 5
 #define NO_DATA_ALLOWED_ERR 6
 #define NO_MODIFICATION_ALLOWED_ERR 7
--- a/dom/workers/File.h
+++ b/dom/workers/File.h
@@ -4,18 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_workers_file_h__
 #define mozilla_dom_workers_file_h__
 
 #include "Workers.h"
 
-#include "jspubtd.h"
-
 class nsIDOMFile;
 class nsIDOMBlob;
 
 BEGIN_WORKERS_NAMESPACE
 
 namespace file {
 
 bool
--- a/dom/workers/Location.h
+++ b/dom/workers/Location.h
@@ -5,18 +5,16 @@
 
 #ifndef mozilla_dom_workers_location_h__
 #define mozilla_dom_workers_location_h__
 
 #include "Workers.h"
 #include "DOMBindingBase.h"
 #include "WorkerPrivate.h"
 
-#include "jspubtd.h"
-
 BEGIN_WORKERS_NAMESPACE
 
 class WorkerLocation MOZ_FINAL : public DOMBindingBase
 {
   nsString mHref;
   nsString mProtocol;
   nsString mHost;
   nsString mHostname;
--- a/dom/workers/Principal.h
+++ b/dom/workers/Principal.h
@@ -3,18 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_workers_principal_h__
 #define mozilla_dom_workers_principal_h__
 
 #include "Workers.h"
 
-#include "jspubtd.h"
-
 BEGIN_WORKERS_NAMESPACE
 
 JSPrincipals*
 GetWorkerPrincipal();
 
 END_WORKERS_NAMESPACE
 
 #endif /* mozilla_dom_workers_principal_h__ */
--- a/dom/workers/RuntimeService.h
+++ b/dom/workers/RuntimeService.h
@@ -6,17 +6,16 @@
 
 #ifndef mozilla_dom_workers_runtimeservice_h__
 #define mozilla_dom_workers_runtimeservice_h__
 
 #include "Workers.h"
 
 #include "nsIObserver.h"
 
-#include "jsapi.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/TimeStamp.h"
 #include "nsAutoPtr.h"
 #include "nsClassHashtable.h"
 #include "nsCOMPtr.h"
 #include "nsHashKeys.h"
 #include "nsStringGlue.h"
--- a/dom/workers/ScriptLoader.h
+++ b/dom/workers/ScriptLoader.h
@@ -3,18 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_workers_scriptloader_h__
 #define mozilla_dom_workers_scriptloader_h__
 
 #include "Workers.h"
 
-#include "jsapi.h"
-
 class nsIPrincipal;
 class nsIURI;
 class nsIDocument;
 class nsString;
 class nsIChannel;
 
 BEGIN_WORKERS_NAMESPACE
 
--- a/dom/workers/Worker.h
+++ b/dom/workers/Worker.h
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_workers_worker_h__
 #define mozilla_dom_workers_worker_h__
 
 #include "Workers.h"
 
-#include "jspubtd.h"
 #include "mozilla/dom/DOMJSClass.h"
 
 BEGIN_WORKERS_NAMESPACE
 
 namespace worker {
 
 JSObject*
 InitClass(JSContext* aCx, JSObject* aGlobal, JSObject* aProto,
--- a/dom/workers/WorkerPrivate.h
+++ b/dom/workers/WorkerPrivate.h
@@ -10,17 +10,16 @@
 #include "Workers.h"
 
 #include "nsIContentSecurityPolicy.h"
 #include "nsIRunnable.h"
 #include "nsIThread.h"
 #include "nsIThreadInternal.h"
 #include "nsPIDOMWindow.h"
 
-#include "jsapi.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/CondVar.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/TimeStamp.h"
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsEventQueue.h"
 #include "nsStringGlue.h"
--- a/embedding/components/windowwatcher/src/nsWindowWatcher.h
+++ b/embedding/components/windowwatcher/src/nsWindowWatcher.h
@@ -6,17 +6,16 @@
 #ifndef __nsWindowWatcher_h__
 #define __nsWindowWatcher_h__
 
 // {a21bfa01-f349-4394-a84c-8de5cf0737d0}
 #define NS_WINDOWWATCHER_CID \
  {0xa21bfa01, 0xf349, 0x4394, {0xa8, 0x4c, 0x8d, 0xe5, 0xcf, 0x7, 0x37, 0xd0}}
 
 #include "nsCOMPtr.h"
-#include "jspubtd.h"
 #include "mozilla/Mutex.h"
 #include "nsIWindowCreator.h" // for stupid compilers
 #include "nsIWindowWatcher.h"
 #include "nsIPromptFactory.h"
 #include "nsPIWindowWatcher.h"
 #include "nsTArray.h"
 
 class  nsIURI;
--- a/ipc/glue/SyncChannel.h
+++ b/ipc/glue/SyncChannel.h
@@ -5,16 +5,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef ipc_glue_SyncChannel_h
 #define ipc_glue_SyncChannel_h 1
 
 #include "mozilla/ipc/AsyncChannel.h"
 
+#include <math.h>
+
 namespace mozilla {
 namespace ipc {
 //-----------------------------------------------------------------------------
 
 class SyncChannel : public AsyncChannel
 {
 protected:
     typedef IPC::Message::msgid_t msgid_t;
--- a/ipc/testshell/TestShellParent.h
+++ b/ipc/testshell/TestShellParent.h
@@ -6,17 +6,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef ipc_testshell_TestShellParent_h
 #define ipc_testshell_TestShellParent_h 1
 
 #include "mozilla/ipc/PTestShellParent.h"
 #include "mozilla/ipc/PTestShellCommandParent.h"
 
-#include "jsapi.h"
 #include "nsAutoJSValHolder.h"
 #include "nsStringGlue.h"
 
 struct JSContext;
 class JSObject;
 
 namespace mozilla {
 
--- a/js/ipc/JavaScriptParent.cpp
+++ b/js/ipc/JavaScriptParent.cpp
@@ -5,16 +5,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "JavaScriptParent.h"
 #include "mozilla/dom/ContentParent.h"
 #include "nsJSUtils.h"
 #include "jsfriendapi.h"
 #include "jsproxy.h"
+#include "jswrapper.h"
 #include "HeapAPI.h"
 #include "xpcprivate.h"
 #include "mozilla/Casting.h"
 
 using namespace js;
 using namespace JS;
 using namespace mozilla;
 using namespace mozilla::jsipc;
--- a/js/ipc/JavaScriptParent.h
+++ b/js/ipc/JavaScriptParent.h
@@ -5,17 +5,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_jsipc_JavaScriptParent__
 #define mozilla_jsipc_JavaScriptParent__
 
 #include "JavaScriptShared.h"
 #include "mozilla/jsipc/PJavaScriptParent.h"
-#include "jsclass.h"
 
 #ifdef XP_WIN
 #undef GetClassName
 #undef GetClassInfo
 #endif
 
 namespace mozilla {
 namespace jsipc {
--- a/js/ipc/JavaScriptShared.h
+++ b/js/ipc/JavaScriptShared.h
@@ -3,19 +3,16 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_jsipc_JavaScriptShared_h__
 #define mozilla_jsipc_JavaScriptShared_h__
 
-#include "jsapi.h"
-#include "jspubtd.h"
-#include "js/HashTable.h"
 #include "mozilla/dom/DOMTypes.h"
 #include "mozilla/jsipc/PJavaScript.h"
 #include "nsJSUtils.h"
 #include "nsFrameMessageManager.h"
 
 namespace mozilla {
 namespace jsipc {
 
--- a/js/jsd/jsd.h
+++ b/js/jsd/jsd.h
@@ -24,22 +24,19 @@
 * in other embeddings.
 */
 #ifdef MOZILLA_CLIENT
 #define JSD_THREADSAFE 1
 /* define JSD_HAS_DANGEROUS_THREAD 1 */
 #define JSD_USE_NSPR_LOCKS 1
 #endif /* MOZILLA_CLIENT */
 
-#include "jstypes.h"
-#include "jsprf.h"
-#include "jshash.h" /* Added by JSIFY */
+#include "jshash.h"
 #include "jsclist.h"
 #include "jsdebug.h"
-#include "jsapi.h"
 #include "jsdbgapi.h"
 #include "jsd_lock.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #define JSD_MAJOR_VERSION 1
--- a/js/jsd/jsd_text.cpp
+++ b/js/jsd/jsd_text.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * JavaScript Debugging support - Source Text functions
  */
 
 #include <ctype.h>
 #include "jsd.h"
+#include "jsprf.h"
 
 #ifdef DEBUG
 void JSD_ASSERT_VALID_SOURCE_TEXT(JSDSourceText* jsdsrc)
 {
     JS_ASSERT(jsdsrc);
     JS_ASSERT(jsdsrc->url);
 }
 #endif
--- a/js/jsd/jsd_xpc.cpp
+++ b/js/jsd/jsd_xpc.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "jsdbgapi.h"
+#include "jsfriendapi.h"
 #include "jsd_xpc.h"
 
 #include "js/GCAPI.h"
 
 #include "nsIXPConnect.h"
 #include "mozilla/ModuleUtils.h"
 #include "nsIServiceManager.h"
 #include "nsIScriptGlobalObject.h"
--- a/js/jsd/jsdebug.h
+++ b/js/jsd/jsdebug.h
@@ -7,17 +7,16 @@
 /*
  * Header for JavaScript Debugging support - All public functions
  */
 
 #ifndef jsdebug_h___
 #define jsdebug_h___
 
 #include "jsapi.h"
-#include "jsdbgapi.h"
 
 extern "C" {
 
 /*
  * The linkage of JSD API functions differs depending on whether the file is
  * used within the JSD library or not.  Any source file within the JSD
  * libraray should define EXPORT_JSD_API whereas any client of the library
  * should not.
--- a/js/jsd/jshash.h
+++ b/js/jsd/jshash.h
@@ -6,18 +6,18 @@
 
 #ifndef jshash_h___
 #define jshash_h___
 
 /*
  * API to portable hash table code.
  */
 #include <stddef.h>
+#include <stdint.h>
 #include <stdio.h>
-#include "jstypes.h"
 
 extern "C" {
 
 typedef uint32_t JSHashNumber;
 typedef struct JSHashEntry JSHashEntry;
 typedef struct JSHashTable JSHashTable;
 
 #define JS_HASH_BITS 32
--- a/js/public/GCAPI.h
+++ b/js/public/GCAPI.h
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef js_GCAPI_h
 #define js_GCAPI_h
 
 #include "js/HeapAPI.h"
 #include "js/RootingAPI.h"
+#include "js/Value.h"
 
 namespace JS {
 
 #define GCREASONS(D)                            \
     /* Reasons internal to the JS engine */     \
     D(API)                                      \
     D(MAYBEGC)                                  \
     D(LAST_CONTEXT)                             \
@@ -202,17 +203,17 @@ IncrementalObjectBarrier(JSObject *obj);
 
 extern JS_FRIEND_API(void)
 PokeGC(JSRuntime *rt);
 
 /* Was the most recent GC run incrementally? */
 extern JS_FRIEND_API(bool)
 WasIncrementalGC(JSRuntime *rt);
 
-class ObjectPtr
+class JS_PUBLIC_API(ObjectPtr)
 {
     Heap<JSObject *> value;
 
   public:
     ObjectPtr() : value(NULL) {}
 
     ObjectPtr(JSObject *obj) : value(obj) {}
 
@@ -228,29 +229,25 @@ class ObjectPtr
     void init(JSObject *obj) { value = obj; }
 
     JSObject *get() const { return value; }
 
     void writeBarrierPre(JSRuntime *rt) {
         IncrementalObjectBarrier(value);
     }
 
-    bool isAboutToBeFinalized() {
-        return JS_IsAboutToBeFinalized(&value);
-    }
+    bool isAboutToBeFinalized();
 
     ObjectPtr &operator=(JSObject *obj) {
         IncrementalObjectBarrier(value);
         value = obj;
         return *this;
     }
 
-    void trace(JSTracer *trc, const char *name) {
-        JS_CallHeapObjectTracer(trc, &value, name);
-    }
+    void trace(JSTracer *trc, const char *name);
 
     JSObject &operator*() const { return *value; }
     JSObject *operator->() const { return value; }
     operator JSObject *() const { return value; }
 };
 
 /*
  * Unsets the gray bit for anything reachable from |thing|. |kind| should not be
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -953,16 +953,28 @@ JS::PokeGC(JSRuntime *rt)
 JS_FRIEND_API(JSCompartment *)
 js::GetAnyCompartmentInZone(JS::Zone *zone)
 {
     CompartmentsInZoneIter comp(zone);
     JS_ASSERT(!comp.done());
     return comp.get();
 }
 
+bool
+JS::ObjectPtr::isAboutToBeFinalized()
+{
+    return JS_IsAboutToBeFinalized(&value);
+}
+
+void
+JS::ObjectPtr::trace(JSTracer *trc, const char *name)
+{
+    JS_CallHeapObjectTracer(trc, &value, name);
+}
+
 JS_FRIEND_API(JSObject *)
 js::GetTestingFunctions(JSContext *cx)
 {
     RootedObject obj(cx, JS_NewObject(cx, NULL, NULL, NULL));
     if (!obj)
         return NULL;
 
     if (!DefineTestingFunctions(cx, obj))
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -24,21 +24,27 @@
 namespace JS {
 
 /*
  * Allow headers to reference JS::Value without #including the whole jsapi.h.
  * Unfortunately, typedefs (hence jsval) cannot be declared.
  */
 class Value;
 
+class AutoIdVector;
+class CallArgs;
+
 template <typename T>
 class Rooted;
 
 class JS_PUBLIC_API(AutoGCRooter);
 
+class JS_PUBLIC_API(CompileOptions);
+class JS_PUBLIC_API(CompartmentOptions);
+
 struct Zone;
 
 } /* namespace JS */
 
 /*
  * In release builds, jsid is defined to be an integral type. This
  * prevents many bugs from being caught at compile time. E.g.:
  *
--- a/js/xpconnect/idl/nsIJSRuntimeService.idl
+++ b/js/xpconnect/idl/nsIJSRuntimeService.idl
@@ -8,16 +8,18 @@
 
 [ptr] native JSRuntime(JSRuntime);
 [ptr] native JSContext(JSContext);
 native xpcGCCallback(xpcGCCallback);
 native xpcContextCallback(xpcContextCallback);
 
 %{C++
 
+#include "jsapi.h"  // for JSGCStatus
+
 typedef void
 (* xpcGCCallback)(JSGCStatus status);
 
 typedef bool
 (* xpcContextCallback)(JSContext* cx, unsigned operation);
 
 %}
 
--- a/js/xpconnect/idl/nsIXPConnect.idl
+++ b/js/xpconnect/idl/nsIXPConnect.idl
@@ -18,40 +18,47 @@
 #include "nsIObjectOutputStream.idl"
 #include "nsIObjectInputStream.idl"
 
 %{ C++
 #include "jspubtd.h"
 #include "xptinfo.h"
 #include "nsAXPCNativeCallContext.h"
 
+struct JSFreeOp;
+
+namespace JS {
+template <typename T> class Handle;
+template <typename T> class MutableHandle;
+}
+
 class nsWrapperCache;
 %}
 
 /***************************************************************************/
 
-// NB: jsval and jsid are declared in nsIVariant.idl
+// NB: jsval and jsid are declared in nsrootidl.idl
 
 [ptr] native JSContextPtr(JSContext);
 [ptr] native JSClassPtr(JSClass);
 [ptr] native JSFreeOpPtr(JSFreeOp);
 [ptr] native JSObjectPtr(JSObject);
-[ptr] native JSValPtr(jsval);
-[ptr] native JSValConstPtr(const jsval);
+[ptr] native JSValPtr(JS::Value);
+[ptr] native JSValConstPtr(const JS::Value);
       native JSPropertyOp(JSPropertyOp);
       native JSEqualityOp(JSEqualityOp);
 [ptr] native JSScriptPtr(JSScript);
 [ptr] native voidPtrPtr(void*);
 [ptr] native nsScriptObjectTracerPtr(nsScriptObjectTracer);
 [ref] native nsCCTraversalCallbackRef(nsCycleCollectionTraversalCallback);
 [ptr] native nsAXPCNativeCallContextPtr(nsAXPCNativeCallContext);
 [ptr] native nsWrapperCachePtr(nsWrapperCache);
 [ref] native JSCompartmentOptions(JS::CompartmentOptions);
 [ref] native JSCallArgsRef(const JS::CallArgs);
-      native JSHandleId(JS::HandleId);
+      native JSHandleId(JS::Handle<jsid>);
 
 /***************************************************************************/
 
 // forward declarations...
 interface nsIXPCScriptable;
 interface nsIXPConnect;
 interface nsIXPConnectWrappedNative;
 interface nsIInterfaceInfo;
--- a/js/xpconnect/idl/xpcexception.idl
+++ b/js/xpconnect/idl/xpcexception.idl
@@ -3,21 +3,24 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 #include "nsIException.idl"
 
 %{ C++
-#include "jsapi.h"
+struct JSContext;
+namespace JS {
+class Value;
+}
 %}
 
 [ptr] native xpcexJSContextPtr(JSContext);
-      native xpcexJSVal(jsval);
+      native xpcexJSVal(JS::Value);
 
 [scriptable, uuid(cac29630-7bf2-4e22-811b-46855a7d5af0)]
 interface nsIXPCException : nsIException
 {
     // inherits methods from nsIException
 
     void initialize(in string           aMessage,
                     in nsresult         aResult,
--- a/js/xpconnect/loader/mozJSComponentLoader.h
+++ b/js/xpconnect/loader/mozJSComponentLoader.h
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "plhash.h"
-#include "jsapi.h"
 #include "mozilla/ModuleLoader.h"
 #include "nsIJSRuntimeService.h"
 #include "nsISupports.h"
 #include "nsIXPConnect.h"
 #include "nsIFile.h"
 #include "nsAutoPtr.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
--- a/js/xpconnect/loader/mozJSLoaderUtils.h
+++ b/js/xpconnect/loader/mozJSLoaderUtils.h
@@ -3,17 +3,16 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozJSLoaderUtils_h
 #define mozJSLoaderUtils_h
 
 #include "nsString.h"
-#include "jsapi.h"
 
 class nsIURI;
 namespace mozilla {
 namespace scache {
 class StartupCache;
 }
 }
 
--- a/js/xpconnect/loader/mozJSSubScriptLoader.h
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.h
@@ -1,15 +1,14 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "jsapi.h"
 #include "nsCOMPtr.h"
 #include "mozIJSSubScriptLoader.h"
 #include "nsIScriptSecurityManager.h"
 
 #define MOZ_JSSUBSCRIPTLOADER_CID                                             \
 { /* 829814d6-1dd2-11b2-8e08-82fa0a339b00 */                                  \
     0x929814d6,                                                               \
     0x1dd2,                                                                   \
--- a/js/xpconnect/public/nsAXPCNativeCallContext.h
+++ b/js/xpconnect/public/nsAXPCNativeCallContext.h
@@ -17,17 +17,17 @@ class nsIXPConnectWrappedNative;
 class nsAXPCNativeCallContext
 {
 public:
     NS_IMETHOD GetCallee(nsISupports **aResult) = 0;
     NS_IMETHOD GetCalleeMethodIndex(uint16_t *aResult) = 0;
     NS_IMETHOD GetCalleeWrapper(nsIXPConnectWrappedNative **aResult) = 0;
     NS_IMETHOD GetJSContext(JSContext **aResult) = 0;
     NS_IMETHOD GetArgc(uint32_t *aResult) = 0;
-    NS_IMETHOD GetArgvPtr(jsval **aResult) = 0;
+    NS_IMETHOD GetArgvPtr(JS::Value **aResult) = 0;
 
     // Methods added since mozilla 0.6....
 
     NS_IMETHOD GetCalleeInterface(nsIInterfaceInfo **aResult) = 0;
     NS_IMETHOD GetCalleeClassInfo(nsIClassInfo **aResult) = 0;
 
     NS_IMETHOD GetPreviousCallContext(nsAXPCNativeCallContext **aResult) = 0;
 
--- a/js/xpconnect/public/nsAutoJSValHolder.h
+++ b/js/xpconnect/public/nsAutoJSValHolder.h
@@ -1,18 +1,16 @@
 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __NSAUTOJSVALHOLDER_H__
 #define __NSAUTOJSVALHOLDER_H__
 
-#include "jsapi.h"
-
 #include "nsDebug.h"
 
 /**
  * Simple class that looks and acts like a jsval except that it unroots
  * itself automatically if Root() is ever called. Designed to be rooted on the
  * context or runtime (but not both!).
  */
 class nsAutoJSValHolder
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -12,16 +12,17 @@
 #include "xpcprivate.h"
 #include "XPCQuickStubs.h"
 #include "nsReadableUtils.h"
 #include "xpcIJSModuleLoader.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIDOMWindow.h"
 #include "XPCJSWeakReference.h"
 #include "XPCWrapper.h"
+#include "jsdbgapi.h"
 #include "jsproxy.h"
 #include "WrapperFactory.h"
 #include "XrayWrapper.h"
 #include "nsNullPrincipal.h"
 #include "nsJSUtils.h"
 #include "mozJSComponentLoader.h"
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -18,16 +18,17 @@
 #include "AccessCheck.h"
 #include "nsJSUtils.h"
 #include "WrapperFactory.h"
 
 #include "nsWrapperCacheInlines.h"
 
 #include "jsapi.h"
 #include "jsfriendapi.h"
+#include "jsprf.h"
 #include "JavaScriptParent.h"
 
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/PrimitiveConversions.h"
 
 using namespace xpc;
 using namespace mozilla;
 using namespace mozilla::dom;
--- a/js/xpconnect/src/XPCDebug.cpp
+++ b/js/xpconnect/src/XPCDebug.cpp
@@ -1,15 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "xpcprivate.h"
+#include "jsdbgapi.h"
+#include "jsprf.h"
 
 #ifdef XP_WIN
 #include <windows.h>
 #endif
 
 static void DebugDump(const char* fmt, ...)
 {
   char buffer[2048];
--- a/js/xpconnect/src/XPCException.cpp
+++ b/js/xpconnect/src/XPCException.cpp
@@ -2,16 +2,17 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* An implementaion of nsIException. */
 
 #include "xpcprivate.h"
+#include "jsprf.h"
 #include "nsError.h"
 #include "nsIUnicodeDecoder.h"
 
 /***************************************************************************/
 /* Quick and dirty mapping of well known result codes to strings. We only
 *  call this when building an exception object, so iterating the short array
 *  is not too bad.
 *
--- a/js/xpconnect/src/XPCInlines.h
+++ b/js/xpconnect/src/XPCInlines.h
@@ -7,18 +7,16 @@
 
 /* private inline methods (#include'd by xpcprivate.h). */
 
 #ifndef xpcinlines_h___
 #define xpcinlines_h___
 
 #include <algorithm>
 
-#include "jsfriendapi.h"
-
 /***************************************************************************/
 
 inline void
 XPCJSRuntime::AddVariantRoot(XPCTraceableVariant* variant)
 {
     variant->AddToRootSet(GetMapLock(), &mVariantRoots);
 }
 
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -26,17 +26,19 @@
 #include "mozilla/Services.h"
 
 #include "nsLayoutStatics.h"
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsCycleCollectionNoteRootCallback.h"
 #include "nsScriptLoader.h"
+#include "jsdbgapi.h"
 #include "jsfriendapi.h"
+#include "jsprf.h"
 #include "js/MemoryMetrics.h"
 #include "mozilla/dom/DOMJSClass.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/Attributes.h"
 #include "AccessCheck.h"
 #include "nsGlobalWindow.h"
 
--- a/js/xpconnect/src/XPCMaps.h
+++ b/js/xpconnect/src/XPCMaps.h
@@ -6,18 +6,16 @@
 
 /* Private maps (hashtables). */
 
 #ifndef xpcmaps_h___
 #define xpcmaps_h___
 
 #include "mozilla/MemoryReporting.h"
 
-#include "js/HashTable.h"
-#include "jsfriendapi.h"
 
 // Maps...
 
 // Note that most of the declarations for hash table entries begin with
 // a pointer to something or another. This makes them look enough like
 // the PLDHashEntryStub struct that the default OPs (PL_DHashGetStubOps())
 // just do the right thing for most of our needs.
 
--- a/js/xpconnect/src/XPCQuickStubs.cpp
+++ b/js/xpconnect/src/XPCQuickStubs.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Util.h"
 
 #include "jsapi.h"
 #include "jsfriendapi.h"
+#include "jsprf.h"
 #include "nsCOMPtr.h"
 #include "xpcprivate.h"
 #include "XPCInlines.h"
 #include "XPCQuickStubs.h"
 #include "mozilla/dom/BindingUtils.h"
 
 using namespace mozilla;
 using namespace JS;
--- a/js/xpconnect/src/XPCStack.cpp
+++ b/js/xpconnect/src/XPCStack.cpp
@@ -2,16 +2,18 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Implements nsIStackFrame. */
 
 #include "xpcprivate.h"
+#include "jsdbgapi.h"
+#include "jsprf.h"
 
 class XPCJSStackFrame : public nsIStackFrame
 {
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSISTACKFRAME
 
     static nsresult CreateStack(JSContext* cx, XPCJSStackFrame** stack);
--- a/js/xpconnect/src/XPCThrower.cpp
+++ b/js/xpconnect/src/XPCThrower.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Code for throwing errors into JavaScript. */
 
 #include "xpcprivate.h"
 #include "xpcpublic.h"
 #include "XPCWrapper.h"
+#include "jsprf.h"
 
 bool XPCThrower::sVerbose = true;
 
 // static
 void
 XPCThrower::Throw(nsresult rv, JSContext* cx)
 {
     const char* format;
--- a/js/xpconnect/src/XPCVariant.cpp
+++ b/js/xpconnect/src/XPCVariant.cpp
@@ -6,16 +6,17 @@
 
 /* nsIVariant implementation for xpconnect. */
 
 #include "xpcprivate.h"
 #include "XPCWrapper.h"
 #include "nsCxPusher.h"
 
 #include "jsfriendapi.h"
+#include "jsprf.h"
 
 using namespace JS;
 using namespace mozilla;
 
 NS_IMPL_CLASSINFO(XPCVariant, NULL, 0, XPCVARIANT_CID)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XPCVariant)
   NS_INTERFACE_MAP_ENTRY(XPCVariant)
   NS_INTERFACE_MAP_ENTRY(nsIVariant)
--- a/js/xpconnect/src/XPCWrappedJS.cpp
+++ b/js/xpconnect/src/XPCWrappedJS.cpp
@@ -2,16 +2,17 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Class that wraps JS objects to appear as XPCOM objects. */
 
 #include "xpcprivate.h"
+#include "jsprf.h"
 #include "nsCxPusher.h"
 #include "nsContentUtils.h"
 #include "nsProxyRelease.h"
 #include "nsThreadUtils.h"
 #include "nsTextFormatter.h"
 
 using namespace mozilla;
 
--- a/js/xpconnect/src/XPCWrappedJSClass.cpp
+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
@@ -3,16 +3,17 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Sharable code and data for wrapper around JSObjects. */
 
 #include "xpcprivate.h"
+#include "jsprf.h"
 #include "nsArrayEnumerator.h"
 #include "nsContentUtils.h"
 #include "nsWrapperCache.h"
 #include "XPCWrapper.h"
 #include "AccessCheck.h"
 #include "nsJSUtils.h"
 #include "mozilla/Attributes.h"
 
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -9,16 +9,17 @@
 
 #include "xpcprivate.h"
 #include "nsCRT.h"
 #include "XPCWrapper.h"
 #include "nsWrapperCacheInlines.h"
 #include "XPCLog.h"
 #include "nsINode.h"
 #include "XPCQuickStubs.h"
+#include "jsprf.h"
 #include "jsproxy.h"
 #include "AccessCheck.h"
 #include "WrapperFactory.h"
 #include "XrayWrapper.h"
 
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
 
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -2,16 +2,17 @@
 // vim:cindent:ts=8:et:sw=4:
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Manage the shared info about interfaces for use by wrappedNatives. */
 
 #include "xpcprivate.h"
+#include "jswrapper.h"
 #include "nsCxPusher.h"
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/XPTInterfaceInfoManager.h"
 
 using namespace JS;
 using namespace mozilla;
 
--- a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp
@@ -5,16 +5,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* JavaScript JSClasses and JSOps for our Wrapped Native JS Objects. */
 
 #include "xpcprivate.h"
 #include "XPCWrapper.h"
 #include "AccessCheck.h"
+#include "jsprf.h"
 #include "nsWrapperCacheInlines.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
 using namespace JS;
 
 /***************************************************************************/
--- a/js/xpconnect/src/XPCWrapper.h
+++ b/js/xpconnect/src/XPCWrapper.h
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef XPC_WRAPPER_H
 #define XPC_WRAPPER_H 1
 
 #include "xpcprivate.h"
 #include "xpcpublic.h"
+#include "jswrapper.h"
 
 class nsIScriptSecurityManager;
 
 namespace XPCNativeWrapper {
 
 // Given an XPCWrappedNative pointer and the name of the function on
 // XPCNativeScriptableFlags corresponding with a flag, returns 'true'
 // if the flag is set.
--- a/js/xpconnect/src/nsScriptError.cpp
+++ b/js/xpconnect/src/nsScriptError.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * nsIScriptError implementation.  Defined here, lacking a JS-specific
  * place to put XPCOM things.
  */
 
 #include "xpcprivate.h"
+#include "jsprf.h"
 #include "nsGlobalWindow.h"
 #include "nsPIDOMWindow.h"
 #include "nsILoadContext.h"
 #include "nsIDocShell.h"
 
 NS_IMPL_ISUPPORTS2(nsScriptError, nsIConsoleMessage, nsIScriptError)
 
 nsScriptError::nsScriptError()
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -11,16 +11,17 @@
 #include "mozilla/Base64.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Util.h"
 
 #include "xpcprivate.h"
 #include "XPCWrapper.h"
 #include "nsBaseHashtable.h"
 #include "nsHashKeys.h"
+#include "jsdbgapi.h"
 #include "jsfriendapi.h"
 #include "dom_quickstubs.h"
 #include "nsNullPrincipal.h"
 #include "nsIURI.h"
 #include "nsJSEnvironment.h"
 #include "nsThreadUtils.h"
 #include "nsDOMJSUtils.h"
 
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -87,24 +87,17 @@
 
 #include <math.h>
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "xpcpublic.h"
-#include "jsapi.h"
-#include "jsprf.h"
 #include "pldhash.h"
-#include "prprf.h"
-#include "jsdbgapi.h"
-#include "jsfriendapi.h"
-#include "js/HeapAPI.h"
-#include "jswrapper.h"
 #include "nscore.h"
 #include "nsXPCOM.h"
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/CycleCollectedJSRuntime.h"
 #include "nsDebug.h"
 #include "nsISupports.h"
 #include "nsIServiceManager.h"
@@ -130,18 +123,16 @@
 #include "prenv.h"
 #include "prclist.h"
 #include "prcvar.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsXPIDLString.h"
 #include "nsAutoJSValHolder.h"
 
-#include "js/HashTable.h"
-
 #include "nsThreadUtils.h"
 #include "nsIJSEngineTelemetryStats.h"
 
 #include "nsIConsoleService.h"
 #include "nsIScriptError.h"
 #include "nsIExceptionService.h"
 
 #include "nsVariant.h"
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -3,20 +3,16 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef xpcpublic_h
 #define xpcpublic_h
 
-#include "jsapi.h"
-#include "jsclass.h"
-#include "jsfriendapi.h"
-#include "jspubtd.h"
 #include "jsproxy.h"
 #include "js/HeapAPI.h"
 #include "js/GCAPI.h"
 
 #include "nsISupports.h"
 #include "nsIURI.h"
 #include "nsIPrincipal.h"
 #include "nsWrapperCache.h"
--- a/js/xpconnect/tests/components/native/xpctest_params.cpp
+++ b/js/xpconnect/tests/components/native/xpctest_params.cpp
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "xpctest_private.h"
 #include "xpctest_interfaces.h"
+#include "js/Value.h"
 
 NS_IMPL_ISUPPORTS1(nsXPCTestParams, nsIXPCTestParams)
 
 nsXPCTestParams::nsXPCTestParams()
 {
 }
 
 nsXPCTestParams::~nsXPCTestParams()
--- a/js/xpconnect/tests/components/native/xpctest_private.h
+++ b/js/xpconnect/tests/components/native/xpctest_private.h
@@ -6,17 +6,16 @@
 
 /* local header for xpconnect tests components */
 
 #ifndef xpctest_private_h___
 #define xpctest_private_h___
 
 #include "nsISupports.h"
 #include "nsMemory.h"
-#include "jsapi.h"
 #include "nsStringGlue.h"
 #include "xpctest_attributes.h"
 #include "xpctest_params.h"
 #include "mozilla/Attributes.h"
 
 class xpcTestObjectReadOnly MOZ_FINAL : public nsIXPCTestObjectReadOnly {
  public:
   NS_DECL_ISUPPORTS
--- a/js/xpconnect/wrappers/AccessCheck.h
+++ b/js/xpconnect/wrappers/AccessCheck.h
@@ -3,17 +3,16 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __AccessCheck_h__
 #define __AccessCheck_h__
 
-#include "jsapi.h"
 #include "jswrapper.h"
 
 class nsIPrincipal;
 
 namespace xpc {
 
 class AccessCheck {
   public:
--- a/js/xpconnect/wrappers/WaiveXrayWrapper.h
+++ b/js/xpconnect/wrappers/WaiveXrayWrapper.h
@@ -5,17 +5,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __CrossOriginWrapper_h__
 #define __CrossOriginWrapper_h__
 
 #include "mozilla/Attributes.h"
 
-#include "jsapi.h"
 #include "jswrapper.h"
 
 namespace xpc {
 
 class WaiveXrayWrapper : public js::CrossCompartmentWrapper {
   public:
     WaiveXrayWrapper(unsigned flags);
     virtual ~WaiveXrayWrapper();
--- a/js/xpconnect/wrappers/WrapperFactory.h
+++ b/js/xpconnect/wrappers/WrapperFactory.h
@@ -3,17 +3,16 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef _xpc_WRAPPERFACTORY_H
 #define _xpc_WRAPPERFACTORY_H
 
-#include "jsapi.h"
 #include "jswrapper.h"
 
 namespace xpc {
 
 class WrapperFactory {
   public:
     enum { WAIVE_XRAY_WRAPPER_FLAG = js::Wrapper::LAST_USED_FLAG << 1,
            IS_XRAY_WRAPPER_FLAG    = WAIVE_XRAY_WRAPPER_FLAG << 1 };
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -13,16 +13,17 @@
 
 #include "nsIContent.h"
 #include "nsContentUtils.h"
 
 #include "XPCWrapper.h"
 #include "xpcprivate.h"
 
 #include "jsapi.h"
+#include "jsprf.h"
 #include "nsJSUtils.h"
 
 #include "mozilla/dom/BindingUtils.h"
 #include "nsGlobalWindow.h"
 
 using namespace mozilla::dom;
 using namespace JS;
 using namespace mozilla;
--- a/js/xpconnect/wrappers/XrayWrapper.h
+++ b/js/xpconnect/wrappers/XrayWrapper.h
@@ -3,17 +3,16 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Attributes.h"
 #include "mozilla/GuardObjects.h"
 
-#include "jsapi.h"
 #include "jswrapper.h"
 
 // Xray wrappers re-resolve the original native properties on the native
 // object and always directly access to those properties.
 // Because they work so differently from the rest of the wrapper hierarchy,
 // we pull them out of the Wrapper inheritance hierarchy and create a
 // little world around them.
 
@@ -75,32 +74,32 @@ class XrayWrapper : public Base {
     virtual bool getPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
                                        JS::MutableHandle<JSPropertyDescriptor> desc, unsigned flags);
     virtual bool getOwnPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
                                           JS::MutableHandle<JSPropertyDescriptor> desc,
                                           unsigned flags);
     virtual bool defineProperty(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
                                 JS::MutableHandle<JSPropertyDescriptor> desc);
     virtual bool getOwnPropertyNames(JSContext *cx, JS::Handle<JSObject*> wrapper,
-                                     js::AutoIdVector &props);
+                                     JS::AutoIdVector &props);
     virtual bool delete_(JSContext *cx, JS::Handle<JSObject*> wrapper,
                          JS::Handle<jsid> id, bool *bp);
-    virtual bool enumerate(JSContext *cx, JS::Handle<JSObject*> wrapper, js::AutoIdVector &props);
+    virtual bool enumerate(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::AutoIdVector &props);
 
     /* Derived proxy traps. */
     virtual bool get(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> receiver,
                      JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp);
     virtual bool set(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> receiver,
                      JS::Handle<jsid> id, bool strict, JS::MutableHandle<JS::Value> vp);
     virtual bool has(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
                      bool *bp);
     virtual bool hasOwn(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
                         bool *bp);
     virtual bool keys(JSContext *cx, JS::Handle<JSObject*> wrapper,
-                      js::AutoIdVector &props);
+                      JS::AutoIdVector &props);
     virtual bool iterate(JSContext *cx, JS::Handle<JSObject*> wrapper, unsigned flags,
                          JS::MutableHandle<JS::Value> vp);
 
     virtual bool call(JSContext *cx, JS::Handle<JSObject*> wrapper,
                       const JS::CallArgs &args) MOZ_OVERRIDE;
     virtual bool construct(JSContext *cx, JS::Handle<JSObject*> wrapper,
                            const JS::CallArgs &args) MOZ_OVERRIDE;
 
--- a/layout/style/nsNthIndexCache.h
+++ b/layout/style/nsNthIndexCache.h
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef nsContentIndexCache_h__
 #define nsContentIndexCache_h__
 
-#include "js/HashTable.h"
 #include "mozilla/dom/Element.h"
 
 /*
  * A class that computes and caches the indices used for :nth-* pseudo-class
  * matching.
  */
 
 class nsNthIndexCache {
--- a/media/webrtc/signaling/src/peerconnection/MediaStreamList.h
+++ b/media/webrtc/signaling/src/peerconnection/MediaStreamList.h
@@ -3,17 +3,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MediaStreamList_h__
 #define MediaStreamList_h__
 
 #include "mozilla/ErrorResult.h"
 #include "nsISupportsImpl.h"
 #include "nsAutoPtr.h"
-#include "jspubtd.h"
 #include "nsWrapperCache.h"
 
 #ifdef USE_FAKE_MEDIA_STREAMS
 #include "FakeMediaStreams.h"
 #else
 #include "DOMMediaStream.h"
 #endif
 
--- a/netwerk/base/src/ArrayBufferInputStream.h
+++ b/netwerk/base/src/ArrayBufferInputStream.h
@@ -3,17 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef ArrayBufferInputStream_h
 #define ArrayBufferInputStream_h
 
 #include "nsIArrayBufferInputStream.h"
 #include "mozilla/Util.h"
-#include "jsapi.h"
+#include "js/Value.h"
 
 #define NS_ARRAYBUFFERINPUTSTREAM_CONTRACTID "@mozilla.org/io/arraybuffer-input-stream;1"
 #define NS_ARRAYBUFFERINPUTSTREAM_CID                \
 { /* 3014dde6-aa1c-41db-87d0-48764a3710f6 */       \
     0x3014dde6,                                      \
     0xaa1c,                                          \
     0x41db,                                          \
     {0x87, 0xd0, 0x48, 0x76, 0x4a, 0x37, 0x10, 0xf6} \
--- a/netwerk/base/src/ProxyAutoConfig.h
+++ b/netwerk/base/src/ProxyAutoConfig.h
@@ -3,22 +3,25 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef ProxyAutoConfig_h__
 #define ProxyAutoConfig_h__
 
 #include "nsString.h"
-#include "jsapi.h"
 #include "prio.h"
 #include "nsITimer.h"
 #include "nsAutoPtr.h"
 #include "mozilla/net/DNS.h"
 
+namespace JS {
+class Value;
+}
+
 namespace mozilla { namespace net {
 
 class JSRuntimeWrapper;
 
 // The ProxyAutoConfig class is meant to be created and run on a
 // non main thread. It synchronously resolves PAC files by blocking that
 // thread and running nested event loops. GetProxyForURI is not re-entrant.
 
--- a/security/manager/ssl/src/nsCrypto.h
+++ b/security/manager/ssl/src/nsCrypto.h
@@ -10,17 +10,16 @@
 #include "mozilla/ErrorResult.h"
 #ifndef MOZ_DISABLE_CRYPTOLEGACY
 #include "Crypto.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMCRMFObject.h"
 #include "nsIDOMCryptoLegacy.h"
 #include "nsIRunnable.h"
 #include "nsString.h"
-#include "jsapi.h"
 #include "nsIPrincipal.h"
 
 #define NS_CRYPTO_CID \
   {0x929d9320, 0x251e, 0x11d4, { 0x8a, 0x7c, 0x00, 0x60, 0x08, 0xc8, 0x44, 0xc3} }
 #define PSM_VERSION_STRING "2.4"
 
 class nsIPSMComponent;
 class nsIDOMScriptObjectFactory;
--- a/storage/src/mozStorageAsyncStatementJSHelper.h
+++ b/storage/src/mozStorageAsyncStatementJSHelper.h
@@ -21,15 +21,15 @@ namespace storage {
  */
 class AsyncStatementJSHelper : public nsIXPCScriptable
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIXPCSCRIPTABLE
 
 private:
-  nsresult getParams(AsyncStatement *, JSContext *, JSObject *, jsval *);
+  nsresult getParams(AsyncStatement *, JSContext *, JSObject *, JS::Value *);
 };
 
 } // namespace storage
 } // namespace mozilla
 
 #endif // mozilla_storage_mozStorageAsyncStatementJSHelper_h_
--- a/storage/src/mozStorageAsyncStatementParams.cpp
+++ b/storage/src/mozStorageAsyncStatementParams.cpp
@@ -3,16 +3,18 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsMemory.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 
+#include "jsapi.h"
+
 #include "mozStoragePrivateHelpers.h"
 #include "mozStorageAsyncStatement.h"
 #include "mozStorageAsyncStatementParams.h"
 #include "mozIStorageStatement.h"
 
 namespace mozilla {
 namespace storage {
 
@@ -42,17 +44,17 @@ NS_IMPL_ISUPPORTS2(
 #include "xpc_map_end.h"
 
 NS_IMETHODIMP
 AsyncStatementParams::SetProperty(
   nsIXPConnectWrappedNative *aWrapper,
   JSContext *aCtx,
   JSObject *aScopeObj,
   jsid aId,
-  jsval *_vp,
+  JS::Value *_vp,
   bool *_retval
 )
 {
   NS_ENSURE_TRUE(mStatement, NS_ERROR_NOT_INITIALIZED);
 
   if (JSID_IS_INT(aId)) {
     int idx = JSID_TO_INT(aId);
 
--- a/storage/src/mozStoragePrivateHelpers.h
+++ b/storage/src/mozStoragePrivateHelpers.h
@@ -9,24 +9,27 @@
 
 /**
  * This file contains convenience methods for mozStorage.
  */
 
 #include "sqlite3.h"
 #include "nsIVariant.h"
 #include "nsError.h"
-#include "jsapi.h"
 #include "nsAutoPtr.h"
 
 class mozIStorageCompletionCallback;
 class mozIStorageBaseStatement;
 class mozIStorageBindingParams;
 class nsIRunnable;
 
+namespace JS {
+class Value;
+}
+
 namespace mozilla {
 namespace storage {
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Macros
 
 #define ENSURE_INDEX_VALUE(aIndex, aCount) \
   NS_ENSURE_TRUE(aIndex < aCount, NS_ERROR_INVALID_ARG)
@@ -50,28 +53,28 @@ nsresult convertResultCode(int aSQLiteRe
  * made faster with the careful use of an index.
  *
  * @param aStatement
  *        The sqlite3_stmt object to check.
  */
 void checkAndLogStatementPerformance(sqlite3_stmt *aStatement);
 
 /**
- * Convert the provided jsval into a variant representation if possible.
+ * Convert the provided JS::Value into a variant representation if possible.
  *
  * @param aCtx
  *        The JSContext the value is from.
  * @param aValue
  *        The JavaScript value to convert.  All primitive types are supported,
  *        but only Date objects are supported from the Date family.  Date
  *        objects are coerced to PRTime (nanoseconds since epoch) values.
  * @return the variant if conversion was successful, nullptr if conversion
  *         failed.  The caller is responsible for addref'ing if non-null.
  */
-nsIVariant *convertJSValToVariant(JSContext *aCtx, jsval aValue);
+nsIVariant *convertJSValToVariant(JSContext *aCtx, JS::Value aValue);
 
 /**
  * Obtains an event that will notify a completion callback about completion.
  *
  * @param aCallback
  *        The callback to be notified.
  * @return an nsIRunnable that can be dispatched to the calling thread.
  */
--- a/storage/src/mozStorageStatementJSHelper.h
+++ b/storage/src/mozStorageStatementJSHelper.h
@@ -16,16 +16,16 @@ namespace storage {
 
 class StatementJSHelper : public nsIXPCScriptable
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIXPCSCRIPTABLE
 
 private:
-  nsresult getRow(Statement *, JSContext *, JSObject *, jsval *);
-  nsresult getParams(Statement *, JSContext *, JSObject *, jsval *);
+  nsresult getRow(Statement *, JSContext *, JSObject *, JS::Value *);
+  nsresult getParams(Statement *, JSContext *, JSObject *, JS::Value *);
 };
 
 } // namespace storage
 } // namespace mozilla
 
 #endif // MOZSTORAGESTATEMENTJSHELPER_H
--- a/storage/src/mozStorageStatementParams.cpp
+++ b/storage/src/mozStorageStatementParams.cpp
@@ -2,16 +2,18 @@
  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsMemory.h"
 #include "nsString.h"
 
+#include "jsapi.h"
+
 #include "mozStoragePrivateHelpers.h"
 #include "mozStorageStatementParams.h"
 #include "mozIStorageStatement.h"
 
 namespace mozilla {
 namespace storage {
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -41,17 +43,17 @@ NS_IMPL_ISUPPORTS2(
 #define XPC_MAP_FLAGS nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
 #include "xpc_map_end.h"
 
 NS_IMETHODIMP
 StatementParams::SetProperty(nsIXPConnectWrappedNative *aWrapper,
                              JSContext *aCtx,
                              JSObject *aScopeObj,
                              jsid aId,
-                             jsval *_vp,
+                             JS::Value *_vp,
                              bool *_retval)
 {
   NS_ENSURE_TRUE(mStatement, NS_ERROR_NOT_INITIALIZED);
 
   if (JSID_IS_INT(aId)) {
     int idx = JSID_TO_INT(aId);
 
     nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCtx, *_vp));
--- a/toolkit/components/ctypes/tests/jsctypes-test-errno.h
+++ b/toolkit/components/ctypes/tests/jsctypes-test-errno.h
@@ -1,16 +1,15 @@
 /* -*-  Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nscore.h"
 #include "prtypes.h"
-#include "jsapi.h"
 
 #define EXPORT_CDECL(type)   NS_EXPORT type
 #define EXPORT_STDCALL(type) NS_EXPORT type NS_STDCALL
 
 NS_EXTERN_C
 {
   EXPORT_CDECL(void) set_errno(int status);
   EXPORT_CDECL(int) get_errno();
--- a/toolkit/components/ctypes/tests/jsctypes-test-finalizer.h
+++ b/toolkit/components/ctypes/tests/jsctypes-test-finalizer.h
@@ -1,14 +1,12 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "jsapi.h"
-
 #define EXPORT_CDECL(type)   NS_EXPORT type
 
 NS_EXTERN_C
 {
   EXPORT_CDECL(void) test_finalizer_start(size_t size);
   EXPORT_CDECL(void) test_finalizer_stop();
   EXPORT_CDECL(bool) test_finalizer_resource_is_acquired(size_t i);
 
--- a/toolkit/components/ctypes/tests/jsctypes-test.h
+++ b/toolkit/components/ctypes/tests/jsctypes-test.h
@@ -1,16 +1,16 @@
 /* -*-  Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nscore.h"
 #include "prtypes.h"
-#include "jsapi.h"
+#include "jspubtd.h"
 
 #define EXPORT_CDECL(type)   NS_EXPORT type
 #define EXPORT_STDCALL(type) NS_EXPORT type NS_STDCALL
 
 NS_EXTERN_C
 {
   EXPORT_CDECL(void) test_void_t_cdecl();
 
--- a/toolkit/components/places/Helpers.h
+++ b/toolkit/components/places/Helpers.h
@@ -10,17 +10,16 @@
  * This file contains helper classes used by various bits of Places code.
  */
 
 #include "mozilla/storage.h"
 #include "nsIURI.h"
 #include "nsThreadUtils.h"
 #include "nsProxyRelease.h"
 #include "mozilla/Telemetry.h"
-#include "jsapi.h"
 
 namespace mozilla {
 namespace places {
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Asynchronous Statement Callback Helper
 
 class AsyncStatementCallback : public mozIStorageStatementCallback
--- a/toolkit/components/places/PlaceInfo.cpp
+++ b/toolkit/components/places/PlaceInfo.cpp
@@ -3,16 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "PlaceInfo.h"
 #include "VisitInfo.h"
 #include "nsIURI.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIXPConnect.h"
 #include "mozilla/Services.h"
+#include "jsapi.h"
 
 namespace mozilla {
 namespace places {
 
 ////////////////////////////////////////////////////////////////////////////////
 //// PlaceInfo
 
 PlaceInfo::PlaceInfo(int64_t aId,
--- a/toolkit/components/places/mozIAsyncHistory.idl
+++ b/toolkit/components/places/mozIAsyncHistory.idl
@@ -2,20 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
 interface nsIURI;
 interface nsIVariant;
 
-%{C++
-#include "jsapi.h"
-%}
-
 [scriptable, uuid(41e4ccc9-f0c8-4cd7-9753-7a38514b8488)]
 interface mozIVisitInfo : nsISupports
 {
   /**
    * The machine-local (internal) id of the visit.
    */
   readonly attribute long long visitId;
 
--- a/toolkit/components/places/mozIAsyncLivemarks.idl
+++ b/toolkit/components/places/mozIAsyncLivemarks.idl
@@ -1,18 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
-%{C++
-#include "jsapi.h"
-%}
-
 interface nsIURI;
 
 interface mozILivemarkCallback;
 interface mozILivemarkInfo;
 interface mozILivemark;
 
 interface nsINavHistoryResultObserver;
 
--- a/tools/profiler/GeckoProfiler.h
+++ b/tools/profiler/GeckoProfiler.h
@@ -44,17 +44,16 @@
  *          application is responding to the event loop. Lower is better.
  * 't' - Elapse time since recording started.
  *
  */
 
 #ifndef SAMPLER_H
 #define SAMPLER_H
 
-#include "jsfriendapi.h"
 #include "mozilla/NullPtr.h"
 #include "mozilla/TimeStamp.h"
 
 #ifndef MOZ_ENABLE_PROFILER_SPS
 
 // Insert a RAII in this scope to active a pseudo label. Any samples collected
 // in this scope will contain this annotation. For dynamic strings use
 // PROFILER_LABEL_PRINTF. Arguments must be string literals.
--- a/tools/profiler/GeckoProfilerFunc.h
+++ b/tools/profiler/GeckoProfilerFunc.h
@@ -4,21 +4,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef PROFILER_FUNCS_H
 #define PROFILER_FUNCS_H
 
 #include "mozilla/NullPtr.h"
 #include <stdint.h>
 #include "mozilla/TimeStamp.h"
-#include "jsfriendapi.h"
 
 using mozilla::TimeStamp;
 using mozilla::TimeDuration;
 
+struct JSContext;
+class JSObject;
+
 // Returns a handle to pass on exit. This can check that we are popping the
 // correct callstack.
 inline void* mozilla_sampler_call_enter(const char *aInfo, void *aFrameAddress = NULL,
                                         bool aCopy = false, uint32_t line = 0);
 inline void  mozilla_sampler_call_exit(void* handle);
 inline void  mozilla_sampler_add_marker(const char *aInfo);
 
 void mozilla_sampler_start(int aEntries, double aInterval,
--- a/tools/profiler/GeckoProfilerImpl.h
+++ b/tools/profiler/GeckoProfilerImpl.h
@@ -11,17 +11,16 @@
 #include <stdarg.h>
 #include <algorithm>
 #include "mozilla/ThreadLocal.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Util.h"
 #include "nsAlgorithm.h"
 #include "nscore.h"
-#include "jsfriendapi.h"
 #include "GeckoProfilerFunc.h"
 #include "PseudoStack.h"
 #include "nsISupports.h"
 
 /* QT has a #define for the word "slots" and jsfriendapi.h has a struct with
  * this variable name, causing compilation problems. Alleviate this for now by
  * removing this #define */
 #ifdef MOZ_WIDGET_QT
--- a/tools/profiler/JSObjectBuilder.h
+++ b/tools/profiler/JSObjectBuilder.h
@@ -6,16 +6,17 @@
 #ifndef JSOBJECTBUILDER_H
 #define JSOBJECTBUILDER_H
 
 #include "JSAObjectBuilder.h"
 
 class JSCustomObject;
 class JSCustomObjectBuilder;
 struct JSContext;
+class JSObject;
 class nsAString;
 
 /* this is handy wrapper around JSAPI to make it more pleasant to use.
  * We collect the JSAPI errors and so that callers don't need to */
 class JSObjectBuilder : public JSAObjectBuilder
 {
 public:
   // We need to ensure that this object lives on the stack so that GC sees it properly
--- a/tools/profiler/SaveProfileTask.h
+++ b/tools/profiler/SaveProfileTask.h
@@ -7,17 +7,16 @@
 #define PROFILER_SAVETASK_H_
 
 #include "platform.h"
 #include "nsThreadUtils.h"
 #include "nsIXULRuntime.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsXULAppAPI.h"
-#include "jsfriendapi.h"
 #include "nsIJSRuntimeService.h"
 #include "nsIProfileSaveEvent.h"
 
 #include <ostream>
 #include <fstream>
 
 #ifdef XP_WIN
  #include <windows.h>
--- a/xpcom/base/CycleCollectedJSRuntime.h
+++ b/xpcom/base/CycleCollectedJSRuntime.h
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_CycleCollectedJSRuntime_h__
 #define mozilla_CycleCollectedJSRuntime_h__
 
 #include "mozilla/MemoryReporting.h"
 #include "jsapi.h"
-#include "jsfriendapi.h"
+#include "jsclass.h"
 
 #include "nsCycleCollector.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "nsTArray.h"
 
 class nsCycleCollectionNoteRootCallback;
--- a/xpcom/build/mozPoisonWriteMac.cpp
+++ b/xpcom/build/mozPoisonWriteMac.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/mozPoisonWrite.h"
 #include "mozPoisonWriteBase.h"
 #include "mozilla/Util.h"
 #include "nsTraceRefcntImpl.h"
 #include "mozilla/Assertions.h"
+#include "mozilla/DebugOnly.h"
 #include "mozilla/Scoped.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/ProcessedStack.h"
 #include "nsStackWalk.h"
 #include "nsPrintfCString.h"
 #include "mach_override.h"
 #include "prio.h"
--- a/xpcom/reflect/xptcall/public/xptcall.h
+++ b/xpcom/reflect/xptcall/public/xptcall.h
@@ -7,17 +7,17 @@
 
 #ifndef xptcall_h___
 #define xptcall_h___
 
 #include "nscore.h"
 #include "nsISupports.h"
 #include "xpt_struct.h"
 #include "xptinfo.h"
-#include "jsapi.h"
+#include "js/Value.h"
 
 struct nsXPTCMiniVariant
 {
 // No ctors or dtors so that we can use arrays of these on the stack
 // with no penalty.
     union
     {
         int8_t    i8;
@@ -33,17 +33,17 @@ struct nsXPTCMiniVariant
         bool      b;
         char      c;
         PRUnichar wc;
         void*     p;
 
         // Types below here are unknown to the assembly implementations, and
         // therefore _must_ be passed with indirect semantics. We put them in
         // the union here for type safety, so that we can avoid void* tricks.
-        jsval j;
+        JS::Value j;
     } val;
 };
 
 struct nsXPTCVariant : public nsXPTCMiniVariant
 {
 // No ctors or dtors so that we can use arrays of these on the stack
 // with no penalty.
 
@@ -70,17 +70,17 @@ struct nsXPTCVariant : public nsXPTCMini
         //
         // Since ptr always points to &val, the semantics of this flag are kind of
         // dumb, since the ptr field is unnecessary. But changing them would
         // require changing dozens of assembly files, so they're likely to stay
         // the way they are.
         PTR_IS_DATA    = 0x1,
 
         // Indicates that the value we hold requires some sort of cleanup (memory
-        // deallocation, interface release, jsval unrooting, etc). The precise
+        // deallocation, interface release, JS::Value unrooting, etc). The precise
         // cleanup that is performed depends on the 'type' field above.
         // If the value is an array, this flag specifies whether the elements
         // within the array require cleanup (we always clean up the array itself,
         // so this flag would be redundant for that purpose).
         VAL_NEEDS_CLEANUP = 0x2
     };
 
     void ClearFlags()         {flags = 0;}
--- a/xpcom/tests/TestHarness.h
+++ b/xpcom/tests/TestHarness.h
@@ -31,17 +31,16 @@
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsIDirectoryService.h"
 #include "nsIFile.h"
 #include "nsIProperties.h"
 #include "nsIObserverService.h"
 #include "nsXULAppAPI.h"
-#include "jsdbgapi.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 
 static uint32_t gFailCount = 0;
 
 /**
  * Prints the given failure message and arguments using printf, prepending