redjs 0.3.1

Full-control Rust embedding layer over Bun's JavaScriptCore prebuilt. C ABI designed for zero-alloc C# (NativeAOT) codegen bindings.
Documentation
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
//! Explicit native DSP factories. These nodes execute Rust compiled into the host,
//! not JavaScript on a second VM. The receiving port is an EventTarget, not a
//! transferable MessagePort; only the latest state crosses into each VM pump.
use super::super::events;
use super::*;

unsafe fn to_string(g: *mut c_void, value: u64) -> Result<String, ()> {
    let value = to_js_string(g, value)?;
    read_string(g, value).ok_or(())
}

struct PortHandle {
    closed: bool,
}
struct Root {
    g: *mut c_void,
    value: u64,
}
impl Root {
    unsafe fn new(g: *mut c_void, value: u64) -> Self {
        crate::ffi::redjs_protect(g, value);
        Self { g, value }
    }
}
impl Drop for Root {
    fn drop(&mut self) {
        unsafe {
            crate::ffi::redjs_unprotect(self.g, self.value);
        }
    }
}

unsafe fn slot(g: *mut c_void, cf: *mut c_void, name: &str) -> u64 {
    if this_node_handle(g, cf).is_none() {
        return throw_type_error(g, "NativeAudioWorkletNode getter called on wrong this");
    }
    get(g, slots_of(g, cf_this(cf)), name)
}
#[crate::host_fn]
unsafe fn parameters(g: *mut c_void, cf: *mut c_void) -> u64 {
    slot(g, cf, "parameters")
}
#[crate::host_fn]
unsafe fn port(g: *mut c_void, cf: *mut c_void) -> u64 {
    slot(g, cf, "port")
}
#[crate::host_fn]
unsafe fn name(g: *mut c_void, cf: *mut c_void) -> u64 {
    slot(g, cf, "processorName")
}
#[crate::host_fn]
unsafe fn channel_count(_g: *mut c_void, _cf: *mut c_void) -> u64 {
    enc_i32(2)
}
#[crate::host_fn]
unsafe fn channel_mode(g: *mut c_void, _cf: *mut c_void) -> u64 {
    js_string(g, "explicit")
}
#[crate::host_fn]
unsafe fn interpretation(g: *mut c_void, cf: *mut c_void) -> u64 {
    slot(g, cf, "channelInterpretation")
}
#[crate::host_fn]
unsafe fn close_port(g: *mut c_void, cf: *mut c_void) -> u64 {
    let object = cf_this(cf);
    let Some(port) = host_data::<PortHandle>(g, classes(g).worklet_port_cls, object) else {
        return throw_type_error(g, "NativeAudioWorkletPort.close called on wrong this");
    };
    port.closed = true;
    define(g, object, "onmessage", NULL, 0);
    // Drop listener/owner edges, including callbacks that close over the node.
    glue::rjs_define(g, object, super::super::state(g).s_listeners, UNDEF, 0);
    glue::rjs_define(g, object, classes(g).s_audio, UNDEF, 0);
    UNDEF
}
#[crate::host_fn]
unsafe fn start_port(g: *mut c_void, cf: *mut c_void) -> u64 {
    if host_data::<PortHandle>(g, classes(g).worklet_port_cls, cf_this(cf)).is_none() {
        return throw_type_error(g, "NativeAudioWorkletPort.start called on wrong this");
    }
    UNDEF // Native state notifications start immediately, including addEventListener.
}
#[crate::host_fn]
unsafe fn post_message(g: *mut c_void, _cf: *mut c_void) -> u64 {
    super::super::domexception::throw(
        g,
        "NotSupportedError",
        "Native worklet ports receive DSP state only; update the node's AudioParams instead",
    )
}

pub(super) unsafe fn install(
    g: *mut c_void,
    parent: u64,
) -> (Class, Class, crate::capi::JSClassRef) {
    let node = define_class(
        g,
        &ClassSpec {
            name: "NativeAudioWorkletNode",
            arity: 0,
            construct: None,
            parent_proto: parent,
            methods: &[],
            getters: &[
                ("parameters", parameters),
                ("port", port),
                ("processorName", name),
                ("channelCount", channel_count),
                ("channelCountMode", channel_mode),
                ("channelInterpretation", interpretation),
            ],
            accessors: &[],
        },
    );
    let port_cls = make_host_class::<PortHandle>("NativeAudioWorkletPort");
    let port = define_class(
        g,
        &ClassSpec {
            name: "NativeAudioWorkletPort",
            arity: 0,
            construct: None,
            parent_proto: super::super::state(g).event_target.proto,
            methods: &[
                ("close", 0, close_port),
                ("start", 0, start_port),
                ("postMessage", 1, post_message),
            ],
            getters: &[],
            accessors: &[],
        },
    );
    (node, port, port_cls)
}

