1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Fine-grained reactivity for ZDeceptron.
//
// Dependencies are discovered at READ time, at runtime — never from the
// shape of the source. Spec §5.5 requires this: Svelte documented that
// compile-time dependency detection silently breaks when an expression is
// extracted into a helper function, because the dependency stops being
// visible at the declaration site. Tracking reads means refactoring cannot
// break reactivity.
//
// The model is SolidJS's: a signal write marks its readers stale and
// schedules them; a read inside a running computation registers an edge.
// There is no virtual DOM and no component re-render — a write reaches
// exactly the bindings that read it.
// **Nothing in the runtime may `for…of`, spread, or `Array.from` a `Set`
// or a `Map`. Call `forEach`.** That is a workaround for an engine bug and
// not a preference: simplifying it back reintroduces a crash.
//
// `boa_engine` 0.21.1 — the engine every test in this repository runs
// emitted JavaScript through — panics with `Object already borrowed:
// BorrowMutError` from `builtins/set/ordered_set.rs:182`, and identically
// from `builtins/map/ordered_map.rs:225`. `Set.prototype.values` hands its
// iterator a lock on the set, and that lock is released only from the
// iterator's `finalize` — so an iterator that is finished with, or
// abandoned, keeps it until the collector reaches it. `SetIterator::next`
// then holds a *borrow* of the same set across an allocation, and a
// collection landing on that allocation runs the pending `finalize`, which
// borrows the set again. boa's own comment at the panic site reads
// `TODO: try_downcast_mut`.
//
// Iterating one collection twice is therefore enough, and which program
// crashes depends only on where the allocations happen to fall — so it
// presents as a bug in whatever changed last, and fixing one call site
// only moves it to another. Restoring the spreads in this file alone, with
// the other three left converted, still failed two `algorithms` tests but
// no longer the same two: the crash follows the allocations, not the
// algorithm. `forEach` is unaffected — it keeps its lock in a Rust local
// rather than in a collectable iterator object, and it drops the borrow
// before calling back. 0.21.1 is the newest published `boa_engine`; when
// there is a newer one, check whether this still bites.
/** Every member of `set`, as an array: the `[...set]` the note forbids.
*
* The specific name is load-bearing. `zdc-bench` flattens every runtime
* file into one scope to measure it, so a top-level name here collides
* with one there, and the loser is called with the wrong arity rather
* than reported — a `snapshot` here silently became `instrument.js`'s. */
/** The computation currently running, or null at the top level. */
let listener = null;
/** Collects disposers created inside `owned`, or null outside one. */
let owner = null;
/** Depth of the current batch. Writes flush when it returns to zero. */
let batchDepth = 0;
let flushing = false;
/** Computations marked stale during the current batch. */
const pending = ;
/** Register a teardown with the scope `owned` opened, if any. */
export
/**
* A mutable value that tracks who reads it.
*
* Returns a [read, write] pair rather than an object so that reading is a
* call — which is what makes the dependency edge observable.
*/
export
/**
* A value computed from other signals, recomputed when they change.
*
* This is `from` in the language. It is lazy: the body does not run until
* something reads it, and it does not re-run until a dependency changes.
*/
export
/**
* Run a function now, and again whenever anything it read changes.
*
* Every DOM binding is one of these, which is why an update touches only
* the nodes that actually read the changed signal.
*/
export
/**
* Run `fn`, collecting every effect it creates so they can be torn down
* together.
*
* Without this a removed list row stays subscribed to whatever it read
* for the life of the page. It is not visible as wrong output — a row
* nobody writes to simply never re-runs — which is exactly why it needs
* an explicit mechanism rather than being noticed.
*/
export
/**
* Apply several writes and flush once.
*
* An event handler is implicitly batched, so `add 1 to a` followed by
* `set b to 2` repaints once rather than twice.
*/
export
/** Computations one update may run before it is a cycle. */
const STEP_LIMIT = 1e5;