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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 // ECMAScript 402 API implementation is broken into separate files for | 29 // ECMAScript 402 API implementation is broken into separate files for |
30 // each service. The build system combines them together into one | 30 // each service. The build system combines them together into one |
31 // Intl namespace. | 31 // Intl namespace. |
32 | 32 |
33 /** | 33 /** |
34 * Initializes the given object so it's a valid Collator instance. | 34 * Initializes the given object so it's a valid Collator instance. |
35 * Useful for subclassing. | 35 * Useful for subclassing. |
36 */ | 36 */ |
37 function initializeCollator(collator, locales, options) { | 37 function initializeCollator(collator, locales, options) { |
38 native function NativeJSCreateCollator(); | |
39 | |
40 if (collator.hasOwnProperty('__initializedIntlObject')) { | 38 if (collator.hasOwnProperty('__initializedIntlObject')) { |
41 throw new TypeError('Trying to re-initialize Collator object.'); | 39 throw new TypeError('Trying to re-initialize Collator object.'); |
42 } | 40 } |
43 | 41 |
44 if (options === undefined) { | 42 if (options === undefined) { |
45 options = {}; | 43 options = {}; |
46 } | 44 } |
47 | 45 |
48 var getOption = getGetOption(options, 'collator'); | 46 var getOption = getGetOption(options, 'collator'); |
49 | 47 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 collation: {value: internalOptions.collation, writable: true}, | 94 collation: {value: internalOptions.collation, writable: true}, |
97 ignorePunctuation: {writable: true}, | 95 ignorePunctuation: {writable: true}, |
98 locale: {writable: true}, | 96 locale: {writable: true}, |
99 numeric: {writable: true}, | 97 numeric: {writable: true}, |
100 requestedLocale: {value: requestedLocale, writable: true}, | 98 requestedLocale: {value: requestedLocale, writable: true}, |
101 sensitivity: {writable: true}, | 99 sensitivity: {writable: true}, |
102 strength: {writable: true}, | 100 strength: {writable: true}, |
103 usage: {value: internalOptions.usage, writable: true} | 101 usage: {value: internalOptions.usage, writable: true} |
104 }); | 102 }); |
105 | 103 |
106 var internalCollator = NativeJSCreateCollator(requestedLocale, | 104 var internalCollator = %CreateCollator(requestedLocale, |
107 internalOptions, | 105 internalOptions, |
108 resolved); | 106 resolved); |
109 | 107 |
110 // Writable, configurable and enumerable are set to false by default. | 108 // Writable, configurable and enumerable are set to false by default. |
111 Object.defineProperty(collator, 'collator', {value: internalCollator}); | 109 Object.defineProperty(collator, 'collator', {value: internalCollator}); |
112 Object.defineProperty(collator, '__initializedIntlObject', | 110 Object.defineProperty(collator, '__initializedIntlObject', |
113 {value: 'collator'}); | 111 {value: 'collator'}); |
114 Object.defineProperty(collator, 'resolved', {value: resolved}); | 112 Object.defineProperty(collator, 'resolved', {value: resolved}); |
115 | 113 |
116 return collator; | 114 return collator; |
117 } | 115 } |
118 | 116 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 * When the compare method is called with two arguments x and y, it returns a | 195 * When the compare method is called with two arguments x and y, it returns a |
198 * Number other than NaN that represents the result of a locale-sensitive | 196 * Number other than NaN that represents the result of a locale-sensitive |
199 * String comparison of x with y. | 197 * String comparison of x with y. |
200 * The result is intended to order String values in the sort order specified | 198 * The result is intended to order String values in the sort order specified |
201 * by the effective locale and collation options computed during construction | 199 * by the effective locale and collation options computed during construction |
202 * of this Collator object, and will be negative, zero, or positive, depending | 200 * of this Collator object, and will be negative, zero, or positive, depending |
203 * on whether x comes before y in the sort order, the Strings are equal under | 201 * on whether x comes before y in the sort order, the Strings are equal under |
204 * the sort order, or x comes after y in the sort order, respectively. | 202 * the sort order, or x comes after y in the sort order, respectively. |
205 */ | 203 */ |
206 function compare(collator, x, y) { | 204 function compare(collator, x, y) { |
207 native function NativeJSInternalCompare(); | 205 return %InternalCompare(collator.collator, String(x), String(y)); |
208 return NativeJSInternalCompare(collator.collator, String(x), String(y)); | |
209 }; | 206 }; |
210 | 207 |
211 | 208 |
212 addBoundMethod(Intl.Collator, 'compare', compare, 2); | 209 addBoundMethod(Intl.Collator, 'compare', compare, 2); |
OLD | NEW |