Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/intl402/Intl/getCanonicalLocales/overriden-arg-length.js

raw
1 // Copyright 2016 Mozilla Corporation. All rights reserved.
2 // This code is governed by the license found in the LICENSE file.
3
4 /*---
5 esid: sec-intl.getcanonicallocales
6 description: Test Intl.getCanonicalLocales for step 5.
7 info: |
8 9.2.1 CanonicalizeLocaleList (locales)
9 5. Let len be ? ToLength(? Get(O, "length")).
10 includes: [compareArray.js]
11 features: [Symbol]
12 ---*/
13
14 var locales = {
15 '0': 'en-US',
16 };
17
18 Object.defineProperty(locales, "length", {
19 get: function() { throw new Test262Error() }
20 });
21
22 assert.throws(Test262Error, function() {
23 Intl.getCanonicalLocales(locales);
24 }, "should throw if locales.length throws");
25
26 var locales = {
27 '0': 'en-US',
28 '1': 'pt-BR',
29 };
30
31 Object.defineProperty(locales, "length", {
32 get: function() { return "1" }
33 });
34
35 assert(compareArray(Intl.getCanonicalLocales(locales), ['en-US']),
36 "should return one element if locales.length is '1'");
37
38 var locales = {
39 '0': 'en-US',
40 '1': 'pt-BR',
41 };
42
43 Object.defineProperty(locales, "length", {
44 get: function() { return 1.3 }
45 });
46
47 assert(compareArray(Intl.getCanonicalLocales(locales), ['en-US']),
48 "should return one element if locales.length is 1.3");
49
50 var locales = {
51 '0': 'en-US',
52 '1': 'pt-BR',
53 };
54
55 Object.defineProperty(locales, "length", {
56 get: function() { return Symbol("1.8") }
57 });
58
59 assert.throws(TypeError, function() {
60 Intl.getCanonicalLocales(locales);
61 }, "should throw if locales.length is a Symbol");
62
63 var locales = {
64 '0': 'en-US',
65 '1': 'pt-BR',
66 };
67
68 Object.defineProperty(locales, "length", {
69 get: function() { return -Infinity }
70 });
71
72 assert(compareArray(Intl.getCanonicalLocales(locales), []),
73 "should return empty array if locales.length is -Infinity");
74
75 var locales = {
76 length: -Math.pow(2, 32) + 1
77 };
78
79 Object.defineProperty(locales, "0", {
80 get: function() { throw new Error("must not be gotten!"); }
81 })
82
83 assert(compareArray(Intl.getCanonicalLocales(locales), []),
84 "should return empty array if locales.length is a negative value");
85
86 var count = 0;
87 var locs = { get length() { if (count++ > 0) throw 42; return 0; } };
88 var locales = Intl.getCanonicalLocales(locs); // shouldn't throw 42
89 assert.sameValue(locales.length, 0);