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 17 matching lines...) Expand all Loading... |
28 var GlobalDate = global.Date; | 28 var GlobalDate = global.Date; |
29 var GlobalNumber = global.Number; | 29 var GlobalNumber = global.Number; |
30 var GlobalRegExp = global.RegExp; | 30 var GlobalRegExp = global.RegExp; |
31 var GlobalString = global.String; | 31 var GlobalString = global.String; |
32 var MakeError; | 32 var MakeError; |
33 var MakeRangeError; | 33 var MakeRangeError; |
34 var MakeTypeError; | 34 var MakeTypeError; |
35 var MathFloor; | 35 var MathFloor; |
36 var ObjectDefineProperties = utils.ImportNow("ObjectDefineProperties"); | 36 var ObjectDefineProperties = utils.ImportNow("ObjectDefineProperties"); |
37 var ObjectDefineProperty = utils.ImportNow("ObjectDefineProperty"); | 37 var ObjectDefineProperty = utils.ImportNow("ObjectDefineProperty"); |
| 38 var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); |
38 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); | 39 var patternSymbol = utils.ImportNow("intl_pattern_symbol"); |
39 var RegExpTest; | 40 var RegExpTest; |
40 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); | 41 var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); |
41 var SetFunctionName = utils.SetFunctionName; | 42 var SetFunctionName = utils.SetFunctionName; |
42 var StringIndexOf; | 43 var StringIndexOf; |
43 var StringLastIndexOf; | 44 var StringLastIndexOf; |
44 var StringMatch; | 45 var StringMatch; |
45 var StringReplace; | 46 var StringReplace; |
46 var StringSplit; | 47 var StringSplit; |
47 var StringSubstr; | 48 var StringSubstr; |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 if (type === 'boolean' && (typeof value === 'string')) { | 539 if (type === 'boolean' && (typeof value === 'string')) { |
539 value = (value === 'true') ? true : false; | 540 value = (value === 'true') ? true : false; |
540 } | 541 } |
541 | 542 |
542 if (!IS_UNDEFINED(property)) { | 543 if (!IS_UNDEFINED(property)) { |
543 defineWEProperty(outOptions, property, value); | 544 defineWEProperty(outOptions, property, value); |
544 } | 545 } |
545 } | 546 } |
546 | 547 |
547 for (var key in keyValues) { | 548 for (var key in keyValues) { |
548 if (%HasOwnProperty(keyValues, key)) { | 549 if (HAS_OWN_PROPERTY(keyValues, key)) { |
549 var value = UNDEFINED; | 550 var value = UNDEFINED; |
550 var map = keyValues[key]; | 551 var map = keyValues[key]; |
551 if (!IS_UNDEFINED(map.property)) { | 552 if (!IS_UNDEFINED(map.property)) { |
552 // This may return true if user specifies numeric: 'false', since | 553 // This may return true if user specifies numeric: 'false', since |
553 // Boolean('nonempty') === true. | 554 // Boolean('nonempty') === true. |
554 value = getOption(map.property, map.type, map.values); | 555 value = getOption(map.property, map.type, map.values); |
555 } | 556 } |
556 if (!IS_UNDEFINED(value)) { | 557 if (!IS_UNDEFINED(value)) { |
557 updateProperty(map.property, map.type, value); | 558 updateProperty(map.property, map.type, value); |
558 extension += updateExtension(key, value); | 559 extension += updateExtension(key, value); |
559 continue; | 560 continue; |
560 } | 561 } |
561 // User options didn't have it, check Unicode extension. | 562 // User options didn't have it, check Unicode extension. |
562 // Here we want to convert strings 'true', 'false' into proper Boolean | 563 // Here we want to convert strings 'true', 'false' into proper Boolean |
563 // values (not a user error). | 564 // values (not a user error). |
564 if (%HasOwnProperty(extensionMap, key)) { | 565 if (HAS_OWN_PROPERTY(extensionMap, key)) { |
565 value = extensionMap[key]; | 566 value = extensionMap[key]; |
566 if (!IS_UNDEFINED(value)) { | 567 if (!IS_UNDEFINED(value)) { |
567 updateProperty(map.property, map.type, value); | 568 updateProperty(map.property, map.type, value); |
568 extension += updateExtension(key, value); | 569 extension += updateExtension(key, value); |
569 } else if (map.type === 'boolean') { | 570 } else if (map.type === 'boolean') { |
570 // Boolean keys are allowed not to have values in Unicode extension. | 571 // Boolean keys are allowed not to have values in Unicode extension. |
571 // Those default to true. | 572 // Those default to true. |
572 updateProperty(map.property, map.type, true); | 573 updateProperty(map.property, map.type, true); |
573 extension += updateExtension(key, true); | 574 extension += updateExtension(key, true); |
574 } | 575 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 /** | 631 /** |
631 * Returns an Object that contains all of supported locales for a given | 632 * Returns an Object that contains all of supported locales for a given |
632 * service. | 633 * service. |
633 * In addition to the supported locales we add xx-ZZ locale for each xx-Yyyy-ZZ | 634 * In addition to the supported locales we add xx-ZZ locale for each xx-Yyyy-ZZ |
634 * that is supported. This is required by the spec. | 635 * that is supported. This is required by the spec. |
635 */ | 636 */ |
636 function getAvailableLocalesOf(service) { | 637 function getAvailableLocalesOf(service) { |
637 var available = %AvailableLocalesOf(service); | 638 var available = %AvailableLocalesOf(service); |
638 | 639 |
639 for (var i in available) { | 640 for (var i in available) { |
640 if (%HasOwnProperty(available, i)) { | 641 if (HAS_OWN_PROPERTY(available, i)) { |
641 var parts = | 642 var parts = |
642 %_Call(StringMatch, i, /^([a-z]{2,3})-([A-Z][a-z]{3})-([A-Z]{2})$/); | 643 %_Call(StringMatch, i, /^([a-z]{2,3})-([A-Z][a-z]{3})-([A-Z]{2})$/); |
643 if (parts !== null) { | 644 if (parts !== null) { |
644 // Build xx-ZZ. We don't care about the actual value, | 645 // Build xx-ZZ. We don't care about the actual value, |
645 // as long it's not undefined. | 646 // as long it's not undefined. |
646 available[parts[1] + '-' + parts[3]] = null; | 647 available[parts[1] + '-' + parts[3]] = null; |
647 } | 648 } |
648 } | 649 } |
649 } | 650 } |
650 | 651 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 'kn': {'property': 'numeric', 'type': 'boolean'}, | 947 'kn': {'property': 'numeric', 'type': 'boolean'}, |
947 'kf': {'property': 'caseFirst', 'type': 'string', | 948 'kf': {'property': 'caseFirst', 'type': 'string', |
948 'values': ['false', 'lower', 'upper']} | 949 'values': ['false', 'lower', 'upper']} |
949 }; | 950 }; |
950 | 951 |
951 setOptions( | 952 setOptions( |
952 options, extensionMap, COLLATOR_KEY_MAP, getOption, internalOptions); | 953 options, extensionMap, COLLATOR_KEY_MAP, getOption, internalOptions); |
953 | 954 |
954 var collation = 'default'; | 955 var collation = 'default'; |
955 var extension = ''; | 956 var extension = ''; |
956 if (%HasOwnProperty(extensionMap, 'co') && internalOptions.usage === 'sort') { | 957 if (HAS_OWN_PROPERTY(extensionMap, 'co') && internalOptions.usage === 'sort')
{ |
957 | 958 |
958 /** | 959 /** |
959 * Allowed -u-co- values. List taken from: | 960 * Allowed -u-co- values. List taken from: |
960 * http://unicode.org/repos/cldr/trunk/common/bcp47/collation.xml | 961 * http://unicode.org/repos/cldr/trunk/common/bcp47/collation.xml |
961 */ | 962 */ |
962 var ALLOWED_CO_VALUES = [ | 963 var ALLOWED_CO_VALUES = [ |
963 'big5han', 'dict', 'direct', 'ducet', 'gb2312', 'phonebk', 'phonetic', | 964 'big5han', 'dict', 'direct', 'ducet', 'gb2312', 'phonebk', 'phonetic', |
964 'pinyin', 'reformed', 'searchjl', 'stroke', 'trad', 'unihan', 'zhuyin' | 965 'pinyin', 'reformed', 'searchjl', 'stroke', 'trad', 'unihan', 'zhuyin' |
965 ]; | 966 ]; |
966 | 967 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 locale: {writable: true}, | 1220 locale: {writable: true}, |
1220 maximumFractionDigits: {writable: true}, | 1221 maximumFractionDigits: {writable: true}, |
1221 minimumFractionDigits: {writable: true}, | 1222 minimumFractionDigits: {writable: true}, |
1222 minimumIntegerDigits: {writable: true}, | 1223 minimumIntegerDigits: {writable: true}, |
1223 numberingSystem: {writable: true}, | 1224 numberingSystem: {writable: true}, |
1224 pattern: patternAccessor, | 1225 pattern: patternAccessor, |
1225 requestedLocale: {value: requestedLocale, writable: true}, | 1226 requestedLocale: {value: requestedLocale, writable: true}, |
1226 style: {value: internalOptions.style, writable: true}, | 1227 style: {value: internalOptions.style, writable: true}, |
1227 useGrouping: {writable: true} | 1228 useGrouping: {writable: true} |
1228 }); | 1229 }); |
1229 if (%HasOwnProperty(internalOptions, 'minimumSignificantDigits')) { | 1230 if (HAS_OWN_PROPERTY(internalOptions, 'minimumSignificantDigits')) { |
1230 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED); | 1231 defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED); |
1231 } | 1232 } |
1232 if (%HasOwnProperty(internalOptions, 'maximumSignificantDigits')) { | 1233 if (HAS_OWN_PROPERTY(internalOptions, 'maximumSignificantDigits')) { |
1233 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED); | 1234 defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED); |
1234 } | 1235 } |
1235 var formatter = %CreateNumberFormat(requestedLocale, | 1236 var formatter = %CreateNumberFormat(requestedLocale, |
1236 internalOptions, | 1237 internalOptions, |
1237 resolved); | 1238 resolved); |
1238 | 1239 |
1239 if (internalOptions.style === 'currency') { | 1240 if (internalOptions.style === 'currency') { |
1240 ObjectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, | 1241 ObjectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, |
1241 writable: true}); | 1242 writable: true}); |
1242 } | 1243 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 minimumFractionDigits: format[resolvedSymbol].minimumFractionDigits, | 1295 minimumFractionDigits: format[resolvedSymbol].minimumFractionDigits, |
1295 maximumFractionDigits: format[resolvedSymbol].maximumFractionDigits, | 1296 maximumFractionDigits: format[resolvedSymbol].maximumFractionDigits, |
1296 }; | 1297 }; |
1297 | 1298 |
1298 if (result.style === 'currency') { | 1299 if (result.style === 'currency') { |
1299 defineWECProperty(result, 'currency', format[resolvedSymbol].currency); | 1300 defineWECProperty(result, 'currency', format[resolvedSymbol].currency); |
1300 defineWECProperty(result, 'currencyDisplay', | 1301 defineWECProperty(result, 'currencyDisplay', |
1301 format[resolvedSymbol].currencyDisplay); | 1302 format[resolvedSymbol].currencyDisplay); |
1302 } | 1303 } |
1303 | 1304 |
1304 if (%HasOwnProperty(format[resolvedSymbol], 'minimumSignificantDigits')) { | 1305 if (HAS_OWN_PROPERTY(format[resolvedSymbol], 'minimumSignificantDigits')) { |
1305 defineWECProperty(result, 'minimumSignificantDigits', | 1306 defineWECProperty(result, 'minimumSignificantDigits', |
1306 format[resolvedSymbol].minimumSignificantDigits); | 1307 format[resolvedSymbol].minimumSignificantDigits); |
1307 } | 1308 } |
1308 | 1309 |
1309 if (%HasOwnProperty(format[resolvedSymbol], 'maximumSignificantDigits')) { | 1310 if (HAS_OWN_PROPERTY(format[resolvedSymbol], 'maximumSignificantDigits')) { |
1310 defineWECProperty(result, 'maximumSignificantDigits', | 1311 defineWECProperty(result, 'maximumSignificantDigits', |
1311 format[resolvedSymbol].maximumSignificantDigits); | 1312 format[resolvedSymbol].maximumSignificantDigits); |
1312 } | 1313 } |
1313 | 1314 |
1314 return result; | 1315 return result; |
1315 } | 1316 } |
1316 ); | 1317 ); |
1317 | 1318 |
1318 | 1319 |
1319 /** | 1320 /** |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 match = %_Call(StringMatch, ldmlString, /z|zzzz/g); | 1480 match = %_Call(StringMatch, ldmlString, /z|zzzz/g); |
1480 options = appendToDateTimeObject( | 1481 options = appendToDateTimeObject( |
1481 options, 'timeZoneName', match, {z: 'short', zzzz: 'long'}); | 1482 options, 'timeZoneName', match, {z: 'short', zzzz: 'long'}); |
1482 | 1483 |
1483 return options; | 1484 return options; |
1484 } | 1485 } |
1485 | 1486 |
1486 | 1487 |
1487 function appendToDateTimeObject(options, option, match, pairs) { | 1488 function appendToDateTimeObject(options, option, match, pairs) { |
1488 if (IS_NULL(match)) { | 1489 if (IS_NULL(match)) { |
1489 if (!%HasOwnProperty(options, option)) { | 1490 if (!HAS_OWN_PROPERTY(options, option)) { |
1490 defineWEProperty(options, option, UNDEFINED); | 1491 defineWEProperty(options, option, UNDEFINED); |
1491 } | 1492 } |
1492 return options; | 1493 return options; |
1493 } | 1494 } |
1494 | 1495 |
1495 var property = match[0]; | 1496 var property = match[0]; |
1496 defineWEProperty(options, option, pairs[property]); | 1497 defineWEProperty(options, option, pairs[property]); |
1497 | 1498 |
1498 return options; | 1499 return options; |
1499 } | 1500 } |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2147 } | 2148 } |
2148 | 2149 |
2149 var locales = arguments[0]; | 2150 var locales = arguments[0]; |
2150 var options = arguments[1]; | 2151 var options = arguments[1]; |
2151 return toLocaleDateTime( | 2152 return toLocaleDateTime( |
2152 this, locales, options, 'time', 'time', 'dateformattime'); | 2153 this, locales, options, 'time', 'time', 'dateformattime'); |
2153 } | 2154 } |
2154 ); | 2155 ); |
2155 | 2156 |
2156 }) | 2157 }) |
OLD | NEW |