unsafe fn option(g: *mut c_void, options: u64, key: &str) -> Result<u64, ()> {
    if options == UNDEF || options == NULL {
        Ok(UNDEF)
    } else {
        try_get(g, options, key)
    }
}
unsafe fn validate(g: *mut c_void, options: u64) -> Result<bool, ()> {
    if options != UNDEF && options != NULL && glue::rjs_kind(g, options) < 8 {
        throw_type_error(g, "Native audio worklet options must be an object");
        return Err(());
    }
    if option(g, options, "processorOptions")? != UNDEF {
        super::super::domexception::throw(
            g,
            "NotSupportedError",
            "Native DSP has no processorOptions; use parameterData/AudioParams",
        );
        return Err(());
    }
    for (key, expected) in [
        ("numberOfInputs", 1.0),
        ("numberOfOutputs", 1.0),
        ("channelCount", 2.0),
    ] {
        let value = option(g, options, key)?;
        if value != UNDEF && to_number(g, value)? != expected {
            super::super::domexception::throw(
                g,
                "NotSupportedError",
                "Native DSP requires one stereo input and one stereo output",
            );
            return Err(());
        }
    }
    let counts = option(g, options, "outputChannelCount")?;
    if counts != UNDEF {
        let _counts_root = is_cell(counts).then(|| Root::new(g, counts));
        let len = try_get(g, counts, "length")?;
        let _len_root = is_cell(len).then(|| Root::new(g, len));
        let len = to_number(g, len)?;
        let first = try_get(g, counts, "0")?;
        let _first_root = is_cell(first).then(|| Root::new(g, first));
        if len != 1.0 || to_number(g, first)? != 2.0 {
            super::super::domexception::throw(
                g,
                "NotSupportedError",
                "Native DSP outputChannelCount must be [2]",
            );
            return Err(());
        }
    }
    let mode = option(g, options, "channelCountMode")?;
    if mode != UNDEF && to_string(g, mode)? != "explicit" {
        super::super::domexception::throw(
            g,
            "NotSupportedError",
            "Native DSP channelCountMode is explicit",
        );
        return Err(());
    }
    let interpretation = option(g, options, "channelInterpretation")?;
    if interpretation == UNDEF {
        return Ok(false);
    }
    match to_string(g, interpretation)?.as_str() {
        "speakers" => Ok(false),
        "discrete" => Ok(true),
        _ => {
            throw_type_error(
                g,
                "Native DSP channelInterpretation must be speakers or discrete",
            );
            Err(())
        }
    }
}

