boa/syntax/ast/node/await_expr/
mod.rs

1//! Await expression node.
2
3use super::Node;
4use crate::{exec::Executable, BoaProfiler, Context, JsResult, JsValue};
5use gc::{Finalize, Trace};
6use std::fmt;
7
8#[cfg(feature = "deser")]
9use serde::{Deserialize, Serialize};
10
11#[cfg(test)]
12mod tests;
13
14/// An await expression is used within an async function to pause execution and wait for a
15/// promise to resolve.
16///
17/// More information:
18///  - [ECMAScript reference][spec]
19///  - [MDN documentation][mdn]
20///
21/// [spec]: https://tc39.es/ecma262/#prod-AwaitExpression
22/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await
23#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
24#[derive(Clone, Debug, Trace, Finalize, PartialEq)]
25pub struct AwaitExpr {
26    expr: Box<Node>,
27}
28
29impl Executable for AwaitExpr {
30    fn run(&self, _: &mut Context) -> JsResult<JsValue> {
31        let _timer = BoaProfiler::global().start_event("AwaitExpression", "exec");
32        // TODO: Implement AwaitExpr
33        Ok(JsValue::undefined())
34    }
35}
36
37impl<T> From<T> for AwaitExpr
38where
39    T: Into<Box<Node>>,
40{
41    fn from(e: T) -> Self {
42        Self { expr: e.into() }
43    }
44}
45
46impl fmt::Display for AwaitExpr {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        write!(f, "await ")?;
49        self.expr.display(f, 0)
50    }
51}
52
53impl From<AwaitExpr> for Node {
54    fn from(awaitexpr: AwaitExpr) -> Self {
55        Self::AwaitExpr(awaitexpr)
56    }
57}