locales-symbol-length.js (1995B)
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 CanonicalizeLocaleList tries to fetch length from Object. 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 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). 17 13. If type is undefined, throw a TypeError exception. 18 ... 19 20 CanonicalizeLocaleList ( locales ) 21 22 1. If locales is undefined, then 23 a. Return a new empty List. 24 2. Let seen be a new empty List. 25 3. If Type(locales) is String, then 26 a. Let O be CreateArrayFromList(« locales »). 27 4. Else, 28 a. Let O be ? ToObject(locales). 29 5. Let len be ? ToLength(? Get(O, "length")). 30 features: [Intl.DisplayNames, Symbol] 31 locale: [en] 32 includes: [compareArray.js] 33 ---*/ 34 35 let calls = []; 36 let symbol = Symbol(); 37 38 Symbol.prototype.length = 1; 39 40 Object.defineProperty(Symbol.prototype, 'length', { 41 get() { 42 assert.notSameValue(this, symbol, 'this is an object from given symbol'); 43 assert.sameValue(this.valueOf(), symbol, 'internal value is the symbol'); 44 assert(this instanceof Symbol); 45 calls.push('length'); 46 return 1; 47 } 48 }); 49 50 Object.defineProperty(Symbol.prototype, '0', { 51 get() { 52 assert.notSameValue(this, symbol, 'this is an object from given symbol'); 53 assert.sameValue(this.valueOf(), symbol, 'internal value is the symbol'); 54 assert(this instanceof Symbol); 55 calls.push('0'); 56 return 'en'; 57 } 58 }); 59 60 new Intl.DisplayNames(symbol, {type: 'language'}); 61 62 assert.compareArray(calls, ['length', '0']); 63 64 reportCompare(0, 0);