2018-10-18 07:59:28 +00:00
|
|
|
// Copyright 2018 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 seg = new Intl.Segmenter();
|
|
|
|
let descriptor = Object.getOwnPropertyDescriptor(
|
|
|
|
Intl.Segmenter, "supportedLocalesOf");
|
|
|
|
assertTrue(descriptor.writable);
|
|
|
|
assertFalse(descriptor.enumerable);
|
|
|
|
assertTrue(descriptor.configurable);
|
|
|
|
|
2020-07-29 15:06:31 +00:00
|
|
|
let segmenterPrototype = Object.getPrototypeOf(seg);
|
|
|
|
assertEquals("Intl.Segmenter", segmenterPrototype[Symbol.toStringTag]);
|
|
|
|
|
2018-10-18 07:59:28 +00:00
|
|
|
// ecma402 #sec-Intl.Segmenter.prototype
|
|
|
|
// Intl.Segmenter.prototype
|
|
|
|
// The value of Intl.Segmenter.prototype is %SegmenterPrototype%.
|
|
|
|
// This property has the attributes
|
|
|
|
// { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
|
|
|
|
descriptor = Object.getOwnPropertyDescriptor(Intl.Segmenter, "prototype");
|
|
|
|
assertFalse(descriptor.writable);
|
|
|
|
assertFalse(descriptor.enumerable);
|
|
|
|
assertFalse(descriptor.configurable);
|
|
|
|
|
|
|
|
for (let func of ["segment", "resolvedOptions"]) {
|
|
|
|
let descriptor = Object.getOwnPropertyDescriptor(
|
|
|
|
Intl.Segmenter.prototype, func);
|
|
|
|
assertTrue(descriptor.writable);
|
|
|
|
assertFalse(descriptor.enumerable);
|
|
|
|
assertTrue(descriptor.configurable);
|
|
|
|
}
|
|
|
|
|
2020-07-29 15:06:31 +00:00
|
|
|
|
|
|
|
let segments = seg.segment('text');
|
|
|
|
let segmentsPrototype = Object.getPrototypeOf(segments);
|
|
|
|
for (let func of ["containing", Symbol.iterator]) {
|
|
|
|
let descriptor = Object.getOwnPropertyDescriptor(segmentsPrototype, func);
|
2018-10-18 07:59:28 +00:00
|
|
|
assertTrue(descriptor.writable);
|
|
|
|
assertFalse(descriptor.enumerable);
|
|
|
|
assertTrue(descriptor.configurable);
|
|
|
|
}
|
2018-10-19 22:17:36 +00:00
|
|
|
|
|
|
|
function checkGetterProperty(prototype, property) {
|
|
|
|
let desc = Object.getOwnPropertyDescriptor(prototype, property);
|
|
|
|
assertEquals(`get ${property}`, desc.get.name);
|
|
|
|
assertEquals('function', typeof desc.get)
|
|
|
|
assertEquals(undefined, desc.set);
|
|
|
|
assertFalse(desc.enumerable);
|
|
|
|
assertTrue(desc.configurable);
|
|
|
|
}
|
|
|
|
|
2020-07-29 15:06:31 +00:00
|
|
|
// Test the SegmentsPrototype methods are called with same
|
2018-10-19 22:17:36 +00:00
|
|
|
// receiver and won't throw.
|
2020-07-29 15:06:31 +00:00
|
|
|
assertDoesNotThrow(() => segmentsPrototype.containing.call(segments));
|
|
|
|
assertDoesNotThrow(() => segmentsPrototype[Symbol.iterator].call(segments));
|
2018-10-19 22:17:36 +00:00
|
|
|
|
|
|
|
// Test the SegmentIteratorPrototype methods are called with a different
|
|
|
|
// receiver and correctly throw.
|
|
|
|
var otherReceivers = [
|
|
|
|
1, 123.45, undefined, null, "string", true, false,
|
|
|
|
Intl, Intl.Segmenter, Intl.Segmenter.prototype,
|
2020-07-29 15:06:31 +00:00
|
|
|
segmentsPrototype,
|
2018-10-19 22:17:36 +00:00
|
|
|
new Intl.Segmenter(),
|
|
|
|
new Intl.Collator(),
|
|
|
|
new Intl.DateTimeFormat(),
|
|
|
|
new Intl.NumberFormat(),
|
|
|
|
];
|
|
|
|
for (let rec of otherReceivers) {
|
2020-07-29 15:06:31 +00:00
|
|
|
assertThrows(() => segmentsPrototype.containing.call(rec), TypeError);
|
|
|
|
}
|
|
|
|
|
|
|
|
let segmentIterator = segments[Symbol.iterator]();
|
|
|
|
let segmentIteratorPrototype = Object.getPrototypeOf(segmentIterator);
|
|
|
|
for (let func of ["next"]) {
|
|
|
|
let descriptor = Object.getOwnPropertyDescriptor(segmentIteratorPrototype,
|
|
|
|
func);
|
|
|
|
assertTrue(descriptor.writable);
|
|
|
|
assertFalse(descriptor.enumerable);
|
|
|
|
assertTrue(descriptor.configurable);
|
2018-10-19 22:17:36 +00:00
|
|
|
}
|
2018-10-23 22:41:47 +00:00
|
|
|
|
2020-07-29 15:06:31 +00:00
|
|
|
assertEquals("Segmenter String Iterator",
|
|
|
|
segmentIteratorPrototype[Symbol.toStringTag]);
|
|
|
|
let desc = Object.getOwnPropertyDescriptor(
|
|
|
|
segmentIteratorPrototype, Symbol.toStringTag);
|
|
|
|
assertFalse(desc.writable);
|
|
|
|
assertFalse(desc.enumerable);
|
|
|
|
assertTrue(desc.configurable);
|
|
|
|
|
2018-10-23 22:41:47 +00:00
|
|
|
let nextReturn = segmentIterator.next();
|
|
|
|
|
|
|
|
function checkProperty(obj, property) {
|
|
|
|
let desc = Object.getOwnPropertyDescriptor(obj, property);
|
|
|
|
assertTrue(desc.writable);
|
|
|
|
assertTrue(desc.enumerable);
|
|
|
|
assertTrue(desc.configurable);
|
|
|
|
}
|