|
13 | 13 |
|
14 | 14 | (function (global, factory) {
|
15 | 15 | var IntlPolyfill = factory();
|
| 16 | + |
16 | 17 | // register in -all- the module systems (at once)
|
17 |
| - if (typeof define === 'function' && define.amd) { |
| 18 | + if (typeof define === 'function' && define.amd) |
18 | 19 | define(IntlPolyfill);
|
19 |
| - } |
20 |
| - if (typeof exports === 'object') { |
| 20 | + |
| 21 | + if (typeof exports === 'object') |
21 | 22 | module.exports = IntlPolyfill;
|
22 |
| - } |
| 23 | + |
23 | 24 | if (!global.Intl) {
|
24 | 25 | global.Intl = IntlPolyfill;
|
| 26 | + IntlPolyfill.__applyLocaleSensitivePrototypes(); |
25 | 27 | }
|
| 28 | + |
26 | 29 | global.IntlPolyfill = IntlPolyfill;
|
| 30 | + |
27 | 31 | })(typeof global !== 'undefined' ? global : this, function() {
|
28 | 32 | "use strict";
|
29 | 33 | var
|
|
40 | 44 | // We use this a lot (and need it for proto-less objects)
|
41 | 45 | hop = Object.prototype.hasOwnProperty,
|
42 | 46 |
|
43 |
| - // Determine whether we need to override ECMA-262 locale sensitive functions |
44 |
| - overrideTLS = (function () { |
45 |
| - try { (0).toLocaleString(null); return true; } catch (e) { return false; } |
46 |
| - })(), |
47 |
| - |
48 | 47 | // Naive defineProperty for compatibility
|
49 | 48 | defineProperty = realDefineProp ? Object.defineProperty : function (obj, name, desc) {
|
50 | 49 | if ('get' in desc && obj.__defineGetter__)
|
@@ -2769,16 +2768,18 @@ var ls = Intl.__localeSensitiveProtos = {
|
2769 | 2768 | return FormatDateTime(dateTimeFormat, x);
|
2770 | 2769 | };
|
2771 | 2770 |
|
2772 |
| -// Where native locale-sensitive functions do not follow ECMA-402 section 13, |
2773 |
| -// Intl.js will override them automatically |
2774 |
| -if (overrideTLS) { |
2775 |
| - defineProperty(Number.prototype, 'toLocaleString', { writable: true, configurable: true, value: ls.Number.toLocaleString }); |
| 2771 | +defineProperty(Intl, '__applyLocaleSensitivePrototypes', { |
| 2772 | + writable: true, |
| 2773 | + configurable: true, |
| 2774 | + value: function () { |
| 2775 | + defineProperty(Number.prototype, 'toLocaleString', { writable: true, configurable: true, value: ls.Number.toLocaleString }); |
2776 | 2776 |
|
2777 |
| - for (var k in ls.Date) { |
2778 |
| - if (hop.call(ls.Date, k)) |
2779 |
| - defineProperty(Date.prototype, k, { writable: true, configurable: true, value: ls.Date[k] }); |
| 2777 | + for (var k in ls.Date) { |
| 2778 | + if (hop.call(ls.Date, k)) |
| 2779 | + defineProperty(Date.prototype, k, { writable: true, configurable: true, value: ls.Date[k] }); |
| 2780 | + } |
2780 | 2781 | }
|
2781 |
| -} |
| 2782 | +}); |
2782 | 2783 |
|
2783 | 2784 | /**
|
2784 | 2785 | * Can't really ship a single script with data for hundreds of locales, so we provide
|
|
0 commit comments