Browse Source

fix(boa): fixes Array.protoype.includes (#1349)

* fix(boa): fixes Array.protoype.includes

- adds fromIndex
- adds infinity checking to indices

Closes #1306

* add comments for clarity

* fix(boa): fixes Array.protoype.includes

- adds fromIndex
- adds infinity checking to indices

Closes #1306

* add comments for clarity
pull/1356/head
neeldug 3 years ago committed by GitHub
parent
commit
83ac2a94f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      boa/src/builtins/array/mod.rs
  2. 1
      test_ignore.txt

21
boa/src/builtins/array/mod.rs

@ -1264,16 +1264,33 @@ impl Array {
) -> Result<Value> {
let search_element = args.get(0).cloned().unwrap_or_else(Value::undefined);
let from_index = args.get(1).cloned().unwrap_or_else(|| Value::from(0));
let length = this.get_field("length", context)?.to_length(context)?;
for idx in 0..length {
if length == 0 {
return Ok(Value::from(false));
}
let n = match from_index.to_integer_or_infinity(context)? {
IntegerOrInfinity::NegativeInfinity => 0,
IntegerOrInfinity::PositiveInfinity => return Ok(Value::from(false)),
IntegerOrInfinity::Integer(i) => i,
};
let k = match n {
num if num >= 0 => num as usize, // if n>=0 -> k=n
num if -num as usize > length => 0, // if n<0 -> k= max(length + n, 0)
_ => length - (-n as usize), // this is `length + n` but is necessary for typing reasons
};
for idx in k..length {
let check_element = this.get_field(idx, context)?.clone();
if Value::same_value_zero(&check_element, &search_element) {
return Ok(Value::from(true));
}
}
Ok(Value::from(false))
}

1
test_ignore.txt

@ -12,7 +12,6 @@ feature:json-modules
// These seem to run forever:
arg-length-exceeding-integer-limit
15.4.4.19-8-c-ii-1
length-boundaries
// These generate a stack overflow
tco-call

Loading…
Cancel
Save