@fireemu/darwin-arm64 0.55.0 → 0.57.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # @fireemu/darwin-arm64
2
2
 
3
3
  The [fireemu](https://www.npmjs.com/package/fireemu) daemon built for `darwin-arm64`
4
- (Rust target `aarch64-apple-darwin`), version 0.55.0.
4
+ (Rust target `aarch64-apple-darwin`), version 0.57.0.
5
5
 
6
6
  macOS 13 or newer on Apple silicon.
7
7
 
package/bin/fireemu CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/fireemu
3
- size: 38568240 bytes
4
- sha256: cd7ce18a96fae259af8bdb25f7c32f09e241a484ef880a39ece9415823683591
3
+ size: 38650816 bytes
4
+ sha256: 69817449ee79828e56f04f2bdf39442676c416e6409e5b169ce45def7db0fb2c
@@ -48,7 +48,7 @@ function options(value) {
48
48
  return value;
49
49
  }
50
50
 
51
- export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real', instantNanos = '0', elapsedNanos = '0'} = {}) {
51
+ export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real', instantNanos = '0', elapsedNanos = '0', following: initiallyFollowing = false} = {}) {
52
52
  if (!['real','virtual'].includes(date) || !['real','virtual'].includes(timerPolicy) ||
53
53
  (timerPolicy === 'virtual' && date !== 'virtual')) throw new TypeError('invalid runtime clock policy');
54
54
  let instant = nanos(instantNanos, 'instant');
@@ -56,6 +56,15 @@ export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real',
56
56
  let elapsed = nanos(elapsedNanos, 'elapsed');
57
57
  if (elapsed < 0n) throw new RangeError('negative timer elapsed time');
58
58
  let installed = false;
59
+ // While the daemon clock follows real time, application time runs on between its updates:
60
+ // the last update is the anchor and a monotonic reading counts the time since then.
61
+ let following = initiallyFollowing === true;
62
+ let anchor = process.hrtime.bigint();
63
+ let lastShown = -Infinity;
64
+ let autoHandle = null;
65
+ let autoDrain = null;
66
+ const live = () => following ? process.hrtime.bigint() - anchor : 0n;
67
+ const currentElapsed = () => elapsed + live();
59
68
  let sequence = 0;
60
69
  let draining = false;
61
70
  const queue = new Map();
@@ -74,10 +83,11 @@ export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real',
74
83
  }
75
84
  refresh() {
76
85
  if (!this.cancelled) {
77
- this.deadline = elapsed + this.duration;
86
+ this.deadline = currentElapsed() + this.duration;
78
87
  this.order = ++sequence;
79
88
  queue.set(this.id, this);
80
89
  handles.set(this.id, this);
90
+ arm();
81
91
  }
82
92
  return this;
83
93
  }
@@ -146,11 +156,33 @@ export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real',
146
156
  }
147
157
  }
148
158
 
