boa_engine 0.21.1

Boa is a Javascript lexer, parser and compiler written in Rust. Currently, it has support for some of the language.
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
use boa_gc::{Finalize, Trace};

use super::Array;
use crate::builtins::AsyncFromSyncIterator;
use crate::builtins::iterable::IteratorRecord;
use crate::builtins::promise::ResolvingFunctions;
use crate::native_function::{CoroutineState, NativeCoroutine};
use crate::object::{JsFunction, JsPromise};
use crate::{
    Context, JsArgs, JsError, JsNativeError, JsObject, JsResult, JsSymbol, JsValue, js_string,
};
use std::cell::Cell;

impl Array {
    /// [`Array.fromAsync ( asyncItems [ , mapfn [ , thisArg ] ] )`][spec]
    ///
    /// The `Array.fromAsync()` static method creates a new,
    /// shallow-copied Array instance from a list or iterator of Promise-like values.
    ///
    /// More information:
    ///  - [ECMAScript reference][spec]
    ///
    /// [spec]: https://tc39.es/proposal-array-from-async/#sec-array.fromAsync
    #[allow(clippy::unnecessary_wraps)]
    pub(crate) fn from_async(
        this: &JsValue,
        args: &[JsValue],
        context: &mut Context,
    ) -> JsResult<JsValue> {
        // 1. Let C be the this value.
        // 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
        let (promise, resolvers) = JsPromise::new_pending(context);

        let async_items = args.get_or_undefined(0);
        let mapfn = args.get_or_undefined(1);
        let this_arg = args.get_or_undefined(2).clone();

        // 3. Let fromAsyncClosure be a new Abstract Closure with no parameters that captures C, mapfn, and thisArg and
        //    performs the following steps when called:
        // 4. Perform AsyncFunctionStart(promiseCapability, fromAsyncClosure).
        // NOTE: We avoid putting more state onto the coroutines by preprocessing all we can before allocating
        //       the coroutines.
        let result: JsResult<()> = (|| {
            // a. If mapfn is undefined, let mapping be false.
            let mapfn = if mapfn.is_undefined() {
                None
            } else {
                // b. Else,
                //     i. If IsCallable(mapfn) is false, throw a TypeError exception.
                let Some(callable) = mapfn.as_callable() else {
                    return Err(JsNativeError::typ()
                        .with_message("Array.fromAsync: mapping function must be callable")
                        .into());
                };
                //     ii. Let mapping be true.
                Some(JsFunction::from_object_unchecked(callable))
            };

            // c. Let usingAsyncIterator be ? GetMethod(asyncItems, @@asyncIterator).
            // d. If usingAsyncIterator is undefined, then
            //     i. Let usingSyncIterator be ? GetMethod(asyncItems, @@iterator).
            // e. Let iteratorRecord be undefined.
            // f. If usingAsyncIterator is not undefined, then
            let iterator_record = if let Some(method) =
                async_items.get_method(JsSymbol::async_iterator(), context)?
            {
                // i. Set iteratorRecord to ? GetIterator(asyncItems, async, usingAsyncIterator).
                async_items.get_iterator_from_method(&method, context)?
            }
            // g. Else if usingSyncIterator is not undefined, then
            else if let Some(method) = async_items.get_method(JsSymbol::iterator(), context)? {
                // i. Set iteratorRecord to ? CreateAsyncFromSyncIterator(GetIterator(asyncItems, sync, usingSyncIterator)).
                AsyncFromSyncIterator::create(
                    async_items.get_iterator_from_method(&method, context)?,
                    context,
                )
            }
            // i. Else,
            else {
                // i. NOTE: asyncItems is neither an AsyncIterable nor an Iterable so assume it is an array-like object.
                // ii. Let arrayLike be ! ToObject(asyncItems).
                let array_like = async_items.to_object(context)?;

                // iii. Let len be ? LengthOfArrayLike(arrayLike).
                let len = array_like.length_of_array_like(context)?;
                // iv. If IsConstructor(C) is true, then
                let a = if let Some(c) = this.as_constructor() {
                    // 1. Let A be ? Construct(C, « 𝔽(len) »).
                    c.construct(&[len.into()], None, context)?
                }
                // v. Else,
                else {
                    // 1. Let A be ? ArrayCreate(len).
                    Array::array_create(len, None, context)?
                };

                let coroutine_state = (
                    GlobalState {
                        mapfn,
                        this_arg,
                        resolvers: resolvers.clone(),
                    },
                    Cell::new(Some(ArrayLikeStateMachine::LoopStart {
                        array_like,
                        a,
                        len,
                        // iii. Let k be 0.
                        k: 0,
                    })),
                );

                // Try to run the coroutine once to see if it finishes early.
                // This avoids allocating a new coroutine that will immediately finish.
                // Spec continues on `from_array_like`...
                if let CoroutineState::Yielded(value) =
                    from_array_like(Ok(JsValue::undefined()), &coroutine_state, context)
                {
                    // Coroutine yielded. We need to allocate it for a future execution.
                    JsPromise::resolve(value, context).await_native(
                        NativeCoroutine::from_copy_closure_with_captures(
                            from_array_like,
                            coroutine_state,
                        ),
                        context,
                    );
                }

                return Ok(());
            };

            // h. If iteratorRecord is not undefined, then

            // i. If IsConstructor(C) is true, then
            let a = if let Some(c) = this.as_constructor() {
                // 1. Let A be ? Construct(C).
                c.construct(&[], None, context)?
            }
            // ii. Else,
            else {
                // 1. Let A be ! ArrayCreate(0).
                Array::array_create(0, None, context)?
            };

            let coroutine_state = (
                GlobalState {
                    mapfn,
                    this_arg,
                    resolvers: resolvers.clone(),
                },
                Cell::new(Some(AsyncIteratorStateMachine::LoopStart {
                    // vi. Let k be 0.
                    k: 0,
                    a,
                    iterator_record,
                })),
            );

            // Try to run the coroutine once to see if it finishes early.
            // This avoids allocating a new coroutine that will immediately finish.
            // Spec continues on `from_async_iterator`...
            if let CoroutineState::Yielded(value) =
                from_async_iterator(Ok(JsValue::undefined()), &coroutine_state, context)
            {
                JsPromise::resolve(value, context).await_native(
                    NativeCoroutine::from_copy_closure_with_captures(
                        from_async_iterator,
                        coroutine_state,
                    ),
                    context,
                );
            }

            Ok(())
        })();

        // AsyncFunctionStart ( promiseCapability, asyncFunctionBody )
        // https://tc39.es/ecma262/#sec-async-functions-abstract-operations-async-function-start
        // ->
        // AsyncBlockStart ( promiseCapability, asyncBody, asyncContext )
        // https://tc39.es/ecma262/#sec-asyncblockstart

        // i. Assert: result is a throw completion.
        if let Err(err) = result {
            // ii. Perform ! Call(promiseCapability.[[Reject]], undefined, « result.[[Value]] »).
            resolvers
                .reject
                .call(&JsValue::undefined(), &[err.to_opaque(context)], context)
                .expect("resolving functions cannot fail");
        }

        // 5. Return promiseCapability.[[Promise]].
        Ok(promise.into())
    }
}

