| 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 10 matching lines...) Expand all Loading... |
| 21 var ArrayJoin; | 21 var ArrayJoin; |
| 22 var IsFinite; | 22 var IsFinite; |
| 23 var IsNaN; | 23 var IsNaN; |
| 24 var GlobalBoolean = global.Boolean; | 24 var GlobalBoolean = global.Boolean; |
| 25 var GlobalDate = global.Date; | 25 var GlobalDate = global.Date; |
| 26 var GlobalNumber = global.Number; | 26 var GlobalNumber = global.Number; |
| 27 var GlobalRegExp = global.RegExp; | 27 var GlobalRegExp = global.RegExp; |
| 28 var GlobalString = global.String; | 28 var GlobalString = global.String; |
| 29 var MathFloor; | 29 var MathFloor; |
| 30 var RegExpTest; | 30 var RegExpTest; |
| 31 var SetFunctionName = utils.SetFunctionName; | |
| 32 var StringIndexOf; | 31 var StringIndexOf; |
| 33 var StringLastIndexOf; | 32 var StringLastIndexOf; |
| 34 var StringMatch; | 33 var StringMatch; |
| 35 var StringReplace; | 34 var StringReplace; |
| 36 var StringSplit; | 35 var StringSplit; |
| 37 var StringSubstr; | 36 var StringSubstr; |
| 38 var StringSubstring; | 37 var StringSubstring; |
| 39 | 38 |
| 40 utils.Import(function(from) { | 39 utils.Import(function(from) { |
| 41 ArrayIndexOf = from.ArrayIndexOf; | 40 ArrayIndexOf = from.ArrayIndexOf; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // DateTimeFormat.format needs to be 0 arg method, but can stil | 213 // DateTimeFormat.format needs to be 0 arg method, but can stil |
| 215 // receive optional dateValue param. If one was provided, pass it | 214 // receive optional dateValue param. If one was provided, pass it |
| 216 // along. | 215 // along. |
| 217 if (%_ArgumentsLength() > 0) { | 216 if (%_ArgumentsLength() > 0) { |
| 218 return implementation(that, %_Arguments(0)); | 217 return implementation(that, %_Arguments(0)); |
| 219 } else { | 218 } else { |
| 220 return implementation(that); | 219 return implementation(that); |
| 221 } | 220 } |
| 222 } | 221 } |
| 223 } | 222 } |
| 224 SetFunctionName(boundMethod, internalName); | 223 %FunctionSetName(boundMethod, internalName); |
| 225 %FunctionRemovePrototype(boundMethod); | 224 %FunctionRemovePrototype(boundMethod); |
| 226 %SetNativeFlag(boundMethod); | 225 %SetNativeFlag(boundMethod); |
| 227 this[internalName] = boundMethod; | 226 this[internalName] = boundMethod; |
| 228 } | 227 } |
| 229 return this[internalName]; | 228 return this[internalName]; |
| 230 } | 229 } |
| 231 | 230 |
| 232 SetFunctionName(getter, methodName); | 231 %FunctionSetName(getter, methodName); |
| 233 %FunctionRemovePrototype(getter); | 232 %FunctionRemovePrototype(getter); |
| 234 %SetNativeFlag(getter); | 233 %SetNativeFlag(getter); |
| 235 | 234 |
| 236 ObjectDefineProperty(obj.prototype, methodName, { | 235 ObjectDefineProperty(obj.prototype, methodName, { |
| 237 get: getter, | 236 get: getter, |
| 238 enumerable: false, | 237 enumerable: false, |
| 239 configurable: true | 238 configurable: true |
| 240 }); | 239 }); |
| 241 } | 240 } |
| 242 | 241 |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 usage: coll.resolved.usage, | 980 usage: coll.resolved.usage, |
| 982 sensitivity: coll.resolved.sensitivity, | 981 sensitivity: coll.resolved.sensitivity, |
| 983 ignorePunctuation: coll.resolved.ignorePunctuation, | 982 ignorePunctuation: coll.resolved.ignorePunctuation, |
| 984 numeric: coll.resolved.numeric, | 983 numeric: coll.resolved.numeric, |
| 985 caseFirst: coll.resolved.caseFirst, | 984 caseFirst: coll.resolved.caseFirst, |
| 986 collation: coll.resolved.collation | 985 collation: coll.resolved.collation |
| 987 }; | 986 }; |
| 988 }, | 987 }, |
| 989 DONT_ENUM | 988 DONT_ENUM |
| 990 ); | 989 ); |
| 991 SetFunctionName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions'); | 990 %FunctionSetName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions'); |
| 992 %FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); | 991 %FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); |
| 993 %SetNativeFlag(Intl.Collator.prototype.resolvedOptions); | 992 %SetNativeFlag(Intl.Collator.prototype.resolvedOptions); |
| 994 | 993 |
| 995 | 994 |
| 996 /** | 995 /** |
| 997 * Returns the subset of the given locale list for which this locale list | 996 * Returns the subset of the given locale list for which this locale list |
| 998 * has a matching (possibly fallback) locale. Locales appear in the same | 997 * has a matching (possibly fallback) locale. Locales appear in the same |
| 999 * order in the returned list as in the input list. | 998 * order in the returned list as in the input list. |
| 1000 * Options are optional parameter. | 999 * Options are optional parameter. |
| 1001 */ | 1000 */ |
| 1002 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { | 1001 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { |
| 1003 if (%_IsConstructCall()) { | 1002 if (%_IsConstructCall()) { |
| 1004 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1003 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
| 1005 } | 1004 } |
| 1006 | 1005 |
| 1007 return supportedLocalesOf('collator', locales, %_Arguments(1)); | 1006 return supportedLocalesOf('collator', locales, %_Arguments(1)); |
| 1008 }, | 1007 }, |
| 1009 DONT_ENUM | 1008 DONT_ENUM |
| 1010 ); | 1009 ); |
| 1011 SetFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); | 1010 %FunctionSetName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); |
| 1012 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); | 1011 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); |
| 1013 %SetNativeFlag(Intl.Collator.supportedLocalesOf); | 1012 %SetNativeFlag(Intl.Collator.supportedLocalesOf); |
| 1014 | 1013 |
| 1015 | 1014 |
| 1016 /** | 1015 /** |
| 1017 * When the compare method is called with two arguments x and y, it returns a | 1016 * When the compare method is called with two arguments x and y, it returns a |
| 1018 * Number other than NaN that represents the result of a locale-sensitive | 1017 * Number other than NaN that represents the result of a locale-sensitive |
| 1019 * String comparison of x with y. | 1018 * String comparison of x with y. |
| 1020 * The result is intended to order String values in the sort order specified | 1019 * The result is intended to order String values in the sort order specified |
| 1021 * by the effective locale and collation options computed during construction | 1020 * by the effective locale and collation options computed during construction |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 | 1239 |
| 1241 if (%HasOwnProperty(format.resolved, 'maximumSignificantDigits')) { | 1240 if (%HasOwnProperty(format.resolved, 'maximumSignificantDigits')) { |
| 1242 defineWECProperty(result, 'maximumSignificantDigits', | 1241 defineWECProperty(result, 'maximumSignificantDigits', |
| 1243 format.resolved.maximumSignificantDigits); | 1242 format.resolved.maximumSignificantDigits); |
| 1244 } | 1243 } |
| 1245 | 1244 |
| 1246 return result; | 1245 return result; |
| 1247 }, | 1246 }, |
| 1248 DONT_ENUM | 1247 DONT_ENUM |
| 1249 ); | 1248 ); |
| 1250 SetFunctionName(Intl.NumberFormat.prototype.resolvedOptions, 'resolvedOptions'); | 1249 %FunctionSetName(Intl.NumberFormat.prototype.resolvedOptions, |
| 1250 'resolvedOptions'); |
| 1251 %FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); | 1251 %FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); |
| 1252 %SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); | 1252 %SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); |
| 1253 | 1253 |
| 1254 | 1254 |
| 1255 /** | 1255 /** |
| 1256 * Returns the subset of the given locale list for which this locale list | 1256 * Returns the subset of the given locale list for which this locale list |
| 1257 * has a matching (possibly fallback) locale. Locales appear in the same | 1257 * has a matching (possibly fallback) locale. Locales appear in the same |
| 1258 * order in the returned list as in the input list. | 1258 * order in the returned list as in the input list. |
| 1259 * Options are optional parameter. | 1259 * Options are optional parameter. |
| 1260 */ | 1260 */ |
| 1261 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { | 1261 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { |
| 1262 if (%_IsConstructCall()) { | 1262 if (%_IsConstructCall()) { |
| 1263 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1263 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
| 1264 } | 1264 } |
| 1265 | 1265 |
| 1266 return supportedLocalesOf('numberformat', locales, %_Arguments(1)); | 1266 return supportedLocalesOf('numberformat', locales, %_Arguments(1)); |
| 1267 }, | 1267 }, |
| 1268 DONT_ENUM | 1268 DONT_ENUM |
| 1269 ); | 1269 ); |
| 1270 SetFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); | 1270 %FunctionSetName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); |
| 1271 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); | 1271 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); |
| 1272 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); | 1272 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); |
| 1273 | 1273 |
| 1274 | 1274 |
| 1275 /** | 1275 /** |
| 1276 * Returns a String value representing the result of calling ToNumber(value) | 1276 * Returns a String value representing the result of calling ToNumber(value) |
| 1277 * according to the effective locale and the formatting options of this | 1277 * according to the effective locale and the formatting options of this |
| 1278 * NumberFormat. | 1278 * NumberFormat. |
| 1279 */ | 1279 */ |
| 1280 function formatNumber(formatter, value) { | 1280 function formatNumber(formatter, value) { |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday); | 1661 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday); |
| 1662 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12); | 1662 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12); |
| 1663 addWECPropertyIfDefined(result, 'hour', fromPattern.hour); | 1663 addWECPropertyIfDefined(result, 'hour', fromPattern.hour); |
| 1664 addWECPropertyIfDefined(result, 'minute', fromPattern.minute); | 1664 addWECPropertyIfDefined(result, 'minute', fromPattern.minute); |
| 1665 addWECPropertyIfDefined(result, 'second', fromPattern.second); | 1665 addWECPropertyIfDefined(result, 'second', fromPattern.second); |
| 1666 | 1666 |
| 1667 return result; | 1667 return result; |
| 1668 }, | 1668 }, |
| 1669 DONT_ENUM | 1669 DONT_ENUM |
| 1670 ); | 1670 ); |
| 1671 SetFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions, | 1671 %FunctionSetName(Intl.DateTimeFormat.prototype.resolvedOptions, |
| 1672 'resolvedOptions'); | 1672 'resolvedOptions'); |
| 1673 %FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); | 1673 %FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); |
| 1674 %SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); | 1674 %SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); |
| 1675 | 1675 |
| 1676 | 1676 |
| 1677 /** | 1677 /** |
| 1678 * Returns the subset of the given locale list for which this locale list | 1678 * Returns the subset of the given locale list for which this locale list |
| 1679 * has a matching (possibly fallback) locale. Locales appear in the same | 1679 * has a matching (possibly fallback) locale. Locales appear in the same |
| 1680 * order in the returned list as in the input list. | 1680 * order in the returned list as in the input list. |
| 1681 * Options are optional parameter. | 1681 * Options are optional parameter. |
| 1682 */ | 1682 */ |
| 1683 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { | 1683 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { |
| 1684 if (%_IsConstructCall()) { | 1684 if (%_IsConstructCall()) { |
| 1685 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1685 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
| 1686 } | 1686 } |
| 1687 | 1687 |
| 1688 return supportedLocalesOf('dateformat', locales, %_Arguments(1)); | 1688 return supportedLocalesOf('dateformat', locales, %_Arguments(1)); |
| 1689 }, | 1689 }, |
| 1690 DONT_ENUM | 1690 DONT_ENUM |
| 1691 ); | 1691 ); |
| 1692 SetFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); | 1692 %FunctionSetName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); |
| 1693 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); | 1693 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); |
| 1694 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); | 1694 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); |
| 1695 | 1695 |
| 1696 | 1696 |
| 1697 /** | 1697 /** |
| 1698 * Returns a String value representing the result of calling ToNumber(date) | 1698 * Returns a String value representing the result of calling ToNumber(date) |
| 1699 * according to the effective locale and the formatting options of this | 1699 * according to the effective locale and the formatting options of this |
| 1700 * DateTimeFormat. | 1700 * DateTimeFormat. |
| 1701 */ | 1701 */ |
| 1702 function formatDate(formatter, dateValue) { | 1702 function formatDate(formatter, dateValue) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1840 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, | 1840 var locale = getOptimalLanguageTag(segmenter.resolved.requestedLocale, |
| 1841 segmenter.resolved.locale); | 1841 segmenter.resolved.locale); |
| 1842 | 1842 |
| 1843 return { | 1843 return { |
| 1844 locale: locale, | 1844 locale: locale, |
| 1845 type: segmenter.resolved.type | 1845 type: segmenter.resolved.type |
| 1846 }; | 1846 }; |
| 1847 }, | 1847 }, |
| 1848 DONT_ENUM | 1848 DONT_ENUM |
| 1849 ); | 1849 ); |
| 1850 SetFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions, | 1850 %FunctionSetName(Intl.v8BreakIterator.prototype.resolvedOptions, |
| 1851 'resolvedOptions'); | 1851 'resolvedOptions'); |
| 1852 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); | 1852 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); |
| 1853 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); | 1853 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); |
| 1854 | 1854 |
| 1855 | 1855 |
| 1856 /** | 1856 /** |
| 1857 * Returns the subset of the given locale list for which this locale list | 1857 * Returns the subset of the given locale list for which this locale list |
| 1858 * has a matching (possibly fallback) locale. Locales appear in the same | 1858 * has a matching (possibly fallback) locale. Locales appear in the same |
| 1859 * order in the returned list as in the input list. | 1859 * order in the returned list as in the input list. |
| 1860 * Options are optional parameter. | 1860 * Options are optional parameter. |
| 1861 */ | 1861 */ |
| 1862 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', | 1862 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', |
| 1863 function(locales) { | 1863 function(locales) { |
| 1864 if (%_IsConstructCall()) { | 1864 if (%_IsConstructCall()) { |
| 1865 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1865 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
| 1866 } | 1866 } |
| 1867 | 1867 |
| 1868 return supportedLocalesOf('breakiterator', locales, %_Arguments(1)); | 1868 return supportedLocalesOf('breakiterator', locales, %_Arguments(1)); |
| 1869 }, | 1869 }, |
| 1870 DONT_ENUM | 1870 DONT_ENUM |
| 1871 ); | 1871 ); |
| 1872 SetFunctionName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); | 1872 %FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); |
| 1873 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); | 1873 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); |
| 1874 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); | 1874 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); |
| 1875 | 1875 |
| 1876 | 1876 |
| 1877 /** | 1877 /** |
| 1878 * Adopts text to segment using the iterator. Old text, if present, | 1878 * Adopts text to segment using the iterator. Old text, if present, |
| 1879 * gets discarded. | 1879 * gets discarded. |
| 1880 */ | 1880 */ |
| 1881 function adoptText(iterator, text) { | 1881 function adoptText(iterator, text) { |
| 1882 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), | 1882 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1958 return new savedObjects[service](locales, useOptions); | 1958 return new savedObjects[service](locales, useOptions); |
| 1959 } | 1959 } |
| 1960 | 1960 |
| 1961 | 1961 |
| 1962 function OverrideFunction(object, name, f) { | 1962 function OverrideFunction(object, name, f) { |
| 1963 %CheckIsBootstrapping(); | 1963 %CheckIsBootstrapping(); |
| 1964 ObjectDefineProperty(object, name, { value: f, | 1964 ObjectDefineProperty(object, name, { value: f, |
| 1965 writeable: true, | 1965 writeable: true, |
| 1966 configurable: true, | 1966 configurable: true, |
| 1967 enumerable: false }); | 1967 enumerable: false }); |
| 1968 SetFunctionName(f, name); | 1968 %FunctionSetName(f, name); |
| 1969 %FunctionRemovePrototype(f); | 1969 %FunctionRemovePrototype(f); |
| 1970 %SetNativeFlag(f); | 1970 %SetNativeFlag(f); |
| 1971 } | 1971 } |
| 1972 | 1972 |
| 1973 /** | 1973 /** |
| 1974 * Compares this and that, and returns less than 0, 0 or greater than 0 value. | 1974 * Compares this and that, and returns less than 0, 0 or greater than 0 value. |
| 1975 * Overrides the built-in method. | 1975 * Overrides the built-in method. |
| 1976 */ | 1976 */ |
| 1977 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { | 1977 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { |
| 1978 if (%_IsConstructCall()) { | 1978 if (%_IsConstructCall()) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 } | 2111 } |
| 2112 | 2112 |
| 2113 var locales = %_Arguments(0); | 2113 var locales = %_Arguments(0); |
| 2114 var options = %_Arguments(1); | 2114 var options = %_Arguments(1); |
| 2115 return toLocaleDateTime( | 2115 return toLocaleDateTime( |
| 2116 this, locales, options, 'time', 'time', 'dateformattime'); | 2116 this, locales, options, 'time', 'time', 'dateformattime'); |
| 2117 } | 2117 } |
| 2118 ); | 2118 ); |
| 2119 | 2119 |
| 2120 }) | 2120 }) |
| OLD | NEW |