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

Side by Side Diff: src/i18n.js

Issue 68133016: Implements ES6 String.prototype.normalize method. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Implemented review feedback: CHECK_OBJECT_COERCIBLE macro to check for null/undefined. Created 6 years, 10 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
« no previous file with comments | « no previous file | src/runtime.h » ('j') | src/string.js » ('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 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 writable: true, 1985 writable: true,
1981 configurable: true, 1986 configurable: true,
1982 enumerable: false 1987 enumerable: false
1983 }); 1988 });
1984 %FunctionSetName($String.prototype.localeCompare, 'localeCompare'); 1989 %FunctionSetName($String.prototype.localeCompare, 'localeCompare');
1985 %FunctionRemovePrototype($String.prototype.localeCompare); 1990 %FunctionRemovePrototype($String.prototype.localeCompare);
1986 %SetNativeFlag($String.prototype.localeCompare); 1991 %SetNativeFlag($String.prototype.localeCompare);
1987 1992
1988 1993
1989 /** 1994 /**
1995 * Unicode normalization. This method is called with one argument that
1996 * specifies the normalization form.
1997 * If none is specified, "NFC" is assumed.
1998 * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw
1999 * a RangeError Exception.
2000 */
2001 $Object.defineProperty($String.prototype, 'normalize', {
2002 value: function(that) {
2003 if (%_IsConstructCall()) {
2004 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
arv (Not doing code reviews) 2014/04/10 18:20:10 Does the spec really mandate this?
mnita 2014/04/10 21:20:30 Hmmmm... Not in spec, sorry. I will remove this wh
2005 }
2006
2007 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
2008
2009 var form = $String(%_Arguments(0) || 'NFC');
2010
2011 var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
arv (Not doing code reviews) 2014/04/10 18:20:10 Does this need to ensure we are calling the origin
mnita 2014/04/10 21:20:30 Done.
2012 if (normalizationForm === -1) {
2013 throw new $RangeError('The normalization form should be one of '
2014 + NORMALIZATION_FORMS.join(', ') + '.');
2015 }
2016
2017 return %StringNormalize(this, normalizationForm);
2018 },
2019 writable: true,
2020 configurable: true,
2021 enumerable: false
2022 });
2023 %FunctionSetName($String.prototype.normalize, 'normalize');
2024 %FunctionRemovePrototype($String.prototype.normalize);
2025 %SetNativeFlag($String.prototype.normalize);
2026
2027
2028 /**
1990 * Formats a Number object (this) using locale and options values. 2029 * Formats a Number object (this) using locale and options values.
1991 * If locale or options are omitted, defaults are used. 2030 * If locale or options are omitted, defaults are used.
1992 */ 2031 */
1993 $Object.defineProperty($Number.prototype, 'toLocaleString', { 2032 $Object.defineProperty($Number.prototype, 'toLocaleString', {
1994 value: function() { 2033 value: function() {
1995 if (%_IsConstructCall()) { 2034 if (%_IsConstructCall()) {
1996 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); 2035 throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
1997 } 2036 }
1998 2037
1999 if (!(this instanceof $Number) && typeof(this) !== 'number') { 2038 if (!(this instanceof $Number) && typeof(this) !== 'number') {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 writable: true, 2143 writable: true,
2105 configurable: true, 2144 configurable: true,
2106 enumerable: false 2145 enumerable: false
2107 }); 2146 });
2108 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString'); 2147 %FunctionSetName($Date.prototype.toLocaleTimeString, 'toLocaleTimeString');
2109 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString); 2148 %FunctionRemovePrototype($Date.prototype.toLocaleTimeString);
2110 %SetNativeFlag($Date.prototype.toLocaleTimeString); 2149 %SetNativeFlag($Date.prototype.toLocaleTimeString);
2111 2150
2112 return Intl; 2151 return Intl;
2113 }())}); 2152 }())});
OLDNEW
« no previous file with comments | « no previous file | src/runtime.h » ('j') | src/string.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698