Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegExp specialization #592

Merged
merged 5 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions boa/src/builtins/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
map::ordered_map::OrderedMap,
property::Property,
value::{RcBigInt, RcString, RcSymbol, ResultValue, Value},
BigInt,
BigInt, RegExp,
},
exec::Interpreter,
BoaProfiler,
Expand Down Expand Up @@ -71,6 +71,7 @@ pub struct Object {
pub enum ObjectData {
Array,
Map(OrderedMap<Value, Value>),
RegExp(RegExp),
BigInt(RcBigInt),
Boolean(bool),
Function(Function),
Expand All @@ -87,8 +88,9 @@ impl Display for ObjectData {
f,
"{}",
match self {
Self::Function(_) => "Function",
Self::Array => "Array",
Self::Function(_) => "Function",
Self::RegExp(_) => "RegExp",
Self::Map(_) => "Map",
Self::String(_) => "String",
Self::Symbol(_) => "Symbol",
Expand Down Expand Up @@ -381,6 +383,20 @@ impl Object {
}
}

/// Checks if it a `RegExp` object.
#[inline]
pub fn is_regexp(&self) -> bool {
matches!(self.data, ObjectData::RegExp(_))
}

#[inline]
pub fn as_regexp(&self) -> Option<&RegExp> {
match self.data {
ObjectData::RegExp(ref regexp) => Some(regexp),
_ => None,
}
}

/// Checks if it an ordinary object.
#[inline]
pub fn is_ordinary(&self) -> bool {
Expand Down
Loading