@amritk/nish-aarch64-linux 0.36.0 → 0.37.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.
Files changed (87) hide show
  1. package/INSTALL.md +67 -58
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +43 -4
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +2 -0
  6. package/runtime/async.mjs +7 -0
  7. package/runtime/nish.d.ts +736 -499
  8. package/runtime/nish.h +25 -0
  9. package/runtime/page.d.ts +53 -0
  10. package/runtime/page.mjs +146 -0
  11. package/runtime/runtime-async.c +557 -0
  12. package/runtime/runtime-wasm.c +63 -7
  13. package/scripts/build.sh +147 -5
  14. package/std/README.md +107 -82
  15. package/std/bytes.ts +23 -19
  16. package/std/compress/checksum.ts +1 -1
  17. package/std/crypto/aes.ts +48 -43
  18. package/std/crypto/base64url.ts +7 -5
  19. package/std/crypto/bcrypt-batch.ts +13 -13
  20. package/std/crypto/bcrypt.ts +33 -27
  21. package/std/crypto/chacha20poly1305.ts +16 -14
  22. package/std/crypto/ed25519.ts +19 -16
  23. package/std/crypto/hmac.ts +7 -6
  24. package/std/crypto/jwt.ts +23 -20
  25. package/std/crypto/p256.ts +63 -56
  26. package/std/crypto/p384.ts +23 -20
  27. package/std/crypto/pki.ts +18 -15
  28. package/std/crypto/rsa.ts +23 -19
  29. package/std/crypto/x25519.ts +11 -10
  30. package/std/crypto/x509.ts +69 -62
  31. package/std/host/ring.ts +124 -0
  32. package/std/json-equal.ts +12 -11
  33. package/std/json-number.ts +12 -12
  34. package/std/json-tokenizer.ts +26 -22
  35. package/std/json-typed.ts +92 -78
  36. package/std/json-value.ts +38 -33
  37. package/std/json.ts +32 -28
  38. package/std/net/fetch.ts +1117 -230
  39. package/std/net/handler.ts +18 -0
  40. package/std/net/hpack.ts +29 -26
  41. package/std/net/http-compress.ts +27 -21
  42. package/std/net/http1-client-codec.ts +29 -25
  43. package/std/net/http1-codec.ts +44 -87
  44. package/std/net/http1-server.ts +66 -54
  45. package/std/net/http2-frame.ts +17 -16
  46. package/std/net/http2-tls.ts +17 -15
  47. package/std/net/http2.ts +67 -54
  48. package/std/net/http3-frame.ts +11 -10
  49. package/std/net/http3-server.ts +36 -35
  50. package/std/net/http3.ts +70 -58
  51. package/std/net/postgres.ts +178 -160
  52. package/std/net/prefork.ts +38 -34
  53. package/std/net/qpack.ts +15 -14
  54. package/std/net/quic-conn-ack.ts +1 -0
  55. package/std/net/quic-conn-cid.ts +11 -0
  56. package/std/net/quic-conn-params.ts +41 -14
  57. package/std/net/quic-datagram.ts +7 -0
  58. package/std/net/quic-frame.ts +48 -12
  59. package/std/net/quic-listener.ts +61 -44
  60. package/std/net/quic-packet.ts +71 -52
  61. package/std/net/quic-recovery.ts +59 -21
  62. package/std/net/quic-stream.ts +83 -55
  63. package/std/net/quic.ts +204 -152
  64. package/std/net/tls/client.ts +1 -0
  65. package/std/net/tls/codec.ts +81 -12
  66. package/std/net/tls/record-client.ts +30 -18
  67. package/std/net/tls/record-server.ts +74 -46
  68. package/std/net/tls/record.ts +33 -24
  69. package/std/net/tls/ticket.ts +2 -0
  70. package/std/net/tls/verify.ts +8 -7
  71. package/std/net/tls-tcp.ts +58 -50
  72. package/std/net/tls.ts +55 -43
  73. package/std/net/url.ts +12 -9
  74. package/std/net/websocket.ts +23 -19
  75. package/std/net/webtransport.ts +24 -18
  76. package/std/random.ts +8 -6
  77. package/std/regex.ts +70 -59
  78. package/std/sync/ring.ts +24 -21
  79. package/std/sync/shm.ts +9 -7
  80. package/std/term-io.ts +17 -14
  81. package/std/term-probe.ts +11 -10
  82. package/std/term-rate.ts +71 -61
  83. package/std/term.ts +73 -59
  84. package/std/text.ts +11 -10
  85. package/std/threads.ts +19 -15
  86. package/std/yaml-json.ts +17 -15
  87. package/std/yaml-write.ts +21 -14
