xbintsc 0.6.9 → 0.6.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/dist/src/checker/globals.js +2 -1
  2. package/dist/src/checker/globals.js.map +1 -1
  3. package/dist/src/cli/help.d.ts +1 -1
  4. package/dist/src/cli/main.js +1 -0
  5. package/dist/src/cli/main.js.map +1 -1
  6. package/dist/src/codegen/generator/state.js +3 -0
  7. package/dist/src/codegen/generator/state.js.map +1 -1
  8. package/dist/src/codegen/generator/tables.js +3 -0
  9. package/dist/src/codegen/generator/tables.js.map +1 -1
  10. package/dist/src/driver/compiler.js +1 -1
  11. package/dist/src/driver/compiler.js.map +1 -1
  12. package/dist/src/driver/config.js +1 -0
  13. package/dist/src/driver/config.js.map +1 -1
  14. package/dist/src/driver/runtime-objects.d.ts +1 -1
  15. package/dist/src/driver/runtime-objects.js +2 -0
  16. package/dist/src/driver/runtime-objects.js.map +1 -1
  17. package/dist/src/driver/version.d.ts +1 -1
  18. package/dist/src/driver/version.js +1 -1
  19. package/dist/src/driver/version.js.map +1 -1
  20. package/dist/src/extensions/node/crypto/index.js +12 -1
  21. package/dist/src/extensions/node/crypto/index.js.map +1 -1
  22. package/dist/tests/driver/config.test.js +15 -2
  23. package/dist/tests/driver/config.test.js.map +1 -1
  24. package/dist/tests/e2e/compile-builtins.test.js +26 -0
  25. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  26. package/dist/tests/e2e/compile-node.test.js +37 -1
  27. package/dist/tests/e2e/compile-node.test.js.map +1 -1
  28. package/dist/tests/e2e/crypto-random.test.d.ts +9 -0
  29. package/dist/tests/e2e/crypto-random.test.js +63 -0
  30. package/dist/tests/e2e/crypto-random.test.js.map +1 -0
  31. package/dist/tests/e2e/date-parse.test.js +27 -1
  32. package/dist/tests/e2e/date-parse.test.js.map +1 -1
  33. package/dist/tests/e2e/gui-css-coverage.test.js +1 -1
  34. package/dist/tests/e2e/gui-dom.test.js +29 -0
  35. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  36. package/dist/tests/e2e/gui-form.test.d.ts +9 -0
  37. package/dist/tests/e2e/gui-form.test.js +359 -0
  38. package/dist/tests/e2e/gui-form.test.js.map +1 -0
  39. package/dist/tests/e2e/gui-helpers.d.ts +2 -0
  40. package/dist/tests/e2e/gui-helpers.js +1 -0
  41. package/dist/tests/e2e/gui-helpers.js.map +1 -1
  42. package/dist/tests/e2e/gui-layout.test.js +47 -0
  43. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  44. package/dist/tests/e2e/gui-paint.test.js +108 -0
  45. package/dist/tests/e2e/gui-paint.test.js.map +1 -1
  46. package/dist/tests/e2e/gui-script-import-order.test.js +6 -1
  47. package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
  48. package/dist/tests/e2e/gui-style.test.js +82 -0
  49. package/dist/tests/e2e/gui-style.test.js.map +1 -1
  50. package/dist/tests/e2e/gui-unsupported.test.d.ts +6 -0
  51. package/dist/tests/e2e/gui-unsupported.test.js +124 -0
  52. package/dist/tests/e2e/gui-unsupported.test.js.map +1 -0
  53. package/dist/tests/e2e/json-parse-errors.test.d.ts +9 -0
  54. package/dist/tests/e2e/json-parse-errors.test.js +48 -0
  55. package/dist/tests/e2e/json-parse-errors.test.js.map +1 -0
  56. package/doc/ai/extensions.md +7 -4
  57. package/doc/ai/language-support.md +2 -1
  58. package/doc/ai/zh-CN/extensions.md +6 -3
  59. package/doc/ai/zh-CN/language-support.md +2 -1
  60. package/doc/gui/api.md +8 -2
  61. package/doc/gui/dom.md +81 -4
  62. package/doc/gui/input.md +74 -3
  63. package/doc/gui/known-issues.md +12 -5
  64. package/doc/gui/layout.md +19 -6
  65. package/doc/gui/rendering.md +16 -9
  66. package/doc/implemented/node/crypto.md +8 -0
  67. package/doc/implemented/node/fs.md +1 -1
  68. package/doc/implemented/stdlib.md +10 -2
  69. package/doc/zh-CN/gui/api.md +8 -2
  70. package/doc/zh-CN/gui/dom.md +70 -4
  71. package/doc/zh-CN/gui/input.md +65 -4
  72. package/doc/zh-CN/gui/known-issues.md +11 -4
  73. package/doc/zh-CN/gui/layout.md +14 -4
  74. package/doc/zh-CN/gui/rendering.md +13 -10
  75. package/doc/zh-CN/implemented/node/crypto.md +6 -0
  76. package/doc/zh-CN/implemented/node/fs.md +1 -1
  77. package/doc/zh-CN/implemented/stdlib.md +10 -2
  78. package/package.json +7 -7
  79. package/runtime/ext_gui/clip_values.cpp +11 -0
  80. package/runtime/ext_gui/css.cpp +27 -2
  81. package/runtime/ext_gui/css_match.cpp +21 -1
  82. package/runtime/ext_gui/css_selector.cpp +23 -0
  83. package/runtime/ext_gui/css_sheet.cpp +7 -0
  84. package/runtime/ext_gui/document.cpp +15 -0
  85. package/runtime/ext_gui/document_animation.cpp +4 -1
  86. package/runtime/ext_gui/dom.h +41 -2
  87. package/runtime/ext_gui/dom_api.cpp +3 -0
  88. package/runtime/ext_gui/dom_api_document.cpp +28 -0
  89. package/runtime/ext_gui/dom_api_events.cpp +17 -14
  90. package/runtime/ext_gui/dom_api_form.cpp +567 -0
  91. package/runtime/ext_gui/dom_api_internal.h +46 -214
  92. package/runtime/ext_gui/dom_api_mutation.cpp +1 -1
  93. package/runtime/ext_gui/dom_api_node.cpp +10 -3
  94. package/runtime/ext_gui/dom_api_node_read.cpp +1 -1
  95. package/runtime/ext_gui/dom_api_proto.cpp +45 -0
  96. package/runtime/ext_gui/dom_api_webgl_methods.h +217 -0
  97. package/runtime/ext_gui/dom_parse.cpp +118 -1
  98. package/runtime/ext_gui/effect_values.cpp +28 -7
  99. package/runtime/ext_gui/form_focus.cpp +293 -0
  100. package/runtime/ext_gui/form_input.cpp +448 -0
  101. package/runtime/ext_gui/form_internal.h +30 -0
  102. package/runtime/ext_gui/form_shared.cpp +126 -0
  103. package/runtime/ext_gui/form_state.cpp +536 -0
  104. package/runtime/ext_gui/form_state.h +97 -0
  105. package/runtime/ext_gui/gradient_values.cpp +25 -5
  106. package/runtime/ext_gui/gui_engine.h +40 -4
  107. package/runtime/ext_gui/gui_events.cpp +63 -48
  108. package/runtime/ext_gui/inline_svg.cpp +3 -0
  109. package/runtime/ext_gui/layout.cpp +6 -0
  110. package/runtime/ext_gui/layout.h +4 -0
  111. package/runtime/ext_gui/layout_flow.cpp +35 -3
  112. package/runtime/ext_gui/layout_inline.cpp +80 -7
  113. package/runtime/ext_gui/media_query.cpp +7 -1
  114. package/runtime/ext_gui/paint.cpp +62 -24
  115. package/runtime/ext_gui/paint.h +7 -4
  116. package/runtime/ext_gui/paint_clip.cpp +74 -19
  117. package/runtime/ext_gui/paint_form.cpp +389 -0
  118. package/runtime/ext_gui/paint_internal.h +13 -1
  119. package/runtime/ext_gui/renderer_clip.cpp +19 -17
  120. package/runtime/ext_gui/style.cpp +5 -1
  121. package/runtime/ext_gui/style.h +5 -0
  122. package/runtime/ext_gui/style_cascade.cpp +2 -0
  123. package/runtime/ext_gui/style_internal.h +7 -2
  124. package/runtime/ext_gui/style_print.cpp +33 -0
  125. package/runtime/ext_gui/style_text.cpp +11 -0
  126. package/runtime/ext_gui/style_ua.cpp +42 -0
  127. package/runtime/ext_gui/style_values.cpp +89 -90
  128. package/runtime/ext_gui/transform.cpp +2 -0
  129. package/runtime/ext_gui/warnings.cpp +298 -0
  130. package/runtime/ext_gui/warnings.h +59 -0
  131. package/runtime/ext_gui/window.cpp +31 -55
  132. package/runtime/ext_gui/window_diagnostics.cpp +58 -0
  133. package/runtime/ext_gui/window_emit.cpp +51 -0
  134. package/runtime/ext_node/crypto/crypto.c +3 -2
  135. package/runtime/ext_node/crypto/crypto_hash.h +13 -0
  136. package/runtime/ext_node/crypto/crypto_random.c +339 -0
  137. package/runtime/ext_node/fs/async_worker.c +1 -1
  138. package/runtime/ext_node/fs/fs_ops.c +1 -1
  139. package/runtime/ext_node/fs/parts/platform.inc +65 -0
  140. package/runtime/rt.h +27 -0
  141. package/runtime/xt_crypto.c +132 -0
  142. package/runtime/xt_random.c +143 -0
  143. package/runtime/xt_regex/matcher.inc +9 -28
  144. package/runtime/xt_regex/parser.inc +65 -2
  145. package/runtime/xt_regex/types.inc +11 -1
  146. package/runtime/xt_regex.h +6 -2
  147. package/runtime/xt_stdlib/dispatch.inc +2 -0
  148. package/runtime/xt_stdlib/math.inc +1 -1
  149. package/runtime/xt_stdlib2/date.inc +204 -4
  150. package/runtime/xt_stdlib2/json.inc +4 -546
  151. package/runtime/xt_stdlib2/json_parse.inc +347 -0
  152. package/runtime/xt_stdlib2/json_stringify.inc +368 -0
  153. package/runtime/xt_stdlib2/regexp-match.inc +6 -11
  154. package/runtime/xt_stdlib2.c +0 -4
  155. package/runtime/xt_typed_array/elements.inc +6 -1
  156. package/src/checker/globals.ts +2 -0
  157. package/src/cli/main.ts +1 -0
  158. package/src/codegen/generator/state.ts +3 -0
  159. package/src/codegen/generator/tables.ts +3 -0
  160. package/src/driver/compiler.ts +1 -1
  161. package/src/driver/config.ts +1 -0
  162. package/src/driver/runtime-objects.ts +2 -0
  163. package/src/driver/version.ts +1 -1
  164. package/src/extensions/node/crypto/index.ts +12 -1
