2013-04-16 13:47:10 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2013-02-01 14:24:37 -08:00
|
|
|
/* JS::Value implementation. */
|
2012-01-23 03:43:16 -08:00
|
|
|
|
2013-06-19 17:59:09 -07:00
|
|
|
#ifndef js_Value_h
|
|
|
|
#define js_Value_h
|
2011-09-19 09:34:49 -07:00
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/FloatingPoint.h"
|
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
|
|
|
|
#include <limits> /* for std::numeric_limits */
|
|
|
|
|
2013-10-11 12:11:48 -07:00
|
|
|
#include "jstypes.h"
|
|
|
|
|
2013-02-01 15:31:00 -08:00
|
|
|
#include "js/Anchor.h"
|
2013-03-12 14:05:57 -07:00
|
|
|
#include "js/RootingAPI.h"
|
2012-01-23 03:43:16 -08:00
|
|
|
#include "js/Utility.h"
|
2011-09-19 09:34:49 -07:00
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
namespace JS { class Value; }
|
|
|
|
|
|
|
|
/* JS::Value can store a full int32_t. */
|
|
|
|
#define JSVAL_INT_BITS 32
|
|
|
|
#define JSVAL_INT_MIN ((int32_t)0x80000000)
|
|
|
|
#define JSVAL_INT_MAX ((int32_t)0x7fffffff)
|
|
|
|
|
2010-06-30 17:52:02 -07:00
|
|
|
/*
|
|
|
|
* Try to get jsvals 64-bit aligned. We could almost assert that all values are
|
|
|
|
* aligned, but MSVC and GCC occasionally break alignment.
|
|
|
|
*/
|
2011-03-22 14:19:10 -07:00
|
|
|
#if defined(__GNUC__) || defined(__xlc__) || defined(__xlC__)
|
2010-06-30 17:52:02 -07:00
|
|
|
# define JSVAL_ALIGNMENT __attribute__((aligned (8)))
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
/*
|
|
|
|
* Structs can be aligned with MSVC, but not if they are used as parameters,
|
|
|
|
* so we just don't try to align.
|
|
|
|
*/
|
|
|
|
# define JSVAL_ALIGNMENT
|
2010-07-05 21:14:58 -07:00
|
|
|
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
|
|
|
# define JSVAL_ALIGNMENT
|
2011-03-22 14:19:10 -07:00
|
|
|
#elif defined(__HP_cc) || defined(__HP_aCC)
|
|
|
|
# define JSVAL_ALIGNMENT
|
2010-06-30 17:52:02 -07:00
|
|
|
#endif
|
|
|
|
|
2010-07-21 18:57:01 -07:00
|
|
|
#if JS_BITS_PER_WORD == 64
|
|
|
|
# define JSVAL_TAG_SHIFT 47
|
|
|
|
#endif
|
|
|
|
|
2010-06-30 17:52:02 -07:00
|
|
|
/*
|
|
|
|
* We try to use enums so that printing a jsval_layout in the debugger shows
|
|
|
|
* nice symbolic type tags, however we can only do this when we can force the
|
|
|
|
* underlying type of the enum to be the desired size.
|
|
|
|
*/
|
2013-06-26 18:35:11 -07:00
|
|
|
#if !defined(__SUNPRO_CC) && !defined(__xlC__)
|
2010-06-30 17:52:02 -07:00
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
# define JS_ENUM_HEADER(id, type) enum id : type
|
|
|
|
# define JS_ENUM_FOOTER(id)
|
|
|
|
#else
|
|
|
|
# define JS_ENUM_HEADER(id, type) enum id
|
|
|
|
# define JS_ENUM_FOOTER(id) __attribute__((packed))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Remember to propagate changes to the C defines below. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JS_ENUM_HEADER(JSValueType, uint8_t)
|
2010-06-30 17:52:02 -07:00
|
|
|
{
|
|
|
|
JSVAL_TYPE_DOUBLE = 0x00,
|
|
|
|
JSVAL_TYPE_INT32 = 0x01,
|
|
|
|
JSVAL_TYPE_UNDEFINED = 0x02,
|
|
|
|
JSVAL_TYPE_BOOLEAN = 0x03,
|
|
|
|
JSVAL_TYPE_MAGIC = 0x04,
|
|
|
|
JSVAL_TYPE_STRING = 0x05,
|
|
|
|
JSVAL_TYPE_NULL = 0x06,
|
|
|
|
JSVAL_TYPE_OBJECT = 0x07,
|
|
|
|
|
2012-01-18 16:40:18 -08:00
|
|
|
/* These never appear in a jsval; they are only provided as an out-of-band value. */
|
|
|
|
JSVAL_TYPE_UNKNOWN = 0x20,
|
|
|
|
JSVAL_TYPE_MISSING = 0x21
|
2010-06-30 17:52:02 -07:00
|
|
|
} JS_ENUM_FOOTER(JSValueType);
|
|
|
|
|
2010-07-16 14:00:41 -07:00
|
|
|
JS_STATIC_ASSERT(sizeof(JSValueType) == 1);
|
|
|
|
|
2010-06-30 17:52:02 -07:00
|
|
|
#if JS_BITS_PER_WORD == 32
|
|
|
|
|
|
|
|
/* Remember to propagate changes to the C defines below. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JS_ENUM_HEADER(JSValueTag, uint32_t)
|
2010-06-30 17:52:02 -07:00
|
|
|
{
|
2011-07-29 16:24:30 -07:00
|
|
|
JSVAL_TAG_CLEAR = 0xFFFFFF80,
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32,
|
|
|
|
JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED,
|
|
|
|
JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING,
|
|
|
|
JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN,
|
|
|
|
JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC,
|
|
|
|
JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL,
|
|
|
|
JSVAL_TAG_OBJECT = JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT
|
2010-07-23 17:16:00 -07:00
|
|
|
} JS_ENUM_FOOTER(JSValueTag);
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2010-07-16 14:00:41 -07:00
|
|
|
JS_STATIC_ASSERT(sizeof(JSValueTag) == 4);
|
|
|
|
|
2010-06-30 17:52:02 -07:00
|
|
|
#elif JS_BITS_PER_WORD == 64
|
|
|
|
|
|
|
|
/* Remember to propagate changes to the C defines below. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JS_ENUM_HEADER(JSValueTag, uint32_t)
|
2010-06-30 17:52:02 -07:00
|
|
|
{
|
|
|
|
JSVAL_TAG_MAX_DOUBLE = 0x1FFF0,
|
|
|
|
JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32,
|
|
|
|
JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED,
|
|
|
|
JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING,
|
|
|
|
JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN,
|
|
|
|
JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC,
|
|
|
|
JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL,
|
|
|
|
JSVAL_TAG_OBJECT = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT
|
2010-07-21 18:57:01 -07:00
|
|
|
} JS_ENUM_FOOTER(JSValueTag);
|
2010-06-30 17:52:02 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JS_STATIC_ASSERT(sizeof(JSValueTag) == sizeof(uint32_t));
|
2010-07-21 18:57:01 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JS_ENUM_HEADER(JSValueShiftedTag, uint64_t)
|
2010-07-21 18:57:01 -07:00
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSVAL_SHIFTED_TAG_MAX_DOUBLE = ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF),
|
|
|
|
JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT),
|
|
|
|
JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT),
|
|
|
|
JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT),
|
|
|
|
JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT),
|
|
|
|
JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT),
|
|
|
|
JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT),
|
|
|
|
JSVAL_SHIFTED_TAG_OBJECT = (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT)
|
2010-07-21 18:57:01 -07:00
|
|
|
} JS_ENUM_FOOTER(JSValueShiftedTag);
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JS_STATIC_ASSERT(sizeof(JSValueShiftedTag) == sizeof(uint64_t));
|
2010-07-16 14:00:41 -07:00
|
|
|
|
2010-06-30 17:52:02 -07:00
|
|
|
#endif
|
|
|
|
|
2013-06-26 18:35:11 -07:00
|
|
|
#else /* !defined(__SUNPRO_CC) && !defined(__xlC__) */
|
2010-06-30 17:52:02 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
typedef uint8_t JSValueType;
|
|
|
|
#define JSVAL_TYPE_DOUBLE ((uint8_t)0x00)
|
|
|
|
#define JSVAL_TYPE_INT32 ((uint8_t)0x01)
|
|
|
|
#define JSVAL_TYPE_UNDEFINED ((uint8_t)0x02)
|
|
|
|
#define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03)
|
|
|
|
#define JSVAL_TYPE_MAGIC ((uint8_t)0x04)
|
|
|
|
#define JSVAL_TYPE_STRING ((uint8_t)0x05)
|
|
|
|
#define JSVAL_TYPE_NULL ((uint8_t)0x06)
|
|
|
|
#define JSVAL_TYPE_OBJECT ((uint8_t)0x07)
|
|
|
|
#define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20)
|
2010-06-30 17:52:02 -07:00
|
|
|
|
|
|
|
#if JS_BITS_PER_WORD == 32
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
typedef uint32_t JSValueTag;
|
|
|
|
#define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80))
|
|
|
|
#define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32))
|
|
|
|
#define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED))
|
|
|
|
#define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING))
|
|
|
|
#define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN))
|
|
|
|
#define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC))
|
|
|
|
#define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL))
|
|
|
|
#define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT))
|
2010-06-30 17:52:02 -07:00
|
|
|
|
|
|
|
#elif JS_BITS_PER_WORD == 64
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
typedef uint32_t JSValueTag;
|
|
|
|
#define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0))
|
|
|
|
#define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32)
|
|
|
|
#define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED)
|
|
|
|
#define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING)
|
|
|
|
#define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN)
|
|
|
|
#define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC)
|
|
|
|
#define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL)
|
|
|
|
#define JSVAL_TAG_OBJECT (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT)
|
|
|
|
|
|
|
|
typedef uint64_t JSValueShiftedTag;
|
|
|
|
#define JSVAL_SHIFTED_TAG_MAX_DOUBLE ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF)
|
|
|
|
#define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT)
|
|
|
|
#define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT)
|
|
|
|
#define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT)
|
|
|
|
#define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT)
|
|
|
|
#define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT)
|
|
|
|
#define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT)
|
|
|
|
#define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT)
|
2010-07-21 18:57:01 -07:00
|
|
|
|
2010-06-30 17:52:02 -07:00
|
|
|
#endif /* JS_BITS_PER_WORD */
|
2013-06-26 18:35:11 -07:00
|
|
|
#endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */
|
2010-06-30 17:52:02 -07:00
|
|
|
|
|
|
|
#define JSVAL_LOWER_INCL_TYPE_OF_OBJ_OR_NULL_SET JSVAL_TYPE_NULL
|
|
|
|
#define JSVAL_UPPER_EXCL_TYPE_OF_PRIMITIVE_SET JSVAL_TYPE_OBJECT
|
|
|
|
#define JSVAL_UPPER_INCL_TYPE_OF_NUMBER_SET JSVAL_TYPE_INT32
|
2010-08-16 12:35:04 -07:00
|
|
|
#define JSVAL_LOWER_INCL_TYPE_OF_PTR_PAYLOAD_SET JSVAL_TYPE_MAGIC
|
2010-06-30 17:52:02 -07:00
|
|
|
|
|
|
|
#if JS_BITS_PER_WORD == 32
|
|
|
|
|
|
|
|
#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type)))
|
|
|
|
|
|
|
|
#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL
|
|
|
|
#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT
|
|
|
|
#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32
|
|
|
|
#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING
|
|
|
|
|
|
|
|
#elif JS_BITS_PER_WORD == 64
|
|
|
|
|
|
|
|
#define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL
|
2010-07-21 18:57:01 -07:00
|
|
|
#define JSVAL_TAG_MASK 0xFFFF800000000000LL
|
2010-06-30 17:52:02 -07:00
|
|
|
#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_MAX_DOUBLE | (type)))
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
#define JSVAL_TYPE_TO_SHIFTED_TAG(type) (((uint64_t)JSVAL_TYPE_TO_TAG(type)) << JSVAL_TAG_SHIFT)
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2011-11-18 14:46:30 -08:00
|
|
|
#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL
|
|
|
|
#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT
|
|
|
|
#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32
|
|
|
|
#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING
|
|
|
|
|
2010-06-30 17:52:02 -07:00
|
|
|
#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_OBJ_OR_NULL_SET JSVAL_SHIFTED_TAG_NULL
|
|
|
|
#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET JSVAL_SHIFTED_TAG_OBJECT
|
|
|
|
#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED
|
|
|
|
#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING
|
|
|
|
|
|
|
|
#endif /* JS_BITS_PER_WORD */
|
|
|
|
|
|
|
|
typedef enum JSWhyMagic
|
|
|
|
{
|
2013-01-10 16:53:11 -08:00
|
|
|
JS_ELEMENTS_HOLE, /* a hole in a native object's elements */
|
2010-06-30 17:52:02 -07:00
|
|
|
JS_NATIVE_ENUMERATE, /* indicates that a custom enumerate hook forwarded
|
2011-10-04 07:06:54 -07:00
|
|
|
* to JS_EnumerateState, which really means the object can be
|
2010-06-30 17:52:02 -07:00
|
|
|
* enumerated like a native object. */
|
|
|
|
JS_NO_ITER_VALUE, /* there is not a pending iterator value */
|
|
|
|
JS_GENERATOR_CLOSING, /* exception value thrown when closing a generator */
|
2010-07-04 00:12:06 -07:00
|
|
|
JS_NO_CONSTANT, /* compiler sentinel value */
|
|
|
|
JS_THIS_POISON, /* used in debug builds to catch tracing errors */
|
2010-08-09 22:43:33 -07:00
|
|
|
JS_ARG_POISON, /* used in debug builds to catch tracing errors */
|
2010-06-15 13:32:32 -07:00
|
|
|
JS_SERIALIZE_NO_NODE, /* an empty subnode in the AST serializer */
|
2011-05-26 12:28:19 -07:00
|
|
|
JS_LAZY_ARGUMENTS, /* lazy arguments value on the stack */
|
2012-01-17 16:35:12 -08:00
|
|
|
JS_OPTIMIZED_ARGUMENTS, /* optimized-away 'arguments' value */
|
2012-01-02 16:01:34 -08:00
|
|
|
JS_IS_CONSTRUCTING, /* magic value passed to natives to indicate construction */
|
2012-03-21 16:19:06 -07:00
|
|
|
JS_OVERWRITTEN_CALLEE, /* arguments.callee has been overwritten */
|
2012-02-23 13:59:10 -08:00
|
|
|
JS_BLOCK_NEEDS_CLONE, /* value of static block object slot */
|
2012-07-03 14:33:38 -07:00
|
|
|
JS_HASH_KEY_EMPTY, /* see class js::HashableValue */
|
2011-11-11 17:10:39 -08:00
|
|
|
JS_ION_ERROR, /* error while running Ion code */
|
2014-04-29 10:17:51 -07:00
|
|
|
JS_ION_BAILOUT, /* missing recover instruction result */
|
2014-04-24 01:59:36 -07:00
|
|
|
JS_OPTIMIZED_OUT, /* optimized out slot */
|
2010-07-04 00:12:06 -07:00
|
|
|
JS_GENERIC_MAGIC /* for local use */
|
2010-06-30 17:52:02 -07:00
|
|
|
} JSWhyMagic;
|
|
|
|
|
2010-06-30 18:23:30 -07:00
|
|
|
#if defined(IS_LITTLE_ENDIAN)
|
2010-07-01 13:06:36 -07:00
|
|
|
# if JS_BITS_PER_WORD == 32
|
2010-06-30 17:52:02 -07:00
|
|
|
typedef union jsval_layout
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t asBits;
|
2010-06-30 17:52:02 -07:00
|
|
|
struct {
|
|
|
|
union {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
int32_t i32;
|
|
|
|
uint32_t u32;
|
2013-08-08 15:53:04 -07:00
|
|
|
uint32_t boo; // Don't use |bool| -- it must be four bytes.
|
2010-06-30 17:52:02 -07:00
|
|
|
JSString *str;
|
|
|
|
JSObject *obj;
|
|
|
|
void *ptr;
|
|
|
|
JSWhyMagic why;
|
2011-09-19 09:34:49 -07:00
|
|
|
size_t word;
|
2012-05-21 23:45:13 -07:00
|
|
|
uintptr_t uintptr;
|
2010-06-30 17:52:02 -07:00
|
|
|
} payload;
|
|
|
|
JSValueTag tag;
|
|
|
|
} s;
|
|
|
|
double asDouble;
|
2010-09-10 17:06:30 -07:00
|
|
|
void *asPtr;
|
2012-01-14 20:39:32 -08:00
|
|
|
} JSVAL_ALIGNMENT jsval_layout;
|
2010-07-01 13:06:36 -07:00
|
|
|
# elif JS_BITS_PER_WORD == 64
|
2010-06-30 17:52:02 -07:00
|
|
|
typedef union jsval_layout
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t asBits;
|
2013-06-26 18:35:11 -07:00
|
|
|
#if !defined(_WIN64)
|
2010-07-24 09:10:31 -07:00
|
|
|
/* MSVC does not pack these correctly :-( */
|
2010-06-30 17:52:02 -07:00
|
|
|
struct {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t payload47 : 47;
|
2010-06-30 17:52:02 -07:00
|
|
|
JSValueTag tag : 17;
|
|
|
|
} debugView;
|
2010-07-24 09:10:31 -07:00
|
|
|
#endif
|
2010-06-30 17:52:02 -07:00
|
|
|
struct {
|
|
|
|
union {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
int32_t i32;
|
|
|
|
uint32_t u32;
|
2010-06-30 17:52:02 -07:00
|
|
|
JSWhyMagic why;
|
|
|
|
} payload;
|
|
|
|
} s;
|
|
|
|
double asDouble;
|
2010-09-10 17:06:30 -07:00
|
|
|
void *asPtr;
|
2011-09-19 09:34:49 -07:00
|
|
|
size_t asWord;
|
2012-05-21 23:45:13 -07:00
|
|
|
uintptr_t asUIntPtr;
|
2012-01-14 20:39:32 -08:00
|
|
|
} JSVAL_ALIGNMENT jsval_layout;
|
2010-07-01 13:06:36 -07:00
|
|
|
# endif /* JS_BITS_PER_WORD */
|
|
|
|
#else /* defined(IS_LITTLE_ENDIAN) */
|
|
|
|
# if JS_BITS_PER_WORD == 32
|
|
|
|
typedef union jsval_layout
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t asBits;
|
2010-07-01 13:06:36 -07:00
|
|
|
struct {
|
|
|
|
JSValueTag tag;
|
|
|
|
union {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
int32_t i32;
|
|
|
|
uint32_t u32;
|
2013-08-08 15:53:04 -07:00
|
|
|
uint32_t boo; // Don't use |bool| -- it must be four bytes.
|
2010-07-01 13:06:36 -07:00
|
|
|
JSString *str;
|
|
|
|
JSObject *obj;
|
|
|
|
void *ptr;
|
|
|
|
JSWhyMagic why;
|
2011-09-19 09:34:49 -07:00
|
|
|
size_t word;
|
2012-05-21 23:45:13 -07:00
|
|
|
uintptr_t uintptr;
|
2010-07-01 13:06:36 -07:00
|
|
|
} payload;
|
|
|
|
} s;
|
|
|
|
double asDouble;
|
2010-09-10 21:20:46 -07:00
|
|
|
void *asPtr;
|
2012-01-14 20:39:32 -08:00
|
|
|
} JSVAL_ALIGNMENT jsval_layout;
|
2011-01-03 09:16:16 -08:00
|
|
|
# elif JS_BITS_PER_WORD == 64
|
|
|
|
typedef union jsval_layout
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t asBits;
|
2011-01-03 09:16:16 -08:00
|
|
|
struct {
|
|
|
|
JSValueTag tag : 17;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t payload47 : 47;
|
2011-01-03 09:16:16 -08:00
|
|
|
} debugView;
|
|
|
|
struct {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t padding;
|
2011-01-03 09:16:16 -08:00
|
|
|
union {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
int32_t i32;
|
|
|
|
uint32_t u32;
|
2011-01-03 09:16:16 -08:00
|
|
|
JSWhyMagic why;
|
|
|
|
} payload;
|
|
|
|
} s;
|
|
|
|
double asDouble;
|
|
|
|
void *asPtr;
|
2011-09-19 09:34:49 -07:00
|
|
|
size_t asWord;
|
2012-05-21 23:45:13 -07:00
|
|
|
uintptr_t asUIntPtr;
|
2012-01-14 20:39:32 -08:00
|
|
|
} JSVAL_ALIGNMENT jsval_layout;
|
2010-07-01 13:06:36 -07:00
|
|
|
# endif /* JS_BITS_PER_WORD */
|
|
|
|
#endif /* defined(IS_LITTLE_ENDIAN) */
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2011-08-04 14:49:35 -07:00
|
|
|
JS_STATIC_ASSERT(sizeof(jsval_layout) == 8);
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
/*
|
|
|
|
* For codesize purposes on some platforms, it's important that the
|
|
|
|
* compiler know that JS::Values constructed from constant values can be
|
|
|
|
* folded to constant bit patterns at compile time, rather than
|
|
|
|
* constructed at runtime. Doing this requires a fair amount of C++11
|
|
|
|
* features, which are not supported on all of our compilers. Set up
|
|
|
|
* some defines and helper macros in an attempt to confine the ugliness
|
|
|
|
* here, rather than scattering it all about the file. The important
|
|
|
|
* features are:
|
|
|
|
*
|
|
|
|
* - constexpr;
|
|
|
|
* - defaulted functions;
|
|
|
|
* - C99-style designated initializers.
|
|
|
|
*/
|
|
|
|
#if defined(__clang__)
|
|
|
|
# if __has_feature(cxx_constexpr) && __has_feature(cxx_defaulted_functions)
|
|
|
|
# define JS_VALUE_IS_CONSTEXPR
|
|
|
|
# endif
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
/*
|
|
|
|
* We need 4.5 for defaulted functions, 4.6 for constexpr, 4.7 because 4.6
|
|
|
|
* doesn't understand |(X) { .field = ... }| syntax, and 4.7.3 because
|
|
|
|
* versions prior to that have bugs in the C++ front-end that cause crashes.
|
|
|
|
*/
|
|
|
|
# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 3)
|
|
|
|
# define JS_VALUE_IS_CONSTEXPR
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(JS_VALUE_IS_CONSTEXPR)
|
|
|
|
# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \
|
|
|
|
return (jsval_layout) { .asBits = (BITS) }
|
|
|
|
# define JS_VALUE_CONSTEXPR MOZ_CONSTEXPR
|
|
|
|
# define JS_VALUE_CONSTEXPR_VAR MOZ_CONSTEXPR_VAR
|
|
|
|
#else
|
|
|
|
# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \
|
|
|
|
jsval_layout l; \
|
|
|
|
l.asBits = (BITS); \
|
|
|
|
return l;
|
|
|
|
# define JS_VALUE_CONSTEXPR
|
|
|
|
# define JS_VALUE_CONSTEXPR_VAR const
|
|
|
|
#endif
|
|
|
|
|
2010-06-30 17:52:02 -07:00
|
|
|
#if JS_BITS_PER_WORD == 32
|
|
|
|
|
2010-07-16 14:00:41 -07:00
|
|
|
/*
|
|
|
|
* N.B. GCC, in some but not all cases, chooses to emit signed comparison of
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
* JSValueTag even though its underlying type has been forced to be uint32_t.
|
|
|
|
* Thus, all comparisons should explicitly cast operands to uint32_t.
|
2010-07-16 14:00:41 -07:00
|
|
|
*/
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR jsval_layout
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
BUILD_JSVAL(JSValueTag tag, uint32_t payload)
|
2011-09-19 09:34:49 -07:00
|
|
|
{
|
2013-07-29 13:59:34 -07:00
|
|
|
JS_RETURN_LAYOUT_FROM_BITS((((uint64_t)(uint32_t)tag) << 32) | payload);
|
2011-09-19 09:34:49 -07:00
|
|
|
}
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_DOUBLE_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return (uint32_t)l.s.tag <= (uint32_t)JSVAL_TAG_CLEAR;
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2010-06-30 17:52:02 -07:00
|
|
|
DOUBLE_TO_JSVAL_IMPL(double d)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
|
|
|
l.asDouble = d;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l));
|
2010-06-30 17:52:02 -07:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_INT32_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.tag == JSVAL_TAG_INT32;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline int32_t
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_INT32_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.payload.i32;
|
|
|
|
}
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR jsval_layout
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
INT32_TO_JSVAL_IMPL(int32_t i)
|
2010-06-30 17:52:02 -07:00
|
|
|
{
|
2013-07-29 13:59:34 -07:00
|
|
|
#if defined(JS_VALUE_IS_CONSTEXPR)
|
|
|
|
return BUILD_JSVAL(JSVAL_TAG_INT32, i);
|
|
|
|
#else
|
2010-06-30 17:52:02 -07:00
|
|
|
jsval_layout l;
|
|
|
|
l.s.tag = JSVAL_TAG_INT32;
|
|
|
|
l.s.payload.i32 = i;
|
|
|
|
return l;
|
2013-07-29 13:59:34 -07:00
|
|
|
#endif
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_NUMBER_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
JSValueTag tag = l.s.tag;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT(tag != JSVAL_TAG_CLEAR);
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return (uint32_t)tag <= (uint32_t)JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET;
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_UNDEFINED_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.tag == JSVAL_TAG_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_STRING_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.tag == JSVAL_TAG_STRING;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2010-06-30 17:52:02 -07:00
|
|
|
STRING_TO_JSVAL_IMPL(JSString *str)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
2014-01-16 03:06:31 -08:00
|
|
|
MOZ_ASSERT(uintptr_t(str) > 0x1000);
|
2010-06-30 17:52:02 -07:00
|
|
|
l.s.tag = JSVAL_TAG_STRING;
|
|
|
|
l.s.payload.str = str;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline JSString *
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_STRING_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.payload.str;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_BOOLEAN_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.tag == JSVAL_TAG_BOOLEAN;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_BOOLEAN_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.payload.boo;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2013-08-08 15:53:04 -07:00
|
|
|
BOOLEAN_TO_JSVAL_IMPL(bool b)
|
2010-06-30 17:52:02 -07:00
|
|
|
{
|
|
|
|
jsval_layout l;
|
|
|
|
l.s.tag = JSVAL_TAG_BOOLEAN;
|
|
|
|
l.s.payload.boo = b;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-08-16 12:35:04 -07:00
|
|
|
JSVAL_IS_MAGIC_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.tag == JSVAL_TAG_MAGIC;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_OBJECT_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.tag == JSVAL_TAG_OBJECT;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return (uint32_t)l.s.tag < (uint32_t)JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET;
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l)
|
|
|
|
{
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT((uint32_t)l.s.tag <= (uint32_t)JSVAL_TAG_OBJECT);
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET;
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline JSObject *
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_OBJECT_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.payload.obj;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2010-06-30 17:52:02 -07:00
|
|
|
OBJECT_TO_JSVAL_IMPL(JSObject *obj)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
2014-01-16 03:06:31 -08:00
|
|
|
MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42);
|
2010-06-30 17:52:02 -07:00
|
|
|
l.s.tag = JSVAL_TAG_OBJECT;
|
|
|
|
l.s.payload.obj = obj;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_NULL_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.tag == JSVAL_TAG_NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2010-06-30 17:52:02 -07:00
|
|
|
PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT(((uint32_t)ptr & 1) == 0);
|
2010-06-30 17:52:02 -07:00
|
|
|
l.s.tag = (JSValueTag)0;
|
|
|
|
l.s.payload.ptr = ptr;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l));
|
2010-06-30 17:52:02 -07:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline void *
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.payload.ptr;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_GCTHING_IMPL(jsval_layout l)
|
|
|
|
{
|
2010-07-16 14:00:41 -07:00
|
|
|
/* gcc sometimes generates signed < without explicit casts. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return (uint32_t)l.s.tag >= (uint32_t)JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET;
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline void *
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_GCTHING_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.payload.ptr;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_TRACEABLE_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.s.tag == JSVAL_TAG_STRING || l.s.tag == JSVAL_TAG_OBJECT;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline uint32_t
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TRACE_KIND_IMPL(jsval_layout l)
|
|
|
|
{
|
2013-08-08 15:53:04 -07:00
|
|
|
return (uint32_t)(bool)JSVAL_IS_STRING_IMPL(l);
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32)
|
2011-09-19 09:34:49 -07:00
|
|
|
{
|
|
|
|
return l.s.tag == JSVAL_TAG_INT32 && l.s.payload.i32 == i32;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2014-04-28 16:55:40 -07:00
|
|
|
JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b)
|
2011-09-19 09:34:49 -07:00
|
|
|
{
|
2013-08-08 15:53:04 -07:00
|
|
|
return (l.s.tag == JSVAL_TAG_BOOLEAN) && (l.s.payload.boo == uint32_t(b));
|
2011-09-19 09:34:49 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2011-09-19 09:34:49 -07:00
|
|
|
MAGIC_TO_JSVAL_IMPL(JSWhyMagic why)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
|
|
|
l.s.tag = JSVAL_TAG_MAGIC;
|
|
|
|
l.s.payload.why = why;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2014-03-05 12:49:36 -08:00
|
|
|
static inline jsval_layout
|
|
|
|
MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
|
|
|
l.s.tag = JSVAL_TAG_MAGIC;
|
|
|
|
l.s.payload.u32 = payload;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2011-09-19 09:34:49 -07:00
|
|
|
JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs)
|
|
|
|
{
|
|
|
|
JSValueTag ltag = lhs.s.tag, rtag = rhs.s.tag;
|
|
|
|
return ltag == rtag || (ltag < JSVAL_TAG_CLEAR && rtag < JSVAL_TAG_CLEAR);
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline JSValueType
|
2011-09-19 09:34:49 -07:00
|
|
|
JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t type = l.s.tag & 0xF;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT(type > JSVAL_TYPE_DOUBLE);
|
2011-09-19 09:34:49 -07:00
|
|
|
return (JSValueType)type;
|
|
|
|
}
|
|
|
|
|
2010-06-30 17:52:02 -07:00
|
|
|
#elif JS_BITS_PER_WORD == 64
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR jsval_layout
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
BUILD_JSVAL(JSValueTag tag, uint64_t payload)
|
2011-09-19 09:34:49 -07:00
|
|
|
{
|
2013-07-29 13:59:34 -07:00
|
|
|
JS_RETURN_LAYOUT_FROM_BITS((((uint64_t)(uint32_t)tag) << JSVAL_TAG_SHIFT) | payload);
|
2011-09-19 09:34:49 -07:00
|
|
|
}
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_DOUBLE_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2010-06-30 17:52:02 -07:00
|
|
|
DOUBLE_TO_JSVAL_IMPL(double d)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
|
|
|
l.asDouble = d;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT(l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE);
|
2010-06-30 17:52:02 -07:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_INT32_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_INT32;
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline int32_t
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_INT32_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return (int32_t)l.asBits;
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR jsval_layout
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
INT32_TO_JSVAL_IMPL(int32_t i32)
|
2010-06-30 17:52:02 -07:00
|
|
|
{
|
2013-07-29 13:59:34 -07:00
|
|
|
JS_RETURN_LAYOUT_FROM_BITS(((uint64_t)(uint32_t)i32) | JSVAL_SHIFTED_TAG_INT32);
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_NUMBER_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.asBits < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_UNDEFINED_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.asBits == JSVAL_SHIFTED_TAG_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_STRING_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_STRING;
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2010-06-30 17:52:02 -07:00
|
|
|
STRING_TO_JSVAL_IMPL(JSString *str)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t strBits = (uint64_t)str;
|
2014-01-16 03:06:31 -08:00
|
|
|
MOZ_ASSERT(uintptr_t(str) > 0x1000);
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT((strBits >> JSVAL_TAG_SHIFT) == 0);
|
2010-06-30 17:52:02 -07:00
|
|
|
l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline JSString *
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_STRING_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return (JSString *)(l.asBits & JSVAL_PAYLOAD_MASK);
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_BOOLEAN_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return (uint32_t)(l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_BOOLEAN;
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_BOOLEAN_IMPL(jsval_layout l)
|
|
|
|
{
|
2013-08-08 15:53:04 -07:00
|
|
|
return (bool)(l.asBits & JSVAL_PAYLOAD_MASK);
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2013-08-08 15:53:04 -07:00
|
|
|
BOOLEAN_TO_JSVAL_IMPL(bool b)
|
2010-06-30 17:52:02 -07:00
|
|
|
{
|
|
|
|
jsval_layout l;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
l.asBits = ((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN;
|
2010-06-30 17:52:02 -07:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-08-16 12:35:04 -07:00
|
|
|
JSVAL_IS_MAGIC_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return (l.asBits >> JSVAL_TAG_SHIFT) == JSVAL_TAG_MAGIC;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.asBits < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_OBJECT_IMPL(jsval_layout l)
|
|
|
|
{
|
2014-03-27 13:05:13 -07:00
|
|
|
MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT);
|
2010-06-30 17:52:02 -07:00
|
|
|
return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l)
|
|
|
|
{
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT((l.asBits >> JSVAL_TAG_SHIFT) <= JSVAL_TAG_OBJECT);
|
2010-06-30 17:52:02 -07:00
|
|
|
return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_OBJ_OR_NULL_SET;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline JSObject *
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_OBJECT_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT((ptrBits & 0x7) == 0);
|
2010-06-30 17:52:02 -07:00
|
|
|
return (JSObject *)ptrBits;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2010-06-30 17:52:02 -07:00
|
|
|
OBJECT_TO_JSVAL_IMPL(JSObject *obj)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t objBits = (uint64_t)obj;
|
2014-01-16 03:06:31 -08:00
|
|
|
MOZ_ASSERT(uintptr_t(obj) > 0x1000 || uintptr_t(obj) == 0x42);
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT((objBits >> JSVAL_TAG_SHIFT) == 0);
|
2010-06-30 17:52:02 -07:00
|
|
|
l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_NULL_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.asBits == JSVAL_SHIFTED_TAG_NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_GCTHING_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l.asBits >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline void *
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_GCTHING_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t ptrBits = l.asBits & JSVAL_PAYLOAD_MASK;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT((ptrBits & 0x7) == 0);
|
2010-06-30 17:52:02 -07:00
|
|
|
return (void *)ptrBits;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_IS_TRACEABLE_IMPL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l);
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline uint32_t
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TRACE_KIND_IMPL(jsval_layout l)
|
|
|
|
{
|
2013-08-08 15:53:04 -07:00
|
|
|
return (uint32_t)(bool)!(JSVAL_IS_OBJECT_IMPL(l));
|
2010-06-30 17:52:02 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2010-06-30 17:52:02 -07:00
|
|
|
PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t ptrBits = (uint64_t)ptr;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT((ptrBits & 1) == 0);
|
2010-06-30 17:52:02 -07:00
|
|
|
l.asBits = ptrBits >> 1;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(l));
|
2010-06-30 17:52:02 -07:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline void *
|
2010-06-30 17:52:02 -07:00
|
|
|
JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l)
|
|
|
|
{
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT((l.asBits & 0x8000000000000000LL) == 0);
|
2010-06-30 17:52:02 -07:00
|
|
|
return (void *)(l.asBits << 1);
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32_t i32)
|
2011-09-19 09:34:49 -07:00
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return l.asBits == (((uint64_t)(uint32_t)i32) | JSVAL_SHIFTED_TAG_INT32);
|
2011-09-19 09:34:49 -07:00
|
|
|
}
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2014-04-28 16:55:40 -07:00
|
|
|
JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(jsval_layout l, bool b)
|
2010-08-04 04:13:19 -07:00
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
return l.asBits == (((uint64_t)(uint32_t)b) | JSVAL_SHIFTED_TAG_BOOLEAN);
|
2010-08-04 04:13:19 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout
|
2011-09-19 09:34:49 -07:00
|
|
|
MAGIC_TO_JSVAL_IMPL(JSWhyMagic why)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
l.asBits = ((uint64_t)(uint32_t)why) | JSVAL_SHIFTED_TAG_MAGIC;
|
2011-09-19 09:34:49 -07:00
|
|
|
return l;
|
|
|
|
}
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2014-03-05 12:49:36 -08:00
|
|
|
static inline jsval_layout
|
|
|
|
MAGIC_UINT32_TO_JSVAL_IMPL(uint32_t payload)
|
|
|
|
{
|
|
|
|
jsval_layout l;
|
|
|
|
l.asBits = ((uint64_t)payload) | JSVAL_SHIFTED_TAG_MAGIC;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
static inline bool
|
2011-09-19 09:34:49 -07:00
|
|
|
JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t lbits = lhs.asBits, rbits = rhs.asBits;
|
2011-09-19 09:34:49 -07:00
|
|
|
return (lbits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE && rbits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE) ||
|
|
|
|
(((lbits ^ rbits) & 0xFFFF800000000000LL) == 0);
|
|
|
|
}
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline JSValueType
|
2011-09-19 09:34:49 -07:00
|
|
|
JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l)
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint64_t type = (l.asBits >> JSVAL_TAG_SHIFT) & 0xF;
|
2013-02-01 16:15:49 -08:00
|
|
|
MOZ_ASSERT(type > JSVAL_TYPE_DOUBLE);
|
2011-09-19 09:34:49 -07:00
|
|
|
return (JSValueType)type;
|
|
|
|
}
|
2010-06-30 17:52:02 -07:00
|
|
|
|
2011-09-19 09:34:49 -07:00
|
|
|
#endif /* JS_BITS_PER_WORD */
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval_layout JSVAL_TO_IMPL(JS::Value v);
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l);
|
2013-02-01 16:15:49 -08:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue();
|
|
|
|
|
2013-09-19 18:42:56 -07:00
|
|
|
/**
|
|
|
|
* Returns a generic quiet NaN value, with all payload bits set to zero.
|
|
|
|
*
|
|
|
|
* Among other properties, this NaN's bit pattern conforms to JS::Value's
|
|
|
|
* bit pattern restrictions.
|
|
|
|
*/
|
|
|
|
static MOZ_ALWAYS_INLINE double
|
|
|
|
GenericNaN()
|
|
|
|
{
|
2014-02-27 07:23:11 -08:00
|
|
|
return mozilla::SpecificNaN<double>(0, 0x8000000000000ULL);
|
2013-09-19 18:42:56 -07:00
|
|
|
}
|
|
|
|
|
2014-02-27 11:48:59 -08:00
|
|
|
/* MSVC with PGO miscompiles this function. */
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
# pragma optimize("g", off)
|
|
|
|
#endif
|
2013-10-17 01:16:17 -07:00
|
|
|
static inline double
|
|
|
|
CanonicalizeNaN(double d)
|
|
|
|
{
|
|
|
|
if (MOZ_UNLIKELY(mozilla::IsNaN(d)))
|
|
|
|
return GenericNaN();
|
|
|
|
return d;
|
|
|
|
}
|
2014-02-27 11:48:59 -08:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
# pragma optimize("", on)
|
|
|
|
#endif
|
2013-10-17 01:16:17 -07:00
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
/*
|
|
|
|
* JS::Value is the interface for a single JavaScript Engine value. A few
|
|
|
|
* general notes on JS::Value:
|
|
|
|
*
|
|
|
|
* - JS::Value has setX() and isX() members for X in
|
|
|
|
*
|
|
|
|
* { Int32, Double, String, Boolean, Undefined, Null, Object, Magic }
|
|
|
|
*
|
|
|
|
* JS::Value also contains toX() for each of the non-singleton types.
|
|
|
|
*
|
2014-03-05 12:49:36 -08:00
|
|
|
* - Magic is a singleton type whose payload contains either a JSWhyMagic "reason" for
|
|
|
|
* the magic value or a uint32_t value. By providing JSWhyMagic values when
|
|
|
|
* creating and checking for magic values, it is possible to assert, at
|
|
|
|
* runtime, that only magic values with the expected reason flow through a
|
|
|
|
* particular value. For example, if cx->exception has a magic value, the
|
|
|
|
* reason must be JS_GENERATOR_CLOSING.
|
2013-02-01 16:15:49 -08:00
|
|
|
*
|
|
|
|
* - The JS::Value operations are preferred. The JSVAL_* operations remain for
|
|
|
|
* compatibility; they may be removed at some point. These operations mostly
|
|
|
|
* provide similar functionality. But there are a few key differences. One
|
2014-04-27 20:27:54 -07:00
|
|
|
* is that JS::Value gives null a separate type.
|
2013-02-01 16:15:49 -08:00
|
|
|
* Also, to help prevent mistakenly boxing a nullable JSObject* as an object,
|
2014-01-14 12:41:22 -08:00
|
|
|
* Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a
|
2013-02-01 16:15:49 -08:00
|
|
|
* JSObject&.) A convenience member Value::setObjectOrNull is provided.
|
|
|
|
*
|
|
|
|
* - JSVAL_VOID is the same as the singleton value of the Undefined type.
|
|
|
|
*
|
|
|
|
* - Note that JS::Value is 8 bytes on 32 and 64-bit architectures. Thus, on
|
|
|
|
* 32-bit user code should avoid copying jsval/JS::Value as much as possible,
|
|
|
|
* preferring to pass by const Value &.
|
|
|
|
*/
|
|
|
|
class Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* N.B. the default constructor leaves Value unitialized. Adding a default
|
|
|
|
* constructor prevents Value from being stored in a union.
|
|
|
|
*/
|
2013-07-29 13:59:34 -07:00
|
|
|
#if defined(JS_VALUE_IS_CONSTEXPR)
|
|
|
|
Value() = default;
|
|
|
|
Value(const Value& v) = default;
|
|
|
|
#endif
|
2013-02-01 16:15:49 -08:00
|
|
|
|
|
|
|
/*** Mutators ***/
|
|
|
|
|
|
|
|
void setNull() {
|
|
|
|
data.asBits = BUILD_JSVAL(JSVAL_TAG_NULL, 0).asBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setUndefined() {
|
|
|
|
data.asBits = BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0).asBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setInt32(int32_t i) {
|
|
|
|
data = INT32_TO_JSVAL_IMPL(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t &getInt32Ref() {
|
|
|
|
MOZ_ASSERT(isInt32());
|
|
|
|
return data.s.payload.i32;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDouble(double d) {
|
|
|
|
data = DOUBLE_TO_JSVAL_IMPL(d);
|
|
|
|
}
|
|
|
|
|
2013-09-19 18:42:56 -07:00
|
|
|
void setNaN() {
|
|
|
|
setDouble(GenericNaN());
|
|
|
|
}
|
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
double &getDoubleRef() {
|
|
|
|
MOZ_ASSERT(isDouble());
|
|
|
|
return data.asDouble;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setString(JSString *str) {
|
|
|
|
MOZ_ASSERT(!IsPoisonedPtr(str));
|
|
|
|
data = STRING_TO_JSVAL_IMPL(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setObject(JSObject &obj) {
|
|
|
|
MOZ_ASSERT(!IsPoisonedPtr(&obj));
|
|
|
|
data = OBJECT_TO_JSVAL_IMPL(&obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBoolean(bool b) {
|
|
|
|
data = BOOLEAN_TO_JSVAL_IMPL(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMagic(JSWhyMagic why) {
|
|
|
|
data = MAGIC_TO_JSVAL_IMPL(why);
|
|
|
|
}
|
|
|
|
|
2014-03-05 12:49:36 -08:00
|
|
|
void setMagicUint32(uint32_t payload) {
|
|
|
|
data = MAGIC_UINT32_TO_JSVAL_IMPL(payload);
|
|
|
|
}
|
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
bool setNumber(uint32_t ui) {
|
|
|
|
if (ui > JSVAL_INT_MAX) {
|
|
|
|
setDouble((double)ui);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
setInt32((int32_t)ui);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool setNumber(double d) {
|
|
|
|
int32_t i;
|
2014-02-27 07:23:11 -08:00
|
|
|
if (mozilla::NumberIsInt32(d, &i)) {
|
2013-02-01 16:15:49 -08:00
|
|
|
setInt32(i);
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-01 13:55:13 -07:00
|
|
|
|
|
|
|
setDouble(d);
|
|
|
|
return false;
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setObjectOrNull(JSObject *arg) {
|
|
|
|
if (arg)
|
|
|
|
setObject(*arg);
|
|
|
|
else
|
|
|
|
setNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void swap(Value &rhs) {
|
|
|
|
uint64_t tmp = rhs.data.asBits;
|
|
|
|
rhs.data.asBits = data.asBits;
|
|
|
|
data.asBits = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** Value type queries ***/
|
|
|
|
|
|
|
|
bool isUndefined() const {
|
|
|
|
return JSVAL_IS_UNDEFINED_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNull() const {
|
|
|
|
return JSVAL_IS_NULL_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNullOrUndefined() const {
|
|
|
|
return isNull() || isUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInt32() const {
|
|
|
|
return JSVAL_IS_INT32_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isInt32(int32_t i32) const {
|
|
|
|
return JSVAL_IS_SPECIFIC_INT32_IMPL(data, i32);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDouble() const {
|
|
|
|
return JSVAL_IS_DOUBLE_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isNumber() const {
|
|
|
|
return JSVAL_IS_NUMBER_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isString() const {
|
|
|
|
return JSVAL_IS_STRING_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isObject() const {
|
|
|
|
return JSVAL_IS_OBJECT_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isPrimitive() const {
|
|
|
|
return JSVAL_IS_PRIMITIVE_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isObjectOrNull() const {
|
|
|
|
return JSVAL_IS_OBJECT_OR_NULL_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isGCThing() const {
|
|
|
|
return JSVAL_IS_GCTHING_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isBoolean() const {
|
|
|
|
return JSVAL_IS_BOOLEAN_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isTrue() const {
|
2014-04-28 16:55:40 -07:00
|
|
|
return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, true);
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isFalse() const {
|
2014-04-28 16:55:40 -07:00
|
|
|
return JSVAL_IS_SPECIFIC_BOOLEAN_IMPL(data, false);
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isMagic() const {
|
|
|
|
return JSVAL_IS_MAGIC_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isMagic(JSWhyMagic why) const {
|
|
|
|
MOZ_ASSERT_IF(isMagic(), data.s.payload.why == why);
|
|
|
|
return JSVAL_IS_MAGIC_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isMarkable() const {
|
|
|
|
return JSVAL_IS_TRACEABLE_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSGCTraceKind gcKind() const {
|
|
|
|
MOZ_ASSERT(isMarkable());
|
|
|
|
return JSGCTraceKind(JSVAL_TRACE_KIND_IMPL(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSWhyMagic whyMagic() const {
|
|
|
|
MOZ_ASSERT(isMagic());
|
|
|
|
return data.s.payload.why;
|
|
|
|
}
|
|
|
|
|
2014-03-05 12:49:36 -08:00
|
|
|
uint32_t magicUint32() const {
|
|
|
|
MOZ_ASSERT(isMagic());
|
|
|
|
return data.s.payload.u32;
|
|
|
|
}
|
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
/*** Comparison ***/
|
|
|
|
|
|
|
|
bool operator==(const Value &rhs) const {
|
|
|
|
return data.asBits == rhs.data.asBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const Value &rhs) const {
|
|
|
|
return data.asBits != rhs.data.asBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline bool SameType(const Value &lhs, const Value &rhs);
|
|
|
|
|
|
|
|
/*** Extract the value's typed payload ***/
|
|
|
|
|
|
|
|
int32_t toInt32() const {
|
|
|
|
MOZ_ASSERT(isInt32());
|
|
|
|
return JSVAL_TO_INT32_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
double toDouble() const {
|
|
|
|
MOZ_ASSERT(isDouble());
|
|
|
|
return data.asDouble;
|
|
|
|
}
|
|
|
|
|
|
|
|
double toNumber() const {
|
|
|
|
MOZ_ASSERT(isNumber());
|
|
|
|
return isDouble() ? toDouble() : double(toInt32());
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString *toString() const {
|
|
|
|
MOZ_ASSERT(isString());
|
|
|
|
return JSVAL_TO_STRING_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject &toObject() const {
|
|
|
|
MOZ_ASSERT(isObject());
|
|
|
|
return *JSVAL_TO_OBJECT_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *toObjectOrNull() const {
|
|
|
|
MOZ_ASSERT(isObjectOrNull());
|
|
|
|
return JSVAL_TO_OBJECT_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *toGCThing() const {
|
|
|
|
MOZ_ASSERT(isGCThing());
|
|
|
|
return JSVAL_TO_GCTHING_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool toBoolean() const {
|
|
|
|
MOZ_ASSERT(isBoolean());
|
|
|
|
return JSVAL_TO_BOOLEAN_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t payloadAsRawUint32() const {
|
|
|
|
MOZ_ASSERT(!isDouble());
|
|
|
|
return data.s.payload.u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t asRawBits() const {
|
|
|
|
return data.asBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSValueType extractNonDoubleType() const {
|
|
|
|
return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private API
|
|
|
|
*
|
|
|
|
* Private setters/getters allow the caller to read/write arbitrary types
|
|
|
|
* that fit in the 64-bit payload. It is the caller's responsibility, after
|
|
|
|
* storing to a value with setPrivateX to read only using getPrivateX.
|
2013-03-14 18:44:03 -07:00
|
|
|
* Privates values are given a type which ensures they are not marked.
|
2013-02-01 16:15:49 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
void setPrivate(void *ptr) {
|
|
|
|
data = PRIVATE_PTR_TO_JSVAL_IMPL(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *toPrivate() const {
|
|
|
|
MOZ_ASSERT(JSVAL_IS_DOUBLE_IMPL(data));
|
|
|
|
return JSVAL_TO_PRIVATE_PTR_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPrivateUint32(uint32_t ui) {
|
2013-02-01 18:41:35 -08:00
|
|
|
MOZ_ASSERT(uint32_t(int32_t(ui)) == ui);
|
|
|
|
setInt32(int32_t(ui));
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t toPrivateUint32() const {
|
2013-02-01 18:41:35 -08:00
|
|
|
return uint32_t(toInt32());
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An unmarked value is just a void* cast as a Value. Thus, the Value is
|
|
|
|
* not safe for GC and must not be marked. This API avoids raw casts
|
|
|
|
* and the ensuing strict-aliasing warnings.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void setUnmarkedPtr(void *ptr) {
|
|
|
|
data.asPtr = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *toUnmarkedPtr() const {
|
|
|
|
return data.asPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t *payloadWord() const {
|
|
|
|
#if JS_BITS_PER_WORD == 32
|
|
|
|
return &data.s.payload.word;
|
|
|
|
#elif JS_BITS_PER_WORD == 64
|
|
|
|
return &data.asWord;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const uintptr_t *payloadUIntPtr() const {
|
|
|
|
#if JS_BITS_PER_WORD == 32
|
|
|
|
return &data.s.payload.uintptr;
|
|
|
|
#elif JS_BITS_PER_WORD == 64
|
|
|
|
return &data.asUIntPtr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(_MSC_VER) && !defined(__sparc)
|
|
|
|
// Value must be POD so that MSVC will pass it by value and not in memory
|
|
|
|
// (bug 689101); the same is true for SPARC as well (bug 737344). More
|
|
|
|
// precisely, we don't want Value return values compiled as out params.
|
|
|
|
private:
|
|
|
|
#endif
|
|
|
|
|
|
|
|
jsval_layout data;
|
|
|
|
|
|
|
|
private:
|
2013-07-29 13:59:34 -07:00
|
|
|
#if defined(JS_VALUE_IS_CONSTEXPR)
|
|
|
|
JS_VALUE_CONSTEXPR Value(jsval_layout layout) : data(layout) {}
|
|
|
|
#endif
|
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
void staticAssertions() {
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSValueType) == 1);
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSValueTag) == 4);
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSWhyMagic) <= 4);
|
|
|
|
JS_STATIC_ASSERT(sizeof(Value) == 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend jsval_layout (::JSVAL_TO_IMPL)(Value);
|
2013-07-29 13:59:34 -07:00
|
|
|
friend Value JS_VALUE_CONSTEXPR (::IMPL_TO_JSVAL)(jsval_layout l);
|
|
|
|
friend Value JS_VALUE_CONSTEXPR (JS::UndefinedValue)();
|
2013-02-01 16:15:49 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
IsPoisonedValue(const Value &v)
|
|
|
|
{
|
|
|
|
if (v.isString())
|
|
|
|
return IsPoisonedPtr(v.toString());
|
|
|
|
if (v.isObject())
|
|
|
|
return IsPoisonedPtr(&v.toObject());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-24 01:59:36 -07:00
|
|
|
inline bool
|
|
|
|
IsOptimizedPlaceholderMagicValue(const Value &v)
|
|
|
|
{
|
|
|
|
if (v.isMagic()) {
|
|
|
|
MOZ_ASSERT(v.whyMagic() == JS_OPTIMIZED_ARGUMENTS || v.whyMagic() == JS_OPTIMIZED_OUT);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
/************************************************************************/
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NullValue()
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setNull();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR Value
|
2013-02-01 16:15:49 -08:00
|
|
|
UndefinedValue()
|
|
|
|
{
|
2013-07-29 13:59:34 -07:00
|
|
|
#if defined(JS_VALUE_IS_CONSTEXPR)
|
|
|
|
return Value(BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0));
|
|
|
|
#else
|
|
|
|
JS::Value v;
|
2013-02-01 16:15:49 -08:00
|
|
|
v.setUndefined();
|
|
|
|
return v;
|
2013-07-29 13:59:34 -07:00
|
|
|
#endif
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
Int32Value(int32_t i32)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setInt32(i32);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
DoubleValue(double dbl)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setDouble(dbl);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-09-19 18:42:56 -07:00
|
|
|
static inline Value
|
|
|
|
DoubleNaNValue()
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setNaN();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-07-18 15:13:15 -07:00
|
|
|
static inline Value
|
|
|
|
Float32Value(float f)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setDouble(f);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
StringValue(JSString *str)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setString(str);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
BooleanValue(bool boo)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setBoolean(boo);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-11-15 18:46:39 -08:00
|
|
|
static inline Value
|
|
|
|
TrueValue()
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setBoolean(true);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Value
|
|
|
|
FalseValue()
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setBoolean(false);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
ObjectValue(JSObject &obj)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setObject(obj);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
ObjectValueCrashOnTouch()
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setObject(*reinterpret_cast<JSObject *>(0x42));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
MagicValue(JSWhyMagic why)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setMagic(why);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2014-03-05 12:49:36 -08:00
|
|
|
static inline Value
|
|
|
|
MagicValueUint32(uint32_t payload)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setMagicUint32(payload);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NumberValue(float f)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setNumber(f);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NumberValue(double dbl)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setNumber(dbl);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NumberValue(int8_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NumberValue(uint8_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NumberValue(int16_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NumberValue(uint16_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NumberValue(int32_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NumberValue(uint32_t i)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setNumber(i);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template <bool Signed>
|
|
|
|
class MakeNumberValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
static inline Value create(const T t)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
if (JSVAL_INT_MIN <= t && t <= JSVAL_INT_MAX)
|
|
|
|
v.setInt32(int32_t(t));
|
|
|
|
else
|
|
|
|
v.setDouble(double(t));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class MakeNumberValue<false>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
static inline Value create(const T t)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
if (t <= JSVAL_INT_MAX)
|
|
|
|
v.setInt32(int32_t(t));
|
|
|
|
else
|
|
|
|
v.setDouble(double(t));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
template <typename T>
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
NumberValue(const T t)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(T(double(t)) == t, "value creation would be lossy");
|
|
|
|
return detail::MakeNumberValue<std::numeric_limits<T>::is_signed>::create(t);
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
ObjectOrNullValue(JSObject *obj)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setObjectOrNull(obj);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
PrivateValue(void *ptr)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setPrivate(ptr);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline Value
|
2013-02-01 16:15:49 -08:00
|
|
|
PrivateUint32Value(uint32_t ui)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setPrivateUint32(ui);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
inline bool
|
2013-02-01 16:15:49 -08:00
|
|
|
SameType(const Value &lhs, const Value &rhs)
|
|
|
|
{
|
|
|
|
return JSVAL_SAME_TYPE_IMPL(lhs.data, rhs.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace JS
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2013-05-27 04:51:25 -07:00
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
namespace JS {
|
|
|
|
JS_PUBLIC_API(void) HeapValuePostBarrier(Value *valuep);
|
|
|
|
JS_PUBLIC_API(void) HeapValueRelocate(Value *valuep);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
namespace js {
|
|
|
|
|
2013-06-19 03:32:26 -07:00
|
|
|
template <> struct GCMethods<const JS::Value>
|
2013-02-01 16:15:49 -08:00
|
|
|
{
|
2013-03-19 03:35:41 -07:00
|
|
|
static JS::Value initial() { return JS::UndefinedValue(); }
|
2013-02-01 16:15:49 -08:00
|
|
|
static ThingRootKind kind() { return THING_ROOT_VALUE; }
|
2013-03-19 03:35:41 -07:00
|
|
|
static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); }
|
2013-02-01 16:15:49 -08:00
|
|
|
};
|
|
|
|
|
2013-06-19 03:32:26 -07:00
|
|
|
template <> struct GCMethods<JS::Value>
|
2013-02-01 16:15:49 -08:00
|
|
|
{
|
2013-03-19 03:35:41 -07:00
|
|
|
static JS::Value initial() { return JS::UndefinedValue(); }
|
2013-02-01 16:15:49 -08:00
|
|
|
static ThingRootKind kind() { return THING_ROOT_VALUE; }
|
2013-03-19 03:35:41 -07:00
|
|
|
static bool poisoned(const JS::Value &v) { return JS::IsPoisonedValue(v); }
|
2013-05-27 04:51:25 -07:00
|
|
|
static bool needsPostBarrier(const JS::Value &v) { return v.isMarkable(); }
|
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
static void postBarrier(JS::Value *v) { JS::HeapValuePostBarrier(v); }
|
|
|
|
static void relocate(JS::Value *v) { JS::HeapValueRelocate(v); }
|
|
|
|
#endif
|
2013-02-01 16:15:49 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class Outer> class MutableValueOperations;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A class designed for CRTP use in implementing the non-mutating parts of the
|
|
|
|
* Value interface in Value-like classes. Outer must be a class inheriting
|
|
|
|
* ValueOperations<Outer> with a visible extract() method returning the
|
|
|
|
* const Value* abstracted by Outer.
|
|
|
|
*/
|
|
|
|
template <class Outer>
|
|
|
|
class ValueOperations
|
|
|
|
{
|
|
|
|
friend class MutableValueOperations<Outer>;
|
2013-06-18 03:00:37 -07:00
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
const JS::Value * value() const { return static_cast<const Outer*>(this)->extract(); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool isUndefined() const { return value()->isUndefined(); }
|
|
|
|
bool isNull() const { return value()->isNull(); }
|
|
|
|
bool isBoolean() const { return value()->isBoolean(); }
|
|
|
|
bool isTrue() const { return value()->isTrue(); }
|
|
|
|
bool isFalse() const { return value()->isFalse(); }
|
|
|
|
bool isNumber() const { return value()->isNumber(); }
|
|
|
|
bool isInt32() const { return value()->isInt32(); }
|
|
|
|
bool isDouble() const { return value()->isDouble(); }
|
|
|
|
bool isString() const { return value()->isString(); }
|
|
|
|
bool isObject() const { return value()->isObject(); }
|
|
|
|
bool isMagic() const { return value()->isMagic(); }
|
|
|
|
bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); }
|
|
|
|
bool isMarkable() const { return value()->isMarkable(); }
|
|
|
|
bool isPrimitive() const { return value()->isPrimitive(); }
|
|
|
|
bool isGCThing() const { return value()->isGCThing(); }
|
|
|
|
|
|
|
|
bool isNullOrUndefined() const { return value()->isNullOrUndefined(); }
|
|
|
|
bool isObjectOrNull() const { return value()->isObjectOrNull(); }
|
|
|
|
|
|
|
|
bool toBoolean() const { return value()->toBoolean(); }
|
|
|
|
double toNumber() const { return value()->toNumber(); }
|
|
|
|
int32_t toInt32() const { return value()->toInt32(); }
|
|
|
|
double toDouble() const { return value()->toDouble(); }
|
|
|
|
JSString *toString() const { return value()->toString(); }
|
|
|
|
JSObject &toObject() const { return value()->toObject(); }
|
|
|
|
JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); }
|
|
|
|
void *toGCThing() const { return value()->toGCThing(); }
|
2014-04-25 14:18:18 -07:00
|
|
|
uint64_t asRawBits() const { return value()->asRawBits(); }
|
2013-02-01 16:15:49 -08:00
|
|
|
|
|
|
|
JSValueType extractNonDoubleType() const { return value()->extractNonDoubleType(); }
|
2013-06-26 16:26:45 -07:00
|
|
|
uint32_t toPrivateUint32() const { return value()->toPrivateUint32(); }
|
2013-02-01 16:15:49 -08:00
|
|
|
|
|
|
|
JSWhyMagic whyMagic() const { return value()->whyMagic(); }
|
2014-03-05 12:49:36 -08:00
|
|
|
uint32_t magicUint32() const { return value()->magicUint32(); }
|
2013-02-01 16:15:49 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2013-11-19 14:53:36 -08:00
|
|
|
* A class designed for CRTP use in implementing all the mutating parts of the
|
|
|
|
* Value interface in Value-like classes. Outer must be a class inheriting
|
|
|
|
* MutableValueOperations<Outer> with visible extractMutable() and extract()
|
|
|
|
* methods returning the const Value* and Value* abstracted by Outer.
|
2013-02-01 16:15:49 -08:00
|
|
|
*/
|
|
|
|
template <class Outer>
|
2013-11-19 14:53:36 -08:00
|
|
|
class MutableValueOperations : public ValueOperations<Outer>
|
2013-02-01 16:15:49 -08:00
|
|
|
{
|
|
|
|
JS::Value * value() { return static_cast<Outer*>(this)->extractMutable(); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setNull() { value()->setNull(); }
|
|
|
|
void setUndefined() { value()->setUndefined(); }
|
|
|
|
void setInt32(int32_t i) { value()->setInt32(i); }
|
|
|
|
void setDouble(double d) { value()->setDouble(d); }
|
2013-09-19 18:42:56 -07:00
|
|
|
void setNaN() { setDouble(JS::GenericNaN()); }
|
2013-02-01 16:15:49 -08:00
|
|
|
void setBoolean(bool b) { value()->setBoolean(b); }
|
|
|
|
void setMagic(JSWhyMagic why) { value()->setMagic(why); }
|
|
|
|
bool setNumber(uint32_t ui) { return value()->setNumber(ui); }
|
|
|
|
bool setNumber(double d) { return value()->setNumber(d); }
|
2013-06-18 03:00:37 -07:00
|
|
|
void setString(JSString *str) { this->value()->setString(str); }
|
|
|
|
void setObject(JSObject &obj) { this->value()->setObject(obj); }
|
|
|
|
void setObjectOrNull(JSObject *arg) { this->value()->setObjectOrNull(arg); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Augment the generic Heap<T> interface when T = Value with
|
|
|
|
* type-querying, value-extracting, and mutating operations.
|
2013-05-27 04:51:25 -07:00
|
|
|
*/
|
|
|
|
template <>
|
2013-11-12 03:21:01 -08:00
|
|
|
class HeapBase<JS::Value> : public ValueOperations<JS::Heap<JS::Value> >
|
2013-05-27 04:51:25 -07:00
|
|
|
{
|
2013-06-18 03:00:37 -07:00
|
|
|
typedef JS::Heap<JS::Value> Outer;
|
|
|
|
|
|
|
|
friend class ValueOperations<Outer>;
|
|
|
|
|
|
|
|
const JS::Value * extract() const { return static_cast<const Outer*>(this)->address(); }
|
|
|
|
|
|
|
|
void setBarriered(const JS::Value &v) {
|
|
|
|
static_cast<JS::Heap<JS::Value> *>(this)->set(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2013-11-12 03:21:01 -08:00
|
|
|
void setNull() { setBarriered(JS::NullValue()); }
|
|
|
|
void setUndefined() { setBarriered(JS::UndefinedValue()); }
|
|
|
|
void setInt32(int32_t i) { setBarriered(JS::Int32Value(i)); }
|
|
|
|
void setDouble(double d) { setBarriered(JS::DoubleValue(d)); }
|
|
|
|
void setNaN() { setDouble(JS::GenericNaN()); }
|
|
|
|
void setBoolean(bool b) { setBarriered(JS::BooleanValue(b)); }
|
|
|
|
void setMagic(JSWhyMagic why) { setBarriered(JS::MagicValue(why)); }
|
2013-06-18 03:00:37 -07:00
|
|
|
void setString(JSString *str) { setBarriered(JS::StringValue(str)); }
|
|
|
|
void setObject(JSObject &obj) { setBarriered(JS::ObjectValue(obj)); }
|
|
|
|
|
2013-11-12 03:21:01 -08:00
|
|
|
bool setNumber(uint32_t ui) {
|
|
|
|
if (ui > JSVAL_INT_MAX) {
|
|
|
|
setDouble((double)ui);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
setInt32((int32_t)ui);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool setNumber(double d) {
|
|
|
|
int32_t i;
|
2014-02-27 07:23:11 -08:00
|
|
|
if (mozilla::NumberIsInt32(d, &i)) {
|
2013-11-12 03:21:01 -08:00
|
|
|
setInt32(i);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
setDouble(d);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-18 03:00:37 -07:00
|
|
|
void setObjectOrNull(JSObject *arg) {
|
|
|
|
if (arg)
|
|
|
|
setObject(*arg);
|
|
|
|
else
|
|
|
|
setNull();
|
2013-05-27 04:51:25 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
/*
|
|
|
|
* Augment the generic Handle<T> interface when T = Value with type-querying
|
|
|
|
* and value-extracting operations.
|
|
|
|
*/
|
|
|
|
template <>
|
2013-03-19 03:35:41 -07:00
|
|
|
class HandleBase<JS::Value> : public ValueOperations<JS::Handle<JS::Value> >
|
2013-02-01 16:15:49 -08:00
|
|
|
{
|
2013-03-19 03:35:41 -07:00
|
|
|
friend class ValueOperations<JS::Handle<JS::Value> >;
|
2013-02-01 16:15:49 -08:00
|
|
|
const JS::Value * extract() const {
|
2013-03-19 03:35:41 -07:00
|
|
|
return static_cast<const JS::Handle<JS::Value>*>(this)->address();
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Augment the generic MutableHandle<T> interface when T = Value with
|
|
|
|
* type-querying, value-extracting, and mutating operations.
|
|
|
|
*/
|
|
|
|
template <>
|
2013-03-19 03:35:41 -07:00
|
|
|
class MutableHandleBase<JS::Value> : public MutableValueOperations<JS::MutableHandle<JS::Value> >
|
2013-02-01 16:15:49 -08:00
|
|
|
{
|
2013-03-19 03:35:41 -07:00
|
|
|
friend class ValueOperations<JS::MutableHandle<JS::Value> >;
|
2013-02-01 16:15:49 -08:00
|
|
|
const JS::Value * extract() const {
|
2013-03-19 03:35:41 -07:00
|
|
|
return static_cast<const JS::MutableHandle<JS::Value>*>(this)->address();
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
2013-03-19 03:35:41 -07:00
|
|
|
friend class MutableValueOperations<JS::MutableHandle<JS::Value> >;
|
2013-02-01 16:15:49 -08:00
|
|
|
JS::Value * extractMutable() {
|
2013-03-19 03:35:41 -07:00
|
|
|
return static_cast<JS::MutableHandle<JS::Value>*>(this)->address();
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Augment the generic Rooted<T> interface when T = Value with type-querying,
|
|
|
|
* value-extracting, and mutating operations.
|
|
|
|
*/
|
|
|
|
template <>
|
2013-03-19 03:35:41 -07:00
|
|
|
class RootedBase<JS::Value> : public MutableValueOperations<JS::Rooted<JS::Value> >
|
2013-02-01 16:15:49 -08:00
|
|
|
{
|
2013-03-19 03:35:41 -07:00
|
|
|
friend class ValueOperations<JS::Rooted<JS::Value> >;
|
2013-02-01 16:15:49 -08:00
|
|
|
const JS::Value * extract() const {
|
2013-03-19 03:35:41 -07:00
|
|
|
return static_cast<const JS::Rooted<JS::Value>*>(this)->address();
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
2013-03-19 03:35:41 -07:00
|
|
|
friend class MutableValueOperations<JS::Rooted<JS::Value> >;
|
2013-02-01 16:15:49 -08:00
|
|
|
JS::Value * extractMutable() {
|
2013-03-19 03:35:41 -07:00
|
|
|
return static_cast<JS::Rooted<JS::Value>*>(this)->address();
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace js
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
inline jsval_layout
|
2013-02-01 16:15:49 -08:00
|
|
|
JSVAL_TO_IMPL(JS::Value v)
|
|
|
|
{
|
|
|
|
return v.data;
|
|
|
|
}
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
inline JS_VALUE_CONSTEXPR JS::Value
|
2013-02-01 16:15:49 -08:00
|
|
|
IMPL_TO_JSVAL(jsval_layout l)
|
|
|
|
{
|
2013-07-29 13:59:34 -07:00
|
|
|
#if defined(JS_VALUE_IS_CONSTEXPR)
|
|
|
|
return JS::Value(l);
|
|
|
|
#else
|
2013-02-01 16:15:49 -08:00
|
|
|
JS::Value v;
|
|
|
|
v.data = l;
|
|
|
|
return v;
|
2013-07-29 13:59:34 -07:00
|
|
|
#endif
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
2011-09-19 09:34:49 -07:00
|
|
|
|
2013-02-01 15:31:00 -08:00
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
#ifndef __GNUC__
|
|
|
|
/*
|
|
|
|
* The default assignment operator for |struct C| has the signature:
|
|
|
|
*
|
|
|
|
* C& C::operator=(const C&)
|
|
|
|
*
|
|
|
|
* And in particular requires implicit conversion of |this| to type |C| for the
|
|
|
|
* return value. But |volatile C| cannot thus be converted to |C|, so just
|
|
|
|
* doing |sink = hold| as in the non-specialized version would fail to compile.
|
|
|
|
* Do the assignment on asBits instead, since I don't think we want to give
|
|
|
|
* jsval_layout an assignment operator returning |volatile jsval_layout|.
|
|
|
|
*/
|
|
|
|
template<>
|
|
|
|
inline Anchor<Value>::~Anchor()
|
|
|
|
{
|
|
|
|
volatile uint64_t bits;
|
|
|
|
bits = JSVAL_TO_IMPL(hold).asBits;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-06 15:03:08 -08:00
|
|
|
#ifdef JS_DEBUG
|
2013-02-01 16:15:49 -08:00
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
struct ValueAlignmentTester { char c; JS::Value v; };
|
2013-07-18 10:59:53 -07:00
|
|
|
static_assert(sizeof(ValueAlignmentTester) == 16,
|
|
|
|
"JS::Value must be 16-byte-aligned");
|
2013-02-01 16:15:49 -08:00
|
|
|
|
|
|
|
struct LayoutAlignmentTester { char c; jsval_layout l; };
|
2013-07-18 10:59:53 -07:00
|
|
|
static_assert(sizeof(LayoutAlignmentTester) == 16,
|
|
|
|
"jsval_layout must be 16-byte-aligned");
|
2013-02-01 16:15:49 -08:00
|
|
|
|
|
|
|
} // namespace detail
|
2013-12-06 15:03:08 -08:00
|
|
|
#endif /* JS_DEBUG */
|
2013-02-01 16:15:49 -08:00
|
|
|
|
2013-02-01 15:31:00 -08:00
|
|
|
} // namespace JS
|
|
|
|
|
2013-02-01 16:15:49 -08:00
|
|
|
/*
|
|
|
|
* JS::Value and jsval are the same type; jsval is the old name, kept around
|
|
|
|
* for backwards compatibility along with all the JSVAL_* operations below.
|
|
|
|
* jsval_layout is an implementation detail and should not be used externally.
|
|
|
|
*/
|
|
|
|
typedef JS::Value jsval;
|
|
|
|
|
2013-07-18 10:59:53 -07:00
|
|
|
static_assert(sizeof(jsval_layout) == sizeof(JS::Value),
|
|
|
|
"jsval_layout and JS::Value must have identical layouts");
|
2013-02-01 16:15:49 -08:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR jsval
|
2013-02-01 16:15:49 -08:00
|
|
|
INT_TO_JSVAL(int32_t i)
|
|
|
|
{
|
|
|
|
return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i));
|
|
|
|
}
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR jsval
|
2013-02-01 16:15:49 -08:00
|
|
|
DOUBLE_TO_JSVAL(double d)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This is a manually inlined version of:
|
|
|
|
* d = JS_CANONICALIZE_NAN(d);
|
|
|
|
* return IMPL_TO_JSVAL(DOUBLE_TO_JSVAL_IMPL(d));
|
|
|
|
* because GCC from XCode 3.1.4 miscompiles the above code.
|
|
|
|
*/
|
2013-07-29 13:59:34 -07:00
|
|
|
#if defined(JS_VALUE_IS_CONSTEXPR)
|
|
|
|
return IMPL_TO_JSVAL(MOZ_UNLIKELY(d != d)
|
|
|
|
? (jsval_layout) { .asBits = 0x7FF8000000000000LL }
|
|
|
|
: (jsval_layout) { .asDouble = d });
|
|
|
|
#else
|
2013-02-01 16:15:49 -08:00
|
|
|
jsval_layout l;
|
|
|
|
if (MOZ_UNLIKELY(d != d))
|
|
|
|
l.asBits = 0x7FF8000000000000LL;
|
|
|
|
else
|
|
|
|
l.asDouble = d;
|
|
|
|
return IMPL_TO_JSVAL(l);
|
2013-07-29 13:59:34 -07:00
|
|
|
#endif
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
static inline JS_VALUE_CONSTEXPR jsval
|
2013-02-01 16:15:49 -08:00
|
|
|
UINT_TO_JSVAL(uint32_t i)
|
|
|
|
{
|
2013-07-29 13:59:34 -07:00
|
|
|
return (i <= JSVAL_INT_MAX
|
|
|
|
? INT_TO_JSVAL((int32_t)i)
|
|
|
|
: DOUBLE_TO_JSVAL((double)i));
|
2013-02-01 16:15:49 -08:00
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval
|
2013-02-01 16:15:49 -08:00
|
|
|
STRING_TO_JSVAL(JSString *str)
|
|
|
|
{
|
|
|
|
return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str));
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval
|
2013-02-01 16:15:49 -08:00
|
|
|
OBJECT_TO_JSVAL(JSObject *obj)
|
|
|
|
{
|
|
|
|
if (obj)
|
|
|
|
return IMPL_TO_JSVAL(OBJECT_TO_JSVAL_IMPL(obj));
|
|
|
|
return IMPL_TO_JSVAL(BUILD_JSVAL(JSVAL_TAG_NULL, 0));
|
|
|
|
}
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval
|
2013-08-08 15:53:04 -07:00
|
|
|
BOOLEAN_TO_JSVAL(bool b)
|
2013-02-01 16:15:49 -08:00
|
|
|
{
|
|
|
|
return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* To be GC-safe, privates are tagged as doubles. */
|
|
|
|
|
2013-03-04 09:41:11 -08:00
|
|
|
static inline jsval
|
2013-02-01 16:15:49 -08:00
|
|
|
PRIVATE_TO_JSVAL(void *ptr)
|
|
|
|
{
|
|
|
|
return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr));
|
|
|
|
}
|
|
|
|
|
2013-08-19 23:43:47 -07:00
|
|
|
// JS constants. For efficiency, prefer predicates (e.g. v.isNull()) and
|
|
|
|
// constructing values from scratch (e.g. Int32Value(0)). These constants are
|
|
|
|
// stored in memory and initialized at startup, so testing against them and
|
|
|
|
// using them requires memory loads and will be correspondingly slow.
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_NULL;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_ZERO;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_ONE;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_FALSE;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_TRUE;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID;
|
|
|
|
|
2013-08-19 23:45:26 -07:00
|
|
|
namespace JS {
|
|
|
|
|
2014-01-15 02:31:00 -08:00
|
|
|
extern JS_PUBLIC_DATA(const HandleValue) NullHandleValue;
|
|
|
|
extern JS_PUBLIC_DATA(const HandleValue) UndefinedHandleValue;
|
2014-04-30 02:10:33 -07:00
|
|
|
extern JS_PUBLIC_DATA(const HandleValue) TrueHandleValue;
|
|
|
|
extern JS_PUBLIC_DATA(const HandleValue) FalseHandleValue;
|
2013-08-19 23:45:26 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-29 13:59:34 -07:00
|
|
|
#undef JS_VALUE_IS_CONSTEXPR
|
|
|
|
#undef JS_RETURN_LAYOUT_FROM_BITS
|
|
|
|
|
2013-06-19 17:59:09 -07:00
|
|
|
#endif /* js_Value_h */
|