locales-length-tolength-throws.js (1896B)
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 Locales invalid length 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 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). 15 ... 16 17 CanonicalizeLocaleList ( locales ) 18 19 1. If locales is undefined, then 20 a. Return a new empty List. 21 2. Let seen be a new empty List. 22 3. If Type(locales) is String, then 23 a. Let O be CreateArrayFromList(« locales »). 24 4. Else, 25 a. Let O be ? ToObject(locales). 26 5. Let len be ? ToLength(? Get(O, "length")). 27 28 ToLength ( argument ) 29 30 1. Let len be ? ToInteger(argument). 31 ... 32 features: [Intl.DisplayNames, Symbol, BigInt] 33 ---*/ 34 35 var locales = { 36 length: { 37 valueOf() { 38 throw new Test262Error(); 39 } 40 } 41 }; 42 43 assert.throws(Test262Error, () => { 44 new Intl.DisplayNames(locales); 45 }, 'poisoned valueOf for ToNumber'); 46 47 locales.length = { 48 [Symbol.toPrimitive]() { 49 throw new Test262Error(); 50 } 51 }; 52 assert.throws(Test262Error, () => { 53 new Intl.DisplayNames(locales); 54 }, 'poisoned ToPrimitive for ToNumber'); 55 56 locales.length = { 57 toString() { 58 throw new Test262Error(); 59 } 60 }; 61 assert.throws(Test262Error, () => { 62 new Intl.DisplayNames(locales); 63 }, 'poisoned toString for ToNumber'); 64 65 locales.length = Symbol(); 66 assert.throws(TypeError, () => { 67 new Intl.DisplayNames(locales); 68 }, 'length is Symbol'); 69 70 locales.length = BigInt(1); 71 assert.throws(TypeError, () => { 72 new Intl.DisplayNames(locales); 73 }, 'length is BigInt'); 74 75 reportCompare(0, 0);