| 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 localeMatcher 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 |
GetOption ( options, property, type, values, fallback ) |
| 23 |
|
| 24 |
1. Let value be ? Get(options, property). |
| 25 |
2. If value is not undefined, then |
| 26 |
... |
| 27 |
c. If type is "string", then |
| 28 |
i. Let value be ? ToString(value). |
| 29 |
d. If values is not undefined, then |
| 30 |
i. If values does not contain an element equal to value, throw a RangeError exception. |
| 31 |
... |
| 32 |
features: [Intl.DisplayNames] |
| 33 |
locale: [en] |
| 34 |
---*/ |
| 35 |
|
| 36 |
var options = { |
| 37 |
localeMatcher: 'bestfit' // not "best fit" |
| 38 |
}; |
| 39 |
|
| 40 |
assert.throws(RangeError, () => { |
| 41 |
new Intl.DisplayNames('en', options); |
| 42 |
}, 'bestfit'); |
| 43 |
|
| 44 |
options.localeMatcher = 'look up'; |
| 45 |
|
| 46 |
assert.throws(RangeError, () => { |
| 47 |
new Intl.DisplayNames('en', options); |
| 48 |
}, 'look up'); |
| 49 |
|
| 50 |
options.localeMatcher = null; |
| 51 |
|
| 52 |
assert.throws(RangeError, () => { |
| 53 |
new Intl.DisplayNames('en', options); |
| 54 |
}, 'null'); |
| 55 |
|
| 56 |
options.localeMatcher = ''; |
| 57 |
|
| 58 |
assert.throws(RangeError, () => { |
| 59 |
new Intl.DisplayNames('en', options); |
| 60 |
}, 'the empty string'); |
| 61 |
|
| 62 |
// The world could burn |
| 63 |
options.localeMatcher = ['lookup', 'best fit']; |
| 64 |
|
| 65 |
assert.throws(RangeError, () => { |
| 66 |
new Intl.DisplayNames('en', options); |
| 67 |
}, 'an array with the valid options is not necessarily valid'); |
| 68 |
|
| 69 |
reportCompare(0, 0); |