regress-9747.js 1.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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);