| 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 style 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. If options is undefined, then |
| 16 |
a. Let options be ObjectCreate(null). |
| 17 |
5. Else |
| 18 |
a. Let options be ? ToObject(options). |
| 19 |
... |
| 20 |
8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). |
| 21 |
... |
| 22 |
11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). |
| 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 |
var options = { |
| 40 |
style: 'small' |
| 41 |
}; |
| 42 |
|
| 43 |
assert.throws(RangeError, () => { |
| 44 |
new Intl.DisplayNames('en', options); |
| 45 |
}, 'small'); |
| 46 |
|
| 47 |
options.style = 'very long'; |
| 48 |
|
| 49 |
assert.throws(RangeError, () => { |
| 50 |
new Intl.DisplayNames('en', options); |
| 51 |
}, 'very long'); |
| 52 |
|
| 53 |
options.style = 'full'; |
| 54 |
|
| 55 |
assert.throws(RangeError, () => { |
| 56 |
new Intl.DisplayNames('en', options); |
| 57 |
}, 'full'); |
| 58 |
|
| 59 |
options.style = null; |
| 60 |
|
| 61 |
assert.throws(RangeError, () => { |
| 62 |
new Intl.DisplayNames('en', options); |
| 63 |
}, 'null'); |
| 64 |
|
| 65 |
options.style = ''; |
| 66 |
|
| 67 |
assert.throws(RangeError, () => { |
| 68 |
new Intl.DisplayNames('en', options); |
| 69 |
}, 'the empty string'); |
| 70 |
|
| 71 |
options.style = ['narrow', 'short', 'long']; |
| 72 |
|
| 73 |
assert.throws(RangeError, () => { |
| 74 |
new Intl.DisplayNames('en', options); |
| 75 |
}, 'an array with the valid options is not necessarily valid'); |
| 76 |
|
| 77 |
reportCompare(0, 0); |