Browse Source

fix(boa): fix stringpad abstract operation (#1347)

* fix(boa): fix stringpad abstract operation

- renames filter to filler in accordance with spec
- adds empty string
check to StringPad function

Closes #1306

* refactor to use `is_empty` method over comparison
pull/1356/head
neeldug 3 years ago committed by GitHub
parent
commit
b3ff0bff9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      boa/src/builtins/string/mod.rs
  2. 1
      test_ignore.txt

8
boa/src/builtins/string/mod.rs

@ -918,13 +918,17 @@ impl String {
return Value::from(primitive); return Value::from(primitive);
} }
let filter = fill_string.as_deref().unwrap_or(" "); let filler = fill_string.as_deref().unwrap_or(" ");
if filler.is_empty() {
return Value::from(primitive);
}
let fill_len = max_length.wrapping_sub(primitive_length); let fill_len = max_length.wrapping_sub(primitive_length);
let mut fill_str = StdString::new(); let mut fill_str = StdString::new();
while fill_str.len() < fill_len as usize { while fill_str.len() < fill_len as usize {
fill_str.push_str(filter); fill_str.push_str(filler);
} }
// Cut to size max_length // Cut to size max_length
let concat_fill_str: StdString = fill_str.chars().take(fill_len as usize).collect(); let concat_fill_str: StdString = fill_str.chars().take(fill_len as usize).collect();

1
test_ignore.txt

@ -12,7 +12,6 @@ feature:json-modules
// These seem to run forever: // These seem to run forever:
arg-length-exceeding-integer-limit arg-length-exceeding-integer-limit
15.4.4.19-8-c-ii-1 15.4.4.19-8-c-ii-1
fill-string-empty
length-boundaries length-boundaries
throws-if-integer-limit-exceeded throws-if-integer-limit-exceeded

Loading…
Cancel
Save