2 * Defines for JSON, especially duk_bi_json.c.
5 #ifndef DUK_JSON_H_INCLUDED
6 #define DUK_JSON_H_INCLUDED
8 /* Encoding/decoding flags */
9 #define DUK_JSON_FLAG_ASCII_ONLY (1 << 0) /* escape any non-ASCII characters */
10 #define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1 << 1) /* avoid key quotes when key is an ASCII Identifier */
11 #define DUK_JSON_FLAG_EXT_CUSTOM (1 << 2) /* extended types: custom encoding */
12 #define DUK_JSON_FLAG_EXT_COMPATIBLE (1 << 3) /* extended types: compatible encoding */
14 /* How much stack to require on entry to object/array encode */
15 #define DUK_JSON_ENC_REQSTACK 32
17 /* How much stack to require on entry to object/array decode */
18 #define DUK_JSON_DEC_REQSTACK 32
20 /* How large a loop detection stack to use for fast path */
21 #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH)
22 #define DUK_JSON_ENC_LOOPARRAY 64
25 /* Encoding state. Heap object references are all borrowed. */
28 duk_bufwriter_ctx bw
; /* output bufwriter */
29 duk_hobject
*h_replacer
; /* replacer function */
30 duk_hstring
*h_gap
; /* gap (if empty string, NULL) */
31 duk_hstring
*h_indent
; /* current indent (if gap is NULL, this is NULL) */
32 duk_idx_t idx_proplist
; /* explicit PropertyList */
33 duk_idx_t idx_loop
; /* valstack index of loop detection object */
34 duk_small_uint_t flags
;
35 duk_small_uint_t flag_ascii_only
;
36 duk_small_uint_t flag_avoid_key_quotes
;
37 #if defined(DUK_USE_JX) || defined(DUK_USE_JC)
38 duk_small_uint_t flag_ext_custom
;
39 duk_small_uint_t flag_ext_compatible
;
41 duk_int_t recursion_depth
;
42 duk_int_t recursion_limit
;
43 duk_uint_t mask_for_undefined
; /* type bit mask: types which certainly produce 'undefined' */
44 #if defined(DUK_USE_JX) || defined(DUK_USE_JC)
45 duk_small_uint_t stridx_custom_undefined
;
46 duk_small_uint_t stridx_custom_nan
;
47 duk_small_uint_t stridx_custom_neginf
;
48 duk_small_uint_t stridx_custom_posinf
;
49 duk_small_uint_t stridx_custom_function
;
51 #if defined(DUK_USE_JSON_STRINGIFY_FASTPATH)
52 duk_hobject
*visiting
[DUK_JSON_ENC_LOOPARRAY
]; /* indexed by recursion_depth */
59 const duk_uint8_t
*p_start
;
60 const duk_uint8_t
*p_end
;
61 duk_idx_t idx_reviver
;
62 duk_small_uint_t flags
;
63 #if defined(DUK_USE_JX) || defined(DUK_USE_JC)
64 duk_small_uint_t flag_ext_custom
;
65 duk_small_uint_t flag_ext_compatible
;
67 duk_int_t recursion_depth
;
68 duk_int_t recursion_limit
;
71 #endif /* DUK_JSON_H_INCLUDED */