#[derive(Trace, Finalize)]
struct GlobalState {
    mapfn: Option<JsFunction>,
    this_arg: JsValue,
    resolvers: ResolvingFunctions,
}

#[derive(Trace, Finalize)]
#[boa_gc(unsafe_no_drop)]
enum AsyncIteratorStateMachine {
    LoopStart {
        a: JsObject,
        k: u64,
        iterator_record: IteratorRecord,
    },
    LoopContinue {
        a: JsObject,
        k: u64,
        iterator_record: IteratorRecord,
    },
    LoopEnd {
        a: JsObject,
        k: u64,
        iterator_record: IteratorRecord,
        mapped_value: Option<JsResult<JsValue>>,
    },
    AsyncIteratorCloseStart {
        err: JsError,
        iterator: JsObject,
    },
    AsyncIteratorCloseEnd {
        err: JsError,
    },
}

/// Part of [`Array.fromAsync ( asyncItems [ , mapfn [ , thisArg ] ] )`][<https://tc39.es/proposal-array-from-async/#sec-array.fromAsync>].
fn from_async_iterator(
    mut result: JsResult<JsValue>,
    (global_state, state_machine): &(GlobalState, Cell<Option<AsyncIteratorStateMachine>>),
    context: &mut Context,
) -> CoroutineState {
    let result = (|| {
        let Some(mut sm) = state_machine.take() else {
            return Ok(CoroutineState::Done);
        };

        // iv. Repeat,
        loop {
            match sm {
                AsyncIteratorStateMachine::LoopStart {
                    a,
                    k,
                    iterator_record,
                } => {
                    // Inverted conditional makes for a simpler code.
                    if k < 2u64.pow(53) - 1 {
                        // 2. Let Pk be ! ToString(𝔽(k)).
                        // 3. Let nextResult be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]).
                        let next_result = iterator_record.next_method().call(
                            &iterator_record.iterator().clone().into(),
                            &[],
                            context,
                        )?;

                        state_machine.set(Some(AsyncIteratorStateMachine::LoopContinue {
                            a,
                            k,
                            iterator_record,
                        }));

                        // 4. Set nextResult to ? Await(nextResult).
                        return Ok(CoroutineState::Yielded(next_result));
                    }

                    // 1. If k ≥ 2**53 - 1, then

                    // a. Let error be ThrowCompletion(a newly created TypeError object).
                    // b. Return ? AsyncIteratorClose(iteratorRecord, error).
                    sm = AsyncIteratorStateMachine::AsyncIteratorCloseStart {
                        err: JsNativeError::typ()
                            .with_message(
                                "Array.fromAsync: \
                                            reached the maximum number of elements in an array \
                                            (2^53 - 1)",
                            )
                            .into(),
                        iterator: iterator_record.iterator().clone(),
                    };
                }
                AsyncIteratorStateMachine::LoopContinue {
                    a,
                    k,
                    mut iterator_record,
                } => {
                    // `result` is `Await(nextResult)`.
                    let result = std::mem::replace(&mut result, Ok(JsValue::undefined()));

                    // 5. If nextResult is not an Object, throw a TypeError exception.
                    // Implicit on the call to `update_result`.
                    iterator_record.update_result(result?, context)?;

                    // 6. Let done be ? IteratorComplete(nextResult).
                    // 7. If done is true,
                    if iterator_record.done() {
                        // a. Perform ? Set(A, "length", 𝔽(k), true).
                        a.set(js_string!("length"), k, true, context)?;

                        // b. Return Completion Record { [[Type]]: return, [[Value]]: A, [[Target]]: empty }.
                        // AsyncFunctionStart ( promiseCapability, asyncFunctionBody )
                        // https://tc39.es/ecma262/#sec-async-functions-abstract-operations-async-function-start
                        // ->
                        // AsyncBlockStart ( promiseCapability, asyncBody, asyncContext )
                        // https://tc39.es/ecma262/#sec-asyncblockstart

                        // g. Else if result is a return completion, then
                        //        i. Perform ! Call(promiseCapability.[[Resolve]], undefined, « result.[[Value]] »).
                        global_state
                            .resolvers
                            .resolve
                            .call(&JsValue::undefined(), &[a.into()], context)
                            .expect("resolving functions cannot fail");

                        return Ok(CoroutineState::Done);
                    }

                    // 8. Let nextValue be ? IteratorValue(nextResult).
                    let next_value = iterator_record.value(context)?;
                    // 9. If mapping is true, then
                    if let Some(mapfn) = &global_state.mapfn {
                        // a. Let mappedValue be Call(mapfn, thisArg, « nextValue, 𝔽(k) »).
                        // b. IfAbruptCloseAsyncIterator(mappedValue, iteratorRecord).
                        // https://tc39.es/proposal-array-from-async/#sec-ifabruptcloseasynciterator
                        let mapped_value = match mapfn.call(
                            &global_state.this_arg,
                            &[next_value, k.into()],
                            context,
                        ) {
                            // 1. If value is an abrupt completion, then
                            Err(err) => {
                                // a. Perform ? AsyncIteratorClose(iteratorRecord, value).
                                // b. Return value.
                                sm = AsyncIteratorStateMachine::AsyncIteratorCloseStart {
                                    err,
                                    iterator: iterator_record.iterator().clone(),
                                };
                                continue;
                            }
                            // 2. Else if value is a Completion Record, set value to value.[[Value]].
                            Ok(value) => value,
                        };
                        state_machine.set(Some(AsyncIteratorStateMachine::LoopEnd {
                            a,
                            k,
                            iterator_record,
                            mapped_value: None,
                        }));
                        // c. Set mappedValue to Await(mappedValue).
                        return Ok(CoroutineState::Yielded(mapped_value));
                    }

                    sm = AsyncIteratorStateMachine::LoopEnd {
                        a,
                        k,
                        iterator_record,
                        // 10. Else, let mappedValue be nextValue.
                        mapped_value: Some(Ok(next_value)),
                    }
                }
                AsyncIteratorStateMachine::LoopEnd {
                    a,
                    k,
                    iterator_record,
                    mapped_value,
                } => {
                    // Either awaited `mappedValue` or directly set `mappedValue` to `nextValue`.
                    let result = std::mem::replace(&mut result, Ok(JsValue::undefined()));

                    // d. IfAbruptCloseAsyncIterator(mappedValue, iteratorRecord).
                    // https://tc39.es/proposal-array-from-async/#sec-ifabruptcloseasynciterator
                    let mapped_value = match mapped_value.unwrap_or(result) {
                        // 1. If value is an abrupt completion, then
                        Err(err) => {
                            // a. Perform ? AsyncIteratorClose(iteratorRecord, value).
                            // b. Return value.
                            sm = AsyncIteratorStateMachine::AsyncIteratorCloseStart {
                                err,
                                iterator: iterator_record.iterator().clone(),
                            };
                            continue;
                        }
                        // 2. Else if value is a Completion Record, set value to value.[[Value]].
                        Ok(value) => value,
                    };

                    // 11. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, mappedValue).
                    sm = if let Err(err) = a.create_data_property_or_throw(k, mapped_value, context)
                    {
                        // 12. If defineStatus is an abrupt completion, return ? AsyncIteratorClose(iteratorRecord, defineStatus).
                        AsyncIteratorStateMachine::AsyncIteratorCloseStart {
                            err,
                            iterator: iterator_record.iterator().clone(),
                        }
                    } else {
                        AsyncIteratorStateMachine::LoopStart {
                            a,
                            // 13. Set k to k + 1.
                            k: k + 1,
                            iterator_record,
                        }
                    };
                }
                // AsyncIteratorClose ( iteratorRecord, completion )
                // https://tc39.es/ecma262/#sec-asynciteratorclose
                // Simplified for only error completions.
                AsyncIteratorStateMachine::AsyncIteratorCloseStart { err, iterator } => {
                    // 1. Assert: iteratorRecord.[[Iterator]] is an Object.
                    // 2. Let iterator be iteratorRecord.[[Iterator]].
                    // 3. Let innerResult be Completion(GetMethod(iterator, "return")).
                    // 4. If innerResult is a normal completion, then
                    //     a. Let return be innerResult.[[Value]].
                    //     b. If return is undefined, return ? completion.
                    //     c. Set innerResult to Completion(Call(return, iterator)).
                    //     d. If innerResult is a normal completion, set innerResult to Completion(Await(innerResult.[[Value]])).
                    // 5. If completion is a throw completion, return ? completion.
                    let Ok(Some(ret)) = iterator.get_method(js_string!("return"), context) else {
                        return Err(err);
                    };

                    let Ok(value) = ret.call(&iterator.into(), &[], context) else {
                        return Err(err);
                    };

                    state_machine.set(Some(AsyncIteratorStateMachine::AsyncIteratorCloseEnd {
                        err,
                    }));
                    return Ok(CoroutineState::Yielded(value));
                }
                AsyncIteratorStateMachine::AsyncIteratorCloseEnd { err } => {
                    // Awaited `innerResult.[[Value]]`.
                    // Only need to return the original error.
                    return Err(err);
                }
            }
        }
    })();

    // AsyncFunctionStart ( promiseCapability, asyncFunctionBody )
    // https://tc39.es/ecma262/#sec-async-functions-abstract-operations-async-function-start
    // ->
    // AsyncBlockStart ( promiseCapability, asyncBody, asyncContext )
    // https://tc39.es/ecma262/#sec-asyncblockstart
    match result {
        Ok(cont) => cont,

        // i. Assert: result is a throw completion.
        Err(err) => {
            // ii. Perform ! Call(promiseCapability.[[Reject]], undefined, « result.[[Value]] »).
            global_state
                .resolvers
                .reject
                .call(&JsValue::undefined(), &[err.to_opaque(context)], context)
                .expect("resolving functions cannot fail");
            CoroutineState::Done
        }
    }
}

