@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.
- package/INSTALL.md +67 -58
- package/bin/nish +0 -0
- package/docs/AI.md +43 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +736 -499
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/scripts/build.sh +147 -5
- package/std/README.md +107 -82
- package/std/bytes.ts +23 -19
- package/std/compress/checksum.ts +1 -1
- package/std/crypto/aes.ts +48 -43
- package/std/crypto/base64url.ts +7 -5
- package/std/crypto/bcrypt-batch.ts +13 -13
- package/std/crypto/bcrypt.ts +33 -27
- package/std/crypto/chacha20poly1305.ts +16 -14
- package/std/crypto/ed25519.ts +19 -16
- package/std/crypto/hmac.ts +7 -6
- package/std/crypto/jwt.ts +23 -20
- package/std/crypto/p256.ts +63 -56
- package/std/crypto/p384.ts +23 -20
- package/std/crypto/pki.ts +18 -15
- package/std/crypto/rsa.ts +23 -19
- package/std/crypto/x25519.ts +11 -10
- package/std/crypto/x509.ts +69 -62
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +12 -11
- package/std/json-number.ts +12 -12
- package/std/json-tokenizer.ts +26 -22
- package/std/json-typed.ts +92 -78
- package/std/json-value.ts +38 -33
- package/std/json.ts +32 -28
- package/std/net/fetch.ts +1117 -230
- package/std/net/handler.ts +18 -0
- package/std/net/hpack.ts +29 -26
- package/std/net/http-compress.ts +27 -21
- package/std/net/http1-client-codec.ts +29 -25
- package/std/net/http1-codec.ts +44 -87
- package/std/net/http1-server.ts +66 -54
- package/std/net/http2-frame.ts +17 -16
- package/std/net/http2-tls.ts +17 -15
- package/std/net/http2.ts +67 -54
- package/std/net/http3-frame.ts +11 -10
- package/std/net/http3-server.ts +36 -35
- package/std/net/http3.ts +70 -58
- package/std/net/postgres.ts +178 -160
- package/std/net/prefork.ts +38 -34
- package/std/net/qpack.ts +15 -14
- package/std/net/quic-conn-ack.ts +1 -0
- package/std/net/quic-conn-cid.ts +11 -0
- package/std/net/quic-conn-params.ts +41 -14
- package/std/net/quic-datagram.ts +7 -0
- package/std/net/quic-frame.ts +48 -12
- package/std/net/quic-listener.ts +61 -44
- package/std/net/quic-packet.ts +71 -52
- package/std/net/quic-recovery.ts +59 -21
- package/std/net/quic-stream.ts +83 -55
- package/std/net/quic.ts +204 -152
- package/std/net/tls/client.ts +1 -0
- package/std/net/tls/codec.ts +81 -12
- package/std/net/tls/record-client.ts +30 -18
- package/std/net/tls/record-server.ts +74 -46
- package/std/net/tls/record.ts +33 -24
- package/std/net/tls/ticket.ts +2 -0
- package/std/net/tls/verify.ts +8 -7
- package/std/net/tls-tcp.ts +58 -50
- package/std/net/tls.ts +55 -43
- package/std/net/url.ts +12 -9
- package/std/net/websocket.ts +23 -19
- package/std/net/webtransport.ts +24 -18
- package/std/random.ts +8 -6
- package/std/regex.ts +70 -59
- package/std/sync/ring.ts +24 -21
- package/std/sync/shm.ts +9 -7
- package/std/term-io.ts +17 -14
- package/std/term-probe.ts +11 -10
- package/std/term-rate.ts +71 -61
- package/std/term.ts +73 -59
- package/std/text.ts +11 -10
- package/std/threads.ts +19 -15
- package/std/yaml-json.ts +17 -15
- package/std/yaml-write.ts +21 -14
package/std/json-tokenizer.ts
CHANGED
|
@@ -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
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* string
|
|
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
|
-
*
|
|
58
|
-
* multiply or divide of two exact doubles (Clinger's fast path).
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* `
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
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
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* of
|
|
30
|
-
*
|
|
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
|
-
*
|
|
77
|
-
* recurses as the data does.
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* or a
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
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`.
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
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
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* input's order: a nested object is decoded
|
|
126
|
-
* holds, an array's elements into the
|
|
127
|
-
* made past its end and the rest dropped
|
|
128
|
-
* object reuses its arrays and objects, and `Arena.used()` stays
|
|
129
|
-
* flat over 1,000 decodes of a three-level object), and a
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* `
|
|
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
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
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
|
-
*
|
|
206
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
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
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
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
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* `
|
|
88
|
-
*
|
|
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
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* bytes; `parse` over a `u8[]`
|
|
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
|
-
*
|
|
75
|
-
* `JSON.stringify(v, null, n)` and `JSON.stringify(v, null, "\t")` write:
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
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
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
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.
|