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

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

Merged
merged 6 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 19 additions & 2 deletions boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,16 +1254,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))
}

Expand Down
1 change: 0 additions & 1 deletion test_ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ feature:json-modules
arg-length-exceeding-integer-limit
15.4.4.19-8-c-ii-1
fill-string-empty
length-boundaries
throws-if-integer-limit-exceeded

// These generate a stack overflow
Expand Down