substrate-lang 0.9.3 → 0.10.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/README.md +1 -1
- package/build/compiler/binary.2d43b43d1600@0+0.wasm +0 -0
- package/build/compiler/checker.4dd4556dd421@0+0.wasm +0 -0
- package/build/compiler/compile.5d8f6407af2a@0+0.wasm +0 -0
- package/build/compiler/{core.fc3dab9d1846@0+0.wasm → core.f2defb75e00b@0+0.wasm} +0 -0
- package/build/compiler/expander.967ce443d379@0+0.wasm +0 -0
- package/build/compiler/fs.01b8aab4a9a8@0+0.wasm +0 -0
- package/build/compiler/{leb128.748b1c37277a@0+0.wasm → leb128.15d814b7b4f2@0+0.wasm} +0 -0
- package/build/compiler/{link.11b643d35670@0+0.wasm → link.b826ea7c8f17@0+0.wasm} +0 -0
- package/build/compiler/{macros.4083601c00db@0+0.wasm → macros.b269e0c42784@0+0.wasm} +0 -0
- package/build/compiler/{main.ed62cce43000@0+0.wasm → main.4fc52f204d54@0+0.wasm} +0 -0
- package/build/compiler/{ops.b361e858d8e1@0+0.wasm → ops.515b5e05f646@0+0.wasm} +0 -0
- package/build/compiler/{path.dcc4712bcc7b@0+0.wasm → path.5a6286472cd4@0+0.wasm} +0 -0
- package/build/compiler/program +21 -21
- package/build/compiler/prune.406215c3e4f8@0+0.wasm +0 -0
- package/build/compiler/reader.694b03770bf0@0+0.wasm +0 -0
- package/build/compiler/roots.cefd10e93684@0+0.wasm +0 -0
- package/build/compiler/{running.d73f7826cb74@0+0.wasm → running.0d25dbaec018@0+0.wasm} +0 -0
- package/build/compiler/serialize.b0d82f3d63d2@0+0.wasm +0 -0
- package/build/compiler/{sha256.5fc9d60f8bb2@0+0.wasm → sha256.a6c32b04d799@0+0.wasm} +0 -0
- package/build/compiler/substrate.5ee5d0b4d3e7@0+0.wasm +0 -0
- package/build/compiler/syntax.32f3e40b61c7@0+0.wasm +0 -0
- package/build/compiler/{writer.806bc85aa684@0+0.wasm → writer.00b7802cbe39@0+0.wasm} +0 -0
- package/build/sub/{base64.8fba03e1be0a@0+0.wasm → base64.a26bdcf60a2d@0+0.wasm} +0 -0
- package/build/sub/build.459c5b9412bd@0+0.wasm +0 -0
- package/build/sub/chromium.3d5818f2707d@0+0.wasm +0 -0
- package/build/sub/common.1edc613607a0@0+0.wasm +0 -0
- package/build/sub/deflate.23f7c4679260@0+0.wasm +0 -0
- package/build/sub/doc.0775df5de6fe@0+0.wasm +0 -0
- package/build/sub/{doc.566f9861828e@0+0.wasm → doc.ef9965d5d402@0+0.wasm} +0 -0
- package/build/sub/env.e5451da6e747@0+0.wasm +0 -0
- package/build/sub/events.bf5473ebf220@0+0.wasm +0 -0
- package/build/sub/fetch.7790d4943758@0+0.wasm +0 -0
- package/build/sub/fetch.96b2d10f025e@0+0.wasm +0 -0
- package/build/sub/files.ad0469fdf6fa@0+0.wasm +0 -0
- package/build/sub/fs.01b8aab4a9a8@0+0.wasm +0 -0
- package/build/sub/git.dc4c0e757ebe@0+0.wasm +0 -0
- package/build/sub/grants.c54776c0d7e3@0+0.wasm +0 -0
- package/build/sub/gzip.16e372eda1cf@0+0.wasm +0 -0
- package/build/sub/hash.660682e4f491@0+0.wasm +0 -0
- package/build/sub/{html.20baa1dc7ca6@0+0.wasm → html.a23126eb949a@0+0.wasm} +0 -0
- package/build/sub/{html.c1671a102b4d@0+0.wasm → html.e9ed37f34977@0+0.wasm} +0 -0
- package/build/sub/{inflate.8899e0933792@0+0.wasm → inflate.59bb61f14001@0+0.wasm} +0 -0
- package/build/sub/json.55590d2f518a@0+0.wasm +0 -0
- package/build/sub/manifest.ef317480deb0@0+0.wasm +0 -0
- package/build/sub/map.f455cca6a42a@0+0.wasm +0 -0
- package/build/sub/pack.e02836264f6a@0+0.wasm +0 -0
- package/build/sub/{path.dcc4712bcc7b@0+0.wasm → path.5a6286472cd4@0+0.wasm} +0 -0
- package/build/sub/path.6891ffea73ca@0+0.wasm +0 -0
- package/build/sub/process.7106571fa723@0+0.wasm +0 -0
- package/build/sub/program +48 -48
- package/build/sub/read.0b93933d62a2@0+0.wasm +0 -0
- package/build/sub/{reader.b535e61f99f4@0+0.wasm → reader.694b03770bf0@0+0.wasm} +0 -0
- package/build/sub/{root.9b713ec588c1@0+0.wasm → root.f10a4906f460@0+0.wasm} +0 -0
- package/build/sub/{roots.6d2942578055@0+0.wasm → roots.cefd10e93684@0+0.wasm} +0 -0
- package/build/sub/{sha256.5fc9d60f8bb2@0+0.wasm → sha256.a6c32b04d799@0+0.wasm} +0 -0
- package/build/sub/{sha512.b988b9dc6114@0+0.wasm → sha512.c24a792d7891@0+0.wasm} +0 -0
- package/build/sub/site.1732b58ec0e8@0+0.wasm +0 -0
- package/build/sub/site.ae3913b0b0f4@0+0.wasm +0 -0
- package/build/sub/store.a24d7a25daa6@0+0.wasm +0 -0
- package/build/sub/stream.126e3bd5d626@0+0.wasm +0 -0
- package/build/sub/sub.2e3092140706@0+0.wasm +0 -0
- package/build/sub/substrate.5ee5d0b4d3e7@0+0.wasm +0 -0
- package/build/sub/{syntax.9857f6784d63@0+0.wasm → syntax.32f3e40b61c7@0+0.wasm} +0 -0
- package/build/sub/tar.2a633861e654@0+0.wasm +0 -0
- package/build/sub/test.9bd59c73f65e@0+0.wasm +0 -0
- package/build/sub/{text.4ab70ac35b5a@0+0.wasm → text.1bc90482bd43@0+0.wasm} +0 -0
- package/build/sub/{timer.3809bb17a7a1@0+0.wasm → timer.f35eb62ae446@0+0.wasm} +0 -0
- package/build/sub/upgrade.39ee449b00d5@0+0.wasm +0 -0
- package/build/sub/{utf8.524c475ecd40@0+0.wasm → utf8.e7216bd054e1@0+0.wasm} +0 -0
- package/build/sub/worker.762a9d642af0@0+0.wasm +0 -0
- package/build/sub/writer.00b7802cbe39@0+0.wasm +0 -0
- package/package.json +1 -1
- package/std/archive/tar.sub +44 -44
- package/std/browser/chromium.sub +5 -4
- package/std/browser/devtools.sub +24 -19
- package/std/compress/deflate.sub +10 -12
- package/std/compress/gzip.sub +18 -16
- package/std/compress/inflate.sub +7 -4
- package/std/crypto/password.sub +3 -3
- package/std/doc/doc.sub +2 -2
- package/std/encoding/json.sub +64 -73
- package/std/encoding/wire.sub +15 -15
- package/std/http/checks.sub +3 -3
- package/std/http/conditional.sub +2 -4
- package/std/http/cookie.sub +5 -7
- package/std/http/form.sub +9 -12
- package/std/http/http.sub +17 -24
- package/std/http/multipart.sub +13 -15
- package/std/http/route.sub +18 -13
- package/std/http/server.sub +21 -23
- package/std/http/session.sub +3 -6
- package/std/http/sse-client.sub +9 -14
- package/std/http/static.sub +5 -5
- package/std/http/url.sub +10 -10
- package/std/http/websocket.sub +2 -5
- package/std/meta/derive.sub +0 -2
- package/std/meta/method.sub +41 -0
- package/std/meta/type-info.sub +30 -37
- package/std/package/files.sub +24 -25
- package/std/package/git.sub +26 -33
- package/std/package/hash.sub +9 -9
- package/std/package/manifest.sub +81 -57
- package/std/package/map.sub +5 -9
- package/std/package/pack.sub +13 -13
- package/std/package/path.sub +1 -4
- package/std/package/read.sub +10 -14
- package/std/package/site.sub +11 -11
- package/std/package/store.sub +16 -12
- package/std/package.sub +6 -6
- package/std/test/browser.sub +9 -8
- package/std/test/build.sub +2 -2
- package/std/test/compare.sub +9 -10
- package/std/test/page.sub +32 -27
- package/std/test/run.sub +9 -8
- package/std/test/test.sub +36 -30
- package/std/vector/vector.sub +75 -0
- package/substrate/VERSION +1 -1
- package/substrate/compiler/binary.sub +5 -14
- package/substrate/compiler/checker.sub +235 -222
- package/substrate/compiler/compile.sub +11 -11
- package/substrate/compiler/expander.sub +52 -78
- package/substrate/compiler/link.sub +2 -2
- package/substrate/compiler/main.sub +9 -9
- package/substrate/compiler/ops.sub +1 -1
- package/substrate/compiler/prune.sub +12 -17
- package/substrate/compiler/reader.sub +4 -4
- package/substrate/compiler/roots.sub +11 -10
- package/substrate/compiler/running.sub +1 -1
- package/substrate/compiler/serialize.sub +57 -50
- package/substrate/compiler/substrate.sub +60 -23
- package/substrate/compiler/syntax.sub +8 -21
- package/substrate/host/errors.mjs +3 -2
- package/substrate/host/events.sub +3 -16
- package/substrate/host/fs.mjs +5 -4
- package/substrate/host/fs.sub +142 -112
- package/substrate/host/grants.mjs +1 -1
- package/substrate/host/grants.sub +33 -33
- package/substrate/host/modules/fake.mjs +1 -1
- package/substrate/host/modules/websocket.mjs +4 -4
- package/substrate/host/modules/websocket.sub +8 -6
- package/substrate/host/node/env.mjs +12 -6
- package/substrate/host/node/env.sub +21 -16
- package/substrate/host/node/fs.mjs +1 -1
- package/substrate/host/node/net.mjs +2 -2
- package/substrate/host/node/net.sub +13 -6
- package/substrate/host/node/process.mjs +4 -4
- package/substrate/host/node/process.sub +28 -28
- package/substrate/host/node/signal.mjs +3 -2
- package/substrate/host/node/signal.sub +9 -6
- package/substrate/host/node/watch.mjs +1 -1
- package/substrate/host/node/watch.sub +11 -9
- package/substrate/host/stream.sub +2 -0
- package/substrate/host/subhost-core.mjs +9 -1
- package/substrate/host/web/clipboard.mjs +2 -2
- package/substrate/host/web/clipboard.sub +10 -3
- package/substrate/host/web/files.mjs +2 -2
- package/substrate/host/web/files.sub +6 -2
- package/substrate/host/web/fs.mjs +3 -3
- package/substrate/host/web/location.mjs +3 -1
- package/substrate/host/web/location.sub +8 -4
- package/substrate/host/worker-side.mjs +3 -1
- package/substrate/host/worker.mjs +6 -5
- package/substrate/host/worker.sub +10 -10
- package/build/compiler/binary.3823f89ce414@0+0.wasm +0 -0
- package/build/compiler/checker.592d37dcbec9@0+0.wasm +0 -0
- package/build/compiler/compile.86a2b03b0c9b@0+0.wasm +0 -0
- package/build/compiler/expander.689d326e5a1b@0+0.wasm +0 -0
- package/build/compiler/fs.563034be70c3@0+0.wasm +0 -0
- package/build/compiler/prune.d4a3f9834095@0+0.wasm +0 -0
- package/build/compiler/reader.b535e61f99f4@0+0.wasm +0 -0
- package/build/compiler/roots.6d2942578055@0+0.wasm +0 -0
- package/build/compiler/serialize.b2196de75bc8@0+0.wasm +0 -0
- package/build/compiler/substrate.4c780d6dd6d4@0+0.wasm +0 -0
- package/build/compiler/syntax.9857f6784d63@0+0.wasm +0 -0
- package/build/sub/build.84ac996eda63@0+0.wasm +0 -0
- package/build/sub/chromium.e4db7d29897c@0+0.wasm +0 -0
- package/build/sub/common.91ddee6b7a67@0+0.wasm +0 -0
- package/build/sub/deflate.fc8075e3aed1@0+0.wasm +0 -0
- package/build/sub/doc.0b48bbac404b@0+0.wasm +0 -0
- package/build/sub/env.f051f8166526@0+0.wasm +0 -0
- package/build/sub/events.f952172735e0@0+0.wasm +0 -0
- package/build/sub/fetch.097f1cc9502d@0+0.wasm +0 -0
- package/build/sub/fetch.5d2f427c995e@0+0.wasm +0 -0
- package/build/sub/files.30e55182c5df@0+0.wasm +0 -0
- package/build/sub/fs.563034be70c3@0+0.wasm +0 -0
- package/build/sub/git.48aefa1644be@0+0.wasm +0 -0
- package/build/sub/grants.5bf25700d47c@0+0.wasm +0 -0
- package/build/sub/gzip.69588e97c35a@0+0.wasm +0 -0
- package/build/sub/hash.3f0d118da63f@0+0.wasm +0 -0
- package/build/sub/json.f15a29d99d8d@0+0.wasm +0 -0
- package/build/sub/manifest.cf7471880377@0+0.wasm +0 -0
- package/build/sub/map.dc516eec27ff@0+0.wasm +0 -0
- package/build/sub/pack.55992e8cc09c@0+0.wasm +0 -0
- package/build/sub/path.b7a8e1cf3aaa@0+0.wasm +0 -0
- package/build/sub/process.aea2c88cb7a0@0+0.wasm +0 -0
- package/build/sub/read.cd1e693f4fb4@0+0.wasm +0 -0
- package/build/sub/site.7c6d8c7747af@0+0.wasm +0 -0
- package/build/sub/site.81548474c323@0+0.wasm +0 -0
- package/build/sub/store.d4e845ff24ac@0+0.wasm +0 -0
- package/build/sub/stream.4c07247477f7@0+0.wasm +0 -0
- package/build/sub/sub.b57e17b6876b@0+0.wasm +0 -0
- package/build/sub/substrate.4c780d6dd6d4@0+0.wasm +0 -0
- package/build/sub/tar.e482cf873cfc@0+0.wasm +0 -0
- package/build/sub/test.0d9c079bb309@0+0.wasm +0 -0
- package/build/sub/upgrade.18a5aa0dae89@0+0.wasm +0 -0
- package/build/sub/worker.f1190de21b21@0+0.wasm +0 -0
- package/build/sub/writer.806bc85aa684@0+0.wasm +0 -0
package/substrate/host/fs.sub
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
;; Files: the host module "fs", on paths and on open files. fs-list stores a directory's names
|
|
2
2
|
;; at into, and fs-read-link, fs-real-path, fs-make-temp-dir, fs-make-temp-file and fs-cwd a path, as host calls give
|
|
3
3
|
;; them. fs-stat fills an fs-info, and fs-lstat does too without following a link at the end of the path. fs-remove
|
|
4
|
-
;; removes a file, a link or an empty directory, or when recursive a directory and everything in it.
|
|
5
|
-
;; 0, or -1 when they fail, and store a failure's reason at err.
|
|
4
|
+
;; removes a file, a link or an empty directory, or when recursive a directory and everything in it.
|
|
6
5
|
(provide fs-read-file fs-write-file fs-make-dir fs-info fs-stat fs-lstat fs-list fs-remove fs-rename
|
|
7
6
|
fs-read-link fs-real-path fs-symlink fs-copy fs-chmod fs-make-temp-dir fs-make-temp-file
|
|
8
|
-
fs-cwd fs-file fs-directory fs-link fs-other
|
|
7
|
+
fs-cwd fs-kind fs-none fs-file fs-directory fs-link fs-other
|
|
9
8
|
fs-open-file fs-read-at fs-write-at fs-set-size fs-sync fs-size fs-close-file fs-read-stream fs-write-stream
|
|
10
9
|
fs-read-flag fs-write-flag fs-append-flag fs-truncate-flag fs-create-flag fs-create-new-flag)
|
|
11
10
|
|
|
@@ -32,92 +31,106 @@
|
|
|
32
31
|
(import file_stream "fs" "file_stream" (i32 i32 f64 i32 i32 -> i32))
|
|
33
32
|
|
|
34
33
|
;; An fs-info's kind.
|
|
35
|
-
(
|
|
36
|
-
(const fs-directory i32 2)
|
|
37
|
-
(const fs-link i32 3)
|
|
38
|
-
(const fs-other i32 4)
|
|
34
|
+
(enum fs-kind fs-none fs-file fs-directory fs-link fs-other)
|
|
39
35
|
|
|
40
36
|
;; modified is in milliseconds since 1970, and mode is the file's mode bits, its type's included.
|
|
41
|
-
(struct fs-info [kind
|
|
37
|
+
(struct fs-info [kind fs-kind] [size i64] [modified f64] [mode u32])
|
|
42
38
|
|
|
43
|
-
(define (
|
|
44
|
-
(make_dir (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 err)))
|
|
39
|
+
(define (done [r i32] [why (ptr string)] [err (ptr error)]) -> bool (or (== r 0) (host-failed! why err)))
|
|
45
40
|
|
|
46
|
-
(define (
|
|
47
|
-
(let ([
|
|
48
|
-
(
|
|
49
|
-
(set! (-> i size) (cast i64 size))
|
|
50
|
-
(set! (-> i modified) modified)
|
|
51
|
-
(set! (-> i mode) (cast u32 mode))
|
|
52
|
-
(if (== kind 0) -1 0)))
|
|
41
|
+
(define (fs-make-dir [path string] [err (ptr error)]) -> bool
|
|
42
|
+
(let ([why string])
|
|
43
|
+
(done (make_dir (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 (& why))) (& why) err)))
|
|
53
44
|
|
|
54
|
-
(define (
|
|
45
|
+
(define (stat-of [path string] [follow bool] [i (ptr fs-info)] [err (ptr error)]) -> bool
|
|
46
|
+
(let ([why string])
|
|
47
|
+
(let ([(kind size modified mode)
|
|
48
|
+
(info (cast i32 (-> path bytes)) (cast i32 (-> path length)) follow (cast i32 (& why)))])
|
|
49
|
+
(set! (-> i kind) (cast fs-kind kind))
|
|
50
|
+
(set! (-> i size) (cast i64 size))
|
|
51
|
+
(set! (-> i modified) modified)
|
|
52
|
+
(set! (-> i mode) (cast u32 mode))
|
|
53
|
+
(or (!= kind 0) (host-failed! (& why) err)))))
|
|
55
54
|
|
|
56
|
-
(define (fs-
|
|
55
|
+
(define (fs-stat [path string] [i (ptr fs-info)] [err (ptr error)]) -> bool (stat-of path #t i err))
|
|
57
56
|
|
|
58
|
-
(define (fs-
|
|
59
|
-
(let* ([n u32 0] [p (list (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 (& n)) (cast i32 err))])
|
|
60
|
-
(set! (@ into) (entry-strings (cast (ptr u8) p) n))
|
|
61
|
-
(if (== p 0) -1 0)))
|
|
62
|
-
|
|
63
|
-
(define (fs-remove [path string] [recursive bool] [err (ptr string)]) -> i32
|
|
64
|
-
(if recursive
|
|
65
|
-
(remove_all (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 err))
|
|
66
|
-
(remove (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 err))))
|
|
57
|
+
(define (fs-lstat [path string] [i (ptr fs-info)] [err (ptr error)]) -> bool (stat-of path #f i err))
|
|
67
58
|
|
|
68
|
-
(define (fs-
|
|
69
|
-
(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
(
|
|
59
|
+
(define (fs-list [path string] [into (ptr (slice string))] [err (ptr error)]) -> bool
|
|
60
|
+
(let* ([why string] [n u32 0]
|
|
61
|
+
[p (list (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 (& n)) (cast i32 (& why)))])
|
|
62
|
+
(set! (@ into) (entry-strings (cast (ptr u8) p) n))
|
|
63
|
+
(or (!= p 0) (host-failed! (& why) err))))
|
|
64
|
+
|
|
65
|
+
(define (fs-remove [path string] [recursive bool] [err (ptr error)]) -> bool
|
|
66
|
+
(let ([why string])
|
|
67
|
+
(done (if recursive
|
|
68
|
+
(remove_all (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 (& why)))
|
|
69
|
+
(remove (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 (& why))))
|
|
70
|
+
(& why) err)))
|
|
71
|
+
|
|
72
|
+
(define (fs-rename [from string] [to string] [err (ptr error)]) -> bool
|
|
73
|
+
(let ([why string])
|
|
74
|
+
(done (rename (cast i32 (-> from bytes)) (cast i32 (-> from length)) (cast i32 (-> to bytes))
|
|
75
|
+
(cast i32 (-> to length)) (cast i32 (& why)))
|
|
76
|
+
(& why) err)))
|
|
77
|
+
|
|
78
|
+
(define (path-given [p i32] [n u32] [into (ptr string)] [why (ptr string)] [err (ptr error)]) -> bool
|
|
73
79
|
(set! (@ into) (cast string (slice (cast (ptr u8) p) n)))
|
|
74
|
-
(
|
|
80
|
+
(or (!= p 0) (host-failed! why err)))
|
|
75
81
|
|
|
76
|
-
(define (fs-read-link [path string] [into (ptr string)] [err (ptr
|
|
77
|
-
(let* ([
|
|
78
|
-
|
|
82
|
+
(define (fs-read-link [path string] [into (ptr string)] [err (ptr error)]) -> bool
|
|
83
|
+
(let* ([why string] [n u32 0]
|
|
84
|
+
[p (read_link (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 (& n)) (cast i32 (& why)))])
|
|
85
|
+
(path-given p n into (& why) err)))
|
|
79
86
|
|
|
80
|
-
(define (fs-real-path [path string] [into (ptr string)] [err (ptr
|
|
81
|
-
(let* ([
|
|
82
|
-
|
|
87
|
+
(define (fs-real-path [path string] [into (ptr string)] [err (ptr error)]) -> bool
|
|
88
|
+
(let* ([why string] [n u32 0]
|
|
89
|
+
[p (real_path (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 (& n)) (cast i32 (& why)))])
|
|
90
|
+
(path-given p n into (& why) err)))
|
|
83
91
|
|
|
84
92
|
;; fs-symlink makes a link at path to target, which needs all of -R and -W, as Deno's symlink does.
|
|
85
|
-
(define (fs-symlink [target string] [path string] [err (ptr
|
|
86
|
-
(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
(
|
|
94
|
-
|
|
93
|
+
(define (fs-symlink [target string] [path string] [err (ptr error)]) -> bool
|
|
94
|
+
(let ([why string])
|
|
95
|
+
(done (symlink (cast i32 (-> target bytes)) (cast i32 (-> target length)) (cast i32 (-> path bytes))
|
|
96
|
+
(cast i32 (-> path length)) (cast i32 (& why)))
|
|
97
|
+
(& why) err)))
|
|
98
|
+
|
|
99
|
+
(define (fs-copy [from string] [to string] [err (ptr error)]) -> bool
|
|
100
|
+
(let ([why string])
|
|
101
|
+
(done (copy_file (cast i32 (-> from bytes)) (cast i32 (-> from length)) (cast i32 (-> to bytes))
|
|
102
|
+
(cast i32 (-> to length)) (cast i32 (& why)))
|
|
103
|
+
(& why) err)))
|
|
104
|
+
|
|
105
|
+
(define (fs-chmod [path string] [mode u32] [err (ptr error)]) -> bool
|
|
106
|
+
(let ([why string])
|
|
107
|
+
(done (chmod (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 mode) (cast i32 (& why)))
|
|
108
|
+
(& why) err)))
|
|
95
109
|
|
|
96
110
|
;; The temporary calls make a new directory or file named prefix, random hexadecimal digits and suffix, in dir, or in
|
|
97
111
|
;; the system's temporary directory when dir is empty, and give its path.
|
|
98
|
-
(define (make-temp [dir string] [prefix string] [suffix string] [file bool] [into (ptr string)] [err (ptr
|
|
99
|
-
->
|
|
100
|
-
(let* ([n u32 0]
|
|
112
|
+
(define (make-temp [dir string] [prefix string] [suffix string] [file bool] [into (ptr string)] [err (ptr error)])
|
|
113
|
+
-> bool
|
|
114
|
+
(let* ([why string] [n u32 0]
|
|
101
115
|
[p (make_temp (cast i32 (-> dir bytes)) (cast i32 (-> dir length)) (cast i32 (-> prefix bytes))
|
|
102
116
|
(cast i32 (-> prefix length)) (cast i32 (-> suffix bytes)) (cast i32 (-> suffix length)) file
|
|
103
|
-
(cast i32 (& n)) (cast i32
|
|
104
|
-
(path-given p n into)))
|
|
117
|
+
(cast i32 (& n)) (cast i32 (& why)))])
|
|
118
|
+
(path-given p n into (& why) err)))
|
|
105
119
|
|
|
106
|
-
(define (fs-make-temp-dir [dir string] [prefix string] [suffix string] [into (ptr string)] [err (ptr
|
|
120
|
+
(define (fs-make-temp-dir [dir string] [prefix string] [suffix string] [into (ptr string)] [err (ptr error)]) -> bool
|
|
107
121
|
(make-temp dir prefix suffix #f into err))
|
|
108
122
|
|
|
109
|
-
(define (fs-make-temp-file [dir string] [prefix string] [suffix string] [into (ptr string)] [err (ptr
|
|
123
|
+
(define (fs-make-temp-file [dir string] [prefix string] [suffix string] [into (ptr string)] [err (ptr error)]) -> bool
|
|
110
124
|
(make-temp dir prefix suffix #t into err))
|
|
111
125
|
|
|
112
|
-
(define (fs-cwd [into (ptr string)] [err (ptr
|
|
113
|
-
(let* ([n u32 0] [p (cwd (cast i32 (& n)) (cast i32
|
|
126
|
+
(define (fs-cwd [into (ptr string)] [err (ptr error)]) -> bool
|
|
127
|
+
(let* ([why string] [n u32 0] [p (cwd (cast i32 (& n)) (cast i32 (& why)))]) (path-given p n into (& why) err)))
|
|
114
128
|
|
|
115
129
|
;; Open files, read and written at a position. fs-open-file gives a handle opened as flags say, to read when they say
|
|
116
|
-
;; neither read nor write
|
|
117
|
-
;;
|
|
118
|
-
;;
|
|
119
|
-
;;
|
|
120
|
-
;; fs-write-file makes a file hold b.
|
|
130
|
+
;; neither read nor write; writing, appending, creating and truncating need -W, and reading -R. fs-read-at gives the
|
|
131
|
+
;; number of bytes it read, fewer at the end of the file, and fs-size the file's size. fs-read-stream and
|
|
132
|
+
;; fs-write-stream make a handle a stream from start, which closes the handle when it closes. If they fail, they close
|
|
133
|
+
;; the handle. fs-read-file stores a file's bytes, from malloc, at into, and fs-write-file makes a file hold b.
|
|
121
134
|
(const fs-read-flag u32 1)
|
|
122
135
|
(const fs-write-flag u32 2)
|
|
123
136
|
(const fs-append-flag u32 4)
|
|
@@ -125,61 +138,78 @@
|
|
|
125
138
|
(const fs-create-flag u32 16)
|
|
126
139
|
(const fs-create-new-flag u32 32)
|
|
127
140
|
|
|
128
|
-
(define (fs-open-file [path string] [flags u32] [err (ptr
|
|
129
|
-
(
|
|
130
|
-
|
|
131
|
-
(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
(
|
|
138
|
-
|
|
139
|
-
(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
(
|
|
144
|
-
|
|
145
|
-
(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
(
|
|
152
|
-
|
|
153
|
-
|
|
141
|
+
(define (fs-open-file [path string] [flags u32] [h (ptr u32)] [err (ptr error)]) -> bool
|
|
142
|
+
(let ([why string] [n u32 0])
|
|
143
|
+
(set! n (cast u32 (open_file (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 flags)
|
|
144
|
+
(cast i32 (& why)))))
|
|
145
|
+
(unless (== h 0) (set! (@ h) n))
|
|
146
|
+
(or (!= n 0) (host-failed! (& why) err))))
|
|
147
|
+
|
|
148
|
+
(define (fs-read-at [h u32] [into (slice u8)] [at i64] [n (ptr u32)] [err (ptr error)]) -> bool
|
|
149
|
+
(let* ([why string]
|
|
150
|
+
[r (read_at (cast i32 h) (cast i32 (-> into items)) (cast i32 (-> into length)) (cast f64 at)
|
|
151
|
+
(cast i32 (& why)))])
|
|
152
|
+
(set! (@ n) (if (< r 0) 0 (cast u32 r)))
|
|
153
|
+
(or (>= r 0) (host-failed! (& why) err))))
|
|
154
|
+
|
|
155
|
+
(define (fs-write-at [h u32] [b (slice u8)] [at i64] [err (ptr error)]) -> bool
|
|
156
|
+
(let ([why string])
|
|
157
|
+
(done (write_at (cast i32 h) (cast i32 (-> b items)) (cast i32 (-> b length)) (cast f64 at) (cast i32 (& why)))
|
|
158
|
+
(& why) err)))
|
|
159
|
+
|
|
160
|
+
(define (fs-set-size [h u32] [n i64] [err (ptr error)]) -> bool
|
|
161
|
+
(let ([why string]) (done (set_file_size (cast i32 h) (cast f64 n) (cast i32 (& why))) (& why) err)))
|
|
162
|
+
|
|
163
|
+
(define (fs-sync [h u32] [err (ptr error)]) -> bool
|
|
164
|
+
(let ([why string]) (done (sync_file (cast i32 h) (cast i32 (& why))) (& why) err)))
|
|
165
|
+
|
|
166
|
+
(define (fs-size [h u32] [size (ptr i64)] [err (ptr error)]) -> bool
|
|
167
|
+
(let* ([why string] [s (file_size (cast i32 h) (cast i32 (& why)))])
|
|
168
|
+
(set! (@ size) (if (< s 0.0) 0 (cast i64 s)))
|
|
169
|
+
(or (>= s 0.0) (host-failed! (& why) err))))
|
|
170
|
+
|
|
171
|
+
(define (fs-close-file [h u32] [err (ptr error)]) -> bool
|
|
172
|
+
(let ([why string]) (done (close_file (cast i32 h) (cast i32 (& why))) (& why) err)))
|
|
173
|
+
|
|
174
|
+
(define (file-stream [h u32] [write i32] [start i64] [tag (ptr void)] [id (ptr u32)] [err (ptr error)]) -> bool
|
|
175
|
+
(let ([why string] [n u32 0])
|
|
176
|
+
(set! n (cast u32 (file_stream (cast i32 h) write (cast f64 start) (cast i32 tag) (cast i32 (& why)))))
|
|
177
|
+
(unless (== id 0) (set! (@ id) n))
|
|
178
|
+
(or (!= n 0) (host-failed! (& why) err))))
|
|
179
|
+
|
|
180
|
+
(define (fs-read-stream [h u32] [start i64] [tag (ptr void)] [id (ptr u32)] [err (ptr error)]) -> bool
|
|
181
|
+
(file-stream h 0 start tag id err))
|
|
182
|
+
|
|
183
|
+
(define (fs-write-stream [h u32] [start i64] [tag (ptr void)] [id (ptr u32)] [err (ptr error)]) -> bool
|
|
184
|
+
(file-stream h 1 start tag id err))
|
|
185
|
+
|
|
186
|
+
(define (fs-read-file [path string] [into (ptr (slice u8))] [err (ptr error)]) -> bool
|
|
187
|
+
(let ([h u32 0] [size i64 0] [room u32 0] [p (ptr u8) 0] [more (ptr u8) 0] [n u32 0] [got u32 0])
|
|
154
188
|
(set! (@ into) (slice (cast (ptr u8) 0) 0))
|
|
155
|
-
(
|
|
156
|
-
(
|
|
189
|
+
(unless (fs-open-file path fs-read-flag (& h) err) (return #f))
|
|
190
|
+
(fs-size h (& size) 0)
|
|
157
191
|
(set! room (if (> size 0) (+ (cast u32 (if (> size 2147483583) 2147483583 size)) 1) 4096))
|
|
158
|
-
(set! p (
|
|
192
|
+
(set! p (try-malloc room))
|
|
159
193
|
(while (!= p 0)
|
|
160
|
-
(
|
|
161
|
-
|
|
162
|
-
(free (cast (ptr void) p))
|
|
194
|
+
(unless (fs-read-at h (slice (+ p n) (- room n)) (cast i64 n) (& got) err)
|
|
195
|
+
(free p)
|
|
163
196
|
(fs-close-file h 0)
|
|
164
|
-
(return
|
|
165
|
-
(+= n
|
|
197
|
+
(return #f))
|
|
198
|
+
(+= n got)
|
|
166
199
|
(when (< n room)
|
|
167
200
|
(fs-close-file h 0)
|
|
168
201
|
(set! (@ into) (slice p n))
|
|
169
|
-
(return
|
|
170
|
-
(set! more (
|
|
171
|
-
(when (== more 0) (free
|
|
202
|
+
(return #t))
|
|
203
|
+
(set! more (try-realloc p (* room 2)))
|
|
204
|
+
(when (== more 0) (free p))
|
|
172
205
|
(set! p more)
|
|
173
206
|
(set! room (* room 2)))
|
|
174
207
|
(fs-close-file h 0)
|
|
175
|
-
(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
(fs-close-file h 0)
|
|
184
|
-
(set! r (fs-close-file h err)))
|
|
185
|
-
r))
|
|
208
|
+
(error-fail! err error-other "File too large")))
|
|
209
|
+
|
|
210
|
+
(define (fs-write-file [path string] [b (slice u8)] [err (ptr error)]) -> bool
|
|
211
|
+
(let ([h u32 0])
|
|
212
|
+
(and (fs-open-file path (bit-or fs-write-flag fs-create-flag fs-truncate-flag) (& h) err)
|
|
213
|
+
(if (fs-write-at h b 0 err)
|
|
214
|
+
(fs-close-file h err)
|
|
215
|
+
(begin (fs-close-file h 0) #f)))))
|
|
@@ -247,7 +247,7 @@ export function within(asked, parent) {
|
|
|
247
247
|
if (beyond) {
|
|
248
248
|
const subnet = beyond.bits === undefined ? '' : `/${beyond.bits}`;
|
|
249
249
|
const item = k === 'net' ? `${beyond.host}${subnet}${beyond.port === null ? '' : `:${beyond.port}`}` : beyond;
|
|
250
|
-
throw
|
|
250
|
+
throw notGranted(`${beyond === true ? `all ${k}` : `${k} ${item}`} reaches beyond the parent's grants`);
|
|
251
251
|
}
|
|
252
252
|
const deny = { all: a.deny.all || p.deny.all, items: [...a.deny.items, ...p.deny.items] };
|
|
253
253
|
out[k] = { all: a.all, items: [...a.items], deny };
|
|
@@ -8,18 +8,14 @@
|
|
|
8
8
|
;; tls-cert tls-key a file
|
|
9
9
|
;; grants-parse! reads flags as people type them, like -R=a,b, where ",," is a comma inside an item, and grants-add! a
|
|
10
10
|
;; clause as manifests and tests write one, like (read "a" "b"), (all net) or (tls "cert.pem" "key.pem").
|
|
11
|
-
(provide grant grants grant-read grant-write grant-net grant-env grant-run make-grants grants-allow! grants-deny!
|
|
11
|
+
(provide grant grants grant-kind grant-read grant-write grant-net grant-env grant-run make-grants grants-allow! grants-deny!
|
|
12
12
|
grants-allow-all! grants-deny-all! grants-all! grants-inherit! grants-fake! grants-fetch! grants-tls!
|
|
13
13
|
grants-join! grants-parse! grants-flag? grants-add! grants-entries! grants-arguments)
|
|
14
14
|
|
|
15
15
|
(struct grant [kind string] [item string])
|
|
16
16
|
(struct grants [list buffer])
|
|
17
17
|
|
|
18
|
-
(
|
|
19
|
-
(const grant-write u32 1)
|
|
20
|
-
(const grant-net u32 2)
|
|
21
|
-
(const grant-env u32 3)
|
|
22
|
-
(const grant-run u32 4)
|
|
18
|
+
(enum grant-kind grant-read grant-write grant-net grant-env grant-run)
|
|
23
19
|
|
|
24
20
|
(define (make-grants) -> grants
|
|
25
21
|
(let ([g grants])
|
|
@@ -30,22 +26,24 @@
|
|
|
30
26
|
(let ([e (grant #:kind kind #:item item)])
|
|
31
27
|
(buffer-add! (& (-> g list)) (slice (cast (ptr u8) (& e)) (sizeof grant)))))
|
|
32
28
|
|
|
33
|
-
(define (allowed [k
|
|
29
|
+
(define (allowed [k grant-kind]) -> string
|
|
30
|
+
(match k [grant-read "read"] [grant-write "write"] [grant-net "net"] [grant-env "env"] [grant-run "run"]))
|
|
34
31
|
|
|
35
|
-
(define (denied [k
|
|
36
|
-
(
|
|
32
|
+
(define (denied [k grant-kind]) -> string
|
|
33
|
+
(match k [grant-read "deny-read"] [grant-write "deny-write"] [grant-net "deny-net"] [grant-env "deny-env"] [grant-run "deny-run"]))
|
|
37
34
|
|
|
38
|
-
(define (grants-allow! [g (ptr grants)] [k
|
|
35
|
+
(define (grants-allow! [g (ptr grants)] [k grant-kind] [item string]) (added! g (allowed k) item))
|
|
39
36
|
|
|
40
|
-
(define (grants-deny! [g (ptr grants)] [k
|
|
37
|
+
(define (grants-deny! [g (ptr grants)] [k grant-kind] [item string]) (added! g (denied k) item))
|
|
41
38
|
|
|
42
|
-
(define (grants-allow-all! [g (ptr grants)] [k
|
|
39
|
+
(define (grants-allow-all! [g (ptr grants)] [k grant-kind]) (added! g "all" (allowed k)))
|
|
43
40
|
|
|
44
|
-
(define (grants-deny-all! [g (ptr grants)] [k
|
|
41
|
+
(define (grants-deny-all! [g (ptr grants)] [k grant-kind]) (added! g "all" (denied k)))
|
|
45
42
|
|
|
46
|
-
(define (grants-all! [g (ptr grants)]) (for ([k u32 0]) (< k 5) (+= k 1) (grants-allow-all! g k)))
|
|
43
|
+
(define (grants-all! [g (ptr grants)]) (for ([k u32 0]) (< k 5) (+= k 1) (grants-allow-all! g (cast grant-kind k))))
|
|
47
44
|
|
|
48
|
-
(define (grants-inherit! [g (ptr grants)])
|
|
45
|
+
(define (grants-inherit! [g (ptr grants)])
|
|
46
|
+
(for ([k u32 0]) (< k 5) (+= k 1) (added! g "inherit" (allowed (cast grant-kind k)))))
|
|
49
47
|
|
|
50
48
|
(define (grants-fake! [g (ptr grants)] [name string]) (added! g "fake" name))
|
|
51
49
|
|
|
@@ -87,33 +85,34 @@
|
|
|
87
85
|
(for ([i u32 0]) (< i (-> s length)) (+= i 1) (when (== (@ s i) #\=) (return i)))
|
|
88
86
|
(-> s length))
|
|
89
87
|
|
|
90
|
-
(define (kind-of [name string] [k (ptr
|
|
88
|
+
(define (kind-of [name string] [k (ptr grant-kind)]) -> bool
|
|
91
89
|
(let ([shorts (array-of string "-R" "-W" "-N" "-E" "--allow-run")]
|
|
92
90
|
[longs (array-of string "--allow-read" "--allow-write" "--allow-net" "--allow-env" "--allow-run")])
|
|
93
91
|
(for ([i u32 0]) (< i 5) (+= i 1)
|
|
94
92
|
(when (or (== name (@ shorts i)) (== name (@ longs i)))
|
|
95
|
-
(set! (@ k) i)
|
|
93
|
+
(set! (@ k) (cast grant-kind i))
|
|
96
94
|
(return #t)))
|
|
97
95
|
#f))
|
|
98
96
|
|
|
99
|
-
(define (denial-of [name string] [k (ptr
|
|
97
|
+
(define (denial-of [name string] [k (ptr grant-kind)]) -> bool
|
|
100
98
|
(let ([names (array-of string "--deny-read" "--deny-write" "--deny-net" "--deny-env" "--deny-run")])
|
|
101
99
|
(for ([i u32 0]) (< i 5) (+= i 1)
|
|
102
100
|
(when (== name (@ names i))
|
|
103
|
-
(set! (@ k) i)
|
|
101
|
+
(set! (@ k) (cast grant-kind i))
|
|
104
102
|
(return #t)))
|
|
105
103
|
#f))
|
|
106
104
|
|
|
107
|
-
(define (refused [err (ptr
|
|
105
|
+
(define (refused [err (ptr error)] [a string] [b string]) -> bool
|
|
108
106
|
(let ([m (make-buffer)])
|
|
109
107
|
(buffer-add-string! (& m) a)
|
|
110
108
|
(buffer-add-string! (& m) b)
|
|
111
|
-
(
|
|
109
|
+
(error-fail! err error-invalid (buffer-string (& m)))
|
|
110
|
+
(buffer-free! (& m))
|
|
112
111
|
#f))
|
|
113
112
|
|
|
114
113
|
(define (pushed! [b (ptr buffer)] [s string]) (buffer-add! b (slice (cast (ptr u8) (& s)) (sizeof string))))
|
|
115
114
|
|
|
116
|
-
(define (split [flag string] [list string] [into (ptr buffer)] [err (ptr
|
|
115
|
+
(define (split [flag string] [list string] [into (ptr buffer)] [err (ptr error)]) -> bool
|
|
117
116
|
(let ([item (make-buffer)] [i u32 0] [n (-> list length)])
|
|
118
117
|
(while (<= i n)
|
|
119
118
|
(cond [(and (< (+ i 1) n) (== (@ list i) #\,) (== (@ list (+ i 1)) #\,))
|
|
@@ -132,13 +131,13 @@
|
|
|
132
131
|
(define (strings-in [b (ptr buffer)]) -> (slice string)
|
|
133
132
|
(slice (cast (ptr string) (-> b bytes)) (/ (-> b length) (sizeof string))))
|
|
134
133
|
|
|
135
|
-
(define (listed! [g (ptr grants)] [kind string] [flag string] [list string] [err (ptr
|
|
134
|
+
(define (listed! [g (ptr grants)] [kind string] [flag string] [list string] [err (ptr error)]) -> bool
|
|
136
135
|
(let ([items (make-buffer)])
|
|
137
136
|
(unless (split flag list (& items) err) (return #f))
|
|
138
137
|
(let ([l (strings-in (& items))]) (for ([i u32 0]) (< i (-> l length)) (+= i 1) (added! g kind (@ l i))))
|
|
139
138
|
#t))
|
|
140
139
|
|
|
141
|
-
(define (fakes! [g (ptr grants)] [flag string] [list string] [err (ptr
|
|
140
|
+
(define (fakes! [g (ptr grants)] [flag string] [list string] [err (ptr error)]) -> bool
|
|
142
141
|
(let ([items (make-buffer)])
|
|
143
142
|
(unless (split flag list (& items) err) (return #f))
|
|
144
143
|
(let ([l (strings-in (& items))])
|
|
@@ -157,10 +156,10 @@
|
|
|
157
156
|
(for ([i u32 0]) (< i (-> s length)) (+= i 1) (when (== (@ s i) #\:) (return i)))
|
|
158
157
|
(-> s length))
|
|
159
158
|
|
|
160
|
-
(define (grants-parse! [g (ptr grants)] [flags (slice string)] [err (ptr
|
|
159
|
+
(define (grants-parse! [g (ptr grants)] [flags (slice string)] [err (ptr error)]) -> bool
|
|
161
160
|
(for ([i u32 0]) (< i (-> flags length)) (+= i 1)
|
|
162
161
|
(let* ([flag (@ flags i)] [eq (equals-at flag)] [name (slice flag 0 eq)] [listed (< eq (-> flag length))]
|
|
163
|
-
[value (if listed (slice flag (+ eq 1) (-> flag length)) "")] [k
|
|
162
|
+
[value (if listed (slice flag (+ eq 1) (-> flag length)) "")] [k grant-kind])
|
|
164
163
|
(cond [(or (== name "-A") (== name "--allow-all"))
|
|
165
164
|
(when listed (return (refused err name " takes no list")))
|
|
166
165
|
(grants-all! g)]
|
|
@@ -178,21 +177,22 @@
|
|
|
178
177
|
#t)
|
|
179
178
|
|
|
180
179
|
(define (grants-flag? [s string]) -> bool
|
|
181
|
-
(let ([name (slice s 0 (equals-at s))] [k
|
|
180
|
+
(let ([name (slice s 0 (equals-at s))] [k grant-kind])
|
|
182
181
|
(or (== name "-A") (== name "--allow-all") (kind-of name (& k)) (denial-of name (& k)) (== name "--fake")
|
|
183
182
|
(== name "--tls-cert") (== name "--tls-key"))))
|
|
184
183
|
|
|
185
184
|
;; ---- clauses ----
|
|
186
185
|
|
|
187
|
-
(define (kind-named [name string] [deny bool] [k (ptr
|
|
186
|
+
(define (kind-named [name string] [deny bool] [k (ptr grant-kind)]) -> bool
|
|
188
187
|
(for ([i u32 0]) (< i 5) (+= i 1)
|
|
189
|
-
(
|
|
190
|
-
(
|
|
191
|
-
|
|
188
|
+
(let ([c (cast grant-kind i)])
|
|
189
|
+
(when (== name (if deny (denied c) (allowed c)))
|
|
190
|
+
(set! (@ k) c)
|
|
191
|
+
(return #t))))
|
|
192
192
|
#f)
|
|
193
193
|
|
|
194
|
-
(define (grants-add! [g (ptr grants)] [head string] [items (slice string)] [err (ptr
|
|
195
|
-
(let ([k
|
|
194
|
+
(define (grants-add! [g (ptr grants)] [head string] [items (slice string)] [err (ptr error)]) -> bool
|
|
195
|
+
(let ([k grant-kind] [n (-> items length)])
|
|
196
196
|
(when (== n 0) (return (refused err head " has no items")))
|
|
197
197
|
(for ([i u32 0]) (< i n) (+= i 1)
|
|
198
198
|
(when (== (-> (@ items i) length) 0) (return (refused err head " has an empty item"))))
|
|
@@ -122,7 +122,7 @@ export function fakeModules(setup, read) {
|
|
|
122
122
|
connect(up, ul, pp, pl, hp, hl, tag, err) {
|
|
123
123
|
const url = new URL(caller.string(up, ul));
|
|
124
124
|
if (!mayUrl(setup.grants.net, url)) {
|
|
125
|
-
caller.fail(err, `websocket.connect: ${url.host} is not granted (--allow-net)
|
|
125
|
+
caller.fail(err, `websocket.connect: ${url.host} is not granted (--allow-net)`, errors.notGranted);
|
|
126
126
|
return 0;
|
|
127
127
|
}
|
|
128
128
|
const [protocol = ''] = entries(caller.string(pp, pl));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The host module "websocket" (websocket.sub).
|
|
2
|
-
import { errors } from '../errors.mjs';
|
|
2
|
+
import { errors, errorOf } from '../errors.mjs';
|
|
3
3
|
import { entries } from '../entries.mjs';
|
|
4
4
|
import { mayUrl, portOfUrl } from '../grants.mjs';
|
|
5
5
|
|
|
@@ -46,7 +46,7 @@ export function websocket(grants, guard, node = false) {
|
|
|
46
46
|
connect(up, ul, pp, pl, hp, hl, tag, err) {
|
|
47
47
|
const url = caller.string(up, ul);
|
|
48
48
|
if (URL.canParse(url) && !mayUrl(grants.net, new URL(url))) {
|
|
49
|
-
caller.fail(err, `websocket.connect: ${new URL(url).host} is not granted (--allow-net)
|
|
49
|
+
caller.fail(err, `websocket.connect: ${new URL(url).host} is not granted (--allow-net)`, errors.notGranted);
|
|
50
50
|
return 0;
|
|
51
51
|
}
|
|
52
52
|
const protocols = entries(caller.string(pp, pl));
|
|
@@ -54,7 +54,7 @@ export function websocket(grants, guard, node = false) {
|
|
|
54
54
|
const headers = [];
|
|
55
55
|
for (let i = 0; i + 1 < list.length; i += 2) headers.push([list[i], list[i + 1]]);
|
|
56
56
|
if (headers.length > 0 && !node) {
|
|
57
|
-
caller.fail(err, 'websocket.connect: a page cannot send headers');
|
|
57
|
+
caller.fail(err, 'websocket.connect: a page cannot send headers', errors.invalid);
|
|
58
58
|
return 0;
|
|
59
59
|
}
|
|
60
60
|
const s = { ws: null, tag, polling: false, opened: false, denied: null };
|
|
@@ -65,7 +65,7 @@ export function websocket(grants, guard, node = false) {
|
|
|
65
65
|
const dispatcher = guard && URL.canParse(url) ? guard(portOfUrl(new URL(url)), denied) : undefined;
|
|
66
66
|
s.ws = node ? new WebSocket(url, { protocols, headers, dispatcher }) : new WebSocket(url, protocols);
|
|
67
67
|
} catch (e) {
|
|
68
|
-
caller.fail(err, e.message);
|
|
68
|
+
caller.fail(err, e.message, errorOf(e));
|
|
69
69
|
return 0;
|
|
70
70
|
}
|
|
71
71
|
const id = next++;
|
|
@@ -25,19 +25,21 @@
|
|
|
25
25
|
(set! (-> o protocols) 0)
|
|
26
26
|
(set! (-> o headers) 0))
|
|
27
27
|
|
|
28
|
-
(define (websocket-connect [url string] [o (ptr websocket-options)] [tag (ptr void)] [err (ptr
|
|
29
|
-
|
|
28
|
+
(define (websocket-connect [url string] [o (ptr websocket-options)] [tag (ptr void)] [id (ptr u32)] [err (ptr error)])
|
|
29
|
+
-> bool
|
|
30
|
+
(let ([defaults websocket-options] [p o] [protocols (make-buffer)] [headers (make-buffer)] [why string] [n u32 0])
|
|
30
31
|
(when (== p 0)
|
|
31
32
|
(websocket-options-init! (& defaults))
|
|
32
33
|
(set! p (& defaults)))
|
|
33
34
|
(buffer-add-entries! (& protocols) (-> p protocols))
|
|
34
35
|
(buffer-add-entries! (& headers) (-> p headers))
|
|
35
|
-
(set!
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
(set! n (cast u32 (connect (cast i32 (-> url bytes)) (cast i32 (-> url length)) (cast i32 (-> protocols bytes))
|
|
37
|
+
(cast i32 (-> protocols length)) (cast i32 (-> headers bytes))
|
|
38
|
+
(cast i32 (-> headers length)) (cast i32 tag) (cast i32 (& why)))))
|
|
38
39
|
(buffer-free! (& protocols))
|
|
39
40
|
(buffer-free! (& headers))
|
|
40
|
-
id))
|
|
41
|
+
(unless (== id 0) (set! (@ id) n))
|
|
42
|
+
(or (!= n 0) (host-failed! (& why) err))))
|
|
41
43
|
|
|
42
44
|
(define (websocket-send [id u32] [b (slice u8)] [kind i32]) -> i32
|
|
43
45
|
(send (cast i32 id) (cast i32 (-> b items)) (cast i32 (-> b length)) kind))
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The host module "env" (env.sub).
|
|
2
2
|
import { joined } from '../entries.mjs';
|
|
3
|
+
import { errors } from '../errors.mjs';
|
|
3
4
|
import { mayEnv, unlimited } from '../grants.mjs';
|
|
4
5
|
|
|
5
6
|
const utf8 = new TextEncoder();
|
|
@@ -9,11 +10,11 @@ export function env(grants) {
|
|
|
9
10
|
const named = (call, ptr, len, err) => {
|
|
10
11
|
const name = caller.string(ptr, len);
|
|
11
12
|
if (name === '' || /[=\0]/.test(name)) {
|
|
12
|
-
caller.fail(err, `${call}: a variable's name cannot be empty or hold = or NUL
|
|
13
|
+
caller.fail(err, `${call}: a variable's name cannot be empty or hold = or NUL`, errors.invalid);
|
|
13
14
|
return null;
|
|
14
15
|
}
|
|
15
16
|
if (!mayEnv(grants.env, name)) {
|
|
16
|
-
caller.fail(err, `${call}: ${name} is not granted (--allow-env)
|
|
17
|
+
caller.fail(err, `${call}: ${name} is not granted (--allow-env)`, errors.notGranted);
|
|
17
18
|
return null;
|
|
18
19
|
}
|
|
19
20
|
return name;
|
|
@@ -21,15 +22,20 @@ export function env(grants) {
|
|
|
21
22
|
return {
|
|
22
23
|
get(ptr, len, out, err) {
|
|
23
24
|
const name = named('env.get', ptr, len, err);
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
if (name === null) return 0;
|
|
26
|
+
const value = process.env[name];
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
caller.fail(err, `env.get: ${name} is not set`, errors.missing);
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
return caller.give(utf8.encode(value), out);
|
|
26
32
|
},
|
|
27
33
|
set(np, nl, vp, vl, err) {
|
|
28
34
|
const name = named('env.set', np, nl, err);
|
|
29
35
|
if (name === null) return -1;
|
|
30
36
|
const value = caller.string(vp, vl);
|
|
31
37
|
if (value.includes('\0')) {
|
|
32
|
-
caller.fail(err, "env.set: a variable's value cannot hold NUL");
|
|
38
|
+
caller.fail(err, "env.set: a variable's value cannot hold NUL", errors.invalid);
|
|
33
39
|
return -1;
|
|
34
40
|
}
|
|
35
41
|
process.env[name] = value;
|
|
@@ -44,7 +50,7 @@ export function env(grants) {
|
|
|
44
50
|
list(out, err) {
|
|
45
51
|
const all = unlimited(grants.env);
|
|
46
52
|
if (!all && (grants.env.deny.all || (!grants.env.all && grants.env.items.length === 0))) {
|
|
47
|
-
caller.fail(err, 'env.list: the environment is not granted (--allow-env)');
|
|
53
|
+
caller.fail(err, 'env.list: the environment is not granted (--allow-env)', errors.notGranted);
|
|
48
54
|
return 0;
|
|
49
55
|
}
|
|
50
56
|
const names = Object.keys(process.env)
|