Bug 948638 - Always use jsid struct types. r=Waldo
authorSean Stangl <sstangl@mozilla.com>
Tue, 10 Dec 2013 15:45:41 -0800
changeset 159808 a9acb6b5ed0f528ca9695ddcc4ed6507ea7e2a99
parent 159807 28587965e6478dd747be4a72a86f2a6a31d4ad38
child 159809 9bbd931da6d9696f2790318ae8e5e41178729c5d
push idunknown
push userunknown
push dateunknown
reviewersWaldo
bugs948638
milestone29.0a1
Bug 948638 - Always use jsid struct types. r=Waldo
js/public/Id.h
js/public/TypeDecls.h
js/src/vm/Id.cpp
--- a/js/public/Id.h
+++ b/js/public/Id.h
@@ -23,27 +23,23 @@
 #include "mozilla/NullPtr.h"
  
 #include "jstypes.h"
 
 #include "js/RootingAPI.h"
 #include "js/TypeDecls.h"
 #include "js/Utility.h"
 
-#ifdef JS_USE_JSID_STRUCT_TYPES
 struct jsid
 {
     size_t asBits;
     bool operator==(jsid rhs) const { return asBits == rhs.asBits; }
     bool operator!=(jsid rhs) const { return asBits != rhs.asBits; }
 };
-# define JSID_BITS(id) (id.asBits)
-#else
-# define JSID_BITS(id) (id)
-#endif
+#define JSID_BITS(id) (id.asBits)
 
 #define JSID_TYPE_STRING                 0x0
 #define JSID_TYPE_INT                    0x1
 #define JSID_TYPE_VOID                   0x2
 #define JSID_TYPE_OBJECT                 0x4
 #define JSID_TYPE_MASK                   0x7
 
 // Avoid using canonical 'id' for jsid parameters since this is a magic word in
@@ -147,23 +143,18 @@ JSID_IS_VOID(const jsid id)
 static JS_ALWAYS_INLINE bool
 JSID_IS_EMPTY(const jsid id)
 {
     return ((size_t)JSID_BITS(id) == JSID_TYPE_OBJECT);
 }
 
 #undef id
 
-#ifdef JS_USE_JSID_STRUCT_TYPES
 extern JS_PUBLIC_DATA(const jsid) JSID_VOID;
 extern JS_PUBLIC_DATA(const jsid) JSID_EMPTY;
-#else
-# define JSID_VOID ((jsid)JSID_TYPE_VOID)
-# define JSID_EMPTY ((jsid)JSID_TYPE_OBJECT)
-#endif
 
 extern JS_PUBLIC_DATA(const JS::Handle<jsid>) JSID_VOIDHANDLE;
 extern JS_PUBLIC_DATA(const JS::Handle<jsid>) JSID_EMPTYHANDLE;
 
 namespace js {
 
 inline bool
 IsPoisonedId(jsid iden)
--- a/js/public/TypeDecls.h
+++ b/js/public/TypeDecls.h
@@ -23,39 +23,17 @@
 #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.:
-//
-//  jsid id = ...
-//  if (id)             // error
-//    ...
-//
-//  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(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
 
 typedef char16_t jschar;
 
 namespace JS {
 
 class Value;
 template <typename T> class Handle;
 template <typename T> class MutableHandle;
--- a/js/src/vm/Id.cpp
+++ b/js/src/vm/Id.cpp
@@ -2,18 +2,16 @@
  * 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 "js/Id.h"
 #include "js/RootingAPI.h"
 
-#ifdef JS_USE_JSID_STRUCT_TYPES
 const jsid JSID_VOID  = { size_t(JSID_TYPE_VOID) };
 const jsid JSID_EMPTY = { size_t(JSID_TYPE_OBJECT) };
-#endif
 
 static const jsid voidIdValue = JSID_VOID;
 static const jsid emptyIdValue = JSID_EMPTY;
 const JS::HandleId JSID_VOIDHANDLE = JS::HandleId::fromMarkedLocation(&voidIdValue);
 const JS::HandleId JSID_EMPTYHANDLE = JS::HandleId::fromMarkedLocation(&emptyIdValue);