@waffle-os/runtime 0.0.153 → 0.0.155
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/browser/net/helper.ts +114 -19
- package/browser/net/ring.ts +18 -6
- package/browser/net/runtime.ts +2 -2
- package/browser/notification-relay.ts +105 -18
- package/browser/notification-wait.ts +45 -4
- package/browser/notification-worker.ts +169 -76
- package/browser/preview.ts +15 -2
- package/core/filesystem.ts +18 -0
- package/core/wasi.ts +75 -4
- package/dist/browser/net/helper.js +83 -18
- package/dist/browser/net/ring.js +6 -5
- package/dist/browser/net/runtime.js +2 -2
- package/dist/browser/notification-relay.js +78 -15
- package/dist/browser/notification-wait.js +37 -5
- package/dist/browser/notification-worker.js +146 -67
- package/dist/core/wasi.js +62 -4
- package/dist/fs/backend.js +7 -0
- package/dist/fs/client.js +75 -17
- package/dist/fs/dirty-admission.js +15 -8
- package/dist/fs/guest-watch.js +267 -94
- package/dist/fs/indexeddb-chunks.js +88 -11
- package/dist/fs/indexeddb.js +366 -110
- package/dist/fs/memory.js +106 -20
- package/dist/fs/multitab-backend.js +291 -74
- package/dist/fs/multitab-protocol.js +1 -0
- package/dist/fs/persistent.js +70 -16
- package/dist/fs/protocol.js +15 -7
- package/dist/fs/publication-attachment.js +9 -7
- package/dist/fs/service.js +62 -9
- package/dist/fs/shared.js +100 -6
- package/dist/fs/storage.js +107 -8
- package/dist/fs/watch-service.js +97 -2
- package/dist/fs/watch-subscriptions.js +121 -8
- package/dist/proc/command-stdio.js +1 -1
- package/dist/proc/intrinsics/core.js +5 -0
- package/dist/proc/intrinsics.js +1 -0
- package/dist/tooling/program/program-transformer.json +1 -1
- package/fs/backend.ts +17 -0
- package/fs/client.ts +99 -16
- package/fs/dirty-admission.ts +22 -7
- package/fs/guest-watch.ts +299 -103
- package/fs/indexeddb-chunks.ts +103 -9
- package/fs/indexeddb.ts +477 -121
- package/fs/memory.ts +120 -19
- package/fs/multitab-backend.ts +440 -95
- package/fs/multitab-protocol.ts +1 -0
- package/fs/persistent.ts +88 -16
- package/fs/protocol.ts +26 -7
- package/fs/publication-attachment.ts +9 -7
- package/fs/service.ts +62 -7
- package/fs/shared.ts +110 -8
- package/fs/storage.ts +128 -10
- package/fs/watch-service.ts +110 -3
- package/fs/watch-subscriptions.ts +115 -7
- package/package.json +1 -1
- package/proc/command-stdio.ts +1 -1
- package/proc/intrinsics/core.ts +7 -0
- package/proc/intrinsics.ts +1 -0
- package/testing/idle-workspace-cancellation-browser.ts +22 -13
- package/testing/indexeddb-storage-browser.ts +564 -1
- package/tooling/program/program-transformer.json +1 -1
package/dist/fs/storage.js
CHANGED
|
@@ -14,17 +14,116 @@ export function restoreTime(time) {
|
|
|
14
14
|
function validTime(value) {
|
|
15
15
|
return typeof value === "string" && /^(0|[1-9][0-9]{0,19})$/.test(value) && BigInt(value) <= MAX_FILE_TIME;
|
|
16
16
|
}
|
|
17
|
+
const NODE_KEYS = new Set([
|
|
18
|
+
"ino",
|
|
19
|
+
"kind",
|
|
20
|
+
"atime",
|
|
21
|
+
"mtime",
|
|
22
|
+
"ctime",
|
|
23
|
+
"mode",
|
|
24
|
+
"size",
|
|
25
|
+
"children",
|
|
26
|
+
"data",
|
|
27
|
+
"target",
|
|
28
|
+
"identity"
|
|
29
|
+
]);
|
|
30
|
+
function isPlainObject(value) {
|
|
31
|
+
if (!value || typeof value !== "object")
|
|
32
|
+
return false;
|
|
33
|
+
const proto = Object.getPrototypeOf(value);
|
|
34
|
+
return proto === Object.prototype || proto === null;
|
|
35
|
+
}
|
|
36
|
+
function cloneStoredIdentity(value) {
|
|
37
|
+
if (!isPlainObject(value))
|
|
38
|
+
return;
|
|
39
|
+
const keys = Object.keys(value);
|
|
40
|
+
if (keys.length !== 4 || typeof value.format !== "string" || typeof value.workspace !== "string" || typeof value.id !== "string" || typeof value.version !== "string")
|
|
41
|
+
return;
|
|
42
|
+
return {
|
|
43
|
+
format: value.format,
|
|
44
|
+
workspace: value.workspace,
|
|
45
|
+
id: value.id,
|
|
46
|
+
version: value.version
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function clonePersistedNode(node) {
|
|
50
|
+
if (!isPlainObject(node))
|
|
51
|
+
return structuredClone(node);
|
|
52
|
+
const keys = Object.keys(node);
|
|
53
|
+
for (let i = 0;i < keys.length; i++) {
|
|
54
|
+
if (!NODE_KEYS.has(keys[i]))
|
|
55
|
+
return structuredClone(node);
|
|
56
|
+
}
|
|
57
|
+
if (typeof node.ino !== "number" || typeof node.kind !== "string" || typeof node.atime !== "string" || typeof node.mtime !== "string" || typeof node.ctime !== "string" || typeof node.size !== "number" || node.mode !== undefined && typeof node.mode !== "number" || node.data !== undefined && typeof node.data !== "string" || node.target !== undefined && typeof node.target !== "string")
|
|
58
|
+
return structuredClone(node);
|
|
59
|
+
let identity;
|
|
60
|
+
if (node.identity !== undefined) {
|
|
61
|
+
identity = cloneStoredIdentity(node.identity);
|
|
62
|
+
if (!identity)
|
|
63
|
+
return structuredClone(node);
|
|
64
|
+
}
|
|
65
|
+
let children;
|
|
66
|
+
if (node.children !== undefined) {
|
|
67
|
+
if (!Array.isArray(node.children))
|
|
68
|
+
return structuredClone(node);
|
|
69
|
+
children = Array.from({ length: node.children.length });
|
|
70
|
+
for (let i = 0;i < node.children.length; i++) {
|
|
71
|
+
const entry = node.children[i];
|
|
72
|
+
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string" || typeof entry[1] !== "number")
|
|
73
|
+
return structuredClone(node);
|
|
74
|
+
children[i] = [entry[0], entry[1]];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const copy = {
|
|
78
|
+
ino: node.ino,
|
|
79
|
+
kind: node.kind,
|
|
80
|
+
atime: node.atime,
|
|
81
|
+
mtime: node.mtime,
|
|
82
|
+
ctime: node.ctime,
|
|
83
|
+
size: node.size
|
|
84
|
+
};
|
|
85
|
+
if ("mode" in node)
|
|
86
|
+
copy.mode = node.mode;
|
|
87
|
+
if ("data" in node)
|
|
88
|
+
copy.data = node.data;
|
|
89
|
+
if ("target" in node)
|
|
90
|
+
copy.target = node.target;
|
|
91
|
+
if ("children" in node)
|
|
92
|
+
copy.children = children;
|
|
93
|
+
if ("identity" in node)
|
|
94
|
+
copy.identity = identity;
|
|
95
|
+
return copy;
|
|
96
|
+
}
|
|
97
|
+
function cloneNumberArray(values) {
|
|
98
|
+
if (!Array.isArray(values))
|
|
99
|
+
return structuredClone(values);
|
|
100
|
+
for (let i = 0;i < values.length; i++) {
|
|
101
|
+
if (typeof values[i] !== "number")
|
|
102
|
+
return structuredClone(values);
|
|
103
|
+
}
|
|
104
|
+
return values.slice();
|
|
105
|
+
}
|
|
106
|
+
function cloneStringArray(values) {
|
|
107
|
+
if (!Array.isArray(values))
|
|
108
|
+
return structuredClone(values);
|
|
109
|
+
for (let i = 0;i < values.length; i++) {
|
|
110
|
+
if (typeof values[i] !== "string")
|
|
111
|
+
return structuredClone(values);
|
|
112
|
+
}
|
|
113
|
+
return values.slice();
|
|
114
|
+
}
|
|
17
115
|
export function snapshotBatch(batch) {
|
|
116
|
+
const data = new Map;
|
|
117
|
+
for (const [key, bytes] of batch.data)
|
|
118
|
+
data.set(key, new Uint8Array(bytes));
|
|
18
119
|
return {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
retainedData: batch.retainedData
|
|
25
|
-
}),
|
|
120
|
+
generation: batch.generation,
|
|
121
|
+
root: batch.root,
|
|
122
|
+
upserts: Array.isArray(batch.upserts) ? batch.upserts.map(clonePersistedNode) : structuredClone(batch.upserts),
|
|
123
|
+
removes: cloneNumberArray(batch.removes),
|
|
124
|
+
...batch.retainedData !== undefined ? { retainedData: cloneStringArray(batch.retainedData) } : {},
|
|
26
125
|
...batch.publication ? { publication: snapshotPublicationCheckpoint(batch.publication) } : {},
|
|
27
|
-
data
|
|
126
|
+
data
|
|
28
127
|
};
|
|
29
128
|
}
|
|
30
129
|
function invalid() {
|
package/dist/fs/watch-service.js
CHANGED
|
@@ -4,6 +4,7 @@ import { WatchIndex } from "./watch-index.js";
|
|
|
4
4
|
import { WatchRouting } from "./watch-routing.js";
|
|
5
5
|
import { WatchSubscriptions } from "./watch-subscriptions.js";
|
|
6
6
|
import { WATCH_CAPACITY } from "./watch-ring.js";
|
|
7
|
+
const MAX_DRAIN_ITEMS = 128;
|
|
7
8
|
|
|
8
9
|
export class WatchService {
|
|
9
10
|
backend;
|
|
@@ -89,6 +90,95 @@ export class WatchService {
|
|
|
89
90
|
held.release();
|
|
90
91
|
}
|
|
91
92
|
}
|
|
93
|
+
drainHeld(owner) {
|
|
94
|
+
return this.backend.shared.mutate(undefined, undefined, () => this.collectDrain(owner));
|
|
95
|
+
}
|
|
96
|
+
collectDrain(owner) {
|
|
97
|
+
this.drain();
|
|
98
|
+
const state = { entries: [], held: [], events: 0, items: 0, more: false };
|
|
99
|
+
try {
|
|
100
|
+
this.subscriptions.forReady(owner, (id) => this.collectDrainWatch(owner, id, state));
|
|
101
|
+
} catch (error) {
|
|
102
|
+
for (let i = state.held.length - 1;i >= 0; i--)
|
|
103
|
+
state.held[i].rollback();
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
return this.finishDrain(state);
|
|
107
|
+
}
|
|
108
|
+
collectDrainWatch(owner, id, state) {
|
|
109
|
+
const denied = this.drainAccess(owner, id);
|
|
110
|
+
if (denied !== undefined) {
|
|
111
|
+
if (state.entries.length > 0 && state.items + 1 > MAX_DRAIN_ITEMS) {
|
|
112
|
+
state.more = true;
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
state.items++;
|
|
116
|
+
state.entries.push({ id, errno: denied });
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
const overflowed = this.subscriptions.overflowed(owner, id);
|
|
120
|
+
const queued = overflowed ? 0 : this.subscriptions.queuedCount(owner, id);
|
|
121
|
+
if (!overflowed && queued === 0)
|
|
122
|
+
return true;
|
|
123
|
+
const cost = overflowed ? 1 : queued;
|
|
124
|
+
if (state.entries.length > 0 && state.items + cost > MAX_DRAIN_ITEMS) {
|
|
125
|
+
state.more = true;
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const item = this.subscriptions.batch(owner, id, state.held.length > 0);
|
|
129
|
+
if (!item) {
|
|
130
|
+
state.more = true;
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
if (item.batch.kind === "events" && !item.batch.events.length) {
|
|
134
|
+
item.release();
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
if (item.batch.events.length) {
|
|
138
|
+
state.events += item.batch.events.length;
|
|
139
|
+
state.items += item.batch.events.length;
|
|
140
|
+
state.held.push(item);
|
|
141
|
+
} else {
|
|
142
|
+
state.items++;
|
|
143
|
+
item.release();
|
|
144
|
+
}
|
|
145
|
+
state.entries.push({ id, batch: item.batch });
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
drainAccess(owner, id) {
|
|
149
|
+
if (this.incomplete || this.subscriptions.overflowed(owner, id))
|
|
150
|
+
return;
|
|
151
|
+
try {
|
|
152
|
+
this.access(this.subscriptions.root(owner, id));
|
|
153
|
+
return;
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (error instanceof FilesystemError)
|
|
156
|
+
return error.errno;
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
finishDrain(state) {
|
|
161
|
+
let settled = false;
|
|
162
|
+
const settle = (rollback) => {
|
|
163
|
+
if (settled)
|
|
164
|
+
return;
|
|
165
|
+
settled = true;
|
|
166
|
+
if (rollback) {
|
|
167
|
+
for (let i = state.held.length - 1;i >= 0; i--)
|
|
168
|
+
state.held[i].rollback();
|
|
169
|
+
} else {
|
|
170
|
+
for (const item of state.held)
|
|
171
|
+
item.release();
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
entries: state.entries,
|
|
176
|
+
more: state.more,
|
|
177
|
+
hasEvents: state.events > 0,
|
|
178
|
+
release: () => settle(false),
|
|
179
|
+
rollback: () => settle(true)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
92
182
|
close(owner, id) {
|
|
93
183
|
let directory = false;
|
|
94
184
|
try {
|
|
@@ -228,8 +318,13 @@ export class WatchService {
|
|
|
228
318
|
}
|
|
229
319
|
if (!this.index.has(record.file))
|
|
230
320
|
return;
|
|
231
|
-
if (record.kind === "metadata")
|
|
232
|
-
|
|
321
|
+
if (record.kind === "metadata") {
|
|
322
|
+
const directory = this.index.metadata(record.file).directory;
|
|
323
|
+
this.index.upsert(record.file, record.mode, directory);
|
|
324
|
+
const required = directory ? 320 : 256;
|
|
325
|
+
const inaccessible = (record.mode & required) !== required;
|
|
326
|
+
this.subscriptions.forRoot(record.file, (owner, id) => this.subscriptions.setInaccessible(owner, id, inaccessible));
|
|
327
|
+
}
|
|
233
328
|
this.deliver(record.file, "change");
|
|
234
329
|
}
|
|
235
330
|
target(file, type) {
|
|
@@ -5,12 +5,16 @@ import { WatchIdIndex, watchId, setWatchId } from "./watch-id-index.js";
|
|
|
5
5
|
import { WatchIndex } from "./watch-index.js";
|
|
6
6
|
import { WatchNames } from "./watch-names.js";
|
|
7
7
|
import { WATCH_CAPACITY } from "./watch-ring.js";
|
|
8
|
-
const WIDTH =
|
|
8
|
+
const WIDTH = 56;
|
|
9
9
|
const EVENT = 32;
|
|
10
10
|
const HEAD = 20;
|
|
11
11
|
const TAIL = 24;
|
|
12
12
|
const COUNT = 28;
|
|
13
|
+
const READY_NEXT = 48;
|
|
14
|
+
const READY_PREV = 52;
|
|
13
15
|
const OVERFLOW = 2;
|
|
16
|
+
const READY = 4;
|
|
17
|
+
const INACCESSIBLE = 8;
|
|
14
18
|
const NULL_NAME = 4294967295;
|
|
15
19
|
|
|
16
20
|
export class WatchSubscriptions {
|
|
@@ -19,6 +23,7 @@ export class WatchSubscriptions {
|
|
|
19
23
|
records;
|
|
20
24
|
ids;
|
|
21
25
|
owners;
|
|
26
|
+
readyOwners;
|
|
22
27
|
events;
|
|
23
28
|
names;
|
|
24
29
|
tail = 0;
|
|
@@ -34,6 +39,7 @@ export class WatchSubscriptions {
|
|
|
34
39
|
this.records = new WatchArena(account);
|
|
35
40
|
this.ids = new WatchIdIndex(account);
|
|
36
41
|
this.owners = new WatchIdIndex(account);
|
|
42
|
+
this.readyOwners = new WatchIdIndex(account);
|
|
37
43
|
this.events = new WatchArena(account, "events");
|
|
38
44
|
this.names = new WatchNames(account, 12288, "events");
|
|
39
45
|
}
|
|
@@ -67,18 +73,23 @@ export class WatchSubscriptions {
|
|
|
67
73
|
const record = this.records.stage(slot * WIDTH);
|
|
68
74
|
let lookup;
|
|
69
75
|
let owners;
|
|
76
|
+
let readyOwners;
|
|
70
77
|
try {
|
|
71
78
|
lookup = this.ids.stage();
|
|
72
|
-
if (!this.owners.get(BigInt(owner)))
|
|
79
|
+
if (!this.owners.get(BigInt(owner))) {
|
|
73
80
|
owners = this.owners.stage();
|
|
81
|
+
readyOwners = this.readyOwners.stage();
|
|
82
|
+
}
|
|
74
83
|
this.index.pin(root);
|
|
75
84
|
record.commit();
|
|
76
85
|
lookup.commit();
|
|
77
86
|
owners?.commit();
|
|
87
|
+
readyOwners?.commit();
|
|
78
88
|
} catch (error) {
|
|
79
89
|
record.cancel();
|
|
80
90
|
lookup?.cancel();
|
|
81
91
|
owners?.cancel();
|
|
92
|
+
readyOwners?.cancel();
|
|
82
93
|
throw error;
|
|
83
94
|
}
|
|
84
95
|
const at = (slot - 1) * WIDTH;
|
|
@@ -100,19 +111,109 @@ export class WatchSubscriptions {
|
|
|
100
111
|
}
|
|
101
112
|
attach(slot, root, owner) {
|
|
102
113
|
const at = (slot - 1) * WIDTH;
|
|
103
|
-
const
|
|
114
|
+
const ownerKey = BigInt(owner);
|
|
115
|
+
const ownerHead = this.owners.get(ownerKey);
|
|
104
116
|
const rootHead = this.index.watchHead(root);
|
|
105
117
|
this.records.view.setUint32(at + 32, ownerHead, true);
|
|
106
118
|
this.records.view.setUint32(at + 40, rootHead, true);
|
|
107
119
|
if (ownerHead) {
|
|
108
120
|
this.records.view.setUint32((ownerHead - 1) * WIDTH + 36, slot, true);
|
|
109
|
-
this.owners.set(
|
|
110
|
-
} else
|
|
111
|
-
this.owners.add(
|
|
121
|
+
this.owners.set(ownerKey, slot);
|
|
122
|
+
} else {
|
|
123
|
+
this.owners.add(ownerKey, slot);
|
|
124
|
+
this.readyOwners.add(ownerKey, 0);
|
|
125
|
+
}
|
|
112
126
|
if (rootHead)
|
|
113
127
|
this.records.view.setUint32((rootHead - 1) * WIDTH + 44, slot, true);
|
|
114
128
|
this.index.setWatchHead(root, slot);
|
|
115
129
|
}
|
|
130
|
+
markReady(slot, owner) {
|
|
131
|
+
const at = (slot - 1) * WIDTH;
|
|
132
|
+
const view = this.records.view;
|
|
133
|
+
const flags = view.getUint32(at + 16, true);
|
|
134
|
+
if (flags & READY)
|
|
135
|
+
return;
|
|
136
|
+
view.setUint32(at + 16, flags | READY, true);
|
|
137
|
+
const ownerKey = BigInt(owner);
|
|
138
|
+
const head = this.readyOwners.get(ownerKey);
|
|
139
|
+
if (!head) {
|
|
140
|
+
view.setUint32(at + READY_NEXT, slot, true);
|
|
141
|
+
view.setUint32(at + READY_PREV, slot, true);
|
|
142
|
+
this.readyOwners.set(ownerKey, slot);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const headAt = (head - 1) * WIDTH;
|
|
146
|
+
const tail = view.getUint32(headAt + READY_PREV, true);
|
|
147
|
+
view.setUint32(at + READY_NEXT, head, true);
|
|
148
|
+
view.setUint32(at + READY_PREV, tail, true);
|
|
149
|
+
view.setUint32((tail - 1) * WIDTH + READY_NEXT, slot, true);
|
|
150
|
+
view.setUint32(headAt + READY_PREV, slot, true);
|
|
151
|
+
}
|
|
152
|
+
unmarkReady(slot, owner) {
|
|
153
|
+
const at = (slot - 1) * WIDTH;
|
|
154
|
+
const view = this.records.view;
|
|
155
|
+
const flags = view.getUint32(at + 16, true);
|
|
156
|
+
if (!(flags & READY))
|
|
157
|
+
return;
|
|
158
|
+
view.setUint32(at + 16, flags & ~READY, true);
|
|
159
|
+
const next = view.getUint32(at + READY_NEXT, true);
|
|
160
|
+
const previous = view.getUint32(at + READY_PREV, true);
|
|
161
|
+
const ownerKey = BigInt(owner);
|
|
162
|
+
if (next === slot) {
|
|
163
|
+
this.readyOwners.set(ownerKey, 0);
|
|
164
|
+
} else {
|
|
165
|
+
view.setUint32((previous - 1) * WIDTH + READY_NEXT, next, true);
|
|
166
|
+
view.setUint32((next - 1) * WIDTH + READY_PREV, previous, true);
|
|
167
|
+
if (this.readyOwners.get(ownerKey) === slot)
|
|
168
|
+
this.readyOwners.set(ownerKey, next);
|
|
169
|
+
}
|
|
170
|
+
view.setUint32(at + READY_NEXT, 0, true);
|
|
171
|
+
view.setUint32(at + READY_PREV, 0, true);
|
|
172
|
+
}
|
|
173
|
+
setInaccessible(owner, id, inaccessible) {
|
|
174
|
+
const at = this.at(owner, id);
|
|
175
|
+
const slot = at / WIDTH + 1;
|
|
176
|
+
const view = this.records.view;
|
|
177
|
+
const flags = view.getUint32(at + 16, true);
|
|
178
|
+
if (inaccessible) {
|
|
179
|
+
view.setUint32(at + 16, flags | INACCESSIBLE, true);
|
|
180
|
+
this.markReady(slot, owner);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (!(flags & INACCESSIBLE))
|
|
184
|
+
return;
|
|
185
|
+
view.setUint32(at + 16, flags & ~INACCESSIBLE, true);
|
|
186
|
+
if (!(flags & OVERFLOW) && !view.getUint32(at + COUNT, true))
|
|
187
|
+
this.unmarkReady(slot, owner);
|
|
188
|
+
}
|
|
189
|
+
forReady(owner, visit) {
|
|
190
|
+
const ownerKey = BigInt(owner);
|
|
191
|
+
const start = this.readyOwners.get(ownerKey);
|
|
192
|
+
if (!start)
|
|
193
|
+
return;
|
|
194
|
+
const last = this.records.view.getUint32((start - 1) * WIDTH + READY_PREV, true);
|
|
195
|
+
let slot = start;
|
|
196
|
+
while (slot) {
|
|
197
|
+
const at = (slot - 1) * WIDTH;
|
|
198
|
+
const done = slot === last;
|
|
199
|
+
const next = this.records.view.getUint32(at + READY_NEXT, true);
|
|
200
|
+
const keepGoing = visit(this.records.view.getFloat64(at, true));
|
|
201
|
+
if (keepGoing === false)
|
|
202
|
+
return;
|
|
203
|
+
if (this.records.view.getUint32(at + 16, true) & READY && next !== slot) {
|
|
204
|
+
this.readyOwners.set(ownerKey, next);
|
|
205
|
+
}
|
|
206
|
+
if (done)
|
|
207
|
+
return;
|
|
208
|
+
slot = next;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
queuedCount(owner, id) {
|
|
212
|
+
const at = this.at(owner, id);
|
|
213
|
+
if (this.records.view.getUint32(at + 16, true) & OVERFLOW)
|
|
214
|
+
return 0;
|
|
215
|
+
return this.records.view.getUint32(at + COUNT, true);
|
|
216
|
+
}
|
|
116
217
|
root(owner, id) {
|
|
117
218
|
const at = this.at(owner, id);
|
|
118
219
|
return this.index.id(this.records.view.getUint32(at + 12, true));
|
|
@@ -149,6 +250,7 @@ export class WatchSubscriptions {
|
|
|
149
250
|
return this.overflow(owner, id);
|
|
150
251
|
try {
|
|
151
252
|
this.append(at, event);
|
|
253
|
+
this.markReady(at / WIDTH + 1, owner);
|
|
152
254
|
} catch (error) {
|
|
153
255
|
if (!(error instanceof FilesystemError) || error.errno !== 6 && error.errno !== 48)
|
|
154
256
|
throw error;
|
|
@@ -217,7 +319,7 @@ export class WatchSubscriptions {
|
|
|
217
319
|
name: length === NULL_NAME ? null : this.names.read(view.getUint32(at + 28, true), length)
|
|
218
320
|
};
|
|
219
321
|
}
|
|
220
|
-
batch(owner, id) {
|
|
322
|
+
batch(owner, id, deferOnBudget = false) {
|
|
221
323
|
const at = this.at(owner, id);
|
|
222
324
|
if (this.records.view.getUint32(at + 16, true) & OVERFLOW)
|
|
223
325
|
return { batch: { kind: "overflow", events: [] }, release() {}, rollback() {} };
|
|
@@ -235,6 +337,8 @@ export class WatchSubscriptions {
|
|
|
235
337
|
} catch (error) {
|
|
236
338
|
if (!(error instanceof FilesystemError) || error.errno !== 6)
|
|
237
339
|
throw error;
|
|
340
|
+
if (deferOnBudget)
|
|
341
|
+
return;
|
|
238
342
|
this.overflow(owner, id);
|
|
239
343
|
return { batch: { kind: "overflow", events: [] }, release() {}, rollback() {} };
|
|
240
344
|
}
|
|
@@ -251,6 +355,8 @@ export class WatchSubscriptions {
|
|
|
251
355
|
this.records.view.setUint32(at + HEAD, 0, true);
|
|
252
356
|
this.records.view.setUint32(at + TAIL, 0, true);
|
|
253
357
|
this.records.view.setUint32(at + COUNT, 0, true);
|
|
358
|
+
if (!(this.records.view.getUint32(at + 16, true) & (OVERFLOW | INACCESSIBLE)))
|
|
359
|
+
this.unmarkReady(at / WIDTH + 1, owner);
|
|
254
360
|
let held = true;
|
|
255
361
|
const settle = (rollback) => {
|
|
256
362
|
if (!held)
|
|
@@ -285,6 +391,7 @@ export class WatchSubscriptions {
|
|
|
285
391
|
if (!current)
|
|
286
392
|
this.records.view.setUint32(at + TAIL, last, true);
|
|
287
393
|
this.records.view.setUint32(at + COUNT, current + count, true);
|
|
394
|
+
this.markReady(at / WIDTH + 1, owner);
|
|
288
395
|
return true;
|
|
289
396
|
}
|
|
290
397
|
releaseEvents(first) {
|
|
@@ -308,6 +415,7 @@ export class WatchSubscriptions {
|
|
|
308
415
|
this.records.view.setUint32(at + TAIL, 0, true);
|
|
309
416
|
this.records.view.setUint32(at + COUNT, 0, true);
|
|
310
417
|
this.records.view.setUint32(at + 16, this.records.view.getUint32(at + 16, true) | OVERFLOW, true);
|
|
418
|
+
this.markReady(at / WIDTH + 1, owner);
|
|
311
419
|
}
|
|
312
420
|
close(owner, id) {
|
|
313
421
|
if (!this.slot(id))
|
|
@@ -327,6 +435,7 @@ export class WatchSubscriptions {
|
|
|
327
435
|
this.records.close();
|
|
328
436
|
this.ids.close();
|
|
329
437
|
this.owners.close();
|
|
438
|
+
this.readyOwners.close();
|
|
330
439
|
this.tail = this.free = 0;
|
|
331
440
|
if (!this.queued)
|
|
332
441
|
this.resetEvents();
|
|
@@ -334,6 +443,7 @@ export class WatchSubscriptions {
|
|
|
334
443
|
return true;
|
|
335
444
|
}
|
|
336
445
|
detach(slot, root, owner) {
|
|
446
|
+
this.unmarkReady(slot, owner);
|
|
337
447
|
const at = (slot - 1) * WIDTH;
|
|
338
448
|
const ownerNext = this.records.view.getUint32(at + 32, true);
|
|
339
449
|
const ownerPrevious = this.records.view.getUint32(at + 36, true);
|
|
@@ -343,8 +453,10 @@ export class WatchSubscriptions {
|
|
|
343
453
|
this.records.view.setUint32((ownerPrevious - 1) * WIDTH + 32, ownerNext, true);
|
|
344
454
|
else if (ownerNext)
|
|
345
455
|
this.owners.set(BigInt(owner), ownerNext);
|
|
346
|
-
else
|
|
456
|
+
else {
|
|
347
457
|
this.owners.delete(BigInt(owner));
|
|
458
|
+
this.readyOwners.delete(BigInt(owner));
|
|
459
|
+
}
|
|
348
460
|
if (ownerNext)
|
|
349
461
|
this.records.view.setUint32((ownerNext - 1) * WIDTH + 36, ownerPrevious, true);
|
|
350
462
|
if (rootPrevious)
|
|
@@ -375,6 +487,7 @@ export class WatchSubscriptions {
|
|
|
375
487
|
this.records.close();
|
|
376
488
|
this.ids.close();
|
|
377
489
|
this.owners.close();
|
|
490
|
+
this.readyOwners.close();
|
|
378
491
|
this.events.close();
|
|
379
492
|
this.names.close();
|
|
380
493
|
}
|
|
@@ -211,7 +211,7 @@ export class CommandStdio {
|
|
|
211
211
|
if (!filesystem)
|
|
212
212
|
throw new CommandStdioError("EBADF", "File descriptor has no filesystem connection");
|
|
213
213
|
const offset = shareFileResource(resource, filesystem.connection);
|
|
214
|
-
return [new Int32Array(filesystem.connection.signal), new Int32Array(offset, 0, 1)];
|
|
214
|
+
return [new Int32Array(filesystem.connection.signal, 0, 1), new Int32Array(offset, 0, 1)];
|
|
215
215
|
}
|
|
216
216
|
file(resource, bytes, writing) {
|
|
217
217
|
const filesystem = this.filesystem;
|
|
@@ -29,7 +29,12 @@ export const MapConstructor = Map;
|
|
|
29
29
|
const mapGetMethod = Map.prototype.get, mapSetMethod = Map.prototype.set;
|
|
30
30
|
const mapHasMethod = Map.prototype.has, mapDeleteMethod = Map.prototype.delete;
|
|
31
31
|
const mapForEachMethod = Map.prototype.forEach;
|
|
32
|
+
const mapValuesMethod = Map.prototype.values;
|
|
33
|
+
const mapIteratorNext = objectGetPrototypeOf(new MapConstructor().values()).next;
|
|
32
34
|
const mapSizeGetter = descriptor(Map.prototype, "size").get;
|
|
35
|
+
export function mapFirst(map) {
|
|
36
|
+
return apply(mapIteratorNext, apply(mapValuesMethod, map, []), []).value;
|
|
37
|
+
}
|
|
33
38
|
export function mapGet(map, key) {
|
|
34
39
|
return apply(mapGetMethod, map, [key]);
|
|
35
40
|
}
|
package/dist/proc/intrinsics.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commit":"
|
|
1
|
+
{"commit":"b2cbaa1b6b80ccf3d082d6cb6af8075e2b607006","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
|
package/fs/backend.ts
CHANGED
|
@@ -55,6 +55,12 @@ export interface FilesystemBackend {
|
|
|
55
55
|
):
|
|
56
56
|
| import("./watch-subscriptions.js").HeldWatchBatch
|
|
57
57
|
| Promise<import("./watch-subscriptions.js").HeldWatchBatch>;
|
|
58
|
+
watchDrain?(
|
|
59
|
+
owner: number,
|
|
60
|
+
cancelled: () => boolean,
|
|
61
|
+
):
|
|
62
|
+
| import("./watch-service.js").HeldWatchDrain
|
|
63
|
+
| Promise<import("./watch-service.js").HeldWatchDrain>;
|
|
58
64
|
watchClose?(owner: number, watchId: number): void;
|
|
59
65
|
closeWatchOwner?(owner: number): void;
|
|
60
66
|
/** Called in FilesystemService.request() finally after finishResult() to settle provisional pins. */
|
|
@@ -71,6 +77,9 @@ export interface FilesystemBackend {
|
|
|
71
77
|
isPreparedReadValid?(): boolean;
|
|
72
78
|
/** Whether a handle is unlinked (used by service capability trimming when not MemoryBackend). */
|
|
73
79
|
isUnlinked?(handle: FileHandle): boolean;
|
|
80
|
+
/** Changes whenever `isUnlinked` may have become true for some handle, so capability trimming
|
|
81
|
+
* can skip rescanning while nothing was unlinked. Without it every trim rescans. */
|
|
82
|
+
unlinkGeneration?(): number;
|
|
74
83
|
/** Select a bounded cold descriptor range before asynchronous storage work. */
|
|
75
84
|
prepareDescriptorRead?(
|
|
76
85
|
handle: FileHandle,
|
|
@@ -162,6 +171,10 @@ export type MemoryBackendSharedRoot = Pick<FilesystemIdentity, "shared" | "maxBy
|
|
|
162
171
|
|
|
163
172
|
export class MemoryBackend implements FilesystemBackend {
|
|
164
173
|
private readonly watchOwner: { observer?: WatchMutationObserver };
|
|
174
|
+
/** The shared slot table's unlink count, so wrappers over the same table share it. */
|
|
175
|
+
unlinkGeneration(): number {
|
|
176
|
+
return this.shared.unlinkGeneration();
|
|
177
|
+
}
|
|
165
178
|
installWatchObserver(observer: WatchMutationObserver): void {
|
|
166
179
|
if (this.watchOwner.observer && this.watchOwner.observer !== observer)
|
|
167
180
|
throw new Error("filesystem root already has a watch owner");
|
|
@@ -270,6 +283,7 @@ export class MemoryBackend implements FilesystemBackend {
|
|
|
270
283
|
publication,
|
|
271
284
|
);
|
|
272
285
|
if (this.sharedPhase !== "imported") this.shared.identities.copyFrom(previous.identities);
|
|
286
|
+
this.shared.continueUnlinks(previous);
|
|
273
287
|
this.sharedPhase = "attached";
|
|
274
288
|
}
|
|
275
289
|
/** revoked ends a wait for another owner's shared lock when the caller's request is cancelled. */
|
|
@@ -448,6 +462,9 @@ export class MemoryBackend implements FilesystemBackend {
|
|
|
448
462
|
case "resolve":
|
|
449
463
|
this.check(a, "directory");
|
|
450
464
|
return this.fs.resolve(a, b, c === true, args[3] === true);
|
|
465
|
+
case "realpath":
|
|
466
|
+
this.check(a, "directory");
|
|
467
|
+
return this.fs.realpath(a, b, c === true);
|
|
451
468
|
case "readlink":
|
|
452
469
|
this.check(a);
|
|
453
470
|
return this.fs.readlink(a);
|