149
- const now = () => epochMillis;
159
+ function now() {
160
+ if (!following) return epochMillis;
161
+ const value = milliseconds(instant + live());
162
+ lastShown = Math.max(lastShown, value);
163
+ return lastShown;
164
+ }
165
+
166
+ // Under a following clock nobody moves the clock, so due timers run on their own.
167
+ function arm() {
168
+ if (autoHandle !== null) { native.clearTimeout(autoHandle); autoHandle = null; }
169
+ if (!following || timerPolicy !== 'virtual' || !installed || queue.size === 0) return;
170
+ let earliest;
171
+ for (const handle of queue.values()) if (earliest === undefined || handle.deadline < earliest) earliest = handle.deadline;
172
+ const wait = earliest - currentElapsed();
173
+ const ms = wait <= 0n ? 0 : Number((wait + nanosPerMilli - 1n) / nanosPerMilli);
174
+ autoHandle = native.setTimeout(() => {
175
+ autoHandle = null;
176
+ if (draining) return;
177
+ autoDrain = api.runDue().catch(() => {}).finally(() => { autoDrain = null; arm(); });
178
+ }, Math.min(ms, 2_147_483_647));
179
+ autoHandle.unref?.();
180
+ }
181
+
150
182
  const VirtualDate = new Proxy(NativeDate, {
151
- apply() { return new NativeDate(epochMillis).toString(); },
183
+ apply() { return new NativeDate(now()).toString(); },
152
184
  construct(target, args, newTarget) {
153
- return Reflect.construct(target, args.length === 0 ? [epochMillis] : args, newTarget);
185
+ return Reflect.construct(target, args.length === 0 ? [now()] : args, newTarget);
154
186
  },
155
187
  get(target, key, receiver) {
156
188
  return key === 'now' ? now : Reflect.get(target, key, receiver);
@@ -165,11 +197,12 @@ export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real',
165
197
 
166
198
  function status() {
167
199
  let due = 0;
168
- for (const handle of queue.values()) if (handle.deadline <= elapsed) due++;
169
- return {pending:queue.size, due, instantNanos:instant.toString(), elapsedNanos:elapsed.toString()};
200
+ const current = currentElapsed();
201
+ for (const handle of queue.values()) if (handle.deadline <= current) due++;
202
+ return {pending:queue.size, due, instantNanos:(instant + live()).toString(), elapsedNanos:current.toString()};
170
203
  }
171
204
 
172
- return {
205
+ const api = {
173
206
  install() {
174
207
  if (installed) return;
175
208
  installed = true;
@@ -184,10 +217,12 @@ export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real',
184
217
  promises.setInterval = promiseInterval;
185
218
  syncBuiltinESMExports();
186
219
  }
220
+ arm();
187
221
  },
188
222
  restore() {
189
223
  if (!installed) return;
190
224
  installed = false;
225
+ if (autoHandle !== null) { native.clearTimeout(autoHandle); autoHandle = null; }
191
226
  if (date === 'virtual') {
192
227
  globalThis.Date = NativeDate;
193
228
  Object.defineProperty(NativeDate.prototype, 'constructor', dateConstructor);
@@ -208,13 +243,21 @@ export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real',
208
243
  ? elapsed + (next > instant ? next - instant : 0n)
209
244
  : nanos(value.elapsedNanos, 'elapsed');
210
245
  if (nextElapsed < elapsed) throw new RangeError('timer elapsed time cannot rewind');
246
+ // A tick that lands slightly behind what was already shown does not step Date back; a
247
+ // rewind (a move back by more than a second) does.
248
+ if (date === 'virtual' && nextMillis < lastShown - 1000) lastShown = -Infinity;
249
+ if (value.following !== undefined) following = value.following === true;
250
+ if (!following) lastShown = -Infinity;
211
251
  instant = next;
212
252
  epochMillis = nextMillis;
213
253
  elapsed = nextElapsed;
254
+ anchor = process.hrtime.bigint();
255
+ arm();
214
256
  return status();
215
257
  },
216
258
  async runDue(budget = 1000) {
217
259
  if (!Number.isSafeInteger(budget) || budget < 1 || budget > maxDrain) throw new RangeError('invalid timer drain budget');
260
+ if (autoDrain && !draining) await autoDrain;
218
261
  if (draining) throw new Error('timer drain is already running');
219
262
  draining = true;
220
263
  let executed = 0;
@@ -222,7 +265,7 @@ export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real',
222
265
  while (executed < budget) {
223
266
  let next;
224
267
  for (const handle of queue.values()) {
225
- if (handle.deadline <= elapsed && (!next || handle.deadline < next.deadline ||
268
+ if (handle.deadline <= currentElapsed() && (!next || handle.deadline < next.deadline ||
226
269
  (handle.deadline === next.deadline && handle.order < next.order))) next = handle;
227
270
  }
228
271
  if (!next) break;
@@ -244,4 +287,5 @@ export function createRuntimeClock({date = 'real', timers: timerPolicy = 'real',
244
287
  },
245
288
  status,
246
289
  };
290
+ return api;
247
291
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireemu/darwin-arm64",
3
- "version": "0.55.0",
3
+ "version": "0.57.0",
4
4
  "description": "The fireemu daemon for darwin-arm64",
5
5
  "homepage": "https://fireemu.github.io/fireemu/",
6
6
  "repository": {