-
-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathclass.rs
More file actions
777 lines (681 loc) · 24.8 KB
/
class.rs
File metadata and controls
777 lines (681 loc) · 24.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
use crate::utils::{
RenameScheme, SpannedResult, error, take_error_from_attrs, take_length_from_attrs,
take_name_value_attr, take_name_value_string, take_path_attr,
};
use proc_macro::TokenStream;
use proc_macro2::{Span as Span2, TokenStream as TokenStream2};
use quote::quote;
use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};
use syn::parse::{Parse, ParseStream};
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::visit_mut::VisitMut;
use syn::{
Attribute, ConstParam, Expr, FnArg, GenericParam, Ident, ImplItemFn, ItemImpl, LifetimeParam,
Lit, Meta, MetaNameValue, PatType, Receiver, ReturnType, Signature, Token, Type, TypeParam,
};
/// The name of a method or accessor, which can be either a string property key or a
/// well-known symbol (e.g. `Symbol.iterator`).
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum MethodName {
String(String),
Symbol(String),
}
impl MethodName {
fn to_key_tokens(&self) -> TokenStream2 {
match self {
Self::String(s) => quote! { boa_engine::js_string!( #s ) },
Self::Symbol(sym) => {
let snake = camel_to_snake_case(sym);
let ident = Ident::new_raw(&snake, Span2::call_site());
quote! { boa_engine::JsSymbol:: #ident () }
}
}
}
}
/// Converts a `camelCase` string to `snake_case`.
///
/// The symbol name is forwarded to `JsSymbol::<snake_name>()` without
/// validation; if the accessor does not exist the Rust compiler will report
/// the error.
fn camel_to_snake_case(s: &str) -> String {
let mut result = String::with_capacity(s.len() + 4);
for (i, ch) in s.chars().enumerate() {
if ch.is_ascii_uppercase() {
if i > 0 {
result.push('_');
}
result.push(ch.to_ascii_lowercase());
} else {
result.push(ch);
}
}
result
}
/// A function representation. Takes a function from the AST and remember its name, length and
/// how its body should be in the output AST.
/// There are three types of functions: Constructors, Methods and Accessors (setter/getter).
///
/// This is not an enum for simplicity. The body is dependent on how this was created.
pub(crate) struct Function {
/// The name of the function. Can be a string key or a well-known symbol.
name: MethodName,
/// The length of the function in JavaScript. Can be overridden with `#[boa(length = ...)]`.
length: usize,
/// The body of the function serialized. This depends highly on the type of function.
body: TokenStream2,
/// Whether a receiver was found.
is_static: bool,
}
impl std::fmt::Debug for Function {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Function")
.field("name", &self.name)
.field("length", &self.length)
.field("is_static", &self.is_static)
.field("body", &self.body.to_string())
.finish()
}
}
impl Display for MethodName {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::String(s) => f.write_str(s),
Self::Symbol(s) => write!(f, "[Symbol.{s}]"),
}
}
}
impl Function {
/// Serializes the `self` argument declaration and call.
fn arg_self_from_receiver(
receiver: &mut Receiver,
class_ty: &Type,
) -> SpannedResult<(TokenStream2, TokenStream2)> {
let err = take_error_from_attrs(&mut receiver.attrs)?
.unwrap_or("Invalid class for type".to_string());
// `&mut self`
let downcast = if receiver.mutability.is_some() {
quote! {
let object = this.as_object();
let self_ = &mut *object.as_ref().and_then(|o| o.downcast_mut::< #class_ty >())
.ok_or( boa_engine::js_error!( #err ))?;
}
} else {
quote! {
let object = this.as_object();
let self_ = &*object.as_ref().and_then(|o| o.downcast_ref::< #class_ty >())
.ok_or( boa_engine::js_error!( #err ))?;
}
};
Ok((downcast, quote! { self_ }))
}
/// Serializes an argument of form `pat: Type` into its declaration and call. Also returns
/// whether we should increment the length.
#[allow(clippy::unnecessary_wraps)]
fn arg_from_pat_type(
pat_type: &mut PatType,
i: usize,
) -> SpannedResult<(bool, TokenStream2, TokenStream2)> {
let ty = pat_type.ty.as_ref();
let ident = Ident::new(&format!("boa_arg_{i}"), Span2::call_site());
// Find out if it's a boa context.
let is_context = match ty {
Type::Reference(syn::TypeReference {
elem,
mutability: Some(_),
..
}) => match elem.as_ref() {
Type::Path(syn::TypePath { qself: _, path }) => {
if let Some(maybe_ctx) = path.segments.last() {
maybe_ctx.ident == "Context"
} else {
false
}
}
_ => take_path_attr(&mut pat_type.attrs, "context"),
},
_ => false,
};
if is_context {
Ok((true, quote! {}, quote! { context }))
} else {
Ok((
false,
quote! {
let (#ident, rest): (#ty, &[boa_engine::JsValue]) =
boa_engine::interop::TryFromJsArgument::try_from_js_argument( this, rest, context )?;
},
quote! { #ident },
))
}
}
pub(crate) fn from_sig(
name: MethodName,
has_explicit_method: bool,
has_explicit_static: bool,
attrs: &mut Vec<Attribute>,
sig: &mut Signature,
class_ty: Option<&Type>,
) -> SpannedResult<Self> {
// The amount of arguments that aren't really arguments in JavaScript,
// e.g. `self`, `&mut Context`, etc.
let mut not_param_count = 0;
let (args_decl, args_call): (Vec<TokenStream2>, Vec<TokenStream2>) = sig
.inputs
.iter_mut()
.enumerate()
.map(|(i, a)| match a {
FnArg::Receiver(receiver) => {
not_param_count += 1;
if let Some(cty) = class_ty {
Self::arg_self_from_receiver(receiver, cty)
} else {
error(receiver, "Invalid context for using a receiver.")
}
}
FnArg::Typed(ty) => {
let (incr, decl, call) = Self::arg_from_pat_type(ty, i)?;
if incr {
not_param_count += 1;
}
Ok((decl, call))
}
})
.collect::<SpannedResult<_>>()?;
let length = take_length_from_attrs(attrs)?.unwrap_or(args_decl.len() - not_param_count);
let fn_name = &sig.ident;
let generics = if sig.generics.params.is_empty() {
quote! {}
} else {
let generics = sig
.generics
.params
.iter()
.map(|param| match param {
GenericParam::Type(TypeParam { ident, .. })
| GenericParam::Const(ConstParam { ident, .. }) => {
quote! { #ident }
}
GenericParam::Lifetime(LifetimeParam { lifetime, .. }) => {
quote! { #lifetime }
}
})
.collect::<TokenStream2>();
quote! { :: < #generics > }
};
// A method is static if it has the `#[boa(static)]` attribute, or if it is
// not a method and doesn't contain `self`.
let is_static = has_explicit_static || !(has_explicit_method || not_param_count > 0);
// If this is a scoped function to a type (e.g. inside an `impl` block),
let scope = if class_ty.is_some() {
quote! { Self :: }
} else {
quote! {}
};
Ok(Self {
length,
name,
body: quote! {
| this: &boa_engine::JsValue,
args: &[boa_engine::JsValue],
context: &mut boa_engine::Context
| -> boa_engine::JsResult<boa_engine::JsValue> {
let rest = args;
#(#args_decl)*
let result = #scope #fn_name #generics ( #(#args_call),* );
boa_engine::TryIntoJsResult::try_into_js_result(result, context)
}
},
is_static,
})
}
fn method(
name: MethodName,
has_explicit_method: bool,
has_explicit_static: bool,
fn_: &mut ImplItemFn,
class_ty: Option<&Type>,
) -> SpannedResult<Self> {
if fn_.sig.asyncness.is_some() {
error(&fn_.sig.asyncness, "Async methods are not supported.")?;
}
if !fn_.sig.generics.params.is_empty() {
error(&fn_.sig.generics, "Generic methods are not supported.")?;
}
Self::from_sig(
name,
has_explicit_method,
has_explicit_static,
&mut fn_.attrs,
&mut fn_.sig,
class_ty,
)
}
fn getter(name: MethodName, fn_: &mut ImplItemFn, class_ty: &Type) -> SpannedResult<Self> {
Self::method(name, false, true, fn_, Some(class_ty))
}
fn setter(name: MethodName, fn_: &mut ImplItemFn, class_ty: &Type) -> SpannedResult<Self> {
Self::method(name, false, true, fn_, Some(class_ty))
}
fn constructor(fn_: &mut ImplItemFn, _class_ty: &Type) -> SpannedResult<Self> {
if fn_.sig.asyncness.is_some() {
error(&fn_.sig.asyncness, "Async methods are not supported.")?;
}
if !fn_.sig.generics.params.is_empty() {
error(&fn_.sig.generics, "Generic methods are not supported.")?;
}
let (args_decl, args_call): (Vec<TokenStream2>, Vec<TokenStream2>) = fn_
.sig
.inputs
.iter_mut()
.enumerate()
.map(|(i, a)| match a {
FnArg::Receiver(receiver) => error(receiver, "Constructors cannot use 'self'"),
FnArg::Typed(ty) => {
let (_, decl, call) = Self::arg_from_pat_type(ty, i)?;
Ok((decl, call))
}
})
.collect::<SpannedResult<_>>()?;
let length = take_length_from_attrs(&mut fn_.attrs)?.unwrap_or(args_decl.len());
let fn_name = &fn_.sig.ident;
// Does the function return Result<_> or JsResult<_>? If so, Into JsResult (to
// transform the error. If not, return Ok(_).
let return_statement = match &fn_.sig.output {
ReturnType::Default => quote! { Default::default() },
ReturnType::Type(_, ty) => {
if let Type::Path(path) = ty.as_ref() {
let Some(t) = path.path.segments.last() else {
return error(&fn_.sig.output, "Cannot infer return type.");
};
if t.ident == "Self" {
quote! { Ok(result) }
} else if t.ident == "JsResult" {
quote! { result.into() }
} else {
return error(
&fn_.sig.output,
"Invalid return type: constructors should return Self or JsResult<Self>.",
);
}
} else {
quote! { Ok(result) }
}
}
};
Ok(Self {
length,
name: MethodName::String(String::new()),
body: quote! {
let rest = args;
#(#args_decl)*
let result = Self:: #fn_name ( #(#args_call),* );
#return_statement
},
is_static: false,
})
}
pub(crate) fn body(&self) -> &TokenStream2 {
&self.body
}
}
#[derive(Debug, Default)]
struct Accessor {
getter: Option<Function>,
setter: Option<Function>,
}
impl Accessor {
fn set_getter(
&mut self,
name: MethodName,
fn_: &mut ImplItemFn,
class_ty: &Type,
) -> SpannedResult<()> {
if self.getter.is_some() {
error(fn_, format!("Getter for property {name} already declared."))
} else {
let getter = Function::getter(name, fn_, class_ty)?;
self.getter = Some(getter);
Ok(())
}
}
fn set_setter(
&mut self,
name: MethodName,
fn_: &mut ImplItemFn,
class_ty: &Type,
) -> SpannedResult<()> {
if self.setter.is_some() {
error(fn_, format!("Setter for property {name} already declared."))
} else {
let setter = Function::setter(name, fn_, class_ty)?;
self.setter = Some(setter);
Ok(())
}
}
fn body(&self) -> TokenStream2 {
let Some(name) = self
.getter
.as_ref()
.map_or_else(|| self.setter.as_ref().map(|s| &s.name), |g| Some(&g.name))
else {
return quote! {};
};
let key_tokens = name.to_key_tokens();
let getter = if let Some(getter) = self.getter.as_ref() {
let body = getter.body.clone();
quote! {
Some(
boa_engine::NativeFunction::from_fn_ptr( #body )
.to_js_function(builder.context().realm())
)
}
} else {
quote! { None }
};
let setter = if let Some(setter) = self.setter.as_ref() {
let body = setter.body.clone();
quote! {
Some(
boa_engine::NativeFunction::from_fn_ptr( #body )
.to_js_function(builder.context().realm())
)
}
} else {
quote! { None }
};
quote! {
{
let g = #getter;
let s = #setter;
builder.accessor(
#key_tokens,
g,
s,
boa_engine::property::Attribute::CONFIGURABLE
| boa_engine::property::Attribute::NON_ENUMERABLE,
);
}
}
}
}
/// A visitor for the `impl X { ... }` block. This will record all top-level functions
/// and create endpoints for the JavaScript class.
#[derive(Debug)]
struct ClassVisitor {
renaming: RenameScheme,
// The type name for this class.
type_: Type,
// Whether we detected a constructor while visiting.
constructor: Option<Function>,
// All static functions recorded.
statics: Vec<Function>,
// All methods recorded.
methods: Vec<Function>,
// All accessors (getters and/or setters) with their names.
accessors: BTreeMap<MethodName, Accessor>,
// All errors we found along the way.
errors: Option<syn::Error>,
}
impl ClassVisitor {
fn new(renaming: RenameScheme, type_: Type) -> Self {
Self {
renaming,
type_,
constructor: None,
statics: Vec::new(),
methods: Vec::new(),
accessors: BTreeMap::default(),
errors: None,
}
}
fn name_of(&self, fn_: &mut ImplItemFn) -> SpannedResult<MethodName> {
if let Some(sym) = take_name_value_string(&mut fn_.attrs, "symbol")? {
return Ok(MethodName::Symbol(sym));
}
take_name_value_attr(&mut fn_.attrs, "rename").map_or_else(
|| {
Ok(MethodName::String(
self.renaming.rename(fn_.sig.ident.to_string()),
))
},
|nv| match &nv {
Lit::Str(s) => Ok(MethodName::String(s.value())),
_ => error(&nv, "Invalid attribute value literal"),
},
)
}
fn method(
&mut self,
explicit_method: bool,
explicit_static: bool,
fn_: &mut ImplItemFn,
) -> SpannedResult<()> {
let name = self.name_of(fn_)?;
let f = Function::method(
name,
explicit_method,
explicit_static,
fn_,
Some(&self.type_),
)?;
if f.is_static {
self.statics.push(f);
} else {
self.methods.push(f);
}
Ok(())
}
fn getter(&mut self, fn_: &mut ImplItemFn) -> SpannedResult<()> {
let name = self.name_of(fn_)?;
self.accessors
.entry(name.clone())
.or_default()
.set_getter(name, fn_, &self.type_)?;
Ok(())
}
fn setter(&mut self, fn_: &mut ImplItemFn) -> SpannedResult<()> {
let name = self.name_of(fn_)?;
self.accessors
.entry(name.clone())
.or_default()
.set_setter(name, fn_, &self.type_)?;
Ok(())
}
fn constructor(&mut self, fn_: &mut ImplItemFn) -> SpannedResult<()> {
self.constructor = Some(Function::constructor(fn_, &self.type_)?);
Ok(())
}
/// Add an error to list of errors we are recording along the way. Errors are handled
/// at the end of the process, so this combines all errors.
#[allow(clippy::needless_pass_by_value)]
fn error(&mut self, node: impl Spanned, message: impl Display) {
let error = syn::Error::new(node.span(), message);
match &mut self.errors {
None => {
self.errors = Some(error);
}
Some(e) => {
e.combine(error);
}
}
}
/// Serialize the `boa_engine::Class` implementation into a token stream.
fn serialize_class_impl(&self, class_ty: &Type, class_name: &str) -> TokenStream2 {
let arg_count = self.constructor.as_ref().map_or(0, |c| c.length);
let accessors = self.accessors.values().map(Accessor::body);
let builder_methods = self.methods.iter().map(|m| {
let key_tokens = m.name.to_key_tokens();
let length = m.length;
let body = &m.body;
quote! {
builder.method(
#key_tokens,
#length,
boa_engine::NativeFunction::from_fn_ptr(
#body
)
);
}
});
let builder_statics = self.statics.iter().map(|m| {
let key_tokens = m.name.to_key_tokens();
let length = m.length;
let body = &m.body;
quote! {
builder.static_method(
#key_tokens,
#length,
boa_engine::NativeFunction::from_fn_ptr(
#body
)
);
}
});
let constructor_body = self.constructor.as_ref().map_or_else(
|| {
quote! {
Ok(Default::default())
}
},
|c| c.body.clone(),
);
quote! {
impl boa_engine::class::Class for #class_ty {
const NAME: &'static str = #class_name;
const LENGTH: usize = #arg_count;
fn data_constructor(
this: &boa_engine::JsValue,
args: &[boa_engine::JsValue],
context: &mut boa_engine::Context
) -> boa_engine::JsResult<Self> {
#constructor_body
}
fn init(builder: &mut boa_engine::class::ClassBuilder) -> boa_engine::JsResult<()> {
// Add all statics.
#(#builder_statics)*
// Add all accessors.
#(#accessors)*
// Add all methods to the class.
#(#builder_methods)*
Ok(())
}
}
impl boa_engine::value::TryIntoJs for #class_ty
where
Self: Clone,
{
fn try_into_js(&self, context: &mut boa_engine::Context) -> boa_engine::JsResult<boa_engine::JsValue> {
<Self as boa_engine::class::Class>::from_data(self.clone(), context).map(Into::into)
}
}
}
}
}
impl VisitMut for ClassVisitor {
// Allow similar names as there are no better ways to name `getter` and `setter`.
#[allow(clippy::similar_names)]
fn visit_impl_item_fn_mut(&mut self, item: &mut ImplItemFn) {
// If there's a `boa` argument, parse it.
let has_ctor_attr = take_path_attr(&mut item.attrs, "constructor");
let has_getter_attr = take_path_attr(&mut item.attrs, "getter");
let has_setter_attr = take_path_attr(&mut item.attrs, "setter");
let has_method_attr = take_path_attr(&mut item.attrs, "method");
let has_static_attr = take_path_attr(&mut item.attrs, "static");
if has_getter_attr && let Err((span, msg)) = self.getter(item) {
self.error(span, msg);
}
if has_setter_attr && let Err((span, msg)) = self.setter(item) {
self.error(span, msg);
}
if has_ctor_attr && let Err((span, msg)) = self.constructor(item) {
self.error(span, msg);
}
// A function is a method if it has a `#[boa(method)]` attribute or has no
// method-type related attributes.
if (has_static_attr
|| has_method_attr
|| !(has_getter_attr || has_ctor_attr || has_setter_attr))
&& let Err((span, msg)) = self.method(has_method_attr, has_static_attr, item)
{
self.error(span, msg);
}
syn::visit_mut::visit_impl_item_fn_mut(self, item);
}
}
#[derive(Debug)]
struct ClassArguments {
name: Option<String>,
}
impl Parse for ClassArguments {
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
let args: Punctuated<Meta, Token![,]> = Punctuated::parse_terminated(input)?;
let mut name = None;
for arg in &args {
match arg {
Meta::NameValue(MetaNameValue {
path,
value: Expr::Lit(lit),
..
}) if path.is_ident("rename") => {
name = Some(match &lit.lit {
Lit::Str(s) => Ok(s.value()),
_ => Err(syn::Error::new(lit.span(), "Expected a string literal")),
}?);
}
_ => return Err(syn::Error::new(arg.span(), "Unrecognize argument.")),
}
}
Ok(Self { name })
}
}
pub(crate) fn class_impl(attr: TokenStream, input: TokenStream) -> TokenStream {
// Parse the attribute arguments.
let args = syn::parse_macro_input!(attr as ClassArguments);
// Parse the input.
let mut impl_ = syn::parse_macro_input!(input as ItemImpl);
let renaming = match RenameScheme::from_named_attrs(&mut impl_.attrs, "rename_all") {
Ok(Some(r)) => r,
Ok(None) => RenameScheme::CamelCase,
Err((span, msg)) => {
return syn::Error::new(span, msg).to_compile_error().into();
}
};
// Get all methods from the input.
let mut visitor = ClassVisitor::new(renaming, impl_.self_ty.as_ref().clone());
syn::visit_mut::visit_item_impl_mut(&mut visitor, &mut impl_);
if let Some(err) = visitor.errors {
return err.to_compile_error().into();
}
let Type::Path(pa) = impl_.self_ty.as_ref() else {
return syn::Error::new(impl_.span(), "Impossible to find the name of the class.")
.to_compile_error()
.into();
};
let Some(name) = args
.name
.or_else(|| pa.path.get_ident().map(ToString::to_string))
else {
return syn::Error::new(pa.span(), "Impossible to find the name of the class.")
.to_compile_error()
.into();
};
let class_impl = visitor.serialize_class_impl(&impl_.self_ty, &name);
let debug = take_path_attr(&mut impl_.attrs, "debug");
let tokens = quote! {
// Keep the original implementation as is.
// Add `#[allow(clippy::needless_pass_by_value)]`, as clippy can complaint when
// using passing-by-value but not using it in the body, except that we cannot
// convert the types if we pass by reference.
#[allow(clippy::needless_pass_by_value)]
#impl_
// The boa_engine::Class implementation.
#class_impl
};
#[allow(clippy::print_stderr)]
if debug {
eprintln!("---------\n{tokens}\n---------\n");
}
tokens.into()
}