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

Side by Side Diff: src/i18n.js

Issue 40133004: Implements ES6 String.prototype.normalize method. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « no previous file | src/runtime.h » ('j') | src/runtime.cc » ('J')
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 27 matching lines...) Expand all
38 38
39 var Intl = {}; 39 var Intl = {};
40 40
41 var undefined = global.undefined; 41 var undefined = global.undefined;
42 42
43 var AVAILABLE_SERVICES = ['collator', 43 var AVAILABLE_SERVICES = ['collator',
44 'numberformat', 44 'numberformat',
45 'dateformat', 45 'dateformat',
46 'breakiterator']; 46 'breakiterator'];
47 47
48 var NORMALIZATION_FORMS = ['NFC',
49 'NFD',
50 'NFKC',
51 'NFKD'];
52
48 /** 53 /**
49 * Caches available locales for each service. 54 * Caches available locales for each service.
50 */ 55 */
51 var AVAILABLE_LOCALES = { 56 var AVAILABLE_LOCALES = {
52 'collator': undefined, 57 'collator': undefined,
53 'numberformat': undefined, 58 'numberformat': undefined,
54 'dateformat': undefined, 59 'dateformat': undefined,
55 'breakiterator': undefined 60 'breakiterator': undefined
56 }; 61 };
57 62
(...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 return compare(collator, this, that); 1986 return compare(collator, this, that);
1982 }, 1987 },
1983 writable: true, 1988 writable: true,
1984 configurable: true, 1989 configurable: true,
1985 enumerable: false 1990 enumerable: false
1986 }); 1991 });
1987 %FunctionSetName($String.prototype.localeCompare, 'localeCompare'); 1992 %FunctionSetName($String.prototype.localeCompare, 'localeCompare');
1988 %FunctionRemovePrototype($String.prototype.localeCompare); 1993 %FunctionRemovePrototype($String.prototype.localeCompare);
1989 %SetNativeFlag($String.prototype.localeCompare); 1994 %SetNativeFlag($String.prototype.localeCompare);
1990 1995
1996 /**
1997 * Unicode normalization. This method is called with one argument that
1998 * specifies the normalization form.
1999 * If none is specified, "NFC" is assumed.
2000 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw
2001 * a RangeError Exception.
2002 * Adds a new method.
Nebojša Ćirić 2013/10/24 19:54:18 Remove * Adds a new method comment. That belongs t
mnita 2013/10/25 15:22:10 Done.
2003 */
2004 $Object.defineProperty($String.prototype, 'normalize', {
2005 value: function(that) {
2006 if (%_IsConstructCall()) {
2007 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
2008 }
2009
2010 if (IS_NULL_OR_UNDEFINED(this)) {
2011 throw new $TypeError('Method invoked on undefined or null value.');
2012 }
2013
2014 var form = $String(%_Arguments(0) || 'NFC');
2015
2016 var normForm = NORMALIZATION_FORMS.indexOf(form);
Nebojša Ćirić 2013/10/24 19:54:18 normalizationForm, don't abbreviate (except for lo
mnita 2013/10/25 15:22:10 Done.
2017 if (normForm !== -1) {
2018 return %StringNormalize(this, normForm);
2019 }
2020 throw new $RangeError('The normalization form should be one of '
2021 + NORMALIZATION_FORMS.join(', ') + '.');
2022 },
2023 writable: true,
2024 configurable: true,
2025 enumerable: false
2026 });
2027 %FunctionSetName($String.prototype.normalize, 'normalize');
2028 %FunctionRemovePrototype($String.prototype.normalize);
2029 %SetNativeFlag($String.prototype.normalize);
2030
1991 2031
1992 /** 2032 /**
1993 * Formats a Number object (this) using locale and options values. 2033 * Formats a Number object (this) using locale and options values.
1994 * If locale or options are omitted, defaults are used. 2034 * If locale or options are omitted, defaults are used.
1995 */ 2035 */
1996 $Object.defineProperty($Number.prototype, 'toLocaleString', { 2036 $Object.defineProperty($Number.prototype, 'toLocaleString', {
1997 value: function() { 2037 value: function() {
1998 if (%_IsConstructCall()) { 2038 if (%_IsConstructCall()) {
1999 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 2039 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
2000 } 2040 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 writable: true, 2147 writable: true,
2108 configurable: true, 2148 configurable: true,
2109 enumerable: false 2149 enumerable: false
2110 }); 2150 });
2111 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); 2151 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString');
2112 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); 2152 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString);
2113 %SetNativeFlag($Date.prototype.toLocaleTimeString); 2153 %SetNativeFlag($Date.prototype.toLocaleTimeString);
2114 2154
2115 return Intl; 2155 return Intl;
2116 }())}); 2156 }())});
OLDNEW
« no previous file with comments | « no previous file | src/runtime.h » ('j') | src/runtime.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698