2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* IBM Corp.
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
** File: jstypes.h
|
|
|
|
** Description: Definitions of NSPR's basic types
|
|
|
|
**
|
|
|
|
** Prototypes and macros used to make up for deficiencies in ANSI environments
|
|
|
|
** that we have found.
|
|
|
|
**
|
|
|
|
** Since we do not wrap <stdlib.h> and all the other standard headers, authors
|
|
|
|
** of portable code will not know in general that they need these definitions.
|
|
|
|
** Instead of requiring these authors to find the dependent uses in their code
|
|
|
|
** and take the following steps only in those C files, we take steps once here
|
|
|
|
** for all C files.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef jstypes_h___
|
|
|
|
#define jstypes_h___
|
|
|
|
|
|
|
|
#include <stddef.h>
|
Bug 479258: Don't define <stdint.h> types in public headers. r=brendan
On systems that don't have <stdint.h> (i.e., Microsoft, which is
tragically underfunded and cannot spare the resources necessary to
provide and support this header: http://tinyurl.com/absoh8),
SpiderMonkey header files should not introduce definitions for these
types, as doing so may conflict with client code's attempts to provide
its own definitions for these types.
Instead, have jstypes.h define JS{Int,Uint}{8,16,32,64,Ptr} types
based on configure's results, and make jsstdint.h into an uninstalled
header for use within SpiderMonkey that does whatever is necessary to
get definitions for the <stdint.h> types.
The changes to make the appropriate SpiderMonkey .cpp files #include
"jsstdint.h" explicitly are in a separate patch, for ease of review.
2009-03-18 11:38:15 -07:00
|
|
|
#include "js-config.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
** MACROS: JS_EXTERN_API
|
|
|
|
** JS_EXPORT_API
|
|
|
|
** DESCRIPTION:
|
|
|
|
** These are only for externally visible routines and globals. For
|
|
|
|
** internal routines, just use "extern" for type checking and that
|
|
|
|
** will not export internal cross-file or forward-declared symbols.
|
|
|
|
** Define a macro for declaring procedures return types. We use this to
|
|
|
|
** deal with windoze specific type hackery for DLL definitions. Use
|
|
|
|
** JS_EXTERN_API when the prototype for the method is declared. Use
|
|
|
|
** JS_EXPORT_API for the implementation of the method.
|
|
|
|
**
|
|
|
|
** Example:
|
|
|
|
** in dowhim.h
|
|
|
|
** JS_EXTERN_API( void ) DoWhatIMean( void );
|
|
|
|
** in dowhim.c
|
|
|
|
** JS_EXPORT_API( void ) DoWhatIMean( void ) { return; }
|
|
|
|
**
|
|
|
|
**
|
|
|
|
***********************************************************************/
|
|
|
|
#ifdef WIN32
|
2008-02-09 06:19:36 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* These also work for __MWERKS__ */
|
2008-02-09 06:19:36 -08:00
|
|
|
# define JS_EXTERN_API(__type) extern __declspec(dllexport) __type
|
|
|
|
# define JS_EXPORT_API(__type) __declspec(dllexport) __type
|
|
|
|
# define JS_EXTERN_DATA(__type) extern __declspec(dllexport) __type
|
|
|
|
# define JS_EXPORT_DATA(__type) __declspec(dllexport) __type
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#elif defined(XP_OS2) && defined(__declspec)
|
|
|
|
|
2008-02-09 06:19:36 -08:00
|
|
|
# define JS_EXTERN_API(__type) extern __declspec(dllexport) __type
|
|
|
|
# define JS_EXPORT_API(__type) __declspec(dllexport) __type
|
|
|
|
# define JS_EXTERN_DATA(__type) extern __declspec(dllexport) __type
|
|
|
|
# define JS_EXPORT_DATA(__type) __declspec(dllexport) __type
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-15 23:58:02 -07:00
|
|
|
#elif defined(__SYMBIAN32__)
|
|
|
|
|
|
|
|
# define JS_EXTERN_API(__type) extern EXPORT_C __type
|
|
|
|
# define JS_EXPORT_API(__type) EXPORT_C __type
|
|
|
|
# define JS_EXTERN_DATA(__type) extern EXPORT_C __type
|
|
|
|
# define JS_EXPORT_DATA(__type) EXPORT_C __type
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#else /* Unix */
|
|
|
|
|
2008-02-09 06:19:36 -08:00
|
|
|
# ifdef HAVE_VISIBILITY_ATTRIBUTE
|
|
|
|
# define JS_EXTERNAL_VIS __attribute__((visibility ("default")))
|
2008-09-07 23:21:07 -07:00
|
|
|
# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
|
|
|
# define JS_EXTERNAL_VIS __global
|
2008-02-09 06:19:36 -08:00
|
|
|
# else
|
|
|
|
# define JS_EXTERNAL_VIS
|
|
|
|
# endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-09 06:19:36 -08:00
|
|
|
# define JS_EXTERN_API(__type) extern JS_EXTERNAL_VIS __type
|
|
|
|
# define JS_EXPORT_API(__type) JS_EXTERNAL_VIS __type
|
|
|
|
# define JS_EXTERN_DATA(__type) extern JS_EXTERNAL_VIS __type
|
|
|
|
# define JS_EXPORT_DATA(__type) JS_EXTERNAL_VIS __type
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2008-02-09 06:19:36 -08:00
|
|
|
# if defined(__MWERKS__) || defined(__GNUC__)
|
|
|
|
# define JS_IMPORT_API(__x) __x
|
|
|
|
# else
|
|
|
|
# define JS_IMPORT_API(__x) __declspec(dllimport) __x
|
|
|
|
# endif
|
2007-03-22 10:30:00 -07:00
|
|
|
#elif defined(XP_OS2) && defined(__declspec)
|
2008-02-09 06:19:36 -08:00
|
|
|
# define JS_IMPORT_API(__x) __declspec(dllimport) __x
|
2009-07-15 23:58:02 -07:00
|
|
|
#elif defined(__SYMBIAN32__)
|
|
|
|
# define JS_IMPORT_API(__x) IMPORT_C __x
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2008-02-09 06:19:36 -08:00
|
|
|
# define JS_IMPORT_API(__x) JS_EXPORT_API (__x)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__MWERKS__)
|
2008-02-09 06:19:36 -08:00
|
|
|
# define JS_IMPORT_DATA(__x) __declspec(dllimport) __x
|
2007-03-22 10:30:00 -07:00
|
|
|
#elif defined(XP_OS2) && defined(__declspec)
|
2008-02-09 06:19:36 -08:00
|
|
|
# define JS_IMPORT_DATA(__x) __declspec(dllimport) __x
|
2009-07-15 23:58:02 -07:00
|
|
|
#elif defined(__SYMBIAN32__)
|
|
|
|
# if defined(__CW32__)
|
|
|
|
# define JS_IMPORT_DATA(__x) __declspec(dllimport) __x
|
|
|
|
# else
|
|
|
|
# define JS_IMPORT_DATA(__x) IMPORT_C __x
|
|
|
|
# endif
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2008-02-09 06:19:36 -08:00
|
|
|
# define JS_IMPORT_DATA(__x) JS_EXPORT_DATA (__x)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The linkage of JS API functions differs depending on whether the file is
|
2008-02-09 06:19:36 -08:00
|
|
|
* used within the JS library or not. Any source file within the JS
|
2007-03-22 10:30:00 -07:00
|
|
|
* interpreter should define EXPORT_JS_API whereas any client of the library
|
2008-02-09 06:19:36 -08:00
|
|
|
* should not. STATIC_JS_API is used to build JS as a static library.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-02-09 06:19:36 -08:00
|
|
|
#if defined(STATIC_JS_API)
|
|
|
|
|
|
|
|
# define JS_PUBLIC_API(t) t
|
|
|
|
# define JS_PUBLIC_DATA(t) t
|
|
|
|
|
|
|
|
#elif defined(EXPORT_JS_API)
|
|
|
|
|
|
|
|
# define JS_PUBLIC_API(t) JS_EXPORT_API(t)
|
|
|
|
# define JS_PUBLIC_DATA(t) JS_EXPORT_DATA(t)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2008-02-09 06:19:36 -08:00
|
|
|
|
|
|
|
# define JS_PUBLIC_API(t) JS_IMPORT_API(t)
|
|
|
|
# define JS_PUBLIC_DATA(t) JS_IMPORT_DATA(t)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define JS_FRIEND_API(t) JS_PUBLIC_API(t)
|
|
|
|
#define JS_FRIEND_DATA(t) JS_PUBLIC_DATA(t)
|
|
|
|
|
2008-08-12 11:46:57 -07:00
|
|
|
#if defined(_MSC_VER) && defined(_M_IX86)
|
2008-08-10 00:39:18 -07:00
|
|
|
#define JS_FASTCALL __fastcall
|
2008-08-29 00:51:00 -07:00
|
|
|
#elif defined(__GNUC__) && defined(__i386__) && \
|
|
|
|
((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
|
2008-08-10 00:39:18 -07:00
|
|
|
#define JS_FASTCALL __attribute__((fastcall))
|
2008-08-12 11:46:57 -07:00
|
|
|
#else
|
|
|
|
#define JS_FASTCALL
|
2008-09-02 11:43:55 -07:00
|
|
|
#define JS_NO_FASTCALL
|
2008-09-02 12:36:23 -07:00
|
|
|
#endif
|
2008-08-10 00:39:18 -07:00
|
|
|
|
2008-07-29 10:53:03 -07:00
|
|
|
#ifndef JS_INLINE
|
|
|
|
# if defined __cplusplus
|
|
|
|
# define JS_INLINE inline
|
|
|
|
# elif defined _MSC_VER
|
|
|
|
# define JS_INLINE __inline
|
|
|
|
# elif defined __GNUC__
|
|
|
|
# define JS_INLINE __inline__
|
2008-02-13 13:50:05 -08:00
|
|
|
# else
|
2008-07-29 10:53:03 -07:00
|
|
|
# define JS_INLINE inline
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef JS_ALWAYS_INLINE
|
|
|
|
# if defined DEBUG
|
|
|
|
# define JS_ALWAYS_INLINE JS_INLINE
|
|
|
|
# elif defined _MSC_VER
|
|
|
|
# define JS_ALWAYS_INLINE __forceinline
|
|
|
|
# elif defined __GNUC__
|
2009-02-03 13:56:25 -08:00
|
|
|
# define JS_ALWAYS_INLINE __attribute__((always_inline)) JS_INLINE
|
2008-07-29 10:53:03 -07:00
|
|
|
# else
|
|
|
|
# define JS_ALWAYS_INLINE JS_INLINE
|
2008-02-13 13:50:05 -08:00
|
|
|
# endif
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2008-12-09 08:38:32 -08:00
|
|
|
#ifdef NS_STATIC_CHECKING
|
|
|
|
/*
|
|
|
|
* Attributes for static analysis. Functions declared with JS_REQUIRES_STACK
|
|
|
|
* always have a valid cx->fp and can access it freely. Other functions can
|
|
|
|
* access cx->fp only after calling a function that "forces" the stack
|
|
|
|
* (i.e. lazily instantiates it as needed).
|
|
|
|
*/
|
|
|
|
# define JS_REQUIRES_STACK __attribute__((user("JS_REQUIRES_STACK")))
|
|
|
|
# define JS_FORCES_STACK __attribute__((user("JS_FORCES_STACK")))
|
2009-06-25 12:12:19 -07:00
|
|
|
/*
|
|
|
|
* Skip the JS_REQUIRES_STACK analysis within functions with this annotation.
|
|
|
|
*/
|
|
|
|
# define JS_IGNORE_STACK __attribute__((user("JS_IGNORE_STACK")))
|
2008-12-09 08:38:32 -08:00
|
|
|
#else
|
|
|
|
# define JS_REQUIRES_STACK
|
|
|
|
# define JS_FORCES_STACK
|
2009-06-25 12:12:19 -07:00
|
|
|
# define JS_IGNORE_STACK
|
2008-12-09 08:38:32 -08:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/***********************************************************************
|
|
|
|
** MACROS: JS_BEGIN_MACRO
|
|
|
|
** JS_END_MACRO
|
|
|
|
** DESCRIPTION:
|
|
|
|
** Macro body brackets so that macros with compound statement definitions
|
|
|
|
** behave syntactically more like functions when called.
|
|
|
|
***********************************************************************/
|
|
|
|
#define JS_BEGIN_MACRO do {
|
2007-06-18 12:33:21 -07:00
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
# define JS_END_MACRO \
|
|
|
|
} __pragma(warning(push)) __pragma(warning(disable:4127)) \
|
|
|
|
while (0) __pragma(warning(pop))
|
|
|
|
#else
|
|
|
|
# define JS_END_MACRO } while (0)
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
** MACROS: JS_BEGIN_EXTERN_C
|
|
|
|
** JS_END_EXTERN_C
|
|
|
|
** DESCRIPTION:
|
|
|
|
** Macro shorthands for conditional C++ extern block delimiters.
|
|
|
|
***********************************************************************/
|
|
|
|
#ifdef __cplusplus
|
2008-02-09 06:19:36 -08:00
|
|
|
|
|
|
|
# define JS_BEGIN_EXTERN_C extern "C" {
|
|
|
|
# define JS_END_EXTERN_C }
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2008-02-09 06:19:36 -08:00
|
|
|
|
|
|
|
# define JS_BEGIN_EXTERN_C
|
|
|
|
# define JS_END_EXTERN_C
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
** MACROS: JS_BIT
|
|
|
|
** JS_BITMASK
|
|
|
|
** DESCRIPTION:
|
|
|
|
** Bit masking macros. XXX n must be <= 31 to be portable
|
|
|
|
***********************************************************************/
|
|
|
|
#define JS_BIT(n) ((JSUint32)1 << (n))
|
|
|
|
#define JS_BITMASK(n) (JS_BIT(n) - 1)
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
** MACROS: JS_PTR_TO_INT32
|
|
|
|
** JS_PTR_TO_UINT32
|
|
|
|
** JS_INT32_TO_PTR
|
|
|
|
** JS_UINT32_TO_PTR
|
|
|
|
** DESCRIPTION:
|
|
|
|
** Integer to pointer and pointer to integer conversion macros.
|
|
|
|
***********************************************************************/
|
|
|
|
#define JS_PTR_TO_INT32(x) ((jsint)((char *)(x) - (char *)0))
|
|
|
|
#define JS_PTR_TO_UINT32(x) ((jsuint)((char *)(x) - (char *)0))
|
|
|
|
#define JS_INT32_TO_PTR(x) ((void *)((char *)0 + (jsint)(x)))
|
|
|
|
#define JS_UINT32_TO_PTR(x) ((void *)((char *)0 + (jsuint)(x)))
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
** MACROS: JS_HOWMANY
|
|
|
|
** JS_ROUNDUP
|
|
|
|
** JS_MIN
|
|
|
|
** JS_MAX
|
|
|
|
** DESCRIPTION:
|
|
|
|
** Commonly used macros for operations on compatible types.
|
|
|
|
***********************************************************************/
|
|
|
|
#define JS_HOWMANY(x,y) (((x)+(y)-1)/(y))
|
|
|
|
#define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y))
|
|
|
|
#define JS_MIN(x,y) ((x)<(y)?(x):(y))
|
|
|
|
#define JS_MAX(x,y) ((x)>(y)?(x):(y))
|
|
|
|
|
2009-01-23 11:46:15 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# include "jscpucfg.h" /* We can't auto-detect MSVC configuration */
|
2009-07-15 12:31:26 -07:00
|
|
|
# if _MSC_VER < 1400
|
2009-10-15 16:04:55 -07:00
|
|
|
# define NJ_NO_VARIADIC_MACROS
|
2009-07-15 12:31:26 -07:00
|
|
|
# endif
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2009-01-23 11:46:15 -08:00
|
|
|
# include "jsautocfg.h" /* Use auto-detected configuration */
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
Bug 479258: Don't define <stdint.h> types in public headers. r=brendan
On systems that don't have <stdint.h> (i.e., Microsoft, which is
tragically underfunded and cannot spare the resources necessary to
provide and support this header: http://tinyurl.com/absoh8),
SpiderMonkey header files should not introduce definitions for these
types, as doing so may conflict with client code's attempts to provide
its own definitions for these types.
Instead, have jstypes.h define JS{Int,Uint}{8,16,32,64,Ptr} types
based on configure's results, and make jsstdint.h into an uninstalled
header for use within SpiderMonkey that does whatever is necessary to
get definitions for the <stdint.h> types.
The changes to make the appropriate SpiderMonkey .cpp files #include
"jsstdint.h" explicitly are in a separate patch, for ease of review.
2009-03-18 11:38:15 -07:00
|
|
|
#include "jsinttypes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 479258: Don't define <stdint.h> types in public headers. r=brendan
On systems that don't have <stdint.h> (i.e., Microsoft, which is
tragically underfunded and cannot spare the resources necessary to
provide and support this header: http://tinyurl.com/absoh8),
SpiderMonkey header files should not introduce definitions for these
types, as doing so may conflict with client code's attempts to provide
its own definitions for these types.
Instead, have jstypes.h define JS{Int,Uint}{8,16,32,64,Ptr} types
based on configure's results, and make jsstdint.h into an uninstalled
header for use within SpiderMonkey that does whatever is necessary to
get definitions for the <stdint.h> types.
The changes to make the appropriate SpiderMonkey .cpp files #include
"jsstdint.h" explicitly are in a separate patch, for ease of review.
2009-03-18 11:38:15 -07:00
|
|
|
JS_BEGIN_EXTERN_C
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
** TYPES: JSUintn
|
|
|
|
** JSIntn
|
|
|
|
** DESCRIPTION:
|
|
|
|
** The JSIntn types are most appropriate for automatic variables. They are
|
|
|
|
** guaranteed to be at least 16 bits, though various architectures may
|
|
|
|
** define them to be wider (e.g., 32 or even 64 bits). These types are
|
|
|
|
** never valid for fields of a structure.
|
|
|
|
************************************************************************/
|
2009-01-14 12:56:30 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
typedef int JSIntn;
|
|
|
|
typedef unsigned int JSUintn;
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
** TYPES: JSFloat64
|
|
|
|
** DESCRIPTION:
|
|
|
|
** NSPR's floating point type is always 64 bits.
|
|
|
|
************************************************************************/
|
|
|
|
typedef double JSFloat64;
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
** TYPES: JSSize
|
|
|
|
** DESCRIPTION:
|
|
|
|
** A type for representing the size of objects.
|
|
|
|
************************************************************************/
|
|
|
|
typedef size_t JSSize;
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
** TYPES: JSPtrDiff
|
|
|
|
** DESCRIPTION:
|
|
|
|
** A type for pointer difference. Variables of this type are suitable
|
|
|
|
** for storing a pointer or pointer sutraction.
|
|
|
|
************************************************************************/
|
|
|
|
typedef ptrdiff_t JSPtrdiff;
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
** TYPES: JSUptrdiff
|
|
|
|
** DESCRIPTION:
|
|
|
|
** A type for pointer difference. Variables of this type are suitable
|
|
|
|
** for storing a pointer or pointer sutraction.
|
|
|
|
************************************************************************/
|
Bug 479258: Don't define <stdint.h> types in public headers. r=brendan
On systems that don't have <stdint.h> (i.e., Microsoft, which is
tragically underfunded and cannot spare the resources necessary to
provide and support this header: http://tinyurl.com/absoh8),
SpiderMonkey header files should not introduce definitions for these
types, as doing so may conflict with client code's attempts to provide
its own definitions for these types.
Instead, have jstypes.h define JS{Int,Uint}{8,16,32,64,Ptr} types
based on configure's results, and make jsstdint.h into an uninstalled
header for use within SpiderMonkey that does whatever is necessary to
get definitions for the <stdint.h> types.
The changes to make the appropriate SpiderMonkey .cpp files #include
"jsstdint.h" explicitly are in a separate patch, for ease of review.
2009-03-18 11:38:15 -07:00
|
|
|
typedef JSUintPtr JSUptrdiff;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
** TYPES: JSBool
|
|
|
|
** DESCRIPTION:
|
|
|
|
** Use JSBool for variables and parameter types. Use JS_FALSE and JS_TRUE
|
|
|
|
** for clarity of target type in assignments and actual arguments. Use
|
|
|
|
** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
|
|
|
|
** just as you would C int-valued conditions.
|
|
|
|
************************************************************************/
|
|
|
|
typedef JSIntn JSBool;
|
|
|
|
#define JS_TRUE (JSIntn)1
|
|
|
|
#define JS_FALSE (JSIntn)0
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
** TYPES: JSPackedBool
|
|
|
|
** DESCRIPTION:
|
|
|
|
** Use JSPackedBool within structs where bitfields are not desireable
|
|
|
|
** but minimum and consistent overhead matters.
|
|
|
|
************************************************************************/
|
|
|
|
typedef JSUint8 JSPackedBool;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** A JSWord is an integer that is the same size as a void*
|
|
|
|
*/
|
Bug 479258: Don't define <stdint.h> types in public headers. r=brendan
On systems that don't have <stdint.h> (i.e., Microsoft, which is
tragically underfunded and cannot spare the resources necessary to
provide and support this header: http://tinyurl.com/absoh8),
SpiderMonkey header files should not introduce definitions for these
types, as doing so may conflict with client code's attempts to provide
its own definitions for these types.
Instead, have jstypes.h define JS{Int,Uint}{8,16,32,64,Ptr} types
based on configure's results, and make jsstdint.h into an uninstalled
header for use within SpiderMonkey that does whatever is necessary to
get definitions for the <stdint.h> types.
The changes to make the appropriate SpiderMonkey .cpp files #include
"jsstdint.h" explicitly are in a separate patch, for ease of review.
2009-03-18 11:38:15 -07:00
|
|
|
typedef JSIntPtr JSWord;
|
|
|
|
typedef JSUintPtr JSUword;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "jsotypes.h"
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
** MACROS: JS_LIKELY
|
|
|
|
** JS_UNLIKELY
|
|
|
|
** DESCRIPTION:
|
|
|
|
** These macros allow you to give a hint to the compiler about branch
|
|
|
|
** probability so that it can better optimize. Use them like this:
|
|
|
|
**
|
|
|
|
** if (JS_LIKELY(v == 1)) {
|
|
|
|
** ... expected code path ...
|
|
|
|
** }
|
|
|
|
**
|
|
|
|
** if (JS_UNLIKELY(v == 0)) {
|
|
|
|
** ... non-expected code path ...
|
|
|
|
** }
|
|
|
|
**
|
|
|
|
***********************************************************************/
|
|
|
|
#if defined(__GNUC__) && (__GNUC__ > 2)
|
2008-02-09 06:19:36 -08:00
|
|
|
|
|
|
|
# define JS_LIKELY(x) (__builtin_expect((x), 1))
|
|
|
|
# define JS_UNLIKELY(x) (__builtin_expect((x), 0))
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2008-02-09 06:19:36 -08:00
|
|
|
|
|
|
|
# define JS_LIKELY(x) (x)
|
|
|
|
# define JS_UNLIKELY(x) (x)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
** MACROS: JS_ARRAY_LENGTH
|
|
|
|
** JS_ARRAY_END
|
|
|
|
** DESCRIPTION:
|
|
|
|
** Macros to get the number of elements and the pointer to one past the
|
|
|
|
** last element of a C array. Use them like this:
|
|
|
|
**
|
|
|
|
** jschar buf[10], *s;
|
|
|
|
** JSString *str;
|
|
|
|
** ...
|
|
|
|
** for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...;
|
|
|
|
** ...
|
|
|
|
** str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf));
|
|
|
|
** ...
|
|
|
|
**
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0])
|
|
|
|
#define JS_ARRAY_END(array) ((array) + JS_ARRAY_LENGTH(array))
|
|
|
|
|
2009-01-14 12:56:30 -08:00
|
|
|
#define JS_BITS_PER_BYTE 8
|
|
|
|
#define JS_BITS_PER_BYTE_LOG2 3
|
|
|
|
|
|
|
|
#define JS_BITS_PER_WORD (JS_BITS_PER_BYTE * JS_BYTES_PER_WORD)
|
|
|
|
#define JS_BITS_PER_DOUBLE (JS_BITS_PER_BYTE * JS_BYTES_PER_DOUBLE)
|
|
|
|
|
2009-03-05 03:12:50 -08:00
|
|
|
/***********************************************************************
|
|
|
|
** 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:
|
|
|
|
**
|
|
|
|
** JSPropertyOp nativeGetter;
|
|
|
|
** JSObject *scriptedGetter;
|
|
|
|
** ...
|
|
|
|
** scriptedGetter = JS_FUNC_TO_DATA_PTR(JSObject *, nativeGetter);
|
|
|
|
** ...
|
|
|
|
** nativeGetter = JS_DATA_TO_FUNC_PTR(JSPropertyOp, scriptedGetter);
|
|
|
|
**
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
# define JS_FUNC_TO_DATA_PTR(type, fun) (__extension__ (type) (fun))
|
|
|
|
# define JS_DATA_TO_FUNC_PTR(type, ptr) (__extension__ (type) (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
|
|
|
|
|
2009-09-03 14:41:19 -07:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# define JS_EXTENSION __extension__
|
|
|
|
# define JS_EXTENSION_(s) __extension__ ({ s; })
|
|
|
|
#else
|
|
|
|
# define JS_EXTENSION
|
|
|
|
# define JS_EXTENSION_(s) s
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
|
|
|
#endif /* jstypes_h___ */
|