Browse Source

Small optimisation in som types that can be `Copy` (#479)

pull/489/head
Iban Eguia 5 years ago committed by GitHub
parent
commit
a5ed8b7743
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      boa/src/builtins/function/mod.rs
  2. 8
      boa/src/environment/function_environment_record.rs
  3. 8
      boa/src/syntax/ast/node/mod.rs

6
boa/src/builtins/function/mod.rs

@ -40,12 +40,16 @@ pub enum ConstructorKind {
/// Defines how this references are interpreted within the formal parameters and code body of the function.
///
/// Arrow functions don't define a `this` and thus are lexical, `function`s do define a this and thus are NonLexical
#[derive(Trace, Finalize, Debug, Clone)]
#[derive(Copy, Finalize, Debug, Clone)]
pub enum ThisMode {
Lexical,
NonLexical,
}
unsafe impl Trace for ThisMode {
unsafe_empty_trace!();
}
/// FunctionBody is specific to this interpreter, it will either be Rust code or JavaScript code (AST Node)
#[derive(Clone, Finalize)]
pub enum FunctionBody {

8
boa/src/environment/function_environment_record.rs

@ -16,12 +16,12 @@ use crate::{
lexical_environment::{Environment, EnvironmentType},
},
};
use gc::{Finalize, Trace};
use gc::{unsafe_empty_trace, Finalize, Trace};
use rustc_hash::FxHashMap;
/// Different binding status for `this`.
/// Usually set on a function environment record
#[derive(Trace, Finalize, Debug, Clone)]
#[derive(Copy, Finalize, Debug, Clone)]
pub enum BindingStatus {
/// If the value is "lexical", this is an ArrowFunction and does not have a local this value.
Lexical,
@ -31,6 +31,10 @@ pub enum BindingStatus {
Uninitialized,
}
unsafe impl Trace for BindingStatus {
unsafe_empty_trace!();
}
/// <https://tc39.es/ecma262/#table-16>
#[derive(Debug, Trace, Finalize, Clone)]
pub struct FunctionEnvironmentRecord {

8
boa/src/syntax/ast/node/mod.rs

@ -41,7 +41,7 @@ pub use self::{
try_node::{Catch, Finally, Try},
};
use super::Const;
use gc::{Finalize, Trace};
use gc::{unsafe_empty_trace, Finalize, Trace};
use std::{
cmp::Ordering,
fmt::{self, Display},
@ -428,7 +428,7 @@ impl PropertyDefinition {
/// [spec]: https://tc39.es/ecma262/#prod-MethodDefinition
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq, Trace, Finalize)]
#[derive(Clone, Debug, PartialEq, Copy, Finalize)]
pub enum MethodDefinitionKind {
/// The `get` syntax binds an object property to a function that will be called when that property is looked up.
///
@ -472,3 +472,7 @@ pub enum MethodDefinitionKind {
Ordinary,
// TODO: support other method definition kinds, like `Generator`.
}
unsafe impl Trace for MethodDefinitionKind {
unsafe_empty_trace!();
}

Loading…
Cancel
Save