boa/syntax/ast/node/iteration/continue_node/
mod.rs1use crate::{
2 exec::{Executable, InterpreterState},
3 gc::{Finalize, Trace},
4 syntax::ast::node::Node,
5 Context, JsResult, JsValue,
6};
7use std::fmt;
8
9#[cfg(feature = "deser")]
10use serde::{Deserialize, Serialize};
11
12#[cfg_attr(feature = "deser", derive(Serialize, Deserialize))]
26#[derive(Clone, Debug, Trace, Finalize, PartialEq)]
27pub struct Continue {
28 label: Option<Box<str>>,
29}
30
31impl Continue {
32 pub fn label(&self) -> Option<&str> {
33 self.label.as_ref().map(Box::as_ref)
34 }
35
36 pub fn new<OL, L>(label: OL) -> Self
38 where
39 L: Into<Box<str>>,
40 OL: Into<Option<L>>,
41 {
42 Self {
43 label: label.into().map(L::into),
44 }
45 }
46}
47
48impl Executable for Continue {
49 fn run(&self, context: &mut Context) -> JsResult<JsValue> {
50 context
51 .executor()
52 .set_current_state(InterpreterState::Continue(self.label().map(Box::from)));
53
54 Ok(JsValue::undefined())
55 }
56}
57
58impl fmt::Display for Continue {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 write!(f, "continue")?;
61 if let Some(label) = self.label() {
62 write!(f, " {}", label)?;
63 }
64 Ok(())
65 }
66}
67
68impl From<Continue> for Node {
69 fn from(cont: Continue) -> Node {
70 Self::Continue(cont)
71 }
72}