Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: src/js/i18n.js

Issue 2023753002: Revert of [builtins] Also migrate String.prototype.toLowerCase/toUpperCase to C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@StringTrim
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/contexts.h ('k') | src/js/string.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 matching lines...) Expand all
39 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); 39 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty");
40 var OverrideFunction = utils.OverrideFunction; 40 var OverrideFunction = utils.OverrideFunction;
41 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); 41 var patternSymbol = utils.ImportNow("intl_pattern_symbol");
42 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); 42 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol");
43 var SetFunctionName = utils.SetFunctionName; 43 var SetFunctionName = utils.SetFunctionName;
44 var StringIndexOf; 44 var StringIndexOf;
45 var StringLastIndexOf; 45 var StringLastIndexOf;
46 var StringSplit; 46 var StringSplit;
47 var StringSubstr; 47 var StringSubstr;
48 var StringSubstring; 48 var StringSubstring;
49 var StringToLowerCase = GlobalString.prototype.toLowerCase;
50 var StringToUpperCase = GlobalString.prototype.toUpperCase;
51 49
52 utils.Import(function(from) { 50 utils.Import(function(from) {
53 ArrayIndexOf = from.ArrayIndexOf; 51 ArrayIndexOf = from.ArrayIndexOf;
54 ArrayJoin = from.ArrayJoin; 52 ArrayJoin = from.ArrayJoin;
55 ArrayPush = from.ArrayPush; 53 ArrayPush = from.ArrayPush;
56 IsFinite = from.IsFinite; 54 IsFinite = from.IsFinite;
57 IsNaN = from.IsNaN; 55 IsNaN = from.IsNaN;
58 MakeError = from.MakeError; 56 MakeError = from.MakeError;
59 MakeRangeError = from.MakeRangeError; 57 MakeRangeError = from.MakeRangeError;
60 MakeTypeError = from.MakeTypeError; 58 MakeTypeError = from.MakeTypeError;
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 if (!IS_UNDEFINED(value)) { 686 if (!IS_UNDEFINED(value)) {
689 defineWECProperty(object, property, value); 687 defineWECProperty(object, property, value);
690 } 688 }
691 } 689 }
692 690
693 691
694 /** 692 /**
695 * Returns titlecased word, aMeRricA -> America. 693 * Returns titlecased word, aMeRricA -> America.
696 */ 694 */
697 function toTitleCaseWord(word) { 695 function toTitleCaseWord(word) {
698 return %_Call(StringToUpperCase, %_Call(StringSubstr, word, 0, 1)) + 696 return %StringToUpperCase(%_Call(StringSubstr, word, 0, 1)) +
699 %_Call(StringToLowerCase, %_Call(StringSubstr, word, 1)); 697 %StringToLowerCase(%_Call(StringSubstr, word, 1));
700 } 698 }
701 699
702 /** 700 /**
703 * Returns titlecased location, bueNos_airES -> Buenos_Aires 701 * Returns titlecased location, bueNos_airES -> Buenos_Aires
704 * or ho_cHi_minH -> Ho_Chi_Minh. It is locale-agnostic and only 702 * or ho_cHi_minH -> Ho_Chi_Minh. It is locale-agnostic and only
705 * deals with ASCII only characters. 703 * deals with ASCII only characters.
706 * 'of', 'au' and 'es' are special-cased and lowercased. 704 * 'of', 'au' and 'es' are special-cased and lowercased.
707 */ 705 */
708 function toTitleCaseTimezoneLocation(location) { 706 function toTitleCaseTimezoneLocation(location) {
709 var match = InternalRegExpMatch(GetTimezoneNameLocationPartRE(), location) 707 var match = InternalRegExpMatch(GetTimezoneNameLocationPartRE(), location)
710 if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, location); 708 if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, location);
711 709
712 var result = toTitleCaseWord(match[1]); 710 var result = toTitleCaseWord(match[1]);
713 if (!IS_UNDEFINED(match[2]) && 2 < match.length) { 711 if (!IS_UNDEFINED(match[2]) && 2 < match.length) {
714 // The first character is a separator, '_' or '-'. 712 // The first character is a separator, '_' or '-'.
715 // None of IANA zone names has both '_' and '-'. 713 // None of IANA zone names has both '_' and '-'.
716 var separator = %_Call(StringSubstring, match[2], 0, 1); 714 var separator = %_Call(StringSubstring, match[2], 0, 1);
717 var parts = %_Call(StringSplit, match[2], separator); 715 var parts = %_Call(StringSplit, match[2], separator);
718 for (var i = 1; i < parts.length; i++) { 716 for (var i = 1; i < parts.length; i++) {
719 var part = parts[i] 717 var part = parts[i]
720 var lowercasedPart = %_Call(StringToLowerCase, part); 718 var lowercasedPart = %StringToLowerCase(part);
721 result = result + separator + 719 result = result + separator +
722 ((lowercasedPart !== 'es' && 720 ((lowercasedPart !== 'es' &&
723 lowercasedPart !== 'of' && lowercasedPart !== 'au') ? 721 lowercasedPart !== 'of' && lowercasedPart !== 'au') ?
724 toTitleCaseWord(part) : lowercasedPart); 722 toTitleCaseWord(part) : lowercasedPart);
725 } 723 }
726 } 724 }
727 return result; 725 return result;
728 } 726 }
729 727
730 /** 728 /**
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 throw MakeRangeError(kInvalidCurrencyCode, currency); 1148 throw MakeRangeError(kInvalidCurrencyCode, currency);
1151 } 1149 }
1152 1150
1153 if (internalOptions.style === 'currency' && IS_UNDEFINED(currency)) { 1151 if (internalOptions.style === 'currency' && IS_UNDEFINED(currency)) {
1154 throw MakeTypeError(kCurrencyCode); 1152 throw MakeTypeError(kCurrencyCode);
1155 } 1153 }
1156 1154
1157 var currencyDisplay = getOption( 1155 var currencyDisplay = getOption(
1158 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol'); 1156 'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol');
1159 if (internalOptions.style === 'currency') { 1157 if (internalOptions.style === 'currency') {
1160 defineWEProperty(internalOptions, 'currency', 1158 defineWEProperty(internalOptions, 'currency', %StringToUpperCase(currency));
1161 %_Call(StringToUpperCase, currency));
1162 defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay); 1159 defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay);
1163 } 1160 }
1164 1161
1165 // Digit ranges. 1162 // Digit ranges.
1166 var mnid = getNumberOption(options, 'minimumIntegerDigits', 1, 21, 1); 1163 var mnid = getNumberOption(options, 'minimumIntegerDigits', 1, 21, 1);
1167 defineWEProperty(internalOptions, 'minimumIntegerDigits', mnid); 1164 defineWEProperty(internalOptions, 'minimumIntegerDigits', mnid);
1168 1165
1169 var mnfd = options['minimumFractionDigits']; 1166 var mnfd = options['minimumFractionDigits'];
1170 var mxfd = options['maximumFractionDigits']; 1167 var mxfd = options['maximumFractionDigits'];
1171 if (!IS_UNDEFINED(mnfd) || internalOptions.style !== 'currency') { 1168 if (!IS_UNDEFINED(mnfd) || internalOptions.style !== 'currency') {
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 * Returns canonical Area/Location(/Location) name, or throws an exception 1782 * Returns canonical Area/Location(/Location) name, or throws an exception
1786 * if the zone name is invalid IANA name. 1783 * if the zone name is invalid IANA name.
1787 */ 1784 */
1788 function canonicalizeTimeZoneID(tzID) { 1785 function canonicalizeTimeZoneID(tzID) {
1789 // Skip undefined zones. 1786 // Skip undefined zones.
1790 if (IS_UNDEFINED(tzID)) { 1787 if (IS_UNDEFINED(tzID)) {
1791 return tzID; 1788 return tzID;
1792 } 1789 }
1793 1790
1794 // Special case handling (UTC, GMT). 1791 // Special case handling (UTC, GMT).
1795 var upperID = %_Call(StringToUpperCase, tzID); 1792 var upperID = %StringToUpperCase(tzID);
1796 if (upperID === 'UTC' || upperID === 'GMT' || 1793 if (upperID === 'UTC' || upperID === 'GMT' ||
1797 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') { 1794 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') {
1798 return 'UTC'; 1795 return 'UTC';
1799 } 1796 }
1800 1797
1801 // TODO(jshin): Add support for Etc/GMT[+-]([1-9]|1[0-2]) 1798 // TODO(jshin): Add support for Etc/GMT[+-]([1-9]|1[0-2])
1802 1799
1803 // We expect only _, '-' and / beside ASCII letters. 1800 // We expect only _, '-' and / beside ASCII letters.
1804 // All inputs should conform to Area/Location(/Location)* from now on. 1801 // All inputs should conform to Area/Location(/Location)* from now on.
1805 var match = InternalRegExpMatch(GetTimezoneNameCheckRE(), tzID); 1802 var match = InternalRegExpMatch(GetTimezoneNameCheckRE(), tzID);
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 } 2252 }
2256 ); 2253 );
2257 2254
2258 utils.Export(function(to) { 2255 utils.Export(function(to) {
2259 to.AddBoundMethod = AddBoundMethod; 2256 to.AddBoundMethod = AddBoundMethod;
2260 to.IntlParseDate = IntlParseDate; 2257 to.IntlParseDate = IntlParseDate;
2261 to.IntlParseNumber = IntlParseNumber; 2258 to.IntlParseNumber = IntlParseNumber;
2262 }); 2259 });
2263 2260
2264 }) 2261 })
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698