@@ -0,0 +1,347 @@
1
+ /* -- JSON ----------------------------------------------------------------- */
2
+
3
+ typedef struct {
4
+ const char *data;
5
+ size_t length;
6
+ size_t pos;
7
+ int depth;
8
+ int error;
9
+ } xt_json_cursor;
10
+
11
+ #define XT_JSON_MAX_DEPTH 512
12
+
13
+ static void xt_json_skip_ws(xt_json_cursor *c) {
14
+ while (c->pos < c->length) {
15
+ char ch = c->data[c->pos];
16
+ if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') c->pos++;
17
+ else break;
18
+ }
19
+ }
20
+
21
+ static void xt_json_fail(xt_json_cursor *c) { c->error = 1; }
22
+
23
+ static xt_value xt_json_parse_value(xt_json_cursor *c);
24
+
25
+ static int xt_json_hex_digit(char ch) {
26
+ if (ch >= '0' && ch <= '9') return ch - '0';
27
+ if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10;
28
+ if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10;
29
+ return -1;
30
+ }
31
+
32
+ static xt_value xt_json_parse_string(xt_json_cursor *c) {
33
+ c->pos++; /* opening quote */
34
+ size_t capacity = 32, length = 0;
35
+ char *out = (char *)malloc(capacity);
36
+ if (!out) abort();
37
+ int closed = 0;
38
+ while (c->pos < c->length) {
39
+ unsigned char ch = (unsigned char)c->data[c->pos++];
40
+ if (ch == '"') {
41
+ closed = 1;
42
+ break;
43
+ }
44
+ /* JSON forbids unescaped control characters. */
45
+ if (ch < 0x20) {
46
+ xt_json_fail(c);
47
+ break;
48
+ }
49
+ if (ch == '\\') {
50
+ if (c->pos >= c->length) {
51
+ xt_json_fail(c);
52
+ break;
53
+ }
54
+ char esc = c->data[c->pos++];
55
+ if (esc == 'n') ch = '\n';
56
+ else if (esc == 't') ch = '\t';
57
+ else if (esc == 'r') ch = '\r';
58
+ else if (esc == 'b') ch = '\b';
59
+ else if (esc == 'f') ch = '\f';
60
+ else if (esc == '"' || esc == '\\' || esc == '/') ch = (unsigned char)esc;
61
+ else if (esc == 'u') {
62
+ unsigned code = 0;
63
+ int valid = 1;
64
+ if (c->pos + 4 > c->length) valid = 0;
65
+ for (int i = 0; valid && i < 4; i++) {
66
+ int digit = xt_json_hex_digit(c->data[c->pos + (size_t)i]);
67
+ if (digit < 0) valid = 0;
68
+ else code = (code << 4) | (unsigned)digit;
69
+ }
70
+ if (!valid) {
71
+ xt_json_fail(c);
72
+ break;
73
+ }
74
+ c->pos += 4;
75
+ /* A high surrogate followed by `\u` and a low surrogate denotes one
76
+ * supplementary code point, exactly like a JavaScript string. */
77
+ if (code >= 0xD800 && code <= 0xDBFF && c->pos + 6 <= c->length &&
78
+ c->data[c->pos] == '\\' && c->data[c->pos + 1] == 'u') {
79
+ unsigned low = 0;
80
+ int low_valid = 1;
81
+ for (int i = 0; i < 4; i++) {
82
+ int digit = xt_json_hex_digit(c->data[c->pos + 2 + (size_t)i]);
83
+ if (digit < 0) low_valid = 0;
84
+ else low = (low << 4) | (unsigned)digit;
85
+ }
86
+ if (low_valid && low >= 0xDC00 && low <= 0xDFFF) {
87
+ code = 0x10000 + ((code - 0xD800) << 10) + (low - 0xDC00);
88
+ c->pos += 6;
89
+ }
90
+ }
91
+ if (code >= 0x80) {
92
+ char tmp[4];
93
+ size_t bytes = xt_utf8_encode(code, tmp);
94
+ if (length + bytes + 1 > capacity) {
95
+ capacity = (length + bytes + 1) * 2;
96
+ out = (char *)realloc(out, capacity);
97
+ if (!out) abort();
98
+ }
99
+ memcpy(out + length, tmp, bytes);
100
+ length += bytes;
101
+ continue;
102
+ }
103
+ ch = (unsigned char)code;
104
+ } else {
105
+ xt_json_fail(c);
106
+ break;
107
+ }
108
+ }
109
+ if (length + 2 > capacity) {
110
+ capacity *= 2;
111
+ out = (char *)realloc(out, capacity);
112
+ if (!out) abort();
113
+ }
114
+ out[length++] = (char)ch;
115
+ }
116
+ if (!closed || c->error) {
117
+ xt_json_fail(c);
118
+ free(out);
119
+ return XT_UNDEFINED;
120
+ }
121
+ xt_value result = xt_string_new(out, length);
122
+ free(out);
123
+ return result;
124
+ }
125
+
126
+ static xt_value xt_json_parse_number(xt_json_cursor *c) {
127
+ size_t start = c->pos;
128
+ if (c->pos < c->length && c->data[c->pos] == '-') c->pos++;
129
+ if (c->pos >= c->length || !isdigit((unsigned char)c->data[c->pos])) {
130
+ xt_json_fail(c);
131
+ return XT_UNDEFINED;
132
+ }
133
+ if (c->data[c->pos] == '0') {
134
+ c->pos++;
135
+ } else {
136
+ while (c->pos < c->length && isdigit((unsigned char)c->data[c->pos])) c->pos++;
137
+ }
138
+ if (c->pos < c->length && c->data[c->pos] == '.') {
139
+ c->pos++;
140
+ if (c->pos >= c->length || !isdigit((unsigned char)c->data[c->pos])) {
141
+ xt_json_fail(c);
142
+ return XT_UNDEFINED;
143
+ }
144
+ while (c->pos < c->length && isdigit((unsigned char)c->data[c->pos])) c->pos++;
145
+ }
146
+ if (c->pos < c->length && (c->data[c->pos] == 'e' || c->data[c->pos] == 'E')) {
147
+ c->pos++;
148
+ if (c->pos < c->length && (c->data[c->pos] == '+' || c->data[c->pos] == '-')) c->pos++;
149
+ if (c->pos >= c->length || !isdigit((unsigned char)c->data[c->pos])) {
150
+ xt_json_fail(c);
151
+ return XT_UNDEFINED;
152
+ }
153
+ while (c->pos < c->length && isdigit((unsigned char)c->data[c->pos])) c->pos++;
154
+ }
155
+ char buffer[64];
156
+ size_t n = c->pos - start;
157
+ if (n >= sizeof(buffer)) {
158
+ xt_json_fail(c);
159
+ return XT_UNDEFINED;
160
+ }
161
+ memcpy(buffer, c->data + start, n);
162
+ buffer[n] = '\0';
163
+ return xt_number(strtod(buffer, NULL));
164
+ }
165
+
166
+ static xt_value xt_json_parse_object(xt_json_cursor *c) {
167
+ c->pos++; /* opening brace */
168
+ xt_value object = xt_object_new();
169
+ xt_json_skip_ws(c);
170
+ if (c->pos < c->length && c->data[c->pos] == '}') {
171
+ c->pos++;
172
+ return object;
173
+ }
174
+ for (;;) {
175
+ xt_json_skip_ws(c);
176
+ if (c->pos >= c->length || c->data[c->pos] != '"') {
177
+ xt_json_fail(c);
178
+ return object;
179
+ }
180
+ xt_value key = xt_json_parse_string(c);
181
+ if (c->error) return object;
182
+ xt_json_skip_ws(c);
183
+ if (c->pos >= c->length || c->data[c->pos] != ':') {
184
+ xt_json_fail(c);
185
+ return object;
186
+ }
187
+ c->pos++;
188
+ xt_value value = xt_json_parse_value(c);
189
+ if (c->error) return object;
190
+ xt_object_set(object, key, value);
191
+ xt_json_skip_ws(c);
192
+ if (c->pos >= c->length) {
193
+ xt_json_fail(c);
194
+ return object;
195
+ }
196
+ if (c->data[c->pos] == ',') {
197
+ c->pos++;
198
+ continue;
199
+ }
200
+ if (c->data[c->pos] == '}') {
201
+ c->pos++;
202
+ return object;
203
+ }
204
+ xt_json_fail(c);
205
+ return object;
206
+ }
207
+ }
208
+
209
+ static xt_value xt_json_parse_array(xt_json_cursor *c) {
210
+ c->pos++; /* opening bracket */
211
+ xt_value array = xt_array_new(0, NULL);
212
+ xt_json_skip_ws(c);
213
+ if (c->pos < c->length && c->data[c->pos] == ']') {
214
+ c->pos++;
215
+ return array;
216
+ }
217
+ for (;;) {
218
+ xt_value value = xt_json_parse_value(c);
219
+ if (c->error) return array;
220
+ xt_array_push(array, value);
221
+ xt_json_skip_ws(c);
222
+ if (c->pos >= c->length) {
223
+ xt_json_fail(c);
224
+ return array;
225
+ }
226
+ if (c->data[c->pos] == ',') {
227
+ c->pos++;
228
+ continue;
229
+ }
230
+ if (c->data[c->pos] == ']') {
231
+ c->pos++;
232
+ return array;
233
+ }
234
+ xt_json_fail(c);
235
+ return array;
236
+ }
237
+ }
238
+
239
+ static xt_value xt_json_parse_value(xt_json_cursor *c) {
240
+ xt_json_skip_ws(c);
241
+ if (c->error) return XT_UNDEFINED;
242
+ if (c->pos >= c->length) {
243
+ xt_json_fail(c);
244
+ return XT_UNDEFINED;
245
+ }
246
+ char ch = c->data[c->pos];
247
+ if (ch == '"') return xt_json_parse_string(c);
248
+ if (ch == '{' || ch == '[') {
249
+ if (++c->depth > XT_JSON_MAX_DEPTH) {
250
+ xt_json_fail(c);
251
+ return XT_UNDEFINED;
252
+ }
253
+ xt_value result = ch == '{' ? xt_json_parse_object(c) : xt_json_parse_array(c);
254
+ c->depth--;
255
+ return result;
256
+ }
257
+ if (ch == '-' || (ch >= '0' && ch <= '9')) return xt_json_parse_number(c);
258
+ if (ch == 't') {
259
+ if (c->pos + 4 <= c->length && memcmp(c->data + c->pos, "true", 4) == 0) {
260
+ c->pos += 4;
261
+ return XT_TRUE;
262
+ }
263
+ xt_json_fail(c);
264
+ return XT_UNDEFINED;
265
+ }
266
+ if (ch == 'f') {
267
+ if (c->pos + 5 <= c->length && memcmp(c->data + c->pos, "false", 5) == 0) {
268
+ c->pos += 5;
269
+ return XT_FALSE;
270
+ }
271
+ xt_json_fail(c);
272
+ return XT_UNDEFINED;
273
+ }
274
+ if (ch == 'n') {
275
+ if (c->pos + 4 <= c->length && memcmp(c->data + c->pos, "null", 4) == 0) {
276
+ c->pos += 4;
277
+ return XT_NULL;
278
+ }
279
+ xt_json_fail(c);
280
+ return XT_UNDEFINED;
281
+ }
282
+ xt_json_fail(c);
283
+ return XT_UNDEFINED;
284
+ }
285
+
286
+ /* Reviver walk: rebuild each container bottom-up, then pass the value to the
287
+ * user callback with its holder as `this`. Returning undefined deletes an
288
+ * object property / array element, exactly like the specification. */
289
+ static xt_value xt_json_revive(xt_value holder, xt_value key, xt_value reviver) {
290
+ xt_value value = xt_get(holder, key);
291
+ if (XT_IS_ARRAY(value)) {
292
+ xt_array *array = xt_as_array(value);
293
+ for (uint32_t i = 0; i < array->length; i++) {
294
+ /* Reviver keys are strings even for array indices. */
295
+ char keyBuffer[16];
296
+ snprintf(keyBuffer, sizeof(keyBuffer), "%u", i);
297
+ xt_value index = xt_string_from_cstr(keyBuffer);
298
+ xt_value updated = xt_json_revive(value, index, reviver);
299
+ if (updated == XT_UNDEFINED) xt_delete(value, index);
300
+ else xt_set(value, index, updated);
301
+ }
302
+ } else if (XT_IS_OBJECT(value)) {
303
+ xt_value keys = xt_object_keys(value);
304
+ xt_array *list = xt_as_array(keys);
305
+ if (list) {
306
+ for (uint32_t i = 0; i < list->length; i++) {
307
+ xt_value childKey = list->items[i];
308
+ xt_value updated = xt_json_revive(value, childKey, reviver);
309
+ if (updated == XT_UNDEFINED) xt_delete(value, childKey);
310
+ else xt_object_set(value, childKey, updated);
311
+ }
312
+ }
313
+ }
314
+ xt_value args[2] = {key, value};
315
+ return xt_call_with_this(reviver, holder, 2, args);
316
+ }
317
+
318
+ xt_value xt_json_parse(int32_t argc, xt_value *argv) {
319
+ xt_value input = xt_to_string(xt_arg_at(argc, argv, 0));
320
+ xt_string *s = xt_as_string(input);
321
+ if (!s) {
322
+ xt_value message = xt_string_from_cstr("Unexpected token in JSON");
323
+ xt_throw(xt_error_ctor_by_name(xt_string_from_cstr("SyntaxError"), 1, &message));
324
+ }
325
+ xt_json_cursor cursor = {xt_string_bytes(s), s->length, 0, 0, 0};
326
+ xt_value parsed = xt_json_parse_value(&cursor);
327
+ if (!cursor.error) {
328
+ xt_json_skip_ws(&cursor);
329
+ if (cursor.pos != cursor.length) cursor.error = 1;
330
+ }
331
+ if (cursor.error) {
332
+ char message[96];
333
+ if (cursor.pos >= cursor.length) {
334
+ snprintf(message, sizeof(message), "Unexpected end of JSON input");
335
+ } else {
336
+ snprintf(message, sizeof(message), "Unexpected token in JSON at position %zu",
337
+ cursor.pos);
338
+ }
339
+ xt_value text = xt_string_from_cstr(message);
340
+ xt_throw(xt_error_ctor_by_name(xt_string_from_cstr("SyntaxError"), 1, &text));
341
+ }
342
+ xt_value reviver = xt_arg_at(argc, argv, 1);
343
+ if (!XT_IS_FUNCTION(reviver)) return parsed;
344
+ xt_value holder = xt_object_new();
345
+ xt_object_set(holder, xt_string_from_cstr(""), parsed);
346
+ return xt_json_revive(holder, xt_string_from_cstr(""), reviver);
347
+ }