-
Notifications
You must be signed in to change notification settings - Fork 516
tests for Iterator.prototype.join #4768
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
Open
bakkot
wants to merge
1
commit into
main
Choose a base branch
from
iterator-join
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+360
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
36 changes: 36 additions & 0 deletions
36
test/built-ins/Iterator/prototype/join/closes-on-contents-coercion-exception.js
This file contains hidden or 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,36 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join closes its receiver if coercing a value from the iterator throws. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| var throwy = { | ||
| toString: function () { | ||
| throw new Test262Error(); | ||
| }, | ||
| }; | ||
|
|
||
| var calledNextCount = 0; | ||
| var calledReturn = false; | ||
| var it = { | ||
| next: function () { | ||
| ++calledNextCount; | ||
| if (calledNextCount > 1) { | ||
| return { done: true, value: undefined }; | ||
| } | ||
| return { done: false, value: throwy }; | ||
| }, | ||
| return: function () { | ||
| calledReturn = true; | ||
| }, | ||
| }; | ||
|
|
||
| assert.throws(Test262Error, function () { | ||
| Iterator.prototype.join.call(it); | ||
| }); | ||
|
|
||
| assert.sameValue(calledNextCount, 1); | ||
| assert(calledReturn); |
33 changes: 33 additions & 0 deletions
33
test/built-ins/Iterator/prototype/join/closes-on-separator-coercion-exception.js
This file contains hidden or 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,33 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join closes its receiver if coercing the separator throws. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| var throwy = { | ||
| toString: function () { | ||
| throw new Test262Error(); | ||
| }, | ||
| }; | ||
|
|
||
| var gotNext = false; | ||
| var calledReturn = false; | ||
| var it = { | ||
| get next() { | ||
| // we use a variable instead of simply throwing because throwing is expected in this test | ||
| gotNext = true; | ||
| }, | ||
| return: function () { | ||
| calledReturn = true; | ||
| }, | ||
| }; | ||
|
|
||
| assert.throws(Test262Error, function () { | ||
| Iterator.prototype.join.call(it, throwy); | ||
| }); | ||
|
|
||
| assert.sameValue(gotNext, false); | ||
| assert(calledReturn); |
13 changes: 13 additions & 0 deletions
13
test/built-ins/Iterator/prototype/join/contents-nullish.js
This file contains hidden or 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,13 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join formats nullish iterator contents as an empty string. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| assert.sameValue( | ||
| ['one', null, 'two', undefined, 'three'].values().join(), | ||
| 'one,,two,,three' | ||
| ); |
22 changes: 22 additions & 0 deletions
22
test/built-ins/Iterator/prototype/join/contents-tostring.js
This file contains hidden or 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,22 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join coerces non-nullish iterator contents to string. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| var called = false; | ||
| var coercible = { | ||
| toString: function () { | ||
| if (called) { | ||
| throw new Test262Error('toString should be called exactly once'); | ||
| } | ||
| called = true; | ||
| return 'value'; | ||
| }, | ||
| }; | ||
|
|
||
| assert.sameValue([coercible, 0, true].values().join(), 'value,0,true'); | ||
| assert(called); |
This file contains hidden or 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,15 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join has default data property attributes. | ||
| includes: [propertyHelper.js] | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| verifyProperty(Iterator.prototype, 'join', { | ||
| enumerable: false, | ||
| writable: true, | ||
| configurable: true | ||
| }); |
24 changes: 24 additions & 0 deletions
24
test/built-ins/Iterator/prototype/join/does-not-close-on-iterator-error.js
This file contains hidden or 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,24 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join does not close its receiver if the iterator itself throws. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| var gotReturn = false; | ||
| var it = { | ||
| next: function () { | ||
| throw new Test262Error(); | ||
| }, | ||
| get return() { | ||
| gotReturn = true; | ||
| }, | ||
| }; | ||
|
|
||
| assert.throws(Test262Error, function () { | ||
| Iterator.prototype.join.call(it); | ||
| }); | ||
|
|
||
| assert.sameValue(gotReturn, false); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Iterator/prototype/join/does-not-close-on-iterator-exhaustion.js
This file contains hidden or 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,29 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join does not close its receiver if the iterator is exhausted. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| var calledNextCount = 0; | ||
| var gotReturn = false; | ||
| var it = { | ||
| next: function () { | ||
| ++calledNextCount; | ||
| if (calledNextCount > 2) { | ||
| return { done: true, value: undefined }; | ||
| } | ||
| return { done: false, value: 'ES' }; | ||
| }, | ||
| get return() { | ||
| gotReturn = true; | ||
| }, | ||
| }; | ||
|
|
||
| assert.sameValue(Iterator.prototype.join.call(it), 'ES,ES'); | ||
|
|
||
| assert.sameValue(calledNextCount, 3); | ||
|
|
||
| assert.sameValue(gotReturn, false); |
24 changes: 24 additions & 0 deletions
24
test/built-ins/Iterator/prototype/join/does-not-close-on-iterator-protocol-violation.js
This file contains hidden or 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,24 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join does not close its receiver if the iterator itself throws. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| var gotReturn = false; | ||
| var it = { | ||
| next: function () { | ||
| return null; | ||
| }, | ||
| get return() { | ||
| gotReturn = true; | ||
| }, | ||
| }; | ||
|
|
||
| assert.throws(TypeError, function () { | ||
| Iterator.prototype.join.call(it); | ||
| }); | ||
|
|
||
| assert.sameValue(gotReturn, false); |
This file contains hidden or 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,16 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join.length is 1. | ||
| includes: [propertyHelper.js] | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| verifyProperty(Iterator.prototype.join, 'length', { | ||
| value: 1, | ||
| enumerable: false, | ||
| writable: false, | ||
| configurable: true | ||
| }); |
This file contains hidden or 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,16 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join.name is "join". | ||
| includes: [propertyHelper.js] | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| verifyProperty(Iterator.prototype.join, 'name', { | ||
| value: 'join', | ||
| enumerable: false, | ||
| writable: false, | ||
| configurable: true | ||
| }); |
16 changes: 16 additions & 0 deletions
16
test/built-ins/Iterator/prototype/join/not-a-constructor.js
This file contains hidden or 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,16 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join is not a constructor | ||
| includes: [isConstructor.js] | ||
| features: [Iterator.prototype.join, Reflect.construct] | ||
| ---*/ | ||
|
|
||
| assert(!isConstructor(Iterator.prototype.join), "Iterator.prototype.join should not be a constructor"); | ||
|
|
||
| assert.throws(TypeError, function() { | ||
| var iterator = [].values(); | ||
| new iterator.join(); | ||
| }); |
38 changes: 38 additions & 0 deletions
38
test/built-ins/Iterator/prototype/join/receiver-not-object.js
This file contains hidden or 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,38 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join throws if the receiver is not an object. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| var it = [].values(); | ||
|
|
||
| assert.throws(TypeError, function () { | ||
| it.join.call(undefined); | ||
| }); | ||
|
|
||
| assert.throws(TypeError, function () { | ||
| it.join.call(null); | ||
| }); | ||
|
|
||
| assert.throws(TypeError, function () { | ||
| it.join.call(false); | ||
| }); | ||
|
|
||
| assert.throws(TypeError, function () { | ||
| it.join.call(0); | ||
| }); | ||
|
|
||
| assert.throws(TypeError, function () { | ||
| it.join.call(0n); | ||
| }); | ||
|
|
||
| assert.throws(TypeError, function () { | ||
| it.join.call(""); | ||
| }); | ||
|
|
||
| assert.throws(TypeError, function () { | ||
| it.join.call(Symbol()); | ||
| }); |
16 changes: 16 additions & 0 deletions
16
test/built-ins/Iterator/prototype/join/results-empty-separator.js
This file contains hidden or 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,16 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join allows empty string as separator. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| assert.sameValue([].values().join(''), ''); | ||
|
|
||
| assert.sameValue(['one'].values().join(''), 'one'); | ||
|
|
||
| assert.sameValue(['one', 'two'].values().join(''), 'onetwo'); | ||
|
|
||
| assert.sameValue(['one', 'two', 'three'].values().join(''), 'onetwothree'); |
16 changes: 16 additions & 0 deletions
16
test/built-ins/Iterator/prototype/join/results-no-separator.js
This file contains hidden or 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,16 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join joins using a comma if no separator is passed. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| assert.sameValue([].values().join(), ''); | ||
|
|
||
| assert.sameValue(['one'].values().join(), 'one'); | ||
|
|
||
| assert.sameValue(['one', 'two'].values().join(), 'one,two'); | ||
|
|
||
| assert.sameValue(['one', 'two', 'three'].values().join(), 'one,two,three'); |
16 changes: 16 additions & 0 deletions
16
test/built-ins/Iterator/prototype/join/results-nonempty-separator.js
This file contains hidden or 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,16 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join joins using the passed separator. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| assert.sameValue([].values().join('&&'), ''); | ||
|
|
||
| assert.sameValue(['one'].values().join('&&'), 'one'); | ||
|
|
||
| assert.sameValue(['one', 'two'].values().join('&&'), 'one&&two'); | ||
|
|
||
| assert.sameValue(['one', 'two', 'three'].values().join('&&'), 'one&&two&&three'); |
26 changes: 26 additions & 0 deletions
26
test/built-ins/Iterator/prototype/join/separator-tostring.js
This file contains hidden or 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,26 @@ | ||
| // Copyright (C) 2025 Kevin Gibbons. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-iterator.prototype.join | ||
| description: Iterator.prototype.join coerces the passed separator to a string. | ||
| features: [Iterator.prototype.join] | ||
| ---*/ | ||
|
|
||
| var called = false; | ||
| var coercible = { | ||
| toString: function () { | ||
| if (called) { | ||
| throw new Test262Error('toString should be called exactly once'); | ||
| } | ||
| called = true; | ||
| return '&&'; | ||
| }, | ||
| }; | ||
|
|
||
| assert.sameValue(['one', 'two', 'three'].values().join(coercible), 'one&&two&&three'); | ||
| assert(called); | ||
|
|
||
| assert.sameValue(['one', 'two', 'three'].values().join(undefined), 'one,two,three'); | ||
|
|
||
| assert.sameValue(['one', 'two', 'three'].values().join(null), 'onenulltwonullthree'); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.