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

Side by Side Diff: src/i18n.js

Issue 27491002: Cosmetic: Add macros for NaN, undefined and Infinity to native js code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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/debug-debugger.js ('k') | src/json.js » ('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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 configurable: true 283 configurable: true
284 }); 284 });
285 } 285 }
286 286
287 287
288 /** 288 /**
289 * Returns an intersection of locales and service supported locales. 289 * Returns an intersection of locales and service supported locales.
290 * Parameter locales is treated as a priority list. 290 * Parameter locales is treated as a priority list.
291 */ 291 */
292 function supportedLocalesOf(service, locales, options) { 292 function supportedLocalesOf(service, locales, options) {
293 if (service.match(GetServiceRE()) === null) { 293 if (IS_NULL(service.match(GetServiceRE()))) {
294 throw new $Error('Internal error, wrong service type: ' + service); 294 throw new $Error('Internal error, wrong service type: ' + service);
295 } 295 }
296 296
297 // Provide defaults if matcher was not specified. 297 // Provide defaults if matcher was not specified.
298 if (options === undefined) { 298 if (options === undefined) {
299 options = {}; 299 options = {};
300 } else { 300 } else {
301 options = toObject(options); 301 options = toObject(options);
302 } 302 }
303 303
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 440
441 return resolved; 441 return resolved;
442 } 442 }
443 443
444 444
445 /** 445 /**
446 * Returns best matched supported locale and extension info using basic 446 * Returns best matched supported locale and extension info using basic
447 * lookup algorithm. 447 * lookup algorithm.
448 */ 448 */
449 function lookupMatcher(service, requestedLocales) { 449 function lookupMatcher(service, requestedLocales) {
450 if (service.match(GetServiceRE()) === null) { 450 if (IS_NULL(service.match(GetServiceRE()))) {
451 throw new $Error('Internal error, wrong service type: ' + service); 451 throw new $Error('Internal error, wrong service type: ' + service);
452 } 452 }
453 453
454 // Cache these, they don't ever change per service. 454 // Cache these, they don't ever change per service.
455 if (AVAILABLE_LOCALES[service] === undefined) { 455 if (AVAILABLE_LOCALES[service] === undefined) {
456 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service); 456 AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service);
457 } 457 }
458 458
459 for (var i = 0; i < requestedLocales.length; ++i) { 459 for (var i = 0; i < requestedLocales.length; ++i) {
460 // Remove all extensions. 460 // Remove all extensions.
461 var locale = requestedLocales[i].replace(GetAnyExtensionRE(), ''); 461 var locale = requestedLocales[i].replace(GetAnyExtensionRE(), '');
462 do { 462 do {
463 if (AVAILABLE_LOCALES[service][locale] !== undefined) { 463 if (AVAILABLE_LOCALES[service][locale] !== undefined) {
464 // Return the resolved locale and extension. 464 // Return the resolved locale and extension.
465 var extensionMatch = requestedLocales[i].match(GetUnicodeExtensionRE()); 465 var extensionMatch = requestedLocales[i].match(GetUnicodeExtensionRE());
466 var extension = (extensionMatch === null) ? '' : extensionMatch[0]; 466 var extension = IS_NULL(extensionMatch) ? '' : extensionMatch[0];
467 return {'locale': locale, 'extension': extension, 'position': i}; 467 return {'locale': locale, 'extension': extension, 'position': i};
468 } 468 }
469 // Truncate locale if possible. 469 // Truncate locale if possible.
470 var pos = locale.lastIndexOf('-'); 470 var pos = locale.lastIndexOf('-');
471 if (pos === -1) { 471 if (pos === -1) {
472 break; 472 break;
473 } 473 }
474 locale = locale.substring(0, pos); 474 locale = locale.substring(0, pos);
475 } while (true); 475 } while (true);
476 } 476 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 } 528 }
529 529
530 return extensionMap; 530 return extensionMap;
531 } 531 }
532 532
533 533
534 /** 534 /**
535 * Converts parameter to an Object if possible. 535 * Converts parameter to an Object if possible.
536 */ 536 */
537 function toObject(value) { 537 function toObject(value) {
538 if (value === undefined || value === null) { 538 if (IS_NULL_OR_UNDEFINED(value)) {
539 throw new $TypeError('Value cannot be converted to an Object.'); 539 throw new $TypeError('Value cannot be converted to an Object.');
540 } 540 }
541 541
542 return $Object(value); 542 return $Object(value);
543 } 543 }
544 544
545 545
546 /** 546 /**
547 * Populates internalOptions object with boolean key-value pairs 547 * Populates internalOptions object with boolean key-value pairs
548 * from extensionMap and options. 548 * from extensionMap and options.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 function toTitleCaseWord(word) { 726 function toTitleCaseWord(word) {
727 return word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase(); 727 return word.substr(0, 1).toUpperCase() + word.substr(1).toLowerCase();
728 } 728 }
729 729
730 /** 730 /**
731 * Canonicalizes the language tag, or throws in case the tag is invalid. 731 * Canonicalizes the language tag, or throws in case the tag is invalid.
732 */ 732 */
733 function canonicalizeLanguageTag(localeID) { 733 function canonicalizeLanguageTag(localeID) {
734 // null is typeof 'object' so we have to do extra check. 734 // null is typeof 'object' so we have to do extra check.
735 if (typeof localeID !== 'string' && typeof localeID !== 'object' || 735 if (typeof localeID !== 'string' && typeof localeID !== 'object' ||
736 localeID === null) { 736 IS_NULL(localeID)) {
737 throw new $TypeError('Language ID should be string or object.'); 737 throw new $TypeError('Language ID should be string or object.');
738 } 738 }
739 739
740 var localeString = $String(localeID); 740 var localeString = $String(localeID);
741 741
742 if (isValidLanguageTag(localeString) === false) { 742 if (isValidLanguageTag(localeString) === false) {
743 throw new $RangeError('Invalid language tag: ' + localeString); 743 throw new $RangeError('Invalid language tag: ' + localeString);
744 } 744 }
745 745
746 // This call will strip -kn but not -kn-true extensions. 746 // This call will strip -kn but not -kn-true extensions.
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 1442
1443 match = ldmlString.match(/z|zzzz/g); 1443 match = ldmlString.match(/z|zzzz/g);
1444 options = appendToDateTimeObject( 1444 options = appendToDateTimeObject(
1445 options, 'timeZoneName', match, {z: 'short', zzzz: 'long'}); 1445 options, 'timeZoneName', match, {z: 'short', zzzz: 'long'});
1446 1446
1447 return options; 1447 return options;
1448 } 1448 }
1449 1449
1450 1450
1451 function appendToDateTimeObject(options, option, match, pairs) { 1451 function appendToDateTimeObject(options, option, match, pairs) {
1452 if (match === null) { 1452 if (IS_NULL(match)) {
1453 if (!options.hasOwnProperty(option)) { 1453 if (!options.hasOwnProperty(option)) {
1454 defineWEProperty(options, option, undefined); 1454 defineWEProperty(options, option, undefined);
1455 } 1455 }
1456 return options; 1456 return options;
1457 } 1457 }
1458 1458
1459 var property = match[0]; 1459 var property = match[0];
1460 defineWEProperty(options, option, pairs[property]); 1460 defineWEProperty(options, option, pairs[property]);
1461 1461
1462 return options; 1462 return options;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 // Special case handling (UTC, GMT). 1744 // Special case handling (UTC, GMT).
1745 var upperID = tzID.toUpperCase(); 1745 var upperID = tzID.toUpperCase();
1746 if (upperID === 'UTC' || upperID === 'GMT' || 1746 if (upperID === 'UTC' || upperID === 'GMT' ||
1747 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') { 1747 upperID === 'ETC/UTC' || upperID === 'ETC/GMT') {
1748 return 'UTC'; 1748 return 'UTC';
1749 } 1749 }
1750 1750
1751 // We expect only _ and / beside ASCII letters. 1751 // We expect only _ and / beside ASCII letters.
1752 // All inputs should conform to Area/Location from now on. 1752 // All inputs should conform to Area/Location from now on.
1753 var match = GetTimezoneNameCheckRE().exec(tzID); 1753 var match = GetTimezoneNameCheckRE().exec(tzID);
1754 if (match === null) { 1754 if (IS_NULL(match)) {
1755 throw new $RangeError('Expected Area/Location for time zone, got ' + tzID); 1755 throw new $RangeError('Expected Area/Location for time zone, got ' + tzID);
1756 } 1756 }
1757 1757
1758 var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]); 1758 var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]);
1759 var i = 3; 1759 var i = 3;
1760 while (match[i] !== undefined && i < match.length) { 1760 while (match[i] !== undefined && i < match.length) {
1761 result = result + '_' + toTitleCaseWord(match[i]); 1761 result = result + '_' + toTitleCaseWord(match[i]);
1762 i++; 1762 i++;
1763 } 1763 }
1764 1764
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 /** 1964 /**
1965 * Compares this and that, and returns less than 0, 0 or greater than 0 value. 1965 * Compares this and that, and returns less than 0, 0 or greater than 0 value.
1966 * Overrides the built-in method. 1966 * Overrides the built-in method.
1967 */ 1967 */
1968 $Object.defineProperty($String.prototype, 'localeCompare', { 1968 $Object.defineProperty($String.prototype, 'localeCompare', {
1969 value: function(that) { 1969 value: function(that) {
1970 if (%_IsConstructCall()) { 1970 if (%_IsConstructCall()) {
1971 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 1971 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
1972 } 1972 }
1973 1973
1974 if (this === undefined || this === null) { 1974 if (IS_NULL_OR_UNDEFINED(this)) {
1975 throw new $TypeError('Method invoked on undefined or null value.'); 1975 throw new $TypeError('Method invoked on undefined or null value.');
1976 } 1976 }
1977 1977
1978 var locales = %_Arguments(1); 1978 var locales = %_Arguments(1);
1979 var options = %_Arguments(2); 1979 var options = %_Arguments(2);
1980 var collator = cachedOrNewService('collator', locales, options); 1980 var collator = cachedOrNewService('collator', locales, options);
1981 return compare(collator, this, that); 1981 return compare(collator, this, that);
1982 }, 1982 },
1983 writable: true, 1983 writable: true,
1984 configurable: true, 1984 configurable: true,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 writable: true, 2107 writable: true,
2108 configurable: true, 2108 configurable: true,
2109 enumerable: false 2109 enumerable: false
2110 }); 2110 });
2111 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); 2111 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString');
2112 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); 2112 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString);
2113 %SetNativeFlag($Date.prototype.toLocaleTimeString); 2113 %SetNativeFlag($Date.prototype.toLocaleTimeString);
2114 2114
2115 return Intl; 2115 return Intl;
2116 }())}); 2116 }())});
OLDNEW
« no previous file with comments | « src/debug-debugger.js ('k') | src/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698