Bug 939505 - Use JS_DEBUG in public headers. r=jorendorff
authorSean Stangl <sstangl@mozilla.com>
Fri, 06 Dec 2013 15:03:08 -0800
changeset 159520 83160d1d58c831b0e15534e3d24a2e85886f5711
parent 159519 fabe232e8be92d71ff8544f3ee3f2055f40ee0af
child 159521 66bdd9219610d21c4610b95c14e8bd08c89a2a52
push id37350
push usersean.stangl@gmail.com
push dateMon, 09 Dec 2013 20:57:19 +0000
treeherdermozilla-inbound@83160d1d58c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs939505
milestone28.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 939505 - Use JS_DEBUG in public headers. r=jorendorff
js/public/CallArgs.h
js/public/GCAPI.h
js/public/HashTable.h
js/public/OldDebugAPI.h
js/public/RootingAPI.h
js/public/TypeDecls.h
js/public/Utility.h
js/public/Value.h
js/src/configure.in
js/src/js-config.h.in
js/src/jsapi.h
js/src/jsfriendapi.h
js/src/jsproxy.h
js/src/jspubtd.h
--- a/js/public/CallArgs.h
+++ b/js/public/CallArgs.h
@@ -113,17 +113,17 @@ extern JS_PUBLIC_DATA(const HandleValue)
  *
  * CallReceiver is exposed publicly and used internally.  Not all parts of its
  * public interface are meant to be used by embedders!  See inline comments to
  * for details.
  */
 
 namespace detail {
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
 extern JS_PUBLIC_API(void)
 CheckIsValidConstructible(Value v);
 #endif
 
 enum UsedRval { IncludeUsedRval, NoUsedRval };
 
 template<UsedRval WantUsedRval>
 class MOZ_STACK_CLASS UsedRvalBase;
@@ -142,17 +142,17 @@ class MOZ_STACK_CLASS UsedRvalBase<NoUse
 {
   protected:
     void setUsedRval() const {}
     void clearUsedRval() const {}
 };
 
 template<UsedRval WantUsedRval>
 class MOZ_STACK_CLASS CallReceiverBase : public UsedRvalBase<
-#ifdef DEBUG
+#ifdef JS_DEBUG
         WantUsedRval
 #else
         NoUsedRval
 #endif
     >
 {
   protected:
     Value *argv_;
@@ -192,17 +192,17 @@ class MOZ_STACK_CLASS CallReceiverBase :
     Value computeThis(JSContext *cx) const {
         if (thisv().isObject())
             return thisv();
 
         return JS_ComputeThis(cx, base());
     }
 
     bool isConstructing() const {
-#ifdef DEBUG
+#ifdef JS_DEBUG
         if (this->usedRval_)
             CheckIsValidConstructible(calleev());
 #endif
         return argv_[-1].isMagic();
     }
 
     /*
      * Returns the currently-set return value.  The initial contents of this
--- a/js/public/GCAPI.h
+++ b/js/public/GCAPI.h
@@ -209,17 +209,17 @@ PokeGC(JSRuntime *rt);
 extern JS_FRIEND_API(bool)
 WasIncrementalGC(JSRuntime *rt);
 
 extern JS_FRIEND_API(size_t)
 GetGCNumber();
 
 class JS_PUBLIC_API(AutoAssertNoGC)
 {
-#ifdef DEBUG
+#ifdef JS_DEBUG
     JSRuntime *runtime;
     size_t gcNumber;
 
   public:
     AutoAssertNoGC();
     AutoAssertNoGC(JSRuntime *rt);
     ~AutoAssertNoGC();
 #else
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -758,17 +758,17 @@ class HashTable : private AllocPolicy
         Entry *entry_;
 
       protected:
         Ptr(Entry &entry) : entry_(&entry) {}
 
       public:
         // Leaves Ptr uninitialized.
         Ptr() {
-#ifdef DEBUG
+#ifdef JS_DEBUG
             entry_ = (Entry *)0xbad;
 #endif
         }
 
         bool found() const                    { return entry_->isLive(); }
         operator ConvertibleToBool() const    { return found() ? &Ptr::nonNull : 0; }
         bool operator==(const Ptr &rhs) const { JS_ASSERT(found() && rhs.found()); return entry_ == rhs.entry_; }
         bool operator!=(const Ptr &rhs) const { return !(*this == rhs); }
@@ -914,17 +914,17 @@ class HashTable : private AllocPolicy
     uint32_t    removedCount;   // removed entry sentinels in table
     Entry       *table;         // entry storage
 
     void setTableSizeLog2(unsigned sizeLog2)
     {
         hashShift = sHashBits - sizeLog2;
     }
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
     mutable struct Stats
     {
         uint32_t        searches;       // total number of table searches
         uint32_t        steps;          // hash chain links traversed
         uint32_t        hits;           // searches that found key
         uint32_t        misses;         // searches that didn't find key
         uint32_t        addOverRemoved; // adds that recycled a removed entry
         uint32_t        removes;        // calls to remove
--- a/js/public/OldDebugAPI.h
+++ b/js/public/OldDebugAPI.h
@@ -44,17 +44,17 @@ DescribeStack(JSContext *cx, unsigned ma
 extern JS_PUBLIC_API(void)
 FreeStackDescription(JSContext *cx, StackDescription *desc);
 
 extern JS_PUBLIC_API(char *)
 FormatStackDump(JSContext *cx, char *buf, bool showArgs, bool showLocals, bool showThisProps);
 
 }
 
-# ifdef DEBUG
+# ifdef JS_DEBUG
 JS_FRIEND_API(void) js_DumpValue(const JS::Value &val);
 JS_FRIEND_API(void) js_DumpId(jsid id);
 JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, js::StackFrame *start = nullptr);
 # endif
 
 JS_FRIEND_API(void)
 js_DumpBacktrace(JSContext *cx);
 
--- a/js/public/RootingAPI.h
+++ b/js/public/RootingAPI.h
@@ -145,17 +145,17 @@ struct Cell;
 namespace JS {
 
 template <typename T> class Rooted;
 template <typename T> class PersistentRooted;
 
 /* This is exposing internal state of the GC for inlining purposes. */
 JS_FRIEND_API(bool) isGCEnabled();
 
-#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
+#if defined(JS_DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
 extern void
 CheckStackRoots(JSContext *cx);
 #endif
 
 /*
  * JS::NullPtr acts like a nullptr pointer in contexts that require a Handle.
  *
  * Handle provides an implicit constructor for JS::NullPtr so that, given:
@@ -260,17 +260,17 @@ class Heap : public js::HeapBase<T>
 #ifdef JSGC_GENERATIONAL
         js::GCMethods<T>::relocate(&ptr);
 #endif
     }
 
     T ptr;
 };
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
 /*
  * For generational GC, assert that an object is in the tenured generation as
  * opposed to being in the nursery.
  */
 extern JS_FRIEND_API(void)
 AssertGCThingMustBeTenured(JSObject* obj);
 #else
 inline void
@@ -643,17 +643,17 @@ struct GCMethods<T *>
         JS::HeapCellPostBarrier(reinterpret_cast<js::gc::Cell **>(vp));
     }
     static void relocate(T **vp) {
         JS::HeapCellRelocate(reinterpret_cast<js::gc::Cell **>(vp));
     }
 #endif
 };
 
