# HG changeset patch
# Parent  f414213f01f5e0943377f070f6475eec278886f7

diff --git a/js/public/RequiredDefines.h b/js/public/RequiredDefines.h
new file mode 100644
--- /dev/null
+++ b/js/public/RequiredDefines.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=8 sts=2 et sw=2 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/. */
+
+/*
+ * Various #defines required to build SpiderMonkey.  Embedders should add this
+ * file to the start of the command line via -include or a similar mechanism,
+ * or SpiderMonkey public headers may not work correctly.
+ */
+
+#ifndef js_RequiredDefines_h
+#define js_RequiredDefines_h
+
+/*
+ * The c99 defining the limit macros (UINT32_MAX for example), says:
+ *
+ *   C++ implementations should define these macros only when
+ *   __STDC_LIMIT_MACROS is defined before <stdint.h> is included.
+ *
+ * The same also occurs with __STDC_CONSTANT_MACROS for the constant macros
+ * (INT8_C for example) used to specify a literal constant of the proper type,
+ * and with __STDC_FORMAT_MACROS for the format macros (PRId32 for example) used
+ * with the fprintf function family.
+ */
+#define __STDC_LIMIT_MACROS
+#define __STDC_CONSTANT_MACROS
+#define __STDC_FORMAT_MACROS
+
+#endif /* js_RequiredDefines_h */
diff --git a/js/src/build/js-config.in b/js/src/build/js-config.in
--- a/js/src/build/js-config.in
+++ b/js/src/build/js-config.in
@@ -103,14 +103,14 @@ if test "$echo_includedir" = "yes"; then
     echo $includedir
 fi
 
 if test "$echo_libdir" = "yes"; then
     echo $libdir
 fi
 
 if test "$echo_cflags" = "yes"; then
-    echo "-std=gnu++11 -isystem $includedir/$JS_LIBRARY_NAME $NSPR_CFLAGS"
+    echo "-std=gnu++11 -include $includedir/$JS_LIBRARY_NAME/js/RequiredDefines.h -isystem $includedir/$JS_LIBRARY_NAME $NSPR_CFLAGS"
 fi
 
 if test "$echo_libs" = "yes"; then
     echo "$MOZ_JS_LIBS $JS_CONFIG_LIBS"
 fi
diff --git a/js/src/build/js.pc.in b/js/src/build/js.pc.in
--- a/js/src/build/js.pc.in
+++ b/js/src/build/js.pc.in
@@ -6,9 +6,9 @@ includedir=@includedir@
 Name: SpiderMonkey @MOZILLA_VERSION@
 Description: The Mozilla library for JavaScript
 Version: @MOZILLA_VERSION@
 @PKGCONF_REQUIRES_PRIVATE@
 Libs: -L${libdir} -l@JS_LIBRARY_NAME@
 # Use -isystem for includes rather than -I, to mark them as "system headers"
 # that don't generate warning diagnostics. For justification, see
 # https://bugzilla.mozilla.org/show_bug.cgi?id=1539036
-Cflags: -isystem ${includedir}/@JS_LIBRARY_NAME@
+Cflags: -include ${includedir}/@JS_LIBRARY_NAME@/js/RequiredDefines.h -isystem ${includedir}/@JS_LIBRARY_NAME@
diff --git a/js/src/js-confdefs.h.in b/js/src/js-confdefs.h.in
--- a/js/src/js-confdefs.h.in
+++ b/js/src/js-confdefs.h.in
@@ -4,9 +4,11 @@
  */
 
 #ifndef js_confdefs_h
 #define js_confdefs_h
 
 // Expands to all the defines from configure.
 #undef ALLDEFINES
 
+#include "js/RequiredDefines.h"
+
 #endif /* js_confdefs_h */
diff --git a/js/src/jstypes.h b/js/src/jstypes.h
--- a/js/src/jstypes.h
+++ b/js/src/jstypes.h
@@ -24,16 +24,19 @@
 #include "mozilla/Casting.h"
 #include "mozilla/Types.h"
 
 #include <stddef.h>
 #include <stdint.h>
 
 // jstypes.h is (or should be!) included by every file in SpiderMonkey.
 // js-config.h also should be included by every file. So include it here.
+// XXX: including it in js/RequiredDefines.h should be a better option, since
+// that is by definition the header file that should be included in all
+// SpiderMonkey code.  However, Gecko doesn't do this!  See bug 909576.
 #include "js-config.h"
 
 /*
  * The linkage of JS API functions differs depending on whether the file is
  * used within the JS library or not. Any source file within the JS
  * interpreter should define EXPORT_JS_API whereas any client of the library
  * should not. STATIC_JS_API is used to build JS as a static library.
  */
diff --git a/js/src/moz.build b/js/src/moz.build
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -180,16 +180,17 @@ EXPORTS.js += [
     "../public/ProtoKey.h",
     "../public/Proxy.h",
     "../public/Realm.h",
     "../public/RealmIterators.h",
     "../public/RealmOptions.h",
     "../public/RefCounted.h",
     "../public/RegExp.h",
     "../public/RegExpFlags.h",
+    "../public/RequiredDefines.h",
     "../public/Result.h",
     "../public/RootingAPI.h",
     "../public/SavedFrameAPI.h",
     "../public/ScalarType.h",
     "../public/SharedArrayBuffer.h",
     "../public/SliceBudget.h",
     "../public/SourceText.h",
     "../public/StableStringChars.h",
