@amritk/nish-x86_64-darwin 0.49.0 → 0.49.1
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/bin/nish +0 -0
- package/package.json +1 -1
- package/std/json-typed.ts +17 -6
- package/std/net/websocket.ts +17 -6
- package/std/threads.ts +52 -8
package/bin/nish
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/std/json-typed.ts
CHANGED
|
@@ -890,20 +890,31 @@ export class JsonDecoder {
|
|
|
890
890
|
}
|
|
891
891
|
const start: i32 = tok.tokStart
|
|
892
892
|
const end: i32 = tok.tokEnd
|
|
893
|
+
const src: u8[] = tok.src
|
|
893
894
|
// In `i64`, where the width between the quotes cannot wrap. A string
|
|
894
895
|
// token starts at a byte of the input and spans `n + 2` bytes, so the
|
|
895
|
-
// other tests always hold
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
896
|
+
// other tests always hold: they prove both quotes' moves fit, and that
|
|
897
|
+
// the bytes between the quotes are a window of `src`.
|
|
898
|
+
if (toI64(n) === toI64(end) - toI64(start) - toI64(2) && start >= 0 && end > 0) {
|
|
899
|
+
const to: i32 = end - 1
|
|
900
|
+
if (start < to && to < toI32(src.length)) {
|
|
901
|
+
const from: i32 = start + 1
|
|
902
|
+
// Never false, after `start < to`: it states the window's order for
|
|
903
|
+
// the slice. No escape, so the bytes between the quotes are the
|
|
904
|
+
// string's, copied once by `String.fromBytes`.
|
|
905
|
+
if (from <= to) {
|
|
906
|
+
return String.fromBytes(src, from, to)
|
|
907
|
+
}
|
|
908
|
+
}
|
|
900
909
|
}
|
|
901
910
|
// The unescaped bytes are a temporary: a caller that keeps only the string
|
|
902
911
|
// it answers gives them back (the call-site reclaim, docs/LANGUAGE.md).
|
|
903
912
|
const bytes: u8[] = jsonTypedZeroBytes(n)
|
|
904
913
|
const at: i32 = 0
|
|
905
914
|
tok.stringInto(bytes, at)
|
|
906
|
-
|
|
915
|
+
// `bytes` is `n` long, and `stringInto` writes its elements without
|
|
916
|
+
// growing it: its own length is the window's end, which needs no proof.
|
|
917
|
+
return String.fromBytes(bytes, 0, toI32(bytes.length))
|
|
907
918
|
}
|
|
908
919
|
|
|
909
920
|
/**
|
package/std/net/websocket.ts
CHANGED
|
@@ -251,6 +251,16 @@ const websocketUtf8Run = (state: WsUtf8, buf: u8[], off: i32, len: i32): boolean
|
|
|
251
251
|
return true
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Whether `buf[off .. off + len)` is well-formed UTF-8, no character cut short
|
|
256
|
+
* at the end. The window is the caller's, already checked against `buf`, as
|
|
257
|
+
* for `websocketUtf8Run`: what `websocketIsUtf8` checks before it calls this.
|
|
258
|
+
*/
|
|
259
|
+
const websocketUtf8Whole = (buf: u8[], off: i32, len: i32): boolean => {
|
|
260
|
+
const state: WsUtf8 = new WsUtf8()
|
|
261
|
+
return websocketUtf8Run(state, buf, off, len) && state.need === 0
|
|
262
|
+
}
|
|
263
|
+
|
|
254
264
|
/**
|
|
255
265
|
* Whether `buf[off .. off + len)` is well-formed UTF-8: what a whole text
|
|
256
266
|
* message's payload, or a close frame's reason, must be (§8.1). A window
|
|
@@ -266,8 +276,7 @@ export const websocketIsUtf8 = (buf: u8[], off: i32, len: i32): boolean => {
|
|
|
266
276
|
if (off < 0 || len < 0 || off > size || len > size - off) {
|
|
267
277
|
panic("websocketIsUtf8: the window is outside the buffer")
|
|
268
278
|
}
|
|
269
|
-
|
|
270
|
-
return websocketUtf8Run(state, buf, off, len) && state.need === 0
|
|
279
|
+
return websocketUtf8Whole(buf, off, len)
|
|
271
280
|
}
|
|
272
281
|
|
|
273
282
|
/**
|
|
@@ -536,8 +545,10 @@ const websocketReadClose = (d: WsDecoder, len: i32): i32 => {
|
|
|
536
545
|
if (len === 1) {
|
|
537
546
|
return websocketFail(d, WS_CLOSE_PROTOCOL_ERROR, "a close frame with a one-byte payload")
|
|
538
547
|
}
|
|
539
|
-
// `control` holds 125 bytes and the frame's payload was copied into it.
|
|
540
|
-
|
|
548
|
+
// `control` holds 125 bytes and the frame's payload was copied into it. The
|
|
549
|
+
// test against 2 proves the code's two bytes; the one against `len`, the
|
|
550
|
+
// reason's window.
|
|
551
|
+
if (len < 2 || toI32(payload.length) < 2 || toI32(payload.length) < len) {
|
|
541
552
|
return websocketFail(d, WS_CLOSE_INTERNAL_ERROR, "a close frame payload that was not kept")
|
|
542
553
|
}
|
|
543
554
|
const code: i32 = (toI32(payload[0]) << 8) | toI32(payload[1])
|
|
@@ -545,7 +556,7 @@ const websocketReadClose = (d: WsDecoder, len: i32): i32 => {
|
|
|
545
556
|
return websocketFail(d, WS_CLOSE_PROTOCOL_ERROR, "a close status code that may not be sent")
|
|
546
557
|
}
|
|
547
558
|
const reasonStart: i32 = 2
|
|
548
|
-
if (!
|
|
559
|
+
if (!websocketUtf8Whole(payload, reasonStart, len - 2)) {
|
|
549
560
|
return websocketFail(d, WS_CLOSE_INVALID_DATA, "a close reason that is not UTF-8")
|
|
550
561
|
}
|
|
551
562
|
const parts: string[] = []
|
|
@@ -960,7 +971,7 @@ export const websocketClosePayload = (code: i32, reason: string): u8[] | null =>
|
|
|
960
971
|
out.push(toU8(reason.charCodeAt(k)))
|
|
961
972
|
}
|
|
962
973
|
const reasonStart: i32 = 2
|
|
963
|
-
if (!
|
|
974
|
+
if (!websocketUtf8Whole(out, reasonStart, n)) {
|
|
964
975
|
return null
|
|
965
976
|
}
|
|
966
977
|
return out
|
package/std/threads.ts
CHANGED
|
@@ -783,11 +783,21 @@ export class AtomicI64 {
|
|
|
783
783
|
}
|
|
784
784
|
|
|
785
785
|
/**
|
|
786
|
-
*
|
|
787
|
-
* `new Array` of one prints, so
|
|
786
|
+
* Why an atomic array cannot be made `length` long, or "" when it can: a
|
|
787
|
+
* negative length is refused with the message `new Array` of one prints, so
|
|
788
|
+
* the two refuse it alike.
|
|
789
|
+
*
|
|
790
|
+
* @param length the length an atomic array would be made with.
|
|
791
|
+
* @returns the reason the length is refused, or "" when it is not.
|
|
788
792
|
*/
|
|
789
|
-
const
|
|
790
|
-
|
|
793
|
+
export const atomicArrayLengthFault = (length: i32): string => (length < 0 ? "array length out of range" : "")
|
|
794
|
+
|
|
795
|
+
/** Panics unless an atomic array can be made `length` long: a negative length is the program's mistake. */
|
|
796
|
+
const atomicArrayCheckLength = (length: i32): void => {
|
|
797
|
+
const fault: string = atomicArrayLengthFault(length)
|
|
798
|
+
if (fault.length > 0) {
|
|
799
|
+
panic(fault)
|
|
800
|
+
}
|
|
791
801
|
}
|
|
792
802
|
|
|
793
803
|
/**
|
|
@@ -821,12 +831,12 @@ export class AtomicI32Array {
|
|
|
821
831
|
* `new Array` of one does.
|
|
822
832
|
*/
|
|
823
833
|
constructor(length: i32) {
|
|
834
|
+
atomicArrayCheckLength(length)
|
|
824
835
|
this.length = length
|
|
825
836
|
if (length >= 0) {
|
|
826
837
|
this.values = new Array<i32>(length)
|
|
827
838
|
} else {
|
|
828
|
-
|
|
829
|
-
// Never reached: `negativeAtomicLength` stops the program.
|
|
839
|
+
// Never reached: `atomicArrayCheckLength` stops the program.
|
|
830
840
|
this.values = []
|
|
831
841
|
}
|
|
832
842
|
this.values.fill(0)
|
|
@@ -977,12 +987,12 @@ export class AtomicI64Array {
|
|
|
977
987
|
* `new Array` of one does.
|
|
978
988
|
*/
|
|
979
989
|
constructor(length: i32) {
|
|
990
|
+
atomicArrayCheckLength(length)
|
|
980
991
|
this.length = length
|
|
981
992
|
if (length >= 0) {
|
|
982
993
|
this.values = new Array<i64>(length)
|
|
983
994
|
} else {
|
|
984
|
-
|
|
985
|
-
// Never reached: `negativeAtomicLength` stops the program.
|
|
995
|
+
// Never reached: `atomicArrayCheckLength` stops the program.
|
|
986
996
|
this.values = []
|
|
987
997
|
}
|
|
988
998
|
this.values.fill(0)
|
|
@@ -1100,6 +1110,40 @@ export class AtomicI64Array {
|
|
|
1100
1110
|
}
|
|
1101
1111
|
}
|
|
1102
1112
|
|
|
1113
|
+
/**
|
|
1114
|
+
* A new `AtomicI32Array` of `length` elements, each `0`, or why one cannot
|
|
1115
|
+
* be made: the twin of its constructor for a length read from input, which
|
|
1116
|
+
* refuses a negative length with the message the constructor would panic
|
|
1117
|
+
* with, rather than panicking.
|
|
1118
|
+
*
|
|
1119
|
+
* @param length how many elements.
|
|
1120
|
+
* @returns the array, or the reason the length is refused.
|
|
1121
|
+
*/
|
|
1122
|
+
export const atomicI32ArrayChecked = (length: i32): Result<AtomicI32Array, string> => {
|
|
1123
|
+
const fault: string = atomicArrayLengthFault(length)
|
|
1124
|
+
if (fault.length > 0) {
|
|
1125
|
+
return Err(fault)
|
|
1126
|
+
}
|
|
1127
|
+
return Ok(new AtomicI32Array(length))
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* A new `AtomicI64Array` of `length` elements, each `0`, or why one cannot
|
|
1132
|
+
* be made: the twin of its constructor for a length read from input, which
|
|
1133
|
+
* refuses a negative length with the message the constructor would panic
|
|
1134
|
+
* with, rather than panicking.
|
|
1135
|
+
*
|
|
1136
|
+
* @param length how many elements.
|
|
1137
|
+
* @returns the array, or the reason the length is refused.
|
|
1138
|
+
*/
|
|
1139
|
+
export const atomicI64ArrayChecked = (length: i32): Result<AtomicI64Array, string> => {
|
|
1140
|
+
const fault: string = atomicArrayLengthFault(length)
|
|
1141
|
+
if (fault.length > 0) {
|
|
1142
|
+
return Err(fault)
|
|
1143
|
+
}
|
|
1144
|
+
return Ok(new AtomicI64Array(length))
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1103
1147
|
/**
|
|
1104
1148
|
* A channel of scalars or strings between a scope's tasks (docs/wp29-thread-surface.md
|
|
1105
1149
|
* §4.4); a string is copied out of the sender's arena at `send` and into the
|