-#if defined(DEBUG)
+#if defined(JS_DEBUG)
 /* This helper allows us to assert that Rooted<T> is scoped within a request. */
 extern JS_PUBLIC_API(bool)
 IsInRequest(JSContext *cx);
 #endif
 
 } /* namespace js */
 
 namespace JS {
@@ -793,17 +793,17 @@ class MOZ_STACK_CLASS Rooted : public js
     bool operator!=(const T &other) const { return ptr != other; }
     bool operator==(const T &other) const { return ptr == other; }
 
   private:
 #ifdef JSGC_TRACK_EXACT_ROOTS
     Rooted<void*> **stack, *prev;
 #endif
 
-#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
+#if defined(JS_DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
     /* Has the rooting analysis ever scanned this Rooted's stack location? */
     friend void JS::CheckStackRoots(JSContext*);
 #endif
 
 #ifdef JSGC_ROOT_ANALYSIS
     bool scanned;
 #endif
 
@@ -831,17 +831,17 @@ namespace js {
 /*
  * Mark a stack location as a root for the rooting analysis, without actually
  * rooting it in release builds. This should only be used for stack locations
  * of GC things that cannot be relocated by a garbage collection, and that
  * are definitely reachable via another path.
  */
 class SkipRoot
 {
-#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
+#if defined(JS_DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
 
     SkipRoot **stack, *prev;
     const uint8_t *start;
     const uint8_t *end;
 
     template <typename CX, typename T>
     void init(CX *cx, const T *ptr, size_t count) {
         SkipRoot **head = &cx->skipGCRooters;
@@ -859,28 +859,28 @@ class SkipRoot
     }
 
     SkipRoot *previous() { return prev; }
 
     bool contains(const uint8_t *v, size_t len) {
         return v >= start && v + len <= end;
     }
 
-#else /* DEBUG && JSGC_ROOT_ANALYSIS */
+#else /* JS_DEBUG && JSGC_ROOT_ANALYSIS */
 
     template <typename T>
     void init(js::ContextFriendFields *cx, const T *ptr, size_t count) {}
 
   public:
     ~SkipRoot() {
         // An empty destructor is needed to avoid warnings from clang about
         // unused local variables of this type.
     }
 
-#endif /* DEBUG && JSGC_ROOT_ANALYSIS */
+#endif /* JS_DEBUG && JSGC_ROOT_ANALYSIS */
 
     template <typename T>
     SkipRoot(JSContext *cx, const T *ptr, size_t count = 1
              MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
     {
         init(ContextFriendFields::get(cx), ptr, count);
         MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     }
@@ -1199,17 +1199,17 @@ class PersistentRooted : public mozilla:
 namespace js {
 
 /*
  * Hook for dynamic root analysis. Checks the native stack and poisons
  * references to GC things which have not been rooted.
  */
 inline void MaybeCheckStackRoots(JSContext *cx)
 {
-#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
+#if defined(JS_DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
     JS::CheckStackRoots(cx);
 #endif
 }
 
 /* Base class for automatic read-only object rooting during compilation. */
 class CompilerRootNode
 {
   protected:
--- a/js/public/TypeDecls.h
+++ b/js/public/TypeDecls.h
@@ -15,16 +15,18 @@
 // It does *not* contain any struct or class definitions.
 
 #ifndef js_TypeDecls_h
 #define js_TypeDecls_h
 
 #include <stddef.h>
 #include <stdint.h>
 
+#include "js-config.h"
+
 struct JSContext;
 class JSFunction;
 class JSObject;
 class JSScript;
 class JSString;
 
 // In release builds, jsid is defined to be an integral type. This
 // prevents many bugs from being caught at compile time. E.g.:
@@ -35,17 +37,17 @@ class JSString;
 //
 //  size_t n = id;      // error
 //
 // To catch more errors, jsid is given a struct type in C++ debug builds.
 // Struct assignment and (in C++) operator== allow correct code to be mostly
 // oblivious to the change. This feature can be explicitly disabled in debug
 // builds by defining JS_NO_JSVAL_JSID_STRUCT_TYPES.
 //
-#if defined(DEBUG) && !defined(JS_NO_JSVAL_JSID_STRUCT_TYPES)
+#if defined(JS_DEBUG) && !defined(JS_NO_JSVAL_JSID_STRUCT_TYPES)
 # define JS_USE_JSID_STRUCT_TYPES
 #endif
 
 #ifdef JS_USE_JSID_STRUCT_TYPES
 struct jsid;
 #else
 typedef ptrdiff_t jsid;
 #endif
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -40,17 +40,17 @@ namespace js {}
  */
 #define JS_FREE_PATTERN 0xDA
 
 #define JS_ASSERT(expr)           MOZ_ASSERT(expr)
 #define JS_ASSERT_IF(cond, expr)  MOZ_ASSERT_IF(cond, expr)
 #define JS_ALWAYS_TRUE(expr)      MOZ_ALWAYS_TRUE(expr)
 #define JS_ALWAYS_FALSE(expr)     MOZ_ALWAYS_FALSE(expr)
 
-#if defined(DEBUG)
+#if defined(JS_DEBUG)
 # define JS_DIAGNOSTICS_ASSERT(expr) MOZ_ASSERT(expr)
 #elif defined(JS_CRASH_DIAGNOSTICS)
 # define JS_DIAGNOSTICS_ASSERT(expr) do { if (!(expr)) MOZ_CRASH(); } while(0)
 #else
 # define JS_DIAGNOSTICS_ASSERT(expr) ((void) 0)
 #endif
 
 #define JS_STATIC_ASSERT(cond)           static_assert(cond, "JS_STATIC_ASSERT")
@@ -67,17 +67,17 @@ JS_Assert(const char *s, const char *fil
 extern JS_PUBLIC_API(void) JS_Abort(void);
 
 /*
  * Custom allocator support for SpiderMonkey
  */
 #if defined JS_USE_CUSTOM_ALLOCATOR
 # include "jscustomallocator.h"
 #else
-# ifdef DEBUG
+# ifdef JS_DEBUG
 /*
  * In order to test OOM conditions, when the testing function
  * oomAfterAllocations COUNT is passed, we fail continuously after the NUM'th
  * allocation from now.
  */
 extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtins/TestingFunctions.cpp */
 extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */
 
@@ -131,17 +131,17 @@ PrintBacktrace()
             js_ReportOutOfMemory(cx);\
             return nullptr; \
         } \
     } while (0)
 
 # else
 #  define JS_OOM_POSSIBLY_FAIL() do {} while(0)
 #  define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0)
-# endif /* DEBUG */
+# endif /* JS_DEBUG */
 
 static inline void* js_malloc(size_t bytes)
 {
     JS_OOM_POSSIBLY_FAIL();
     return malloc(bytes);
 }
 
 static inline void* js_calloc(size_t bytes)
@@ -530,26 +530,26 @@ namespace JS {
  * pointer to a GC thing, one byte of that pointer is poisoned to refer to an
  * invalid location. For both 32 bit and 64 bit systems, the fourth byte of the
  * pointer is overwritten, to reduce the likelihood of accidentally changing
  * a live integer value.
  */
 
 inline void PoisonPtr(void *v)
 {
-#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG)
+#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG)
     uint8_t *ptr = (uint8_t *) v + 3;
     *ptr = JS_FREE_PATTERN;
 #endif
 }
 
 template <typename T>
 inline bool IsPoisonedPtr(T *v)
 {
-#if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG)
+#if defined(JSGC_ROOT_ANALYSIS) && defined(JS_DEBUG)
     uint32_t mask = uintptr_t(v) & 0xff000000;
     return mask == uint32_t(JS_FREE_PATTERN << 24);
 #else
     return false;
 #endif
 }
 
 }
--- a/js/public/Value.h
+++ b/js/public/Value.h
@@ -1735,29 +1735,29 @@ namespace JS {
 template<>
 inline Anchor<Value>::~Anchor()
 {
     volatile uint64_t bits;
     bits = JSVAL_TO_IMPL(hold).asBits;
 }
 #endif
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
 namespace detail {
 
 struct ValueAlignmentTester { char c; JS::Value v; };
 static_assert(sizeof(ValueAlignmentTester) == 16,
               "JS::Value must be 16-byte-aligned");
 
 struct LayoutAlignmentTester { char c; jsval_layout l; };
 static_assert(sizeof(LayoutAlignmentTester) == 16,
               "jsval_layout must be 16-byte-aligned");
 
 } // namespace detail
-#endif /* DEBUG */
+#endif /* JS_DEBUG */
 
 } // namespace JS
 
 /*
  * JS::Value and jsval are the same type; jsval is the old name, kept around
  * for backwards compatibility along with all the JSVAL_* operations below.
  * jsval_layout is an implementation detail and should not be used externally.
  */
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -3453,16 +3453,23 @@ dnl ====================================
 dnl vtune
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(vtune,
 [  --enable-vtune          Enable vtune profiling. Implies --enable-profiling.],
     MOZ_VTUNE=1,
     MOZ_VTUNE= )
 
 dnl ========================================================
+dnl Debug (see Bug 939505)
+dnl ========================================================
+if test -n "$MOZ_DEBUG"; then
+    AC_DEFINE(JS_DEBUG)
+fi
+
+dnl ========================================================
 dnl Profiling
 dnl ========================================================
 if test -n "$MOZ_PROFILING"; then
     AC_DEFINE(MOZ_PROFILING)
 
     case "$OS_TARGET" in
         Linux) MOZ_VTUNE=1 ;;
         WINNT) MOZ_VTUNE=1 ;;
--- a/js/src/js-config.h.in
+++ b/js/src/js-config.h.in
@@ -7,16 +7,22 @@
 
 #ifndef js_config_h
 #define js_config_h
 
 /* Definitions set at build time that affect SpiderMonkey's public API.
    This header file is generated by the SpiderMonkey configure script,
    and installed along with jsapi.h.  */
 
+/* Define to 1 if SpiderMonkey is in debug mode. */
+#undef JS_DEBUG
+
+/* Define to 1 if SpiderMonkey should not use struct types in debug builds. */
+#undef JS_NO_JSVAL_JSID_STRUCT_TYPES
+
 /* Define to 1 if SpiderMonkey should support multi-threaded clients.  */
 #undef JS_THREADSAFE
 
 /* Define to 1 if SpiderMonkey should include ctypes support.  */
 #undef JS_HAS_CTYPES
 
 /* Define to 1 if SpiderMonkey should support the ability to perform
    entirely too much GC.  */
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -47,17 +47,17 @@ class StableCharPtr : public CharPtr {
     StableCharPtr(const StableCharPtr &s) : CharPtr(s) {}
     StableCharPtr(const mozilla::RangedPtr<const jschar> &s) : CharPtr(s) {}
     StableCharPtr(const jschar *s, size_t len) : CharPtr(s, len) {}
     StableCharPtr(const jschar *pos, const jschar *start, size_t len)
       : CharPtr(pos, start, len)
     {}
 };
 
-#if defined JS_THREADSAFE && defined DEBUG
+#if defined JS_THREADSAFE && defined JS_DEBUG
 
 class JS_PUBLIC_API(AutoCheckRequestDepth)
 {
     JSContext *cx;
   public:
     AutoCheckRequestDepth(JSContext *cx);
     AutoCheckRequestDepth(js::ContextFriendFields *cx);
     ~AutoCheckRequestDepth();
@@ -66,31 +66,31 @@ class JS_PUBLIC_API(AutoCheckRequestDept
 # define CHECK_REQUEST(cx) \
     JS::AutoCheckRequestDepth _autoCheckRequestDepth(cx)
 
 #else
 
 # define CHECK_REQUEST(cx) \
     ((void) 0)
 
-#endif /* JS_THREADSAFE && DEBUG */
-
-#ifdef DEBUG
+#endif /* JS_THREADSAFE && JS_DEBUG */
+
+#ifdef JS_DEBUG
 /*
  * Assert that we're not doing GC on cx, that we're in a request as
  * needed, and that the compartments for cx and v are correct.
  * Also check that GC would be safe at this point.
  */
 JS_PUBLIC_API(void)
 AssertArgumentsAreSane(JSContext *cx, JS::Handle<JS::Value> v);
 #else
 inline void AssertArgumentsAreSane(JSContext *cx, JS::Handle<JS::Value> v) {
     /* Do nothing */
 }
-#endif /* DEBUG */
+#endif /* JS_DEBUG */
 
 class JS_PUBLIC_API(AutoGCRooter) {
   public:
     AutoGCRooter(JSContext *cx, ptrdiff_t tag);
     AutoGCRooter(js::ContextFriendFields *cx, ptrdiff_t tag);
 
     ~AutoGCRooter() {
         JS_ASSERT(this == *stackTop);
@@ -1365,32 +1365,32 @@ class JSAutoRequest
 };
 
 class JSAutoCheckRequest
 {
   public:
     JSAutoCheckRequest(JSContext *cx
                        MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
     {
-#if defined JS_THREADSAFE && defined DEBUG
+#if defined JS_THREADSAFE && defined JS_DEBUG
         mContext = cx;
         JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx)));
 #endif
         MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     }
 
     ~JSAutoCheckRequest() {
-#if defined JS_THREADSAFE && defined DEBUG
+#if defined JS_THREADSAFE && defined JS_DEBUG
         JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext)));
 #endif
     }
 
 
   private:
-#if defined JS_THREADSAFE && defined DEBUG
+#if defined JS_THREADSAFE && defined JS_DEBUG
     JSContext *mContext;
 #endif
     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
 extern JS_PUBLIC_API(void)
 JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback, void *data);
 
@@ -2028,20 +2028,20 @@ JSVAL_TO_TRACEABLE(jsval v)
 
 static JS_ALWAYS_INLINE JSGCTraceKind
 JSVAL_TRACE_KIND(jsval v)
 {
     JS_ASSERT(JSVAL_IS_GCTHING(v));
     return (JSGCTraceKind) JSVAL_TRACE_KIND_IMPL(JSVAL_TO_IMPL(v));
 }
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
 
 /*
- * DEBUG-only method to dump the object graph of heap-allocated things.
+ * Debug-only method to dump the object graph of heap-allocated things.
  *
  * fp:              file for the dump output.
  * start:           when non-null, dump only things reachable from start
  *                  thing. Otherwise dump all things reachable from the
  *                  runtime roots.
  * startKind:       trace kind of start if start is not null. Must be
  *                  JSTRACE_OBJECT when start is null.
  * thingToFind:     dump only paths in the object graph leading to thingToFind
@@ -2070,17 +2070,17 @@ JS_SetGCCallback(JSRuntime *rt, JSGCCall
 
 extern JS_PUBLIC_API(void)
 JS_SetFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb);
 
 extern JS_PUBLIC_API(bool)
 JS_IsGCMarkingTracer(JSTracer *trc);
 
 /* For assertions only. */
-#ifdef DEBUG
+#ifdef JS_DEBUG
 extern JS_PUBLIC_API(bool)
 JS_IsMarkingGray(JSTracer *trc);
 #endif
 
 /*
  * JS_IsAboutToBeFinalized checks if the given object is going to be finalized
  * at the end of the current GC. When called outside of the context of a GC,
  * this function will return false. Typically this function is used on weak
@@ -3150,23 +3150,23 @@ JS_SetReservedSlot(JSObject *obj, uint32
 struct JSPrincipals {
     /* Don't call "destroy"; use reference counting macros below. */
 #ifdef JS_THREADSAFE
     mozilla::Atomic<int32_t> refcount;
 #else
     int32_t refcount;
 #endif
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
     /* A helper to facilitate principals debugging. */
     uint32_t    debugToken;
 #endif
 
     void setDebugToken(uint32_t token) {
-# ifdef DEBUG
+# ifdef JS_DEBUG
         debugToken = token;
 # endif
     }
 
     /*
      * This is not defined by the JS engine but should be provided by the
      * embedding.
      */
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -150,17 +150,17 @@ JS_FRIEND_API(const char *)
 js_ObjectClassName(JSContext *cx, JS::HandleObject obj);
 
 JS_FRIEND_API(bool)
 js_AddObjectRoot(JSRuntime *rt, JSObject **objp);
 
 JS_FRIEND_API(void)
 js_RemoveObjectRoot(JSRuntime *rt, JSObject **objp);
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
 
 /*
  * Routines to print out values during debugging.  These are FRIEND_API to help
  * the debugger find them and to support temporarily hacking js_Dump* calls
  * into other code.
  */
 
 extern JS_FRIEND_API(void)
@@ -487,17 +487,17 @@ JS_FRIEND_API(JSObject *)
 GetObjectParentMaybeScope(JSObject *obj);
 
 JS_FRIEND_API(JSObject *)
 GetGlobalForObjectCrossCompartment(JSObject *obj);
 
 JS_FRIEND_API(void)
 AssertSameCompartment(JSContext *cx, JSObject *obj);
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
 JS_FRIEND_API(void)
 AssertSameCompartment(JSObject *objA, JSObject *objB);
 #else
 inline void AssertSameCompartment(JSObject *objA, JSObject *objB) {}
 #endif
 
 // For legacy consumers only. This whole concept is going away soon.
 JS_FRIEND_API(JSObject *)
@@ -794,17 +794,17 @@ CastToJSFreeOp(FreeOp *fop)
 
 /*
  * Get an error type name from a JSExnType constant.
  * Returns nullptr for invalid arguments and JSEXN_INTERNALERR
  */
 extern JS_FRIEND_API(const jschar*)
 GetErrorTypeName(JSRuntime* rt, int16_t exnType);
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
 extern JS_FRIEND_API(unsigned)
 GetEnterCompartmentDepth(JSContext* cx);
 #endif
 
 /* Implemented in jswrapper.cpp. */
 typedef enum NukeReferencesToWindow {
     NukeWindowReferences,
     DontNukeWindowReferences
@@ -1707,17 +1707,17 @@ class JS_FRIEND_API(AutoCTypesActivityCa
     void DoEndCallback() {
         if (callback) {
             callback(cx, endType);
             callback = nullptr;
         }
     }
 };
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
 extern JS_FRIEND_API(void)
 assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id);
 #else
 inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id) {};
 #endif
 
 typedef bool
 (* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata);
