Skip to content

Commit

Permalink
Refactor / Implement RegExp functions (#1350)
Browse files Browse the repository at this point in the history
* Refactor regexp exec function
Refactor regexp match function
Refactor regexp matchAll function
Refactor regexp test function
Implement regexp split function
Refactor string split function
Implement RegExpStringIterator

* Implement get RegExp.prototype.source

* fix some minor issues

* Docs: Minor typo

Co-authored-by: João Borges <rageknify@gmail.com>
  • Loading branch information
raskad and RageKnify committed Jul 7, 2021
1 parent 88452aa commit 2b45010
Show file tree
Hide file tree
Showing 8 changed files with 1,736 additions and 447 deletions.
6 changes: 5 additions & 1 deletion boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ impl Array {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-arraycreate
fn array_create(length: u32, prototype: Option<GcObject>, context: &mut Context) -> Value {
pub(crate) fn array_create(
length: u32,
prototype: Option<GcObject>,
context: &mut Context,
) -> Value {
let prototype = match prototype {
Some(prototype) => prototype,
None => context.standard_objects().array_object().prototype(),
Expand Down
20 changes: 15 additions & 5 deletions boa/src/builtins/iterable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
builtins::string::string_iterator::StringIterator,
builtins::ArrayIterator,
builtins::ForInIterator,
builtins::MapIterator,
builtins::SetIterator,
builtins::{
regexp::regexp_string_iterator::RegExpStringIterator,
string::string_iterator::StringIterator, ArrayIterator, ForInIterator, MapIterator,
SetIterator,
},
object::{GcObject, ObjectInitializer},
property::{Attribute, DataDescriptor},
symbol::WellKnownSymbols,
Expand All @@ -16,6 +16,7 @@ pub struct IteratorPrototypes {
array_iterator: GcObject,
set_iterator: GcObject,
string_iterator: GcObject,
regexp_string_iterator: GcObject,
map_iterator: GcObject,
for_in_iterator: GcObject,
}
Expand All @@ -33,6 +34,10 @@ impl IteratorPrototypes {
context,
iterator_prototype.clone().into(),
),
regexp_string_iterator: RegExpStringIterator::create_prototype(
context,
iterator_prototype.clone().into(),
),
map_iterator: MapIterator::create_prototype(context, iterator_prototype.clone().into()),
for_in_iterator: ForInIterator::create_prototype(
context,
Expand Down Expand Up @@ -62,6 +67,11 @@ impl IteratorPrototypes {
self.string_iterator.clone()
}

#[inline]
pub fn regexp_string_iterator(&self) -> GcObject {
self.regexp_string_iterator.clone()
}

#[inline]
pub fn map_iterator(&self) -> GcObject {
self.map_iterator.clone()
Expand Down

0 comments on commit 2b45010

Please sign in to comment.