OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 return fallback; | 59 return fallback; |
60 } | 60 } |
61 | 61 |
62 | 62 |
63 /** | 63 /** |
64 * Initializes the given object so it's a valid NumberFormat instance. | 64 * Initializes the given object so it's a valid NumberFormat instance. |
65 * Useful for subclassing. | 65 * Useful for subclassing. |
66 */ | 66 */ |
67 function initializeNumberFormat(numberFormat, locales, options) { | 67 function initializeNumberFormat(numberFormat, locales, options) { |
68 native function NativeJSCreateNumberFormat(); | |
69 | |
70 if (numberFormat.hasOwnProperty('__initializedIntlObject')) { | 68 if (numberFormat.hasOwnProperty('__initializedIntlObject')) { |
71 throw new TypeError('Trying to re-initialize NumberFormat object.'); | 69 throw new TypeError('Trying to re-initialize NumberFormat object.'); |
72 } | 70 } |
73 | 71 |
74 if (options === undefined) { | 72 if (options === undefined) { |
75 options = {}; | 73 options = {}; |
76 } | 74 } |
77 | 75 |
78 var getOption = getGetOption(options, 'numberformat'); | 76 var getOption = getGetOption(options, 'numberformat'); |
79 | 77 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 requestedLocale: {value: requestedLocale, writable: true}, | 139 requestedLocale: {value: requestedLocale, writable: true}, |
142 style: {value: internalOptions.style, writable: true}, | 140 style: {value: internalOptions.style, writable: true}, |
143 useGrouping: {writable: true} | 141 useGrouping: {writable: true} |
144 }); | 142 }); |
145 if (internalOptions.hasOwnProperty('minimumSignificantDigits')) { | 143 if (internalOptions.hasOwnProperty('minimumSignificantDigits')) { |
146 defineWEProperty(resolved, 'minimumSignificantDigits', undefined); | 144 defineWEProperty(resolved, 'minimumSignificantDigits', undefined); |
147 } | 145 } |
148 if (internalOptions.hasOwnProperty('maximumSignificantDigits')) { | 146 if (internalOptions.hasOwnProperty('maximumSignificantDigits')) { |
149 defineWEProperty(resolved, 'maximumSignificantDigits', undefined); | 147 defineWEProperty(resolved, 'maximumSignificantDigits', undefined); |
150 } | 148 } |
151 var formatter = NativeJSCreateNumberFormat(requestedLocale, | 149 var formatter = %CreateNumberFormat(requestedLocale, |
152 internalOptions, | 150 internalOptions, |
153 resolved); | 151 resolved); |
154 | 152 |
155 // We can't get information about number or currency style from ICU, so we | 153 // We can't get information about number or currency style from ICU, so we |
156 // assume user request was fulfilled. | 154 // assume user request was fulfilled. |
157 if (internalOptions.style === 'currency') { | 155 if (internalOptions.style === 'currency') { |
158 Object.defineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, | 156 Object.defineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, |
159 writable: true}); | 157 writable: true}); |
160 } | 158 } |
161 | 159 |
162 Object.defineProperty(numberFormat, 'formatter', {value: formatter}); | 160 Object.defineProperty(numberFormat, 'formatter', {value: formatter}); |
163 Object.defineProperty(numberFormat, 'resolved', {value: resolved}); | 161 Object.defineProperty(numberFormat, 'resolved', {value: resolved}); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); | 260 %FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); |
263 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); | 261 %SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); |
264 | 262 |
265 | 263 |
266 /** | 264 /** |
267 * Returns a String value representing the result of calling ToNumber(value) | 265 * Returns a String value representing the result of calling ToNumber(value) |
268 * according to the effective locale and the formatting options of this | 266 * according to the effective locale and the formatting options of this |
269 * NumberFormat. | 267 * NumberFormat. |
270 */ | 268 */ |
271 function formatNumber(formatter, value) { | 269 function formatNumber(formatter, value) { |
272 native function NativeJSInternalNumberFormat(); | |
273 | |
274 // Spec treats -0 and +0 as 0. | 270 // Spec treats -0 and +0 as 0. |
275 var number = Number(value); | 271 var number = Number(value); |
276 if (number === -0) { | 272 if (number === -0) { |
277 number = 0; | 273 number = 0; |
278 } | 274 } |
279 | 275 |
280 return NativeJSInternalNumberFormat(formatter.formatter, number); | 276 return %InternalNumberFormat(formatter.formatter, number); |
281 } | 277 } |
282 | 278 |
283 | 279 |
284 /** | 280 /** |
285 * Returns a Number that represents string value that was passed in. | 281 * Returns a Number that represents string value that was passed in. |
286 */ | 282 */ |
287 function parseNumber(formatter, value) { | 283 function parseNumber(formatter, value) { |
288 native function NativeJSInternalNumberParse(); | 284 return %InternalNumberParse(formatter.formatter, String(value)); |
289 | |
290 return NativeJSInternalNumberParse(formatter.formatter, String(value)); | |
291 } | 285 } |
292 | 286 |
293 | 287 |
294 addBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); | 288 addBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); |
295 addBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); | 289 addBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); |
OLD | NEW |