--- a/js/src/jsproxy.h
+++ b/js/src/jsproxy.h
@@ -421,17 +421,17 @@ JSObject *
 RenewProxyObject(JSContext *cx, JSObject *obj, BaseProxyHandler *handler, Value priv);
 
 class JS_FRIEND_API(AutoEnterPolicy)
 {
   public:
     typedef BaseProxyHandler::Action Action;
     AutoEnterPolicy(JSContext *cx, BaseProxyHandler *handler,
                     HandleObject wrapper, HandleId id, Action act, bool mayThrow)
-#ifdef DEBUG
+#ifdef JS_DEBUG
         : context(nullptr)
 #endif
     {
         allow = handler->hasPolicy() ? handler->enter(cx, wrapper, id, act, &rv)
                                      : true;
         recordEnter(cx, wrapper, id);
         // We want to throw an exception if all of the following are true:
         // * The policy disallowed access.
@@ -444,25 +444,25 @@ class JS_FRIEND_API(AutoEnterPolicy)
 
     virtual ~AutoEnterPolicy() { recordLeave(); }
     inline bool allowed() { return allow; }
     inline bool returnValue() { JS_ASSERT(!allowed()); return rv; }
 
   protected:
     // no-op constructor for subclass
     AutoEnterPolicy()
-#ifdef DEBUG
+#ifdef JS_DEBUG
         : context(nullptr)
 #endif
         {};
     void reportErrorIfExceptionIsNotPending(JSContext *cx, jsid id);
     bool allow;
     bool rv;
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
     JSContext *context;
     mozilla::Maybe<HandleObject> enteredProxy;
     mozilla::Maybe<HandleId> enteredId;
     // NB: We explicitly don't track the entered action here, because sometimes
     // SET traps do an implicit GET during their implementation, leading to
     // spurious assertions.
     AutoEnterPolicy *prev;
     void recordEnter(JSContext *cx, HandleObject proxy, HandleId id);
@@ -471,17 +471,17 @@ class JS_FRIEND_API(AutoEnterPolicy)
     friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id);
 #else
     inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id) {}
     inline void recordLeave() {}
 #endif
 
 };
 
