Moving JavaScript code from i18n-extension.cc into i18n.js file using
tools/js2c.py script. Added new type I18N to natives.h enum. Review URL: http://codereview.chromium.org/6825049 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7591 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
1d774ac5ca
commit
df453b1203
@ -41,6 +41,7 @@
|
||||
'break-iterator.h',
|
||||
'i18n-extension.cc',
|
||||
'i18n-extension.h',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/i18n-js.cc',
|
||||
],
|
||||
'include_dirs': [
|
||||
'<(icu_src_dir)/public/common',
|
||||
@ -48,8 +49,39 @@
|
||||
],
|
||||
'dependencies': [
|
||||
'<(icu_src_dir)/icu.gyp:*',
|
||||
'js2c_i18n#host',
|
||||
'../../../tools/gyp/v8.gyp:v8',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'js2c_i18n',
|
||||
'type': 'none',
|
||||
'toolsets': ['host'],
|
||||
'variables': {
|
||||
'library_files': [
|
||||
'i18n.js'
|
||||
],
|
||||
},
|
||||
'actions': [
|
||||
{
|
||||
'action_name': 'js2c_i18n',
|
||||
'inputs': [
|
||||
'../../../tools/js2c.py',
|
||||
'<@(library_files)',
|
||||
],
|
||||
'outputs': [
|
||||
'<(SHARED_INTERMEDIATE_DIR)/i18n-js.cc',
|
||||
'<(SHARED_INTERMEDIATE_DIR)/i18n-js-empty.cc'
|
||||
],
|
||||
'action': [
|
||||
'python',
|
||||
'../../../tools/js2c.py',
|
||||
'<@(_outputs)',
|
||||
'I18N',
|
||||
'<@(library_files)'
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
], # targets
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "break-iterator.h"
|
||||
#include "natives.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/uloc.h"
|
||||
|
||||
@ -39,73 +40,19 @@ namespace internal {
|
||||
|
||||
I18NExtension* I18NExtension::extension_ = NULL;
|
||||
|
||||
// TODO(cira): maybe move JS code to a .js file and generata cc files from it?
|
||||
// TODO(cira): Remove v8 prefix from v8Locale once we have stable API.
|
||||
const char* const I18NExtension::kSource =
|
||||
"v8Locale = function(optLocale) {"
|
||||
" native function NativeJSLocale();"
|
||||
" var properties = NativeJSLocale(optLocale);"
|
||||
" this.locale = properties.locale;"
|
||||
" this.language = properties.language;"
|
||||
" this.script = properties.script;"
|
||||
" this.region = properties.region;"
|
||||
"};"
|
||||
"v8Locale.availableLocales = function() {"
|
||||
" native function NativeJSAvailableLocales();"
|
||||
" return NativeJSAvailableLocales();"
|
||||
"};"
|
||||
"v8Locale.prototype.maximizedLocale = function() {"
|
||||
" native function NativeJSMaximizedLocale();"
|
||||
" return new v8Locale(NativeJSMaximizedLocale(this.locale));"
|
||||
"};"
|
||||
"v8Locale.prototype.minimizedLocale = function() {"
|
||||
" native function NativeJSMinimizedLocale();"
|
||||
" return new v8Locale(NativeJSMinimizedLocale(this.locale));"
|
||||
"};"
|
||||
"v8Locale.prototype.displayLocale_ = function(displayLocale) {"
|
||||
" var result = this.locale;"
|
||||
" if (displayLocale !== undefined) {"
|
||||
" result = displayLocale.locale;"
|
||||
" }"
|
||||
" return result;"
|
||||
"};"
|
||||
"v8Locale.prototype.displayLanguage = function(optDisplayLocale) {"
|
||||
" var displayLocale = this.displayLocale_(optDisplayLocale);"
|
||||
" native function NativeJSDisplayLanguage();"
|
||||
" return NativeJSDisplayLanguage(this.locale, displayLocale);"
|
||||
"};"
|
||||
"v8Locale.prototype.displayScript = function(optDisplayLocale) {"
|
||||
" var displayLocale = this.displayLocale_(optDisplayLocale);"
|
||||
" native function NativeJSDisplayScript();"
|
||||
" return NativeJSDisplayScript(this.locale, displayLocale);"
|
||||
"};"
|
||||
"v8Locale.prototype.displayRegion = function(optDisplayLocale) {"
|
||||
" var displayLocale = this.displayLocale_(optDisplayLocale);"
|
||||
" native function NativeJSDisplayRegion();"
|
||||
" return NativeJSDisplayRegion(this.locale, displayLocale);"
|
||||
"};"
|
||||
"v8Locale.prototype.displayName = function(optDisplayLocale) {"
|
||||
" var displayLocale = this.displayLocale_(optDisplayLocale);"
|
||||
" native function NativeJSDisplayName();"
|
||||
" return NativeJSDisplayName(this.locale, displayLocale);"
|
||||
"};"
|
||||
"v8Locale.v8BreakIterator = function(locale, type) {"
|
||||
" native function NativeJSBreakIterator();"
|
||||
" var iterator = NativeJSBreakIterator(locale, type);"
|
||||
" iterator.type = type;"
|
||||
" return iterator;"
|
||||
"};"
|
||||
"v8Locale.v8BreakIterator.BreakType = {"
|
||||
" 'unknown': -1,"
|
||||
" 'none': 0,"
|
||||
" 'number': 100,"
|
||||
" 'word': 200,"
|
||||
" 'kana': 300,"
|
||||
" 'ideo': 400"
|
||||
"};"
|
||||
"v8Locale.prototype.v8CreateBreakIterator = function(type) {"
|
||||
" return new v8Locale.v8BreakIterator(this.locale, type);"
|
||||
"};";
|
||||
// Returns a pointer to static string containing the actual
|
||||
// JavaScript code generated from i18n.js file.
|
||||
static const char* GetScriptSource() {
|
||||
int index = NativesCollection<I18N>::GetIndex("i18n");
|
||||
Vector<const char> script_data =
|
||||
NativesCollection<I18N>::GetScriptSource(index);
|
||||
|
||||
return script_data.start();
|
||||
}
|
||||
|
||||
I18NExtension::I18NExtension()
|
||||
: v8::Extension("v8/i18n", GetScriptSource()) {
|
||||
}
|
||||
|
||||
v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction(
|
||||
v8::Handle<v8::String> name) {
|
||||
|
@ -36,7 +36,8 @@ namespace internal {
|
||||
|
||||
class I18NExtension : public v8::Extension {
|
||||
public:
|
||||
I18NExtension() : v8::Extension("v8/i18n", kSource) {}
|
||||
I18NExtension();
|
||||
|
||||
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
|
||||
v8::Handle<v8::String> name);
|
||||
|
||||
@ -55,7 +56,6 @@ class I18NExtension : public v8::Extension {
|
||||
static I18NExtension* get();
|
||||
|
||||
private:
|
||||
static const char* const kSource;
|
||||
static I18NExtension* extension_;
|
||||
};
|
||||
|
||||
|
103
src/extensions/experimental/i18n.js
Normal file
103
src/extensions/experimental/i18n.js
Normal file
@ -0,0 +1,103 @@
|
||||
// Copyright 2006-2011 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// TODO(cira): Remove v8 prefix from v8Locale once we have stable API.
|
||||
v8Locale = function(optLocale) {
|
||||
native function NativeJSLocale();
|
||||
var properties = NativeJSLocale(optLocale);
|
||||
this.locale = properties.locale;
|
||||
this.language = properties.language;
|
||||
this.script = properties.script;
|
||||
this.region = properties.region;
|
||||
};
|
||||
|
||||
v8Locale.availableLocales = function() {
|
||||
native function NativeJSAvailableLocales();
|
||||
return NativeJSAvailableLocales();
|
||||
};
|
||||
|
||||
v8Locale.prototype.maximizedLocale = function() {
|
||||
native function NativeJSMaximizedLocale();
|
||||
return new v8Locale(NativeJSMaximizedLocale(this.locale));
|
||||
};
|
||||
|
||||
v8Locale.prototype.minimizedLocale = function() {
|
||||
native function NativeJSMinimizedLocale();
|
||||
return new v8Locale(NativeJSMinimizedLocale(this.locale));
|
||||
};
|
||||
|
||||
v8Locale.prototype.displayLocale_ = function(displayLocale) {
|
||||
var result = this.locale;
|
||||
if (displayLocale !== undefined) {
|
||||
result = displayLocale.locale;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
v8Locale.prototype.displayLanguage = function(optDisplayLocale) {
|
||||
var displayLocale = this.displayLocale_(optDisplayLocale);
|
||||
native function NativeJSDisplayLanguage();
|
||||
return NativeJSDisplayLanguage(this.locale, displayLocale);
|
||||
};
|
||||
|
||||
v8Locale.prototype.displayScript = function(optDisplayLocale) {
|
||||
var displayLocale = this.displayLocale_(optDisplayLocale);
|
||||
native function NativeJSDisplayScript();
|
||||
return NativeJSDisplayScript(this.locale, displayLocale);
|
||||
};
|
||||
|
||||
v8Locale.prototype.displayRegion = function(optDisplayLocale) {
|
||||
var displayLocale = this.displayLocale_(optDisplayLocale);
|
||||
native function NativeJSDisplayRegion();
|
||||
return NativeJSDisplayRegion(this.locale, displayLocale);
|
||||
};
|
||||
|
||||
v8Locale.prototype.displayName = function(optDisplayLocale) {
|
||||
var displayLocale = this.displayLocale_(optDisplayLocale);
|
||||
native function NativeJSDisplayName();
|
||||
return NativeJSDisplayName(this.locale, displayLocale);
|
||||
};
|
||||
|
||||
v8Locale.v8BreakIterator = function(locale, type) {
|
||||
native function NativeJSBreakIterator();
|
||||
var iterator = NativeJSBreakIterator(locale, type);
|
||||
iterator.type = type;
|
||||
return iterator;
|
||||
};
|
||||
|
||||
v8Locale.v8BreakIterator.BreakType = {
|
||||
'unknown': -1,
|
||||
'none': 0,
|
||||
'number': 100,
|
||||
'word': 200,
|
||||
'kana': 300,
|
||||
'ideo': 400
|
||||
};
|
||||
|
||||
v8Locale.prototype.v8CreateBreakIterator = function(type) {
|
||||
return new v8Locale.v8BreakIterator(this.locale, type);
|
||||
};
|
@ -36,7 +36,7 @@ typedef bool (*NativeSourceCallback)(Vector<const char> name,
|
||||
int index);
|
||||
|
||||
enum NativeType {
|
||||
CORE, D8
|
||||
CORE, D8, I18N
|
||||
};
|
||||
|
||||
template <NativeType type>
|
||||
|
Loading…
Reference in New Issue
Block a user