#[crate::host_fn]
pub(super) unsafe fn load(g: *mut c_void, cf: *mut c_void) -> u64 {
    let Some(engine) = this_engine_handle(g, cf) else {
        return throw_type_error(
            g,
            "AudioContext.loadNativeAudioWorklet called on wrong this",
        );
    };
    let Ok(name) = to_string(g, cf_arg(cf, 0)) else {
        return UNDEF;
    };
    let Some(kind) = NativeKind::from_name(&name) else {
        return super::super::domexception::throw(g, "NotSupportedError", "Unknown native audio processor; available: peak-meter-stereo, peak-meter-mono, stereo-to-mono, input-gate");
    };
    let options = cf_arg(cf, 1);
    let Ok(discrete) = validate(g, options) else {
        return UNDEF;
    };
    let shared = ArcGc::new(NativeShared::new(kind));
    let jsparams: &[(&str, u8, f64)] = match kind {
        NativeKind::StereoToMono => &[("enabled", P_NATIVE_ENABLED, 1.0)],
        NativeKind::InputGate => &[
            ("enabled", P_NATIVE_ENABLED, 0.0),
            ("threshold", P_NATIVE_THRESHOLD, -40.0),
        ],
        _ => &[],
    };
    let Ok(data) = option(g, options, "parameterData") else {
        return UNDEF;
    };
    let _data_root = is_cell(data).then(|| Root::new(g, data));
    let mut values = Vec::with_capacity(jsparams.len());
    for &(name, param, initial) in jsparams {
        let Ok(value) = option(g, data, name) else {
            return UNDEF;
        };
        let number = if value == UNDEF {
            initial
        } else {
            let Ok(value) = to_number(g, value) else {
                return UNDEF;
            };
            if !value.is_finite() {
                return throw_type_error(g, "Native audio parameters must be finite");
            }
            value
        };
        let number = if param == P_NATIVE_ENABLED {
            number.clamp(0.0, 1.0)
        } else {
            number.clamp(-100.0, 0.0)
        };
        if param == P_NATIVE_ENABLED {
            shared.set_enabled(number as f32);
        } else {
            shared.set_threshold(number as f32);
        }
        values.push((name, param, number));
    }
    let c = classes(g);
    let object = create_node_on(
        g,
        engine,
        Params::Native {
            kind,
            shared,
            discrete,
        },
        c.worklet.proto,
        &values,
    );
    if !is_cell(object) {
        return object;
    }
    let _root = Root::new(g, object);
    let slots = slots_of(g, object);
    let port = host_create(
        g,
        c.worklet_port_cls,
        c.worklet_port.proto,
        PortHandle { closed: false },
    );
    define(g, slots, "port", port, 0);
    // Keeping only a receiving port alive must also keep its native node alive.
    let owner = new_object(g, UNDEF);
    glue::rjs_define(g, port, c.s_audio, owner, 0);
    define(g, owner, "owner", object, 0);
    define(g, port, "onmessage", NULL, 0);
    define(g, slots, "processorName", js_string(g, kind.name()), 0);
    define(
        g,
        slots,
        "channelInterpretation",
        js_string(g, if discrete { "discrete" } else { "speakers" }),
        0,
    );
    define(g, object, "onprocessorerror", NULL, 0);
    let mut map = UNDEF;
    if glue::rjs_construct(
        g,
        get(g, glue::rjs_global(g), "Map"),
        core::ptr::null(),
        0,
        &mut map,
    ) != 0
    {
        return UNDEF;
    }
    define(g, slots, "parameters", map, 0);
    for &(name, _, _) in &values {
        let args = [js_string(g, name), get(g, slots, name)];
        if let Err(error) = call(g, get(g, map, "set"), map, &args) {
            glue::rjs_throw(g, error);
            return UNDEF;
        }
    }
    if let Some(handle) = host_data::<NodeHandle>(g, c.node_cls, object) {
        if let Some(rec) = glob().lock().unwrap().nodes.get_mut(&handle.0) {
            rec.worklet_obj = object;
        }
    }
    object
}

pub(super) unsafe fn dispatch_message(g: *mut c_void, object: u64, message: NativeMessage) {
    let c = classes(g);
    let Some(handle) = host_data::<NodeHandle>(g, c.node_cls, object) else {
        return;
    };
    // Another listener in this batch may have closed the context.
    let live = {
        let gl = glob().lock().unwrap();
        gl.nodes
            .get(&handle.0)
            .and_then(|n| gl.engines.get(&n.engine))
            .is_some_and(|e| e.g == g as usize && e.state != ST_CLOSED)
    };
    if !live {
        return;
    }
    let port = get(g, slots_of(g, object), "port");
    if host_data::<PortHandle>(g, c.worklet_port_cls, port).is_none_or(|p| p.closed) {
        return;
    }
    let event = events::new_trusted_event(g, "message");
    let _event_root = Root::new(g, event);
    let value = match message {
        NativeMessage::Stereo(levels) => {
            let mut array = UNDEF;
            if crate::ffi::redjs_typedarray_create(g, 8 /* f32 */, 2, &mut array) != 0 {
                return;
            }
            // Attach immediately; the event is rooted through listener reentry and GC.
            define(g, event, "data", array, 0);
            set_i(g, array, 0, enc_f64(levels[0] as f64));
            set_i(g, array, 1, enc_f64(levels[1] as f64));
            array
        }
        NativeMessage::Mono(level) => enc_f64(level as f64),
        NativeMessage::Gate(is_open) => {
            let data = new_object(g, UNDEF);
            define(g, event, "data", data, 0);
            define(g, data, "isOpen", enc_bool(is_open), 0);
            data
        }
    };
    define(g, event, "data", value, 0);
    events::dispatch(g, port, event);
}