@@ -42,31 +42,35 @@
42
42
  * any well-formed UTF-8 (RFC 3629: no overlong form, no surrogate code point,
43
43
  * nothing past U+10FFFF, no sequence cut short), no raw byte below 0x20, and
44
44
  * the escapes of RFC 8259 §7. A `\u` escape of a high surrogate must be
45
- * followed at once by one of a low surrogate, and a low surrogate must follow
46
- * a high one: a lone surrogate escape is an error. RFC 8259 allows one, but it
47
- * names no Unicode character, decodes to no valid UTF-8, and is what a peer
48
- * smuggles past a check done on the decoded bytes, so this module takes the
49
- * stricter reading (`docs/security/json.md`, "Lone surrogates"). Nothing is decoded until
50
- * the caller asks: `stringInto` writes the decoded bytes of the current key
51
- * or string into the caller's array, and `keyEquals` compares them with a
52
- * string without writing them anywhere.
45
+ * followed at once by one of a low surrogate, and a low surrogate must follow a
46
+ * high one: a lone surrogate escape is an error.
47
+ *
48
+ * RFC 8259 allows one, but it names no Unicode character, decodes to no valid
49
+ * UTF-8, and is what a peer smuggles past a check done on the decoded bytes, so
50
+ * this module takes the stricter reading (`docs/security/json.md`, "Lone
51
+ * surrogates"). Nothing is decoded until the caller asks: `stringInto` writes
52
+ * the decoded bytes of the current key or string into the caller's array, and
53
+ * `keyEquals` compares them with a string without writing them anywhere.
53
54
  *
54
55
  * **Numbers are checked against the grammar and parsed on request.**
55
56
  * `numberF64` is correctly rounded, ties to even, in one of three ways. A
56
- * number of at most 19 significant digits is read into a `u64`. When that is
57
- * at most 2^53 and the decimal exponent is within ±22, the answer is one exact
58
- * multiply or divide of two exact doubles (Clinger's fast path). Any other
59
- * number of at most 19 digits is the Eisel–Lemire algorithm as fast_float
60
- * computes it: one or two 64×64-bit products with a truncated power of five,
61
- * which Mushtak and Lemire prove always decide the rounding for so few digits,
62
- * so it never needs a fallback. A number of more digits, or with an exponent
63
- * past `JSON_TOK_EXPONENT_CAP`, goes to the runtime's `parseFloat`, which is
64
- * `strtod`, from a function whose own arena scope releases the copy it reads,
65
- * so it leaves the arena where it was. `isInteger` and `numberI64` read a number
66
- * written without a fraction or an exponent that fits in an `i64`, and
67
- * `isU64` and `numberU64` one written without a sign either that fits in a
68
- * `u64`. Those go by spelling; `isIntegral` asks whether the value is whole,
69
- * however it is written (`1.0`, `1e2`), from the text and at any size.
57
+ * number of at most 19 significant digits is read into a `u64`. When that is at
58
+ * most 2^53 and the decimal exponent is within ±22, the answer is one exact
59
+ * multiply or divide of two exact doubles (Clinger's fast path).
60
+ *
61
+ * Any other number of at most 19 digits is the Eisel–Lemire algorithm as
62
+ * fast_float computes it: one or two 64×64-bit products with a truncated power
63
+ * of five, which Mushtak and Lemire prove always decide the rounding for so few
64
+ * digits, so it never needs a fallback. A number of more digits, or with an
65
+ * exponent past `JSON_TOK_EXPONENT_CAP`, goes to the runtime's `parseFloat`,
66
+ * which is `strtod`, from a function whose own arena scope releases the copy it
67
+ * reads, so it leaves the arena where it was.
68
+ *
69
+ * `isInteger` and `numberI64` read a number written without a fraction or an
70
+ * exponent that fits in an `i64`, and `isU64` and `numberU64` one written
71
+ * without a sign either that fits in a `u64`. Those go by spelling;
72
+ * `isIntegral` asks whether the value is whole, however it is written (`1.0`,
73
+ * `1e2`), from the text and at any size.
70
74
  *
71
75
  * **Runs are read in bulk.** A string's plain bytes, the blanks between
72
76
  * tokens and a number's digits are each stepped over by a loop that reads
package/std/json-typed.ts CHANGED
@@ -15,19 +15,20 @@
15
15
  * jsonEncode(w, p); // out[0 .. w.end) is {"x":..,"y":..}
16
16
  * }
17
17
  *
18
- * **What is generated, and from what.** `jsonDecode(d, out)` and
19
- * `jsonEncode(w, value)` are generic, and the bodies written below are not
20
- * what runs natively: the compiler lowers every call in place, in the module
21
- * that makes it, to code it writes from the layout of the class the call
22
- * binds `T` to (`src/json-typed.ts`, `src/emit-json.ts`). That code is
23
- * straight-line calls into the methods of `JsonDecoder` and the functions
24
- * here for each field, and into `JsonWriter`'s, so all of the parsing is the
25
- * tokenizer's and all of the writing is the writer's. A field may be an
26
- * `i32`, `u32`, `i64`, `u64`, `f64` (or `number`), `boolean` or `string`, a
27
- * numeric enum (its number), a class decoded the same way, a `JsonNumber`, an
28
- * array of any of those, a `Map<string, V>` (a JSON object) whose `V` is any
29
- * of these, or a string, class, array or map `| null`; anything else is
30
- * refused at the call, naming the field (docs/LANGUAGE.md, "Typed JSON").
18
+ * **What is generated, and from what.** `jsonDecode(d, out)` and `jsonEncode(w,
19
+ * value)` are generic, and the bodies written below are not what runs natively:
20
+ * the compiler lowers every call in place, in the module that makes it, to code
21
+ * it writes from the layout of the class the call binds `T` to
22
+ * (`src/json-typed.ts`, `src/emit-json.ts`).
23
+ *
24
+ * That code is straight-line calls into the methods of `JsonDecoder` and the
25
+ * functions here for each field, and into `JsonWriter`'s, so all of the parsing
26
+ * is the tokenizer's and all of the writing is the writer's. A field may be an
27
+ * `i32`, `u32`, `i64`, `u64`, `f64` (or `number`), `boolean` or `string`, a
28
+ * numeric enum (its number), a class decoded the same way, a `JsonNumber`, an
29
+ * array of any of those, a `Map<string, V>` (a JSON object) whose `V` is any of
30
+ * these, or a string, class, array or map `| null`; anything else is refused at
31
+ * the call, naming the field (docs/LANGUAGE.md, "Typed JSON").
31
32
  *
32
33
  * **Call shapes.** `jsonDecode(d, out)` reads the one JSON object `d` holds
33
34
  * into `out`, a declared class, and answers `d.failed`: `JSON_DECODE_OK` (0)
@@ -72,18 +73,22 @@
72
73
  *
73
74
  * A `Map`'s `V` is any type in this list, `| null` or not, a `Map` included;
74
75
  * `JsonNumber` may stand alone, be `| null`, be an array's element or be a
75
- * `Map`'s value. The code written for a nested class, an array's element
76
- * class, a `| null` field's class and a `Map`'s values is the same code, so it
77
- * recurses as the data does. Anything else is refused at the call's argument,
78
- * naming the class and the field (NL2485 for a field type, such as an `f32`,
79
- * an `i32[][]`, a `Level[][]`, a `Set`, an array of maps, a `Map` not keyed by
80
- * `string` (an enum key included) or a `Map` whose values cannot be written,
81
- * and a generic class of the program's own). An enum whose members are strings
82
- * or a mix is not one the language declares (NL1043), and a `const enum` is
83
- * refused where it is declared (NL2285). A value that is not a declared class
84
- * (an interface, a generic class or any other type) is NL2486; decoding into an
85
- * interface is left for a later version. A call inside a generic function is
86
- * checked for each class an instantiation binds.
76
+ * `Map`'s value. The code written for a nested class, an array's element class,
77
+ * a `| null` field's class and a `Map`'s values is the same code, so it
78
+ * recurses as the data does.
79
+ *
80
+ * Anything else is refused at the call's argument, naming the class and the
81
+ * field (NL2485 for a field type, such as an `f32`, an `i32[][]`, a
82
+ * `Level[][]`, a `Set`, an array of maps, a `Map` not keyed by `string` (an
83
+ * enum key included) or a `Map` whose values cannot be written, and a generic
84
+ * class of the program's own). An enum whose members are strings or a mix is
85
+ * not one the language declares (NL1043), and a `const enum` is refused where
86
+ * it is declared (NL2285).
87
+ *
88
+ * A value that is not a declared class (an interface, a generic class or any
89
+ * other type) is NL2486; decoding into an interface is left for a later
90
+ * version. A call inside a generic function is checked for each class an
91
+ * instantiation binds.
87
92
  *
88
93
  * **Reading the class.** A class the decoder has to make itself, an array's
89
94
  * element past the end, a `| null` field that holds `null` or a map's value,
@@ -100,10 +105,11 @@
100
105
  * once more, on the key's byte at the one position where those names differ
101
106
  * most, and calls `keyIs` for each name with that byte there, in declaration
102
107
  * order; a byte none of them has is an unknown key at once. One or two names
103
- * are compared in turn with `keyIs`. A key with an escape has no byte to switch
104
- * on there and is compared with every name of its length, so `"id"` is
105
- * the field `id`; a field name that is not ASCII is dispatched by its UTF-8
106
- * bytes like any other.
108
+ * are compared in turn with `keyIs`.
109
+ *
110
+ * A key with an escape has no byte to switch on there and is compared with
111
+ * every name of its length, so `"id"` is the field `id`; a field name that is
112
+ * not ASCII is dispatched by its UTF-8 bytes like any other.
107
113
  *
108
114
  * **The decoding rules.** A JSON object's keys are the class's field names,
109
115
  * byte for byte, or the keys its options give them, found by the key's length
@@ -115,39 +121,44 @@
115
121
  * }
116
122
  *
117
123
  * The compiler reads that literal; it is not a field. Every field is required
118
- * but an optional one, whose missing key sets it to its initializer, a key
119
- * may appear once, and a key that names no field is an error unless
120
- * `ignoreUnknown` is set, when its value is stepped over, checked but not
121
- * kept. A number must fit its field: an integer field takes
122
- * an integer written without a fraction or an exponent and in the field's
123
- * range, and `f64` takes any number. `null` is accepted only by a field whose
124
- * type is `| null`. Fields are written to `out` as they are read, in the
125
- * input's order: a nested object is decoded into the object the field already
126
- * holds, an array's elements into the elements it already has, with new ones
127
- * made past its end and the rest dropped (so a reused
128
- * object reuses its arrays and objects, and `Arena.used()` stays flat: it is
129
- * flat over 1,000 decodes of a three-level object), and a
130
- * string field keeps the string it holds when the input's is equal. A string
131
- * that changes is a new string, made by one `String.fromBytes`, straight from
132
- * the input when it has no escape and from its unescaped bytes when it has one.
133
- * A class the decoder has to make — an array element past the array's end, a
134
- * `| null` field that holds `null`, or a map's value — is made with `new C()`.
135
- * A map is emptied once the object opens, then each key is read as a new
136
- * string and its value as a `V` made fresh for the key (a zero, `""`, the
137
- * enum's first member, `null`, or a new object, array or map) and `set`, so
138
- * the entries are the input's, in the input's order. A key the object gave
139
- * already is `JSON_DECODE_DUPLICATE` before its value is read, however either
140
- * is escaped. A value whose read fails is not `set`, so a map never holds a
141
- * value the input did not give. Unlike the rest of a decode, a map's entries
142
- * are made anew each time, so decoding into a map allocates its keys and
143
- * values. Every map of one decoding takes at most `maxMapKeys` keys between
144
- * them (4,096 unless set), the keys of a map inside another map included; the
145
- * key past it is `JSON_DECODE_MAP_LIMIT` before it is read, and `reset`
146
- * starts the count again. At `0` or below no map may take a key, and `{}` is
147
- * the one map value accepted. Encoding writes the entries in the map's own
148
- * order, which is insertion order. That differs from a JavaScript object in
149
- * one case: a key that reads as an array index (`"1"`) keeps its place, where
150
- * `JSON.parse` would move it first.
124
+ * but an optional one, whose missing key sets it to its initializer, a key may
125
+ * appear once, and a key that names no field is an error unless `ignoreUnknown`
126
+ * is set, when its value is stepped over, checked but not kept. A number must
127
+ * fit its field: an integer field takes an integer written without a fraction
128
+ * or an exponent and in the field's range, and `f64` takes any number.
129
+ *
130
+ * `null` is accepted only by a field whose type is `| null`. Fields are written
131
+ * to `out` as they are read, in the input's order: a nested object is decoded
132
+ * into the object the field already holds, an array's elements into the
133
+ * elements it already has, with new ones made past its end and the rest dropped
134
+ * (so a reused object reuses its arrays and objects, and `Arena.used()` stays
135
+ * flat: it is flat over 1,000 decodes of a three-level object), and a string
136
+ * field keeps the string it holds when the input's is equal.
137
+ *
138
+ * A string that changes is a new string, made by one `String.fromBytes`,
139
+ * straight from the input when it has no escape and from its unescaped bytes
140
+ * when it has one. A class the decoder has to make — an array element past the
141
+ * array's end, a `| null` field that holds `null`, or a map's value — is made
142
+ * with `new C()`.
143
+ *
144
+ * A map is emptied once the object opens, then each key is read as a new string
145
+ * and its value as a `V` made fresh for the key (a zero, `""`, the enum's first
146
+ * member, `null`, or a new object, array or map) and `set`, so the entries are
147
+ * the input's, in the input's order. A key the object gave already is
148
+ * `JSON_DECODE_DUPLICATE` before its value is read, however either is escaped.
149
+ * A value whose read fails is not `set`, so a map never holds a value the input
150
+ * did not give.
151
+ *
152
+ * Unlike the rest of a decode, a map's entries are made anew each time, so
153
+ * decoding into a map allocates its keys and values. Every map of one decoding
154
+ * takes at most `maxMapKeys` keys between them (4,096 unless set), the keys of
155
+ * a map inside another map included; the key past it is `JSON_DECODE_MAP_LIMIT`
156
+ * before it is read, and `reset` starts the count again. At `0` or below no map
157
+ * may take a key, and `{}` is the one map value accepted. Encoding writes the
158
+ * entries in the map's own order, which is insertion order.
159
+ *
160
+ * That differs from a JavaScript object in one case: a key that reads as an
161
+ * array index (`"1"`) keeps its place, where `JSON.parse` would move it first.
151
162
  *
152
163
  * **A class's options** are one `static readonly json` object literal written
153
164
  * in the class, which the compiler reads when it writes the class's code. It
@@ -196,14 +207,15 @@
196
207
  *
197
208
  * A spread or a computed key in the literal is refused as it is anywhere
198
209
  * (NL1061, NL1041), a subclass by `extends`, and a second `static readonly
199
- * json` is a duplicate member. The options are not a value: `User.json` names
200
- * a class where a value is due, and is refused as any class name there is.
201
- * Only `static readonly json` may leave out its type: written `static json =
202
- * { ... }`, or as an instance field, it is an ordinary field to the parser and
210
+ * json` is a duplicate member. The options are not a value: `User.json` names a
211
+ * class where a value is due, and is refused as any class name there is.
212
+ *
213
+ * Only `static readonly json` may leave out its type: written `static json = {
214
+ * ... }`, or as an instance field, it is an ordinary field to the parser and
203
215
  * needs one, and an instance field called `json` with a type is an ordinary
204
- * field, read and written under its own name. A field or a method called
205
- * `json` may come before or after the options. Under Node the literal is a
206
- * static property of the class that nothing reads.
216
+ * field, read and written under its own name. A field or a method called `json`
217
+ * may come before or after the options. Under Node the literal is a static
218
+ * property of the class that nothing reads.
207
219
  *
208
220
  * **Which keys were given.** An optional field's missing key and a key given
209
221
  * the field's initializer leave the same value; the `presence` option tells
@@ -219,16 +231,18 @@
219
231
  * hasEmail: boolean = false;
220
232
  * }
221
233
  *
222
- * Any field can be recorded, of any kind and optional or not. A presence
223
- * field is off the wire: no key reads it, encoding leaves it out, and no option
234
+ * Any field can be recorded, of any kind and optional or not. A presence field
235
+ * is off the wire: no key reads it, encoding leaves it out, and no option
224
236
  * renames it, makes it optional or records it. It is set when the object
225
- * closes, from the flag the decoder already keeps per field to find a
226
- * duplicate or a missing key, so recording costs one store per recorded field
227
- * and allocates nothing, and a class that records nothing compiles to the code
228
- * it did before. Each object sets its own, so a nested class or an array
229
- * element answers for its own keys. A decoding that fails may set some of
230
- * them and not others (when the input is not an object, none), so read them
231
- * only when `jsonDecode` answered `JSON_DECODE_OK`.
237
+ * closes, from the flag the decoder already keeps per field to find a duplicate
238
+ * or a missing key, so recording costs one store per recorded field and
239
+ * allocates nothing, and a class that records nothing compiles to the code it
240
+ * did before.
241
+ *
242
+ * Each object sets its own, so a nested class or an array element answers for
243
+ * its own keys. A decoding that fails may set some of them and not others (when
244
+ * the input is not an object, none), so read them only when `jsonDecode`
245
+ * answered `JSON_DECODE_OK`.
232
246
  *
233
247
  * **A merge patch (RFC 7396)** is that option's use: a patch class whose
234
248
  * every field is optional and recorded, decoded and then applied a field at a
package/std/json-value.ts CHANGED
@@ -31,14 +31,15 @@
31
31
  * largest request seen, parsing allocates nothing.
32
32
  *
33
33
  * A handle carries the generation of the document's contents it was made in,
34
- * which moves on at every `parse` and `clear`, so a handle kept from an
35
- * earlier request names nothing in the next one, even when the next one has
36
- * the same shape: it is `JSON_VALUE_NONE` to `kind`, and every reader answers
37
- * its empty value for it rather than another document's. The generation has
38
- * 511 values and moves by one at a `clear`, one at a parse and two at a parse
39
- * that fails, so the check misses only a handle kept across exactly a
40
- * multiple of 511 of those steps; a program must not keep handles across
41
- * documents, and this catches the mistake rather than licensing it. A
34
+ * which moves on at every `parse` and `clear`, so a handle kept from an earlier
35
+ * request names nothing in the next one, even when the next one has the same
36
+ * shape: it is `JSON_VALUE_NONE` to `kind`, and every reader answers its empty
37
+ * value for it rather than another document's.
38
+ *
39
+ * The generation has 511 values and moves by one at a `clear`, one at a parse
40
+ * and two at a parse that fails, so the check misses only a handle kept across
41
+ * exactly a multiple of 511 of those steps; a program must not keep handles
42
+ * across documents, and this catches the mistake rather than licensing it. A
42
43
  * negative handle, or one past the last value, is `JSON_VALUE_NONE` too.
43
44
  *
44
45
  * **The document's size is bounded.** Each value costs about 46 bytes of the
@@ -67,25 +68,28 @@
67
68
  * the range of bytes it was read from: `start(v)` and `end(v)` bound a value,
68
69
  * `keyStart(o, i)` and `keyEnd(o, i)` the key of member `i`, its quotes
69
70
  * included. They are offsets into the bytes `parseRanged` was given, or
70
- * `parseTextRanged`'s string, so a line index over that text
71
- * (`YamlLineIndex` is one) turns them into a line and a column. Under Node,
72
- * where `parseTextRanged` takes one byte per UTF-16 code unit (below), its
73
- * offsets count code units, so past the first non-ASCII character they differ
74
- * from a native build's, which count UTF-8 bytes. Ranges cost about 20 bytes
75
- * per value more: two offsets for the value, two for its key and about one on
76
- * the parse's stacks, which grow with the nesting and the members pending.
77
- * They are entry points of their own rather than a flag `parse` tests, so
78
- * that `parse` keeps the loop it had before ranges existed. A plain `parse`
79
- * writes nothing for them: ranges carry the generation they were written in,
80
- * which `clear` moves anyway, so after a `parse` every reader answers `-1`,
81
- * and their arrays are made on first use, so a document that never keeps
82
- * ranges allocates none. A
83
- * loader that builds a document from another text `clear`s, then gives each
84
- * value it makes its range with `setRange` and each key with `setKeyRange`;
85
- * until then a built value or key answers `-1`. `set` over an existing key
86
- * keeps the member's key range and takes the new value's own. Under
87
- * `JSON_VALUE_DUPLICATE_LAST` a repeated key's member keeps its first key's
88
- * range and holds the last value, with that value's.
71
+ * `parseTextRanged`'s string, so a line index over that text (`YamlLineIndex`
72
+ * is one) turns them into a line and a column.
73
+ *
74
+ * Under Node, where `parseTextRanged` takes one byte per UTF-16 code unit
75
+ * (below), its offsets count code units, so past the first non-ASCII character
76
+ * they differ from a native build's, which count UTF-8 bytes. Ranges cost about
77
+ * 20 bytes per value more: two offsets for the value, two for its key and about
78
+ * one on the parse's stacks, which grow with the nesting and the members
79
+ * pending. They are entry points of their own rather than a flag `parse` tests,
80
+ * so that `parse` keeps the loop it had before ranges existed.
81
+ *
82
+ * A plain `parse` writes nothing for them: ranges carry the generation they
83
+ * were written in, which `clear` moves anyway, so after a `parse` every reader
84
+ * answers `-1`, and their arrays are made on first use, so a document that
85
+ * never keeps ranges allocates none. A loader that builds a document from
86
+ * another text `clear`s, then gives each value it makes its range with
87
+ * `setRange` and each key with `setKeyRange`; until then a built value or key
88
+ * answers `-1`. `set` over an existing key keeps the member's key range and
89
+ * takes the new value's own.
90
+ *
91
+ * Under `JSON_VALUE_DUPLICATE_LAST` a repeated key's member keeps its first
92
+ * key's range and holds the last value, with that value's.
89
93
  *
90
94
  * **Objects keep insertion order**, the order the members were written in or
91
95
  * added. `get` finds a member by its key with a scan, so it is for a handful of
@@ -125,12 +129,13 @@
125
129
  * `set` can never contain itself: adding a value that is already in a
126
130
  * container, or a container to itself or to anything inside it, is
127
131
  * `JSON_VALUE_ERR_ATTACHED`, and writing always ends.
128
- * Strings handed to a builder are taken as their bytes, as `JsonWriter` takes
129
- * them, and a string read back is made from the stored bytes in one
130
- * allocation (`String.fromBytes`). Under Node a string is UTF-16, and
131
- * `parseText` and the builders take one byte per code unit, so non-ASCII text
132
- * is stored differently there than natively, where a string is its UTF-8
133
- * bytes; `parse` over a `u8[]` reads the same bytes both ways.
132
+ *
133
+ * Strings handed to a builder are taken as their bytes, as `JsonWriter` takes
134
+ * them, and a string read back is made from the stored bytes in one allocation
135
+ * (`String.fromBytes`). Under Node a string is UTF-16, and `parseText` and the
136
+ * builders take one byte per code unit, so non-ASCII text is stored differently
137
+ * there than natively, where a string is its UTF-8 bytes; `parse` over a `u8[]`
138
+ * reads the same bytes both ways.
134
139
  *
135
140
  * **Public is not the whole API.** The compiler ignores `private`, so every
136
141
  * member is reachable by a program; `private` and `@internal` mark what is
package/std/json.ts CHANGED
@@ -70,28 +70,31 @@
70
70
  * infinities as `null`. `jsonStringifyString` is the same string rule
71
71
  * answered as a string.
72
72
  *
73
- * **Two modes**, both off by default and both kept across `reset`, so a
74
- * server sets them once. `setIndent(n)` and `setIndentTab()` write what
75
- * `JSON.stringify(v, null, n)` and `JSON.stringify(v, null, "\t")` write:
76
- * one member or element a line, `": "` after a key, an empty `{}` or `[]` on
77
- * one line, and `n` clamped to 10. The indent is one byte stored as many times
78
- * as the depth asks, so the indented text allocates no more than the minified
79
- * one, and a `raw` fragment is copied as it is, not re-indented.
80
- * `setStrict(true)` makes NaN and the infinities, which JSON cannot
81
- * spell, the sticky `JSON_WRITE_NON_FINITE` instead of `null`: for a caller
82
- * to whom a `null` where a number was due would be a silently corrupt record.
73
+ * **Two modes**, both off by default and both kept across `reset`, so a server
74
+ * sets them once. `setIndent(n)` and `setIndentTab()` write what
75
+ * `JSON.stringify(v, null, n)` and `JSON.stringify(v, null, "\t")` write: one
76
+ * member or element a line, `": "` after a key, an empty `{}` or `[]` on one
77
+ * line, and `n` clamped to 10. The indent is one byte stored as many times as
78
+ * the depth asks, so the indented text allocates no more than the minified one,
79
+ * and a `raw` fragment is copied as it is, not re-indented.
80
+ *
81
+ * `setStrict(true)` makes NaN and the infinities, which JSON cannot spell, the
82
+ * sticky `JSON_WRITE_NON_FINITE` instead of `null`: for a caller to whom a
83
+ * `null` where a number was due would be a silently corrupt record.
83
84
  *
84
85
  * **Misuse is a sticky code**, as in `nish/net/hpack`: never a panic, and no
85
86
  * `Result` to carry on the hot path. The first call that cannot be honoured
86
- * sets `failed` to a negative `JSON_WRITE_*` code — a value where a key is
87
- * due, a key where a value is due, an unbalanced or mismatched `end*`,
88
- * nesting past `JSON_WRITER_MAX_DEPTH`, a buffer with no room, a second
89
- * top-level value, a bad `raw` window or `start`, a non-finite `f64` in strict
90
- * mode — and every later call does nothing. A call that fails writes nothing
91
- * past `buf.length` (a full buffer is checked before the bytes go in, never
92
- * by the bounds check), so the caller writes the whole value, reads `failed`
93
- * once at the end, and grows the buffer and retries or answers a 500. `complete()` says whether one
94
- * whole value was written with every container closed.
87
+ * sets `failed` to a negative `JSON_WRITE_*` code — a value where a key is due,
88
+ * a key where a value is due, an unbalanced or mismatched `end*`, nesting past
89
+ * `JSON_WRITER_MAX_DEPTH`, a buffer with no room, a second top-level value, a
90
+ * bad `raw` window or `start`, a non-finite `f64` in strict mode — and every
91
+ * later call does nothing.
92
+ *
93
+ * A call that fails writes nothing past `buf.length` (a full buffer is checked
94
+ * before the bytes go in, never by the bounds check), so the caller writes the
95
+ * whole value, reads `failed` once at the end, and grows the buffer and retries
96
+ * or answers a 500. `complete()` says whether one whole value was written with
97
+ * every container closed.
95
98
  *
96
99
  * **A string is its bytes** (WP33 class C, `docs/wp33-round-trip.md` §3.2,
97
100
  * the first row). The writer escapes by byte and copies every byte at or
@@ -754,15 +757,16 @@ export const jsonField = (object: string, name: string): string | null => {
754
757
  *
755
758
  * The answer is a fresh array and the only allocation besides the values. Each
756
759
  * value is stored into it by a plain `values[k] = text` statement, and the
757
- * array is only stored into, tested and returned, so the values travel with
758
- * the array: the call lets nothing else out (LANGUAGE.md, "Memory model", a
759
- * value stored into an array that is returned with it). A loop calling this
760
- * keeps its per-pass release on a line older than the pass, as `jsonField`'s
761
- * does, and a `using a = arena()` block may hold the call. On a line built in
762
- * the pass neither reader keeps the release (LANGUAGE.md, "Memory model").
763
- * Reading `values` back, passing it to a function, or storing it anywhere
764
- * before the return would undo this; `tests/link/std_json` pins the flat
765
- * arena and the `using` block.
760
+ * array is only stored into, tested and returned, so the values travel with the
761
+ * array: the call lets nothing else out (LANGUAGE.md, "Memory model", a value
762
+ * stored into an array that is returned with it). A loop calling this keeps its
763
+ * per-pass release on a line older than the pass, as `jsonField`'s does, and a
764
+ * `using a = arena()` block may hold the call.
765
+ *
766
+ * On a line built in the pass neither reader keeps the release (LANGUAGE.md,
767
+ * "Memory model"). Reading `values` back, passing it to a function, or storing
768
+ * it anywhere before the return would undo this; `tests/link/std_json` pins the
769
+ * flat arena and the `using` block.
766
770
  *
767
771
  * @param object - the text of one JSON object.
768
772
  * @param names - the fields to look for.