@amritk/nish-x86_64-linux 0.34.1 → 0.36.0
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.
- package/INSTALL.md +22 -13
- package/bin/nish +0 -0
- package/docs/AI.md +86 -16
- package/package.json +1 -1
- package/runtime/async.d.mts +49 -0
- package/runtime/async.mjs +27 -0
- package/runtime/nish.d.ts +4681 -427
- package/runtime/nish.h +6 -2
- package/runtime/nish.mjs +4 -0
- package/runtime/runtime-net.c +22 -0
- package/runtime/runtime-shm.c +93 -2
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/README.md +131 -131
- package/std/base64.ts +34 -5
- package/std/bytes.ts +258 -42
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +297 -77
- package/std/net/http1-server.ts +430 -94
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +275 -101
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +801 -112
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +264 -52
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +1124 -201
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +430 -40
- package/std/sync/shm.ts +222 -15
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/json-value.ts
CHANGED
|
@@ -132,9 +132,9 @@
|
|
|
132
132
|
* is stored differently there than natively, where a string is its UTF-8
|
|
133
133
|
* bytes; `parse` over a `u8[]` reads the same bytes both ways.
|
|
134
134
|
*
|
|
135
|
-
* **Public is not the whole API.**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
135
|
+
* **Public is not the whole API.** The compiler ignores `private`, so every
|
|
136
|
+
* member is reachable by a program; `private` and `@internal` mark what is
|
|
137
|
+
* not API, and the guarantees above hold only through the members that are
|
|
138
138
|
* not marked so. `append` with indices of the program's choosing, for
|
|
139
139
|
* example, skips the check that keeps a tree finite.
|
|
140
140
|
*
|
|
@@ -165,12 +165,17 @@ export type JsonValue = i32
|
|
|
165
165
|
|
|
166
166
|
/** What `kind` answers for a handle that names no value. */
|
|
167
167
|
export const JSON_VALUE_NONE: i32 = 0
|
|
168
|
+
/** The kind of `null`. */
|
|
168
169
|
export const JSON_VALUE_NULL: i32 = 1
|
|
170
|
+
/** The kind of `true` and `false`, which `boolean` reads. */
|
|
169
171
|
export const JSON_VALUE_BOOLEAN: i32 = 2
|
|
170
172
|
/** A number, kept as its text: `numberText`, `isI64`, `i64`, `isU64`, `u64` and `f64` read it. */
|
|
171
173
|
export const JSON_VALUE_NUMBER: i32 = 3
|
|
174
|
+
/** A string, decoded: `string` and `stringEquals` read it. */
|
|
172
175
|
export const JSON_VALUE_STRING: i32 = 4
|
|
176
|
+
/** An array: `length` and `at` read its elements, in order. */
|
|
173
177
|
export const JSON_VALUE_ARRAY: i32 = 5
|
|
178
|
+
/** An object: `length`, `keyAt`, `at` and `get` read its members, in order. */
|
|
174
179
|
export const JSON_VALUE_OBJECT: i32 = 6
|
|
175
180
|
|
|
176
181
|
/** What a builder answers when it did what it was asked. */
|
|
@@ -226,18 +231,32 @@ const JSON_VALUE_NO_WORD: i32 = 0
|
|
|
226
231
|
const JSON_VALUE_TRUE_WORD: i32 = 1
|
|
227
232
|
const JSON_VALUE_MINUS: i32 = 45
|
|
228
233
|
|
|
229
|
-
/**
|
|
234
|
+
/** A `JsonDocument`'s source ranges, made on first use; see `JsonDocument.ranges`. */
|
|
230
235
|
class JsonValueRanges {
|
|
231
236
|
/**
|
|
232
237
|
* Per value, its first byte in the parsed bytes and one past its last; per
|
|
233
238
|
* member slot, its key's, quotes included. `-1` where nothing was recorded.
|
|
239
|
+
*
|
|
240
|
+
* @internal Read and written by `JsonDocument` alone; the class is not
|
|
241
|
+
* exported.
|
|
234
242
|
*/
|
|
235
243
|
valueStart: i32[]
|
|
244
|
+
/** @internal Read and written by `JsonDocument` alone; the class is not exported. */
|
|
236
245
|
valueEnd: i32[]
|
|
246
|
+
/** @internal Read and written by `JsonDocument` alone; the class is not exported. */
|
|
237
247
|
slotKeyStart: i32[]
|
|
248
|
+
/** @internal Read and written by `JsonDocument` alone; the class is not exported. */
|
|
238
249
|
slotKeyEnd: i32[]
|
|
239
|
-
/**
|
|
250
|
+
/**
|
|
251
|
+
* For `parseRanged`: where each open container's key and each pending
|
|
252
|
+
* member's key end; `openKeySource` and `pendingSource` hold where they
|
|
253
|
+
* start.
|
|
254
|
+
*
|
|
255
|
+
* @internal Read and written by `JsonDocument` alone; the class is not
|
|
256
|
+
* exported.
|
|
257
|
+
*/
|
|
240
258
|
openKeyEnd: i32[]
|
|
259
|
+
/** @internal Read and written by `JsonDocument` alone; the class is not exported. */
|
|
241
260
|
pendingKeyEnd: i32[]
|
|
242
261
|
|
|
243
262
|
constructor() {
|
|
@@ -253,26 +272,26 @@ class JsonValueRanges {
|
|
|
253
272
|
/**
|
|
254
273
|
* A JSON tree, and the memory every value of it lives in. Make one, then
|
|
255
274
|
* `parse` into it or build with the `new*` methods; the module header has the
|
|
256
|
-
* rules. Its
|
|
257
|
-
* member in Nish is
|
|
275
|
+
* rules. Its `private` and `@internal` members are reachable, as every
|
|
276
|
+
* member in Nish is, because the compiler ignores `private`; use the others.
|
|
258
277
|
*/
|
|
259
278
|
export class JsonDocument {
|
|
260
279
|
/** Per value: its `JSON_VALUE_*` kind. */
|
|
261
|
-
kinds: u8[]
|
|
280
|
+
private kinds: u8[]
|
|
262
281
|
/** Per value: a string's or a number's first byte in `bytes`, a container's first slot, a boolean's `0` or `1`. */
|
|
263
|
-
first: i32[]
|
|
282
|
+
private first: i32[]
|
|
264
283
|
/** Per value: a string's or a number's byte count, or a container's member count. */
|
|
265
|
-
count: i32[]
|
|
284
|
+
private count: i32[]
|
|
266
285
|
/** Per value: how many slots a container has from `first`, its members and room to grow. */
|
|
267
|
-
room: i32[]
|
|
286
|
+
private room: i32[]
|
|
268
287
|
/** Per value: the container it is in, or `-1`. */
|
|
269
|
-
parent: i32[]
|
|
288
|
+
private parent: i32[]
|
|
270
289
|
/** Per member slot: the member's value, and an object member's key as a window of `bytes`. */
|
|
271
|
-
slotValue: i32[]
|
|
272
|
-
slotKeyAt: i32[]
|
|
273
|
-
slotKeyLength: i32[]
|
|
290
|
+
private slotValue: i32[]
|
|
291
|
+
private slotKeyAt: i32[]
|
|
292
|
+
private slotKeyLength: i32[]
|
|
274
293
|
/** The bytes of every string, key and number, decoded, one after the other. */
|
|
275
|
-
bytes: u8[]
|
|
294
|
+
private bytes: u8[]
|
|
276
295
|
/**
|
|
277
296
|
* The source ranges, `null` until the first `parseRanged` or setter, so
|
|
278
297
|
* that a document that never keeps ranges allocates nothing for them.
|
|
@@ -283,8 +302,8 @@ export class JsonDocument {
|
|
|
283
302
|
* `clear` moves anyway, so that a plain `parse` writes nothing for ranges.
|
|
284
303
|
*/
|
|
285
304
|
ranges: JsonValueRanges | null = null
|
|
286
|
-
rangeTop: i32 = 0
|
|
287
|
-
slotRangeTop: i32 = 0
|
|
305
|
+
private rangeTop: i32 = 0
|
|
306
|
+
private slotRangeTop: i32 = 0
|
|
288
307
|
/** The generation the ranges were written in; `0`, never a generation, when none were. */
|
|
289
308
|
rangeGeneration: i32 = 0
|
|
290
309
|
/**
|
|
@@ -295,22 +314,26 @@ export class JsonDocument {
|
|
|
295
314
|
* duplicate check's. All of them keep their length from one parse to the
|
|
296
315
|
* next, which is what lets a parse allocate nothing.
|
|
297
316
|
*/
|
|
298
|
-
openValue: i32[]
|
|
299
|
-
openBase: i32[]
|
|
300
|
-
openKeyAt: i32[]
|
|
301
|
-
openKeyLength: i32[]
|
|
302
|
-
openKeySource: i32[]
|
|
303
|
-
pendingValue: i32[]
|
|
304
|
-
pendingKeyAt: i32[]
|
|
305
|
-
pendingKeyLength: i32[]
|
|
306
|
-
pendingSource: i32[]
|
|
307
|
-
sortA: i32[]
|
|
308
|
-
sortB: i32[]
|
|
317
|
+
private openValue: i32[]
|
|
318
|
+
private openBase: i32[]
|
|
319
|
+
private openKeyAt: i32[]
|
|
320
|
+
private openKeyLength: i32[]
|
|
321
|
+
private openKeySource: i32[]
|
|
322
|
+
private pendingValue: i32[]
|
|
323
|
+
private pendingKeyAt: i32[]
|
|
324
|
+
private pendingKeyLength: i32[]
|
|
325
|
+
private pendingSource: i32[]
|
|
326
|
+
private sortA: i32[]
|
|
327
|
+
private sortB: i32[]
|
|
309
328
|
/** `parseText`'s copy of its string. */
|
|
310
|
-
textBytes: u8[]
|
|
329
|
+
private textBytes: u8[]
|
|
330
|
+
/**
|
|
331
|
+
* @internal The tokenizer every parse reads through. Read by
|
|
332
|
+
* std/yaml-json.ts, which builds a document from YAML through it.
|
|
333
|
+
*/
|
|
311
334
|
tok: JsonTokenizer
|
|
312
335
|
/** A tokenizer over one stored number at a time, for `isI64`, `i64` and `f64`, limited only by `i32`. */
|
|
313
|
-
numbers: JsonTokenizer
|
|
336
|
+
private numbers: JsonTokenizer
|
|
314
337
|
|
|
315
338
|
/** `JSON_VALUE_DUPLICATE_REFUSE` or `JSON_VALUE_DUPLICATE_LAST`; read by `parse`. */
|
|
316
339
|
duplicates: i32 = 0
|
|
@@ -322,16 +345,25 @@ export class JsonDocument {
|
|
|
322
345
|
top: i32 = 0
|
|
323
346
|
/** How many member slots are in use, and how many bytes. */
|
|
324
347
|
slotTop: i32 = 0
|
|
348
|
+
/** How many bytes of the decoded-text store are in use. */
|
|
325
349
|
byteTop: i32 = 0
|
|
326
350
|
/** How many members are pending. */
|
|
327
|
-
pendingTop: i32 = 0
|
|
351
|
+
private pendingTop: i32 = 0
|
|
328
352
|
/** The most values the document holds; more is `JSON_VALUE_ERR_VALUES`. At most `JSON_VALUE_MAX_VALUES`. */
|
|
329
353
|
maxValues: i32 = 0
|
|
330
354
|
/** The generation every handle of the current document carries; see `JSON_VALUE_INDEX_BITS`. */
|
|
331
355
|
generation: i32 = 1
|
|
332
356
|
/** Whether the last `unsigned` read a number that fits a `u64`. */
|
|
333
|
-
unsignedFits: boolean = false
|
|
357
|
+
private unsignedFits: boolean = false
|
|
334
358
|
|
|
359
|
+
/**
|
|
360
|
+
* An empty document whose parses are held to `limits`, with `maxDepth` capped
|
|
361
|
+
* at `JSON_WRITER_MAX_DEPTH` so that every document a parse accepts can be
|
|
362
|
+
* written back. `maxValues` starts at `JSON_VALUE_DEFAULT_MAX_VALUES`.
|
|
363
|
+
*
|
|
364
|
+
* @param limits - the depth and size limits for every parse; the document
|
|
365
|
+
* copies them.
|
|
366
|
+
*/
|
|
335
367
|
constructor(limits: JsonLimits) {
|
|
336
368
|
this.maxValues = JSON_VALUE_DEFAULT_MAX_VALUES
|
|
337
369
|
this.kinds = []
|
|
@@ -398,6 +430,12 @@ export class JsonDocument {
|
|
|
398
430
|
* source ranges; `parseRanged` does.
|
|
399
431
|
*
|
|
400
432
|
* Keep in step with `parseRanged`, the same loop plus the ranges.
|
|
433
|
+
*
|
|
434
|
+
* @param src - the bytes to parse, which the document only reads.
|
|
435
|
+
* @param off - the offset in `src` of the first byte of the text.
|
|
436
|
+
* @param len - how many bytes the text is.
|
|
437
|
+
* @returns the root value's handle, or the negative code that is also in
|
|
438
|
+
* `failed`.
|
|
401
439
|
*/
|
|
402
440
|
parse(src: u8[], off: i32, len: i32): JsonValue {
|
|
403
441
|
this.clear()
|
|
@@ -489,6 +527,12 @@ export class JsonDocument {
|
|
|
489
527
|
* loop inline there and cost the plain loop more instructions. A program
|
|
490
528
|
* that links both can still see the plain loop's code laid out differently
|
|
491
529
|
* (`docs/BENCHMARKS.md`). Keep in step with `parse`.
|
|
530
|
+
*
|
|
531
|
+
* @param src - the bytes to parse, which the document only reads.
|
|
532
|
+
* @param off - the offset in `src` of the first byte of the text.
|
|
533
|
+
* @param len - how many bytes the text is.
|
|
534
|
+
* @returns the root value's handle, or the negative code that is also in
|
|
535
|
+
* `failed`.
|
|
492
536
|
*/
|
|
493
537
|
parseRanged(src: u8[], off: i32, len: i32): JsonValue {
|
|
494
538
|
this.clear()
|
|
@@ -587,7 +631,14 @@ export class JsonDocument {
|
|
|
587
631
|
return this.handle(root)
|
|
588
632
|
}
|
|
589
633
|
|
|
590
|
-
/**
|
|
634
|
+
/**
|
|
635
|
+
* `parse` over the bytes of `s`, copied into an array the document reuses;
|
|
636
|
+
* `errorAt` is a byte offset in `s`. Keep in step with `parseTextRanged`.
|
|
637
|
+
*
|
|
638
|
+
* @param s - the JSON text.
|
|
639
|
+
* @returns the root value's handle, or the negative code that is also in
|
|
640
|
+
* `failed`.
|
|
641
|
+
*/
|
|
591
642
|
parseText(s: string): JsonValue {
|
|
592
643
|
const n: i32 = toI32(s.length)
|
|
593
644
|
const buf: u8[] = jsonValueRoom(this.textBytes, n)
|
|
@@ -598,7 +649,14 @@ export class JsonDocument {
|
|
|
598
649
|
return this.parse(buf, JSON_VALUE_NO_WORD, n)
|
|
599
650
|
}
|
|
600
651
|
|
|
601
|
-
/**
|
|
652
|
+
/**
|
|
653
|
+
* `parseRanged` over the bytes of `s`, as `parseText` is `parse`'s; its
|
|
654
|
+
* offsets are byte offsets in `s`. Keep in step with `parseText`.
|
|
655
|
+
*
|
|
656
|
+
* @param s - the JSON text.
|
|
657
|
+
* @returns the root value's handle, or the negative code that is also in
|
|
658
|
+
* `failed`.
|
|
659
|
+
*/
|
|
602
660
|
parseTextRanged(s: string): JsonValue {
|
|
603
661
|
const n: i32 = toI32(s.length)
|
|
604
662
|
const buf: u8[] = jsonValueRoom(this.textBytes, n)
|
|
@@ -609,8 +667,8 @@ export class JsonDocument {
|
|
|
609
667
|
return this.parseRanged(buf, JSON_VALUE_NO_WORD, n)
|
|
610
668
|
}
|
|
611
669
|
|
|
612
|
-
/**
|
|
613
|
-
parseFailed(code: i32, at: i32): i32 {
|
|
670
|
+
/** Records a failed parse and forgets what it built. */
|
|
671
|
+
private parseFailed(code: i32, at: i32): i32 {
|
|
614
672
|
this.clear()
|
|
615
673
|
this.failed = code
|
|
616
674
|
this.errorAt = at
|
|
@@ -618,12 +676,12 @@ export class JsonDocument {
|
|
|
618
676
|
}
|
|
619
677
|
|
|
620
678
|
/**
|
|
621
|
-
*
|
|
679
|
+
* Places the members pending from `base` into container `c` as one run of
|
|
622
680
|
* slots, checking an object's keys for duplicates first. Answers `0`, or
|
|
623
681
|
* `JSON_VALUE_ERR_DUPLICATE` with `errorAt` set. Keep in step with
|
|
624
682
|
* `closeRanged`.
|
|
625
683
|
*/
|
|
626
|
-
close(c: i32, base: i32): i32 {
|
|
684
|
+
private close(c: i32, base: i32): i32 {
|
|
627
685
|
let n: i32 = this.pendingTop - base
|
|
628
686
|
const object: boolean = this.kindAt(c) === JSON_VALUE_OBJECT
|
|
629
687
|
if (object && n > 1) {
|
|
@@ -655,8 +713,8 @@ export class JsonDocument {
|
|
|
655
713
|
return 0
|
|
656
714
|
}
|
|
657
715
|
|
|
658
|
-
/**
|
|
659
|
-
closeRanged(c: i32, base: i32): i32 {
|
|
716
|
+
/** `close` for `parseRanged`, which also gives each member its key's range. Keep in step with `close`. */
|
|
717
|
+
private closeRanged(c: i32, base: i32): i32 {
|
|
660
718
|
let n: i32 = this.pendingTop - base
|
|
661
719
|
const object: boolean = this.kindAt(c) === JSON_VALUE_OBJECT
|
|
662
720
|
if (object && n > 1) {
|
|
@@ -692,7 +750,7 @@ export class JsonDocument {
|
|
|
692
750
|
}
|
|
693
751
|
|
|
694
752
|
/**
|
|
695
|
-
*
|
|
753
|
+
* The duplicate check over the `n` members pending from `base`. Under
|
|
696
754
|
* `JSON_VALUE_DUPLICATE_LAST`, a repeated key's later members are marked
|
|
697
755
|
* gone (their pending value set to `-1`) and the first one takes the last
|
|
698
756
|
* one's value. Small objects compare every pair; larger ones are sorted by
|
|
@@ -700,7 +758,7 @@ export class JsonDocument {
|
|
|
700
758
|
* and the first of them is its first member. Keep in step with
|
|
701
759
|
* `duplicateKeysRanged`.
|
|
702
760
|
*/
|
|
703
|
-
duplicateKeys(base: i32, n: i32): i32 {
|
|
761
|
+
private duplicateKeys(base: i32, n: i32): i32 {
|
|
704
762
|
let firstRepeat: i32 = -1
|
|
705
763
|
if (n <= JSON_VALUE_PAIRWISE) {
|
|
706
764
|
for (let i: i32 = base + 1; i < base + n; i += 1) {
|
|
@@ -732,11 +790,11 @@ export class JsonDocument {
|
|
|
732
790
|
}
|
|
733
791
|
|
|
734
792
|
/**
|
|
735
|
-
*
|
|
793
|
+
* `duplicateKeys` for `closeRanged`, the same check. A copy, so that
|
|
736
794
|
* `duplicateKeys` keeps the one caller that lets it inline into `parse`.
|
|
737
795
|
* Keep in step with `duplicateKeys`.
|
|
738
796
|
*/
|
|
739
|
-
duplicateKeysRanged(base: i32, n: i32): i32 {
|
|
797
|
+
private duplicateKeysRanged(base: i32, n: i32): i32 {
|
|
740
798
|
let firstRepeat: i32 = -1
|
|
741
799
|
if (n <= JSON_VALUE_PAIRWISE) {
|
|
742
800
|
for (let i: i32 = base + 1; i < base + n; i += 1) {
|
|
@@ -768,11 +826,11 @@ export class JsonDocument {
|
|
|
768
826
|
}
|
|
769
827
|
|
|
770
828
|
/**
|
|
771
|
-
*
|
|
829
|
+
* Pending member `later` repeats the key of the earlier `head`: under
|
|
772
830
|
* `JSON_VALUE_DUPLICATE_LAST` `head` takes its value and it is marked gone.
|
|
773
831
|
* Answers the smallest source offset of a repeating key seen so far.
|
|
774
832
|
*/
|
|
775
|
-
repeat(head: i32, later: i32, firstRepeat: i32): i32 {
|
|
833
|
+
private repeat(head: i32, later: i32, firstRepeat: i32): i32 {
|
|
776
834
|
const source: i32 = jsonValueGet(this.pendingSource, later)
|
|
777
835
|
if (this.duplicates === JSON_VALUE_DUPLICATE_LAST) {
|
|
778
836
|
jsonValuePut(this.pendingValue, head, jsonValueGet(this.pendingValue, later))
|
|
@@ -781,18 +839,18 @@ export class JsonDocument {
|
|
|
781
839
|
return firstRepeat < 0 || source < firstRepeat ? source : firstRepeat
|
|
782
840
|
}
|
|
783
841
|
|
|
784
|
-
/**
|
|
785
|
-
samePendingKey(a: i32, b: i32): boolean {
|
|
842
|
+
/** Whether pending members `a` and `b` have the same key bytes. */
|
|
843
|
+
private samePendingKey(a: i32, b: i32): boolean {
|
|
786
844
|
return this.comparePending(a, b) === 0
|
|
787
845
|
}
|
|
788
846
|
|
|
789
847
|
/**
|
|
790
|
-
*
|
|
848
|
+
* The pending indices `base .. base + n - 1` sorted by key, ties in index
|
|
791
849
|
* order: a bottom-up merge sort between the two sort arrays, which answers
|
|
792
850
|
* whichever of them holds the result. Keep in step with
|
|
793
851
|
* `sortPendingRanged`.
|
|
794
852
|
*/
|
|
795
|
-
sortPending(base: i32, n: i32): i32[] {
|
|
853
|
+
private sortPending(base: i32, n: i32): i32[] {
|
|
796
854
|
let from: i32[] = jsonValueRoomI32(this.sortA, n)
|
|
797
855
|
let to: i32[] = jsonValueRoomI32(this.sortB, n)
|
|
798
856
|
this.sortA = from
|
|
@@ -832,11 +890,11 @@ export class JsonDocument {
|
|
|
832
890
|
}
|
|
833
891
|
|
|
834
892
|
/**
|
|
835
|
-
*
|
|
893
|
+
* `sortPending` for `duplicateKeysRanged`, the same sort. A copy, so
|
|
836
894
|
* that `sortPending` keeps the one caller that lets it inline into `parse`.
|
|
837
895
|
* Keep in step with `sortPending`.
|
|
838
896
|
*/
|
|
839
|
-
sortPendingRanged(base: i32, n: i32): i32[] {
|
|
897
|
+
private sortPendingRanged(base: i32, n: i32): i32[] {
|
|
840
898
|
let from: i32[] = jsonValueRoomI32(this.sortA, n)
|
|
841
899
|
let to: i32[] = jsonValueRoomI32(this.sortB, n)
|
|
842
900
|
this.sortA = from
|
|
@@ -875,8 +933,8 @@ export class JsonDocument {
|
|
|
875
933
|
return from
|
|
876
934
|
}
|
|
877
935
|
|
|
878
|
-
/**
|
|
879
|
-
comparePending(a: i32, b: i32): i32 {
|
|
936
|
+
/** Pending members `a` and `b` ordered by key bytes. */
|
|
937
|
+
private comparePending(a: i32, b: i32): i32 {
|
|
880
938
|
return jsonValueCompareBytes(
|
|
881
939
|
this.bytes,
|
|
882
940
|
jsonValueGet(this.pendingKeyAt, a),
|
|
@@ -886,8 +944,8 @@ export class JsonDocument {
|
|
|
886
944
|
)
|
|
887
945
|
}
|
|
888
946
|
|
|
889
|
-
/**
|
|
890
|
-
storeString(tok: JsonTokenizer): i32 {
|
|
947
|
+
/** The tokenizer's current string or key, decoded onto the end of `bytes`; answers its length. */
|
|
948
|
+
private storeString(tok: JsonTokenizer): i32 {
|
|
891
949
|
const n: i32 = tok.stringLength()
|
|
892
950
|
const at: i32 = this.byteTop
|
|
893
951
|
const buf: u8[] = jsonValueRoom(this.bytes, at + n)
|
|
@@ -897,8 +955,8 @@ export class JsonDocument {
|
|
|
897
955
|
return n
|
|
898
956
|
}
|
|
899
957
|
|
|
900
|
-
/**
|
|
901
|
-
storeSource(tok: JsonTokenizer): i32 {
|
|
958
|
+
/** The tokenizer's current token as written, a number's text, onto the end of `bytes`; answers its length. Keep in step with `storeSourceRanged`. */
|
|
959
|
+
private storeSource(tok: JsonTokenizer): i32 {
|
|
902
960
|
const src: u8[] = tok.src
|
|
903
961
|
const start: i32 = tok.tokStart
|
|
904
962
|
const n: i32 = tok.tokEnd - start
|
|
@@ -915,11 +973,11 @@ export class JsonDocument {
|
|
|
915
973
|
}
|
|
916
974
|
|
|
917
975
|
/**
|
|
918
|
-
*
|
|
976
|
+
* `storeSource` for `parseRanged`, the same copy. A copy, so that
|
|
919
977
|
* `storeSource` keeps the one caller that lets it inline into `parse`.
|
|
920
978
|
* Keep in step with `storeSource`.
|
|
921
979
|
*/
|
|
922
|
-
storeSourceRanged(tok: JsonTokenizer): i32 {
|
|
980
|
+
private storeSourceRanged(tok: JsonTokenizer): i32 {
|
|
923
981
|
const src: u8[] = tok.src
|
|
924
982
|
const start: i32 = tok.tokStart
|
|
925
983
|
const n: i32 = tok.tokEnd - start
|
|
@@ -936,11 +994,11 @@ export class JsonDocument {
|
|
|
936
994
|
}
|
|
937
995
|
|
|
938
996
|
/**
|
|
939
|
-
*
|
|
997
|
+
* A new value of `kind` with its two words, in no container, and
|
|
940
998
|
* its index; `JSON_VALUE_ERR_VALUES` when the document already holds
|
|
941
999
|
* `maxValues`.
|
|
942
1000
|
*/
|
|
943
|
-
newNode(kind: i32, first: i32, count: i32): i32 {
|
|
1001
|
+
private newNode(kind: i32, first: i32, count: i32): i32 {
|
|
944
1002
|
const v: i32 = this.top
|
|
945
1003
|
const cap: i32 = this.maxValues < JSON_VALUE_MAX_VALUES ? this.maxValues : JSON_VALUE_MAX_VALUES
|
|
946
1004
|
if (v >= cap) {
|
|
@@ -961,7 +1019,13 @@ export class JsonDocument {
|
|
|
961
1019
|
|
|
962
1020
|
// ---- Handles ----------------------------------------------------------------
|
|
963
1021
|
|
|
964
|
-
/**
|
|
1022
|
+
/**
|
|
1023
|
+
* The index handle `v` names in this document, or `-1` when it
|
|
1024
|
+
* names nothing here.
|
|
1025
|
+
*
|
|
1026
|
+
* @internal Read by std/yaml-json.ts, which builds a document from YAML
|
|
1027
|
+
* through it.
|
|
1028
|
+
*/
|
|
965
1029
|
index(v: JsonValue): i32 {
|
|
966
1030
|
if (v < 0 || v >> JSON_VALUE_INDEX_BITS !== this.generation) {
|
|
967
1031
|
return -1
|
|
@@ -970,20 +1034,26 @@ export class JsonDocument {
|
|
|
970
1034
|
return x < this.top ? x : -1
|
|
971
1035
|
}
|
|
972
1036
|
|
|
973
|
-
/**
|
|
974
|
-
handle(x: i32): JsonValue {
|
|
1037
|
+
/** The handle of index `x` in this document's generation; a negative `x` is answered as it is. */
|
|
1038
|
+
private handle(x: i32): JsonValue {
|
|
975
1039
|
return x < 0 ? x : (this.generation << JSON_VALUE_INDEX_BITS) | x
|
|
976
1040
|
}
|
|
977
1041
|
|
|
978
1042
|
// ---- Reading ----------------------------------------------------------------
|
|
979
1043
|
|
|
980
|
-
/**
|
|
1044
|
+
/**
|
|
1045
|
+
* `v`'s `JSON_VALUE_*` kind, or `JSON_VALUE_NONE` when `v` names no value of
|
|
1046
|
+
* this document's current contents.
|
|
1047
|
+
*
|
|
1048
|
+
* @param v - any handle.
|
|
1049
|
+
* @returns a `JSON_VALUE_*` kind.
|
|
1050
|
+
*/
|
|
981
1051
|
kind(v: JsonValue): i32 {
|
|
982
1052
|
return this.kindAt(this.index(v))
|
|
983
1053
|
}
|
|
984
1054
|
|
|
985
|
-
/**
|
|
986
|
-
kindAt(x: i32): i32 {
|
|
1055
|
+
/** The kind of index `x`, or `JSON_VALUE_NONE`. */
|
|
1056
|
+
private kindAt(x: i32): i32 {
|
|
987
1057
|
const kinds: u8[] = this.kinds
|
|
988
1058
|
if (x < 0 || x >= this.top || x >= toI32(kinds.length)) {
|
|
989
1059
|
return JSON_VALUE_NONE
|
|
@@ -991,38 +1061,65 @@ export class JsonDocument {
|
|
|
991
1061
|
return toI32(kinds[x])
|
|
992
1062
|
}
|
|
993
1063
|
|
|
994
|
-
/**
|
|
1064
|
+
/**
|
|
1065
|
+
* A boolean's value; `false` for any other value.
|
|
1066
|
+
*
|
|
1067
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1068
|
+
* nothing.
|
|
1069
|
+
* @returns true only for a `true` value.
|
|
1070
|
+
*/
|
|
995
1071
|
boolean(v: JsonValue): boolean {
|
|
996
1072
|
const x: i32 = this.index(v)
|
|
997
1073
|
return this.kindAt(x) === JSON_VALUE_BOOLEAN && jsonValueGet(this.first, x) === JSON_VALUE_TRUE_WORD
|
|
998
1074
|
}
|
|
999
1075
|
|
|
1000
|
-
/**
|
|
1076
|
+
/**
|
|
1077
|
+
* How many elements an array has, or members an object has; `-1` for any
|
|
1078
|
+
* other value.
|
|
1079
|
+
*
|
|
1080
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1081
|
+
* nothing.
|
|
1082
|
+
* @returns the element or member count, or `-1`.
|
|
1083
|
+
*/
|
|
1001
1084
|
length(v: JsonValue): i32 {
|
|
1002
1085
|
return this.lengthAt(this.index(v))
|
|
1003
1086
|
}
|
|
1004
1087
|
|
|
1005
|
-
/**
|
|
1006
|
-
lengthAt(x: i32): i32 {
|
|
1088
|
+
/** `length` of index `x`. */
|
|
1089
|
+
private lengthAt(x: i32): i32 {
|
|
1007
1090
|
const k: i32 = this.kindAt(x)
|
|
1008
1091
|
return k === JSON_VALUE_ARRAY || k === JSON_VALUE_OBJECT ? jsonValueGet(this.count, x) : -1
|
|
1009
1092
|
}
|
|
1010
1093
|
|
|
1011
|
-
/**
|
|
1012
|
-
slotAt(x: i32, i: i32): i32 {
|
|
1094
|
+
/** The slot of member or element `i` of the container at index `x`, or `-1`. */
|
|
1095
|
+
private slotAt(x: i32, i: i32): i32 {
|
|
1013
1096
|
if (i < 0 || i >= this.lengthAt(x)) {
|
|
1014
1097
|
return -1
|
|
1015
1098
|
}
|
|
1016
1099
|
return jsonValueGet(this.first, x) + i
|
|
1017
1100
|
}
|
|
1018
1101
|
|
|
1019
|
-
/**
|
|
1102
|
+
/**
|
|
1103
|
+
* Element `i` of an array, or the value of member `i` of an object, in order;
|
|
1104
|
+
* `-1` when there is none.
|
|
1105
|
+
*
|
|
1106
|
+
* @param v - an array or object handle.
|
|
1107
|
+
* @param i - the position, from 0.
|
|
1108
|
+
* @returns the element or member value, or `-1`.
|
|
1109
|
+
*/
|
|
1020
1110
|
at(v: JsonValue, i: i32): JsonValue {
|
|
1021
1111
|
const s: i32 = this.slotAt(this.index(v), i)
|
|
1022
1112
|
return s < 0 ? -1 : this.handle(jsonValueGet(this.slotValue, s))
|
|
1023
1113
|
}
|
|
1024
1114
|
|
|
1025
|
-
/**
|
|
1115
|
+
/**
|
|
1116
|
+
* The key of member `i` of an object, decoded; `""` when `v` is not an object
|
|
1117
|
+
* or has no member `i`.
|
|
1118
|
+
*
|
|
1119
|
+
* @param v - an object handle.
|
|
1120
|
+
* @param i - the member position, from 0.
|
|
1121
|
+
* @returns the key, a new string, or `""`.
|
|
1122
|
+
*/
|
|
1026
1123
|
keyAt(v: JsonValue, i: i32): string {
|
|
1027
1124
|
const x: i32 = this.index(v)
|
|
1028
1125
|
if (this.kindAt(x) !== JSON_VALUE_OBJECT) {
|
|
@@ -1035,7 +1132,14 @@ export class JsonDocument {
|
|
|
1035
1132
|
return this.textOf(jsonValueGet(this.slotKeyAt, s), jsonValueGet(this.slotKeyLength, s))
|
|
1036
1133
|
}
|
|
1037
1134
|
|
|
1038
|
-
/**
|
|
1135
|
+
/**
|
|
1136
|
+
* The value of the member of object `v` whose key is `key`'s bytes; `-1` when
|
|
1137
|
+
* there is none.
|
|
1138
|
+
*
|
|
1139
|
+
* @param v - an object handle.
|
|
1140
|
+
* @param key - the key to look for, compared byte by byte.
|
|
1141
|
+
* @returns the member value, or `-1`.
|
|
1142
|
+
*/
|
|
1039
1143
|
get(v: JsonValue, key: string): JsonValue {
|
|
1040
1144
|
const x: i32 = this.index(v)
|
|
1041
1145
|
if (this.kindAt(x) !== JSON_VALUE_OBJECT) {
|
|
@@ -1045,8 +1149,8 @@ export class JsonDocument {
|
|
|
1045
1149
|
return s < 0 ? -1 : this.handle(jsonValueGet(this.slotValue, s))
|
|
1046
1150
|
}
|
|
1047
1151
|
|
|
1048
|
-
/**
|
|
1049
|
-
findKey(x: i32, key: string): i32 {
|
|
1152
|
+
/** The slot of the member of the object at index `x` whose key is `key`'s bytes, or `-1`. */
|
|
1153
|
+
private findKey(x: i32, key: string): i32 {
|
|
1050
1154
|
const start: i32 = jsonValueGet(this.first, x)
|
|
1051
1155
|
const n: i32 = jsonValueGet(this.count, x)
|
|
1052
1156
|
for (let s: i32 = start; s < start + n; s += 1) {
|
|
@@ -1057,7 +1161,13 @@ export class JsonDocument {
|
|
|
1057
1161
|
return -1
|
|
1058
1162
|
}
|
|
1059
1163
|
|
|
1060
|
-
/**
|
|
1164
|
+
/**
|
|
1165
|
+
* A string's decoded bytes as a string; `""` for any other value.
|
|
1166
|
+
*
|
|
1167
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1168
|
+
* nothing.
|
|
1169
|
+
* @returns the string, a new one each call, or `""`.
|
|
1170
|
+
*/
|
|
1061
1171
|
string(v: JsonValue): string {
|
|
1062
1172
|
const x: i32 = this.index(v)
|
|
1063
1173
|
if (this.kindAt(x) !== JSON_VALUE_STRING) {
|
|
@@ -1066,7 +1176,14 @@ export class JsonDocument {
|
|
|
1066
1176
|
return this.textOf(jsonValueGet(this.first, x), jsonValueGet(this.count, x))
|
|
1067
1177
|
}
|
|
1068
1178
|
|
|
1069
|
-
/**
|
|
1179
|
+
/**
|
|
1180
|
+
* Whether `v` is a string whose decoded bytes are `s`'s. Allocates nothing.
|
|
1181
|
+
*
|
|
1182
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1183
|
+
* nothing.
|
|
1184
|
+
* @param s - the text to compare against.
|
|
1185
|
+
* @returns true when the bytes match exactly.
|
|
1186
|
+
*/
|
|
1070
1187
|
stringEquals(v: JsonValue, s: string): boolean {
|
|
1071
1188
|
const x: i32 = this.index(v)
|
|
1072
1189
|
return (
|
|
@@ -1075,7 +1192,14 @@ export class JsonDocument {
|
|
|
1075
1192
|
)
|
|
1076
1193
|
}
|
|
1077
1194
|
|
|
1078
|
-
/**
|
|
1195
|
+
/**
|
|
1196
|
+
* A number's text, exactly as it was written or built; `""` for any other
|
|
1197
|
+
* value.
|
|
1198
|
+
*
|
|
1199
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1200
|
+
* nothing.
|
|
1201
|
+
* @returns the number text, or `""`.
|
|
1202
|
+
*/
|
|
1079
1203
|
numberText(v: JsonValue): string {
|
|
1080
1204
|
const x: i32 = this.index(v)
|
|
1081
1205
|
if (this.kindAt(x) !== JSON_VALUE_NUMBER) {
|
|
@@ -1088,12 +1212,22 @@ export class JsonDocument {
|
|
|
1088
1212
|
* Whether `v` is a number written without a fraction or an exponent whose
|
|
1089
1213
|
* value fits an `i64`: the spelling, so `1.0` is not one. `isIntegral(v)`
|
|
1090
1214
|
* asks whether the value is whole.
|
|
1215
|
+
*
|
|
1216
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1217
|
+
* nothing.
|
|
1218
|
+
* @returns true when `i64(v)` gives the exact value.
|
|
1091
1219
|
*/
|
|
1092
1220
|
isI64(v: JsonValue): boolean {
|
|
1093
1221
|
return this.readNumber(this.index(v)) && this.numbers.isInteger()
|
|
1094
1222
|
}
|
|
1095
1223
|
|
|
1096
|
-
/**
|
|
1224
|
+
/**
|
|
1225
|
+
* A number's value as an `i64` when `isI64(v)` holds, and `0` otherwise.
|
|
1226
|
+
*
|
|
1227
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1228
|
+
* nothing.
|
|
1229
|
+
* @returns the integer, or `0`.
|
|
1230
|
+
*/
|
|
1097
1231
|
i64(v: JsonValue): i64 {
|
|
1098
1232
|
// `numberI64` is already `0` for a number that is not an `i64`.
|
|
1099
1233
|
return this.readNumber(this.index(v)) ? this.numbers.numberI64() : toI64(0)
|
|
@@ -1102,24 +1236,34 @@ export class JsonDocument {
|
|
|
1102
1236
|
/**
|
|
1103
1237
|
* Whether `v` is a number written without a sign, a fraction or an exponent
|
|
1104
1238
|
* whose value fits a `u64`: the spelling, as `isI64(v)` is.
|
|
1239
|
+
*
|
|
1240
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1241
|
+
* nothing.
|
|
1242
|
+
* @returns true when `u64(v)` gives the exact value.
|
|
1105
1243
|
*/
|
|
1106
1244
|
isU64(v: JsonValue): boolean {
|
|
1107
1245
|
this.unsigned(this.index(v))
|
|
1108
1246
|
return this.unsignedFits
|
|
1109
1247
|
}
|
|
1110
1248
|
|
|
1111
|
-
/**
|
|
1249
|
+
/**
|
|
1250
|
+
* A number's value as a `u64` when `isU64(v)` holds, and `0` otherwise.
|
|
1251
|
+
*
|
|
1252
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1253
|
+
* nothing.
|
|
1254
|
+
* @returns the integer, or `0`.
|
|
1255
|
+
*/
|
|
1112
1256
|
u64(v: JsonValue): u64 {
|
|
1113
1257
|
return this.unsigned(this.index(v))
|
|
1114
1258
|
}
|
|
1115
1259
|
|
|
1116
1260
|
/**
|
|
1117
|
-
*
|
|
1261
|
+
* The digits of the number at index `x` as a `u64`, setting
|
|
1118
1262
|
* `unsignedFits` to whether it is a `u64` at all: no sign, no fraction or
|
|
1119
1263
|
* exponent, and at most 2^64 - 1. Every `u64` comes from `toU64`, which is
|
|
1120
1264
|
* a BigInt under Node, and nothing here wraps, so it means the same there.
|
|
1121
1265
|
*/
|
|
1122
|
-
unsigned(x: i32): u64 {
|
|
1266
|
+
private unsigned(x: i32): u64 {
|
|
1123
1267
|
this.unsignedFits = false
|
|
1124
1268
|
if (!this.readNumber(x) || !this.numbers.integral) {
|
|
1125
1269
|
return toU64(0)
|
|
@@ -1153,12 +1297,23 @@ export class JsonDocument {
|
|
|
1153
1297
|
* `1e2` and `1e400` are, where `isI64(v)` and `isU64(v)` go by spelling and
|
|
1154
1298
|
* by range and answer `false` for all three. `false` for any other kind and
|
|
1155
1299
|
* for a handle from an earlier parse.
|
|
1300
|
+
*
|
|
1301
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1302
|
+
* nothing.
|
|
1303
|
+
* @returns true when the value is a whole number.
|
|
1156
1304
|
*/
|
|
1157
1305
|
isIntegral(v: JsonValue): boolean {
|
|
1158
1306
|
return this.readNumber(this.index(v)) && this.numbers.isIntegral()
|
|
1159
1307
|
}
|
|
1160
1308
|
|
|
1161
|
-
/**
|
|
1309
|
+
/**
|
|
1310
|
+
* A number's nearest `f64`, ties to even, as `JSON.parse` reads it; `0` for
|
|
1311
|
+
* any other value.
|
|
1312
|
+
*
|
|
1313
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1314
|
+
* nothing.
|
|
1315
|
+
* @returns the nearest double, or `0`.
|
|
1316
|
+
*/
|
|
1162
1317
|
f64(v: JsonValue): f64 {
|
|
1163
1318
|
if (!this.readNumber(this.index(v))) {
|
|
1164
1319
|
return 0
|
|
@@ -1166,8 +1321,8 @@ export class JsonDocument {
|
|
|
1166
1321
|
return this.numbers.numberF64()
|
|
1167
1322
|
}
|
|
1168
1323
|
|
|
1169
|
-
/**
|
|
1170
|
-
readNumber(x: i32): boolean {
|
|
1324
|
+
/** Points the number tokenizer at index `x`'s text and reads its one token; `false` when it is not a number. */
|
|
1325
|
+
private readNumber(x: i32): boolean {
|
|
1171
1326
|
if (this.kindAt(x) !== JSON_VALUE_NUMBER) {
|
|
1172
1327
|
return false
|
|
1173
1328
|
}
|
|
@@ -1176,8 +1331,8 @@ export class JsonDocument {
|
|
|
1176
1331
|
return numbers.next() === JSON_TOK_NUMBER
|
|
1177
1332
|
}
|
|
1178
1333
|
|
|
1179
|
-
/**
|
|
1180
|
-
textOf(at: i32, n: i32): string {
|
|
1334
|
+
/** `bytes[at, at + n)` as a string, in one allocation. */
|
|
1335
|
+
private textOf(at: i32, n: i32): string {
|
|
1181
1336
|
const bytes: u8[] = this.bytes
|
|
1182
1337
|
if (at < 0 || n <= 0 || at > toI32(bytes.length) - n) {
|
|
1183
1338
|
return ""
|
|
@@ -1185,8 +1340,8 @@ export class JsonDocument {
|
|
|
1185
1340
|
return String.fromBytes(bytes, at, at + n)
|
|
1186
1341
|
}
|
|
1187
1342
|
|
|
1188
|
-
/**
|
|
1189
|
-
bytesEqual(at: i32, n: i32, s: string): boolean {
|
|
1343
|
+
/** Whether `bytes[at, at + n)` are exactly `s`'s bytes. */
|
|
1344
|
+
private bytesEqual(at: i32, n: i32, s: string): boolean {
|
|
1190
1345
|
const bytes: u8[] = this.bytes
|
|
1191
1346
|
if (toI32(s.length) !== n || at < 0 || at > toI32(bytes.length) - n) {
|
|
1192
1347
|
return false
|
|
@@ -1204,42 +1359,68 @@ export class JsonDocument {
|
|
|
1204
1359
|
// that is not there, for a value or key a builder made and no setter gave a
|
|
1205
1360
|
// range, and for every value and key after a `parse` or `parseText`.
|
|
1206
1361
|
|
|
1207
|
-
/**
|
|
1362
|
+
/**
|
|
1363
|
+
* The offset of `v`'s first byte in the bytes the document parsed.
|
|
1364
|
+
*
|
|
1365
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1366
|
+
* nothing.
|
|
1367
|
+
* @returns the byte offset, or `-1`.
|
|
1368
|
+
*/
|
|
1208
1369
|
start(v: JsonValue): i32 {
|
|
1209
1370
|
const x: i32 = this.index(v)
|
|
1210
1371
|
return this.hasValueRange(x) ? jsonValueGet(this.rangeArrays().valueStart, x) : -1
|
|
1211
1372
|
}
|
|
1212
1373
|
|
|
1213
|
-
/**
|
|
1374
|
+
/**
|
|
1375
|
+
* One past the offset of `v`'s last byte: `v` is `src[start(v), end(v))`.
|
|
1376
|
+
*
|
|
1377
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1378
|
+
* nothing.
|
|
1379
|
+
* @returns the byte offset, or `-1`.
|
|
1380
|
+
*/
|
|
1214
1381
|
end(v: JsonValue): i32 {
|
|
1215
1382
|
const x: i32 = this.index(v)
|
|
1216
1383
|
return this.hasValueRange(x) ? jsonValueGet(this.rangeArrays().valueEnd, x) : -1
|
|
1217
1384
|
}
|
|
1218
1385
|
|
|
1219
|
-
/**
|
|
1386
|
+
/**
|
|
1387
|
+
* The offset of the first byte of the key of member `i` of object `o`, its
|
|
1388
|
+
* opening quote.
|
|
1389
|
+
*
|
|
1390
|
+
* @param o - an object handle.
|
|
1391
|
+
* @param i - the member position, from 0.
|
|
1392
|
+
* @returns the byte offset, or `-1`.
|
|
1393
|
+
*/
|
|
1220
1394
|
keyStart(o: JsonValue, i: i32): i32 {
|
|
1221
1395
|
const s: i32 = this.keySlot(this.index(o), i)
|
|
1222
1396
|
return this.hasKeyRange(s) ? jsonValueGet(this.rangeArrays().slotKeyStart, s) : -1
|
|
1223
1397
|
}
|
|
1224
1398
|
|
|
1225
|
-
/**
|
|
1399
|
+
/**
|
|
1400
|
+
* One past the offset of the last byte of the key of member `i` of object
|
|
1401
|
+
* `o`, its closing quote.
|
|
1402
|
+
*
|
|
1403
|
+
* @param o - an object handle.
|
|
1404
|
+
* @param i - the member position, from 0.
|
|
1405
|
+
* @returns the byte offset, or `-1`.
|
|
1406
|
+
*/
|
|
1226
1407
|
keyEnd(o: JsonValue, i: i32): i32 {
|
|
1227
1408
|
const s: i32 = this.keySlot(this.index(o), i)
|
|
1228
1409
|
return this.hasKeyRange(s) ? jsonValueGet(this.rangeArrays().slotKeyEnd, s) : -1
|
|
1229
1410
|
}
|
|
1230
1411
|
|
|
1231
|
-
/**
|
|
1232
|
-
hasValueRange(x: i32): boolean {
|
|
1412
|
+
/** Whether value `x` has a current range: below `rangeTop`, and written in this generation. */
|
|
1413
|
+
private hasValueRange(x: i32): boolean {
|
|
1233
1414
|
return x >= 0 && x < this.rangeTop && this.rangeGeneration === this.generation
|
|
1234
1415
|
}
|
|
1235
1416
|
|
|
1236
|
-
/**
|
|
1237
|
-
hasKeyRange(s: i32): boolean {
|
|
1417
|
+
/** Whether slot `s` has a current key range: below `slotRangeTop`, and written in this generation. */
|
|
1418
|
+
private hasKeyRange(s: i32): boolean {
|
|
1238
1419
|
return s >= 0 && s < this.slotRangeTop && this.rangeGeneration === this.generation
|
|
1239
1420
|
}
|
|
1240
1421
|
|
|
1241
|
-
/**
|
|
1242
|
-
rangeArrays(): JsonValueRanges {
|
|
1422
|
+
/** The range arrays, made the first time a parse or setter writes a range. */
|
|
1423
|
+
private rangeArrays(): JsonValueRanges {
|
|
1243
1424
|
const had: JsonValueRanges | null = this.ranges
|
|
1244
1425
|
if (had !== null) {
|
|
1245
1426
|
return had
|
|
@@ -1249,8 +1430,8 @@ export class JsonDocument {
|
|
|
1249
1430
|
return made
|
|
1250
1431
|
}
|
|
1251
1432
|
|
|
1252
|
-
/**
|
|
1253
|
-
ownRanges(): void {
|
|
1433
|
+
/** Before a setter writes a range, forgets an earlier generation's, so that none of them reads as this one's. */
|
|
1434
|
+
private ownRanges(): void {
|
|
1254
1435
|
if (this.rangeGeneration !== this.generation) {
|
|
1255
1436
|
this.rangeTop = 0
|
|
1256
1437
|
this.slotRangeTop = 0
|
|
@@ -1263,6 +1444,11 @@ export class JsonDocument {
|
|
|
1263
1444
|
* from another text with the `new*` methods and keeps where each value
|
|
1264
1445
|
* came from. `JSON_VALUE_OK`, `JSON_VALUE_ERR_HANDLE`, or
|
|
1265
1446
|
* `JSON_VALUE_ERR_RANGE` when `0 <= start <= end` does not hold.
|
|
1447
|
+
*
|
|
1448
|
+
* @param v - the value to give the range to.
|
|
1449
|
+
* @param start - the offset of its first byte in the other text.
|
|
1450
|
+
* @param end - one past the offset of its last byte.
|
|
1451
|
+
* @returns `JSON_VALUE_OK` or the error code.
|
|
1266
1452
|
*/
|
|
1267
1453
|
setRange(v: JsonValue, start: i32, end: i32): i32 {
|
|
1268
1454
|
const x: i32 = this.index(v)
|
|
@@ -1291,6 +1477,12 @@ export class JsonDocument {
|
|
|
1291
1477
|
* Gives the key of member `i` of object `o` the range `[start, end)`, as
|
|
1292
1478
|
* `setRange` does a value's. `JSON_VALUE_ERR_HANDLE` when `o` is not an
|
|
1293
1479
|
* object or has no member `i`.
|
|
1480
|
+
*
|
|
1481
|
+
* @param o - an object handle.
|
|
1482
|
+
* @param i - the member position, from 0.
|
|
1483
|
+
* @param start - the offset of the key's first byte in the other text.
|
|
1484
|
+
* @param end - one past the offset of its last byte.
|
|
1485
|
+
* @returns `JSON_VALUE_OK` or the error code.
|
|
1294
1486
|
*/
|
|
1295
1487
|
setKeyRange(o: JsonValue, i: i32, start: i32, end: i32): i32 {
|
|
1296
1488
|
const s: i32 = this.keySlot(this.index(o), i)
|
|
@@ -1314,8 +1506,8 @@ export class JsonDocument {
|
|
|
1314
1506
|
return JSON_VALUE_OK
|
|
1315
1507
|
}
|
|
1316
1508
|
|
|
1317
|
-
/**
|
|
1318
|
-
keySlot(x: i32, i: i32): i32 {
|
|
1509
|
+
/** The slot of member `i` of the object at index `x`, or `-1` when `x` is not an object or has no member `i`. */
|
|
1510
|
+
private keySlot(x: i32, i: i32): i32 {
|
|
1319
1511
|
return this.kindAt(x) === JSON_VALUE_OBJECT ? this.slotAt(x, i) : -1
|
|
1320
1512
|
}
|
|
1321
1513
|
|
|
@@ -1323,27 +1515,58 @@ export class JsonDocument {
|
|
|
1323
1515
|
// Each `new*` answers a handle, or `JSON_VALUE_ERR_VALUES` when the document
|
|
1324
1516
|
// already holds `maxValues`.
|
|
1325
1517
|
|
|
1518
|
+
/**
|
|
1519
|
+
* A new `null`.
|
|
1520
|
+
*
|
|
1521
|
+
* @returns the new value's handle, in no container yet, or
|
|
1522
|
+
* `JSON_VALUE_ERR_VALUES` when the document already holds `maxValues`.
|
|
1523
|
+
*/
|
|
1326
1524
|
newNull(): JsonValue {
|
|
1327
1525
|
return this.handle(this.newNode(JSON_VALUE_NULL, JSON_VALUE_NO_WORD, JSON_VALUE_NO_WORD))
|
|
1328
1526
|
}
|
|
1329
1527
|
|
|
1528
|
+
/**
|
|
1529
|
+
* A new boolean.
|
|
1530
|
+
*
|
|
1531
|
+
* @param b - the value it holds.
|
|
1532
|
+
* @returns the new value's handle, in no container yet, or
|
|
1533
|
+
* `JSON_VALUE_ERR_VALUES` when the document already holds `maxValues`.
|
|
1534
|
+
*/
|
|
1330
1535
|
newBoolean(b: boolean): JsonValue {
|
|
1331
1536
|
return this.handle(
|
|
1332
1537
|
this.newNode(JSON_VALUE_BOOLEAN, b ? JSON_VALUE_TRUE_WORD : JSON_VALUE_NO_WORD, JSON_VALUE_NO_WORD)
|
|
1333
1538
|
)
|
|
1334
1539
|
}
|
|
1335
1540
|
|
|
1336
|
-
/**
|
|
1541
|
+
/**
|
|
1542
|
+
* A string holding `s`'s bytes.
|
|
1543
|
+
*
|
|
1544
|
+
* @param s - the text, copied into the document.
|
|
1545
|
+
* @returns the new value's handle, in no container yet, or
|
|
1546
|
+
* `JSON_VALUE_ERR_VALUES` when the document already holds `maxValues`.
|
|
1547
|
+
*/
|
|
1337
1548
|
newString(s: string): JsonValue {
|
|
1338
1549
|
return this.newStored(JSON_VALUE_STRING, s)
|
|
1339
1550
|
}
|
|
1340
1551
|
|
|
1341
|
-
/**
|
|
1552
|
+
/**
|
|
1553
|
+
* A number holding `x`'s digits.
|
|
1554
|
+
*
|
|
1555
|
+
* @param x - the value, written in decimal.
|
|
1556
|
+
* @returns the new value's handle, in no container yet, or
|
|
1557
|
+
* `JSON_VALUE_ERR_VALUES` when the document already holds `maxValues`.
|
|
1558
|
+
*/
|
|
1342
1559
|
newI64(x: i64): JsonValue {
|
|
1343
1560
|
return this.newStored(JSON_VALUE_NUMBER, `${x}`)
|
|
1344
1561
|
}
|
|
1345
1562
|
|
|
1346
|
-
/**
|
|
1563
|
+
/**
|
|
1564
|
+
* A number holding `x`'s digits.
|
|
1565
|
+
*
|
|
1566
|
+
* @param x - the value, written in decimal.
|
|
1567
|
+
* @returns the new value's handle, in no container yet, or
|
|
1568
|
+
* `JSON_VALUE_ERR_VALUES` when the document already holds `maxValues`.
|
|
1569
|
+
*/
|
|
1347
1570
|
newU64(x: u64): JsonValue {
|
|
1348
1571
|
return this.newStored(JSON_VALUE_NUMBER, `${x}`)
|
|
1349
1572
|
}
|
|
@@ -1353,6 +1576,11 @@ export class JsonDocument {
|
|
|
1353
1576
|
* read back as `x`, with `-0` as `0`: what `JsonWriter.f64` writes.
|
|
1354
1577
|
* `JSON_VALUE_ERR_NUMBER` for NaN and both infinities, which JSON cannot
|
|
1355
1578
|
* spell.
|
|
1579
|
+
*
|
|
1580
|
+
* @param x - the value; it must be finite.
|
|
1581
|
+
* @returns the new value's handle, in no container yet, or
|
|
1582
|
+
* `JSON_VALUE_ERR_VALUES` when the document already holds `maxValues`.
|
|
1583
|
+
* `JSON_VALUE_ERR_NUMBER` for a value that is not finite.
|
|
1356
1584
|
*/
|
|
1357
1585
|
newF64(x: f64): JsonValue {
|
|
1358
1586
|
// `x - x` is `0` for every finite `x`, and NaN for NaN and both infinities.
|
|
@@ -1366,6 +1594,11 @@ export class JsonDocument {
|
|
|
1366
1594
|
* A number holding `text` exactly, which must be one JSON number and
|
|
1367
1595
|
* nothing else (RFC 8259 §6); `JSON_VALUE_ERR_NUMBER` otherwise. This is how
|
|
1368
1596
|
* a program writes a number no integer or float type holds.
|
|
1597
|
+
*
|
|
1598
|
+
* @param text - the number text, such as `"1e400"`.
|
|
1599
|
+
* @returns the new value's handle, in no container yet, or
|
|
1600
|
+
* `JSON_VALUE_ERR_VALUES` when the document already holds `maxValues`.
|
|
1601
|
+
* `JSON_VALUE_ERR_NUMBER` for text that is not one number.
|
|
1369
1602
|
*/
|
|
1370
1603
|
newNumber(text: string): JsonValue {
|
|
1371
1604
|
const at: i32 = this.byteTop
|
|
@@ -1382,15 +1615,34 @@ export class JsonDocument {
|
|
|
1382
1615
|
return this.handle(this.newNode(JSON_VALUE_NUMBER, at, n))
|
|
1383
1616
|
}
|
|
1384
1617
|
|
|
1618
|
+
/**
|
|
1619
|
+
* A new empty array, which `push` fills.
|
|
1620
|
+
*
|
|
1621
|
+
* @returns the new value's handle, in no container yet, or
|
|
1622
|
+
* `JSON_VALUE_ERR_VALUES` when the document already holds `maxValues`.
|
|
1623
|
+
*/
|
|
1385
1624
|
newArray(): JsonValue {
|
|
1386
1625
|
return this.handle(this.newNode(JSON_VALUE_ARRAY, this.slotTop, JSON_VALUE_NO_WORD))
|
|
1387
1626
|
}
|
|
1388
1627
|
|
|
1628
|
+
/**
|
|
1629
|
+
* A new empty object, which `set` fills.
|
|
1630
|
+
*
|
|
1631
|
+
* @returns the new value's handle, in no container yet, or
|
|
1632
|
+
* `JSON_VALUE_ERR_VALUES` when the document already holds `maxValues`.
|
|
1633
|
+
*/
|
|
1389
1634
|
newObject(): JsonValue {
|
|
1390
1635
|
return this.handle(this.newNode(JSON_VALUE_OBJECT, this.slotTop, JSON_VALUE_NO_WORD))
|
|
1391
1636
|
}
|
|
1392
1637
|
|
|
1393
|
-
/**
|
|
1638
|
+
/**
|
|
1639
|
+
* Appends `v` to array `a`. `JSON_VALUE_OK`, or `JSON_VALUE_ERR_HANDLE` or
|
|
1640
|
+
* `JSON_VALUE_ERR_ATTACHED`.
|
|
1641
|
+
*
|
|
1642
|
+
* @param a - the array to append to.
|
|
1643
|
+
* @param v - the value to append, which must be in no container.
|
|
1644
|
+
* @returns `JSON_VALUE_OK` or the error code.
|
|
1645
|
+
*/
|
|
1394
1646
|
push(a: JsonValue, v: JsonValue): i32 {
|
|
1395
1647
|
const ax: i32 = this.index(a)
|
|
1396
1648
|
const vx: i32 = this.index(v)
|
|
@@ -1411,6 +1663,11 @@ export class JsonDocument {
|
|
|
1411
1663
|
* property of a JavaScript object does. The value it replaces leaves the
|
|
1412
1664
|
* object and is in no container afterwards. `JSON_VALUE_OK`, or
|
|
1413
1665
|
* `JSON_VALUE_ERR_HANDLE` or `JSON_VALUE_ERR_ATTACHED`.
|
|
1666
|
+
*
|
|
1667
|
+
* @param o - the object to change.
|
|
1668
|
+
* @param key - the member key.
|
|
1669
|
+
* @param v - the value, which must be in no container.
|
|
1670
|
+
* @returns `JSON_VALUE_OK` or the error code.
|
|
1414
1671
|
*/
|
|
1415
1672
|
set(o: JsonValue, key: string, v: JsonValue): i32 {
|
|
1416
1673
|
const ox: i32 = this.index(o)
|
|
@@ -1434,12 +1691,12 @@ export class JsonDocument {
|
|
|
1434
1691
|
}
|
|
1435
1692
|
|
|
1436
1693
|
/**
|
|
1437
|
-
*
|
|
1694
|
+
* Whether the value at index `v` may go into the container at
|
|
1438
1695
|
* index `c`: it is a value, it is in no container, and it is not `c` or a
|
|
1439
1696
|
* container `c` is inside. Through `push` and `set`, that is what keeps
|
|
1440
1697
|
* every tree finite.
|
|
1441
1698
|
*/
|
|
1442
|
-
adoptable(c: i32, v: i32): i32 {
|
|
1699
|
+
private adoptable(c: i32, v: i32): i32 {
|
|
1443
1700
|
if (this.kindAt(v) === JSON_VALUE_NONE) {
|
|
1444
1701
|
return JSON_VALUE_ERR_HANDLE
|
|
1445
1702
|
}
|
|
@@ -1457,11 +1714,14 @@ export class JsonDocument {
|
|
|
1457
1714
|
}
|
|
1458
1715
|
|
|
1459
1716
|
/**
|
|
1460
|
-
*
|
|
1717
|
+
* Adds index `v`, with the key `bytes[keyAt, keyAt + keyLength)`,
|
|
1461
1718
|
* after the last member of index `c`, unchecked: `push` and `set` check
|
|
1462
1719
|
* first. A container whose slots are full moves them to the end of the slot
|
|
1463
1720
|
* arrays with twice the room, unless they are at the end already, where they
|
|
1464
1721
|
* grow in place; the slots it leaves are not reused until `clear`.
|
|
1722
|
+
*
|
|
1723
|
+
* @internal Read by std/yaml-json.ts, which builds a document from YAML
|
|
1724
|
+
* through it.
|
|
1465
1725
|
*/
|
|
1466
1726
|
append(c: i32, v: i32, keyAt: i32, keyLength: i32): void {
|
|
1467
1727
|
let start: i32 = jsonValueGet(this.first, c)
|
|
@@ -1486,19 +1746,19 @@ export class JsonDocument {
|
|
|
1486
1746
|
jsonValuePut(this.parent, v, c)
|
|
1487
1747
|
}
|
|
1488
1748
|
|
|
1489
|
-
/**
|
|
1490
|
-
newStored(kind: i32, s: string): JsonValue {
|
|
1749
|
+
/** A new value of `kind` holding `s`'s bytes, as a handle. */
|
|
1750
|
+
private newStored(kind: i32, s: string): JsonValue {
|
|
1491
1751
|
return this.handle(this.newNode(kind, this.byteTop, this.storeText(s)))
|
|
1492
1752
|
}
|
|
1493
1753
|
|
|
1494
1754
|
/**
|
|
1495
|
-
*
|
|
1755
|
+
* Copies the `n` slots from `start` to the end of the slot arrays,
|
|
1496
1756
|
* key ranges with them, and answers where they now start. Key ranges move
|
|
1497
1757
|
* only when the slots are below `slotRangeTop` and of this generation, the
|
|
1498
1758
|
* test that comes first: a document that never keeps ranges, or a builder's
|
|
1499
1759
|
* own slots, skip the copy without leaving `append`'s loop.
|
|
1500
1760
|
*/
|
|
1501
|
-
moveSlots(start: i32, n: i32): i32 {
|
|
1761
|
+
private moveSlots(start: i32, n: i32): i32 {
|
|
1502
1762
|
const moved: i32 = this.slotTop
|
|
1503
1763
|
for (let i: i32 = 0; i < n; i += 1) {
|
|
1504
1764
|
jsonValuePut(this.slotValue, moved + i, jsonValueGet(this.slotValue, start + i))
|
|
@@ -1512,13 +1772,13 @@ export class JsonDocument {
|
|
|
1512
1772
|
}
|
|
1513
1773
|
|
|
1514
1774
|
/**
|
|
1515
|
-
*
|
|
1775
|
+
* `append` moving the `n` slots from `from`, some of them below
|
|
1516
1776
|
* `slotRangeTop`, to `to`, the end of the slots: their key ranges move with
|
|
1517
1777
|
* them, and the slots between keep none. `moveSlots` has checked the
|
|
1518
1778
|
* generation, and a slot below `slotRangeTop` means the arrays were made;
|
|
1519
1779
|
* reading them here, not through `rangeArrays`, keeps `append` small.
|
|
1520
1780
|
*/
|
|
1521
|
-
moveKeyRanges(from: i32, to: i32, n: i32): void {
|
|
1781
|
+
private moveKeyRanges(from: i32, to: i32, n: i32): void {
|
|
1522
1782
|
const r: JsonValueRanges | null = this.ranges
|
|
1523
1783
|
const top: i32 = this.slotRangeTop
|
|
1524
1784
|
if (r !== null) {
|
|
@@ -1535,7 +1795,15 @@ export class JsonDocument {
|
|
|
1535
1795
|
}
|
|
1536
1796
|
}
|
|
1537
1797
|
|
|
1538
|
-
/**
|
|
1798
|
+
/**
|
|
1799
|
+
* Appends `s`'s bytes to the end of `bytes`.
|
|
1800
|
+
*
|
|
1801
|
+
* @param s - the text whose bytes are stored.
|
|
1802
|
+
* @returns how many bytes were stored.
|
|
1803
|
+
*
|
|
1804
|
+
* @internal Read by std/yaml-json.ts, which builds a document from YAML
|
|
1805
|
+
* through it.
|
|
1806
|
+
*/
|
|
1539
1807
|
storeText(s: string): i32 {
|
|
1540
1808
|
const n: i32 = toI32(s.length)
|
|
1541
1809
|
const at: i32 = this.byteTop
|
|
@@ -1558,13 +1826,17 @@ export class JsonDocument {
|
|
|
1558
1826
|
* nothing writes nothing and fails nothing. A parsed tree is never deeper
|
|
1559
1827
|
* than the writer nests; a built one deeper than `JSON_WRITER_MAX_DEPTH`
|
|
1560
1828
|
* ends at `JSON_WRITE_TOO_DEEP`, where the recursion stops.
|
|
1829
|
+
*
|
|
1830
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1831
|
+
* nothing.
|
|
1832
|
+
* @param w - the writer, where a value is due.
|
|
1561
1833
|
*/
|
|
1562
1834
|
write(v: JsonValue, w: JsonWriter): void {
|
|
1563
1835
|
this.writeAt(this.index(v), w)
|
|
1564
1836
|
}
|
|
1565
1837
|
|
|
1566
|
-
/**
|
|
1567
|
-
writeAt(x: i32, w: JsonWriter): void {
|
|
1838
|
+
/** `write` of index `x`. */
|
|
1839
|
+
private writeAt(x: i32, w: JsonWriter): void {
|
|
1568
1840
|
const k: i32 = this.kindAt(x)
|
|
1569
1841
|
if (k === JSON_VALUE_NONE || w.failed !== JSON_WRITE_OK) {
|
|
1570
1842
|
return
|
|
@@ -1606,6 +1878,10 @@ export class JsonDocument {
|
|
|
1606
1878
|
* fits, then made into one string. `""` when `v` names nothing or the
|
|
1607
1879
|
* writer refuses it, which only a built tree deeper than
|
|
1608
1880
|
* `JSON_WRITER_MAX_DEPTH` makes it do; `write` gives the code.
|
|
1881
|
+
*
|
|
1882
|
+
* @param v - a handle from this document; one from an earlier parse names
|
|
1883
|
+
* nothing.
|
|
1884
|
+
* @returns the minified text, or `""`.
|
|
1609
1885
|
*/
|
|
1610
1886
|
stringify(v: JsonValue): string {
|
|
1611
1887
|
// Every byte stored and a few of punctuation per value: one pass fits most
|