diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 2a6a422331d0..3450c2af8da0 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -234,15 +234,25 @@ STRING_TO_JSVAL(JSString *str) #define JSVAL_INT_MAX (JSVAL_INT_POW2(30) - 1) /* Not a function, because we have static asserts that use it */ -#define INT_FITS_IN_JSVAL(i) ((jsuint)(i) - (jsuint)JSVAL_INT_MIN <= \ +#define INT_FITS_IN_JSVAL(i) ((jsuint)(i) - (jsuint)JSVAL_INT_MIN <= \ (jsuint)(JSVAL_INT_MAX - JSVAL_INT_MIN)) -/* Not a function, because we have static asserts that use it */ -/* FIXME: Bug 506721, since that means we can't assert JSVAL_IS_INT(v) */ -#define JSVAL_TO_INT(v) ((jsint)(v) >> 1) + +static JS_ALWAYS_INLINE jsint +JSVAL_TO_INT(jsval v) +{ + JS_ASSERT(JSVAL_IS_INT(v)); + return (jsint) v >> 1; +} /* Not a function, because we have static asserts that use it */ -/* FIXME: Bug 506721, since that means we can't assert INT_FITS_IN_JSVAL(i) */ -#define INT_TO_JSVAL(i) (((jsval)(i) << 1) | JSVAL_INT) +#define INT_TO_JSVAL_CONSTEXPR(i) (((jsval)(i) << 1) | JSVAL_INT) + +static JS_ALWAYS_INLINE jsval +INT_TO_JSVAL(jsint i) +{ + JS_ASSERT(INT_FITS_IN_JSVAL(i)); + return INT_TO_JSVAL_CONSTEXPR(i); +} /* Convert between boolean and jsval, asserting that inputs are valid. */ static JS_ALWAYS_INLINE JSBool diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 75ee312bfce7..9f6d5249db63 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -623,7 +623,7 @@ args_resolve(JSContext *cx, JSObject *obj, jsval idval, uintN flags, if (str == ATOM_TO_STRING(atom)) { if (TEST_OVERRIDE_BIT(fp, ARGS_CALLEE)) return true; - v = INT_TO_JSVAL(fp->callee); + v = INT_TO_JSVAL(reinterpret_cast(fp->callee)); } else { return true; } diff --git a/js/src/jsinterp.cpp b/js/src/jsinterp.cpp index 71e4e4ba1786..1aaa1df5fc7b 100644 --- a/js/src/jsinterp.cpp +++ b/js/src/jsinterp.cpp @@ -2436,8 +2436,8 @@ js_DumpOpMeters() #define CAN_DO_FAST_INC_DEC(v) (((((v) << 1) ^ v) & 0x80000001) == 1) JS_STATIC_ASSERT(JSVAL_INT == 1); -JS_STATIC_ASSERT(!CAN_DO_FAST_INC_DEC(INT_TO_JSVAL(JSVAL_INT_MIN))); -JS_STATIC_ASSERT(!CAN_DO_FAST_INC_DEC(INT_TO_JSVAL(JSVAL_INT_MAX))); +JS_STATIC_ASSERT(!CAN_DO_FAST_INC_DEC(INT_TO_JSVAL_CONSTEXPR(JSVAL_INT_MIN))); +JS_STATIC_ASSERT(!CAN_DO_FAST_INC_DEC(INT_TO_JSVAL_CONSTEXPR(JSVAL_INT_MAX))); /* * Conditional assert to detect failure to clear a pending exception that is