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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 RegExpTest = from.RegExpTest; | 57 RegExpTest = from.RegExpTest; |
58 StringIndexOf = from.StringIndexOf; | 58 StringIndexOf = from.StringIndexOf; |
59 StringLastIndexOf = from.StringLastIndexOf; | 59 StringLastIndexOf = from.StringLastIndexOf; |
60 StringMatch = from.StringMatch; | 60 StringMatch = from.StringMatch; |
61 StringReplace = from.StringReplace; | 61 StringReplace = from.StringReplace; |
62 StringSplit = from.StringSplit; | 62 StringSplit = from.StringSplit; |
63 StringSubstr = from.StringSubstr; | 63 StringSubstr = from.StringSubstr; |
64 StringSubstring = from.StringSubstring; | 64 StringSubstring = from.StringSubstring; |
65 }); | 65 }); |
66 | 66 |
67 // Utilities for definitions | 67 // ------------------------------------------------------------------- |
68 | 68 |
69 function OverrideFunction(object, name, f) { | 69 var Intl = {}; |
70 %CheckIsBootstrapping(); | 70 |
71 ObjectDefineProperty(object, name, { value: f, | 71 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); |
72 writeable: true, | 72 |
73 configurable: true, | 73 /** |
74 enumerable: false }); | 74 * Caches available locales for each service. |
75 %FunctionSetName(f, name); | 75 */ |
76 %FunctionRemovePrototype(f); | 76 var AVAILABLE_LOCALES = { |
77 %SetNativeFlag(f); | 77 'collator': UNDEFINED, |
| 78 'numberformat': UNDEFINED, |
| 79 'dateformat': UNDEFINED, |
| 80 'breakiterator': UNDEFINED |
| 81 }; |
| 82 |
| 83 /** |
| 84 * Caches default ICU locale. |
| 85 */ |
| 86 var DEFAULT_ICU_LOCALE = UNDEFINED; |
| 87 |
| 88 /** |
| 89 * Unicode extension regular expression. |
| 90 */ |
| 91 var UNICODE_EXTENSION_RE = UNDEFINED; |
| 92 |
| 93 function GetUnicodeExtensionRE() { |
| 94 if (IS_UNDEFINED(UNDEFINED)) { |
| 95 UNICODE_EXTENSION_RE = new GlobalRegExp('-u(-[a-z0-9]{2,8})+', 'g'); |
| 96 } |
| 97 return UNICODE_EXTENSION_RE; |
78 } | 98 } |
79 | 99 |
80 function InstallFunction(object, name, func) { | 100 /** |
81 utils.InstallFunctions(object, DONT_ENUM, [name, func]); | 101 * Matches any Unicode extension. |
| 102 */ |
| 103 var ANY_EXTENSION_RE = UNDEFINED; |
| 104 |
| 105 function GetAnyExtensionRE() { |
| 106 if (IS_UNDEFINED(ANY_EXTENSION_RE)) { |
| 107 ANY_EXTENSION_RE = new GlobalRegExp('-[a-z0-9]{1}-.*', 'g'); |
| 108 } |
| 109 return ANY_EXTENSION_RE; |
82 } | 110 } |
83 | 111 |
| 112 /** |
| 113 * Replace quoted text (single quote, anything but the quote and quote again). |
| 114 */ |
| 115 var QUOTED_STRING_RE = UNDEFINED; |
84 | 116 |
85 function InstallConstructor(object, name, func) { | 117 function GetQuotedStringRE() { |
86 %CheckIsBootstrapping(); | 118 if (IS_UNDEFINED(QUOTED_STRING_RE)) { |
87 utils.SetFunctionName(func, name); | 119 QUOTED_STRING_RE = new GlobalRegExp("'[^']+'", 'g'); |
88 %AddNamedProperty(object, name, func, DONT_ENUM); | 120 } |
89 %SetNativeFlag(func); | 121 return QUOTED_STRING_RE; |
90 %ToFastProperties(object); | 122 } |
| 123 |
| 124 /** |
| 125 * Matches valid service name. |
| 126 */ |
| 127 var SERVICE_RE = UNDEFINED; |
| 128 |
| 129 function GetServiceRE() { |
| 130 if (IS_UNDEFINED(SERVICE_RE)) { |
| 131 SERVICE_RE = |
| 132 new GlobalRegExp('^(collator|numberformat|dateformat|breakiterator)$'); |
| 133 } |
| 134 return SERVICE_RE; |
| 135 } |
| 136 |
| 137 /** |
| 138 * Validates a language tag against bcp47 spec. |
| 139 * Actual value is assigned on first run. |
| 140 */ |
| 141 var LANGUAGE_TAG_RE = UNDEFINED; |
| 142 |
| 143 function GetLanguageTagRE() { |
| 144 if (IS_UNDEFINED(LANGUAGE_TAG_RE)) { |
| 145 BuildLanguageTagREs(); |
| 146 } |
| 147 return LANGUAGE_TAG_RE; |
| 148 } |
| 149 |
| 150 /** |
| 151 * Helps find duplicate variants in the language tag. |
| 152 */ |
| 153 var LANGUAGE_VARIANT_RE = UNDEFINED; |
| 154 |
| 155 function GetLanguageVariantRE() { |
| 156 if (IS_UNDEFINED(LANGUAGE_VARIANT_RE)) { |
| 157 BuildLanguageTagREs(); |
| 158 } |
| 159 return LANGUAGE_VARIANT_RE; |
| 160 } |
| 161 |
| 162 /** |
| 163 * Helps find duplicate singletons in the language tag. |
| 164 */ |
| 165 var LANGUAGE_SINGLETON_RE = UNDEFINED; |
| 166 |
| 167 function GetLanguageSingletonRE() { |
| 168 if (IS_UNDEFINED(LANGUAGE_SINGLETON_RE)) { |
| 169 BuildLanguageTagREs(); |
| 170 } |
| 171 return LANGUAGE_SINGLETON_RE; |
| 172 } |
| 173 |
| 174 /** |
| 175 * Matches valid IANA time zone names. |
| 176 */ |
| 177 var TIMEZONE_NAME_CHECK_RE = UNDEFINED; |
| 178 |
| 179 function GetTimezoneNameCheckRE() { |
| 180 if (IS_UNDEFINED(TIMEZONE_NAME_CHECK_RE)) { |
| 181 TIMEZONE_NAME_CHECK_RE = new GlobalRegExp( |
| 182 '^([A-Za-z]+)/([A-Za-z_-]+)((?:\/[A-Za-z_-]+)+)*$'); |
| 183 } |
| 184 return TIMEZONE_NAME_CHECK_RE; |
| 185 } |
| 186 |
| 187 /** |
| 188 * Matches valid location parts of IANA time zone names. |
| 189 */ |
| 190 var TIMEZONE_NAME_LOCATION_PART_RE = UNDEFINED; |
| 191 |
| 192 function GetTimezoneNameLocationPartRE() { |
| 193 if (IS_UNDEFINED(TIMEZONE_NAME_LOCATION_PART_RE)) { |
| 194 TIMEZONE_NAME_LOCATION_PART_RE = |
| 195 new GlobalRegExp('^([A-Za-z]+)((?:[_-][A-Za-z]+)+)*$'); |
| 196 } |
| 197 return TIMEZONE_NAME_LOCATION_PART_RE; |
91 } | 198 } |
92 | 199 |
93 /** | 200 /** |
94 * Adds bound method to the prototype of the given object. | 201 * Adds bound method to the prototype of the given object. |
95 */ | 202 */ |
96 function AddBoundMethod(obj, methodName, implementation, length) { | 203 function addBoundMethod(obj, methodName, implementation, length) { |
97 %CheckIsBootstrapping(); | 204 %CheckIsBootstrapping(); |
98 var internalName = %CreatePrivateSymbol(methodName); | 205 var internalName = %CreatePrivateSymbol(methodName); |
99 var getter = function() { | 206 function getter() { |
100 if (!%IsInitializedIntlObject(this)) { | 207 if (!%IsInitializedIntlObject(this)) { |
101 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); | 208 throw MakeTypeError(kMethodCalledOnWrongObject, methodName); |
102 } | 209 } |
103 if (IS_UNDEFINED(this[internalName])) { | 210 if (IS_UNDEFINED(this[internalName])) { |
104 var boundMethod; | 211 var boundMethod; |
105 if (IS_UNDEFINED(length) || length === 2) { | 212 if (IS_UNDEFINED(length) || length === 2) { |
106 boundMethod = (x, y) => implementation(this, x, y); | 213 boundMethod = (x, y) => implementation(this, x, y); |
107 } else if (length === 1) { | 214 } else if (length === 1) { |
108 boundMethod = x => implementation(this, x); | 215 boundMethod = x => implementation(this, x); |
109 } else { | 216 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
120 } | 227 } |
121 // TODO(littledan): Once function name reform is shipped, remove the | 228 // TODO(littledan): Once function name reform is shipped, remove the |
122 // following line and wrap the boundMethod definition in an anonymous | 229 // following line and wrap the boundMethod definition in an anonymous |
123 // function macro. | 230 // function macro. |
124 %FunctionSetName(boundMethod, '__bound' + methodName + '__'); | 231 %FunctionSetName(boundMethod, '__bound' + methodName + '__'); |
125 %FunctionRemovePrototype(boundMethod); | 232 %FunctionRemovePrototype(boundMethod); |
126 %SetNativeFlag(boundMethod); | 233 %SetNativeFlag(boundMethod); |
127 this[internalName] = boundMethod; | 234 this[internalName] = boundMethod; |
128 } | 235 } |
129 return this[internalName]; | 236 return this[internalName]; |
130 }; | 237 } |
131 | 238 |
132 utils.InstallGetter(obj.prototype, methodName, getter, DONT_ENUM); | 239 %FunctionSetName(getter, methodName); |
133 } | 240 %FunctionRemovePrototype(getter); |
| 241 %SetNativeFlag(getter); |
134 | 242 |
135 // ------------------------------------------------------------------- | 243 ObjectDefineProperty(obj.prototype, methodName, { |
136 | 244 get: getter, |
137 var Intl = {}; | 245 enumerable: false, |
138 | 246 configurable: true |
139 %AddNamedProperty(global, "Intl", Intl, DONT_ENUM); | 247 }); |
140 | |
141 /** | |
142 * Caches available locales for each service. | |
143 */ | |
144 var AVAILABLE_LOCALES = { | |
145 'collator': UNDEFINED, | |
146 'numberformat': UNDEFINED, | |
147 'dateformat': UNDEFINED, | |
148 'breakiterator': UNDEFINED | |
149 }; | |
150 | |
151 /** | |
152 * Caches default ICU locale. | |
153 */ | |
154 var DEFAULT_ICU_LOCALE = UNDEFINED; | |
155 | |
156 /** | |
157 * Unicode extension regular expression. | |
158 */ | |
159 var UNICODE_EXTENSION_RE = UNDEFINED; | |
160 | |
161 function GetUnicodeExtensionRE() { | |
162 if (IS_UNDEFINED(UNDEFINED)) { | |
163 UNICODE_EXTENSION_RE = new GlobalRegExp('-u(-[a-z0-9]{2,8})+', 'g'); | |
164 } | |
165 return UNICODE_EXTENSION_RE; | |
166 } | |
167 | |
168 /** | |
169 * Matches any Unicode extension. | |
170 */ | |
171 var ANY_EXTENSION_RE = UNDEFINED; | |
172 | |
173 function GetAnyExtensionRE() { | |
174 if (IS_UNDEFINED(ANY_EXTENSION_RE)) { | |
175 ANY_EXTENSION_RE = new GlobalRegExp('-[a-z0-9]{1}-.*', 'g'); | |
176 } | |
177 return ANY_EXTENSION_RE; | |
178 } | |
179 | |
180 /** | |
181 * Replace quoted text (single quote, anything but the quote and quote again). | |
182 */ | |
183 var QUOTED_STRING_RE = UNDEFINED; | |
184 | |
185 function GetQuotedStringRE() { | |
186 if (IS_UNDEFINED(QUOTED_STRING_RE)) { | |
187 QUOTED_STRING_RE = new GlobalRegExp("'[^']+'", 'g'); | |
188 } | |
189 return QUOTED_STRING_RE; | |
190 } | |
191 | |
192 /** | |
193 * Matches valid service name. | |
194 */ | |
195 var SERVICE_RE = UNDEFINED; | |
196 | |
197 function GetServiceRE() { | |
198 if (IS_UNDEFINED(SERVICE_RE)) { | |
199 SERVICE_RE = | |
200 new GlobalRegExp('^(collator|numberformat|dateformat|breakiterator)$'); | |
201 } | |
202 return SERVICE_RE; | |
203 } | |
204 | |
205 /** | |
206 * Validates a language tag against bcp47 spec. | |
207 * Actual value is assigned on first run. | |
208 */ | |
209 var LANGUAGE_TAG_RE = UNDEFINED; | |
210 | |
211 function GetLanguageTagRE() { | |
212 if (IS_UNDEFINED(LANGUAGE_TAG_RE)) { | |
213 BuildLanguageTagREs(); | |
214 } | |
215 return LANGUAGE_TAG_RE; | |
216 } | |
217 | |
218 /** | |
219 * Helps find duplicate variants in the language tag. | |
220 */ | |
221 var LANGUAGE_VARIANT_RE = UNDEFINED; | |
222 | |
223 function GetLanguageVariantRE() { | |
224 if (IS_UNDEFINED(LANGUAGE_VARIANT_RE)) { | |
225 BuildLanguageTagREs(); | |
226 } | |
227 return LANGUAGE_VARIANT_RE; | |
228 } | |
229 | |
230 /** | |
231 * Helps find duplicate singletons in the language tag. | |
232 */ | |
233 var LANGUAGE_SINGLETON_RE = UNDEFINED; | |
234 | |
235 function GetLanguageSingletonRE() { | |
236 if (IS_UNDEFINED(LANGUAGE_SINGLETON_RE)) { | |
237 BuildLanguageTagREs(); | |
238 } | |
239 return LANGUAGE_SINGLETON_RE; | |
240 } | |
241 | |
242 /** | |
243 * Matches valid IANA time zone names. | |
244 */ | |
245 var TIMEZONE_NAME_CHECK_RE = UNDEFINED; | |
246 | |
247 function GetTimezoneNameCheckRE() { | |
248 if (IS_UNDEFINED(TIMEZONE_NAME_CHECK_RE)) { | |
249 TIMEZONE_NAME_CHECK_RE = new GlobalRegExp( | |
250 '^([A-Za-z]+)/([A-Za-z_-]+)((?:\/[A-Za-z_-]+)+)*$'); | |
251 } | |
252 return TIMEZONE_NAME_CHECK_RE; | |
253 } | |
254 | |
255 /** | |
256 * Matches valid location parts of IANA time zone names. | |
257 */ | |
258 var TIMEZONE_NAME_LOCATION_PART_RE = UNDEFINED; | |
259 | |
260 function GetTimezoneNameLocationPartRE() { | |
261 if (IS_UNDEFINED(TIMEZONE_NAME_LOCATION_PART_RE)) { | |
262 TIMEZONE_NAME_LOCATION_PART_RE = | |
263 new GlobalRegExp('^([A-Za-z]+)((?:[_-][A-Za-z]+)+)*$'); | |
264 } | |
265 return TIMEZONE_NAME_LOCATION_PART_RE; | |
266 } | 248 } |
267 | 249 |
268 | 250 |
269 /** | 251 /** |
270 * Returns an intersection of locales and service supported locales. | 252 * Returns an intersection of locales and service supported locales. |
271 * Parameter locales is treated as a priority list. | 253 * Parameter locales is treated as a priority list. |
272 */ | 254 */ |
273 function supportedLocalesOf(service, locales, options) { | 255 function supportedLocalesOf(service, locales, options) { |
274 if (IS_NULL(%_Call(StringMatch, service, GetServiceRE()))) { | 256 if (IS_NULL(%_Call(StringMatch, service, GetServiceRE()))) { |
275 throw MakeError(kWrongServiceType, service); | 257 throw MakeError(kWrongServiceType, service); |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 return collator; | 983 return collator; |
1002 } | 984 } |
1003 | 985 |
1004 | 986 |
1005 /** | 987 /** |
1006 * Constructs Intl.Collator object given optional locales and options | 988 * Constructs Intl.Collator object given optional locales and options |
1007 * parameters. | 989 * parameters. |
1008 * | 990 * |
1009 * @constructor | 991 * @constructor |
1010 */ | 992 */ |
1011 InstallConstructor(Intl, 'Collator', function() { | 993 %AddNamedProperty(Intl, 'Collator', function() { |
1012 var locales = arguments[0]; | 994 var locales = arguments[0]; |
1013 var options = arguments[1]; | 995 var options = arguments[1]; |
1014 | 996 |
1015 if (!this || this === Intl) { | 997 if (!this || this === Intl) { |
1016 // Constructor is called as a function. | 998 // Constructor is called as a function. |
1017 return new Intl.Collator(locales, options); | 999 return new Intl.Collator(locales, options); |
1018 } | 1000 } |
1019 | 1001 |
1020 return initializeCollator(TO_OBJECT(this), locales, options); | 1002 return initializeCollator(TO_OBJECT(this), locales, options); |
1021 } | 1003 }, |
| 1004 DONT_ENUM |
1022 ); | 1005 ); |
1023 | 1006 |
1024 | 1007 |
1025 /** | 1008 /** |
1026 * Collator resolvedOptions method. | 1009 * Collator resolvedOptions method. |
1027 */ | 1010 */ |
1028 InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { | 1011 %AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() { |
1029 if (!IS_UNDEFINED(new.target)) { | 1012 if (!IS_UNDEFINED(new.target)) { |
1030 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1013 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1031 } | 1014 } |
1032 | 1015 |
1033 if (!%IsInitializedIntlObjectOfType(this, 'collator')) { | 1016 if (!%IsInitializedIntlObjectOfType(this, 'collator')) { |
1034 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "Collator"); | 1017 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "Collator"); |
1035 } | 1018 } |
1036 | 1019 |
1037 var coll = this; | 1020 var coll = this; |
1038 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale, | 1021 var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale, |
1039 coll[resolvedSymbol].locale); | 1022 coll[resolvedSymbol].locale); |
1040 | 1023 |
1041 return { | 1024 return { |
1042 locale: locale, | 1025 locale: locale, |
1043 usage: coll[resolvedSymbol].usage, | 1026 usage: coll[resolvedSymbol].usage, |
1044 sensitivity: coll[resolvedSymbol].sensitivity, | 1027 sensitivity: coll[resolvedSymbol].sensitivity, |
1045 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation, | 1028 ignorePunctuation: coll[resolvedSymbol].ignorePunctuation, |
1046 numeric: coll[resolvedSymbol].numeric, | 1029 numeric: coll[resolvedSymbol].numeric, |
1047 caseFirst: coll[resolvedSymbol].caseFirst, | 1030 caseFirst: coll[resolvedSymbol].caseFirst, |
1048 collation: coll[resolvedSymbol].collation | 1031 collation: coll[resolvedSymbol].collation |
1049 }; | 1032 }; |
1050 } | 1033 }, |
| 1034 DONT_ENUM |
1051 ); | 1035 ); |
| 1036 %FunctionSetName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions'); |
| 1037 %FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); |
| 1038 %SetNativeFlag(Intl.Collator.prototype.resolvedOptions); |
1052 | 1039 |
1053 | 1040 |
1054 /** | 1041 /** |
1055 * Returns the subset of the given locale list for which this locale list | 1042 * Returns the subset of the given locale list for which this locale list |
1056 * has a matching (possibly fallback) locale. Locales appear in the same | 1043 * has a matching (possibly fallback) locale. Locales appear in the same |
1057 * order in the returned list as in the input list. | 1044 * order in the returned list as in the input list. |
1058 * Options are optional parameter. | 1045 * Options are optional parameter. |
1059 */ | 1046 */ |
1060 InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) { | 1047 %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { |
1061 if (!IS_UNDEFINED(new.target)) { | 1048 if (!IS_UNDEFINED(new.target)) { |
1062 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1049 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1063 } | 1050 } |
1064 | 1051 |
1065 return supportedLocalesOf('collator', locales, arguments[1]); | 1052 return supportedLocalesOf('collator', locales, arguments[1]); |
1066 } | 1053 }, |
| 1054 DONT_ENUM |
1067 ); | 1055 ); |
| 1056 %FunctionSetName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); |
| 1057 %FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); |
| 1058 %SetNativeFlag(Intl.Collator.supportedLocalesOf); |
1068 | 1059 |
1069 | 1060 |
1070 /** | 1061 /** |
1071 * When the compare method is called with two arguments x and y, it returns a | 1062 * When the compare method is called with two arguments x and y, it returns a |
1072 * Number other than NaN that represents the result of a locale-sensitive | 1063 * Number other than NaN that represents the result of a locale-sensitive |
1073 * String comparison of x with y. | 1064 * String comparison of x with y. |
1074 * The result is intended to order String values in the sort order specified | 1065 * The result is intended to order String values in the sort order specified |
1075 * by the effective locale and collation options computed during construction | 1066 * by the effective locale and collation options computed during construction |
1076 * of this Collator object, and will be negative, zero, or positive, depending | 1067 * of this Collator object, and will be negative, zero, or positive, depending |
1077 * on whether x comes before y in the sort order, the Strings are equal under | 1068 * on whether x comes before y in the sort order, the Strings are equal under |
1078 * the sort order, or x comes after y in the sort order, respectively. | 1069 * the sort order, or x comes after y in the sort order, respectively. |
1079 */ | 1070 */ |
1080 function compare(collator, x, y) { | 1071 function compare(collator, x, y) { |
1081 return %InternalCompare(%GetImplFromInitializedIntlObject(collator), | 1072 return %InternalCompare(%GetImplFromInitializedIntlObject(collator), |
1082 GlobalString(x), GlobalString(y)); | 1073 GlobalString(x), GlobalString(y)); |
1083 }; | 1074 }; |
1084 | 1075 |
1085 | 1076 |
1086 AddBoundMethod(Intl.Collator, 'compare', compare, 2); | 1077 addBoundMethod(Intl.Collator, 'compare', compare, 2); |
1087 | 1078 |
1088 /** | 1079 /** |
1089 * Verifies that the input is a well-formed ISO 4217 currency code. | 1080 * Verifies that the input is a well-formed ISO 4217 currency code. |
1090 * Don't uppercase to test. It could convert invalid code into a valid one. | 1081 * Don't uppercase to test. It could convert invalid code into a valid one. |
1091 * For example \u00DFP (Eszett+P) becomes SSP. | 1082 * For example \u00DFP (Eszett+P) becomes SSP. |
1092 */ | 1083 */ |
1093 function isWellFormedCurrencyCode(currency) { | 1084 function isWellFormedCurrencyCode(currency) { |
1094 return typeof currency == "string" && | 1085 return typeof currency == "string" && |
1095 currency.length == 3 && | 1086 currency.length == 3 && |
1096 %_Call(StringMatch, currency, /[^A-Za-z]/) == null; | 1087 %_Call(StringMatch, currency, /[^A-Za-z]/) == null; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 return numberFormat; | 1236 return numberFormat; |
1246 } | 1237 } |
1247 | 1238 |
1248 | 1239 |
1249 /** | 1240 /** |
1250 * Constructs Intl.NumberFormat object given optional locales and options | 1241 * Constructs Intl.NumberFormat object given optional locales and options |
1251 * parameters. | 1242 * parameters. |
1252 * | 1243 * |
1253 * @constructor | 1244 * @constructor |
1254 */ | 1245 */ |
1255 InstallConstructor(Intl, 'NumberFormat', function() { | 1246 %AddNamedProperty(Intl, 'NumberFormat', function() { |
1256 var locales = arguments[0]; | 1247 var locales = arguments[0]; |
1257 var options = arguments[1]; | 1248 var options = arguments[1]; |
1258 | 1249 |
1259 if (!this || this === Intl) { | 1250 if (!this || this === Intl) { |
1260 // Constructor is called as a function. | 1251 // Constructor is called as a function. |
1261 return new Intl.NumberFormat(locales, options); | 1252 return new Intl.NumberFormat(locales, options); |
1262 } | 1253 } |
1263 | 1254 |
1264 return initializeNumberFormat(TO_OBJECT(this), locales, options); | 1255 return initializeNumberFormat(TO_OBJECT(this), locales, options); |
1265 } | 1256 }, |
| 1257 DONT_ENUM |
1266 ); | 1258 ); |
1267 | 1259 |
1268 | 1260 |
1269 /** | 1261 /** |
1270 * NumberFormat resolvedOptions method. | 1262 * NumberFormat resolvedOptions method. |
1271 */ | 1263 */ |
1272 InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { | 1264 %AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { |
1273 if (!IS_UNDEFINED(new.target)) { | 1265 if (!IS_UNDEFINED(new.target)) { |
1274 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1266 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1275 } | 1267 } |
1276 | 1268 |
1277 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { | 1269 if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { |
1278 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "NumberFormat"); | 1270 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "NumberFormat"); |
1279 } | 1271 } |
1280 | 1272 |
1281 var format = this; | 1273 var format = this; |
1282 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, | 1274 var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale, |
(...skipping 19 matching lines...) Expand all Loading... |
1302 defineWECProperty(result, 'minimumSignificantDigits', | 1294 defineWECProperty(result, 'minimumSignificantDigits', |
1303 format[resolvedSymbol].minimumSignificantDigits); | 1295 format[resolvedSymbol].minimumSignificantDigits); |
1304 } | 1296 } |
1305 | 1297 |
1306 if (%HasOwnProperty(format[resolvedSymbol], 'maximumSignificantDigits')) { | 1298 if (%HasOwnProperty(format[resolvedSymbol], 'maximumSignificantDigits')) { |
1307 defineWECProperty(result, 'maximumSignificantDigits', | 1299 defineWECProperty(result, 'maximumSignificantDigits', |
1308 format[resolvedSymbol].maximumSignificantDigits); | 1300 format[resolvedSymbol].maximumSignificantDigits); |
1309 } | 1301 } |
1310 | 1302 |
1311 return result; | 1303 return result; |
1312 } | 1304 }, |
| 1305 DONT_ENUM |
1313 ); | 1306 ); |
| 1307 %FunctionSetName(Intl.NumberFormat.prototype.resolvedOptions, |
| 1308 'resolvedOptions'); |
| 1309 %FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); |
| 1310 %SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); |
1314 | 1311 |
1315 | 1312 |
1316 /** | 1313 /** |
1317 * Returns the subset of the given locale list for which this locale list | 1314 * Returns the subset of the given locale list for which this locale list |
1318 * has a matching (possibly fallback) locale. Locales appear in the same | 1315 * has a matching (possibly fallback) locale. Locales appear in the same |
1319 * order in the returned list as in the input list. | 1316 * order in the returned list as in the input list. |
1320 * Options are optional parameter. | 1317 * Options are optional parameter. |
1321 */ | 1318 */ |
1322 InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { | 1319 %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { |
1323 if (!IS_UNDEFINED(new.target)) { | 1320 if (!IS_UNDEFINED(new.target)) { |
1324 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1321 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1325 } | 1322 } |
1326 | 1323 |
1327 return supportedLocalesOf('numberformat', locales, arguments[1]); | 1324 return supportedLocalesOf('numberformat', locales, arguments[1]); |
1328 } | 1325 }, |
| 1326 DONT_ENUM |
1329 ); | 1327 ); |
| 1328 %FunctionSetName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); |
| 1329 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); |
| 1330 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); |
1330 | 1331 |
1331 | 1332 |
1332 /** | 1333 /** |
1333 * Returns a String value representing the result of calling ToNumber(value) | 1334 * Returns a String value representing the result of calling ToNumber(value) |
1334 * according to the effective locale and the formatting options of this | 1335 * according to the effective locale and the formatting options of this |
1335 * NumberFormat. | 1336 * NumberFormat. |
1336 */ | 1337 */ |
1337 function formatNumber(formatter, value) { | 1338 function formatNumber(formatter, value) { |
1338 // Spec treats -0 and +0 as 0. | 1339 // Spec treats -0 and +0 as 0. |
1339 var number = TO_NUMBER(value) + 0; | 1340 var number = TO_NUMBER(value) + 0; |
1340 | 1341 |
1341 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), | 1342 return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), |
1342 number); | 1343 number); |
1343 } | 1344 } |
1344 | 1345 |
1345 | 1346 |
1346 /** | 1347 /** |
1347 * Returns a Number that represents string value that was passed in. | 1348 * Returns a Number that represents string value that was passed in. |
1348 */ | 1349 */ |
1349 function parseNumber(formatter, value) { | 1350 function parseNumber(formatter, value) { |
1350 return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter), | 1351 return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter), |
1351 GlobalString(value)); | 1352 GlobalString(value)); |
1352 } | 1353 } |
1353 | 1354 |
1354 | 1355 |
1355 AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); | 1356 addBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); |
1356 AddBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); | 1357 addBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); |
1357 | 1358 |
1358 /** | 1359 /** |
1359 * Returns a string that matches LDML representation of the options object. | 1360 * Returns a string that matches LDML representation of the options object. |
1360 */ | 1361 */ |
1361 function toLDMLString(options) { | 1362 function toLDMLString(options) { |
1362 var getOption = getGetOption(options, 'dateformat'); | 1363 var getOption = getGetOption(options, 'dateformat'); |
1363 | 1364 |
1364 var ldmlString = ''; | 1365 var ldmlString = ''; |
1365 | 1366 |
1366 var option = getOption('weekday', 'string', ['narrow', 'short', 'long']); | 1367 var option = getOption('weekday', 'string', ['narrow', 'short', 'long']); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 return dateFormat; | 1640 return dateFormat; |
1640 } | 1641 } |
1641 | 1642 |
1642 | 1643 |
1643 /** | 1644 /** |
1644 * Constructs Intl.DateTimeFormat object given optional locales and options | 1645 * Constructs Intl.DateTimeFormat object given optional locales and options |
1645 * parameters. | 1646 * parameters. |
1646 * | 1647 * |
1647 * @constructor | 1648 * @constructor |
1648 */ | 1649 */ |
1649 InstallConstructor(Intl, 'DateTimeFormat', function() { | 1650 %AddNamedProperty(Intl, 'DateTimeFormat', function() { |
1650 var locales = arguments[0]; | 1651 var locales = arguments[0]; |
1651 var options = arguments[1]; | 1652 var options = arguments[1]; |
1652 | 1653 |
1653 if (!this || this === Intl) { | 1654 if (!this || this === Intl) { |
1654 // Constructor is called as a function. | 1655 // Constructor is called as a function. |
1655 return new Intl.DateTimeFormat(locales, options); | 1656 return new Intl.DateTimeFormat(locales, options); |
1656 } | 1657 } |
1657 | 1658 |
1658 return initializeDateTimeFormat(TO_OBJECT(this), locales, options); | 1659 return initializeDateTimeFormat(TO_OBJECT(this), locales, options); |
1659 } | 1660 }, |
| 1661 DONT_ENUM |
1660 ); | 1662 ); |
1661 | 1663 |
1662 | 1664 |
1663 /** | 1665 /** |
1664 * DateTimeFormat resolvedOptions method. | 1666 * DateTimeFormat resolvedOptions method. |
1665 */ | 1667 */ |
1666 InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { | 1668 %AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { |
1667 if (!IS_UNDEFINED(new.target)) { | 1669 if (!IS_UNDEFINED(new.target)) { |
1668 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1670 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1669 } | 1671 } |
1670 | 1672 |
1671 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { | 1673 if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { |
1672 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "DateTimeFormat"); | 1674 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "DateTimeFormat"); |
1673 } | 1675 } |
1674 | 1676 |
1675 /** | 1677 /** |
1676 * Maps ICU calendar names into LDML type. | 1678 * Maps ICU calendar names into LDML type. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 addWECPropertyIfDefined(result, 'year', fromPattern.year); | 1717 addWECPropertyIfDefined(result, 'year', fromPattern.year); |
1716 addWECPropertyIfDefined(result, 'month', fromPattern.month); | 1718 addWECPropertyIfDefined(result, 'month', fromPattern.month); |
1717 addWECPropertyIfDefined(result, 'day', fromPattern.day); | 1719 addWECPropertyIfDefined(result, 'day', fromPattern.day); |
1718 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday); | 1720 addWECPropertyIfDefined(result, 'weekday', fromPattern.weekday); |
1719 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12); | 1721 addWECPropertyIfDefined(result, 'hour12', fromPattern.hour12); |
1720 addWECPropertyIfDefined(result, 'hour', fromPattern.hour); | 1722 addWECPropertyIfDefined(result, 'hour', fromPattern.hour); |
1721 addWECPropertyIfDefined(result, 'minute', fromPattern.minute); | 1723 addWECPropertyIfDefined(result, 'minute', fromPattern.minute); |
1722 addWECPropertyIfDefined(result, 'second', fromPattern.second); | 1724 addWECPropertyIfDefined(result, 'second', fromPattern.second); |
1723 | 1725 |
1724 return result; | 1726 return result; |
1725 } | 1727 }, |
| 1728 DONT_ENUM |
1726 ); | 1729 ); |
| 1730 %FunctionSetName(Intl.DateTimeFormat.prototype.resolvedOptions, |
| 1731 'resolvedOptions'); |
| 1732 %FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); |
| 1733 %SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); |
1727 | 1734 |
1728 | 1735 |
1729 /** | 1736 /** |
1730 * Returns the subset of the given locale list for which this locale list | 1737 * Returns the subset of the given locale list for which this locale list |
1731 * has a matching (possibly fallback) locale. Locales appear in the same | 1738 * has a matching (possibly fallback) locale. Locales appear in the same |
1732 * order in the returned list as in the input list. | 1739 * order in the returned list as in the input list. |
1733 * Options are optional parameter. | 1740 * Options are optional parameter. |
1734 */ | 1741 */ |
1735 InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { | 1742 %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { |
1736 if (!IS_UNDEFINED(new.target)) { | 1743 if (!IS_UNDEFINED(new.target)) { |
1737 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1744 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1738 } | 1745 } |
1739 | 1746 |
1740 return supportedLocalesOf('dateformat', locales, arguments[1]); | 1747 return supportedLocalesOf('dateformat', locales, arguments[1]); |
1741 } | 1748 }, |
| 1749 DONT_ENUM |
1742 ); | 1750 ); |
| 1751 %FunctionSetName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); |
| 1752 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); |
| 1753 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); |
1743 | 1754 |
1744 | 1755 |
1745 /** | 1756 /** |
1746 * Returns a String value representing the result of calling ToNumber(date) | 1757 * Returns a String value representing the result of calling ToNumber(date) |
1747 * according to the effective locale and the formatting options of this | 1758 * according to the effective locale and the formatting options of this |
1748 * DateTimeFormat. | 1759 * DateTimeFormat. |
1749 */ | 1760 */ |
1750 function formatDate(formatter, dateValue) { | 1761 function formatDate(formatter, dateValue) { |
1751 var dateMs; | 1762 var dateMs; |
1752 if (IS_UNDEFINED(dateValue)) { | 1763 if (IS_UNDEFINED(dateValue)) { |
(...skipping 15 matching lines...) Expand all Loading... |
1768 * DateTimeFormat. | 1779 * DateTimeFormat. |
1769 * Returns undefined if date string cannot be parsed. | 1780 * Returns undefined if date string cannot be parsed. |
1770 */ | 1781 */ |
1771 function parseDate(formatter, value) { | 1782 function parseDate(formatter, value) { |
1772 return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter), | 1783 return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter), |
1773 GlobalString(value)); | 1784 GlobalString(value)); |
1774 } | 1785 } |
1775 | 1786 |
1776 | 1787 |
1777 // 0 because date is optional argument. | 1788 // 0 because date is optional argument. |
1778 AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); | 1789 addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); |
1779 AddBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); | 1790 addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); |
1780 | 1791 |
1781 | 1792 |
1782 /** | 1793 /** |
1783 * Returns canonical Area/Location(/Location) name, or throws an exception | 1794 * Returns canonical Area/Location(/Location) name, or throws an exception |
1784 * if the zone name is invalid IANA name. | 1795 * if the zone name is invalid IANA name. |
1785 */ | 1796 */ |
1786 function canonicalizeTimeZoneID(tzID) { | 1797 function canonicalizeTimeZoneID(tzID) { |
1787 // Skip undefined zones. | 1798 // Skip undefined zones. |
1788 if (IS_UNDEFINED(tzID)) { | 1799 if (IS_UNDEFINED(tzID)) { |
1789 return tzID; | 1800 return tzID; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1856 return iterator; | 1867 return iterator; |
1857 } | 1868 } |
1858 | 1869 |
1859 | 1870 |
1860 /** | 1871 /** |
1861 * Constructs Intl.v8BreakIterator object given optional locales and options | 1872 * Constructs Intl.v8BreakIterator object given optional locales and options |
1862 * parameters. | 1873 * parameters. |
1863 * | 1874 * |
1864 * @constructor | 1875 * @constructor |
1865 */ | 1876 */ |
1866 InstallConstructor(Intl, 'v8BreakIterator', function() { | 1877 %AddNamedProperty(Intl, 'v8BreakIterator', function() { |
1867 var locales = arguments[0]; | 1878 var locales = arguments[0]; |
1868 var options = arguments[1]; | 1879 var options = arguments[1]; |
1869 | 1880 |
1870 if (!this || this === Intl) { | 1881 if (!this || this === Intl) { |
1871 // Constructor is called as a function. | 1882 // Constructor is called as a function. |
1872 return new Intl.v8BreakIterator(locales, options); | 1883 return new Intl.v8BreakIterator(locales, options); |
1873 } | 1884 } |
1874 | 1885 |
1875 return initializeBreakIterator(TO_OBJECT(this), locales, options); | 1886 return initializeBreakIterator(TO_OBJECT(this), locales, options); |
1876 } | 1887 }, |
| 1888 DONT_ENUM |
1877 ); | 1889 ); |
1878 | 1890 |
1879 | 1891 |
1880 /** | 1892 /** |
1881 * BreakIterator resolvedOptions method. | 1893 * BreakIterator resolvedOptions method. |
1882 */ | 1894 */ |
1883 InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions', | 1895 %AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', |
1884 function() { | 1896 function() { |
1885 if (!IS_UNDEFINED(new.target)) { | 1897 if (!IS_UNDEFINED(new.target)) { |
1886 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1898 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1887 } | 1899 } |
1888 | 1900 |
1889 if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) { | 1901 if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) { |
1890 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "v8BreakIterator"); | 1902 throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "v8BreakIterator"); |
1891 } | 1903 } |
1892 | 1904 |
1893 var segmenter = this; | 1905 var segmenter = this; |
1894 var locale = | 1906 var locale = |
1895 getOptimalLanguageTag(segmenter[resolvedSymbol].requestedLocale, | 1907 getOptimalLanguageTag(segmenter[resolvedSymbol].requestedLocale, |
1896 segmenter[resolvedSymbol].locale); | 1908 segmenter[resolvedSymbol].locale); |
1897 | 1909 |
1898 return { | 1910 return { |
1899 locale: locale, | 1911 locale: locale, |
1900 type: segmenter[resolvedSymbol].type | 1912 type: segmenter[resolvedSymbol].type |
1901 }; | 1913 }; |
1902 } | 1914 }, |
| 1915 DONT_ENUM |
1903 ); | 1916 ); |
| 1917 %FunctionSetName(Intl.v8BreakIterator.prototype.resolvedOptions, |
| 1918 'resolvedOptions'); |
| 1919 %FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); |
| 1920 %SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); |
1904 | 1921 |
1905 | 1922 |
1906 /** | 1923 /** |
1907 * Returns the subset of the given locale list for which this locale list | 1924 * Returns the subset of the given locale list for which this locale list |
1908 * has a matching (possibly fallback) locale. Locales appear in the same | 1925 * has a matching (possibly fallback) locale. Locales appear in the same |
1909 * order in the returned list as in the input list. | 1926 * order in the returned list as in the input list. |
1910 * Options are optional parameter. | 1927 * Options are optional parameter. |
1911 */ | 1928 */ |
1912 InstallFunction(Intl.v8BreakIterator, 'supportedLocalesOf', | 1929 %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', |
1913 function(locales) { | 1930 function(locales) { |
1914 if (!IS_UNDEFINED(new.target)) { | 1931 if (!IS_UNDEFINED(new.target)) { |
1915 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 1932 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
1916 } | 1933 } |
1917 | 1934 |
1918 return supportedLocalesOf('breakiterator', locales, arguments[1]); | 1935 return supportedLocalesOf('breakiterator', locales, arguments[1]); |
1919 } | 1936 }, |
| 1937 DONT_ENUM |
1920 ); | 1938 ); |
| 1939 %FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); |
| 1940 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); |
| 1941 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); |
1921 | 1942 |
1922 | 1943 |
1923 /** | 1944 /** |
1924 * Adopts text to segment using the iterator. Old text, if present, | 1945 * Adopts text to segment using the iterator. Old text, if present, |
1925 * gets discarded. | 1946 * gets discarded. |
1926 */ | 1947 */ |
1927 function adoptText(iterator, text) { | 1948 function adoptText(iterator, text) { |
1928 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), | 1949 %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), |
1929 GlobalString(text)); | 1950 GlobalString(text)); |
1930 } | 1951 } |
(...skipping 24 matching lines...) Expand all Loading... |
1955 | 1976 |
1956 | 1977 |
1957 /** | 1978 /** |
1958 * Returns type of the current break. | 1979 * Returns type of the current break. |
1959 */ | 1980 */ |
1960 function breakType(iterator) { | 1981 function breakType(iterator) { |
1961 return %BreakIteratorBreakType(%GetImplFromInitializedIntlObject(iterator)); | 1982 return %BreakIteratorBreakType(%GetImplFromInitializedIntlObject(iterator)); |
1962 } | 1983 } |
1963 | 1984 |
1964 | 1985 |
1965 AddBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1); | 1986 addBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1); |
1966 AddBoundMethod(Intl.v8BreakIterator, 'first', first, 0); | 1987 addBoundMethod(Intl.v8BreakIterator, 'first', first, 0); |
1967 AddBoundMethod(Intl.v8BreakIterator, 'next', next, 0); | 1988 addBoundMethod(Intl.v8BreakIterator, 'next', next, 0); |
1968 AddBoundMethod(Intl.v8BreakIterator, 'current', current, 0); | 1989 addBoundMethod(Intl.v8BreakIterator, 'current', current, 0); |
1969 AddBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0); | 1990 addBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0); |
1970 | 1991 |
1971 // Save references to Intl objects and methods we use, for added security. | 1992 // Save references to Intl objects and methods we use, for added security. |
1972 var savedObjects = { | 1993 var savedObjects = { |
1973 'collator': Intl.Collator, | 1994 'collator': Intl.Collator, |
1974 'numberformat': Intl.NumberFormat, | 1995 'numberformat': Intl.NumberFormat, |
1975 'dateformatall': Intl.DateTimeFormat, | 1996 'dateformatall': Intl.DateTimeFormat, |
1976 'dateformatdate': Intl.DateTimeFormat, | 1997 'dateformatdate': Intl.DateTimeFormat, |
1977 'dateformattime': Intl.DateTimeFormat | 1998 'dateformattime': Intl.DateTimeFormat |
1978 }; | 1999 }; |
1979 | 2000 |
(...skipping 17 matching lines...) Expand all Loading... |
1997 var useOptions = (IS_UNDEFINED(defaults)) ? options : defaults; | 2018 var useOptions = (IS_UNDEFINED(defaults)) ? options : defaults; |
1998 if (IS_UNDEFINED(locales) && IS_UNDEFINED(options)) { | 2019 if (IS_UNDEFINED(locales) && IS_UNDEFINED(options)) { |
1999 if (IS_UNDEFINED(defaultObjects[service])) { | 2020 if (IS_UNDEFINED(defaultObjects[service])) { |
2000 defaultObjects[service] = new savedObjects[service](locales, useOptions); | 2021 defaultObjects[service] = new savedObjects[service](locales, useOptions); |
2001 } | 2022 } |
2002 return defaultObjects[service]; | 2023 return defaultObjects[service]; |
2003 } | 2024 } |
2004 return new savedObjects[service](locales, useOptions); | 2025 return new savedObjects[service](locales, useOptions); |
2005 } | 2026 } |
2006 | 2027 |
| 2028 |
| 2029 function OverrideFunction(object, name, f) { |
| 2030 %CheckIsBootstrapping(); |
| 2031 ObjectDefineProperty(object, name, { value: f, |
| 2032 writeable: true, |
| 2033 configurable: true, |
| 2034 enumerable: false }); |
| 2035 %FunctionSetName(f, name); |
| 2036 %FunctionRemovePrototype(f); |
| 2037 %SetNativeFlag(f); |
| 2038 } |
| 2039 |
2007 /** | 2040 /** |
2008 * Compares this and that, and returns less than 0, 0 or greater than 0 value. | 2041 * Compares this and that, and returns less than 0, 0 or greater than 0 value. |
2009 * Overrides the built-in method. | 2042 * Overrides the built-in method. |
2010 */ | 2043 */ |
2011 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { | 2044 OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { |
2012 if (!IS_UNDEFINED(new.target)) { | 2045 if (!IS_UNDEFINED(new.target)) { |
2013 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); | 2046 throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
2014 } | 2047 } |
2015 | 2048 |
2016 if (IS_NULL_OR_UNDEFINED(this)) { | 2049 if (IS_NULL_OR_UNDEFINED(this)) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 } | 2177 } |
2145 | 2178 |
2146 var locales = arguments[0]; | 2179 var locales = arguments[0]; |
2147 var options = arguments[1]; | 2180 var options = arguments[1]; |
2148 return toLocaleDateTime( | 2181 return toLocaleDateTime( |
2149 this, locales, options, 'time', 'time', 'dateformattime'); | 2182 this, locales, options, 'time', 'time', 'dateformattime'); |
2150 } | 2183 } |
2151 ); | 2184 ); |
2152 | 2185 |
2153 }) | 2186 }) |
OLD | NEW |