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

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

Issue 2232063002: [builtins] WIP: Array indexOf in TurboFan/Runtime (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Move fast path FastElements -> FastSmiOrObjectElements Created 4 years, 4 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/js/array.js ('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 */
11 (function(global, utils) { 11 (function(global, utils) {
12 12
13 "use strict"; 13 "use strict";
14 14
15 %CheckIsBootstrapping(); 15 %CheckIsBootstrapping();
16 16
17 // ------------------------------------------------------------------- 17 // -------------------------------------------------------------------
18 // Imports 18 // Imports
19 19
20 var ArrayIndexOf;
21 var ArrayJoin; 20 var ArrayJoin;
22 var ArrayPush; 21 var ArrayPush;
23 var FLAG_intl_extra; 22 var FLAG_intl_extra;
24 var GlobalDate = global.Date; 23 var GlobalDate = global.Date;
25 var GlobalNumber = global.Number; 24 var GlobalNumber = global.Number;
26 var GlobalRegExp = global.RegExp; 25 var GlobalRegExp = global.RegExp;
27 var GlobalString = global.String; 26 var GlobalString = global.String;
28 var InstallFunctions = utils.InstallFunctions; 27 var InstallFunctions = utils.InstallFunctions;
29 var InstallGetter = utils.InstallGetter; 28 var InstallGetter = utils.InstallGetter;
30 var InternalArray = utils.InternalArray; 29 var InternalArray = utils.InternalArray;
31 var InternalRegExpMatch; 30 var InternalRegExpMatch;
32 var InternalRegExpReplace 31 var InternalRegExpReplace
33 var IsNaN; 32 var IsNaN;
34 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); 33 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty");
35 var OverrideFunction = utils.OverrideFunction; 34 var OverrideFunction = utils.OverrideFunction;
36 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); 35 var patternSymbol = utils.ImportNow("intl_pattern_symbol");
37 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); 36 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol");
38 var SetFunctionName = utils.SetFunctionName; 37 var SetFunctionName = utils.SetFunctionName;
39 var StringIndexOf; 38 var StringIndexOf;
40 var StringLastIndexOf; 39 var StringLastIndexOf;
41 var StringSubstr; 40 var StringSubstr;
42 var StringSubstring; 41 var StringSubstring;
43 42
44 utils.Import(function(from) { 43 utils.Import(function(from) {
45 ArrayIndexOf = from.ArrayIndexOf;
46 ArrayJoin = from.ArrayJoin; 44 ArrayJoin = from.ArrayJoin;
47 ArrayPush = from.ArrayPush; 45 ArrayPush = from.ArrayPush;
48 IsNaN = from.IsNaN; 46 IsNaN = from.IsNaN;
49 InternalRegExpMatch = from.InternalRegExpMatch; 47 InternalRegExpMatch = from.InternalRegExpMatch;
50 InternalRegExpReplace = from.InternalRegExpReplace; 48 InternalRegExpReplace = from.InternalRegExpReplace;
51 StringIndexOf = from.StringIndexOf; 49 StringIndexOf = from.StringIndexOf;
52 StringLastIndexOf = from.StringLastIndexOf; 50 StringLastIndexOf = from.StringLastIndexOf;
53 StringSubstr = from.StringSubstr; 51 StringSubstr = from.StringSubstr;
54 StringSubstring = from.StringSubstring; 52 StringSubstring = from.StringSubstring;
55 }); 53 });
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 case 'string': 360 case 'string':
363 value = TO_STRING(value); 361 value = TO_STRING(value);
364 break; 362 break;
365 case 'number': 363 case 'number':
366 value = TO_NUMBER(value); 364 value = TO_NUMBER(value);
367 break; 365 break;
368 default: 366 default:
369 throw %make_error(kWrongValueType); 367 throw %make_error(kWrongValueType);
370 } 368 }
371 369
372 if (!IS_UNDEFINED(values) && %_Call(ArrayIndexOf, values, value) === -1) { 370 if (!IS_UNDEFINED(values) && %ArrayIndexOf(values, value, 0) === -1) {
373 throw %make_range_error(kValueOutOfRange, value, caller, property); 371 throw %make_range_error(kValueOutOfRange, value, caller, property);
374 } 372 }
375 373
376 return value; 374 return value;
377 } 375 }
378 376
379 return defaultValue; 377 return defaultValue;
380 } 378 }
381 379
382 return getOption; 380 return getOption;
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 761
764 var o = TO_OBJECT(locales); 762 var o = TO_OBJECT(locales);
765 var len = TO_UINT32(o.length); 763 var len = TO_UINT32(o.length);
766 764
767 for (var k = 0; k < len; k++) { 765 for (var k = 0; k < len; k++) {
768 if (k in o) { 766 if (k in o) {
769 var value = o[k]; 767 var value = o[k];
770 768
771 var tag = canonicalizeLanguageTag(value); 769 var tag = canonicalizeLanguageTag(value);
772 770
773 if (%_Call(ArrayIndexOf, seen, tag) === -1) { 771 if (%ArrayIndexOf(seen, tag, 0) === -1) {
774 %_Call(ArrayPush, seen, tag); 772 %_Call(ArrayPush, seen, tag);
775 } 773 }
776 } 774 }
777 } 775 }
778 } 776 }
779 777
780 return freezeArray(seen); 778 return freezeArray(seen);
781 } 779 }
782 780
783 781
(...skipping 25 matching lines...) Expand all
809 // Skip language since it can match variant regex, so we start from 1. 807 // Skip language since it can match variant regex, so we start from 1.
810 // We are matching i-klingon here, but that's ok, since i-klingon-klingon 808 // We are matching i-klingon here, but that's ok, since i-klingon-klingon
811 // is not valid and would fail LANGUAGE_TAG_RE test. 809 // is not valid and would fail LANGUAGE_TAG_RE test.
812 var variants = new InternalArray(); 810 var variants = new InternalArray();
813 var extensions = new InternalArray(); 811 var extensions = new InternalArray();
814 var parts = %StringSplit(locale, '-', kMaxUint32); 812 var parts = %StringSplit(locale, '-', kMaxUint32);
815 for (var i = 1; i < parts.length; i++) { 813 for (var i = 1; i < parts.length; i++) {
816 var value = parts[i]; 814 var value = parts[i];
817 if (!IS_NULL(InternalRegExpMatch(GetLanguageVariantRE(), value)) && 815 if (!IS_NULL(InternalRegExpMatch(GetLanguageVariantRE(), value)) &&
818 extensions.length === 0) { 816 extensions.length === 0) {
819 if (%_Call(ArrayIndexOf, variants, value) === -1) { 817 if (%ArrayIndexOf(variants, value, 0) === -1) {
820 %_Call(ArrayPush, variants, value); 818 %_Call(ArrayPush, variants, value);
821 } else { 819 } else {
822 return false; 820 return false;
823 } 821 }
824 } 822 }
825 823
826 if (!IS_NULL(InternalRegExpMatch(GetLanguageSingletonRE(), value))) { 824 if (!IS_NULL(InternalRegExpMatch(GetLanguageSingletonRE(), value))) {
827 if (%_Call(ArrayIndexOf, extensions, value) === -1) { 825 if (%ArrayIndexOf(extensions, value, 0) === -1) {
828 %_Call(ArrayPush, extensions, value); 826 %_Call(ArrayPush, extensions, value);
829 } else { 827 } else {
830 return false; 828 return false;
831 } 829 }
832 } 830 }
833 } 831 }
834 832
835 return true; 833 return true;
836 } 834 }
837 835
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 940
943 /** 941 /**
944 * Allowed -u-co- values. List taken from: 942 * Allowed -u-co- values. List taken from:
945 * http://unicode.org/repos/cldr/trunk/common/bcp47/collation.xml 943 * http://unicode.org/repos/cldr/trunk/common/bcp47/collation.xml
946 */ 944 */
947 var ALLOWED_CO_VALUES = [ 945 var ALLOWED_CO_VALUES = [
948 'big5han', 'dict', 'direct', 'ducet', 'gb2312', 'phonebk', 'phonetic', 946 'big5han', 'dict', 'direct', 'ducet', 'gb2312', 'phonebk', 'phonetic',
949 'pinyin', 'reformed', 'searchjl', 'stroke', 'trad', 'unihan', 'zhuyin' 947 'pinyin', 'reformed', 'searchjl', 'stroke', 'trad', 'unihan', 'zhuyin'
950 ]; 948 ];
951 949
952 if (%_Call(ArrayIndexOf, ALLOWED_CO_VALUES, extensionMap.co) !== -1) { 950 if (%ArrayIndexOf(ALLOWED_CO_VALUES, extensionMap.co, 0) !== -1) {
953 extension = '-u-co-' + extensionMap.co; 951 extension = '-u-co-' + extensionMap.co;
954 // ICU can't tell us what the collation is, so save user's input. 952 // ICU can't tell us what the collation is, so save user's input.
955 collation = extensionMap.co; 953 collation = extensionMap.co;
956 } 954 }
957 } else if (internalOptions.usage === 'search') { 955 } else if (internalOptions.usage === 'search') {
958 extension = '-u-co-search'; 956 extension = '-u-co-search';
959 } 957 }
960 defineWEProperty(internalOptions, 'collation', collation); 958 defineWEProperty(internalOptions, 'collation', collation);
961 959
962 var requestedLocale = locale.locale + extension; 960 var requestedLocale = locale.locale + extension;
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 language = locales.length > 0 ? locales[0] : GetDefaultICULocaleJS(); 2032 language = locales.length > 0 ? locales[0] : GetDefaultICULocaleJS();
2035 } 2033 }
2036 2034
2037 // StringSplit is slower than this. 2035 // StringSplit is slower than this.
2038 var pos = %_Call(StringIndexOf, language, '-'); 2036 var pos = %_Call(StringIndexOf, language, '-');
2039 if (pos != -1) { 2037 if (pos != -1) {
2040 language = %_Call(StringSubstring, language, 0, pos); 2038 language = %_Call(StringSubstring, language, 0, pos);
2041 } 2039 }
2042 2040
2043 var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr']; 2041 var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr'];
2044 var langIndex = %_Call(ArrayIndexOf, CUSTOM_CASE_LANGUAGES, language); 2042 var langIndex = %ArrayIndexOf(CUSTOM_CASE_LANGUAGES, language, 0);
2045 if (langIndex == -1) { 2043 if (langIndex == -1) {
2046 // language-independent case conversion. 2044 // language-independent case conversion.
2047 return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s); 2045 return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s);
2048 } 2046 }
2049 return %StringLocaleConvertCase(s, isToUpper, 2047 return %StringLocaleConvertCase(s, isToUpper,
2050 CUSTOM_CASE_LANGUAGES[langIndex]); 2048 CUSTOM_CASE_LANGUAGES[langIndex]);
2051 } 2049 }
2052 2050
2053 /** 2051 /**
2054 * Compares this and that, and returns less than 0, 0 or greater than 0 value. 2052 * Compares this and that, and returns less than 0, 0 or greater than 0 value.
(...skipping 30 matching lines...) Expand all
2085 } 2083 }
2086 2084
2087 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); 2085 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
2088 var s = TO_STRING(this); 2086 var s = TO_STRING(this);
2089 2087
2090 var formArg = arguments[0]; 2088 var formArg = arguments[0];
2091 var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg); 2089 var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg);
2092 2090
2093 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; 2091 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];
2094 2092
2095 var normalizationForm = %_Call(ArrayIndexOf, NORMALIZATION_FORMS, form); 2093 var normalizationForm = %ArrayIndexOf(NORMALIZATION_FORMS, form, 0);
2096 if (normalizationForm === -1) { 2094 if (normalizationForm === -1) {
2097 throw %make_range_error(kNormalizationForm, 2095 throw %make_range_error(kNormalizationForm,
2098 %_Call(ArrayJoin, NORMALIZATION_FORMS, ', ')); 2096 %_Call(ArrayJoin, NORMALIZATION_FORMS, ', '));
2099 } 2097 }
2100 2098
2101 return %StringNormalize(s, normalizationForm); 2099 return %StringNormalize(s, normalizationForm);
2102 } 2100 }
2103 ); 2101 );
2104 2102
2105 function ToLowerCaseI18N() { 2103 function ToLowerCaseI18N() {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 } 2244 }
2247 ); 2245 );
2248 2246
2249 utils.Export(function(to) { 2247 utils.Export(function(to) {
2250 to.AddBoundMethod = AddBoundMethod; 2248 to.AddBoundMethod = AddBoundMethod;
2251 to.IntlParseDate = IntlParseDate; 2249 to.IntlParseDate = IntlParseDate;
2252 to.IntlParseNumber = IntlParseNumber; 2250 to.IntlParseNumber = IntlParseNumber;
2253 }); 2251 });
2254 2252
2255 }) 2253 })
OLDNEW
« no previous file with comments | « src/js/array.js ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698