options-fallback-invalid-throws.js (2081B)
1 // Copyright (C) 2019 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-Intl.DisplayNames 6 description: > 7 Return abrupt completion from an invalid fallback option 8 info: | 9 Intl.DisplayNames ( locales , options ) 10 11 1. If NewTarget is undefined, throw a TypeError exception. 12 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", 13 « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). 14 ... 15 4. Let options be ? ToObject(options). 16 ... 17 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). 18 ... 19 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », "language"). 20 13. If type is undefined, throw a TypeError exception. 21 ... 22 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). 23 ... 24 25 GetOption ( options, property, type, values, fallback ) 26 27 1. Let value be ? Get(options, property). 28 2. If value is not undefined, then 29 ... 30 c. If type is "string", then 31 i. Let value be ? ToString(value). 32 d. If values is not undefined, then 33 i. If values does not contain an element equal to value, throw a RangeError exception. 34 ... 35 features: [Intl.DisplayNames] 36 locale: [en] 37 ---*/ 38 39 assert.throws(RangeError, () => { 40 new Intl.DisplayNames('en', {fallback: 'err', type: 'language'}); 41 }, 'err'); 42 43 assert.throws(RangeError, () => { 44 new Intl.DisplayNames('en', {fallback: 'non', type: 'language'}); 45 }, 'non, not none'); 46 47 assert.throws(RangeError, () => { 48 new Intl.DisplayNames('en', {fallback: null, type: 'language'}); 49 }, 'null'); 50 51 assert.throws(RangeError, () => { 52 new Intl.DisplayNames('en', {fallback: '', type: 'language'}); 53 }, 'the empty string'); 54 55 assert.throws(RangeError, () => { 56 new Intl.DisplayNames('en', {fallback: ['code', 'none'], type: 'language'}); 57 }, 'an array with the valid options is not necessarily valid'); 58 59 reportCompare(0, 0);