js/src/tests/test262/intl402/ch11/11.1/11.1.2.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/test262/intl402/ch11/11.1/11.1.2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,30 @@
     1.4 +// Copyright 2011-2012 Norbert Lindenberg. All rights reserved.
     1.5 +// Copyright 2012 Mozilla Corporation. All rights reserved.
     1.6 +// This code is governed by the BSD license found in the LICENSE file.
     1.7 +
     1.8 +/**
     1.9 + * @description Tests that Intl.NumberFormat can be subclassed.
    1.10 + * @author Norbert Lindenberg
    1.11 + */
    1.12 +
    1.13 +$INCLUDE("testIntl.js");
    1.14 +
    1.15 +// get a number format and have it format an array of numbers for comparison with the subclass
    1.16 +var locales = ["tlh", "id", "en"];
    1.17 +var a = [0, 1, -1, -123456.789, -Infinity, NaN];
    1.18 +var referenceNumberFormat = new Intl.NumberFormat(locales);
    1.19 +var referenceFormatted = a.map(referenceNumberFormat.format);
    1.20 +
    1.21 +function MyNumberFormat(locales, options) {
    1.22 +    Intl.NumberFormat.call(this, locales, options);
    1.23 +    // could initialize MyNumberFormat properties
    1.24 +}
    1.25 +
    1.26 +MyNumberFormat.prototype = Object.create(Intl.NumberFormat.prototype);
    1.27 +MyNumberFormat.prototype.constructor = MyNumberFormat;
    1.28 +// could add methods to MyNumberFormat.prototype
    1.29 +
    1.30 +var format = new MyNumberFormat(locales);
    1.31 +var actual = a.map(format.format);
    1.32 +testArraysAreSame(referenceFormatted, actual);
    1.33 +

mercurial