INT_FITS_IN_JSVAL

Obsolete since JavaScript 1.8.5
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Determines if a specified C integer is safe to pass to INT_TO_JSVAL.

Syntax

#define INT_FITS_IN_JSVAL(i)  /* ... */
Name Type Description
i jsint The C integer value to check.

Description

Determines if a specified C integer value, i, lies within the range allowed for integer jsvals. If so, INT_FITS_IN_JSVAL returns TRUE, and i can be cast to jsval by calling INT_TO_JSVAL(i). Otherwise, INT_FITS_IN_JSVAL returns FALSE. In this case, the application can still convert i to a jsval using JS_NewNumberValue.

Warning: The type of the argument i must be jsint, but the C/C++ compiler does not enforce type safety here. If i is an unsigned or 64-bit value, INT_FITS_IN_JSVAL can silently give the wrong answer.

JavaScript 1.8.5 note

Starting in SpiderMonkey 1.8.5, jsval can store a full 32-bit integer, so this check isn't needed any longer for 32-bit integers.

Example

The following code snippet illustrates how a C variable, item, is conditionally tested in an if statement to see if it is a legal jsval integer value.

if (INT_FITS_IN_JSVAL(item)) {
    /* ... */
} else {
    JS_ReportError(cx, "Integer out of range: %d", item);
}

See Also

Document Tags and Contributors

 Contributors to this page: arai, fscholz, Sheppy, Jorend, Dria, MMondor, Nickolay, Callek
 Last updated by: arai,