-
Notifications
You must be signed in to change notification settings - Fork 859
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent various array methods from setting empty slots in sparse arra…
…ys to undefined. Defining an array element as undefined yields a similar result as not defining it, but the `in` operator will report the element as present. Affected methods are reverse(), shift(), unshift(), slice(), splice(), and concat(). Also adds doctests for said methods on both sparse and dense arrays.
- Loading branch information
Showing
3 changed files
with
181 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// test various array methods with dense arrays | ||
js> var x = [] | ||
|
||
js> x[10] = 1 | ||
1 | ||
js> x.length | ||
11 | ||
js> 0 in x | ||
false | ||
js> x.shift() | ||
js> x.length | ||
10 | ||
js> 0 in x | ||
false | ||
js> x | ||
,,,,,,,,,1 | ||
js> x.reverse() | ||
1,,,,,,,,, | ||
js> x.length | ||
10 | ||
js> 9 in x | ||
false | ||
js> x.reverse() | ||
,,,,,,,,,1 | ||
js> x.length | ||
10 | ||
js> 5 in x | ||
false | ||
js> x.unshift(2) | ||
11 | ||
js> x | ||
2,,,,,,,,,,1 | ||
js> 9 in x | ||
false | ||
js> var r = x.splice(3, 4, 3, 4, 5) | ||
js> r | ||
,,, | ||
js> r.length | ||
4 | ||
js> 2 in r | ||
false | ||
js> x.length | ||
10 | ||
js> x | ||
2,,,3,4,5,,,,1 | ||
js> x[5] | ||
5 | ||
js> 8 in x | ||
false | ||
js> var s = x.slice(6, 8); | ||
js> s | ||
, | ||
js> s.length | ||
2 | ||
js> 1 in s | ||
false | ||
js> var y = [] | ||
js> y[9] = 1 | ||
1 | ||
js> var z = y.concat(x) | ||
js> z | ||
,,,,,,,,,1,2,,,3,4,5,,,,1 | ||
js> z.length | ||
20 | ||
js> 2 in z | ||
false | ||
js> 12 in z | ||
false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// test various array methods with sparse arrays | ||
js> var x = [] | ||
|
||
js> x.length = 101 | ||
101 | ||
js> x[100] = 1 | ||
1 | ||
js> x.length | ||
101 | ||
js> 0 in x | ||
false | ||
js> x.shift() | ||
js> x.length | ||
100 | ||
js> 0 in x | ||
false | ||
js> x | ||
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1 | ||
js> x.reverse() | ||
1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, | ||
js> x.length | ||
100 | ||
js> 10 in x | ||
false | ||
js> x.reverse() | ||
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1 | ||
js> x.length | ||
100 | ||
js> 10 in x | ||
false | ||
js> x.unshift(2) | ||
101 | ||
js> x | ||
2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1 | ||
js> 10 in x | ||
false | ||
js> var r = x.splice(50, 5, 3, 4, 5) | ||
js> r | ||
,,,, | ||
js> r.length | ||
5 | ||
js> 3 in r | ||
false | ||
js> x.length | ||
99 | ||
js> x | ||
2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3,4,5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1 | ||
js> x[50] | ||
3 | ||
js> 10 in x | ||
false | ||
js> var s = x.slice(60, 70); | ||
js> s | ||
,,,,,,,,, | ||
js> s.length | ||
10 | ||
js> 5 in s | ||
false | ||
js> var y = [] | ||
js> y.length = 100 | ||
100 | ||
js> var z = y.concat(x) | ||
js> z.length | ||
199 | ||
js> 30 in z | ||
false | ||
js> 130 in z | ||
false | ||
|
702abfe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️