boa_ast/statement/
throw.rs1use crate::{
2 Expression,
3 statement::Statement,
4 visitor::{VisitWith, Visitor, VisitorMut},
5};
6use boa_interner::{Interner, ToInternedString};
7use core::ops::ControlFlow;
8
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
24#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
25#[derive(Clone, Debug, PartialEq)]
26pub struct Throw {
27 target: Expression,
28}
29
30impl Throw {
31 #[must_use]
33 pub const fn target(&self) -> &Expression {
34 &self.target
35 }
36
37 #[must_use]
39 pub const fn new(target: Expression) -> Self {
40 Self { target }
41 }
42}
43
44impl ToInternedString for Throw {
45 fn to_interned_string(&self, interner: &Interner) -> String {
46 format!("throw {}", self.target.to_interned_string(interner))
47 }
48}
49
50impl From<Throw> for Statement {
51 fn from(trw: Throw) -> Self {
52 Self::Throw(trw)
53 }
54}
55
56impl VisitWith for Throw {
57 fn visit_with<'a, V>(&'a self, visitor: &mut V) -> ControlFlow<V::BreakTy>
58 where
59 V: Visitor<'a>,
60 {
61 visitor.visit_expression(&self.target)
62 }
63
64 fn visit_with_mut<'a, V>(&'a mut self, visitor: &mut V) -> ControlFlow<V::BreakTy>
65 where
66 V: VisitorMut<'a>,
67 {
68 visitor.visit_expression_mut(&mut self.target)
69 }
70}