Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(765)

Side by Side Diff: src/extensions/i18n/date-format.js

Issue 22411003: Move i18n extension's date-format C++ code to runtime (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/extensions/i18n/date-format.cc ('k') | src/extensions/i18n/i18n-extension.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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();
239 238
240 if (dateFormat.hasOwnProperty('__initializedIntlObject')) { 239 if (dateFormat.hasOwnProperty('__initializedIntlObject')) {
241 throw new TypeError('Trying to re-initialize DateTimeFormat object.'); 240 throw new TypeError('Trying to re-initialize DateTimeFormat object.');
242 } 241 }
243 242
244 if (options === undefined) { 243 if (options === undefined) {
245 options = {}; 244 options = {};
246 } 245 }
247 246
248 var locale = resolveLocale('dateformat', locales, options); 247 var locale = resolveLocale('dateformat', locales, options);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 pattern: {writable: true}, 284 pattern: {writable: true},
286 requestedLocale: {value: requestedLocale, writable: true}, 285 requestedLocale: {value: requestedLocale, writable: true},
287 second: {writable: true}, 286 second: {writable: true},
288 timeZone: {writable: true}, 287 timeZone: {writable: true},
289 timeZoneName: {writable: true}, 288 timeZoneName: {writable: true},
290 tz: {value: tz, writable: true}, 289 tz: {value: tz, writable: true},
291 weekday: {writable: true}, 290 weekday: {writable: true},
292 year: {writable: true} 291 year: {writable: true}
293 }); 292 });
294 293
295 var formatter = NativeJSCreateDateTimeFormat( 294 var formatter = %CreateDateTimeFormat(
296 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved); 295 requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved);
297 296
298 if (tz !== undefined && tz !== resolved.timeZone) { 297 if (tz !== undefined && tz !== resolved.timeZone) {
299 throw new RangeError('Unsupported time zone specified ' + tz); 298 throw new RangeError('Unsupported time zone specified ' + tz);
300 } 299 }
301 300
302 Object.defineProperty(dateFormat, 'formatter', {value: formatter}); 301 Object.defineProperty(dateFormat, 'formatter', {value: formatter});
303 Object.defineProperty(dateFormat, 'resolved', {value: resolved}); 302 Object.defineProperty(dateFormat, 'resolved', {value: resolved});
304 Object.defineProperty(dateFormat, '__initializedIntlObject', 303 Object.defineProperty(dateFormat, '__initializedIntlObject',
305 {value: 'dateformat'}); 304 {value: 'dateformat'});
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); 401 %FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf);
403 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); 402 %SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf);
404 403
405 404
406 /** 405 /**
407 * Returns a String value representing the result of calling ToNumber(date) 406 * Returns a String value representing the result of calling ToNumber(date)
408 * according to the effective locale and the formatting options of this 407 * according to the effective locale and the formatting options of this
409 * DateTimeFormat. 408 * DateTimeFormat.
410 */ 409 */
411 function formatDate(formatter, dateValue) { 410 function formatDate(formatter, dateValue) {
412 native function NativeJSInternalDateFormat();
413
414 var dateMs; 411 var dateMs;
415 if (dateValue === undefined) { 412 if (dateValue === undefined) {
416 dateMs = Date.now(); 413 dateMs = Date.now();
417 } else { 414 } else {
418 dateMs = Number(dateValue); 415 dateMs = Number(dateValue);
419 } 416 }
420 417
421 if (!isFinite(dateMs)) { 418 if (!isFinite(dateMs)) {
422 throw new RangeError('Provided date is not in valid range.'); 419 throw new RangeError('Provided date is not in valid range.');
423 } 420 }
424 421
425 return NativeJSInternalDateFormat(formatter.formatter, new Date(dateMs)); 422 return %InternalDateFormat(formatter.formatter, new Date(dateMs));
426 } 423 }
427 424
428 425
429 /** 426 /**
430 * Returns a Date object representing the result of calling ToString(value) 427 * Returns a Date object representing the result of calling ToString(value)
431 * according to the effective locale and the formatting options of this 428 * according to the effective locale and the formatting options of this
432 * DateTimeFormat. 429 * DateTimeFormat.
433 * Returns undefined if date string cannot be parsed. 430 * Returns undefined if date string cannot be parsed.
434 */ 431 */
435 function parseDate(formatter, value) { 432 function parseDate(formatter, value) {
436 native function NativeJSInternalDateParse(); 433 return %InternalDateParse(formatter.formatter, String(value));
437 return NativeJSInternalDateParse(formatter.formatter, String(value));
438 } 434 }
439 435
440 436
441 // 0 because date is optional argument. 437 // 0 because date is optional argument.
442 addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); 438 addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0);
443 addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); 439 addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1);
444 440
445 441
446 /** 442 /**
447 * Returns canonical Area/Location name, or throws an exception if the zone 443 * Returns canonical Area/Location name, or throws an exception if the zone
(...skipping 21 matching lines...) Expand all
469 465
470 var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]); 466 var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]);
471 var i = 3; 467 var i = 3;
472 while (match[i] !== undefined && i < match.length) { 468 while (match[i] !== undefined && i < match.length) {
473 result = result + '_' + toTitleCaseWord(match[i]); 469 result = result + '_' + toTitleCaseWord(match[i]);
474 i++; 470 i++;
475 } 471 }
476 472
477 return result; 473 return result;
478 } 474 }
OLDNEW
« no previous file with comments | « src/extensions/i18n/date-format.cc ('k') | src/extensions/i18n/i18n-extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698