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 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // ECMAScript 402 API implementation. | 5 // ECMAScript 402 API implementation. |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Intl object is a single object that has some named properties, | 8 * Intl object is a single object that has some named properties, |
| 9 * all of which are constructors. | 9 * all of which are constructors. |
| 10 */ | 10 */ |
| (...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1988 ); | 1988 ); |
| 1989 | 1989 |
| 1990 | 1990 |
| 1991 /** | 1991 /** |
| 1992 * Unicode normalization. This method is called with one argument that | 1992 * Unicode normalization. This method is called with one argument that |
| 1993 * specifies the normalization form. | 1993 * specifies the normalization form. |
| 1994 * If none is specified, "NFC" is assumed. | 1994 * If none is specified, "NFC" is assumed. |
| 1995 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw | 1995 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw |
| 1996 * a RangeError Exception. | 1996 * a RangeError Exception. |
| 1997 */ | 1997 */ |
| 1998 OverrideFunction(GlobalString.prototype, 'normalize', function(form) { | |
| 1999 if (%_IsConstructCall()) { | |
| 2000 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | |
| 2001 } | |
| 2002 | 1998 |
| 2003 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); | 1999 function StringNormalizeJS(form) { |
| 2000 if (%_IsConstructCall()) { | |
| 2001 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | |
| 2002 } | |
| 2004 | 2003 |
| 2005 form = IS_UNDEFINED(form) ? 'NFC' : form; | 2004 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); |
| 2006 | 2005 |
| 2007 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; | 2006 form = IS_UNDEFINED(form) ? 'NFC' : form; |
| 2008 | 2007 |
| 2009 var normalizationForm = | 2008 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; |
| 2010 %_CallFunction(NORMALIZATION_FORMS, form, ArrayIndexOf); | |
| 2011 if (normalizationForm === -1) { | |
| 2012 throw MakeRangeError(kNormalizationForm, | |
| 2013 %_CallFunction(NORMALIZATION_FORMS, ', ', ArrayJoin)); | |
| 2014 } | |
| 2015 | 2009 |
| 2016 return %StringNormalize(this, normalizationForm); | 2010 var normalizationForm = |
| 2011 %_CallFunction(NORMALIZATION_FORMS, form, ArrayIndexOf); | |
| 2012 if (normalizationForm === -1) { | |
| 2013 throw MakeRangeError(kNormalizationForm, | |
| 2014 %_CallFunction(NORMALIZATION_FORMS, ', ', ArrayJoin)); | |
| 2017 } | 2015 } |
| 2018 ); | 2016 |
| 2017 return %StringNormalize(this, normalizationForm); | |
| 2018 } | |
| 2019 %FunctionSetLength(StringNormalizeJS, 0); | |
|
rossberg
2015/08/05 14:23:05
I'd prefer avoiding the runtime call and instead d
mathias
2015/08/05 14:28:11
Done.
| |
| 2020 OverrideFunction(GlobalString.prototype, 'normalize', StringNormalizeJS); | |
| 2019 | 2021 |
| 2020 | 2022 |
| 2021 /** | 2023 /** |
| 2022 * Formats a Number object (this) using locale and options values. | 2024 * Formats a Number object (this) using locale and options values. |
| 2023 * If locale or options are omitted, defaults are used. | 2025 * If locale or options are omitted, defaults are used. |
| 2024 */ | 2026 */ |
| 2025 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { | 2027 OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { |
| 2026 if (%_IsConstructCall()) { | 2028 if (%_IsConstructCall()) { |
| 2027 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2029 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
| 2028 } | 2030 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2105 } | 2107 } |
| 2106 | 2108 |
| 2107 var locales = %_Arguments(0); | 2109 var locales = %_Arguments(0); |
| 2108 var options = %_Arguments(1); | 2110 var options = %_Arguments(1); |
| 2109 return toLocaleDateTime( | 2111 return toLocaleDateTime( |
| 2110 this, locales, options, 'time', 'time', 'dateformattime'); | 2112 this, locales, options, 'time', 'time', 'dateformattime'); |
| 2111 } | 2113 } |
| 2112 ); | 2114 ); |
| 2113 | 2115 |
| 2114 }) | 2116 }) |
| OLD | NEW |