...
|
...
|
@@ -1,8 +1,8 @@
|
1
|
1
|
/*
|
2
|
|
- * Single source autogenerated distributable for Duktape 2.5.0.
|
|
2
|
+ * Single source autogenerated distributable for Duktape 2.6.0.
|
3
|
3
|
*
|
4
|
|
- * Git commit 6001888049cb42656f8649db020e804bcdeca6a7 (v2.5.0).
|
5
|
|
- * Git branch master.
|
|
4
|
+ * Git commit fffa346eff06a8764b02c31d4336f63a773a95c3 (v2.6.0).
|
|
5
|
+ * Git branch v2-maintenance.
|
6
|
6
|
*
|
7
|
7
|
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
|
8
|
8
|
* licensing information.
|
...
|
...
|
@@ -525,7 +525,8 @@ typedef union duk_double_union duk_double_union;
|
525
|
525
|
} while (0)
|
526
|
526
|
|
527
|
527
|
#define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) do { \
|
528
|
|
- if (DUK__DBLUNION_IS_NAN_NOTFULL((u))) { \
|
|
528
|
+ /* Check must be full. */ \
|
|
529
|
+ if (DUK__DBLUNION_IS_NAN_FULL((u))) { \
|
529
|
530
|
DUK__DBLUNION_SET_NAN_NOTFULL((u)); \
|
530
|
531
|
} \
|
531
|
532
|
} while (0)
|
...
|
...
|
@@ -537,12 +538,11 @@ typedef union duk_double_union duk_double_union;
|
537
|
538
|
*/
|
538
|
539
|
|
539
|
540
|
#if defined(DUK_USE_PACKED_TVAL)
|
540
|
|
-#if defined(DUK_USE_FULL_TVAL)
|
541
|
541
|
#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u))
|
542
|
542
|
#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u))
|
543
|
543
|
#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u))
|
544
|
544
|
#define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d))
|
545
|
|
-#else
|
|
545
|
+#if 0
|
546
|
546
|
#define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u))
|
547
|
547
|
#define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u))
|
548
|
548
|
#define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u))
|
...
|
...
|
@@ -3141,10 +3141,12 @@ DUK_INTERNAL_DECL duk_bool_t duk_float_equals(duk_float_t x, duk_float_t y);
|
3141
|
3141
|
/* JSON */
|
3142
|
3142
|
#define DUK_STR_FMT_PTR "%p"
|
3143
|
3143
|
#define DUK_STR_FMT_INVALID_JSON "invalid json (at offset %ld)"
|
3144
|
|
-#define DUK_STR_JSONDEC_RECLIMIT "json decode recursion limit"
|
3145
|
|
-#define DUK_STR_JSONENC_RECLIMIT "json encode recursion limit"
|
3146
|
3144
|
#define DUK_STR_CYCLIC_INPUT "cyclic input"
|
3147
|
3145
|
|
|
3146
|
+/* Generic codec */
|
|
3147
|
+#define DUK_STR_DEC_RECLIMIT "decode recursion limit"
|
|
3148
|
+#define DUK_STR_ENC_RECLIMIT "encode recursion limit"
|
|
3149
|
+
|
3148
|
3150
|
/* Object property access */
|
3149
|
3151
|
#define DUK_STR_INVALID_BASE "invalid base value"
|
3150
|
3152
|
#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'"
|
...
|
...
|
@@ -11289,14 +11291,14 @@ DUK_INTERNAL const duk_uint8_t duk_builtins_data[4281] = {
|
11289
|
11291
|
137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35,
|
11290
|
11292
|
23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165,
|
11291
|
11293
|
19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70,
|
11292
|
|
-72,115,96,0,0,0,0,0,2,234,32,91,60,165,195,201,194,8,134,149,216,162,0,192,
|
11293
|
|
-41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176,195,
|
11294
|
|
-192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20,1,
|
11295
|
|
-119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219,36,
|
11296
|
|
-98,232,237,156,13,26,208,211,14,102,19,87,137,91,95,128,0,10,96,24,92,0,0,
|
11297
|
|
-83,2,53,56,0,0,165,3,28,204,160,160,226,100,226,200,211,76,241,240,0,1,102,
|
11298
|
|
-8,22,75,64,137,73,20,230,105,133,7,19,39,22,70,154,103,143,128,0,11,48,20,
|
11299
|
|
-28,76,156,113,75,34,78,62,0,0,45,3,103,31,0,0,22,65,44,57,137,62,33,179,
|
|
11294
|
+72,115,96,0,0,0,0,0,15,106,32,91,60,165,195,201,194,8,134,149,216,162,0,
|
|
11295
|
+192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176,
|
|
11296
|
+195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20,
|
|
11297
|
+1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219,
|
|
11298
|
+36,98,232,237,156,13,26,208,211,14,102,19,87,137,91,95,128,0,10,96,24,92,0,
|
|
11299
|
+0,83,2,53,56,0,0,165,3,28,204,160,160,226,100,226,200,211,76,241,240,0,1,
|
|
11300
|
+102,8,22,75,64,137,73,20,230,105,133,7,19,39,22,70,154,103,143,128,0,11,48,
|
|
11301
|
+20,28,76,156,113,75,34,78,62,0,0,45,3,103,31,0,0,22,65,44,57,137,62,33,179,
|
11300
|
11302
|
216,162,152,192,131,18,124,162,27,61,138,41,108,32,196,159,16,217,232,235,
|
11301
|
11303
|
81,76,104,73,137,62,81,13,158,142,181,20,184,16,98,79,136,108,244,244,168,
|
11302
|
11304
|
166,56,36,196,159,40,134,207,79,74,138,93,10,49,39,194,173,192,158,158,149,
|
...
|
...
|
@@ -11489,7 +11491,7 @@ DUK_INTERNAL const duk_uint8_t duk_builtins_data[4281] = {
|
11489
|
11491
|
137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35,
|
11490
|
11492
|
23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165,
|
11491
|
11493
|
19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70,
|
11492
|
|
-72,115,96,32,106,2,128,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0,
|
|
11494
|
+72,115,96,32,106,15,0,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0,
|
11493
|
11495
|
192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176,
|
11494
|
11496
|
195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20,
|
11495
|
11497
|
1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219,
|
...
|
...
|
@@ -11689,14 +11691,14 @@ DUK_INTERNAL const duk_uint8_t duk_builtins_data[4281] = {
|
11689
|
11691
|
137,194,70,46,142,68,165,19,236,1,64,174,187,161,95,37,134,204,23,225,35,
|
11690
|
11692
|
23,71,34,82,137,246,128,160,89,93,208,167,147,195,201,194,70,46,142,68,165,
|
11691
|
11693
|
19,238,1,64,182,187,161,71,105,20,19,177,139,163,145,41,68,16,7,6,15,82,70,
|
11692
|
|
-72,115,96,0,2,234,32,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0,192,
|
11693
|
|
-41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176,195,
|
11694
|
|
-192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20,1,
|
11695
|
|
-119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219,36,
|
11696
|
|
-98,232,237,156,13,26,208,211,14,102,19,87,137,91,95,128,0,10,96,24,92,0,0,
|
11697
|
|
-83,2,53,56,0,0,165,3,28,204,160,160,226,100,226,200,211,76,241,240,0,1,102,
|
11698
|
|
-8,22,75,64,137,73,20,230,105,133,7,19,39,22,70,154,103,143,128,0,11,48,20,
|
11699
|
|
-28,76,156,113,75,34,78,62,0,0,45,3,103,31,0,0,22,65,44,57,137,62,33,179,
|
|
11694
|
+72,115,96,0,15,106,32,0,0,0,0,91,60,165,195,201,194,8,134,149,216,162,0,
|
|
11695
|
+192,41,225,8,2,48,177,36,1,149,13,196,15,0,200,209,97,199,128,99,32,176,
|
|
11696
|
+195,192,113,57,143,0,167,133,32,230,80,28,202,139,175,238,2,48,189,192,20,
|
|
11697
|
+1,119,80,87,193,186,129,89,56,72,197,209,200,193,185,35,23,71,109,13,219,
|
|
11698
|
+36,98,232,237,156,13,26,208,211,14,102,19,87,137,91,95,128,0,10,96,24,92,0,
|
|
11699
|
+0,83,2,53,56,0,0,165,3,28,204,160,160,226,100,226,200,211,76,241,240,0,1,
|
|
11700
|
+102,8,22,75,64,137,73,20,230,105,133,7,19,39,22,70,154,103,143,128,0,11,48,
|
|
11701
|
+20,28,76,156,113,75,34,78,62,0,0,45,3,103,31,0,0,22,65,44,57,137,62,33,179,
|
11700
|
11702
|
216,162,152,192,131,18,124,162,27,61,138,41,108,32,196,159,16,217,232,235,
|
11701
|
11703
|
81,76,104,73,137,62,81,13,158,142,181,20,184,16,98,79,136,108,244,244,168,
|
11702
|
11704
|
166,56,36,196,159,40,134,207,79,74,138,93,10,49,39,194,173,192,158,158,149,
|
...
|
...
|
@@ -16443,6 +16445,7 @@ struct duk_internal_thread_state {
|
16443
|
16445
|
duk_ljstate lj;
|
16444
|
16446
|
duk_bool_t creating_error;
|
16445
|
16447
|
duk_hthread *curr_thread;
|
|
16448
|
+ duk_uint8_t thread_state;
|
16446
|
16449
|
duk_int_t call_recursion_depth;
|
16447
|
16450
|
};
|
16448
|
16451
|
|
...
|
...
|
@@ -16541,6 +16544,7 @@ DUK_EXTERNAL void duk_suspend(duk_hthread *thr, duk_thread_state *state) {
|
16541
|
16544
|
duk_memcpy((void *) &snapshot->lj, (const void *) lj, sizeof(duk_ljstate));
|
16542
|
16545
|
snapshot->creating_error = heap->creating_error;
|
16543
|
16546
|
snapshot->curr_thread = heap->curr_thread;
|
|
16547
|
+ snapshot->thread_state = thr->state;
|
16544
|
16548
|
snapshot->call_recursion_depth = heap->call_recursion_depth;
|
16545
|
16549
|
|
16546
|
16550
|
lj->jmpbuf_ptr = NULL;
|
...
|
...
|
@@ -16550,6 +16554,8 @@ DUK_EXTERNAL void duk_suspend(duk_hthread *thr, duk_thread_state *state) {
|
16550
|
16554
|
heap->creating_error = 0;
|
16551
|
16555
|
heap->curr_thread = NULL;
|
16552
|
16556
|
heap->call_recursion_depth = 0;
|
|
16557
|
+
|
|
16558
|
+ thr->state = DUK_HTHREAD_STATE_INACTIVE;
|
16553
|
16559
|
}
|
16554
|
16560
|
|
16555
|
16561
|
DUK_EXTERNAL void duk_resume(duk_hthread *thr, const duk_thread_state *state) {
|
...
|
...
|
@@ -16566,6 +16572,8 @@ DUK_EXTERNAL void duk_resume(duk_hthread *thr, const duk_thread_state *state) {
|
16566
|
16572
|
DUK_ASSERT(thr->heap->pf_prevent_count == 0);
|
16567
|
16573
|
DUK_ASSERT(thr->heap->creating_error == 0);
|
16568
|
16574
|
|
|
16575
|
+ thr->state = snapshot->thread_state;
|
|
16576
|
+
|
16569
|
16577
|
heap = thr->heap;
|
16570
|
16578
|
|
16571
|
16579
|
duk_memcpy((void *) &heap->lj, (const void *) &snapshot->lj, sizeof(duk_ljstate));
|
...
|
...
|
@@ -20026,7 +20034,7 @@ DUK_EXTERNAL void *duk_require_buffer(duk_hthread *thr, duk_idx_t idx, duk_size_
|
20026
|
20034
|
}
|
20027
|
20035
|
|
20028
|
20036
|
/* Get the active buffer data area for a plain buffer or a buffer object.
|
20029
|
|
- * Return NULL if the value is not a buffer. Note that a buffer may
|
|
20037
|
+ * Return NULL if the the value is not a buffer. Note that a buffer may
|
20030
|
20038
|
* have a NULL data pointer when its size is zero, the optional 'out_isbuffer'
|
20031
|
20039
|
* argument allows caller to detect this reliably.
|
20032
|
20040
|
*/
|
...
|
...
|
@@ -30090,6 +30098,8 @@ typedef struct {
|
30090
|
30098
|
duk_uint8_t *buf_end;
|
30091
|
30099
|
duk_size_t len;
|
30092
|
30100
|
duk_idx_t idx_buf;
|
|
30101
|
+ duk_uint_t recursion_depth;
|
|
30102
|
+ duk_uint_t recursion_limit;
|
30093
|
30103
|
} duk_cbor_encode_context;
|
30094
|
30104
|
|
30095
|
30105
|
typedef struct {
|
...
|
...
|
@@ -30097,6 +30107,8 @@ typedef struct {
|
30097
|
30107
|
const duk_uint8_t *buf;
|
30098
|
30108
|
duk_size_t off;
|
30099
|
30109
|
duk_size_t len;
|
|
30110
|
+ duk_uint_t recursion_depth;
|
|
30111
|
+ duk_uint_t recursion_limit;
|
30100
|
30112
|
} duk_cbor_decode_context;
|
30101
|
30113
|
|
30102
|
30114
|
DUK_LOCAL void duk__cbor_encode_value(duk_cbor_encode_context *enc_ctx);
|
...
|
...
|
@@ -30120,6 +30132,34 @@ DUK_LOCAL void duk__cbor_encode_error(duk_cbor_encode_context *enc_ctx) {
|
30120
|
30132
|
(void) duk_type_error(enc_ctx->thr, "cbor encode error");
|
30121
|
30133
|
}
|
30122
|
30134
|
|
|
30135
|
+DUK_LOCAL void duk__cbor_encode_req_stack(duk_cbor_encode_context *enc_ctx) {
|
|
30136
|
+ duk_require_stack(enc_ctx->thr, 4);
|
|
30137
|
+}
|
|
30138
|
+
|
|
30139
|
+DUK_LOCAL void duk__cbor_encode_objarr_entry(duk_cbor_encode_context *enc_ctx) {
|
|
30140
|
+ duk_hthread *thr = enc_ctx->thr;
|
|
30141
|
+
|
|
30142
|
+ /* Native stack check in object/array recursion. */
|
|
30143
|
+ duk_native_stack_check(thr);
|
|
30144
|
+
|
|
30145
|
+ /* When working with deeply recursive structures, this is important
|
|
30146
|
+ * to ensure there's no effective depth limit.
|
|
30147
|
+ */
|
|
30148
|
+ duk__cbor_encode_req_stack(enc_ctx);
|
|
30149
|
+
|
|
30150
|
+ DUK_ASSERT(enc_ctx->recursion_depth <= enc_ctx->recursion_limit);
|
|
30151
|
+ if (enc_ctx->recursion_depth >= enc_ctx->recursion_limit) {
|
|
30152
|
+ DUK_ERROR_RANGE(thr, DUK_STR_ENC_RECLIMIT);
|
|
30153
|
+ DUK_WO_NORETURN(return;);
|
|
30154
|
+ }
|
|
30155
|
+ enc_ctx->recursion_depth++;
|
|
30156
|
+}
|
|
30157
|
+
|
|
30158
|
+DUK_LOCAL void duk__cbor_encode_objarr_exit(duk_cbor_encode_context *enc_ctx) {
|
|
30159
|
+ DUK_ASSERT(enc_ctx->recursion_depth > 0);
|
|
30160
|
+ enc_ctx->recursion_depth--;
|
|
30161
|
+}
|
|
30162
|
+
|
30123
|
30163
|
/* Check that a size_t is in uint32 range to avoid out-of-range casts. */
|
30124
|
30164
|
DUK_LOCAL void duk__cbor_encode_sizet_uint32_check(duk_cbor_encode_context *enc_ctx, duk_size_t len) {
|
30125
|
30165
|
if (DUK_UNLIKELY(sizeof(duk_size_t) > sizeof(duk_uint32_t) && len > (duk_size_t) DUK_UINT32_MAX)) {
|
...
|
...
|
@@ -30522,6 +30562,8 @@ DUK_LOCAL void duk__cbor_encode_object(duk_cbor_encode_context *enc_ctx) {
|
30522
|
30562
|
/* Caller must ensure space. */
|
30523
|
30563
|
DUK_ASSERT(duk__cbor_get_reserve(enc_ctx) >= 1 + 8);
|
30524
|
30564
|
|
|
30565
|
+ duk__cbor_encode_objarr_entry(enc_ctx);
|
|
30566
|
+
|
30525
|
30567
|
/* XXX: Support for specific built-ins like Date and RegExp. */
|
30526
|
30568
|
if (duk_is_array(enc_ctx->thr, -1)) {
|
30527
|
30569
|
/* Shortest encoding for arrays >= 256 in length is actually
|
...
|
...
|
@@ -30546,7 +30588,7 @@ DUK_LOCAL void duk__cbor_encode_object(duk_cbor_encode_context *enc_ctx) {
|
30546
|
30588
|
duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, 0x40U);
|
30547
|
30589
|
duk__cbor_encode_ensure(enc_ctx, len);
|
30548
|
30590
|
p = enc_ctx->ptr;
|
30549
|
|
- duk_memcpy((void *) p, (const void *) buf, len);
|
|
30591
|
+ duk_memcpy_unsafe((void *) p, (const void *) buf, len);
|
30550
|
30592
|
p += len;
|
30551
|
30593
|
enc_ctx->ptr = p;
|
30552
|
30594
|
} else {
|
...
|
...
|
@@ -30585,6 +30627,8 @@ DUK_LOCAL void duk__cbor_encode_object(duk_cbor_encode_context *enc_ctx) {
|
30585
|
30627
|
enc_ctx->ptr = p;
|
30586
|
30628
|
}
|
30587
|
30629
|
}
|
|
30630
|
+
|
|
30631
|
+ duk__cbor_encode_objarr_exit(enc_ctx);
|
30588
|
30632
|
}
|
30589
|
30633
|
|
30590
|
30634
|
DUK_LOCAL void duk__cbor_encode_buffer(duk_cbor_encode_context *enc_ctx) {
|
...
|
...
|
@@ -30601,7 +30645,7 @@ DUK_LOCAL void duk__cbor_encode_buffer(duk_cbor_encode_context *enc_ctx) {
|
30601
|
30645
|
duk__cbor_encode_uint32(enc_ctx, (duk_uint32_t) len, 0x40U);
|
30602
|
30646
|
duk__cbor_encode_ensure(enc_ctx, len);
|
30603
|
30647
|
p = enc_ctx->ptr;
|
30604
|
|
- duk_memcpy((void *) p, (const void *) buf, len);
|
|
30648
|
+ duk_memcpy_unsafe((void *) p, (const void *) buf, len);
|
30605
|
30649
|
p += len;
|
30606
|
30650
|
enc_ctx->ptr = p;
|
30607
|
30651
|
}
|
...
|
...
|
@@ -30648,11 +30692,6 @@ DUK_LOCAL void duk__cbor_encode_value(duk_cbor_encode_context *enc_ctx) {
|
30648
|
30692
|
* This can be improved by registering custom tags with IANA.
|
30649
|
30693
|
*/
|
30650
|
30694
|
|
30651
|
|
- /* When working with deeply recursive structures, this is important
|
30652
|
|
- * to ensure there's no effective depth limit.
|
30653
|
|
- */
|
30654
|
|
- duk_require_stack(enc_ctx->thr, 4);
|
30655
|
|
-
|
30656
|
30695
|
/* Reserve space for up to 64-bit types (1 initial byte + 8
|
30657
|
30696
|
* followup bytes). This allows encoding of integers, floats,
|
30658
|
30697
|
* string/buffer length fields, etc without separate checks
|
...
|
...
|
@@ -30720,12 +30759,33 @@ DUK_LOCAL void duk__cbor_encode_value(duk_cbor_encode_context *enc_ctx) {
|
30720
|
30759
|
* Decoding
|
30721
|
30760
|
*/
|
30722
|
30761
|
|
30723
|
|
-DUK_LOCAL void duk__cbor_req_stack(duk_cbor_decode_context *dec_ctx) {
|
|
30762
|
+DUK_LOCAL void duk__cbor_decode_error(duk_cbor_decode_context *dec_ctx) {
|
|
30763
|
+ (void) duk_type_error(dec_ctx->thr, "cbor decode error");
|
|
30764
|
+}
|
|
30765
|
+
|
|
30766
|
+DUK_LOCAL void duk__cbor_decode_req_stack(duk_cbor_decode_context *dec_ctx) {
|
30724
|
30767
|
duk_require_stack(dec_ctx->thr, 4);
|
30725
|
30768
|
}
|
30726
|
30769
|
|
30727
|
|
-DUK_LOCAL void duk__cbor_decode_error(duk_cbor_decode_context *dec_ctx) {
|
30728
|
|
- (void) duk_type_error(dec_ctx->thr, "cbor decode error");
|
|
30770
|
+DUK_LOCAL void duk__cbor_decode_objarr_entry(duk_cbor_decode_context *dec_ctx) {
|
|
30771
|
+ duk_hthread *thr = dec_ctx->thr;
|
|
30772
|
+
|
|
30773
|
+ /* Native stack check in object/array recursion. */
|
|
30774
|
+ duk_native_stack_check(thr);
|
|
30775
|
+
|
|
30776
|
+ duk__cbor_decode_req_stack(dec_ctx);
|
|
30777
|
+
|
|
30778
|
+ DUK_ASSERT(dec_ctx->recursion_depth <= dec_ctx->recursion_limit);
|
|
30779
|
+ if (dec_ctx->recursion_depth >= dec_ctx->recursion_limit) {
|
|
30780
|
+ DUK_ERROR_RANGE(thr, DUK_STR_DEC_RECLIMIT);
|
|
30781
|
+ DUK_WO_NORETURN(return;);
|
|
30782
|
+ }
|
|
30783
|
+ dec_ctx->recursion_depth++;
|
|
30784
|
+}
|
|
30785
|
+
|
|
30786
|
+DUK_LOCAL void duk__cbor_decode_objarr_exit(duk_cbor_decode_context *dec_ctx) {
|
|
30787
|
+ DUK_ASSERT(dec_ctx->recursion_depth > 0);
|
|
30788
|
+ dec_ctx->recursion_depth--;
|
30729
|
30789
|
}
|
30730
|
30790
|
|
30731
|
30791
|
DUK_LOCAL duk_uint8_t duk__cbor_decode_readbyte(duk_cbor_decode_context *dec_ctx) {
|
...
|
...
|
@@ -31004,9 +31064,7 @@ DUK_LOCAL void duk__cbor_decode_join_buffers(duk_cbor_decode_context *dec_ctx, d
|
31004
|
31064
|
|
31005
|
31065
|
buf_data = (duk_uint8_t *) duk_require_buffer(dec_ctx->thr, idx, &buf_size);
|
31006
|
31066
|
if (p != NULL) {
|
31007
|
|
- if (buf_size > 0U) {
|
31008
|
|
- duk_memcpy((void *) p, (const void *) buf_data, buf_size);
|
31009
|
|
- }
|
|
31067
|
+ duk_memcpy_unsafe((void *) p, (const void *) buf_data, buf_size);
|
31010
|
31068
|
p += buf_size;
|
31011
|
31069
|
} else {
|
31012
|
31070
|
total_size += buf_size;
|
...
|
...
|
@@ -31171,7 +31229,7 @@ DUK_LOCAL void duk__cbor_decode_string(duk_cbor_decode_context *dec_ctx, duk_uin
|
31171
|
31229
|
DUK_LOCAL duk_bool_t duk__cbor_decode_array(duk_cbor_decode_context *dec_ctx, duk_uint8_t ib, duk_uint8_t ai) {
|
31172
|
31230
|
duk_uint32_t idx, len;
|
31173
|
31231
|
|
31174
|
|
- duk__cbor_req_stack(dec_ctx);
|
|
31232
|
+ duk__cbor_decode_objarr_entry(dec_ctx);
|
31175
|
31233
|
|
31176
|
31234
|
/* Support arrays up to 0xfffffffeU in length. 0xffffffff is
|
31177
|
31235
|
* used as an indefinite length marker.
|
...
|
...
|
@@ -31181,7 +31239,7 @@ DUK_LOCAL duk_bool_t duk__cbor_decode_array(duk_cbor_decode_context *dec_ctx, du
|
31181
|
31239
|
} else {
|
31182
|
31240
|
len = duk__cbor_decode_aival_uint32(dec_ctx, ib);
|
31183
|
31241
|
if (len == 0xffffffffUL) {
|
31184
|
|
- return 0;
|
|
31242
|
+ goto failure;
|
31185
|
31243
|
}
|
31186
|
31244
|
}
|
31187
|
31245
|
|
...
|
...
|
@@ -31193,7 +31251,7 @@ DUK_LOCAL duk_bool_t duk__cbor_decode_array(duk_cbor_decode_context *dec_ctx, du
|
31193
|
31251
|
}
|
31194
|
31252
|
if (idx == len) {
|
31195
|
31253
|
if (ai == 0x1fU) {
|
31196
|
|
- return 0;
|
|
31254
|
+ goto failure;
|
31197
|
31255
|
}
|
31198
|
31256
|
break;
|
31199
|
31257
|
}
|
...
|
...
|
@@ -31201,24 +31259,32 @@ DUK_LOCAL duk_bool_t duk__cbor_decode_array(duk_cbor_decode_context *dec_ctx, du
|
31201
|
31259
|
duk_put_prop_index(dec_ctx->thr, -2, (duk_uarridx_t) idx);
|
31202
|
31260
|
idx++;
|
31203
|
31261
|
if (idx == 0U) {
|
31204
|
|
- return 0; /* wrapped */
|
|
31262
|
+ goto failure; /* wrapped */
|
31205
|
31263
|
}
|
31206
|
31264
|
}
|
31207
|
31265
|
|
|
31266
|
+#if 0
|
|
31267
|
+ success:
|
|
31268
|
+#endif
|
|
31269
|
+ duk__cbor_decode_objarr_exit(dec_ctx);
|
31208
|
31270
|
return 1;
|
|
31271
|
+
|
|
31272
|
+ failure:
|
|
31273
|
+ /* No need to unwind recursion checks, caller will throw. */
|
|
31274
|
+ return 0;
|
31209
|
31275
|
}
|
31210
|
31276
|
|
31211
|
31277
|
DUK_LOCAL duk_bool_t duk__cbor_decode_map(duk_cbor_decode_context *dec_ctx, duk_uint8_t ib, duk_uint8_t ai) {
|
31212
|
31278
|
duk_uint32_t count;
|
31213
|
31279
|
|
31214
|
|
- duk__cbor_req_stack(dec_ctx);
|
|
31280
|
+ duk__cbor_decode_objarr_entry(dec_ctx);
|
31215
|
31281
|
|
31216
|
31282
|
if (ai == 0x1fU) {
|
31217
|
31283
|
count = 0xffffffffUL;
|
31218
|
31284
|
} else {
|
31219
|
31285
|
count = duk__cbor_decode_aival_uint32(dec_ctx, ib);
|
31220
|
31286
|
if (count == 0xffffffffUL) {
|
31221
|
|
- return 0;
|
|
31287
|
+ goto failure;
|
31222
|
31288
|
}
|
31223
|
31289
|
}
|
31224
|
31290
|
|
...
|
...
|
@@ -31249,7 +31315,15 @@ DUK_LOCAL duk_bool_t duk__cbor_decode_map(duk_cbor_decode_context *dec_ctx, duk_
|
31249
|
31315
|
duk_put_prop(dec_ctx->thr, -3);
|
31250
|
31316
|
}
|
31251
|
31317
|
|
|
31318
|
+#if 0
|
|
31319
|
+ success:
|
|
31320
|
+#endif
|
|
31321
|
+ duk__cbor_decode_objarr_exit(dec_ctx);
|
31252
|
31322
|
return 1;
|
|
31323
|
+
|
|
31324
|
+ failure:
|
|
31325
|
+ /* No need to unwind recursion checks, caller will throw. */
|
|
31326
|
+ return 0;
|
31253
|
31327
|
}
|
31254
|
31328
|
|
31255
|
31329
|
DUK_LOCAL duk_double_t duk__cbor_decode_float(duk_cbor_decode_context *dec_ctx) {
|
...
|
...
|
@@ -31626,8 +31700,13 @@ DUK_LOCAL void duk__cbor_encode(duk_hthread *thr, duk_idx_t idx, duk_uint_t enco
|
31626
|
31700
|
enc_ctx.buf = buf;
|
31627
|
31701
|
enc_ctx.buf_end = buf + enc_ctx.len;
|
31628
|
31702
|
|
|
31703
|
+ enc_ctx.recursion_depth = 0;
|
|
31704
|
+ enc_ctx.recursion_limit = DUK_USE_CBOR_ENC_RECLIMIT;
|
|
31705
|
+
|
31629
|
31706
|
duk_dup(thr, idx);
|
|
31707
|
+ duk__cbor_encode_req_stack(&enc_ctx);
|
31630
|
31708
|
duk__cbor_encode_value(&enc_ctx);
|
|
31709
|
+ DUK_ASSERT(enc_ctx.recursion_depth == 0);
|
31631
|
31710
|
duk_resize_buffer(enc_ctx.thr, enc_ctx.idx_buf, (duk_size_t) (enc_ctx.ptr - enc_ctx.buf));
|
31632
|
31711
|
duk_replace(thr, idx);
|
31633
|
31712
|
}
|
...
|
...
|
@@ -31649,8 +31728,12 @@ DUK_LOCAL void duk__cbor_decode(duk_hthread *thr, duk_idx_t idx, duk_uint_t deco
|
31649
|
31728
|
dec_ctx.off = 0;
|
31650
|
31729
|
/* dec_ctx.len: set above */
|
31651
|
31730
|
|
31652
|
|
- duk__cbor_req_stack(&dec_ctx);
|
|
31731
|
+ dec_ctx.recursion_depth = 0;
|
|
31732
|
+ dec_ctx.recursion_limit = DUK_USE_CBOR_DEC_RECLIMIT;
|
|
31733
|
+
|
|
31734
|
+ duk__cbor_decode_req_stack(&dec_ctx);
|
31653
|
31735
|
duk__cbor_decode_value(&dec_ctx);
|
|
31736
|
+ DUK_ASSERT(dec_ctx.recursion_depth == 0);
|
31654
|
31737
|
if (dec_ctx.off != dec_ctx.len) {
|
31655
|
31738
|
(void) duk_type_error(thr, "trailing garbage");
|
31656
|
31739
|
}
|
...
|
...
|
@@ -36373,28 +36456,28 @@ DUK_INTERNAL duk_ret_t duk_bi_global_object_unescape(duk_hthread *thr) {
|
36373
|
36456
|
#define DUK__JSON_STRINGIFY_BUFSIZE 128
|
36374
|
36457
|
#define DUK__JSON_MAX_ESC_LEN 10 /* '\Udeadbeef' */
|
36375
|
36458
|
|
36376
|
|
-DUK_LOCAL_DECL void duk__dec_syntax_error(duk_json_dec_ctx *js_ctx);
|
36377
|
|
-DUK_LOCAL_DECL void duk__dec_eat_white(duk_json_dec_ctx *js_ctx);
|
|
36459
|
+DUK_LOCAL_DECL void duk__json_dec_syntax_error(duk_json_dec_ctx *js_ctx);
|
|
36460
|
+DUK_LOCAL_DECL void duk__json_dec_eat_white(duk_json_dec_ctx *js_ctx);
|
36378
|
36461
|
#if defined(DUK_USE_JX)
|
36379
|
|
-DUK_LOCAL_DECL duk_uint8_t duk__dec_peek(duk_json_dec_ctx *js_ctx);
|
|
36462
|
+DUK_LOCAL_DECL duk_uint8_t duk__json_dec_peek(duk_json_dec_ctx *js_ctx);
|
36380
|
36463
|
#endif
|
36381
|
|
-DUK_LOCAL_DECL duk_uint8_t duk__dec_get(duk_json_dec_ctx *js_ctx);
|
36382
|
|
-DUK_LOCAL_DECL duk_uint8_t duk__dec_get_nonwhite(duk_json_dec_ctx *js_ctx);
|
36383
|
|
-DUK_LOCAL_DECL duk_uint_fast32_t duk__dec_decode_hex_escape(duk_json_dec_ctx *js_ctx, duk_small_uint_t n);
|
36384
|
|
-DUK_LOCAL_DECL void duk__dec_req_stridx(duk_json_dec_ctx *js_ctx, duk_small_uint_t stridx);
|
36385
|
|
-DUK_LOCAL_DECL void duk__dec_string(duk_json_dec_ctx *js_ctx);
|
|
36464
|
+DUK_LOCAL_DECL duk_uint8_t duk__json_dec_get(duk_json_dec_ctx *js_ctx);
|
|
36465
|
+DUK_LOCAL_DECL duk_uint8_t duk__json_dec_get_nonwhite(duk_json_dec_ctx *js_ctx);
|
|
36466
|
+DUK_LOCAL_DECL duk_uint_fast32_t duk__json_dec_decode_hex_escape(duk_json_dec_ctx *js_ctx, duk_small_uint_t n);
|
|
36467
|
+DUK_LOCAL_DECL void duk__json_dec_req_stridx(duk_json_dec_ctx *js_ctx, duk_small_uint_t stridx);
|
|
36468
|
+DUK_LOCAL_DECL void duk__json_dec_string(duk_json_dec_ctx *js_ctx);
|
36386
|
36469
|
#if defined(DUK_USE_JX)
|
36387
|
|
-DUK_LOCAL_DECL void duk__dec_plain_string(duk_json_dec_ctx *js_ctx);
|
36388
|
|
-DUK_LOCAL_DECL void duk__dec_pointer(duk_json_dec_ctx *js_ctx);
|
36389
|
|
-DUK_LOCAL_DECL void duk__dec_buffer(duk_json_dec_ctx *js_ctx);
|
36390
|
|
-#endif
|
36391
|
|
-DUK_LOCAL_DECL void duk__dec_number(duk_json_dec_ctx *js_ctx);
|
36392
|
|
-DUK_LOCAL_DECL void duk__dec_objarr_entry(duk_json_dec_ctx *js_ctx);
|
36393
|
|
-DUK_LOCAL_DECL void duk__dec_objarr_exit(duk_json_dec_ctx *js_ctx);
|
36394
|
|
-DUK_LOCAL_DECL void duk__dec_object(duk_json_dec_ctx *js_ctx);
|
36395
|
|
-DUK_LOCAL_DECL void duk__dec_array(duk_json_dec_ctx *js_ctx);
|
36396
|
|
-DUK_LOCAL_DECL void duk__dec_value(duk_json_dec_ctx *js_ctx);
|
36397
|
|
-DUK_LOCAL_DECL void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx);
|
|
36470
|
+DUK_LOCAL_DECL void duk__json_dec_plain_string(duk_json_dec_ctx *js_ctx);
|
|
36471
|
+DUK_LOCAL_DECL void duk__json_dec_pointer(duk_json_dec_ctx *js_ctx);
|
|
36472
|
+DUK_LOCAL_DECL void duk__json_dec_buffer(duk_json_dec_ctx *js_ctx);
|
|
36473
|
+#endif
|
|
36474
|
+DUK_LOCAL_DECL void duk__json_dec_number(duk_json_dec_ctx *js_ctx);
|
|
36475
|
+DUK_LOCAL_DECL void duk__json_dec_objarr_entry(duk_json_dec_ctx *js_ctx);
|
|
36476
|
+DUK_LOCAL_DECL void duk__json_dec_objarr_exit(duk_json_dec_ctx *js_ctx);
|
|
36477
|
+DUK_LOCAL_DECL void duk__json_dec_object(duk_json_dec_ctx *js_ctx);
|
|
36478
|
+DUK_LOCAL_DECL void duk__json_dec_array(duk_json_dec_ctx *js_ctx);
|
|
36479
|
+DUK_LOCAL_DECL void duk__json_dec_value(duk_json_dec_ctx *js_ctx);
|
|
36480
|
+DUK_LOCAL_DECL void duk__json_dec_reviver_walk(duk_json_dec_ctx *js_ctx);
|
36398
|
36481
|
|
36399
|
36482
|
DUK_LOCAL_DECL void duk__emit_1(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch);
|
36400
|
36483
|
DUK_LOCAL_DECL void duk__emit_2(duk_json_enc_ctx *js_ctx, duk_uint_fast8_t ch1, duk_uint_fast8_t ch2);
|
...
|
...
|
@@ -36405,29 +36488,29 @@ DUK_LOCAL_DECL void duk__emit_cstring(duk_json_enc_ctx *js_ctx, const char *p);
|
36405
|
36488
|
#endif
|
36406
|
36489
|
DUK_LOCAL_DECL void duk__emit_stridx(duk_json_enc_ctx *js_ctx, duk_small_uint_t stridx);
|
36407
|
36490
|
DUK_LOCAL_DECL duk_uint8_t *duk__emit_esc_auto_fast(duk_json_enc_ctx *js_ctx, duk_uint_fast32_t cp, duk_uint8_t *q);
|
36408
|
|
-DUK_LOCAL_DECL void duk__enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k);
|
36409
|
|
-DUK_LOCAL_DECL void duk__enc_quote_string(duk_json_enc_ctx *js_ctx, duk_hstring *h_str);
|
36410
|
|
-DUK_LOCAL_DECL void duk__enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top);
|
36411
|
|
-DUK_LOCAL_DECL void duk__enc_objarr_exit(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top);
|
36412
|
|
-DUK_LOCAL_DECL void duk__enc_object(duk_json_enc_ctx *js_ctx);
|
36413
|
|
-DUK_LOCAL_DECL void duk__enc_array(duk_json_enc_ctx *js_ctx);
|
36414
|
|
-DUK_LOCAL_DECL duk_bool_t duk__enc_value(duk_json_enc_ctx *js_ctx, duk_idx_t idx_holder);
|
36415
|
|
-DUK_LOCAL_DECL duk_bool_t duk__enc_allow_into_proplist(duk_tval *tv);
|
36416
|
|
-DUK_LOCAL_DECL void duk__enc_double(duk_json_enc_ctx *js_ctx);
|
|
36491
|
+DUK_LOCAL_DECL void duk__json_enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k);
|
|
36492
|
+DUK_LOCAL_DECL void duk__json_enc_quote_string(duk_json_enc_ctx *js_ctx, duk_hstring *h_str);
|
|
36493
|
+DUK_LOCAL_DECL void duk__json_enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top);
|
|
36494
|
+DUK_LOCAL_DECL void duk__json_enc_objarr_exit(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top);
|
|
36495
|
+DUK_LOCAL_DECL void duk__json_enc_object(duk_json_enc_ctx *js_ctx);
|
|
36496
|
+DUK_LOCAL_DECL void duk__json_enc_array(duk_json_enc_ctx *js_ctx);
|
|
36497
|
+DUK_LOCAL_DECL duk_bool_t duk__json_enc_value(duk_json_enc_ctx *js_ctx, duk_idx_t idx_holder);
|
|
36498
|
+DUK_LOCAL_DECL duk_bool_t duk__json_enc_allow_into_proplist(duk_tval *tv);
|
|
36499
|
+DUK_LOCAL_DECL void duk__json_enc_double(duk_json_enc_ctx *js_ctx);
|
36417
|
36500
|
#if defined(DUK_USE_FASTINT)
|
36418
|
|
-DUK_LOCAL_DECL void duk__enc_fastint_tval(duk_json_enc_ctx *js_ctx, duk_tval *tv);
|
|
36501
|
+DUK_LOCAL_DECL void duk__json_enc_fastint_tval(duk_json_enc_ctx *js_ctx, duk_tval *tv);
|
36419
|
36502
|
#endif
|
36420
|
36503
|
#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
|
36421
|
|
-DUK_LOCAL_DECL void duk__enc_buffer_jx_jc(duk_json_enc_ctx *js_ctx, duk_hbuffer *h);
|
36422
|
|
-DUK_LOCAL_DECL void duk__enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr);
|
|
36504
|
+DUK_LOCAL_DECL void duk__json_enc_buffer_jx_jc(duk_json_enc_ctx *js_ctx, duk_hbuffer *h);
|
|
36505
|
+DUK_LOCAL_DECL void duk__json_enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr);
|
36423
|
36506
|
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
|
36424
|
|
-DUK_LOCAL_DECL void duk__enc_bufobj(duk_json_enc_ctx *js_ctx, duk_hbufobj *h_bufobj);
|
|
36507
|
+DUK_LOCAL_DECL void duk__json_enc_bufobj(duk_json_enc_ctx *js_ctx, duk_hbufobj *h_bufobj);
|
36425
|
36508
|
#endif
|
36426
|
36509
|
#endif
|
36427
|
36510
|
#if defined(DUK_USE_JSON_STRINGIFY_FASTPATH)
|
36428
|
|
-DUK_LOCAL_DECL void duk__enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuffer *h);
|
|
36511
|
+DUK_LOCAL_DECL void duk__json_enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuffer *h);
|
36429
|
36512
|
#endif
|
36430
|
|
-DUK_LOCAL_DECL void duk__enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth);
|
|
36513
|
+DUK_LOCAL_DECL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth);
|
36431
|
36514
|
|
36432
|
36515
|
/*
|
36433
|
36516
|
* Helper tables
|
...
|
...
|
@@ -36552,7 +36635,7 @@ DUK_LOCAL const duk_uint8_t duk__json_decnumber_lookup[256] = {
|
36552
|
36635
|
* CESU-8 encodings.
|
36553
|
36636
|
*/
|
36554
|
36637
|
|
36555
|
|
-DUK_LOCAL void duk__dec_syntax_error(duk_json_dec_ctx *js_ctx) {
|
|
36638
|
+DUK_LOCAL void duk__json_dec_syntax_error(duk_json_dec_ctx *js_ctx) {
|
36556
|
36639
|
/* Shared handler to minimize parser size. Cause will be
|
36557
|
36640
|
* hidden, unfortunately, but we'll have an offset which
|
36558
|
36641
|
* is often quite enough.
|
...
|
...
|
@@ -36562,7 +36645,7 @@ DUK_LOCAL void duk__dec_syntax_error(duk_json_dec_ctx *js_ctx) {
|
36562
|
36645
|
DUK_WO_NORETURN(return;);
|
36563
|
36646
|
}
|
36564
|
36647
|
|
36565
|
|
-DUK_LOCAL void duk__dec_eat_white(duk_json_dec_ctx *js_ctx) {
|
|
36648
|
+DUK_LOCAL void duk__json_dec_eat_white(duk_json_dec_ctx *js_ctx) {
|
36566
|
36649
|
const duk_uint8_t *p;
|
36567
|
36650
|
duk_uint8_t t;
|
36568
|
36651
|
|
...
|
...
|
@@ -36593,24 +36676,24 @@ DUK_LOCAL void duk__dec_eat_white(duk_json_dec_ctx *js_ctx) {
|
36593
|
36676
|
}
|
36594
|
36677
|
|
36595
|
36678
|
#if defined(DUK_USE_JX)
|
36596
|
|
-DUK_LOCAL duk_uint8_t duk__dec_peek(duk_json_dec_ctx *js_ctx) {
|
|
36679
|
+DUK_LOCAL duk_uint8_t duk__json_dec_peek(duk_json_dec_ctx *js_ctx) {
|
36597
|
36680
|
DUK_ASSERT(js_ctx->p <= js_ctx->p_end);
|
36598
|
36681
|
return *js_ctx->p;
|
36599
|
36682
|
}
|
36600
|
36683
|
#endif
|
36601
|
36684
|
|
36602
|
|
-DUK_LOCAL duk_uint8_t duk__dec_get(duk_json_dec_ctx *js_ctx) {
|
|
36685
|
+DUK_LOCAL duk_uint8_t duk__json_dec_get(duk_json_dec_ctx *js_ctx) {
|
36603
|
36686
|
DUK_ASSERT(js_ctx->p <= js_ctx->p_end);
|
36604
|
36687
|
return *js_ctx->p++;
|
36605
|
36688
|
}
|
36606
|
36689
|
|
36607
|
|
-DUK_LOCAL duk_uint8_t duk__dec_get_nonwhite(duk_json_dec_ctx *js_ctx) {
|
36608
|
|
- duk__dec_eat_white(js_ctx);
|
36609
|
|
- return duk__dec_get(js_ctx);
|
|
36690
|
+DUK_LOCAL duk_uint8_t duk__json_dec_get_nonwhite(duk_json_dec_ctx *js_ctx) {
|
|
36691
|
+ duk__json_dec_eat_white(js_ctx);
|
|
36692
|
+ return duk__json_dec_get(js_ctx);
|
36610
|
36693
|
}
|
36611
|
36694
|
|
36612
|
36695
|
/* For JX, expressing the whole unsigned 32-bit range matters. */
|
36613
|
|
-DUK_LOCAL duk_uint_fast32_t duk__dec_decode_hex_escape(duk_json_dec_ctx *js_ctx, duk_small_uint_t n) {
|
|
36696
|
+DUK_LOCAL duk_uint_fast32_t duk__json_dec_decode_hex_escape(duk_json_dec_ctx *js_ctx, duk_small_uint_t n) {
|
36614
|
36697
|
duk_small_uint_t i;
|
36615
|
36698
|
duk_uint_fast32_t res = 0;
|
36616
|
36699
|
duk_uint8_t x;
|
...
|
...
|
@@ -36619,7 +36702,7 @@ DUK_LOCAL duk_uint_fast32_t duk__dec_decode_hex_escape(duk_json_dec_ctx *js_ctx,
|
36619
|
36702
|
for (i = 0; i < n; i++) {
|
36620
|
36703
|
/* XXX: share helper from lexer; duk_lexer.c / hexval(). */
|
36621
|
36704
|
|
36622
|
|
- x = duk__dec_get(js_ctx);
|
|
36705
|
+ x = duk__json_dec_get(js_ctx);
|
36623
|
36706
|
DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%ld, n=%ld, res=%ld, x=%ld",
|
36624
|
36707
|
(long) i, (long) n, (long) res, (long) x));
|
36625
|
36708
|
|
...
|
...
|
@@ -36638,12 +36721,12 @@ DUK_LOCAL duk_uint_fast32_t duk__dec_decode_hex_escape(duk_json_dec_ctx *js_ctx,
|
36638
|
36721
|
return res;
|
36639
|
36722
|
|
36640
|
36723
|
syntax_error:
|
36641
|
|
- duk__dec_syntax_error(js_ctx);
|
|
36724
|
+ duk__json_dec_syntax_error(js_ctx);
|
36642
|
36725
|
DUK_UNREACHABLE();
|
36643
|
36726
|
return 0;
|
36644
|
36727
|
}
|
36645
|
36728
|
|
36646
|
|
-DUK_LOCAL void duk__dec_req_stridx(duk_json_dec_ctx *js_ctx, duk_small_uint_t stridx) {
|
|
36729
|
+DUK_LOCAL void duk__json_dec_req_stridx(duk_json_dec_ctx *js_ctx, duk_small_uint_t stridx) {
|
36647
|
36730
|
duk_hstring *h;
|
36648
|
36731
|
const duk_uint8_t *p;
|
36649
|
36732
|
duk_uint8_t x, y;
|
...
|
...
|
@@ -36665,7 +36748,7 @@ DUK_LOCAL void duk__dec_req_stridx(duk_json_dec_ctx *js_ctx, duk_small_uint_t st
|
36665
|
36748
|
if (x == 0) {
|
36666
|
36749
|
break;
|
36667
|
36750
|
}
|
36668
|
|
- y = duk__dec_get(js_ctx);
|
|
36751
|
+ y = duk__json_dec_get(js_ctx);
|
36669
|
36752
|
if (x != y) {
|
36670
|
36753
|
/* Catches EOF of JSON input. */
|
36671
|
36754
|
goto syntax_error;
|
...
|
...
|
@@ -36676,18 +36759,18 @@ DUK_LOCAL void duk__dec_req_stridx(duk_json_dec_ctx *js_ctx, duk_small_uint_t st
|
36676
|
36759
|
return;
|
36677
|
36760
|
|
36678
|
36761
|
syntax_error:
|
36679
|
|
- duk__dec_syntax_error(js_ctx);
|
|
36762
|
+ duk__json_dec_syntax_error(js_ctx);
|
36680
|
36763
|
DUK_UNREACHABLE();
|
36681
|
36764
|
}
|
36682
|
36765
|
|
36683
|
|
-DUK_LOCAL duk_small_int_t duk__dec_string_escape(duk_json_dec_ctx *js_ctx, duk_uint8_t **ext_p) {
|
|
36766
|
+DUK_LOCAL duk_small_int_t duk__json_dec_string_escape(duk_json_dec_ctx *js_ctx, duk_uint8_t **ext_p) {
|
36684
|
36767
|
duk_uint_fast32_t cp;
|
36685
|
36768
|
|
36686
|
36769
|
/* EOF (-1) will be cast to an unsigned value first
|
36687
|
36770
|
* and then re-cast for the switch. In any case, it
|
36688
|
36771
|
* will match the default case (syntax error).
|
36689
|
36772
|
*/
|
36690
|
|
- cp = (duk_uint_fast32_t) duk__dec_get(js_ctx);
|
|
36773
|
+ cp = (duk_uint_fast32_t) duk__json_dec_get(js_ctx);
|
36691
|
36774
|
switch (cp) {
|
36692
|
36775
|
case DUK_ASC_BACKSLASH: break;
|
36693
|
36776
|
case DUK_ASC_DOUBLEQUOTE: break;
|
...
|
...
|
@@ -36698,13 +36781,13 @@ DUK_LOCAL duk_small_int_t duk__dec_string_escape(duk_json_dec_ctx *js_ctx, duk_u
|
36698
|
36781
|
case DUK_ASC_LC_F: cp = 0x0c; break;
|
36699
|
36782
|
case DUK_ASC_LC_B: cp = 0x08; break;
|
36700
|
36783
|
case DUK_ASC_LC_U: {
|
36701
|
|
- cp = duk__dec_decode_hex_escape(js_ctx, 4);
|
|
36784
|
+ cp = duk__json_dec_decode_hex_escape(js_ctx, 4);
|
36702
|
36785
|
break;
|
36703
|
36786
|
}
|
36704
|
36787
|
#if defined(DUK_USE_JX)
|
36705
|
36788
|
case DUK_ASC_UC_U: {
|
36706
|
36789
|
if (js_ctx->flag_ext_custom) {
|
36707
|
|
- cp = duk__dec_decode_hex_escape(js_ctx, 8);
|
|
36790
|
+ cp = duk__json_dec_decode_hex_escape(js_ctx, 8);
|
36708
|
36791
|
} else {
|
36709
|
36792
|
return 1; /* syntax error */
|
36710
|
36793
|
}
|
...
|
...
|
@@ -36712,7 +36795,7 @@ DUK_LOCAL duk_small_int_t duk__dec_string_escape(duk_json_dec_ctx *js_ctx, duk_u
|
36712
|
36795
|
}
|
36713
|
36796
|
case DUK_ASC_LC_X: {
|
36714
|
36797
|
if (js_ctx->flag_ext_custom) {
|
36715
|
|
- cp = duk__dec_decode_hex_escape(js_ctx, 2);
|
|
36798
|
+ cp = duk__json_dec_decode_hex_escape(js_ctx, 2);
|
36716
|
36799
|
} else {
|
36717
|
36800
|
return 1; /* syntax error */
|
36718
|
36801
|
}
|
...
|
...
|
@@ -36729,7 +36812,7 @@ DUK_LOCAL duk_small_int_t duk__dec_string_escape(duk_json_dec_ctx *js_ctx, duk_u
|
36729
|
36812
|
return 0;
|
36730
|
36813
|
}
|
36731
|
36814
|
|
36732
|
|
-DUK_LOCAL void duk__dec_string(duk_json_dec_ctx *js_ctx) {
|
|
36815
|
+DUK_LOCAL void duk__json_dec_string(duk_json_dec_ctx *js_ctx) {
|
36733
|
36816
|
duk_hthread *thr = js_ctx->thr;
|
36734
|
36817
|
duk_bufwriter_ctx bw_alloc;
|
36735
|
36818
|
duk_bufwriter_ctx *bw;
|
...
|
...
|
@@ -36788,7 +36871,7 @@ DUK_LOCAL void duk__dec_string(duk_json_dec_ctx *js_ctx) {
|
36788
|
36871
|
* quite slow but it's uncommon).
|
36789
|
36872
|
*/
|
36790
|
36873
|
js_ctx->p = p;
|
36791
|
|
- if (duk__dec_string_escape(js_ctx, &q) != 0) {
|
|
36874
|
+ if (duk__json_dec_string_escape(js_ctx, &q) != 0) {
|
36792
|
36875
|
goto syntax_error;
|
36793
|
36876
|
}
|
36794
|
36877
|
break;
|
...
|
...
|
@@ -36805,12 +36888,12 @@ DUK_LOCAL void duk__dec_string(duk_json_dec_ctx *js_ctx) {
|
36805
|
36888
|
|
36806
|
36889
|
q = DUK_BW_ENSURE_RAW(js_ctx->thr, bw, DUK_UNICODE_MAX_XUTF8_LENGTH, q);
|
36807
|
36890
|
|
36808
|
|
- x = duk__dec_get(js_ctx);
|
|
36891
|
+ x = duk__json_dec_get(js_ctx);
|
36809
|
36892
|
|
36810
|
36893
|
if (x == DUK_ASC_DOUBLEQUOTE) {
|
36811
|
36894
|
break;
|
36812
|
36895
|
} else if (x == DUK_ASC_BACKSLASH) {
|
36813
|
|
- if (duk__dec_string_escape(js_ctx, &q) != 0) {
|
|
36896
|
+ if (duk__json_dec_string_escape(js_ctx, &q) != 0) {
|
36814
|
36897
|
goto syntax_error;
|
36815
|
36898
|
}
|
36816
|
36899
|
} else if (x < 0x20) {
|
...
|
...
|
@@ -36830,7 +36913,7 @@ DUK_LOCAL void duk__dec_string(duk_json_dec_ctx *js_ctx) {
|
36830
|
36913
|
return;
|
36831
|
36914
|
|
36832
|
36915
|
syntax_error:
|
36833
|
|
- duk__dec_syntax_error(js_ctx);
|
|
36916
|
+ duk__json_dec_syntax_error(js_ctx);
|
36834
|
36917
|
DUK_UNREACHABLE();
|
36835
|
36918
|
}
|
36836
|
36919
|
|
...
|
...
|
@@ -36838,7 +36921,7 @@ DUK_LOCAL void duk__dec_string(duk_json_dec_ctx *js_ctx) {
|
36838
|
36921
|
/* Decode a plain string consisting entirely of identifier characters.
|
36839
|
36922
|
* Used to parse plain keys (e.g. "foo: 123").
|
36840
|
36923
|
*/
|
36841
|
|
-DUK_LOCAL void duk__dec_plain_string(duk_json_dec_ctx *js_ctx) {
|
|
36924
|
+DUK_LOCAL void duk__json_dec_plain_string(duk_json_dec_ctx *js_ctx) {
|
36842
|
36925
|
duk_hthread *thr = js_ctx->thr;
|
36843
|
36926
|
const duk_uint8_t *p;
|
36844
|
36927
|
duk_small_int_t x;
|
...
|
...
|
@@ -36880,7 +36963,7 @@ DUK_LOCAL void duk__dec_plain_string(duk_json_dec_ctx *js_ctx) {
|
36880
|
36963
|
#endif /* DUK_USE_JX */
|
36881
|
36964
|
|
36882
|
36965
|
#if defined(DUK_USE_JX)
|
36883
|
|
-DUK_LOCAL void duk__dec_pointer(duk_json_dec_ctx *js_ctx) {
|
|
36966
|
+DUK_LOCAL void duk__json_dec_pointer(duk_json_dec_ctx *js_ctx) {
|
36884
|
36967
|
duk_hthread *thr = js_ctx->thr;
|
36885
|
36968
|
const duk_uint8_t *p;
|
36886
|
36969
|
duk_small_int_t x;
|
...
|
...
|
@@ -36927,13 +37010,13 @@ DUK_LOCAL void duk__dec_pointer(duk_json_dec_ctx *js_ctx) {
|
36927
|
37010
|
return;
|
36928
|
37011
|
|
36929
|
37012
|
syntax_error:
|
36930
|
|
- duk__dec_syntax_error(js_ctx);
|
|
37013
|
+ duk__json_dec_syntax_error(js_ctx);
|
36931
|
37014
|
DUK_UNREACHABLE();
|
36932
|
37015
|
}
|
36933
|
37016
|
#endif /* DUK_USE_JX */
|
36934
|
37017
|
|
36935
|
37018
|
#if defined(DUK_USE_JX)
|
36936
|
|
-DUK_LOCAL void duk__dec_buffer(duk_json_dec_ctx *js_ctx) {
|
|
37019
|
+DUK_LOCAL void duk__json_dec_buffer(duk_json_dec_ctx *js_ctx) {
|
36937
|
37020
|
duk_hthread *thr = js_ctx->thr;
|
36938
|
37021
|
const duk_uint8_t *p;
|
36939
|
37022
|
duk_uint8_t *buf;
|
...
|
...
|
@@ -36985,13 +37068,13 @@ DUK_LOCAL void duk__dec_buffer(duk_json_dec_ctx *js_ctx) {
|
36985
|
37068
|
return;
|
36986
|
37069
|
|
36987
|
37070
|
syntax_error:
|
36988
|
|
- duk__dec_syntax_error(js_ctx);
|
|
37071
|
+ duk__json_dec_syntax_error(js_ctx);
|
36989
|
37072
|
DUK_UNREACHABLE();
|
36990
|
37073
|
}
|
36991
|
37074
|
#endif /* DUK_USE_JX */
|
36992
|
37075
|
|
36993
|
37076
|
/* Parse a number, other than NaN or +/- Infinity */
|
36994
|
|
-DUK_LOCAL void duk__dec_number(duk_json_dec_ctx *js_ctx) {
|
|
37077
|
+DUK_LOCAL void duk__json_dec_number(duk_json_dec_ctx *js_ctx) {
|
36995
|
37078
|
duk_hthread *thr = js_ctx->thr;
|
36996
|
37079
|
const duk_uint8_t *p_start;
|
36997
|
37080
|
const duk_uint8_t *p;
|
...
|
...
|
@@ -37047,7 +37130,7 @@ DUK_LOCAL void duk__dec_number(duk_json_dec_ctx *js_ctx) {
|
37047
|
37130
|
(duk_tval *) duk_get_tval(thr, -1)));
|
37048
|
37131
|
duk_numconv_parse(thr, 10 /*radix*/, s2n_flags);
|
37049
|
37132
|
if (duk_is_nan(thr, -1)) {
|
37050
|
|
- duk__dec_syntax_error(js_ctx);
|
|
37133
|
+ duk__json_dec_syntax_error(js_ctx);
|
37051
|
37134
|
}
|
37052
|
37135
|
DUK_ASSERT(duk_is_number(thr, -1));
|
37053
|
37136
|
DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T",
|
...
|
...
|
@@ -37056,22 +37139,24 @@ DUK_LOCAL void duk__dec_number(duk_json_dec_ctx *js_ctx) {
|
37056
|
37139
|
/* [ ... num ] */
|
37057
|
37140
|
}
|
37058
|
37141
|
|
37059
|
|
-DUK_LOCAL void duk__dec_objarr_entry(duk_json_dec_ctx *js_ctx) {
|
|
37142
|
+DUK_LOCAL void duk__json_dec_objarr_entry(duk_json_dec_ctx *js_ctx) {
|
37060
|
37143
|
duk_hthread *thr = js_ctx->thr;
|
37061
|
37144
|
duk_require_stack(thr, DUK_JSON_DEC_REQSTACK);
|
37062
|
37145
|
|
37063
|
37146
|
/* c recursion check */
|
37064
|
37147
|
|
|
37148
|
+ duk_native_stack_check(thr);
|
|
37149
|
+
|
37065
|
37150
|
DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */
|
37066
|
37151
|
DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit);
|
37067
|
37152
|
if (js_ctx->recursion_depth >= js_ctx->recursion_limit) {
|
37068
|
|
- DUK_ERROR_RANGE(thr, DUK_STR_JSONDEC_RECLIMIT);
|
|
37153
|
+ DUK_ERROR_RANGE(thr, DUK_STR_DEC_RECLIMIT);
|
37069
|
37154
|
DUK_WO_NORETURN(return;);
|
37070
|
37155
|
}
|
37071
|
37156
|
js_ctx->recursion_depth++;
|
37072
|
37157
|
}
|
37073
|
37158
|
|
37074
|
|
-DUK_LOCAL void duk__dec_objarr_exit(duk_json_dec_ctx *js_ctx) {
|
|
37159
|
+DUK_LOCAL void duk__json_dec_objarr_exit(duk_json_dec_ctx *js_ctx) {
|
37075
|
37160
|
/* c recursion check */
|
37076
|
37161
|
|
37077
|
37162
|
DUK_ASSERT(js_ctx->recursion_depth > 0);
|
...
|
...
|
@@ -37079,14 +37164,14 @@ DUK_LOCAL void duk__dec_objarr_exit(duk_json_dec_ctx *js_ctx) {
|
37079
|
37164
|
js_ctx->recursion_depth--;
|
37080
|
37165
|
}
|
37081
|
37166
|
|
37082
|
|
-DUK_LOCAL void duk__dec_object(duk_json_dec_ctx *js_ctx) {
|
|
37167
|
+DUK_LOCAL void duk__json_dec_object(duk_json_dec_ctx *js_ctx) {
|
37083
|
37168
|
duk_hthread *thr = js_ctx->thr;
|
37084
|
37169
|
duk_int_t key_count; /* XXX: a "first" flag would suffice */
|
37085
|
37170
|
duk_uint8_t x;
|
37086
|
37171
|
|
37087
|
37172
|
DUK_DDD(DUK_DDDPRINT("parse_object"));
|
37088
|
37173
|
|
37089
|
|
- duk__dec_objarr_entry(js_ctx);
|
|
37174
|
+ duk__json_dec_objarr_entry(js_ctx);
|
37090
|
37175
|
|
37091
|
37176
|
duk_push_object(thr);
|
37092
|
37177
|
|
...
|
...
|
@@ -37094,7 +37179,7 @@ DUK_LOCAL void duk__dec_object(duk_json_dec_ctx *js_ctx) {
|
37094
|
37179
|
|
37095
|
37180
|
key_count = 0;
|
37096
|
37181
|
for (;;) {
|
37097
|
|
- x = duk__dec_get_nonwhite(js_ctx);
|
|
37182
|
+ x = duk__json_dec_get_nonwhite(js_ctx);
|
37098
|
37183
|
|
37099
|
37184
|
DUK_DDD(DUK_DDDPRINT("parse_object: obj=%!T, x=%ld, key_count=%ld",
|
37100
|
37185
|
(duk_tval *) duk_get_tval(thr, -1),
|
...
|
...
|
@@ -37104,7 +37189,7 @@ DUK_LOCAL void duk__dec_object(duk_json_dec_ctx *js_ctx) {
|
37104
|
37189
|
|
37105
|
37190
|
if (x == DUK_ASC_COMMA && key_count > 0) {
|
37106
|
37191
|
/* accept comma, expect new value */
|
37107
|
|
- x = duk__dec_get_nonwhite(js_ctx);
|
|
37192
|
+ x = duk__json_dec_get_nonwhite(js_ctx);
|
37108
|
37193
|
} else if (x == DUK_ASC_RCURLY) {
|
37109
|
37194
|
/* eat closing brace */
|
37110
|
37195
|
break;
|
...
|
...
|
@@ -37121,11 +37206,11 @@ DUK_LOCAL void duk__dec_object(duk_json_dec_ctx *js_ctx) {
|
37121
|
37206
|
/* parse key and value */
|
37122
|
37207
|
|
37123
|
37208
|
if (x == DUK_ASC_DOUBLEQUOTE) {
|
37124
|
|
- duk__dec_string(js_ctx);
|
|
37209
|
+ duk__json_dec_string(js_ctx);
|
37125
|
37210
|
#if defined(DUK_USE_JX)
|
37126
|
37211
|
} else if (js_ctx->flag_ext_custom &&
|
37127
|
37212
|
duk_unicode_is_identifier_start((duk_codepoint_t) x)) {
|
37128
|
|
- duk__dec_plain_string(js_ctx);
|
|
37213
|
+ duk__json_dec_plain_string(js_ctx);
|
37129
|
37214
|
#endif
|
37130
|
37215
|
} else {
|
37131
|
37216
|
goto syntax_error;
|
...
|
...
|
@@ -37133,12 +37218,12 @@ DUK_LOCAL void duk__dec_object(duk_json_dec_ctx *js_ctx) {
|
37133
|
37218
|
|
37134
|
37219
|
/* [ ... obj key ] */
|
37135
|
37220
|
|
37136
|
|
- x = duk__dec_get_nonwhite(js_ctx);
|
|
37221
|
+ x = duk__json_dec_get_nonwhite(js_ctx);
|
37137
|
37222
|
if (x != DUK_ASC_COLON) {
|
37138
|
37223
|
goto syntax_error;
|
37139
|
37224
|
}
|
37140
|
37225
|
|
37141
|
|
- duk__dec_value(js_ctx);
|
|
37226
|
+ duk__json_dec_value(js_ctx);
|
37142
|
37227
|
|
37143
|
37228
|
/* [ ... obj key val ] */
|
37144
|
37229
|
|
...
|
...
|
@@ -37154,22 +37239,22 @@ DUK_LOCAL void duk__dec_object(duk_json_dec_ctx *js_ctx) {
|
37154
|
37239
|
DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T",
|
37155
|
37240
|
(duk_tval *) duk_get_tval(thr, -1)));
|
37156
|
37241
|
|
37157
|
|
- duk__dec_objarr_exit(js_ctx);
|
|
37242
|
+ duk__json_dec_objarr_exit(js_ctx);
|
37158
|
37243
|
return;
|
37159
|
37244
|
|
37160
|
37245
|
syntax_error:
|
37161
|
|
- duk__dec_syntax_error(js_ctx);
|
|
37246
|
+ duk__json_dec_syntax_error(js_ctx);
|
37162
|
37247
|
DUK_UNREACHABLE();
|
37163
|
37248
|
}
|
37164
|
37249
|
|
37165
|
|
-DUK_LOCAL void duk__dec_array(duk_json_dec_ctx *js_ctx) {
|
|
37250
|
+DUK_LOCAL void duk__json_dec_array(duk_json_dec_ctx *js_ctx) {
|
37166
|
37251
|
duk_hthread *thr = js_ctx->thr;
|
37167
|
37252
|
duk_uarridx_t arr_idx;
|
37168
|
37253
|
duk_uint8_t x;
|
37169
|
37254
|
|
37170
|
37255
|
DUK_DDD(DUK_DDDPRINT("parse_array"));
|
37171
|
37256
|
|
37172
|
|
- duk__dec_objarr_entry(js_ctx);
|
|
37257
|
+ duk__json_dec_objarr_entry(js_ctx);
|
37173
|
37258
|
|
37174
|
37259
|
duk_push_array(thr);
|
37175
|
37260
|
|
...
|
...
|
@@ -37177,7 +37262,7 @@ DUK_LOCAL void duk__dec_array(duk_json_dec_ctx *js_ctx) {
|
37177
|
37262
|
|
37178
|
37263
|
arr_idx = 0;
|
37179
|
37264
|
for (;;) {
|
37180
|
|
- x = duk__dec_get_nonwhite(js_ctx);
|
|
37265
|
+ x = duk__json_dec_get_nonwhite(js_ctx);
|
37181
|
37266
|
|
37182
|
37267
|
DUK_DDD(DUK_DDDPRINT("parse_array: arr=%!T, x=%ld, arr_idx=%ld",
|
37183
|
37268
|
(duk_tval *) duk_get_tval(thr, -1),
|
...
|
...
|
@@ -37193,7 +37278,7 @@ DUK_LOCAL void duk__dec_array(duk_json_dec_ctx *js_ctx) {
|
37193
|
37278
|
break;
|
37194
|
37279
|
} else if (arr_idx == 0) {
|
37195
|
37280
|
/* accept anything, expect first value (EOF will be
|
37196
|
|
- * caught by duk__dec_value() below.
|
|
37281
|
+ * caught by duk__json_dec_value() below.
|
37197
|
37282
|
*/
|
37198
|
37283
|
js_ctx->p--; /* backtrack (safe) */
|
37199
|
37284
|
} else {
|
...
|
...
|
@@ -37203,7 +37288,7 @@ DUK_LOCAL void duk__dec_array(duk_json_dec_ctx *js_ctx) {
|
37203
|
37288
|
|
37204
|
37289
|
/* parse value */
|
37205
|
37290
|
|
37206
|
|
- duk__dec_value(js_ctx);
|
|
37291
|
+ duk__json_dec_value(js_ctx);
|
37207
|
37292
|
|
37208
|
37293
|
/* [ ... arr val ] */
|
37209
|
37294
|
|
...
|
...
|
@@ -37222,30 +37307,30 @@ DUK_LOCAL void duk__dec_array(duk_json_dec_ctx *js_ctx) {
|
37222
|
37307
|
DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T",
|
37223
|
37308
|
(duk_tval *) duk_get_tval(thr, -1)));
|
37224
|
37309
|
|
37225
|
|
- duk__dec_objarr_exit(js_ctx);
|
|
37310
|
+ duk__json_dec_objarr_exit(js_ctx);
|
37226
|
37311
|
return;
|
37227
|
37312
|
|
37228
|
37313
|
syntax_error:
|
37229
|
|
- duk__dec_syntax_error(js_ctx);
|
|
37314
|
+ duk__json_dec_syntax_error(js_ctx);
|
37230
|
37315
|
DUK_UNREACHABLE();
|
37231
|
37316
|
}
|
37232
|
37317
|
|
37233
|
|
-DUK_LOCAL void duk__dec_value(duk_json_dec_ctx *js_ctx) {
|
|
37318
|
+DUK_LOCAL void duk__json_dec_value(duk_json_dec_ctx *js_ctx) {
|
37234
|
37319
|
duk_hthread *thr = js_ctx->thr;
|
37235
|
37320
|
duk_uint8_t x;
|
37236
|
37321
|
|
37237
|
|
- x = duk__dec_get_nonwhite(js_ctx);
|
|
37322
|
+ x = duk__json_dec_get_nonwhite(js_ctx);
|
37238
|
37323
|
|
37239
|
37324
|
DUK_DDD(DUK_DDDPRINT("parse_value: initial x=%ld", (long) x));
|
37240
|
37325
|
|
37241
|
|
- /* Note: duk__dec_req_stridx() backtracks one char */
|
|
37326
|
+ /* Note: duk__json_dec_req_stridx() backtracks one char */
|
37242
|
37327
|
|
37243
|
37328
|
if (x == DUK_ASC_DOUBLEQUOTE) {
|
37244
|
|
- duk__dec_string(js_ctx);
|
|
37329
|
+ duk__json_dec_string(js_ctx);
|
37245
|
37330
|
} else if ((x >= DUK_ASC_0 && x <= DUK_ASC_9) || (x == DUK_ASC_MINUS)) {
|
37246
|
37331
|
#if defined(DUK_USE_JX)
|
37247
|
|
- if (js_ctx->flag_ext_custom && x == DUK_ASC_MINUS && duk__dec_peek(js_ctx) == DUK_ASC_UC_I) {
|
37248
|
|
- duk__dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */
|
|
37332
|
+ if (js_ctx->flag_ext_custom && x == DUK_ASC_MINUS && duk__json_dec_peek(js_ctx) == DUK_ASC_UC_I) {
|
|
37333
|
+ duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_MINUS_INFINITY); /* "-Infinity", '-' has been eaten */
|
37249
|
37334
|
duk_push_number(thr, -DUK_DOUBLE_INFINITY);
|
37250
|
37335
|
} else {
|
37251
|
37336
|
#else
|
...
|
...
|
@@ -37253,60 +37338,63 @@ DUK_LOCAL void duk__dec_value(duk_json_dec_ctx *js_ctx) {
|
37253
|
37338
|
#endif
|
37254
|
37339
|
/* We already ate 'x', so backup one byte. */
|
37255
|
37340
|
js_ctx->p--; /* safe */
|
37256
|
|
- duk__dec_number(js_ctx);
|
|
37341
|
+ duk__json_dec_number(js_ctx);
|
37257
|
37342
|
}
|
37258
|
37343
|
} else if (x == DUK_ASC_LC_T) {
|
37259
|
|
- duk__dec_req_stridx(js_ctx, DUK_STRIDX_TRUE);
|
|
37344
|
+ duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_TRUE);
|
37260
|
37345
|
duk_push_true(thr);
|
37261
|
37346
|
} else if (x == DUK_ASC_LC_F) {
|
37262
|
|
- duk__dec_req_stridx(js_ctx, DUK_STRIDX_FALSE);
|
|
37347
|
+ duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_FALSE);
|
37263
|
37348
|
duk_push_false(thr);
|
37264
|
37349
|
} else if (x == DUK_ASC_LC_N) {
|
37265
|
|
- duk__dec_req_stridx(js_ctx, DUK_STRIDX_LC_NULL);
|
|
37350
|
+ duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_LC_NULL);
|
37266
|
37351
|
duk_push_null(thr);
|
37267
|
37352
|
#if defined(DUK_USE_JX)
|
37268
|
37353
|
} else if (js_ctx->flag_ext_custom && x == DUK_ASC_LC_U) {
|
37269
|
|
- duk__dec_req_stridx(js_ctx, DUK_STRIDX_LC_UNDEFINED);
|
|
37354
|
+ duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_LC_UNDEFINED);
|
37270
|
37355
|
duk_push_undefined(thr);
|
37271
|
37356
|
} else if (js_ctx->flag_ext_custom && x == DUK_ASC_UC_N) {
|
37272
|
|
- duk__dec_req_stridx(js_ctx, DUK_STRIDX_NAN);
|
|
37357
|
+ duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_NAN);
|
37273
|
37358
|
duk_push_nan(thr);
|
37274
|
37359
|
} else if (js_ctx->flag_ext_custom && x == DUK_ASC_UC_I) {
|
37275
|
|
- duk__dec_req_stridx(js_ctx, DUK_STRIDX_INFINITY);
|
|
37360
|
+ duk__json_dec_req_stridx(js_ctx, DUK_STRIDX_INFINITY);
|
37276
|
37361
|
duk_push_number(thr, DUK_DOUBLE_INFINITY);
|
37277
|
37362
|
} else if (js_ctx->flag_ext_custom && x == DUK_ASC_LPAREN) {
|
37278
|
|
- duk__dec_pointer(js_ctx);
|
|
37363
|
+ duk__json_dec_pointer(js_ctx);
|
37279
|
37364
|
} else if (js_ctx->flag_ext_custom && x == DUK_ASC_PIPE) {
|
37280
|
|
- duk__dec_buffer(js_ctx);
|
|
37365
|
+ duk__json_dec_buffer(js_ctx);
|
37281
|
37366
|
#endif
|
37282
|
37367
|
} else if (x == DUK_ASC_LCURLY) {
|
37283
|
|
- duk__dec_object(js_ctx);
|
|
37368
|
+ duk__json_dec_object(js_ctx);
|
37284
|
37369
|
} else if (x == DUK_ASC_LBRACKET) {
|
37285
|
|
- duk__dec_array(js_ctx);
|
|
37370
|
+ duk__json_dec_array(js_ctx);
|
37286
|
37371
|
} else {
|
37287
|
37372
|
/* catches EOF (NUL) */
|
37288
|
37373
|
goto syntax_error;
|
37289
|
37374
|
}
|
37290
|
37375
|
|
37291
|
|
- duk__dec_eat_white(js_ctx);
|
|
37376
|
+ duk__json_dec_eat_white(js_ctx);
|
37292
|
37377
|
|
37293
|
37378
|
/* [ ... val ] */
|
37294
|
37379
|
return;
|
37295
|
37380
|
|
37296
|
37381
|
syntax_error:
|
37297
|
|
- duk__dec_syntax_error(js_ctx);
|
|
37382
|
+ duk__json_dec_syntax_error(js_ctx);
|
37298
|
37383
|
DUK_UNREACHABLE();
|
37299
|
37384
|
}
|
37300
|
37385
|
|
37301
|
|
-/* Recursive value reviver, implements the Walk() algorithm. No C recursion
|
37302
|
|
- * check is done here because the initial parsing step will already ensure
|
37303
|
|
- * there is a reasonable limit on C recursion depth and hence object depth.
|
|
37386
|
+/* Recursive value reviver, implements the Walk() algorithm. The parsing
|
|
37387
|
+ * step ensures there is a reasonable depth limit to the input. However,
|
|
37388
|
+ * the reviver may create more depth by editing object or array entries, so
|
|
37389
|
+ * we have both C recursion limit and native stack checks here.
|
37304
|
37390
|
*/
|
37305
|
|
-DUK_LOCAL void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
|
|
37391
|
+DUK_LOCAL void duk__json_dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
|
37306
|
37392
|
duk_hthread *thr = js_ctx->thr;
|
37307
|
37393
|
duk_hobject *h;
|
37308
|
37394
|
duk_uarridx_t i, arr_len;
|
37309
|
37395
|
|
|
37396
|
+ duk__json_dec_objarr_entry(js_ctx);
|
|
37397
|
+
|
37310
|
37398
|
DUK_DDD(DUK_DDDPRINT("walk: top=%ld, holder=%!T, name=%!T",
|
37311
|
37399
|
(long) duk_get_top(thr),
|
37312
|
37400
|
(duk_tval *) duk_get_tval(thr, -2),
|
...
|
...
|
@@ -37329,7 +37417,7 @@ DUK_LOCAL void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
|
37329
|
37417
|
|
37330
|
37418
|
duk_dup_top(thr);
|
37331
|
37419
|
(void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> [ ... holder name val val ToString(i) ] */
|
37332
|
|
- duk__dec_reviver_walk(js_ctx); /* -> [ ... holder name val new_elem ] */
|
|
37420
|
+ duk__json_dec_reviver_walk(js_ctx); /* -> [ ... holder name val new_elem ] */
|
37333
|
37421
|
|
37334
|
37422
|
if (duk_is_undefined(thr, -1)) {
|
37335
|
37423
|
duk_pop(thr);
|
...
|
...
|
@@ -37356,7 +37444,7 @@ DUK_LOCAL void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
|
37356
|
37444
|
duk_dup_m2(thr);
|
37357
|
37445
|
|
37358
|
37446
|
/* [ ... holder name val enum obj_key val obj_key ] */
|
37359
|
|
- duk__dec_reviver_walk(js_ctx);
|
|
37447
|
+ duk__json_dec_reviver_walk(js_ctx);
|
37360
|
37448
|
|
37361
|
37449
|
/* [ ... holder name val enum obj_key new_elem ] */
|
37362
|
37450
|
if (duk_is_undefined(thr, -1)) {
|
...
|
...
|
@@ -37385,6 +37473,8 @@ DUK_LOCAL void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
|
37385
|
37473
|
duk_insert(thr, -4); /* -> [ ... reviver holder name val ] */
|
37386
|
37474
|
duk_call_method(thr, 2); /* -> [ ... res ] */
|
37387
|
37475
|
|
|
37476
|
+ duk__json_dec_objarr_exit(js_ctx);
|
|
37477
|
+
|
37388
|
37478
|
DUK_DDD(DUK_DDDPRINT("walk: top=%ld, result=%!T",
|
37389
|
37479
|
(long) duk_get_top(thr), (duk_tval *) duk_get_tval(thr, -1)));
|
37390
|
37480
|
}
|
...
|
...
|
@@ -37494,7 +37584,7 @@ DUK_LOCAL duk_uint8_t *duk__emit_esc_auto_fast(duk_json_enc_ctx *js_ctx, duk_uin
|
37494
|
37584
|
return q;
|
37495
|
37585
|
}
|
37496
|
37586
|
|
37497
|
|
-DUK_LOCAL void duk__enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k) {
|
|
37587
|
+DUK_LOCAL void duk__json_enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k) {
|
37498
|
37588
|
const duk_int8_t *p, *p_start, *p_end; /* Note: intentionally signed. */
|
37499
|
37589
|
duk_size_t k_len;
|
37500
|
37590
|
duk_codepoint_t cp;
|
...
|
...
|
@@ -37537,7 +37627,7 @@ DUK_LOCAL void duk__enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k)
|
37537
|
37627
|
}
|
37538
|
37628
|
|
37539
|
37629
|
quote_normally:
|
37540
|
|
- duk__enc_quote_string(js_ctx, k);
|
|
37630
|
+ duk__json_enc_quote_string(js_ctx, k);
|
37541
|
37631
|
}
|
37542
|
37632
|
|
37543
|
37633
|
/* The Quote(value) operation: quote a string.
|
...
|
...
|
@@ -37545,13 +37635,13 @@ DUK_LOCAL void duk__enc_key_autoquote(duk_json_enc_ctx *js_ctx, duk_hstring *k)
|
37545
|
37635
|
* Stack policy: [ ] -> [ ].
|
37546
|
37636
|
*/
|
37547
|
37637
|
|
37548
|
|
-DUK_LOCAL void duk__enc_quote_string(duk_json_enc_ctx *js_ctx, duk_hstring *h_str) {
|
|
37638
|
+DUK_LOCAL void duk__json_enc_quote_string(duk_json_enc_ctx *js_ctx, duk_hstring *h_str) {
|
37549
|
37639
|
duk_hthread *thr = js_ctx->thr;
|
37550
|
37640
|
const duk_uint8_t *p, *p_start, *p_end, *p_now, *p_tmp;
|
37551
|
37641
|
duk_uint8_t *q;
|
37552
|
37642
|
duk_ucodepoint_t cp; /* typed for duk_unicode_decode_xutf8() */
|
37553
|
37643
|
|
37554
|
|
- DUK_DDD(DUK_DDDPRINT("duk__enc_quote_string: h_str=%!O", (duk_heaphdr *) h_str));
|
|
37644
|
+ DUK_DDD(DUK_DDDPRINT("duk__json_enc_quote_string: h_str=%!O", (duk_heaphdr *) h_str));
|
37555
|
37645
|
|
37556
|
37646
|
DUK_ASSERT(h_str != NULL);
|
37557
|
37647
|
p_start = DUK_HSTRING_GET_DATA(h_str);
|
...
|
...
|
@@ -37682,7 +37772,7 @@ DUK_LOCAL void duk__enc_quote_string(duk_json_enc_ctx *js_ctx, duk_hstring *h_st
|
37682
|
37772
|
/* Encode a double (checked by caller) from stack top. Stack top may be
|
37683
|
37773
|
* replaced by serialized string but is not popped (caller does that).
|
37684
|
37774
|
*/
|
37685
|
|
-DUK_LOCAL void duk__enc_double(duk_json_enc_ctx *js_ctx) {
|
|
37775
|
+DUK_LOCAL void duk__json_enc_double(duk_json_enc_ctx *js_ctx) {
|
37686
|
37776
|
duk_hthread *thr;
|
37687
|
37777
|
duk_tval *tv;
|
37688
|
37778
|
duk_double_t d;
|
...
|
...
|
@@ -37746,7 +37836,7 @@ DUK_LOCAL void duk__enc_double(duk_json_enc_ctx *js_ctx) {
|
37746
|
37836
|
|
37747
|
37837
|
#if defined(DUK_USE_FASTINT)
|
37748
|
37838
|
/* Encode a fastint from duk_tval ptr, no value stack effects. */
|
37749
|
|
-DUK_LOCAL void duk__enc_fastint_tval(duk_json_enc_ctx *js_ctx, duk_tval *tv) {
|
|
37839
|
+DUK_LOCAL void duk__json_enc_fastint_tval(duk_json_enc_ctx *js_ctx, duk_tval *tv) {
|
37750
|
37840
|
duk_int64_t v;
|
37751
|
37841
|
|
37752
|
37842
|
/* Fastint range is signed 48-bit so longest value is -2^47 = -140737488355328
|
...
|
...
|
@@ -37771,7 +37861,7 @@ DUK_LOCAL void duk__enc_fastint_tval(duk_json_enc_ctx *js_ctx, duk_tval *tv) {
|
37771
|
37861
|
|
37772
|
37862
|
#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
|
37773
|
37863
|
#if defined(DUK_USE_HEX_FASTPATH)
|
37774
|
|
-DUK_LOCAL duk_uint8_t *duk__enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) {
|
|
37864
|
+DUK_LOCAL duk_uint8_t *duk__json_enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) {
|
37775
|
37865
|
duk_uint8_t *q;
|
37776
|
37866
|
duk_uint16_t *q16;
|
37777
|
37867
|
duk_small_uint_t x;
|
...
|
...
|
@@ -37829,7 +37919,7 @@ DUK_LOCAL duk_uint8_t *duk__enc_buffer_data_hex(const duk_uint8_t *src, duk_size
|
37829
|
37919
|
return q;
|
37830
|
37920
|
}
|
37831
|
37921
|
#else /* DUK_USE_HEX_FASTPATH */
|
37832
|
|
-DUK_LOCAL duk_uint8_t *duk__enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) {
|
|
37922
|
+DUK_LOCAL duk_uint8_t *duk__json_enc_buffer_data_hex(const duk_uint8_t *src, duk_size_t src_len, duk_uint8_t *dst) {
|
37833
|
37923
|
const duk_uint8_t *p;
|
37834
|
37924
|
const duk_uint8_t *p_end;
|
37835
|
37925
|
duk_uint8_t *q;
|
...
|
...
|
@@ -37848,7 +37938,7 @@ DUK_LOCAL duk_uint8_t *duk__enc_buffer_data_hex(const duk_uint8_t *src, duk_size
|
37848
|
37938
|
}
|
37849
|
37939
|
#endif /* DUK_USE_HEX_FASTPATH */
|
37850
|
37940
|
|
37851
|
|
-DUK_LOCAL void duk__enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_data, duk_size_t buf_len) {
|
|
37941
|
+DUK_LOCAL void duk__json_enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_data, duk_size_t buf_len) {
|
37852
|
37942
|
duk_hthread *thr;
|
37853
|
37943
|
duk_uint8_t *q;
|
37854
|
37944
|
duk_size_t space;
|
...
|
...
|
@@ -37880,7 +37970,7 @@ DUK_LOCAL void duk__enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_d
|
37880
|
37970
|
#if defined(DUK_USE_JX)
|
37881
|
37971
|
{
|
37882
|
37972
|
*q++ = DUK_ASC_PIPE;
|
37883
|
|
- q = duk__enc_buffer_data_hex(buf_data, buf_len, q);
|
|
37973
|
+ q = duk__json_enc_buffer_data_hex(buf_data, buf_len, q);
|
37884
|
37974
|
*q++ = DUK_ASC_PIPE;
|
37885
|
37975
|
|
37886
|
37976
|
}
|
...
|
...
|
@@ -37893,7 +37983,7 @@ DUK_LOCAL void duk__enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_d
|
37893
|
37983
|
DUK_ASSERT(js_ctx->flag_ext_compatible);
|
37894
|
37984
|
duk_memcpy((void *) q, (const void *) "{\"_buf\":\"", 9); /* len: 9 */
|
37895
|
37985
|
q += 9;
|
37896
|
|
- q = duk__enc_buffer_data_hex(buf_data, buf_len, q);
|
|
37986
|
+ q = duk__json_enc_buffer_data_hex(buf_data, buf_len, q);
|
37897
|
37987
|
*q++ = DUK_ASC_DOUBLEQUOTE;
|
37898
|
37988
|
*q++ = DUK_ASC_RCURLY;
|
37899
|
37989
|
}
|
...
|
...
|
@@ -37902,15 +37992,15 @@ DUK_LOCAL void duk__enc_buffer_data(duk_json_enc_ctx *js_ctx, duk_uint8_t *buf_d
|
37902
|
37992
|
DUK_BW_SET_PTR(thr, &js_ctx->bw, q);
|
37903
|
37993
|
}
|
37904
|
37994
|
|
37905
|
|
-DUK_LOCAL void duk__enc_buffer_jx_jc(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) {
|
37906
|
|
- duk__enc_buffer_data(js_ctx,
|
|
37995
|
+DUK_LOCAL void duk__json_enc_buffer_jx_jc(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) {
|
|
37996
|
+ duk__json_enc_buffer_data(js_ctx,
|
37907
|
37997
|
(duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h),
|
37908
|
37998
|
(duk_size_t) DUK_HBUFFER_GET_SIZE(h));
|
37909
|
37999
|
}
|
37910
|
38000
|
#endif /* DUK_USE_JX || DUK_USE_JC */
|
37911
|
38001
|
|
37912
|
38002
|
#if defined(DUK_USE_JSON_STRINGIFY_FASTPATH)
|
37913
|
|
-DUK_LOCAL void duk__enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) {
|
|
38003
|
+DUK_LOCAL void duk__json_enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuffer *h) {
|
37914
|
38004
|
duk_size_t i, n;
|
37915
|
38005
|
const duk_uint8_t *buf;
|
37916
|
38006
|
duk_uint8_t *q;
|
...
|
...
|
@@ -37934,7 +38024,7 @@ DUK_LOCAL void duk__enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuff
|
37934
|
38024
|
buf = (const duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR(js_ctx->thr->heap, h);
|
37935
|
38025
|
if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
|
37936
|
38026
|
for (i = 0; i < n; i++) {
|
37937
|
|
- duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth + 1);
|
|
38027
|
+ duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth + 1);
|
37938
|
38028
|
q = DUK_BW_ENSURE_GETPTR(js_ctx->thr, &js_ctx->bw, 32);
|
37939
|
38029
|
q += DUK_SPRINTF((char *) q, "\"%lu\": %u,", (unsigned long) i, (unsigned int) buf[i]);
|
37940
|
38030
|
DUK_BW_SET_PTR(js_ctx->thr, &js_ctx->bw, q);
|
...
|
...
|
@@ -37950,14 +38040,14 @@ DUK_LOCAL void duk__enc_buffer_json_fastpath(duk_json_enc_ctx *js_ctx, duk_hbuff
|
37950
|
38040
|
DUK__UNEMIT_1(js_ctx); /* eat trailing comma */
|
37951
|
38041
|
|
37952
|
38042
|
if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
|
37953
|
|
- duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth);
|
|
38043
|
+ duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth);
|
37954
|
38044
|
}
|
37955
|
38045
|
DUK__EMIT_1(js_ctx, DUK_ASC_RCURLY);
|
37956
|
38046
|
}
|
37957
|
38047
|
#endif /* DUK_USE_JSON_STRINGIFY_FASTPATH */
|
37958
|
38048
|
|
37959
|
38049
|
#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
|
37960
|
|
-DUK_LOCAL void duk__enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr) {
|
|
38050
|
+DUK_LOCAL void duk__json_enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr) {
|
37961
|
38051
|
char buf[64]; /* XXX: how to figure correct size? */
|
37962
|
38052
|
const char *fmt;
|
37963
|
38053
|
|
...
|
...
|
@@ -37995,14 +38085,14 @@ DUK_LOCAL void duk__enc_pointer(duk_json_enc_ctx *js_ctx, void *ptr) {
|
37995
|
38085
|
|
37996
|
38086
|
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
|
37997
|
38087
|
#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
|
37998
|
|
-DUK_LOCAL void duk__enc_bufobj(duk_json_enc_ctx *js_ctx, duk_hbufobj *h_bufobj) {
|
|
38088
|
+DUK_LOCAL void duk__json_enc_bufobj(duk_json_enc_ctx *js_ctx, duk_hbufobj *h_bufobj) {
|
37999
|
38089
|
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
|
38000
|
38090
|
|
38001
|
38091
|
if (h_bufobj->buf == NULL || !DUK_HBUFOBJ_VALID_SLICE(h_bufobj)) {
|
38002
|
38092
|
DUK__EMIT_STRIDX(js_ctx, DUK_STRIDX_LC_NULL);
|
38003
|
38093
|
} else {
|
38004
|
38094
|
/* Handle both full and partial slice (as long as covered). */
|
38005
|
|
- duk__enc_buffer_data(js_ctx,
|
|
38095
|
+ duk__json_enc_buffer_data(js_ctx,
|
38006
|
38096
|
(duk_uint8_t *) DUK_HBUFOBJ_GET_SLICE_BASE(js_ctx->thr->heap, h_bufobj),
|
38007
|
38097
|
(duk_size_t) h_bufobj->length);
|
38008
|
38098
|
}
|
...
|
...
|
@@ -38014,7 +38104,7 @@ DUK_LOCAL void duk__enc_bufobj(duk_json_enc_ctx *js_ctx, duk_hbufobj *h_bufobj)
|
38014
|
38104
|
* directly related to indent depth.
|
38015
|
38105
|
*/
|
38016
|
38106
|
#if defined(DUK_USE_PREFER_SIZE)
|
38017
|
|
-DUK_LOCAL void duk__enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) {
|
|
38107
|
+DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) {
|
38018
|
38108
|
DUK_ASSERT(js_ctx->h_gap != NULL);
|
38019
|
38109
|
DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(js_ctx->h_gap) > 0); /* caller guarantees */
|
38020
|
38110
|
|
...
|
...
|
@@ -38024,7 +38114,7 @@ DUK_LOCAL void duk__enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t dept
|
38024
|
38114
|
}
|
38025
|
38115
|
}
|
38026
|
38116
|
#else /* DUK_USE_PREFER_SIZE */
|
38027
|
|
-DUK_LOCAL void duk__enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) {
|
|
38117
|
+DUK_LOCAL void duk__json_enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t depth) {
|
38028
|
38118
|
const duk_uint8_t *gap_data;
|
38029
|
38119
|
duk_size_t gap_len;
|
38030
|
38120
|
duk_size_t avail_bytes; /* bytes of indent available for copying */
|
...
|
...
|
@@ -38077,13 +38167,14 @@ DUK_LOCAL void duk__enc_newline_indent(duk_json_enc_ctx *js_ctx, duk_uint_t dept
|
38077
|
38167
|
#endif /* DUK_USE_PREFER_SIZE */
|
38078
|
38168
|
|
38079
|
38169
|
/* Shared entry handling for object/array serialization. */
|
38080
|
|
-DUK_LOCAL void duk__enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) {
|
|
38170
|
+DUK_LOCAL void duk__json_enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) {
|
38081
|
38171
|
duk_hthread *thr = js_ctx->thr;
|
38082
|
38172
|
duk_hobject *h_target;
|
38083
|
38173
|
duk_uint_fast32_t i, n;
|
38084
|
38174
|
|
38085
|
38175
|
*entry_top = duk_get_top(thr);
|
38086
|
38176
|
|
|
38177
|
+ duk_native_stack_check(thr);
|
38087
|
38178
|
duk_require_stack(thr, DUK_JSON_ENC_REQSTACK);
|
38088
|
38179
|
|
38089
|
38180
|
/* Loop check using a hybrid approach: a fixed-size visited[] array
|
...
|
...
|
@@ -38121,7 +38212,7 @@ DUK_LOCAL void duk__enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_
|
38121
|
38212
|
DUK_ASSERT_DISABLE(js_ctx->recursion_depth >= 0); /* unsigned */
|
38122
|
38213
|
DUK_ASSERT(js_ctx->recursion_depth <= js_ctx->recursion_limit);
|
38123
|
38214
|
if (js_ctx->recursion_depth >= js_ctx->recursion_limit) {
|
38124
|
|
- DUK_ERROR_RANGE(thr, DUK_STR_JSONENC_RECLIMIT);
|
|
38215
|
+ DUK_ERROR_RANGE(thr, DUK_STR_ENC_RECLIMIT);
|
38125
|
38216
|
DUK_WO_NORETURN(return;);
|
38126
|
38217
|
}
|
38127
|
38218
|
js_ctx->recursion_depth++;
|
...
|
...
|
@@ -38131,7 +38222,7 @@ DUK_LOCAL void duk__enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_
|
38131
|
38222
|
}
|
38132
|
38223
|
|
38133
|
38224
|
/* Shared exit handling for object/array serialization. */
|
38134
|
|
-DUK_LOCAL void duk__enc_objarr_exit(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) {
|
|
38225
|
+DUK_LOCAL void duk__json_enc_objarr_exit(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_top) {
|
38135
|
38226
|
duk_hthread *thr = js_ctx->thr;
|
38136
|
38227
|
duk_hobject *h_target;
|
38137
|
38228
|
|
...
|
...
|
@@ -38163,7 +38254,7 @@ DUK_LOCAL void duk__enc_objarr_exit(duk_json_enc_ctx *js_ctx, duk_idx_t *entry_t
|
38163
|
38254
|
*
|
38164
|
38255
|
* Stack policy: [ object ] -> [ object ].
|
38165
|
38256
|
*/
|
38166
|
|
-DUK_LOCAL void duk__enc_object(duk_json_enc_ctx *js_ctx) {
|
|
38257
|
+DUK_LOCAL void duk__json_enc_object(duk_json_enc_ctx *js_ctx) {
|
38167
|
38258
|
duk_hthread *thr = js_ctx->thr;
|
38168
|
38259
|
duk_hstring *h_key;
|
38169
|
38260
|
duk_idx_t entry_top;
|
...
|
...
|
@@ -38173,9 +38264,9 @@ DUK_LOCAL void duk__enc_object(duk_json_enc_ctx *js_ctx) {
|
38173
|
38264
|
duk_uarridx_t arr_len, i;
|
38174
|
38265
|
duk_size_t prev_size;
|
38175
|
38266
|
|
38176
|
|
- DUK_DDD(DUK_DDDPRINT("duk__enc_object: obj=%!T", (duk_tval *) duk_get_tval(thr, -1)));
|
|
38267
|
+ DUK_DDD(DUK_DDDPRINT("duk__json_enc_object: obj=%!T", (duk_tval *) duk_get_tval(thr, -1)));
|
38177
|
38268
|
|
38178
|
|
- duk__enc_objarr_entry(js_ctx, &entry_top);
|
|
38269
|
+ duk__json_enc_objarr_entry(js_ctx, &entry_top);
|
38179
|
38270
|
|
38180
|
38271
|
idx_obj = entry_top - 1;
|
38181
|
38272
|
|
...
|
...
|
@@ -38217,17 +38308,17 @@ DUK_LOCAL void duk__enc_object(duk_json_enc_ctx *js_ctx) {
|
38217
|
38308
|
|
38218
|
38309
|
prev_size = DUK_BW_GET_SIZE(js_ctx->thr, &js_ctx->bw);
|
38219
|
38310
|
if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
|
38220
|
|
- duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth);
|
38221
|
|
- duk__enc_key_autoquote(js_ctx, h_key);
|
|
38311
|
+ duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth);
|
|
38312
|
+ duk__json_enc_key_autoquote(js_ctx, h_key);
|
38222
|
38313
|
DUK__EMIT_2(js_ctx, DUK_ASC_COLON, DUK_ASC_SPACE);
|
38223
|
38314
|
} else {
|
38224
|
|
- duk__enc_key_autoquote(js_ctx, h_key);
|
|
38315
|
+ duk__json_enc_key_autoquote(js_ctx, h_key);
|
38225
|
38316
|
DUK__EMIT_1(js_ctx, DUK_ASC_COLON);
|
38226
|
38317
|
}
|
38227
|
38318
|
|
38228
|
38319
|
/* [ ... key ] */
|
38229
|
38320
|
|
38230
|
|
- if (DUK_UNLIKELY(duk__enc_value(js_ctx, idx_obj) == 0)) {
|
|
38321
|
+ if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_obj) == 0)) {
|
38231
|
38322
|
/* Value would yield 'undefined', so skip key altogether.
|
38232
|
38323
|
* Side effects have already happened.
|
38233
|
38324
|
*/
|
...
|
...
|
@@ -38245,12 +38336,12 @@ DUK_LOCAL void duk__enc_object(duk_json_enc_ctx *js_ctx) {
|
38245
|
38336
|
DUK__UNEMIT_1(js_ctx); /* eat trailing comma */
|
38246
|
38337
|
if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
|
38247
|
38338
|
DUK_ASSERT(js_ctx->recursion_depth >= 1);
|
38248
|
|
- duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U);
|
|
38339
|
+ duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U);
|
38249
|
38340
|
}
|
38250
|
38341
|
}
|
38251
|
38342
|
DUK__EMIT_1(js_ctx, DUK_ASC_RCURLY);
|
38252
|
38343
|
|
38253
|
|
- duk__enc_objarr_exit(js_ctx, &entry_top);
|
|
38344
|
+ duk__json_enc_objarr_exit(js_ctx, &entry_top);
|
38254
|
38345
|
|
38255
|
38346
|
DUK_ASSERT_TOP(thr, entry_top);
|
38256
|
38347
|
}
|
...
|
...
|
@@ -38259,17 +38350,17 @@ DUK_LOCAL void duk__enc_object(duk_json_enc_ctx *js_ctx) {
|
38259
|
38350
|
*
|
38260
|
38351
|
* Stack policy: [ array ] -> [ array ].
|
38261
|
38352
|
*/
|
38262
|
|
-DUK_LOCAL void duk__enc_array(duk_json_enc_ctx *js_ctx) {
|
|
38353
|
+DUK_LOCAL void duk__json_enc_array(duk_json_enc_ctx *js_ctx) {
|
38263
|
38354
|
duk_hthread *thr = js_ctx->thr;
|
38264
|
38355
|
duk_idx_t entry_top;
|
38265
|
38356
|
duk_idx_t idx_arr;
|
38266
|
38357
|
duk_bool_t emitted;
|
38267
|
38358
|
duk_uarridx_t i, arr_len;
|
38268
|
38359
|
|
38269
|
|
- DUK_DDD(DUK_DDDPRINT("duk__enc_array: array=%!T",
|
|
38360
|
+ DUK_DDD(DUK_DDDPRINT("duk__json_enc_array: array=%!T",
|
38270
|
38361
|
(duk_tval *) duk_get_tval(thr, -1)));
|
38271
|
38362
|
|
38272
|
|
- duk__enc_objarr_entry(js_ctx, &entry_top);
|
|
38363
|
+ duk__json_enc_objarr_entry(js_ctx, &entry_top);
|
38273
|
38364
|
|
38274
|
38365
|
idx_arr = entry_top - 1;
|
38275
|
38366
|
|
...
|
...
|
@@ -38286,14 +38377,14 @@ DUK_LOCAL void duk__enc_array(duk_json_enc_ctx *js_ctx) {
|
38286
|
38377
|
|
38287
|
38378
|
if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
|
38288
|
38379
|
DUK_ASSERT(js_ctx->recursion_depth >= 1);
|
38289
|
|
- duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth);
|
|
38380
|
+ duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth);
|
38290
|
38381
|
}
|
38291
|
38382
|
|
38292
|
38383
|
(void) duk_push_uint_to_hstring(thr, (duk_uint_t) i); /* -> [ ... key ] */
|
38293
|
38384
|
|
38294
|
38385
|
/* [ ... key ] */
|
38295
|
38386
|
|
38296
|
|
- if (DUK_UNLIKELY(duk__enc_value(js_ctx, idx_arr) == 0)) {
|
|
38387
|
+ if (DUK_UNLIKELY(duk__json_enc_value(js_ctx, idx_arr) == 0)) {
|
38297
|
38388
|
/* Value would normally be omitted, replace with 'null'. */
|
38298
|
38389
|
DUK__EMIT_STRIDX(js_ctx, DUK_STRIDX_LC_NULL);
|
38299
|
38390
|
} else {
|
...
|
...
|
@@ -38311,12 +38402,12 @@ DUK_LOCAL void duk__enc_array(duk_json_enc_ctx *js_ctx) {
|
38311
|
38402
|
DUK__UNEMIT_1(js_ctx); /* eat trailing comma */
|
38312
|
38403
|
if (DUK_UNLIKELY(js_ctx->h_gap != NULL)) {
|
38313
|
38404
|
DUK_ASSERT(js_ctx->recursion_depth >= 1);
|
38314
|
|
- duk__enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U);
|
|
38405
|
+ duk__json_enc_newline_indent(js_ctx, js_ctx->recursion_depth - 1U);
|
38315
|
38406
|
}
|
38316
|
38407
|
}
|
38317
|
38408
|
DUK__EMIT_1(js_ctx, DUK_ASC_RBRACKET);
|
38318
|
38409
|
|
38319
|
|
- duk__enc_objarr_exit(js_ctx, &entry_top);
|
|
38410
|
+ duk__json_enc_objarr_exit(js_ctx, &entry_top);
|
38320
|
38411
|
|
38321
|
38412
|
DUK_ASSERT_TOP(thr, entry_top);
|
38322
|
38413
|
}
|
...
|
...
|
@@ -38325,14 +38416,14 @@ DUK_LOCAL void duk__enc_array(duk_json_enc_ctx *js_ctx) {
|
38325
|
38416
|
*
|
38326
|
38417
|
* Stack policy: [ ... key ] -> [ ... ]
|
38327
|
38418
|
*/
|
38328
|
|
-DUK_LOCAL duk_bool_t duk__enc_value(duk_json_enc_ctx *js_ctx, duk_idx_t idx_holder) {
|
|
38419
|
+DUK_LOCAL duk_bool_t duk__json_enc_value(duk_json_enc_ctx *js_ctx, duk_idx_t idx_holder) {
|
38329
|
38420
|
duk_hthread *thr = js_ctx->thr;
|
38330
|
38421
|
duk_tval *tv;
|
38331
|
38422
|
duk_tval *tv_holder;
|
38332
|
38423
|
duk_tval *tv_key;
|
38333
|
38424
|
duk_small_int_t c;
|
38334
|
38425
|
|
38335
|
|
- DUK_DDD(DUK_DDDPRINT("duk__enc_value: idx_holder=%ld, holder=%!T, key=%!T",
|
|
38426
|
+ DUK_DDD(DUK_DDDPRINT("duk__json_enc_value: idx_holder=%ld, holder=%!T, key=%!T",
|
38336
|
38427
|
(long) idx_holder, (duk_tval *) duk_get_tval(thr, idx_holder),
|
38337
|
38428
|
(duk_tval *) duk_get_tval(thr, -1)));
|
38338
|
38429
|
|
...
|
...
|
@@ -38402,7 +38493,7 @@ DUK_LOCAL duk_bool_t duk__enc_value(duk_json_enc_ctx *js_ctx, duk_idx_t idx_hold
|
38402
|
38493
|
duk_hbufobj *h_bufobj;
|
38403
|
38494
|
h_bufobj = (duk_hbufobj *) h;
|
38404
|
38495
|
DUK_HBUFOBJ_ASSERT_VALID(h_bufobj);
|
38405
|
|
- duk__enc_bufobj(js_ctx, h_bufobj);
|
|
38496
|
+ duk__json_enc_bufobj(js_ctx, h_bufobj);
|
38406
|
38497
|
goto pop2_emitted;
|
38407
|
38498
|
}
|
38408
|
38499
|
/* Otherwise bufferobjects get serialized as normal objects. */
|
...
|
...
|
@@ -38498,7 +38589,7 @@ DUK_LOCAL duk_bool_t duk__enc_value(duk_json_enc_ctx *js_ctx, duk_idx_t idx_hold
|
38498
|
38589
|
#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
|
38499
|
38590
|
/* When JX/JC not in use, the type mask above will avoid this case if needed. */
|
38500
|
38591
|
case DUK_TAG_POINTER: {
|
38501
|
|
- duk__enc_pointer(js_ctx, DUK_TVAL_GET_POINTER(tv));
|
|
38592
|
+ duk__json_enc_pointer(js_ctx, DUK_TVAL_GET_POINTER(tv));
|
38502
|
38593
|
break;
|
38503
|
38594
|
}
|
38504
|
38595
|
#endif /* DUK_USE_JX || DUK_USE_JC */
|
...
|
...
|
@@ -38508,7 +38599,7 @@ DUK_LOCAL duk_bool_t duk__enc_value(duk_json_enc_ctx *js_ctx, duk_idx_t idx_hold
|
38508
|
38599
|
if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(h))) {
|
38509
|
38600
|
goto pop2_undef;
|
38510
|
38601
|
}
|
38511
|
|
- duk__enc_quote_string(js_ctx, h);
|
|
38602
|
+ duk__json_enc_quote_string(js_ctx, h);
|
|