Skip to content

Commit fec9c40

Browse files
committed
Bug 2025779 - Import Iterator Includes tests; r=arai
These are from tc39/test262#5031 which is currently under review. Once the tests land upstream, these can be removed. This will be handled as part of shipping the feature when it reaches Stage 3. Differential Revision: https://phabricator.services.mozilla.com/D295351
1 parent 8d84993 commit fec9c40

53 files changed

Lines changed: 2008 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

js/src/tests/test262/prs/5031/browser.js

Whitespace-only changes.

js/src/tests/test262/prs/5031/built-ins/Iterator/browser.js

Whitespace-only changes.

js/src/tests/test262/prs/5031/built-ins/Iterator/prototype/browser.js

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// |reftest| shell-option(--enable-iterator-includes) skip-if(!Iterator.prototype.includes||!xulRuntime.shell) -- iterator-includes is not enabled unconditionally, requires shell-options
2+
// Copyright (C) 2026 Michael Ficarra. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
esid: sec-iterator.prototype.includes
6+
description: >
7+
Arguments and this value are validated in the correct order
8+
info: |
9+
Iterator.prototype.includes ( searchElement [ , skippedElements ] )
10+
11+
1. Let O be the this value.
12+
2. If O is not an Object, throw a TypeError exception.
13+
3. Let iterated be the Iterator Record { [[Iterator]]: O, [[NextMethod]]: undefined, [[Done]]: false }.
14+
4. If skippedElements is undefined, let toSkip be 0.
15+
5. Else if skippedElements is not one of +Infinity, -Infinity, or an integral Number,
16+
a. Let error be ThrowCompletion(a newly created TypeError object).
17+
b. Return ? IteratorClose(iterated, error).
18+
9. Set iterated to ? GetIteratorDirect(O).
19+
20+
includes: [compareArray.js]
21+
features: [iterator-includes]
22+
---*/
23+
24+
let effects = [];
25+
26+
assert.throws(TypeError, function() {
27+
Iterator.prototype.includes.call(null, 0, NaN);
28+
});
29+
30+
assert.compareArray(effects, []);
31+
32+
assert.throws(TypeError, function() {
33+
Iterator.prototype.includes.call(
34+
{
35+
get next() {
36+
effects.push('get next');
37+
return function() {
38+
return { done: true, value: undefined };
39+
};
40+
},
41+
return() {
42+
effects.push('return');
43+
return {};
44+
},
45+
},
46+
0,
47+
NaN
48+
);
49+
});
50+
51+
assert.compareArray(effects, ['return']);
52+
53+
effects = [];
54+
55+
Iterator.prototype.includes.call(
56+
{
57+
get next() {
58+
effects.push('get next');
59+
return function() {
60+
return { done: true, value: undefined };
61+
};
62+
},
63+
},
64+
0,
65+
0
66+
);
67+
68+
assert.compareArray(effects, ['get next']);
69+
70+
reportCompare(0, 0);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// |reftest| shell-option(--enable-iterator-includes) skip-if(!Iterator.prototype.includes||!xulRuntime.shell) -- iterator-includes is not enabled unconditionally, requires shell-options
2+
// Copyright (C) 2026 Michael Ficarra. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
esid: sec-iterator.prototype.includes
6+
description: >
7+
Underlying iterator is closed when skippedElements validation fails
8+
features: [iterator-includes]
9+
---*/
10+
11+
let closed = false;
12+
let closable = {
13+
__proto__: Iterator.prototype,
14+
get next() {
15+
throw new Test262Error('next should not be read');
16+
},
17+
return() {
18+
closed = true;
19+
return {};
20+
},
21+
};
22+
23+
assert.throws(RangeError, function() {
24+
closable.includes(null, -2);
25+
});
26+
assert.sameValue(closed, true, 'iterator closed when skippedElements validation produces a RangeError');
27+
28+
closed = false;
29+
assert.throws(TypeError, function() {
30+
closable.includes(null, 'a string');
31+
});
32+
assert.sameValue(closed, true, 'iterator closed when skippedElements validation produces a TypeError');
33+
34+
reportCompare(0, 0);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// |reftest| shell-option(--enable-iterator-includes) skip-if(!Iterator.prototype.includes||!xulRuntime.shell) -- iterator-includes is not enabled unconditionally, requires shell-options
2+
// Copyright (C) 2026 Michael Ficarra. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
esid: sec-iterator.prototype.includes
6+
description: >
7+
Basic positive and negative matches
8+
features: [iterator-includes]
9+
---*/
10+
11+
let arr = [3, 6, 9];
12+
13+
assert.sameValue(arr.values().includes(0), false);
14+
assert.sameValue(arr.values().includes(1), false);
15+
assert.sameValue(arr.values().includes(2), false);
16+
assert.sameValue(arr.values().includes(3), true);
17+
assert.sameValue(arr.values().includes(4), false);
18+
assert.sameValue(arr.values().includes(5), false);
19+
assert.sameValue(arr.values().includes(6), true);
20+
assert.sameValue(arr.values().includes(7), false);
21+
assert.sameValue(arr.values().includes(8), false);
22+
assert.sameValue(arr.values().includes(9), true);
23+
assert.sameValue(arr.values().includes(10), false);
24+
25+
reportCompare(0, 0);

