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

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

Issue 6598014: Adding break iterator support to the i18n api extension.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 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
« no previous file with comments | « src/extensions/experimental/experimental.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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 "unicode/locid.h" 34 #include "unicode/locid.h"
34 #include "unicode/uloc.h" 35 #include "unicode/uloc.h"
35 36
36 namespace v8 { 37 namespace v8 {
37 namespace internal { 38 namespace internal {
38 39
39 I18NExtension* I18NExtension::extension_ = NULL; 40 I18NExtension* I18NExtension::extension_ = NULL;
40 41
41 // TODO(cira): maybe move JS code to a .js file and generata cc files from it? 42 // TODO(cira): maybe move JS code to a .js file and generata cc files from it?
42 // TODO(cira): Remove v8 prefix from v8Locale once we have stable API. 43 // TODO(cira): Remove v8 prefix from v8Locale once we have stable API.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 "};" 81 "};"
81 "v8Locale.prototype.displayRegion = function(optDisplayLocale) {" 82 "v8Locale.prototype.displayRegion = function(optDisplayLocale) {"
82 " var displayLocale = this.displayLocale_(optDisplayLocale);" 83 " var displayLocale = this.displayLocale_(optDisplayLocale);"
83 " native function NativeJSDisplayRegion();" 84 " native function NativeJSDisplayRegion();"
84 " return NativeJSDisplayRegion(this.locale, displayLocale);" 85 " return NativeJSDisplayRegion(this.locale, displayLocale);"
85 "};" 86 "};"
86 "v8Locale.prototype.displayName = function(optDisplayLocale) {" 87 "v8Locale.prototype.displayName = function(optDisplayLocale) {"
87 " var displayLocale = this.displayLocale_(optDisplayLocale);" 88 " var displayLocale = this.displayLocale_(optDisplayLocale);"
88 " native function NativeJSDisplayName();" 89 " native function NativeJSDisplayName();"
89 " return NativeJSDisplayName(this.locale, displayLocale);" 90 " return NativeJSDisplayName(this.locale, displayLocale);"
91 "};"
92 "v8Locale.v8BreakIterator = function(locale, type) {"
93 " native function NativeJSBreakIterator();"
94 " var iterator = NativeJSBreakIterator(locale, type);"
95 " iterator.type = type;"
96 " return iterator;"
97 "};"
98 "v8Locale.v8BreakIterator.BreakType = {"
99 " 'unknown': -1,"
100 " 'none': 0,"
101 " 'number': 100,"
102 " 'word': 200,"
103 " 'kana': 300,"
104 " 'ideo': 400"
105 "};"
106 "v8Locale.prototype.v8CreateBreakIterator = function(type) {"
107 " return new v8Locale.v8BreakIterator(this.locale, type);"
90 "};"; 108 "};";
91 109
92 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction( 110 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction(
93 v8::Handle<v8::String> name) { 111 v8::Handle<v8::String> name) {
94 if (name->Equals(v8::String::New("NativeJSLocale"))) { 112 if (name->Equals(v8::String::New("NativeJSLocale"))) {
95 return v8::FunctionTemplate::New(JSLocale); 113 return v8::FunctionTemplate::New(JSLocale);
96 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) { 114 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) {
97 return v8::FunctionTemplate::New(JSAvailableLocales); 115 return v8::FunctionTemplate::New(JSAvailableLocales);
98 } else if (name->Equals(v8::String::New("NativeJSMaximizedLocale"))) { 116 } else if (name->Equals(v8::String::New("NativeJSMaximizedLocale"))) {
99 return v8::FunctionTemplate::New(JSMaximizedLocale); 117 return v8::FunctionTemplate::New(JSMaximizedLocale);
100 } else if (name->Equals(v8::String::New("NativeJSMinimizedLocale"))) { 118 } else if (name->Equals(v8::String::New("NativeJSMinimizedLocale"))) {
101 return v8::FunctionTemplate::New(JSMinimizedLocale); 119 return v8::FunctionTemplate::New(JSMinimizedLocale);
102 } else if (name->Equals(v8::String::New("NativeJSDisplayLanguage"))) { 120 } else if (name->Equals(v8::String::New("NativeJSDisplayLanguage"))) {
103 return v8::FunctionTemplate::New(JSDisplayLanguage); 121 return v8::FunctionTemplate::New(JSDisplayLanguage);
104 } else if (name->Equals(v8::String::New("NativeJSDisplayScript"))) { 122 } else if (name->Equals(v8::String::New("NativeJSDisplayScript"))) {
105 return v8::FunctionTemplate::New(JSDisplayScript); 123 return v8::FunctionTemplate::New(JSDisplayScript);
106 } else if (name->Equals(v8::String::New("NativeJSDisplayRegion"))) { 124 } else if (name->Equals(v8::String::New("NativeJSDisplayRegion"))) {
107 return v8::FunctionTemplate::New(JSDisplayRegion); 125 return v8::FunctionTemplate::New(JSDisplayRegion);
108 } else if (name->Equals(v8::String::New("NativeJSDisplayName"))) { 126 } else if (name->Equals(v8::String::New("NativeJSDisplayName"))) {
109 return v8::FunctionTemplate::New(JSDisplayName); 127 return v8::FunctionTemplate::New(JSDisplayName);
128 } else if (name->Equals(v8::String::New("NativeJSBreakIterator"))) {
129 return v8::FunctionTemplate::New(BreakIterator::JSBreakIterator);
110 } 130 }
111 131
112 return v8::Handle<v8::FunctionTemplate>(); 132 return v8::Handle<v8::FunctionTemplate>();
113 } 133 }
114 134
115 v8::Handle<v8::Value> I18NExtension::JSLocale(const v8::Arguments& args) { 135 v8::Handle<v8::Value> I18NExtension::JSLocale(const v8::Arguments& args) {
116 // TODO(cira): Fetch browser locale. Accept en-US as good default for now. 136 // TODO(cira): Fetch browser locale. Accept en-US as good default for now.
117 // We could possibly pass browser locale as a parameter in the constructor. 137 // We could possibly pass browser locale as a parameter in the constructor.
118 std::string locale_name("en-US"); 138 std::string locale_name("en-US");
119 if (args.Length() == 1 && args[0]->IsString()) { 139 if (args.Length() == 1 && args[0]->IsString()) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 extension_ = new I18NExtension(); 275 extension_ = new I18NExtension();
256 } 276 }
257 return extension_; 277 return extension_;
258 } 278 }
259 279
260 void I18NExtension::Register() { 280 void I18NExtension::Register() {
261 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get()); 281 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get());
262 } 282 }
263 283
264 } } // namespace v8::internal 284 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/extensions/experimental/experimental.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698