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.
|
|
|
|
|
|
|
|
// Flags: --harmony-intl-segmenter
|
|
|
|
|
|
|
|
let seg = new Intl.Segmenter();
|
|
|
|
let descriptor = Object.getOwnPropertyDescriptor(
|
|
|
|
Intl.Segmenter, "supportedLocalesOf");
|
|
|
|
assertTrue(descriptor.writable);
|
|
|
|
assertFalse(descriptor.enumerable);
|
|
|
|
assertTrue(descriptor.configurable);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2018-10-19 22:17:36 +00:00
|
|
|
let segmentIterator = seg.segment('text');
|
|
|
|
let prototype = Object.getPrototypeOf(segmentIterator);
|
2018-10-18 07:59:28 +00:00
|
|
|
for (let func of ["next", "following", "preceding"]) {
|
|
|
|
let descriptor = Object.getOwnPropertyDescriptor(prototype, func);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the descriptor is correct for properties.
|
2018-12-17 23:09:06 +00:00
|
|
|
checkGetterProperty(prototype, 'index');
|
2018-10-19 22:17:36 +00:00
|
|
|
checkGetterProperty(prototype, 'breakType');
|
|
|
|
|
|
|
|
// Test the SegmentIteratorPrototype methods are called with same
|
|
|
|
// receiver and won't throw.
|
|
|
|
assertDoesNotThrow(() => prototype.next.call(segmentIterator));
|
|
|
|
assertDoesNotThrow(() => prototype.following.call(segmentIterator));
|
|
|
|
assertDoesNotThrow(() => prototype.preceding.call(segmentIterator));
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
prototype,
|
|
|
|
new Intl.Segmenter(),
|
|
|
|
new Intl.Collator(),
|
|
|
|
new Intl.DateTimeFormat(),
|
|
|
|
new Intl.NumberFormat(),
|
|
|
|
];
|
|
|
|
for (let rec of otherReceivers) {
|
|
|
|
assertThrows(() => prototype.next.call(rec), TypeError);
|
|
|
|
assertThrows(() => prototype.following.call(rec), TypeError);
|
|
|
|
assertThrows(() => prototype.preceding.call(rec), TypeError);
|
|
|
|
}
|
2018-10-23 22:41:47 +00:00
|
|
|
|
|
|
|
// Check the property of the return object of next()
|
|
|
|
let nextReturn = segmentIterator.next();
|
|
|
|
|
|
|
|
function checkProperty(obj, property) {
|
|
|
|
let desc = Object.getOwnPropertyDescriptor(obj, property);
|
|
|
|
assertTrue(desc.writable);
|
|
|
|
assertTrue(desc.enumerable);
|
|
|
|
assertTrue(desc.configurable);
|
|
|
|
}
|
|
|
|
|
|
|
|
checkProperty(nextReturn, 'done');
|
|
|
|
checkProperty(nextReturn, 'value');
|
|
|
|
checkProperty(nextReturn.value, 'segment');
|
|
|
|
checkProperty(nextReturn.value, 'breakType');
|
2018-12-17 23:09:06 +00:00
|
|
|
checkProperty(nextReturn.value, 'index');
|