Bug 712939 - Replace a bunch more JS_STATIC_ASSERTs with static_assert. r=jandem

This commit is contained in:
Jeff Walden 2014-10-30 14:28:27 -07:00
Родитель 94c702b2d7
Коммит 040244db4f
8 изменённых файлов: 37 добавлений и 62 удалений

Просмотреть файл

@ -129,8 +129,7 @@ class BitSet::Iterator
if (word_ == numWords)
return;
JS_STATIC_ASSERT(sizeof(value_) * 8 == BitSet::BitsPerWord);
index_ = word_ * sizeof(value_) * 8;
index_ = word_ * BitSet::BitsPerWord;
value_ = bits[word_];
}

Просмотреть файл

@ -490,16 +490,6 @@ exn_toSource(JSContext *cx, unsigned argc, Value *vp)
}
#endif
/* JSProto_ ordering for exceptions shall match JSEXN_ constants. */
JS_STATIC_ASSERT(JSEXN_ERR == 0);
JS_STATIC_ASSERT(JSProto_Error + JSEXN_INTERNALERR == JSProto_InternalError);
JS_STATIC_ASSERT(JSProto_Error + JSEXN_EVALERR == JSProto_EvalError);
JS_STATIC_ASSERT(JSProto_Error + JSEXN_RANGEERR == JSProto_RangeError);
JS_STATIC_ASSERT(JSProto_Error + JSEXN_REFERENCEERR == JSProto_ReferenceError);
JS_STATIC_ASSERT(JSProto_Error + JSEXN_SYNTAXERR == JSProto_SyntaxError);
JS_STATIC_ASSERT(JSProto_Error + JSEXN_TYPEERR == JSProto_TypeError);
JS_STATIC_ASSERT(JSProto_Error + JSEXN_URIERR == JSProto_URIError);
/* static */ JSObject *
ErrorObject::createProto(JSContext *cx, JSProtoKey key)
{

Просмотреть файл

@ -86,6 +86,19 @@ js_ErrorFromException(JSContext *cx, js::HandleObject obj);
extern JSObject *
js_CopyErrorObject(JSContext *cx, JS::Handle<js::ErrorObject*> errobj);
static_assert(JSEXN_ERR == 0 &&
JSProto_Error + JSEXN_INTERNALERR == JSProto_InternalError &&
JSProto_Error + JSEXN_EVALERR == JSProto_EvalError &&
JSProto_Error + JSEXN_RANGEERR == JSProto_RangeError &&
JSProto_Error + JSEXN_REFERENCEERR == JSProto_ReferenceError &&
JSProto_Error + JSEXN_SYNTAXERR == JSProto_SyntaxError &&
JSProto_Error + JSEXN_TYPEERR == JSProto_TypeError &&
JSProto_Error + JSEXN_URIERR == JSProto_URIError &&
JSEXN_URIERR + 1 == JSEXN_LIMIT,
"GetExceptionProtoKey and ExnTypeFromProtoKey require that "
"each corresponding JSExnType and JSProtoKey value be separated "
"by the same constant value");
static inline JSProtoKey
GetExceptionProtoKey(JSExnType exn)
{

Просмотреть файл

@ -542,9 +542,11 @@ num_toSource(JSContext *cx, unsigned argc, Value *vp)
}
#endif
ToCStringBuf::ToCStringBuf() :dbuf(nullptr)
ToCStringBuf::ToCStringBuf() : dbuf(nullptr)
{
JS_STATIC_ASSERT(sbufSize >= DTOSTR_STANDARD_BUFFER_SIZE);
static_assert(sbufSize >= DTOSTR_STANDARD_BUFFER_SIZE,
"builtin space must be large enough to store even the "
"longest string produced by a conversion");
}
ToCStringBuf::~ToCStringBuf()

Просмотреть файл

@ -47,13 +47,15 @@ const Class js::JSONClass = {
JS_ConvertStub
};
static inline bool IsQuoteSpecialCharacter(char16_t c)
static inline bool
IsQuoteSpecialCharacter(char16_t c)
{
JS_STATIC_ASSERT('\b' < ' ');
JS_STATIC_ASSERT('\f' < ' ');
JS_STATIC_ASSERT('\n' < ' ');
JS_STATIC_ASSERT('\r' < ' ');
JS_STATIC_ASSERT('\t' < ' ');
static_assert('\b' < ' ', "'\\b' must be treated as special below");
static_assert('\f' < ' ', "'\\f' must be treated as special below");
static_assert('\n' < ' ', "'\\n' must be treated as special below");
static_assert('\r' < ' ', "'\\r' must be treated as special below");
static_assert('\t' < ' ', "'\\t' must be treated as special below");
return c == '"' || c == '\\' || c < ' ';
}

Просмотреть файл

@ -22,6 +22,7 @@
#define jstypes_h
#include "mozilla/Attributes.h"
#include "mozilla/Casting.h"
#include "mozilla/Types.h"
// jstypes.h is (or should be!) included by every file in SpiderMonkey.
@ -194,8 +195,8 @@
** MACROS: JS_FUNC_TO_DATA_PTR
** JS_DATA_TO_FUNC_PTR
** DESCRIPTION:
** Macros to convert between function and data pointers assuming that
** they have the same size. Use them like this:
** Macros to convert between function and data pointers of the same
** size. Use them like this:
**
** JSPropertyOp nativeGetter;
** JSObject *scriptedGetter;
@ -206,14 +207,8 @@
**
***********************************************************************/
#ifdef __GNUC__
# define JS_FUNC_TO_DATA_PTR(type, fun) (__extension__ (type) (size_t) (fun))
# define JS_DATA_TO_FUNC_PTR(type, ptr) (__extension__ (type) (size_t) (ptr))
#else
/* Use an extra (void *) cast for MSVC. */
# define JS_FUNC_TO_DATA_PTR(type, fun) ((type) (void *) (fun))
# define JS_DATA_TO_FUNC_PTR(type, ptr) ((type) (void *) (ptr))
#endif
#define JS_FUNC_TO_DATA_PTR(type, fun) (mozilla::BitwiseCast<type>(fun))
#define JS_DATA_TO_FUNC_PTR(type, ptr) (mozilla::BitwiseCast<type>(ptr))
#ifdef __GNUC__
# define JS_EXTENSION __extension__

Просмотреть файл

@ -33,12 +33,6 @@ JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations = UINT32_MAX;
JS_PUBLIC_DATA(uint32_t) OOM_counter = 0;
#endif
/*
* Checks the assumption that JS_FUNC_TO_DATA_PTR and JS_DATA_TO_FUNC_PTR
* macros uses to implement casts between function and data pointers.
*/
JS_STATIC_ASSERT(sizeof(void *) == sizeof(void (*)()));
JS_PUBLIC_API(void)
JS_Assert(const char *s, const char *file, int ln)
{

Просмотреть файл

@ -50,6 +50,7 @@
using namespace js;
using mozilla::BitwiseCast;
using mozilla::IsNaN;
using mozilla::LittleEndian;
using mozilla::NativeEndian;
@ -204,7 +205,6 @@ class SCInput {
void staticAssertions() {
JS_STATIC_ASSERT(sizeof(char16_t) == 2);
JS_STATIC_ASSERT(sizeof(uint32_t) == 4);
JS_STATIC_ASSERT(sizeof(double) == 8);
}
JSContext *cx;
@ -634,38 +634,16 @@ SCOutput::writePair(uint32_t tag, uint32_t data)
return write(PairToUInt64(tag, data));
}
static inline uint64_t
ReinterpretDoubleAsUInt64(double d)
{
union {
double d;
uint64_t u;
} pun;
pun.d = d;
return pun.u;
}
static inline double
ReinterpretUInt64AsDouble(uint64_t u)
{
union {
uint64_t u;
double d;
} pun;
pun.u = u;
return pun.d;
}
static inline double
ReinterpretPairAsDouble(uint32_t tag, uint32_t data)
{
return ReinterpretUInt64AsDouble(PairToUInt64(tag, data));
return BitwiseCast<double>(PairToUInt64(tag, data));
}
bool
SCOutput::writeDouble(double d)
{
return write(ReinterpretDoubleAsUInt64(CanonicalizeNaN(d)));
return write(BitwiseCast<uint64_t>(CanonicalizeNaN(d)));
}
template <typename T>
@ -718,7 +696,9 @@ SCOutput::writeBytes(const void *p, size_t nbytes)
bool
SCOutput::writeChars(const char16_t *p, size_t nchars)
{
MOZ_ASSERT(sizeof(char16_t) == sizeof(uint16_t));
static_assert(sizeof(char16_t) == sizeof(uint16_t),
"required so that treating char16_t[] memory as uint16_t[] "
"memory is permissible");
return writeArray((const uint16_t *) p, nchars);
}