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

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

Issue 6825049: Moving JavaScript code from i18n-extension.cc into i18n.js file using (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' 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
« no previous file with comments | « src/extensions/experimental/i18n-extension.h ('k') | src/natives.h » ('j') | 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 13 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 "natives.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 // Returns a pointer to static string containing the actual
43 // TODO(cira): Remove v8 prefix from v8Locale once we have stable API. 44 // JavaScript code generated from i18n.js file.
44 const char* const I18NExtension::kSource = 45 static const char* GetScriptSource() {
45 "v8Locale = function(optLocale) {" 46 int index = NativesCollection<I18N>::GetIndex("i18n");
46 " native function NativeJSLocale();" 47 Vector<const char> script_data =
47 " var properties = NativeJSLocale(optLocale);" 48 NativesCollection<I18N>::GetScriptSource(index);
48 " this.locale = properties.locale;" 49
49 " this.language = properties.language;" 50 return script_data.start();
50 " this.script = properties.script;" 51 }
51 " this.region = properties.region;" 52
52 "};" 53 I18NExtension::I18NExtension()
53 "v8Locale.availableLocales = function() {" 54 : v8::Extension("v8/i18n", GetScriptSource()) {
54 " native function NativeJSAvailableLocales();" 55 }
55 " return NativeJSAvailableLocales();"
56 "};"
57 "v8Locale.prototype.maximizedLocale = function() {"
58 " native function NativeJSMaximizedLocale();"
59 " return new v8Locale(NativeJSMaximizedLocale(this.locale));"
60 "};"
61 "v8Locale.prototype.minimizedLocale = function() {"
62 " native function NativeJSMinimizedLocale();"
63 " return new v8Locale(NativeJSMinimizedLocale(this.locale));"
64 "};"
65 "v8Locale.prototype.displayLocale_ = function(displayLocale) {"
66 " var result = this.locale;"
67 " if (displayLocale !== undefined) {"
68 " result = displayLocale.locale;"
69 " }"
70 " return result;"
71 "};"
72 "v8Locale.prototype.displayLanguage = function(optDisplayLocale) {"
73 " var displayLocale = this.displayLocale_(optDisplayLocale);"
74 " native function NativeJSDisplayLanguage();"
75 " return NativeJSDisplayLanguage(this.locale, displayLocale);"
76 "};"
77 "v8Locale.prototype.displayScript = function(optDisplayLocale) {"
78 " var displayLocale = this.displayLocale_(optDisplayLocale);"
79 " native function NativeJSDisplayScript();"
80 " return NativeJSDisplayScript(this.locale, displayLocale);"
81 "};"
82 "v8Locale.prototype.displayRegion = function(optDisplayLocale) {"
83 " var displayLocale = this.displayLocale_(optDisplayLocale);"
84 " native function NativeJSDisplayRegion();"
85 " return NativeJSDisplayRegion(this.locale, displayLocale);"
86 "};"
87 "v8Locale.prototype.displayName = function(optDisplayLocale) {"
88 " var displayLocale = this.displayLocale_(optDisplayLocale);"
89 " native function NativeJSDisplayName();"
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);"
108 "};";
109 56
110 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction( 57 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction(
111 v8::Handle<v8::String> name) { 58 v8::Handle<v8::String> name) {
112 if (name->Equals(v8::String::New("NativeJSLocale"))) { 59 if (name->Equals(v8::String::New("NativeJSLocale"))) {
113 return v8::FunctionTemplate::New(JSLocale); 60 return v8::FunctionTemplate::New(JSLocale);
114 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) { 61 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) {
115 return v8::FunctionTemplate::New(JSAvailableLocales); 62 return v8::FunctionTemplate::New(JSAvailableLocales);
116 } else if (name->Equals(v8::String::New("NativeJSMaximizedLocale"))) { 63 } else if (name->Equals(v8::String::New("NativeJSMaximizedLocale"))) {
117 return v8::FunctionTemplate::New(JSMaximizedLocale); 64 return v8::FunctionTemplate::New(JSMaximizedLocale);
118 } else if (name->Equals(v8::String::New("NativeJSMinimizedLocale"))) { 65 } else if (name->Equals(v8::String::New("NativeJSMinimizedLocale"))) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 extension_ = new I18NExtension(); 222 extension_ = new I18NExtension();
276 } 223 }
277 return extension_; 224 return extension_;
278 } 225 }
279 226
280 void I18NExtension::Register() { 227 void I18NExtension::Register() {
281 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get()); 228 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get());
282 } 229 }
283 230
284 } } // namespace v8::internal 231 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/extensions/experimental/i18n-extension.h ('k') | src/natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698