options-style-toString-abrupt-throws.js (1771B)
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 GetOption style 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 ... 29 features: [Intl.DisplayNames, Symbol] 30 locale: [en] 31 ---*/ 32 33 var options = { 34 style: { 35 toString() { 36 throw new Test262Error(); 37 } 38 } 39 }; 40 41 assert.throws(Test262Error, () => { 42 new Intl.DisplayNames('en', options); 43 }, 'from toString'); 44 45 options.style = { 46 toString: undefined, 47 valueOf() { 48 throw new Test262Error(); 49 } 50 }; 51 52 assert.throws(Test262Error, () => { 53 new Intl.DisplayNames('en', options); 54 }, 'from valueOf'); 55 56 options.style = { 57 [Symbol.toPrimitive]() { 58 throw new Test262Error(); 59 } 60 }; 61 62 assert.throws(Test262Error, () => { 63 new Intl.DisplayNames('en', options); 64 }, 'from ToPrimitive'); 65 66 options.style = Symbol(); 67 68 assert.throws(TypeError, () => { 69 new Intl.DisplayNames('en', options); 70 }, 'symbol value'); 71 72 reportCompare(0, 0);