Chromium Code Reviews| 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 | |
| 48 /** | 53 /** |
| 49 * Caches available locales for each service. | 54 * Caches available locales for each service. |
| 50 */ | 55 */ |
| 51 var AVAILABLE_LOCALES = { | 56 var AVAILABLE_LOCALES = { |
| 52 'collator': undefined, | 57 'collator': undefined, |
| 53 'numberformat': undefined, | 58 'numberformat': undefined, |
| 54 'dateformat': undefined, | 59 'dateformat': undefined, |
| 55 'breakiterator': undefined | 60 'breakiterator': undefined |
| 56 }; | 61 }; |
| 57 | 62 |
| (...skipping 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1980 writable: true, | 1985 writable: true, |
| 1981 configurable: true, | 1986 configurable: true, |
| 1982 enumerable: false | 1987 enumerable: false |
| 1983 }); | 1988 }); |
| 1984 %FunctionSetName($String.prototype.localeCompare, 'localeCompare'); | 1989 %FunctionSetName($String.prototype.localeCompare, 'localeCompare'); |
| 1985 %FunctionRemovePrototype($String.prototype.localeCompare); | 1990 %FunctionRemovePrototype($String.prototype.localeCompare); |
| 1986 %SetNativeFlag($String.prototype.localeCompare); | 1991 %SetNativeFlag($String.prototype.localeCompare); |
| 1987 | 1992 |
| 1988 | 1993 |
| 1989 /** | 1994 /** |
| 1995 * Unicode normalization. This method is called with one argument that | |
| 1996 * specifies the normalization form. | |
| 1997 * If none is specified, "NFC" is assumed. | |
| 1998 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw | |
| 1999 * a RangeError Exception. | |
| 2000 */ | |
| 2001 $Object.defineProperty($String.prototype, 'normalize', { | |
| 2002 value: function(that) { | |
| 2003 if (%_IsConstructCall()) { | |
| 2004 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); | |
| 2005 } | |
| 2006 | |
| 2007 if (IS_NULL_OR_UNDEFINED(this)) { | |
|
mathias
2014/01/29 09:03:38
You should use `CHECK_OBJECT_COERCIBLE` here as pe
| |
| 2008 throw new $TypeError('Method invoked on undefined or null value.'); | |
| 2009 } | |
| 2010 | |
| 2011 var form = $String(%_Arguments(0) || 'NFC'); | |
| 2012 | |
| 2013 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); | |
| 2014 if (normalizationForm === -1) { | |
| 2015 throw new $RangeError('The normalization form should be one of ' | |
| 2016 + NORMALIZATION_FORMS.join(', ') + '.'); | |
| 2017 } | |
| 2018 | |
| 2019 return %StringNormalize(this, normalizationForm); | |
| 2020 }, | |
| 2021 writable: true, | |
| 2022 configurable: true, | |
| 2023 enumerable: false | |
| 2024 }); | |
| 2025 %FunctionSetName($String.prototype.normalize, 'normalize'); | |
| 2026 %FunctionRemovePrototype($String.prototype.normalize); | |
| 2027 %SetNativeFlag($String.prototype.normalize); | |
| 2028 | |
| 2029 | |
| 2030 /** | |
| 1990 * Formats a Number object (this) using locale and options values. | 2031 * Formats a Number object (this) using locale and options values. |
| 1991 * If locale or options are omitted, defaults are used. | 2032 * If locale or options are omitted, defaults are used. |
| 1992 */ | 2033 */ |
| 1993 $Object.defineProperty($Number.prototype, 'toLocaleString', { | 2034 $Object.defineProperty($Number.prototype, 'toLocaleString', { |
| 1994 value: function() { | 2035 value: function() { |
| 1995 if (%_IsConstructCall()) { | 2036 if (%_IsConstructCall()) { |
| 1996 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); | 2037 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
| 1997 } | 2038 } |
| 1998 | 2039 |
| 1999 if (!(this instanceof $Number) && typeof(this) !== 'number') { | 2040 if (!(this instanceof $Number) && typeof(this) !== 'number') { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2104 writable: true, | 2145 writable: true, |
| 2105 configurable: true, | 2146 configurable: true, |
| 2106 enumerable: false | 2147 enumerable: false |
| 2107 }); | 2148 }); |
| 2108 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); | 2149 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); |
| 2109 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); | 2150 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); |
| 2110 %SetNativeFlag($Date.prototype.toLocaleTimeString); | 2151 %SetNativeFlag($Date.prototype.toLocaleTimeString); |
| 2111 | 2152 |
| 2112 return Intl; | 2153 return Intl; |
| 2113 }())}); | 2154 }())}); |
| OLD | NEW |