-#ifdef DEBUG
+#ifdef JS_DEBUG
 class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy {
 public:
     AutoWaivePolicy(JSContext *cx, HandleObject proxy, HandleId id)
     {
         allow = true;
         recordEnter(cx, proxy, id);
     }
 };
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -15,17 +15,17 @@
 #include "mozilla/NullPtr.h"
 #include "mozilla/PodOperations.h"
 
 #include "jsprototypes.h"
 #include "jstypes.h"
 
 #include "js/TypeDecls.h"
 
-#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING) || defined(DEBUG)
+#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING) || defined(JS_DEBUG)
 # define JSGC_TRACK_EXACT_ROOTS
 #endif
 
 namespace JS {
 
 class AutoIdVector;
 class CallArgs;
 
@@ -360,17 +360,17 @@ struct ContextFriendFields
 
   public:
     explicit ContextFriendFields(JSRuntime *rt)
       : runtime_(rt), compartment_(nullptr), zone_(nullptr), autoGCRooters(nullptr)
     {
 #ifdef JSGC_TRACK_EXACT_ROOTS
         mozilla::PodArrayZero(thingGCRooters);
 #endif
-#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
+#if defined(JS_DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
         skipGCRooters = nullptr;
 #endif
     }
 
     static const ContextFriendFields *get(const JSContext *cx) {
         return reinterpret_cast<const ContextFriendFields *>(cx);
     }
 
@@ -381,17 +381,17 @@ struct ContextFriendFields
 #ifdef JSGC_TRACK_EXACT_ROOTS
     /*
      * Stack allocated GC roots for stack GC heap pointers, which may be
      * overwritten if moved during a GC.
      */
     JS::Rooted<void*> *thingGCRooters[THING_ROOT_LIMIT];
 #endif
 
-#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
+#if defined(JS_DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
     /*
      * Stack allocated list of stack locations which hold non-relocatable
      * GC heap pointers (where the target is rooted somewhere else) or integer
      * values which may be confused for GC heap pointers. These are used to
      * suppress false positives which occur when a rooting analysis treats the
      * location as holding a relocatable pointer, but have no other effect on
      * GC behavior.
      */
@@ -442,17 +442,17 @@ struct PerThreadDataFriendFields
     // Note: this type only exists to permit us to derive the offset of
     // the perThread data within the real JSRuntime* type in a portable
     // way.
     struct RuntimeDummy : JS::shadow::Runtime
     {
         struct PerThreadDummy {
             void *field1;
             uintptr_t field2;
-#ifdef DEBUG
+#ifdef JS_DEBUG
             uint64_t field3;
 #endif
         } mainThread;
     };
 
   public:
 
     PerThreadDataFriendFields();
@@ -460,17 +460,17 @@ struct PerThreadDataFriendFields
 #ifdef JSGC_TRACK_EXACT_ROOTS
     /*
      * Stack allocated GC roots for stack GC heap pointers, which may be
      * overwritten if moved during a GC.
      */
     JS::Rooted<void*> *thingGCRooters[THING_ROOT_LIMIT];
 #endif
 
-#if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
+#if defined(JS_DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
     /*
      * Stack allocated list of stack locations which hold non-relocatable
      * GC heap pointers (where the target is rooted somewhere else) or integer
      * values which may be confused for GC heap pointers. These are used to
      * suppress false positives which occur when a rooting analysis treats the
      * location as holding a relocatable pointer, but have no other effect on
      * GC behavior.
      */