v8/test/intl/segmenter/segment-iterator-ownPropertyDescriptor.js
Frank Tang e76e44f088 [Intl] Add "position" to the return of next()
Add position to the return of %SegmentIterator%.next()
which newly added to the spec in
https://github.com/tc39/proposal-intl-segmenter/pull/42

Bug: v8:8305
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I8de7102acb670a6c529ab3e35601c78a8dc7703c
Reviewed-on: https://chromium-review.googlesource.com/c/1278636
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Daniel Ehrenberg <littledan@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56963}
2018-10-24 18:25:41 +00:00

92 lines
3.2 KiB
JavaScript

// 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);
}
let segmentIterator = seg.segment('text');
let prototype = Object.getPrototypeOf(segmentIterator);
for (let func of ["next", "following", "preceding"]) {
let descriptor = Object.getOwnPropertyDescriptor(prototype, func);
assertTrue(descriptor.writable);
assertFalse(descriptor.enumerable);
assertTrue(descriptor.configurable);
}
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.
checkGetterProperty(prototype, 'position');
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);
}
// 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');
checkProperty(nextReturn.value, 'position');