diff options
Diffstat (limited to 'deps/v8/test/intl/regress-9747.js')
-rw-r--r-- | deps/v8/test/intl/regress-9747.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/deps/v8/test/intl/regress-9747.js b/deps/v8/test/intl/regress-9747.js new file mode 100644 index 0000000000..8b51ddc275 --- /dev/null +++ b/deps/v8/test/intl/regress-9747.js @@ -0,0 +1,50 @@ +// Copyright 2019 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +let lf = new Intl.ListFormat("en"); + +// Test normal array +assertDoesNotThrow(() => lf.format(['a','b','c'])); +assertThrows("lf.format(['a','b',3])", TypeError, "Iterable yielded 3 which is not a string"); + +// Test sparse array +let sparse = ['a','b']; +sparse[10] = 'c'; +assertThrows("lf.format(sparse)", TypeError, "Iterable yielded undefined which is not a string"); + +// Test iterable of all String +let iterable_of_strings = { + [Symbol.iterator]() { + return this; + }, + count: 0, + next() { + if (this.count++ < 4) { + return {done: false, value: String(this.count)}; + } + return {done:true} + } +}; +assertDoesNotThrow(() => lf.format(iterable_of_strings)); + +// Test iterable of none String throw TypeError +let iterable_of_strings_and_number = { + [Symbol.iterator]() { + return this; + }, + count: 0, + next() { + this.count++; + if (this.count == 3) { + return {done:false, value: 3}; + } + if (this.count < 5) { + return {done: false, value: String(this.count)}; + } + return {done:true} + } +}; +assertThrows("lf.format(iterable_of_strings_and_number)", + TypeError, "Iterable yielded 3 which is not a string"); +assertEquals(3, iterable_of_strings_and_number.count); |