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 BreakIterator instance. | 34 * Initializes the given object so it's a valid BreakIterator instance. |
35 * Useful for subclassing. | 35 * Useful for subclassing. |
36 */ | 36 */ |
37 function initializeBreakIterator(iterator, locales, options) { | 37 function initializeBreakIterator(iterator, locales, options) { |
38 native function NativeJSCreateBreakIterator(); | |
39 | |
40 if (iterator.hasOwnProperty('__initializedIntlObject')) { | 38 if (iterator.hasOwnProperty('__initializedIntlObject')) { |
41 throw new TypeError('Trying to re-initialize v8BreakIterator object.'); | 39 throw new TypeError('Trying to re-initialize v8BreakIterator 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, 'breakiterator'); | 46 var getOption = getGetOption(options, 'breakiterator'); |
49 | 47 |
50 var internalOptions = {}; | 48 var internalOptions = {}; |
51 | 49 |
52 defineWEProperty(internalOptions, 'type', getOption( | 50 defineWEProperty(internalOptions, 'type', getOption( |
53 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); | 51 'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); |
54 | 52 |
55 var locale = resolveLocale('breakiterator', locales, options); | 53 var locale = resolveLocale('breakiterator', locales, options); |
56 var resolved = Object.defineProperties({}, { | 54 var resolved = Object.defineProperties({}, { |
57 requestedLocale: {value: locale.locale, writable: true}, | 55 requestedLocale: {value: locale.locale, writable: true}, |
58 type: {value: internalOptions.type, writable: true}, | 56 type: {value: internalOptions.type, writable: true}, |
59 locale: {writable: true} | 57 locale: {writable: true} |
60 }); | 58 }); |
61 | 59 |
62 var internalIterator = NativeJSCreateBreakIterator(locale.locale, | 60 var internalIterator = %CreateBreakIterator(locale.locale, |
63 internalOptions, | 61 internalOptions, |
64 resolved); | 62 resolved); |
65 | 63 |
66 Object.defineProperty(iterator, 'iterator', {value: internalIterator}); | 64 Object.defineProperty(iterator, 'iterator', {value: internalIterator}); |
67 Object.defineProperty(iterator, 'resolved', {value: resolved}); | 65 Object.defineProperty(iterator, 'resolved', {value: resolved}); |
68 Object.defineProperty(iterator, '__initializedIntlObject', | 66 Object.defineProperty(iterator, '__initializedIntlObject', |
69 {value: 'breakiterator'}); | 67 {value: 'breakiterator'}); |
70 | 68 |
71 return iterator; | 69 return iterator; |
72 } | 70 } |
73 | 71 |
74 | 72 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 %FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); | 140 %FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); |
143 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); | 141 %FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); |
144 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); | 142 %SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); |
145 | 143 |
146 | 144 |
147 /** | 145 /** |
148 * Adopts text to segment using the iterator. Old text, if present, | 146 * Adopts text to segment using the iterator. Old text, if present, |
149 * gets discarded. | 147 * gets discarded. |
150 */ | 148 */ |
151 function adoptText(iterator, text) { | 149 function adoptText(iterator, text) { |
152 native function NativeJSBreakIteratorAdoptText(); | 150 %BreakIteratorAdoptText(iterator.iterator, String(text)); |
153 NativeJSBreakIteratorAdoptText(iterator.iterator, String(text)); | |
154 } | 151 } |
155 | 152 |
156 | 153 |
157 /** | 154 /** |
158 * Returns index of the first break in the string and moves current pointer. | 155 * Returns index of the first break in the string and moves current pointer. |
159 */ | 156 */ |
160 function first(iterator) { | 157 function first(iterator) { |
161 native function NativeJSBreakIteratorFirst(); | 158 return %BreakIteratorFirst(iterator.iterator); |
162 return NativeJSBreakIteratorFirst(iterator.iterator); | |
163 } | 159 } |
164 | 160 |
165 | 161 |
166 /** | 162 /** |
167 * Returns the index of the next break and moves the pointer. | 163 * Returns the index of the next break and moves the pointer. |
168 */ | 164 */ |
169 function next(iterator) { | 165 function next(iterator) { |
170 native function NativeJSBreakIteratorNext(); | 166 return %BreakIteratorNext(iterator.iterator); |
171 return NativeJSBreakIteratorNext(iterator.iterator); | |
172 } | 167 } |
173 | 168 |
174 | 169 |
175 /** | 170 /** |
176 * Returns index of the current break. | 171 * Returns index of the current break. |
177 */ | 172 */ |
178 function current(iterator) { | 173 function current(iterator) { |
179 native function NativeJSBreakIteratorCurrent(); | 174 return %BreakIteratorCurrent(iterator.iterator); |
180 return NativeJSBreakIteratorCurrent(iterator.iterator); | |
181 } | 175 } |
182 | 176 |
183 | 177 |
184 /** | 178 /** |
185 * Returns type of the current break. | 179 * Returns type of the current break. |
186 */ | 180 */ |
187 function breakType(iterator) { | 181 function breakType(iterator) { |
188 native function NativeJSBreakIteratorBreakType(); | 182 return %BreakIteratorBreakType(iterator.iterator); |
189 return NativeJSBreakIteratorBreakType(iterator.iterator); | |
190 } | 183 } |
191 | 184 |
192 | 185 |
193 addBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1); | 186 addBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1); |
194 addBoundMethod(Intl.v8BreakIterator, 'first', first, 0); | 187 addBoundMethod(Intl.v8BreakIterator, 'first', first, 0); |
195 addBoundMethod(Intl.v8BreakIterator, 'next', next, 0); | 188 addBoundMethod(Intl.v8BreakIterator, 'next', next, 0); |
196 addBoundMethod(Intl.v8BreakIterator, 'current', current, 0); | 189 addBoundMethod(Intl.v8BreakIterator, 'current', current, 0); |
197 addBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0); | 190 addBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0); |
OLD | NEW |