summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/NumberFormat/constructor-locales-get-tostring.js
blob: d7bb6422c3427633091cfaad01cbc0598240073f (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
// Copyright (C) 2018 Ujjwal Sharma. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializenumberformat
description: >
  Tests that Get(O, P) and ToString(arg) are properly called within the
  constructor for Intl.NumberFormat
info: |
  9.2.1 CanonicalizeLocaleList ( locales )

  5. Let len be ? ToLength(? Get(O, "length")).

  7.a. Let Pk be ToString(k).

  7.c.i. Let kValue be ? Get(O, Pk).
---*/

const locales = {
  length: 8,
  1: 'en-US',
  3: 'de-DE',
  5: 'en-IN',
  7: 'en-GB'
};

const actualLookups = [];
const expectedLookups = Object.keys(locales);

const handlers = {
  get(obj, prop) {
    actualLookups.push(prop);
    return Reflect.get(...arguments);
  }
};

const proxyLocales = new Proxy(locales, handlers);

const nf = new Intl.NumberFormat(proxyLocales);

expectedLookups.forEach(lookup => assert(actualLookups.indexOf(lookup) != -1));

reportCompare(0, 0);