options-languagedisplay-toString-abrupt-throws.js (1753B)
1 // Copyright (C) 2021 the V8 project authors. 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 fallback 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 24. Let languageDisplay be ? GetOption(options, "languageDisplay", "string", « "dialect", "standard" », "dialect"). 20 ... 21 22 GetOption ( options, property, type, values, fallback ) 23 24 1. Let value be ? Get(options, property). 25 ... 26 features: [Intl.DisplayNames-v2, Symbol] 27 locale: [en] 28 ---*/ 29 30 assert.throws(Test262Error, () => { 31 new Intl.DisplayNames('en', { 32 type: 'language', languageDisplay: { toString() { throw new Test262Error(); }} 33 }); 34 }, 'from toString'); 35 36 assert.throws(Test262Error, () => { 37 new Intl.DisplayNames('en', { 38 type: 'language', 39 languageDisplay: {toString: undefined, valueOf() {throw new Test262Error(); }} 40 }); 41 }, 'from valueOf'); 42 43 assert.throws(Test262Error, () => { 44 new Intl.DisplayNames('en', { 45 type: 'language', 46 languageDisplay: { [Symbol.toPrimitive]() { throw new Test262Error(); } } 47 }); 48 }, 'from ToPrimitive'); 49 50 assert.throws(TypeError, () => { 51 new Intl.DisplayNames('en', { 52 type: 'language', 53 languageDisplay: Symbol() 54 }); 55 }, 'symbol value'); 56 57 reportCompare(0, 0);