js/src/tests/test262/prs/5031/built-ins/Iterator/prototype/includes/browser.js

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// |reftest| shell-option(--enable-iterator-includes) skip-if(!Iterator.prototype.includes||!xulRuntime.shell) -- iterator-includes is not enabled unconditionally, requires shell-options
2+
// Copyright (C) 2026 Michael Ficarra. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
esid: sec-iterator.prototype.includes
6+
description: >
7+
Iterator.prototype.includes is callable
8+
features: [iterator-includes]
9+
---*/
10+
11+
function* g() {
12+
yield 0;
13+
}
14+
15+
Iterator.prototype.includes.call(g(), 0);
16+
17+
g().includes(0);
18+
19+
reportCompare(0, 0);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// |reftest| shell-option(--enable-iterator-includes) skip-if(!Iterator.prototype.includes||!xulRuntime.shell) -- iterator-includes is not enabled unconditionally, requires shell-options
2+
// Copyright (C) 2026 Michael Ficarra. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
esid: sec-iterator.prototype.includes
6+
description: >
7+
Iterator.prototype.includes closes the iterator after a successful match
8+
features: [iterator-includes]
9+
---*/
10+
11+
let closed = false;
12+
let i = 0;
13+
let iter = {
14+
__proto__: Iterator.prototype,
15+
next() {
16+
++i;
17+
return { done: false, value: i };
18+
},
19+
return() {
20+
closed = true;
21+
return {};
22+
},
23+
};
24+
25+
assert.sameValue(iter.includes(5), true);
26+
assert.sameValue(closed, true);
27+
28+
reportCompare(0, 0);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// |reftest| shell-option(--enable-iterator-includes) skip-if(!Iterator.prototype.includes||!xulRuntime.shell) -- iterator-includes is not enabled unconditionally, requires shell-options
2+
// Copyright (C) 2026 Michael Ficarra. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
esid: sec-iterator.prototype.includes
6+
description: >
7+
Exhausting the iterator without finding a match does not call return
8+
features: [iterator-includes]
9+
---*/
10+
11+
let index = 0;
12+
let returnCalls = 0;
13+
14+
let iterator = {
15+
__proto__: Iterator.prototype,
16+
next() {
17+
++index;
18+
if (index <= 3) {
19+
return { done: false, value: index };
20+
}
21+
return { done: true, value: undefined };
22+
},
23+
return() {
24+
++returnCalls;
25+
return {};
26+
},
27+
};
28+
29+
assert.sameValue(iterator.includes(99), false);
30+
assert.sameValue(returnCalls, 0);
31+
32+
reportCompare(0, 0);

0 commit comments

Comments
 (0)