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

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: exception check wip 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.
45 // TODO(jungshik): Set |collator.options| to actually recognized / resolved
46 // options once |kSource| is build-time generated from an external file.
44 const char* const I18NExtension::kSource = 47 const char* const I18NExtension::kSource =
45 "v8Locale = function(optLocale) {" 48 "v8Locale = function(optLocale) {"
46 " native function NativeJSLocale();" 49 " native function NativeJSLocale();"
47 " var properties = NativeJSLocale(optLocale);" 50 " var properties = NativeJSLocale(optLocale);"
48 " this.locale = properties.locale;" 51 " this.locale = properties.locale;"
49 " this.language = properties.language;" 52 " this.language = properties.language;"
50 " this.script = properties.script;" 53 " this.script = properties.script;"
51 " this.region = properties.region;" 54 " this.region = properties.region;"
52 "};" 55 "};"
53 "v8Locale.availableLocales = function() {" 56 "v8Locale.availableLocales = function() {"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 "v8Locale.v8BreakIterator.BreakType = {" 101 "v8Locale.v8BreakIterator.BreakType = {"
99 " 'unknown': -1," 102 " 'unknown': -1,"
100 " 'none': 0," 103 " 'none': 0,"
101 " 'number': 100," 104 " 'number': 100,"
102 " 'word': 200," 105 " 'word': 200,"
103 " 'kana': 300," 106 " 'kana': 300,"
104 " 'ideo': 400" 107 " 'ideo': 400"
105 "};" 108 "};"
106 "v8Locale.prototype.v8CreateBreakIterator = function(type) {" 109 "v8Locale.prototype.v8CreateBreakIterator = function(type) {"
107 " return new v8Locale.v8BreakIterator(this.locale, type);" 110 " return new v8Locale.v8BreakIterator(this.locale, type);"
111 "};"
112 "v8Locale.Collator = function(locale, options) {"
113 " native function NativeJSCollator();"
114 " var collator = NativeJSCollator(locale,"
115 " options === undefined ? {} : options);"
116 " return collator;"
117 "};"
118 "v8Locale.prototype.createCollator = function(options) {"
119 " return new v8Locale.Collator(this.locale, options);"
108 "};"; 120 "};";
109 121
110 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction( 122 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction(
111 v8::Handle<v8::String> name) { 123 v8::Handle<v8::String> name) {
112 if (name->Equals(v8::String::New("NativeJSLocale"))) { 124 if (name->Equals(v8::String::New("NativeJSLocale"))) {
113 return v8::FunctionTemplate::New(JSLocale); 125 return v8::FunctionTemplate::New(JSLocale);
114 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) { 126 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) {
115 return v8::FunctionTemplate::New(JSAvailableLocales); 127 return v8::FunctionTemplate::New(JSAvailableLocales);
116 } else if (name->Equals(v8::String::New("NativeJSMaximizedLocale"))) { 128 } else if (name->Equals(v8::String::New("NativeJSMaximizedLocale"))) {
117 return v8::FunctionTemplate::New(JSMaximizedLocale); 129 return v8::FunctionTemplate::New(JSMaximizedLocale);
118 } else if (name->Equals(v8::String::New("NativeJSMinimizedLocale"))) { 130 } else if (name->Equals(v8::String::New("NativeJSMinimizedLocale"))) {
119 return v8::FunctionTemplate::New(JSMinimizedLocale); 131 return v8::FunctionTemplate::New(JSMinimizedLocale);
120 } else if (name->Equals(v8::String::New("NativeJSDisplayLanguage"))) { 132 } else if (name->Equals(v8::String::New("NativeJSDisplayLanguage"))) {
121 return v8::FunctionTemplate::New(JSDisplayLanguage); 133 return v8::FunctionTemplate::New(JSDisplayLanguage);
122 } else if (name->Equals(v8::String::New("NativeJSDisplayScript"))) { 134 } else if (name->Equals(v8::String::New("NativeJSDisplayScript"))) {
123 return v8::FunctionTemplate::New(JSDisplayScript); 135 return v8::FunctionTemplate::New(JSDisplayScript);
124 } else if (name->Equals(v8::String::New("NativeJSDisplayRegion"))) { 136 } else if (name->Equals(v8::String::New("NativeJSDisplayRegion"))) {
125 return v8::FunctionTemplate::New(JSDisplayRegion); 137 return v8::FunctionTemplate::New(JSDisplayRegion);
126 } else if (name->Equals(v8::String::New("NativeJSDisplayName"))) { 138 } else if (name->Equals(v8::String::New("NativeJSDisplayName"))) {
127 return v8::FunctionTemplate::New(JSDisplayName); 139 return v8::FunctionTemplate::New(JSDisplayName);
128 } else if (name->Equals(v8::String::New("NativeJSBreakIterator"))) { 140 } else if (name->Equals(v8::String::New("NativeJSBreakIterator"))) {
129 return v8::FunctionTemplate::New(BreakIterator::JSBreakIterator); 141 return v8::FunctionTemplate::New(BreakIterator::JSBreakIterator);
142 } else if (name->Equals(v8::String::New("NativeJSCollator"))) {
143 return v8::FunctionTemplate::New(Collator::JSCollator);
130 } 144 }
131 145
132 return v8::Handle<v8::FunctionTemplate>(); 146 return v8::Handle<v8::FunctionTemplate>();
133 } 147 }
134 148
135 v8::Handle<v8::Value> I18NExtension::JSLocale(const v8::Arguments& args) { 149 v8::Handle<v8::Value> I18NExtension::JSLocale(const v8::Arguments& args) {
136 // TODO(cira): Fetch browser locale. Accept en-US as good default for now. 150 // 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. 151 // We could possibly pass browser locale as a parameter in the constructor.
138 std::string locale_name("en-US"); 152 std::string locale_name("en-US");
139 if (args.Length() == 1 && args[0]->IsString()) { 153 if (args.Length() == 1 && args[0]->IsString()) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 extension_ = new I18NExtension(); 289 extension_ = new I18NExtension();
276 } 290 }
277 return extension_; 291 return extension_;
278 } 292 }
279 293
280 void I18NExtension::Register() { 294 void I18NExtension::Register() {
281 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get()); 295 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get());
282 } 296 }
283 297
284 } } // namespace v8::internal 298 } } // 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