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

Side by Side Diff: src/extensions/experimental/i18n-extension.cc

Issue 6673011: Add v8Locale.Collator (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: fix lint errors take2 Created 9 years, 8 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2011 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
11 // with the distribution. 11 // with the distribution.
(...skipping 12 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "i18n-extension.h" 28 #include "i18n-extension.h"
29 29
30 #include <algorithm> 30 #include <algorithm>
31 #include <string> 31 #include <string>
32 32
33 #include "break-iterator.h" 33 #include "break-iterator.h"
34 #include "collator.h"
34 #include "unicode/locid.h" 35 #include "unicode/locid.h"
35 #include "unicode/uloc.h" 36 #include "unicode/uloc.h"
36 37
37 namespace v8 { 38 namespace v8 {
38 namespace internal { 39 namespace internal {
39 40
40 I18NExtension* I18NExtension::extension_ = NULL; 41 I18NExtension* I18NExtension::extension_ = NULL;
41 42
42 // TODO(cira): maybe move JS code to a .js file and generata cc files from it? 43 // TODO(cira): maybe move JS code to a .js file and generata cc files from it?
43 // TODO(cira): Remove v8 prefix from v8Locale once we have stable API. 44 // TODO(cira): Remove v8 prefix from v8Locale once we have stable API.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 "v8Locale.v8BreakIterator.BreakType = {" 99 "v8Locale.v8BreakIterator.BreakType = {"
99 " 'unknown': -1," 100 " 'unknown': -1,"
100 " 'none': 0," 101 " 'none': 0,"
101 " 'number': 100," 102 " 'number': 100,"
102 " 'word': 200," 103 " 'word': 200,"
103 " 'kana': 300," 104 " 'kana': 300,"
104 " 'ideo': 400" 105 " 'ideo': 400"
105 "};" 106 "};"
106 "v8Locale.prototype.v8CreateBreakIterator = function(type) {" 107 "v8Locale.prototype.v8CreateBreakIterator = function(type) {"
107 " return new v8Locale.v8BreakIterator(this.locale, type);" 108 " return new v8Locale.v8BreakIterator(this.locale, type);"
109 "};"
110 "v8Locale.Collator = function(locale, options) {"
111 " native function NativeJSCollator();"
112 " var collator = NativeJSCollator(locale, options);"
113 " collator.options = options;"
Nebojša Ćirić 2011/04/11 23:10:33 Why are you hanging all options here? Only those w
114 " return collator;"
115 "};"
116 "v8Locale.prototype.createCollator = function(options) {"
117 " return new v8Locale.Collator(this.locale, options);"
108 "};"; 118 "};";
109 119
110 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction( 120 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction(
111 v8::Handle<v8::String> name) { 121 v8::Handle<v8::String> name) {
112 if (name->Equals(v8::String::New("NativeJSLocale"))) { 122 if (name->Equals(v8::String::New("NativeJSLocale"))) {
113 return v8::FunctionTemplate::New(JSLocale); 123 return v8::FunctionTemplate::New(JSLocale);
114 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) { 124 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) {
115 return v8::FunctionTemplate::New(JSAvailableLocales); 125 return v8::FunctionTemplate::New(JSAvailableLocales);
116 } else if (name->Equals(v8::String::New("NativeJSMaximizedLocale"))) { 126 } else if (name->Equals(v8::String::New("NativeJSMaximizedLocale"))) {
117 return v8::FunctionTemplate::New(JSMaximizedLocale); 127 return v8::FunctionTemplate::New(JSMaximizedLocale);
118 } else if (name->Equals(v8::String::New("NativeJSMinimizedLocale"))) { 128 } else if (name->Equals(v8::String::New("NativeJSMinimizedLocale"))) {
119 return v8::FunctionTemplate::New(JSMinimizedLocale); 129 return v8::FunctionTemplate::New(JSMinimizedLocale);
120 } else if (name->Equals(v8::String::New("NativeJSDisplayLanguage"))) { 130 } else if (name->Equals(v8::String::New("NativeJSDisplayLanguage"))) {
121 return v8::FunctionTemplate::New(JSDisplayLanguage); 131 return v8::FunctionTemplate::New(JSDisplayLanguage);
122 } else if (name->Equals(v8::String::New("NativeJSDisplayScript"))) { 132 } else if (name->Equals(v8::String::New("NativeJSDisplayScript"))) {
123 return v8::FunctionTemplate::New(JSDisplayScript); 133 return v8::FunctionTemplate::New(JSDisplayScript);
124 } else if (name->Equals(v8::String::New("NativeJSDisplayRegion"))) { 134 } else if (name->Equals(v8::String::New("NativeJSDisplayRegion"))) {
125 return v8::FunctionTemplate::New(JSDisplayRegion); 135 return v8::FunctionTemplate::New(JSDisplayRegion);
126 } else if (name->Equals(v8::String::New("NativeJSDisplayName"))) { 136 } else if (name->Equals(v8::String::New("NativeJSDisplayName"))) {
127 return v8::FunctionTemplate::New(JSDisplayName); 137 return v8::FunctionTemplate::New(JSDisplayName);
128 } else if (name->Equals(v8::String::New("NativeJSBreakIterator"))) { 138 } else if (name->Equals(v8::String::New("NativeJSBreakIterator"))) {
129 return v8::FunctionTemplate::New(BreakIterator::JSBreakIterator); 139 return v8::FunctionTemplate::New(BreakIterator::JSBreakIterator);
140 } else if (name->Equals(v8::String::New("NativeJSCollator"))) {
141 return v8::FunctionTemplate::New(Collator::JSCollator);
130 } 142 }
131 143
132 return v8::Handle<v8::FunctionTemplate>(); 144 return v8::Handle<v8::FunctionTemplate>();
133 } 145 }
134 146
135 v8::Handle<v8::Value> I18NExtension::JSLocale(const v8::Arguments& args) { 147 v8::Handle<v8::Value> I18NExtension::JSLocale(const v8::Arguments& args) {
136 // TODO(cira): Fetch browser locale. Accept en-US as good default for now. 148 // TODO(cira): Fetch browser locale. Accept en-US as good default for now.
137 // We could possibly pass browser locale as a parameter in the constructor. 149 // We could possibly pass browser locale as a parameter in the constructor.
138 std::string locale_name("en-US"); 150 std::string locale_name("en-US");
139 if (args.Length() == 1 && args[0]->IsString()) { 151 if (args.Length() == 1 && args[0]->IsString()) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 extension_ = new I18NExtension(); 287 extension_ = new I18NExtension();
276 } 288 }
277 return extension_; 289 return extension_;
278 } 290 }
279 291
280 void I18NExtension::Register() { 292 void I18NExtension::Register() {
281 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get()); 293 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get());
282 } 294 }
283 295
284 } } // namespace v8::internal 296 } } // namespace v8::internal
OLDNEW
« src/extensions/experimental/collator.cc ('K') | « src/extensions/experimental/i18n-extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698