-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
726 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Await expression node. | ||
use super::Node; | ||
use crate::{exec::Executable, BoaProfiler, Context, Result, Value}; | ||
use gc::{Finalize, Trace}; | ||
use std::fmt; | ||
|
||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// | ||
/// | ||
/// More information: | ||
/// - [ECMAScript reference][spec] | ||
/// - [MDN documentation][mdn] | ||
/// | ||
/// [spec]: | ||
/// [mdn]: | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug, Trace, Finalize, PartialEq)] | ||
pub struct AwaitExpr { | ||
expr: Box<Node>, | ||
} | ||
|
||
impl Executable for AwaitExpr { | ||
fn run(&self, interpreter: &mut Context) -> Result<Value> { | ||
let _timer = BoaProfiler::global().start_event("AwaitExpression", "exec"); | ||
unimplemented!("Await expression execution"); | ||
} | ||
} | ||
|
||
impl AwaitExpr { | ||
/// Implements the display formatting with indentation. | ||
pub(super) fn display(&self, f: &mut fmt::Formatter<'_>, indentation: usize) -> fmt::Result { | ||
writeln!(f, "await ")?; | ||
self.expr.display(f, indentation) | ||
} | ||
} | ||
|
||
impl<T> From<T> for AwaitExpr | ||
where | ||
T: Into<Box<Node>>, | ||
{ | ||
fn from(e: T) -> Self { | ||
Self { expr: e.into() } | ||
} | ||
} | ||
|
||
impl fmt::Display for AwaitExpr { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
self.display(f, 0) | ||
} | ||
} | ||
|
||
impl From<AwaitExpr> for Node { | ||
fn from(awaitexpr: AwaitExpr) -> Self { | ||
Self::AwaitExpr(awaitexpr) | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use crate::{ | ||
exec::Executable, | ||
syntax::ast::node::{join_nodes, FormalParameter, Node, StatementList}, | ||
BoaProfiler, Context, Result, Value, | ||
}; | ||
use gc::{Finalize, Trace}; | ||
use std::fmt; | ||
|
||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Async Function Declaration. | ||
/// | ||
/// More information: | ||
/// - [ECMAScript reference][spec] | ||
/// - [MDN documentation][mdn] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#sec-async-function-prototype-properties | ||
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug, Trace, Finalize, PartialEq)] | ||
pub struct AsyncFunctionDecl { | ||
name: Option<Box<str>>, | ||
parameters: Box<[FormalParameter]>, | ||
body: StatementList, | ||
} | ||
|
||
impl AsyncFunctionDecl { | ||
/// Creates a new async function declaration. | ||
pub(in crate::syntax) fn new<N, P, B>(name: N, parameters: P, body: B) -> Self | ||
where | ||
N: Into<Option<Box<str>>>, | ||
P: Into<Box<[FormalParameter]>>, | ||
B: Into<StatementList>, | ||
{ | ||
Self { | ||
name: name.into(), | ||
parameters: parameters.into(), | ||
body: body.into(), | ||
} | ||
} | ||
|
||
/// Gets the name of the async function declaration. | ||
pub fn name(&self) -> Option<&str> { | ||
self.name.as_deref() | ||
} | ||
|
||
/// Gets the list of parameters of the async function declaration. | ||
pub fn parameters(&self) -> &[FormalParameter] { | ||
&self.parameters | ||
} | ||
|
||
/// Gets the body of the async function declaration. | ||
pub fn body(&self) -> &[Node] { | ||
self.body.statements() | ||
} | ||
|
||
/// Implements the display formatting with indentation. | ||
pub(in crate::syntax::ast::node) fn display( | ||
&self, | ||
f: &mut fmt::Formatter<'_>, | ||
indentation: usize, | ||
) -> fmt::Result { | ||
match &self.name { | ||
Some(name) => { | ||
write!(f, "async function {}(", name)?; | ||
} | ||
None => { | ||
write!(f, "async function (")?; | ||
} | ||
} | ||
join_nodes(f, &self.parameters)?; | ||
f.write_str(") {{")?; | ||
|
||
self.body.display(f, indentation + 1)?; | ||
|
||
writeln!(f, "}}") | ||
} | ||
} | ||
|
||
impl Executable for AsyncFunctionDecl { | ||
fn run(&self, interpreter: &mut Context) -> Result<Value> { | ||
let _timer = BoaProfiler::global().start_event("AsyncFunctionDecl", "exec"); | ||
unimplemented!("Execute AsyncFunctionDecl"); | ||
Ok(Value::undefined()) | ||
} | ||
} | ||
|
||
impl From<AsyncFunctionDecl> for Node { | ||
fn from(decl: AsyncFunctionDecl) -> Self { | ||
Self::AsyncFunctionDecl(decl) | ||
} | ||
} | ||
|
||
impl fmt::Display for AsyncFunctionDecl { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
self.display(f, 0) | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
boa/src/syntax/ast/node/declaration/async_function_expr/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use crate::{ | ||
exec::Executable, | ||
syntax::ast::node::{join_nodes, FormalParameter, Node, StatementList}, | ||
Context, Result, Value, | ||
}; | ||
use gc::{Finalize, Trace}; | ||
use std::fmt; | ||
|
||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// AsyncFunctionExpr. | ||
/// | ||
/// More information: | ||
/// - [ECMAScript reference][spec] | ||
/// - [MDN documentation][mdn] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#prod-AsyncFunctionExpression | ||
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/async_function | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug, Trace, Finalize, PartialEq)] | ||
pub struct AsyncFunctionExpr { | ||
name: Option<Box<str>>, | ||
parameters: Box<[FormalParameter]>, | ||
body: StatementList, | ||
} | ||
|
||
impl AsyncFunctionExpr { | ||
/// Creates a new function expression | ||
pub(in crate::syntax) fn new<N, P, B>(name: N, parameters: P, body: B) -> Self | ||
where | ||
N: Into<Option<Box<str>>>, | ||
P: Into<Box<[FormalParameter]>>, | ||
B: Into<StatementList>, | ||
{ | ||
Self { | ||
name: name.into(), | ||
parameters: parameters.into(), | ||
body: body.into(), | ||
} | ||
} | ||
|
||
/// Gets the name of the function declaration. | ||
pub fn name(&self) -> Option<&str> { | ||
self.name.as_ref().map(Box::as_ref) | ||
} | ||
|
||
/// Gets the list of parameters of the function declaration. | ||
pub fn parameters(&self) -> &[FormalParameter] { | ||
&self.parameters | ||
} | ||
|
||
/// Gets the body of the function declaration. | ||
pub fn body(&self) -> &[Node] { | ||
self.body.statements() | ||
} | ||
|
||
/// Implements the display formatting with indentation. | ||
pub(in crate::syntax::ast::node) fn display( | ||
&self, | ||
f: &mut fmt::Formatter<'_>, | ||
indentation: usize, | ||
) -> fmt::Result { | ||
f.write_str("function")?; | ||
if let Some(ref name) = self.name { | ||
write!(f, " {}", name)?; | ||
} | ||
f.write_str("(")?; | ||
join_nodes(f, &self.parameters)?; | ||
f.write_str(") {{")?; | ||
|
||
self.body.display(f, indentation + 1)?; | ||
|
||
writeln!(f, "}}") | ||
} | ||
} | ||
|
||
impl Executable for AsyncFunctionExpr { | ||
fn run(&self, interpreter: &mut Context) -> Result<Value> { | ||
unimplemented!("Execute AsyncFunctionExpr"); | ||
} | ||
} | ||
|
||
impl fmt::Display for AsyncFunctionExpr { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
self.display(f, 0) | ||
} | ||
} | ||
|
||
impl From<AsyncFunctionExpr> for Node { | ||
fn from(expr: AsyncFunctionExpr) -> Self { | ||
Self::AsyncFunctionExpr(expr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.