#[derive(Trace, Finalize)]
#[boa_gc(unsafe_no_drop)]
#[allow(clippy::enum_variant_names)]
enum ArrayLikeStateMachine {
    LoopStart {
        array_like: JsObject,
        a: JsObject,
        len: u64,
        k: u64,
    },
    LoopContinue {
        array_like: JsObject,
        a: JsObject,
        len: u64,
        k: u64,
    },
    LoopEnd {
        array_like: JsObject,
        a: JsObject,
        len: u64,
        k: u64,
        mapped_value: Option<JsValue>,
    },
}

/// Part of [`Array.fromAsync ( asyncItems [ , mapfn [ , thisArg ] ] )`][<https://tc39.es/proposal-array-from-async/#sec-array.fromAsync>].
fn from_array_like(
    mut result: JsResult<JsValue>,
    (global_state, state_machine): &(GlobalState, Cell<Option<ArrayLikeStateMachine>>),
    context: &mut Context,
) -> CoroutineState {
    let result: JsResult<_> = (|| {
        let Some(mut sm) = state_machine.take() else {
            return Ok(CoroutineState::Done);
        };

        loop {
            match sm {
                ArrayLikeStateMachine::LoopStart {
                    array_like,
                    a,
                    len,
                    k,
                } => {
                    // vii. Repeat, while k < len,
                    if k >= len {
                        // viii. Perform ? Set(A, "length", 𝔽(len), true).
                        a.set(js_string!("length"), len, true, context)?;

                        // ix. Return Completion Record { [[Type]]: return, [[Value]]: A, [[Target]]: empty }.

                        // AsyncFunctionStart ( promiseCapability, asyncFunctionBody )
                        // https://tc39.es/ecma262/#sec-async-functions-abstract-operations-async-function-start
                        // ->
                        // AsyncBlockStart ( promiseCapability, asyncBody, asyncContext )
                        // https://tc39.es/ecma262/#sec-asyncblockstart

                        // g. Else if result is a return completion, then
                        //        i. Perform ! Call(promiseCapability.[[Resolve]], undefined, « result.[[Value]] »).
                        global_state
                            .resolvers
                            .resolve
                            .call(&JsValue::undefined(), &[a.into()], context)
                            .expect("resolving functions cannot fail");

                        return Ok(CoroutineState::Done);
                    }

                    // 1. Let Pk be ! ToString(𝔽(k)).
                    // 2. Let kValue be ? Get(arrayLike, Pk).
                    let k_value = array_like.get(k, context)?;
                    state_machine.set(Some(ArrayLikeStateMachine::LoopContinue {
                        array_like,
                        a,
                        len,
                        k,
                    }));

                    // 3. Set kValue to ? Await(kValue).
                    return Ok(CoroutineState::Yielded(k_value));
                }
                ArrayLikeStateMachine::LoopContinue {
                    array_like,
                    a,
                    len,
                    k,
                } => {
                    // Awaited kValue
                    let k_value = std::mem::replace(&mut result, Ok(JsValue::undefined()))?;

                    // 4. If mapping is true, then
                    if let Some(mapfn) = &global_state.mapfn {
                        // a. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »).
                        let mapped_value =
                            mapfn.call(&global_state.this_arg, &[k_value, k.into()], context)?;
                        state_machine.set(Some(ArrayLikeStateMachine::LoopEnd {
                            array_like,
                            a,
                            len,
                            k,
                            mapped_value: None,
                        }));

                        // b. Set mappedValue to ? Await(mappedValue).
                        return Ok(CoroutineState::Yielded(mapped_value));
                    }
                    // 5. Else, let mappedValue be kValue.
                    sm = ArrayLikeStateMachine::LoopEnd {
                        array_like,
                        a,
                        len,
                        k,
                        mapped_value: Some(k_value),
                    }
                }
                ArrayLikeStateMachine::LoopEnd {
                    array_like,
                    a,
                    len,
                    k,
                    mapped_value,
                } => {
                    // Either awaited `mappedValue` or directly set this from `kValue`.
                    let result = std::mem::replace(&mut result, Ok(JsValue::undefined()))?;
                    let mapped_value = mapped_value.unwrap_or(result);

                    // 6. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
                    a.create_data_property_or_throw(k, mapped_value, context)?;

                    // 7. Set k to k + 1.
                    sm = ArrayLikeStateMachine::LoopStart {
                        array_like,
                        a,
                        len,
                        k: k + 1,
                    }
                }
            }
        }
    })();

    // AsyncFunctionStart ( promiseCapability, asyncFunctionBody )
    // https://tc39.es/ecma262/#sec-async-functions-abstract-operations-async-function-start
    // ->
    // AsyncBlockStart ( promiseCapability, asyncBody, asyncContext )
    // https://tc39.es/ecma262/#sec-asyncblockstart
    match result {
        Ok(cont) => cont,
        // i. Assert: result is a throw completion.
        Err(err) => {
            // ii. Perform ! Call(promiseCapability.[[Reject]], undefined, « result.[[Value]] »).
            global_state
                .resolvers
                .reject
                .call(&JsValue::undefined(), &[err.to_opaque(context)], context)
                .expect("resolving functions cannot fail");
            CoroutineState::Done
        }
    }
}