OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 var Intl = {}; | 39 var Intl = {}; |
40 | 40 |
41 var undefined = global.undefined; | 41 var undefined = global.undefined; |
42 | 42 |
43 var AVAILABLE_SERVICES = ['collator', | 43 var AVAILABLE_SERVICES = ['collator', |
44 'numberformat', | 44 'numberformat', |
45 'dateformat', | 45 'dateformat', |
46 'breakiterator']; | 46 'breakiterator']; |
47 | 47 |
48 var NORMALIZATION_FORMS = ['NFC', | |
49 'NFD', | |
50 'NFKC', | |
51 'NFKD']; | |
52 | |
53 /** | 48 /** |
54 * Caches available locales for each service. | 49 * Caches available locales for each service. |
55 */ | 50 */ |
56 var AVAILABLE_LOCALES = { | 51 var AVAILABLE_LOCALES = { |
57 'collator': undefined, | 52 'collator': undefined, |
58 'numberformat': undefined, | 53 'numberformat': undefined, |
59 'dateformat': undefined, | 54 'dateformat': undefined, |
60 'breakiterator': undefined | 55 'breakiterator': undefined |
61 }; | 56 }; |
62 | 57 |
(...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1986 return compare(collator, this, that); | 1981 return compare(collator, this, that); |
1987 }, | 1982 }, |
1988 writable: true, | 1983 writable: true, |
1989 configurable: true, | 1984 configurable: true, |
1990 enumerable: false | 1985 enumerable: false |
1991 }); | 1986 }); |
1992 %FunctionSetName($String.prototype.localeCompare, 'localeCompare'); | 1987 %FunctionSetName($String.prototype.localeCompare, 'localeCompare'); |
1993 %FunctionRemovePrototype($String.prototype.localeCompare); | 1988 %FunctionRemovePrototype($String.prototype.localeCompare); |
1994 %SetNativeFlag($String.prototype.localeCompare); | 1989 %SetNativeFlag($String.prototype.localeCompare); |
1995 | 1990 |
1996 /** | |
1997 * Unicode normalization. This method is called with one argument that | |
1998 * specifies the normalization form. | |
1999 * If none is specified, "NFC" is assumed. | |
2000 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw | |
2001 * a RangeError Exception. | |
2002 */ | |
2003 $Object.defineProperty($String.prototype, 'normalize', { | |
2004 value: function(that) { | |
2005 if (%_IsConstructCall()) { | |
2006 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); | |
2007 } | |
2008 | |
2009 if (IS_NULL_OR_UNDEFINED(this)) { | |
2010 throw new $TypeError('Method invoked on undefined or null value.'); | |
2011 } | |
2012 | |
2013 var form = $String(%_Arguments(0) || 'NFC'); | |
2014 | |
2015 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); | |
2016 if (normalizationForm !== -1) { | |
2017 return %StringNormalize(this, normalizationForm); | |
2018 } | |
2019 throw new $RangeError('The normalization form should be one of ' | |
2020 + NORMALIZATION_FORMS.join(', ') + '.'); | |
2021 }, | |
2022 writable: true, | |
2023 configurable: true, | |
2024 enumerable: false | |
2025 }); | |
2026 %FunctionSetName($String.prototype.normalize, 'normalize'); | |
2027 %FunctionRemovePrototype($String.prototype.normalize); | |
2028 %SetNativeFlag($String.prototype.normalize); | |
2029 | |
2030 | 1991 |
2031 /** | 1992 /** |
2032 * Formats a Number object (this) using locale and options values. | 1993 * Formats a Number object (this) using locale and options values. |
2033 * If locale or options are omitted, defaults are used. | 1994 * If locale or options are omitted, defaults are used. |
2034 */ | 1995 */ |
2035 $Object.defineProperty($Number.prototype, 'toLocaleString', { | 1996 $Object.defineProperty($Number.prototype, 'toLocaleString', { |
2036 value: function() { | 1997 value: function() { |
2037 if (%_IsConstructCall()) { | 1998 if (%_IsConstructCall()) { |
2038 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); | 1999 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
2039 } | 2000 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2146 writable: true, | 2107 writable: true, |
2147 configurable: true, | 2108 configurable: true, |
2148 enumerable: false | 2109 enumerable: false |
2149 }); | 2110 }); |
2150 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); | 2111 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); |
2151 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); | 2112 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); |
2152 %SetNativeFlag($Date.prototype.toLocaleTimeString); | 2113 %SetNativeFlag($Date.prototype.toLocaleTimeString); |
2153 | 2114 |
2154 return Intl; | 2115 return Intl; |
2155 }())}); | 2116 }())}); |
OLD | NEW |