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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 228 |
229 return options; | 229 return options; |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 /** | 233 /** |
234 * Initializes the given object so it's a valid DateTimeFormat instance. | 234 * Initializes the given object so it's a valid DateTimeFormat instance. |
235 * Useful for subclassing. | 235 * Useful for subclassing. |
236 */ | 236 */ |
237 function initializeDateTimeFormat(dateFormat, locales, options) { | 237 function initializeDateTimeFormat(dateFormat, locales, options) { |
| 238 native function NativeJSCreateDateTimeFormat(); |
238 | 239 |
239 if (dateFormat.hasOwnProperty('__initializedIntlObject')) { | 240 if (dateFormat.hasOwnProperty('__initializedIntlObject')) { |
240 throw new TypeError('Trying to re-initialize DateTimeFormat object.'); | 241 throw new TypeError('Trying to re-initialize DateTimeFormat object.'); |
241 } | 242 } |
242 | 243 |
243 if (options === undefined) { | 244 if (options === undefined) { |
244 options = {}; | 245 options = {}; |
245 } | 246 } |
246 | 247 |
247 var locale = resolveLocale('dateformat', locales, options); | 248 var locale = resolveLocale('dateformat', locales, options); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 pattern: {writable: true}, | 285 pattern: {writable: true}, |
285 requestedLocale: {value: requestedLocale, writable: true}, | 286 requestedLocale: {value: requestedLocale, writable: true}, |
286 second: {writable: true}, | 287 second: {writable: true}, |
287 timeZone: {writable: true}, | 288 timeZone: {writable: true}, |
288 timeZoneName: {writable: true}, | 289 timeZoneName: {writable: true}, |
289 tz: {value: tz, writable: true}, | 290 tz: {value: tz, writable: true}, |
290 weekday: {writable: true}, | 291 weekday: {writable: true}, |
291 year: {writable: true} | 292 year: {writable: true} |
292 }); | 293 }); |
293 | 294 |
294 var formatter = %CreateDateTimeFormat( | 295 var formatter = NativeJSCreateDateTimeFormat( |
295 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); | 296 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); |
296 | 297 |
297 if (tz !== undefined && tz !== resolved.timeZone) { | 298 if (tz !== undefined && tz !== resolved.timeZone) { |
298 throw new RangeError('Unsupported time zone specified ' + tz); | 299 throw new RangeError('Unsupported time zone specified ' + tz); |
299 } | 300 } |
300 | 301 |
301 Object.defineProperty(dateFormat, 'formatter', {value: formatter}); | 302 Object.defineProperty(dateFormat, 'formatter', {value: formatter}); |
302 Object.defineProperty(dateFormat, 'resolved', {value: resolved}); | 303 Object.defineProperty(dateFormat, 'resolved', {value: resolved}); |
303 Object.defineProperty(dateFormat, '__initializedIntlObject', | 304 Object.defineProperty(dateFormat, '__initializedIntlObject', |
304 {value: 'dateformat'}); | 305 {value: 'dateformat'}); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); | 402 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); |
402 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); | 403 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); |
403 | 404 |
404 | 405 |
405 /** | 406 /** |
406 * Returns a String value representing the result of calling ToNumber(date) | 407 * Returns a String value representing the result of calling ToNumber(date) |
407 * according to the effective locale and the formatting options of this | 408 * according to the effective locale and the formatting options of this |
408 * DateTimeFormat. | 409 * DateTimeFormat. |
409 */ | 410 */ |
410 function formatDate(formatter, dateValue) { | 411 function formatDate(formatter, dateValue) { |
| 412 native function NativeJSInternalDateFormat(); |
| 413 |
411 var dateMs; | 414 var dateMs; |
412 if (dateValue === undefined) { | 415 if (dateValue === undefined) { |
413 dateMs = Date.now(); | 416 dateMs = Date.now(); |
414 } else { | 417 } else { |
415 dateMs = Number(dateValue); | 418 dateMs = Number(dateValue); |
416 } | 419 } |
417 | 420 |
418 if (!isFinite(dateMs)) { | 421 if (!isFinite(dateMs)) { |
419 throw new RangeError('Provided date is not in valid range.'); | 422 throw new RangeError('Provided date is not in valid range.'); |
420 } | 423 } |
421 | 424 |
422 return %InternalDateFormat(formatter.formatter, new Date(dateMs)); | 425 return NativeJSInternalDateFormat(formatter.formatter, new Date(dateMs)); |
423 } | 426 } |
424 | 427 |
425 | 428 |
426 /** | 429 /** |
427 * Returns a Date object representing the result of calling ToString(value) | 430 * Returns a Date object representing the result of calling ToString(value) |
428 * according to the effective locale and the formatting options of this | 431 * according to the effective locale and the formatting options of this |
429 * DateTimeFormat. | 432 * DateTimeFormat. |
430 * Returns undefined if date string cannot be parsed. | 433 * Returns undefined if date string cannot be parsed. |
431 */ | 434 */ |
432 function parseDate(formatter, value) { | 435 function parseDate(formatter, value) { |
433 return %InternalDateParse(formatter.formatter, String(value)); | 436 native function NativeJSInternalDateParse(); |
| 437 return NativeJSInternalDateParse(formatter.formatter, String(value)); |
434 } | 438 } |
435 | 439 |
436 | 440 |
437 // 0 because date is optional argument. | 441 // 0 because date is optional argument. |
438 addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); | 442 addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); |
439 addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); | 443 addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); |
440 | 444 |
441 | 445 |
442 /** | 446 /** |
443 * Returns canonical Area/Location name, or throws an exception if the zone | 447 * Returns canonical Area/Location name, or throws an exception if the zone |
(...skipping 21 matching lines...) Expand all Loading... |
465 | 469 |
466 var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]); | 470 var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]); |
467 var i = 3; | 471 var i = 3; |
468 while (match[i] !== undefined && i < match.length) { | 472 while (match[i] !== undefined && i < match.length) { |
469 result = result + '_' + toTitleCaseWord(match[i]); | 473 result = result + '_' + toTitleCaseWord(match[i]); |
470 i++; | 474 i++; |
471 } | 475 } |
472 | 476 |
473 return result; | 477 return result; |
474 } | 478 } |
OLD | NEW |