1 /*
2  *  Defines for JSON, especially duk_bi_json.c.
3  */
4 
5 #ifndef DUK_JSON_H_INCLUDED
6 #define DUK_JSON_H_INCLUDED
7 
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 */
13 
14 /* How much stack to require on entry to object/array encode */
15 #define DUK_JSON_ENC_REQSTACK                 32
16 
17 /* How much stack to require on entry to object/array decode */
18 #define DUK_JSON_DEC_REQSTACK                 32
19 
20 /* How large a loop detection stack to use */
21 #define DUK_JSON_ENC_LOOPARRAY                64
22 
23 /* Encoding state.  Heap object references are all borrowed. */
24 typedef struct {
25 	duk_hthread *thr;
26 	duk_bufwriter_ctx bw;        /* output bufwriter */
27 	duk_hobject *h_replacer;     /* replacer function */
28 	duk_hstring *h_gap;          /* gap (if empty string, NULL) */
29 	duk_idx_t idx_proplist;      /* explicit PropertyList */
30 	duk_idx_t idx_loop;          /* valstack index of loop detection object */
31 	duk_small_uint_t flags;
32 	duk_small_uint_t flag_ascii_only;
33 	duk_small_uint_t flag_avoid_key_quotes;
34 #if defined(DUK_USE_JX) || defined(DUK_USE_JC)
35 	duk_small_uint_t flag_ext_custom;
36 	duk_small_uint_t flag_ext_compatible;
37 	duk_small_uint_t flag_ext_custom_or_compatible;
38 #endif
39 	duk_int_t recursion_depth;
40 	duk_int_t recursion_limit;
41 	duk_uint_t mask_for_undefined;      /* type bit mask: types which certainly produce 'undefined' */
42 #if defined(DUK_USE_JX) || defined(DUK_USE_JC)
43 	duk_small_uint_t stridx_custom_undefined;
44 	duk_small_uint_t stridx_custom_nan;
45 	duk_small_uint_t stridx_custom_neginf;
46 	duk_small_uint_t stridx_custom_posinf;
47 	duk_small_uint_t stridx_custom_function;
48 #endif
49 	duk_hobject *visiting[DUK_JSON_ENC_LOOPARRAY];  /* indexed by recursion_depth */
50 } duk_json_enc_ctx;
51 
52 typedef struct {
53 	duk_hthread *thr;
54 	const duk_uint8_t *p;
55 	const duk_uint8_t *p_start;
56 	const duk_uint8_t *p_end;
57 	duk_idx_t idx_reviver;
58 	duk_small_uint_t flags;
59 #if defined(DUK_USE_JX) || defined(DUK_USE_JC)
60 	duk_small_uint_t flag_ext_custom;
61 	duk_small_uint_t flag_ext_compatible;
62 	duk_small_uint_t flag_ext_custom_or_compatible;
63 #endif
64 	duk_int_t recursion_depth;
65 	duk_int_t recursion_limit;
66 } duk_json_dec_ctx;
67 
68 #endif  /* DUK_JSON_H_INCLUDED */
69