Skip to content

Commit

Permalink
Implement trimLeft and trimRight
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Apr 11, 2023
1 parent 333b94a commit 1563882
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions boa_engine/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,37 @@ impl IntrinsicObject for String {

let symbol_iterator = JsSymbol::iterator();

let trim_start = BuiltInBuilder::new(realm)
.callable(Self::trim_start)
.length(0)
.name("trimStart")
.build();

let trim_end = BuiltInBuilder::new(realm)
.callable(Self::trim_end)
.length(0)
.name("trimEnd")
.build();

#[cfg(feature = "annex-b")]
let trim_left = trim_start.clone();

#[cfg(feature = "annex-b")]
let trim_right = trim_end.clone();

let attribute = Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT;
let builder = BuiltInBuilder::from_standard_constructor::<Self>(realm)
.property(utf16!("length"), 0, attribute)
.property(
utf16!("trimStart"),
trim_start,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
utf16!("trimEnd"),
trim_end,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.static_method(Self::raw, "raw", 1)
.static_method(Self::from_char_code, "fromCharCode", 1)
.static_method(Self::from_code_point, "fromCodePoint", 1)
Expand All @@ -90,12 +118,10 @@ impl IntrinsicObject for String {
.method(Self::last_index_of, "lastIndexOf", 1)
.method(Self::locale_compare, "localeCompare", 1)
.method(Self::r#match, "match", 1)
.method(Self::normalize, "normalize", 1)
.method(Self::normalize, "normalize", 0)
.method(Self::pad_end, "padEnd", 1)
.method(Self::pad_start, "padStart", 1)
.method(Self::trim, "trim", 0)
.method(Self::trim_start, "trimStart", 0)
.method(Self::trim_end, "trimEnd", 0)
.method(Self::to_lowercase, "toLowerCase", 0)
.method(Self::to_uppercase, "toUpperCase", 0)
.method(Self::substring, "substring", 2)
Expand All @@ -111,6 +137,16 @@ impl IntrinsicObject for String {
#[cfg(feature = "annex-b")]
{
builder
.property(
utf16!("trimLeft"),
trim_left,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.property(
utf16!("trimRight"),
trim_right,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
)
.method(Self::substr, "substr", 2)
.method(Self::anchor, "anchor", 1)
.method(Self::big, "big", 0)
Expand Down

0 comments on commit 1563882

Please sign in to comment.