summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Intl/getCanonicalLocales/overriden-arg-length.js
blob: 12d4e8c56710d901b798b7f9cb8d335602896e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2016 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.

/*---
esid: sec-intl.getcanonicallocales
description: Test Intl.getCanonicalLocales for step 5. 
info: |
  9.2.1 CanonicalizeLocaleList (locales)
    5. Let len be ? ToLength(? Get(O, "length")).
includes: [compareArray.js]
features: [Symbol]
---*/

var locales = {
  '0': 'en-US',
};

Object.defineProperty(locales, "length", {
  get: function() { throw new Test262Error() }
});

assert.throws(Test262Error, function() {
  Intl.getCanonicalLocales(locales);
}, "should throw if locales.length throws");

var locales = {
  '0': 'en-US',
  '1': 'pt-BR',
};

Object.defineProperty(locales, "length", {
  get: function() { return "1" }
});

assert(compareArray(Intl.getCanonicalLocales(locales), ['en-US']),
  "should return one element if locales.length is '1'");

var locales = {
  '0': 'en-US',
  '1': 'pt-BR',
};

Object.defineProperty(locales, "length", {
  get: function() { return 1.3 }
});

assert(compareArray(Intl.getCanonicalLocales(locales), ['en-US']),
  "should return one element if locales.length is 1.3");

var locales = {
  '0': 'en-US',
  '1': 'pt-BR',
};

Object.defineProperty(locales, "length", {
  get: function() { return Symbol("1.8") }
});

assert.throws(TypeError, function() {
  Intl.getCanonicalLocales(locales);
}, "should throw if locales.length is a Symbol");

var locales = {
  '0': 'en-US',
  '1': 'pt-BR',
};

Object.defineProperty(locales, "length", {
  get: function() { return -Infinity }
});

assert(compareArray(Intl.getCanonicalLocales(locales), []),
  "should return empty array if locales.length is -Infinity");

var locales = {
  length: -Math.pow(2, 32) + 1
};

Object.defineProperty(locales, "0", {
  get: function() { throw new Error("must not be gotten!"); }
})

assert(compareArray(Intl.getCanonicalLocales(locales), []),
  "should return empty array if locales.length is a negative value");

var count = 0;
var locs = { get length() { if (count++ > 0) throw 42; return 0; } };
var locales = Intl.getCanonicalLocales(locs); // shouldn't throw 42
assert.sameValue(locales.length, 0);

reportCompare(0, 0);