Files
vectorcraft/crates/js/src/builtins/async_function.rs
T
dotCooCoo b900ea2308 JavaScript: a block function skips its variable when a let has the name
- A block function in script or eval code no longer stops the run with
  "redeclaration of" when a `let`, a `const` or a block function between
  the code and its variable environment has its name, or when the global
  object cannot take the variable (Annex B.3.3.2 and B.3.3.3). Its block
  still has the function, and a `var` of the name is still a SyntaxError.
- A script stopped by the heap limit or the frame limit declares none of
  its `let` and `const` names, so a later script can declare them. The
  frame limit is checked, and the heap reserved for the names, before
  anything is declared.
- An arrow function in an async arrow function's parameters reads `await`
  as an identifier, as its own body does.
- With E4X, `async::name` is a qualified name.
- `AsyncFunction` inherits from the built-in `Function` even after a
  script replaced `Function.prototype.constructor`.
- The test262 reports list the older edition's panics, an async test
  passes only when one `print` call gives exactly the completion line,
  and the promise collection test checks that all 200 rejections arrive.
2026-11-22 13:56:10 -08:00

35 lines
1.8 KiB
Rust

//! `AsyncFunction` and its prototype (ECMA-262 2017 section 25.5,
//! <https://262.ecma-international.org/8.0/#sec-async-function-objects>), in realms with
//! [`crate::Options::es2015`]: the prototype of every async function, and the constructor a script
//! reaches through it. `AsyncFunction` is not a global.
use super::{data, dynamic_function, native};
use crate::heap::{CONFIGURABLE, Class, NativeKind, Object};
use crate::interp::{Interp, JsResult};
use crate::value::Value;
/// Creates `AsyncFunction` and `AsyncFunction.prototype`, keeping the prototype for the async
/// functions the realm makes.
pub(crate) fn install(interp: &mut Interp) -> JsResult<()> {
let function_proto = interp.intrinsics.function_proto;
let proto = interp.heap.alloc_object(Object::new(Class::Ordinary, Some(function_proto)));
interp.promises.async_function_proto = Some(proto);
let ctor = native(interp, "AsyncFunction", async_function_ctor, 1, NativeKind::Plain, true)?;
interp.promises.async_function_ctor = Some(ctor);
// The built-in `Function` is the constructor's prototype (section 25.5.2), even after a
// script has replaced `Function.prototype.constructor`.
let function_ctor = interp.intrinsics.function_ctor;
if let Some(o) = interp.heap.object_mut(ctor) {
o.proto = Some(function_ctor);
}
data(interp, ctor, "prototype", Value::Object(proto), 0)?;
// Configurable and not writable (section 25.5.3.1), unlike the `constructor` of the ordinary
// built-in prototypes.
data(interp, proto, "constructor", Value::Object(ctor), CONFIGURABLE)
}
/// `AsyncFunction(p1, …, body)` and `new AsyncFunction(…)` (section 25.5.1.1).
fn async_function_ctor(interp: &mut Interp, _: Value, args: &[Value], _: bool) -> JsResult<Value> {
dynamic_function(interp, args, true)
}