diff --git a/test/intl/segmenter/segment-iterator-ownPropertyDescriptor.js b/test/intl/segmenter/segment-iterator-ownPropertyDescriptor.js index e9630060a4..7409382a99 100644 --- a/test/intl/segmenter/segment-iterator-ownPropertyDescriptor.js +++ b/test/intl/segmenter/segment-iterator-ownPropertyDescriptor.js @@ -29,10 +29,47 @@ for (let func of ["segment", "resolvedOptions"]) { assertTrue(descriptor.configurable); } -let prototype = Object.getPrototypeOf(seg.segment('text')); +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); +}