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

Side by Side Diff: src/i18n.js

Issue 1000063002: Hide RegExp and String initialization in a closure. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: address comments Created 5 years, 9 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/api.cc ('k') | src/math.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() { 11 (function() {
12 12
13 "use strict"; 13 "use strict";
14 14
15 %CheckIsBootstrapping(); 15 %CheckIsBootstrapping();
16 16
17 var GlobalDate = global.Date; 17 var GlobalDate = global.Date;
18 var GlobalRegExp = global.RegExp;
19 var GlobalString = global.String;
18 20
19 var undefined = global.undefined; 21 var undefined = global.undefined;
20 22
21 var Intl = {}; 23 var Intl = {};
22 24
23 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); 25 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM);
24 26
25 var AVAILABLE_SERVICES = ['collator', 27 var AVAILABLE_SERVICES = ['collator',
26 'numberformat', 28 'numberformat',
27 'dateformat', 29 'dateformat',
(...skipping 19 matching lines...) Expand all
47 */ 49 */
48 var DEFAULT_ICU_LOCALE = undefined; 50 var DEFAULT_ICU_LOCALE = undefined;
49 51
50 /** 52 /**
51 * Unicode extension regular expression. 53 * Unicode extension regular expression.
52 */ 54 */
53 var UNICODE_EXTENSION_RE = undefined; 55 var UNICODE_EXTENSION_RE = undefined;
54 56
55 function GetUnicodeExtensionRE() { 57 function GetUnicodeExtensionRE() {
56 if (UNICODE_EXTENSION_RE === undefined) { 58 if (UNICODE_EXTENSION_RE === undefined) {
57 UNICODE_EXTENSION_RE = new $RegExp('-u(-[a-z0-9]{2,8})+', 'g'); 59 UNICODE_EXTENSION_RE = new GlobalRegExp('-u(-[a-z0-9]{2,8})+', 'g');
58 } 60 }
59 return UNICODE_EXTENSION_RE; 61 return UNICODE_EXTENSION_RE;
60 } 62 }
61 63
62 /** 64 /**
63 * Matches any Unicode extension. 65 * Matches any Unicode extension.
64 */ 66 */
65 var ANY_EXTENSION_RE = undefined; 67 var ANY_EXTENSION_RE = undefined;
66 68
67 function GetAnyExtensionRE() { 69 function GetAnyExtensionRE() {
68 if (ANY_EXTENSION_RE === undefined) { 70 if (ANY_EXTENSION_RE === undefined) {
69 ANY_EXTENSION_RE = new $RegExp('-[a-z0-9]{1}-.*', 'g'); 71 ANY_EXTENSION_RE = new GlobalRegExp('-[a-z0-9]{1}-.*', 'g');
70 } 72 }
71 return ANY_EXTENSION_RE; 73 return ANY_EXTENSION_RE;
72 } 74 }
73 75
74 /** 76 /**
75 * Replace quoted text (single quote, anything but the quote and quote again). 77 * Replace quoted text (single quote, anything but the quote and quote again).
76 */ 78 */
77 var QUOTED_STRING_RE = undefined; 79 var QUOTED_STRING_RE = undefined;
78 80
79 function GetQuotedStringRE() { 81 function GetQuotedStringRE() {
80 if (QUOTED_STRING_RE === undefined) { 82 if (QUOTED_STRING_RE === undefined) {
81 QUOTED_STRING_RE = new $RegExp("'[^']+'", 'g'); 83 QUOTED_STRING_RE = new GlobalRegExp("'[^']+'", 'g');
82 } 84 }
83 return QUOTED_STRING_RE; 85 return QUOTED_STRING_RE;
84 } 86 }
85 87
86 /** 88 /**
87 * Matches valid service name. 89 * Matches valid service name.
88 */ 90 */
89 var SERVICE_RE = undefined; 91 var SERVICE_RE = undefined;
90 92
91 function GetServiceRE() { 93 function GetServiceRE() {
92 if (SERVICE_RE === undefined) { 94 if (SERVICE_RE === undefined) {
93 SERVICE_RE = 95 SERVICE_RE =
94 new $RegExp('^(collator|numberformat|dateformat|breakiterator)$'); 96 new GlobalRegExp('^(collator|numberformat|dateformat|breakiterator)$');
95 } 97 }
96 return SERVICE_RE; 98 return SERVICE_RE;
97 } 99 }
98 100
99 /** 101 /**
100 * Validates a language tag against bcp47 spec. 102 * Validates a language tag against bcp47 spec.
101 * Actual value is assigned on first run. 103 * Actual value is assigned on first run.
102 */ 104 */
103 var LANGUAGE_TAG_RE = undefined; 105 var LANGUAGE_TAG_RE = undefined;
104 106
(...skipping 29 matching lines...) Expand all
134 } 136 }
135 137
136 /** 138 /**
137 * Matches valid IANA time zone names. 139 * Matches valid IANA time zone names.
138 */ 140 */
139 var TIMEZONE_NAME_CHECK_RE = undefined; 141 var TIMEZONE_NAME_CHECK_RE = undefined;
140 142
141 function GetTimezoneNameCheckRE() { 143 function GetTimezoneNameCheckRE() {
142 if (TIMEZONE_NAME_CHECK_RE === undefined) { 144 if (TIMEZONE_NAME_CHECK_RE === undefined) {
143 TIMEZONE_NAME_CHECK_RE = 145 TIMEZONE_NAME_CHECK_RE =
144 new $RegExp('^([A-Za-z]+)/([A-Za-z]+)(?:_([A-Za-z]+))*$'); 146 new GlobalRegExp('^([A-Za-z]+)/([A-Za-z]+)(?:_([A-Za-z]+))*$');
145 } 147 }
146 return TIMEZONE_NAME_CHECK_RE; 148 return TIMEZONE_NAME_CHECK_RE;
147 } 149 }
148 150
149 /** 151 /**
150 * Maps ICU calendar names into LDML type. 152 * Maps ICU calendar names into LDML type.
151 */ 153 */
152 var ICU_CALENDAR_MAP = { 154 var ICU_CALENDAR_MAP = {
153 'gregorian': 'gregory', 155 'gregorian': 'gregory',
154 'japanese': 'japanese', 156 'japanese': 'japanese',
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 284
283 // Provide defaults if matcher was not specified. 285 // Provide defaults if matcher was not specified.
284 if (options === undefined) { 286 if (options === undefined) {
285 options = {}; 287 options = {};
286 } else { 288 } else {
287 options = ToObject(options); 289 options = ToObject(options);
288 } 290 }
289 291
290 var matcher = options.localeMatcher; 292 var matcher = options.localeMatcher;
291 if (matcher !== undefined) { 293 if (matcher !== undefined) {
292 matcher = $String(matcher); 294 matcher = GlobalString(matcher);
293 if (matcher !== 'lookup' && matcher !== 'best fit') { 295 if (matcher !== 'lookup' && matcher !== 'best fit') {
294 throw new $RangeError('Illegal value for localeMatcher:' + matcher); 296 throw new $RangeError('Illegal value for localeMatcher:' + matcher);
295 } 297 }
296 } else { 298 } else {
297 matcher = 'best fit'; 299 matcher = 'best fit';
298 } 300 }
299 301
300 var requestedLocales = initializeLocaleList(locales); 302 var requestedLocales = initializeLocaleList(locales);
301 303
302 // Cache these, they don't ever change per service. 304 // Cache these, they don't ever change per service.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 370 }
369 371
370 var getOption = function getOption(property, type, values, defaultValue) { 372 var getOption = function getOption(property, type, values, defaultValue) {
371 if (options[property] !== undefined) { 373 if (options[property] !== undefined) {
372 var value = options[property]; 374 var value = options[property];
373 switch (type) { 375 switch (type) {
374 case 'boolean': 376 case 'boolean':
375 value = $Boolean(value); 377 value = $Boolean(value);
376 break; 378 break;
377 case 'string': 379 case 'string':
378 value = $String(value); 380 value = GlobalString(value);
379 break; 381 break;
380 case 'number': 382 case 'number':
381 value = $Number(value); 383 value = $Number(value);
382 break; 384 break;
383 default: 385 default:
384 throw new $Error('Internal error. Wrong value type.'); 386 throw new $Error('Internal error. Wrong value type.');
385 } 387 }
386 if (values !== undefined && values.indexOf(value) === -1) { 388 if (values !== undefined && values.indexOf(value) === -1) {
387 throw new $RangeError('Value ' + value + ' out of range for ' + caller + 389 throw new $RangeError('Value ' + value + ' out of range for ' + caller +
388 ' options property ' + property); 390 ' options property ' + property);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 * Unicode extensions for passing parameters to ICU). 526 * Unicode extensions for passing parameters to ICU).
525 * It's used for extension-option pairs only, e.g. kn-normalization, but not 527 * It's used for extension-option pairs only, e.g. kn-normalization, but not
526 * for 'sensitivity' since it doesn't have extension equivalent. 528 * for 'sensitivity' since it doesn't have extension equivalent.
527 * Extensions like nu and ca don't have options equivalent, so we place 529 * Extensions like nu and ca don't have options equivalent, so we place
528 * undefined in the map.property to denote that. 530 * undefined in the map.property to denote that.
529 */ 531 */
530 function setOptions(inOptions, extensionMap, keyValues, getOption, outOptions) { 532 function setOptions(inOptions, extensionMap, keyValues, getOption, outOptions) {
531 var extension = ''; 533 var extension = '';
532 534
533 var updateExtension = function updateExtension(key, value) { 535 var updateExtension = function updateExtension(key, value) {
534 return '-' + key + '-' + $String(value); 536 return '-' + key + '-' + GlobalString(value);
535 } 537 }
536 538
537 var updateProperty = function updateProperty(property, type, value) { 539 var updateProperty = function updateProperty(property, type, value) {
538 if (type === 'boolean' && (typeof value === 'string')) { 540 if (type === 'boolean' && (typeof value === 'string')) {
539 value = (value === 'true') ? true : false; 541 value = (value === 'true') ? true : false;
540 } 542 }
541 543
542 if (property !== undefined) { 544 if (property !== undefined) {
543 defineWEProperty(outOptions, property, value); 545 defineWEProperty(outOptions, property, value);
544 } 546 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 if (original === resolved) { 615 if (original === resolved) {
614 return original; 616 return original;
615 } 617 }
616 618
617 var locales = %GetLanguageTagVariants([original, resolved]); 619 var locales = %GetLanguageTagVariants([original, resolved]);
618 if (locales[0].maximized !== locales[1].maximized) { 620 if (locales[0].maximized !== locales[1].maximized) {
619 return resolved; 621 return resolved;
620 } 622 }
621 623
622 // Preserve extensions of resolved locale, but swap base tags with original. 624 // Preserve extensions of resolved locale, but swap base tags with original.
623 var resolvedBase = new $RegExp('^' + locales[1].base); 625 var resolvedBase = new GlobalRegExp('^' + locales[1].base);
624 return resolved.replace(resolvedBase, locales[0].base); 626 return resolved.replace(resolvedBase, locales[0].base);
625 } 627 }
626 628
627 629
628 /** 630 /**
629 * Returns an Object that contains all of supported locales for a given 631 * Returns an Object that contains all of supported locales for a given
630 * service. 632 * service.
631 * In addition to the supported locales we add xx-ZZ locale for each xx-Yyyy-ZZ 633 * In addition to the supported locales we add xx-ZZ locale for each xx-Yyyy-ZZ
632 * that is supported. This is required by the spec. 634 * that is supported. This is required by the spec.
633 */ 635 */
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 /** 705 /**
704 * Canonicalizes the language tag, or throws in case the tag is invalid. 706 * Canonicalizes the language tag, or throws in case the tag is invalid.
705 */ 707 */
706 function canonicalizeLanguageTag(localeID) { 708 function canonicalizeLanguageTag(localeID) {
707 // null is typeof 'object' so we have to do extra check. 709 // null is typeof 'object' so we have to do extra check.
708 if (typeof localeID !== 'string' && typeof localeID !== 'object' || 710 if (typeof localeID !== 'string' && typeof localeID !== 'object' ||
709 IS_NULL(localeID)) { 711 IS_NULL(localeID)) {
710 throw new $TypeError('Language ID should be string or object.'); 712 throw new $TypeError('Language ID should be string or object.');
711 } 713 }
712 714
713 var localeString = $String(localeID); 715 var localeString = GlobalString(localeID);
714 716
715 if (isValidLanguageTag(localeString) === false) { 717 if (isValidLanguageTag(localeString) === false) {
716 throw new $RangeError('Invalid language tag: ' + localeString); 718 throw new $RangeError('Invalid language tag: ' + localeString);
717 } 719 }
718 720
719 // This call will strip -kn but not -kn-true extensions. 721 // This call will strip -kn but not -kn-true extensions.
720 // ICU bug filled - http://bugs.icu-project.org/trac/ticket/9265. 722 // ICU bug filled - http://bugs.icu-project.org/trac/ticket/9265.
721 // TODO(cira): check if -u-kn-true-kc-true-kh-true still throws after 723 // TODO(cira): check if -u-kn-true-kc-true-kh-true still throws after
722 // upgrade to ICU 4.9. 724 // upgrade to ICU 4.9.
723 var tag = %CanonicalizeLanguageTag(localeString); 725 var tag = %CanonicalizeLanguageTag(localeString);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 var alphanum = '(' + alpha + '|' + digit + ')'; 834 var alphanum = '(' + alpha + '|' + digit + ')';
833 var regular = '(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|' + 835 var regular = '(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|' +
834 'zh-min|zh-min-nan|zh-xiang)'; 836 'zh-min|zh-min-nan|zh-xiang)';
835 var irregular = '(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|' + 837 var irregular = '(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|' +
836 'i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|' + 838 'i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|' +
837 'i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)'; 839 'i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)';
838 var grandfathered = '(' + irregular + '|' + regular + ')'; 840 var grandfathered = '(' + irregular + '|' + regular + ')';
839 var privateUse = '(x(-' + alphanum + '{1,8})+)'; 841 var privateUse = '(x(-' + alphanum + '{1,8})+)';
840 842
841 var singleton = '(' + digit + '|[A-WY-Za-wy-z])'; 843 var singleton = '(' + digit + '|[A-WY-Za-wy-z])';
842 LANGUAGE_SINGLETON_RE = new $RegExp('^' + singleton + '$', 'i'); 844 LANGUAGE_SINGLETON_RE = new GlobalRegExp('^' + singleton + '$', 'i');
843 845
844 var extension = '(' + singleton + '(-' + alphanum + '{2,8})+)'; 846 var extension = '(' + singleton + '(-' + alphanum + '{2,8})+)';
845 847
846 var variant = '(' + alphanum + '{5,8}|(' + digit + alphanum + '{3}))'; 848 var variant = '(' + alphanum + '{5,8}|(' + digit + alphanum + '{3}))';
847 LANGUAGE_VARIANT_RE = new $RegExp('^' + variant + '$', 'i'); 849 LANGUAGE_VARIANT_RE = new GlobalRegExp('^' + variant + '$', 'i');
848 850
849 var region = '(' + alpha + '{2}|' + digit + '{3})'; 851 var region = '(' + alpha + '{2}|' + digit + '{3})';
850 var script = '(' + alpha + '{4})'; 852 var script = '(' + alpha + '{4})';
851 var extLang = '(' + alpha + '{3}(-' + alpha + '{3}){0,2})'; 853 var extLang = '(' + alpha + '{3}(-' + alpha + '{3}){0,2})';
852 var language = '(' + alpha + '{2,3}(-' + extLang + ')?|' + alpha + '{4}|' + 854 var language = '(' + alpha + '{2,3}(-' + extLang + ')?|' + alpha + '{4}|' +
853 alpha + '{5,8})'; 855 alpha + '{5,8})';
854 var langTag = language + '(-' + script + ')?(-' + region + ')?(-' + 856 var langTag = language + '(-' + script + ')?(-' + region + ')?(-' +
855 variant + ')*(-' + extension + ')*(-' + privateUse + ')?'; 857 variant + ')*(-' + extension + ')*(-' + privateUse + ')?';
856 858
857 var languageTag = 859 var languageTag =
858 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$'; 860 '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$';
859 LANGUAGE_TAG_RE = new $RegExp(languageTag, 'i'); 861 LANGUAGE_TAG_RE = new GlobalRegExp(languageTag, 'i');
860 } 862 }
861 863
862 /** 864 /**
863 * Initializes the given object so it's a valid Collator instance. 865 * Initializes the given object so it's a valid Collator instance.
864 * Useful for subclassing. 866 * Useful for subclassing.
865 */ 867 */
866 function initializeCollator(collator, locales, options) { 868 function initializeCollator(collator, locales, options) {
867 if (%IsInitializedIntlObject(collator)) { 869 if (%IsInitializedIntlObject(collator)) {
868 throw new $TypeError('Trying to re-initialize Collator object.'); 870 throw new $TypeError('Trying to re-initialize Collator object.');
869 } 871 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 * Number other than NaN that represents the result of a locale-sensitive 1024 * Number other than NaN that represents the result of a locale-sensitive
1023 * String comparison of x with y. 1025 * String comparison of x with y.
1024 * The result is intended to order String values in the sort order specified 1026 * The result is intended to order String values in the sort order specified
1025 * by the effective locale and collation options computed during construction 1027 * by the effective locale and collation options computed during construction
1026 * of this Collator object, and will be negative, zero, or positive, depending 1028 * of this Collator object, and will be negative, zero, or positive, depending
1027 * on whether x comes before y in the sort order, the Strings are equal under 1029 * on whether x comes before y in the sort order, the Strings are equal under
1028 * the sort order, or x comes after y in the sort order, respectively. 1030 * the sort order, or x comes after y in the sort order, respectively.
1029 */ 1031 */
1030 function compare(collator, x, y) { 1032 function compare(collator, x, y) {
1031 return %InternalCompare(%GetImplFromInitializedIntlObject(collator), 1033 return %InternalCompare(%GetImplFromInitializedIntlObject(collator),
1032 $String(x), $String(y)); 1034 GlobalString(x), GlobalString(y));
1033 }; 1035 };
1034 1036
1035 1037
1036 addBoundMethod(Intl.Collator, 'compare', compare, 2); 1038 addBoundMethod(Intl.Collator, 'compare', compare, 2);
1037 1039
1038 /** 1040 /**
1039 * Verifies that the input is a well-formed ISO 4217 currency code. 1041 * Verifies that the input is a well-formed ISO 4217 currency code.
1040 * Don't uppercase to test. It could convert invalid code into a valid one. 1042 * Don't uppercase to test. It could convert invalid code into a valid one.
1041 * For example \u00DFP (Eszett+P) becomes SSP. 1043 * For example \u00DFP (Eszett+P) becomes SSP.
1042 */ 1044 */
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), 1277 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter),
1276 number); 1278 number);
1277 } 1279 }
1278 1280
1279 1281
1280 /** 1282 /**
1281 * Returns a Number that represents string value that was passed in. 1283 * Returns a Number that represents string value that was passed in.
1282 */ 1284 */
1283 function parseNumber(formatter, value) { 1285 function parseNumber(formatter, value) {
1284 return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter), 1286 return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter),
1285 $String(value)); 1287 GlobalString(value));
1286 } 1288 }
1287 1289
1288 1290
1289 addBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); 1291 addBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1);
1290 addBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); 1292 addBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1);
1291 1293
1292 /** 1294 /**
1293 * Returns a string that matches LDML representation of the options object. 1295 * Returns a string that matches LDML representation of the options object.
1294 */ 1296 */
1295 function toLDMLString(options) { 1297 function toLDMLString(options) {
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 1681
1680 1682
1681 /** 1683 /**
1682 * Returns a Date object representing the result of calling ToString(value) 1684 * Returns a Date object representing the result of calling ToString(value)
1683 * according to the effective locale and the formatting options of this 1685 * according to the effective locale and the formatting options of this
1684 * DateTimeFormat. 1686 * DateTimeFormat.
1685 * Returns undefined if date string cannot be parsed. 1687 * Returns undefined if date string cannot be parsed.
1686 */ 1688 */
1687 function parseDate(formatter, value) { 1689 function parseDate(formatter, value) {
1688 return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter), 1690 return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter),
1689 $String(value)); 1691 GlobalString(value));
1690 } 1692 }
1691 1693
1692 1694
1693 // 0 because date is optional argument. 1695 // 0 because date is optional argument.
1694 addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); 1696 addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0);
1695 addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); 1697 addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1);
1696 1698
1697 1699
1698 /** 1700 /**
1699 * Returns canonical Area/Location name, or throws an exception if the zone 1701 * Returns canonical Area/Location name, or throws an exception if the zone
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); 1842 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf);
1841 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); 1843 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf);
1842 1844
1843 1845
1844 /** 1846 /**
1845 * Adopts text to segment using the iterator. Old text, if present, 1847 * Adopts text to segment using the iterator. Old text, if present,
1846 * gets discarded. 1848 * gets discarded.
1847 */ 1849 */
1848 function adoptText(iterator, text) { 1850 function adoptText(iterator, text) {
1849 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), 1851 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator),
1850 $String(text)); 1852 GlobalString(text));
1851 } 1853 }
1852 1854
1853 1855
1854 /** 1856 /**
1855 * Returns index of the first break in the string and moves current pointer. 1857 * Returns index of the first break in the string and moves current pointer.
1856 */ 1858 */
1857 function first(iterator) { 1859 function first(iterator) {
1858 return %BreakIteratorFirst(%GetImplFromInitializedIntlObject(iterator)); 1860 return %BreakIteratorFirst(%GetImplFromInitializedIntlObject(iterator));
1859 } 1861 }
1860 1862
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 return defaultObjects[service]; 1925 return defaultObjects[service];
1924 } 1926 }
1925 return new savedObjects[service](locales, useOptions); 1927 return new savedObjects[service](locales, useOptions);
1926 } 1928 }
1927 1929
1928 1930
1929 /** 1931 /**
1930 * Compares this and that, and returns less than 0, 0 or greater than 0 value. 1932 * Compares this and that, and returns less than 0, 0 or greater than 0 value.
1931 * Overrides the built-in method. 1933 * Overrides the built-in method.
1932 */ 1934 */
1933 OverrideFunction($String.prototype, 'localeCompare', function(that) { 1935 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
1934 if (%_IsConstructCall()) { 1936 if (%_IsConstructCall()) {
1935 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1937 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
1936 } 1938 }
1937 1939
1938 if (IS_NULL_OR_UNDEFINED(this)) { 1940 if (IS_NULL_OR_UNDEFINED(this)) {
1939 throw new $TypeError('Method invoked on undefined or null value.'); 1941 throw new $TypeError('Method invoked on undefined or null value.');
1940 } 1942 }
1941 1943
1942 var locales = %_Arguments(1); 1944 var locales = %_Arguments(1);
1943 var options = %_Arguments(2); 1945 var options = %_Arguments(2);
1944 var collator = cachedOrNewService('collator', locales, options); 1946 var collator = cachedOrNewService('collator', locales, options);
1945 return compare(collator, this, that); 1947 return compare(collator, this, that);
1946 } 1948 }
1947 ); 1949 );
1948 1950
1949 1951
1950 /** 1952 /**
1951 * Unicode normalization. This method is called with one argument that 1953 * Unicode normalization. This method is called with one argument that
1952 * specifies the normalization form. 1954 * specifies the normalization form.
1953 * If none is specified, "NFC" is assumed. 1955 * If none is specified, "NFC" is assumed.
1954 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw 1956 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw
1955 * a RangeError Exception. 1957 * a RangeError Exception.
1956 */ 1958 */
1957 OverrideFunction($String.prototype, 'normalize', function(that) { 1959 OverrideFunction(GlobalString.prototype, 'normalize', function(that) {
1958 if (%_IsConstructCall()) { 1960 if (%_IsConstructCall()) {
1959 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1961 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
1960 } 1962 }
1961 1963
1962 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); 1964 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
1963 1965
1964 var form = $String(%_Arguments(0) || 'NFC'); 1966 var form = GlobalString(%_Arguments(0) || 'NFC');
1965 1967
1966 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); 1968 var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
1967 if (normalizationForm === -1) { 1969 if (normalizationForm === -1) {
1968 throw new $RangeError('The normalization form should be one of ' 1970 throw new $RangeError('The normalization form should be one of '
1969 + NORMALIZATION_FORMS.join(', ') + '.'); 1971 + NORMALIZATION_FORMS.join(', ') + '.');
1970 } 1972 }
1971 1973
1972 return %StringNormalize(this, normalizationForm); 1974 return %StringNormalize(this, normalizationForm);
1973 } 1975 }
1974 ); 1976 );
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 } 2065 }
2064 2066
2065 var locales = %_Arguments(0); 2067 var locales = %_Arguments(0);
2066 var options = %_Arguments(1); 2068 var options = %_Arguments(1);
2067 return toLocaleDateTime( 2069 return toLocaleDateTime(
2068 this, locales, options, 'time', 'time', 'dateformattime'); 2070 this, locales, options, 'time', 'time', 'dateformattime');
2069 } 2071 }
2070 ); 2072 );
2071 2073
2072 })(); 2074 })();
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/math.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698