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

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

Issue 1923803002: Use InternalArrays from certain Intl code (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test262 status Created 4 years, 7 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 | « no previous file | src/js/typedarray.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; 20 var ArrayIndexOf;
21 var ArrayJoin; 21 var ArrayJoin;
22 var ArrayPush; 22 var ArrayPush;
23 var GlobalBoolean = global.Boolean; 23 var GlobalBoolean = global.Boolean;
24 var GlobalDate = global.Date; 24 var GlobalDate = global.Date;
25 var GlobalNumber = global.Number; 25 var GlobalNumber = global.Number;
26 var GlobalRegExp = global.RegExp; 26 var GlobalRegExp = global.RegExp;
27 var GlobalString = global.String; 27 var GlobalString = global.String;
28 var InstallFunctions = utils.InstallFunctions; 28 var InstallFunctions = utils.InstallFunctions;
29 var InstallGetter = utils.InstallGetter; 29 var InstallGetter = utils.InstallGetter;
30 var InternalPackedArray = utils.InternalPackedArray; 30 var InternalArray = utils.InternalArray;
31 var InternalRegExpMatch; 31 var InternalRegExpMatch;
32 var InternalRegExpReplace 32 var InternalRegExpReplace
33 var IsFinite; 33 var IsFinite;
34 var IsNaN; 34 var IsNaN;
35 var MakeError; 35 var MakeError;
36 var MakeRangeError; 36 var MakeRangeError;
37 var MakeTypeError; 37 var MakeTypeError;
38 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); 38 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty");
39 var OverrideFunction = utils.OverrideFunction; 39 var OverrideFunction = utils.OverrideFunction;
40 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); 40 var patternSymbol = utils.ImportNow("intl_pattern_symbol");
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 requestedLocales, AVAILABLE_LOCALES[service])); 298 requestedLocales, AVAILABLE_LOCALES[service]));
299 } 299 }
300 300
301 301
302 /** 302 /**
303 * Returns the subset of the provided BCP 47 language priority list for which 303 * Returns the subset of the provided BCP 47 language priority list for which
304 * this service has a matching locale when using the BCP 47 Lookup algorithm. 304 * this service has a matching locale when using the BCP 47 Lookup algorithm.
305 * Locales appear in the same order in the returned list as in the input list. 305 * Locales appear in the same order in the returned list as in the input list.
306 */ 306 */
307 function lookupSupportedLocalesOf(requestedLocales, availableLocales) { 307 function lookupSupportedLocalesOf(requestedLocales, availableLocales) {
308 var matchedLocales = []; 308 var matchedLocales = new InternalArray();
309 for (var i = 0; i < requestedLocales.length; ++i) { 309 for (var i = 0; i < requestedLocales.length; ++i) {
310 // Remove -u- extension. 310 // Remove -u- extension.
311 var locale = InternalRegExpReplace( 311 var locale = InternalRegExpReplace(
312 GetUnicodeExtensionRE(), requestedLocales[i], ''); 312 GetUnicodeExtensionRE(), requestedLocales[i], '');
313 do { 313 do {
314 if (!IS_UNDEFINED(availableLocales[locale])) { 314 if (!IS_UNDEFINED(availableLocales[locale])) {
315 // Push requested locale not the resolved one. 315 // Push requested locale not the resolved one.
316 %_Call(ArrayPush, matchedLocales, requestedLocales[i]); 316 %_Call(ArrayPush, matchedLocales, requestedLocales[i]);
317 break; 317 break;
318 } 318 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } 558 }
559 } 559 }
560 } 560 }
561 } 561 }
562 562
563 return extension === ''? '' : '-u' + extension; 563 return extension === ''? '' : '-u' + extension;
564 } 564 }
565 565
566 566
567 /** 567 /**
568 * Converts all OwnProperties into 568 * Given an array-like, outputs an Array with the numbered
569 * properties copied over and defined
569 * configurable: false, writable: false, enumerable: true. 570 * configurable: false, writable: false, enumerable: true.
570 */ 571 */
571 function freezeArray(array) { 572 function freezeArray(input) {
572 var l = array.length; 573 var array = [];
574 var l = input.length;
573 for (var i = 0; i < l; i++) { 575 for (var i = 0; i < l; i++) {
574 if (i in array) { 576 if (i in input) {
575 %object_define_property(array, i, {value: array[i], 577 %object_define_property(array, i, {value: input[i],
576 configurable: false, 578 configurable: false,
577 writable: false, 579 writable: false,
578 enumerable: true}); 580 enumerable: true});
579 } 581 }
580 } 582 }
581 583
582 %object_define_property(array, 'length', {value: l, writable: false}); 584 %object_define_property(array, 'length', {value: l, writable: false});
583 return array; 585 return array;
584 } 586 }
585 587
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 744
743 return tag; 745 return tag;
744 } 746 }
745 747
746 748
747 /** 749 /**
748 * Returns an array where all locales are canonicalized and duplicates removed. 750 * Returns an array where all locales are canonicalized and duplicates removed.
749 * Throws on locales that are not well formed BCP47 tags. 751 * Throws on locales that are not well formed BCP47 tags.
750 */ 752 */
751 function initializeLocaleList(locales) { 753 function initializeLocaleList(locales) {
752 var seen = []; 754 var seen = new InternalArray();
753 if (IS_UNDEFINED(locales)) { 755 if (!IS_UNDEFINED(locales)) {
754 // Constructor is called without arguments.
755 seen = [];
756 } else {
757 // We allow single string localeID. 756 // We allow single string localeID.
758 if (typeof locales === 'string') { 757 if (typeof locales === 'string') {
759 %_Call(ArrayPush, seen, canonicalizeLanguageTag(locales)); 758 %_Call(ArrayPush, seen, canonicalizeLanguageTag(locales));
760 return freezeArray(seen); 759 return freezeArray(seen);
761 } 760 }
762 761
763 var o = TO_OBJECT(locales); 762 var o = TO_OBJECT(locales);
764 var len = TO_UINT32(o.length); 763 var len = TO_UINT32(o.length);
765 764
766 for (var k = 0; k < len; k++) { 765 for (var k = 0; k < len; k++) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 800 }
802 801
803 // Check if there are any duplicate variants or singletons (extensions). 802 // Check if there are any duplicate variants or singletons (extensions).
804 803
805 // Remove private use section. 804 // Remove private use section.
806 locale = %_Call(StringSplit, locale, '-x-')[0]; 805 locale = %_Call(StringSplit, locale, '-x-')[0];
807 806
808 // 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.
809 // 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
810 // is not valid and would fail LANGUAGE_TAG_RE test. 809 // is not valid and would fail LANGUAGE_TAG_RE test.
811 var variants = []; 810 var variants = new InternalArray();
812 var extensions = []; 811 var extensions = new InternalArray();
813 var parts = %_Call(StringSplit, locale, '-'); 812 var parts = %_Call(StringSplit, locale, '-');
814 for (var i = 1; i < parts.length; i++) { 813 for (var i = 1; i < parts.length; i++) {
815 var value = parts[i]; 814 var value = parts[i];
816 if (!IS_NULL(InternalRegExpMatch(GetLanguageVariantRE(), value)) && 815 if (!IS_NULL(InternalRegExpMatch(GetLanguageVariantRE(), value)) &&
817 extensions.length === 0) { 816 extensions.length === 0) {
818 if (%_Call(ArrayIndexOf, variants, value) === -1) { 817 if (%_Call(ArrayIndexOf, variants, value) === -1) {
819 %_Call(ArrayPush, variants, value); 818 %_Call(ArrayPush, variants, value);
820 } else { 819 } else {
821 return false; 820 return false;
822 } 821 }
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 } 2129 }
2131 2130
2132 var locales = arguments[0]; 2131 var locales = arguments[0];
2133 var options = arguments[1]; 2132 var options = arguments[1];
2134 return toLocaleDateTime( 2133 return toLocaleDateTime(
2135 this, locales, options, 'time', 'time', 'dateformattime'); 2134 this, locales, options, 'time', 'time', 'dateformattime');
2136 } 2135 }
2137 ); 2136 );
2138 2137
2139 }) 2138 })
OLDNEW
« no previous file with comments | « no previous file | src/js/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698