OLD | NEW |
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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #include "unicode/locid.h" | 33 #include "unicode/locid.h" |
34 #include "unicode/uloc.h" | 34 #include "unicode/uloc.h" |
35 | 35 |
36 namespace v8 { | 36 namespace v8 { |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 I18NExtension* I18NExtension::extension_ = NULL; | 39 I18NExtension* I18NExtension::extension_ = NULL; |
40 | 40 |
41 // TODO(cira): maybe move JS code to a .js file and generata cc files from it? | 41 // 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. |
42 const char* const I18NExtension::kSource = | 43 const char* const I18NExtension::kSource = |
43 "Locale = function(optLocale) {" | 44 "v8Locale = function(optLocale) {" |
44 " native function NativeJSLocale();" | 45 " native function NativeJSLocale();" |
45 " var properties = NativeJSLocale(optLocale);" | 46 " var properties = NativeJSLocale(optLocale);" |
46 " this.locale = properties.locale;" | 47 " this.locale = properties.locale;" |
47 " this.language = properties.language;" | 48 " this.language = properties.language;" |
48 " this.script = properties.script;" | 49 " this.script = properties.script;" |
49 " this.region = properties.region;" | 50 " this.region = properties.region;" |
50 "};" | 51 "};" |
51 "Locale.availableLocales = function() {" | 52 "v8Locale.availableLocales = function() {" |
52 " native function NativeJSAvailableLocales();" | 53 " native function NativeJSAvailableLocales();" |
53 " return NativeJSAvailableLocales();" | 54 " return NativeJSAvailableLocales();" |
54 "};" | 55 "};" |
55 "Locale.prototype.maximizedLocale = function() {" | 56 "v8Locale.prototype.maximizedLocale = function() {" |
56 " native function NativeJSMaximizedLocale();" | 57 " native function NativeJSMaximizedLocale();" |
57 " return new Locale(NativeJSMaximizedLocale(this.locale));" | 58 " return new v8Locale(NativeJSMaximizedLocale(this.locale));" |
58 "};" | 59 "};" |
59 "Locale.prototype.minimizedLocale = function() {" | 60 "v8Locale.prototype.minimizedLocale = function() {" |
60 " native function NativeJSMinimizedLocale();" | 61 " native function NativeJSMinimizedLocale();" |
61 " return new Locale(NativeJSMinimizedLocale(this.locale));" | 62 " return new v8Locale(NativeJSMinimizedLocale(this.locale));" |
62 "};" | 63 "};" |
63 "Locale.prototype.displayLocale_ = function(displayLocale) {" | 64 "v8Locale.prototype.displayLocale_ = function(displayLocale) {" |
64 " var result = this.locale;" | 65 " var result = this.locale;" |
65 " if (displayLocale !== undefined) {" | 66 " if (displayLocale !== undefined) {" |
66 " result = displayLocale.locale;" | 67 " result = displayLocale.locale;" |
67 " }" | 68 " }" |
68 " return result;" | 69 " return result;" |
69 "};" | 70 "};" |
70 "Locale.prototype.displayLanguage = function(optDisplayLocale) {" | 71 "v8Locale.prototype.displayLanguage = function(optDisplayLocale) {" |
71 " var displayLocale = this.displayLocale_(optDisplayLocale);" | 72 " var displayLocale = this.displayLocale_(optDisplayLocale);" |
72 " native function NativeJSDisplayLanguage();" | 73 " native function NativeJSDisplayLanguage();" |
73 " return NativeJSDisplayLanguage(this.locale, displayLocale);" | 74 " return NativeJSDisplayLanguage(this.locale, displayLocale);" |
74 "};" | 75 "};" |
75 "Locale.prototype.displayScript = function(optDisplayLocale) {" | 76 "v8Locale.prototype.displayScript = function(optDisplayLocale) {" |
76 " var displayLocale = this.displayLocale_(optDisplayLocale);" | 77 " var displayLocale = this.displayLocale_(optDisplayLocale);" |
77 " native function NativeJSDisplayScript();" | 78 " native function NativeJSDisplayScript();" |
78 " return NativeJSDisplayScript(this.locale, displayLocale);" | 79 " return NativeJSDisplayScript(this.locale, displayLocale);" |
79 "};" | 80 "};" |
80 "Locale.prototype.displayRegion = function(optDisplayLocale) {" | 81 "v8Locale.prototype.displayRegion = function(optDisplayLocale) {" |
81 " var displayLocale = this.displayLocale_(optDisplayLocale);" | 82 " var displayLocale = this.displayLocale_(optDisplayLocale);" |
82 " native function NativeJSDisplayRegion();" | 83 " native function NativeJSDisplayRegion();" |
83 " return NativeJSDisplayRegion(this.locale, displayLocale);" | 84 " return NativeJSDisplayRegion(this.locale, displayLocale);" |
84 "};" | 85 "};" |
85 "Locale.prototype.displayName = function(optDisplayLocale) {" | 86 "v8Locale.prototype.displayName = function(optDisplayLocale) {" |
86 " var displayLocale = this.displayLocale_(optDisplayLocale);" | 87 " var displayLocale = this.displayLocale_(optDisplayLocale);" |
87 " native function NativeJSDisplayName();" | 88 " native function NativeJSDisplayName();" |
88 " return NativeJSDisplayName(this.locale, displayLocale);" | 89 " return NativeJSDisplayName(this.locale, displayLocale);" |
89 "};"; | 90 "};"; |
90 | 91 |
91 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction( | 92 v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction( |
92 v8::Handle<v8::String> name) { | 93 v8::Handle<v8::String> name) { |
93 if (name->Equals(v8::String::New("NativeJSLocale"))) { | 94 if (name->Equals(v8::String::New("NativeJSLocale"))) { |
94 return v8::FunctionTemplate::New(JSLocale); | 95 return v8::FunctionTemplate::New(JSLocale); |
95 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) { | 96 } else if (name->Equals(v8::String::New("NativeJSAvailableLocales"))) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 extension_ = new I18NExtension(); | 255 extension_ = new I18NExtension(); |
255 } | 256 } |
256 return extension_; | 257 return extension_; |
257 } | 258 } |
258 | 259 |
259 void I18NExtension::Register() { | 260 void I18NExtension::Register() { |
260 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get()); | 261 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get()); |
261 } | 262 } |
262 | 263 |
263 } } // namespace v8::internal | 264 } } // namespace v8::internal |
OLD | NEW |