#[cfg(test)]
mod tests {
    use crate::webapi::testing::*;
    #[test]
    fn native_factory_has_explicit_shape_parameters_and_errors() {
        let c = ctx();
        ok(
            &c,
            r#"(() => {
          const a = new AudioContext();
          const n = a.loadNativeAudioWorklet('input-gate', {parameterData:{enabled:1,threshold:-25}});
          const s = a.loadNativeAudioWorklet('stereo-to-mono');
          const good = n instanceof AudioNode && n instanceof NativeAudioWorkletNode &&
            n.port instanceof EventTarget && n.port === n.port && n.parameters === n.parameters &&
            n.parameters.get('enabled') instanceof AudioParam && n.parameters.get('enabled').value === 1 &&
            n.parameters.get('threshold').value === -25 && s.parameters.get('enabled').value === 1 &&
            n.numberOfInputs === 1 && n.numberOfOutputs === 1 && n.processorName === 'input-gate' &&
            n.channelCount === 2 && n.channelCountMode === 'explicit' && n.channelInterpretation === 'speakers' &&
            typeof a.audioWorklet === 'undefined' && typeof AudioWorkletNode === 'undefined';
          let errors = 0;
          for (const f of [() => a.loadNativeAudioWorklet('unknown'),
            () => a.loadNativeAudioWorklet('input-gate',{outputChannelCount:[1]}),
            () => n.port.postMessage({}),
            () => a.loadNativeAudioWorklet('input-gate',{parameterData:{threshold:NaN}}),
            () => {n.parameters.get('threshold').value=Infinity;},
            () => n.parameters.get('enabled').setValueAtTime(NaN,0),
            () => a.loadNativeAudioWorklet('input-gate',{processorOptions:{}})]) {
            try { f(); } catch { errors++; }
          }
          n.parameters.get('threshold').setValueAtTime(-30,a.currentTime);
          n.port.close(); n.port.close(); a.close();
          try { a.loadNativeAudioWorklet('input-gate'); } catch { errors++; }
          return good && errors === 8;
        })()"#,
        );
    }
    #[test]
    fn telemetry_is_a_real_event_with_gc_owned_data_and_reentrant_close() {
        let c = ctx();
        s(
            &c,
            r#"globalThis.__ctx = new AudioContext();
          globalThis.__n = __ctx.loadNativeAudioWorklet('peak-meter-stereo');
          globalThis.__second = __ctx.loadNativeAudioWorklet('peak-meter-mono');
          globalThis.__seen=[];
          __n.port.addEventListener('message', e => { __seen.push(e); __ctx.close(); });
          __second.port.onmessage=() => __seen.push('late'); 'ok'"#,
        );
        let first = c.eval("__n").unwrap().0;
        let second = c.eval("__second").unwrap().0;
        unsafe {
            super::dispatch_message(c.raw(), first, super::NativeMessage::Stereo([0.25, 0.75]));
            super::dispatch_message(c.raw(), second, super::NativeMessage::Mono(1.0));
        }
        c.gc();
        ok(&c, "__seen.length===1 && __seen[0] instanceof Event && __seen[0].data instanceof Float32Array && __seen[0].data[0]===0.25 && __seen[0].data[1]===0.75 && __seen[0].target===__n.port");
    }
    #[test]
    fn port_close_suppresses_late_state_and_releases_owner_edge() {
        let c = ctx();
        s(&c, "globalThis.__ctx=new AudioContext();globalThis.__n=__ctx.loadNativeAudioWorklet('input-gate');globalThis.__count=0;__n.port.onmessage=()=>__count++;'ok'");
        let object = c.eval("__n").unwrap().0;
        unsafe {
            super::dispatch_message(c.raw(), object, super::NativeMessage::Gate(true));
        }
        ok(&c, "__count===1");
        s(&c, "__n.port.close();__n.port.onmessage=()=>__count++;'ok'");
        unsafe {
            super::dispatch_message(c.raw(), object, super::NativeMessage::Gate(false));
        }
        ok(&c, "__count===1");
        s(&c, "__ctx.close();'ok'");
    }
    #[test]
    fn real_graph_native_gate_meter_and_parameter_automation() {
        let c = ctx();
        s(
            &c,
            r#"globalThis.__ctx = new AudioContext();
          globalThis.__osc = __ctx.createOscillator(); __osc.frequency.value=240;
          globalThis.__gain=__ctx.createGain(); __gain.gain.value=0.25;
          globalThis.__gate=__ctx.loadNativeAudioWorklet('input-gate',{parameterData:{enabled:1,threshold:-20}});
          globalThis.__mono=__ctx.loadNativeAudioWorklet('stereo-to-mono');
          globalThis.__meter=__ctx.loadNativeAudioWorklet('peak-meter-stereo');
          globalThis.__an=__ctx.createAnalyser(); __an.fftSize=1024;
          globalThis.__messages=[];globalThis.__states=[];
          __meter.port.onmessage=e=>__messages.push(Array.from(e.data));
          __gate.port.onmessage=e=>__states.push(e.data.isOpen);
          __osc.connect(__gain).connect(__gate).connect(__mono).connect(__an);
          __mono.connect(__meter);__osc.start();'ok'"#,
        );
        // No connection to destination: this probe never plays a tone to speakers.
        let running = super::super::jsc_tests::pump_for(&c, 150);
        if running {
            // Each wait is in the context's time, not wall time. The gate's
            // 150 ms hold counts samples, and a CI VM's virtual output renders
            // in bursts and can fall behind real time: a fixed 260 ms window
            // once ended with the gate still open on a CI Mac. Each change is
            // timed by the clock read AFTER it, so no frame from then on can
            // have been rendered with the old value.
            use super::super::jsc_tests::{analyser_rms, pump_until_rendered};
            let rendered = |t: f64| {
                assert!(
                    pump_until_rendered(&c, t, 3000),
                    "the audio clock did not reach {t} s in 3 s (at {} s)",
                    s(&c, "__ctx.currentTime")
                )
            };
            let now = || s(&c, "__ctx.currentTime").parse::<f64>().unwrap();
            // The meter's envelope settles within ~30 ms of signal, and the
            // osc was already started when this clock was read.
            rendered(now() + 0.2);
            ok(&c, "__messages.length>0 && __messages.at(-1)[0]>0.2 && __messages.at(-1)[0]<0.3 && __states.includes(true)");
            s(
                &c,
                "__gate.parameters.get('threshold').setValueAtTime(0,__ctx.currentTime);'ok'",
            );
            // The 150 ms hold, the quantum that closes it, the analyser's
            // 1024-frame window (~23 ms) of silence after it, and some slack.
            rendered(now() + 0.3);
            ok(&c, "__states.at(-1)===false");
            let rms = analyser_rms(&c, "__an");
            assert!(rms < 1e-5, "closed gate leaked PCM: {rms}");
            s(&c, "__gate.parameters.get('enabled').value=0;'ok'");
            // The analyser's window of passed-through signal, and some slack.
            rendered(now() + 0.15);
            assert!(analyser_rms(&c, "__an") > 0.1);
            eprintln!("[native-worklet-probe] device-backed gate/mono/meter/automation passed");
        } else {
            eprintln!("[native-worklet-probe] no hardware clock; pure DSP tests cover PCM");
        }
        s(
            &c,
            "__meter.port.close();__gate.port.close();__osc.stop();__ctx.close();'ok'",
        );
    }

    #[test]
    fn temporary_option_dictionaries_survive_gc_in_getters_and_coercions() {
        let c = ctx();
        #[crate::host_fn]
        unsafe fn collect(g: *mut super::c_void, _cf: *mut super::c_void) -> u64 {
            crate::ffi::redjs_gc(g, 0);
            super::UNDEF
        }
        unsafe {
            let f = super::make_fn(c.raw(), "forceGC", 0, collect);
            super::define(c.raw(), crate::glue::rjs_global(c.raw()), "forceGC", f, 0);
        }
        ok(
            &c,
            r#"(() => {
          const a=new AudioContext();
          for(let i=0;i<20;i++) {
            const node=a.loadNativeAudioWorklet('input-gate', {
              get parameterData(){ return {
                enabled:{valueOf(){forceGC();return 1;}},
                get threshold(){ forceGC();return -25; }
              }; },
              get outputChannelCount(){return {
                get length(){forceGC();return {valueOf(){forceGC();return 1;}};},
                get 0(){forceGC();return {valueOf(){forceGC();return 2;}};}
              };}
            });
            if(node.parameters.get('enabled').value!==1 || node.parameters.get('threshold').value!==-25) return false;
            node.port.close();node.disconnect();
          }
          a.close();return true;
        })()"#,
        );
    }
    #[test]
    fn finite_double_parameters_clamp_before_float_narrowing() {
        let c = ctx();
        ok(
            &c,
            r#"(() => { const a=new AudioContext();const n=a.loadNativeAudioWorklet('input-gate');
          const t=n.parameters.get('threshold'),e=n.parameters.get('enabled');
          t.value=-1e300;e.value=1e300;const direct=t.value===-100&&e.value===1;
          t.setValueAtTime(1e300,a.currentTime);e.setValueAtTime(-1e300,a.currentTime);
          const scheduled=t.value===0&&e.value===0;a.close();return direct&&scheduled; })()"#,
        );
    }
    #[test]
    fn options_getter_exceptions_propagate_before_allocating_a_node() {
        let c = ctx();
        ok(
            &c,
            r#"(() => { const a=new AudioContext(); const marker={}; let caught=false;
          try { a.loadNativeAudioWorklet('input-gate',{get parameterData(){throw marker;}}); }
          catch(e) {caught=e===marker;} a.close();return caught; })()"#,
        );
    }
}