Commit ab00b00a authored by cira@chromium.org's avatar cira@chromium.org

Removed all references to v8/src from i18n extension code.

Removed I18N enum from v8/src/natives.h

Removed use of Vector and natives.h from i18n-extension.cc. Added new
python script that generates i18n-js.cc from i18n.js.

Made all paths absolute pointing to either v8/include or
v8/src/extensions/experimental.

Exported -Iv8 for embedders (-Iv8/include was there already).
Review URL: http://codereview.chromium.org/7077012

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8127 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 670f947a
......@@ -25,7 +25,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "break-iterator.h"
#include "src/extensions/experimental/break-iterator.h"
#include <string.h>
#include "unicode/brkiter.h"
#include "unicode/locid.h"
......
......@@ -28,7 +28,7 @@
#ifndef V8_EXTENSIONS_EXPERIMENTAL_BREAK_ITERATOR_H_
#define V8_EXTENSIONS_EXPERIMENTAL_BREAK_ITERATOR_H_
#include <v8.h>
#include "include/v8.h"
#include "unicode/uversion.h"
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "collator.h"
#include "src/extensions/experimental/collator.h"
#include "unicode/coll.h"
#include "unicode/locid.h"
......@@ -220,4 +220,3 @@ v8::Handle<v8::Value> Collator::JSCollator(const v8::Arguments& args) {
}
} } // namespace v8::internal
......@@ -28,7 +28,7 @@
#ifndef V8_EXTENSIONS_EXPERIMENTAL_COLLATOR_H
#define V8_EXTENSIONS_EXPERIMENTAL_COLLATOR_H_
#include <v8.h>
#include "include/v8.h"
#include "unicode/uversion.h"
......@@ -66,4 +66,3 @@ class Collator {
} } // namespace v8::internal
#endif // V8_EXTENSIONS_EXPERIMENTAL_COLLATOR
......@@ -45,6 +45,7 @@
'i18n-extension.h',
'i18n-locale.cc',
'i18n-locale.h',
'i18n-natives.h',
'i18n-utils.cc',
'i18n-utils.h',
'language-matcher.cc',
......@@ -53,13 +54,20 @@
],
'include_dirs': [
'<(icu_src_dir)/public/common',
'../..',
# v8/ is root for all includes.
'../../..'
],
'dependencies': [
'<(icu_src_dir)/icu.gyp:*',
'js2c_i18n#host',
'../../../tools/gyp/v8.gyp:v8',
],
'direct_dependent_settings': {
# Adds -Iv8 for embedders.
'include_dirs': [
'../../..'
],
},
},
{
'target_name': 'js2c_i18n',
......@@ -74,7 +82,7 @@
{
'action_name': 'js2c_i18n',
'inputs': [
'../../../tools/js2c.py',
'i18n-js2c.py',
'<@(library_files)',
],
'outputs': [
......@@ -82,9 +90,8 @@
],
'action': [
'python',
'../../../tools/js2c.py',
'i18n-js2c.py',
'<@(_outputs)',
'I18N',
'<@(library_files)'
],
},
......
......@@ -25,30 +25,20 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "i18n-extension.h"
#include "src/extensions/experimental/i18n-extension.h"
#include "break-iterator.h"
#include "collator.h"
#include "i18n-locale.h"
#include "natives.h"
#include "src/extensions/experimental/break-iterator.h"
#include "src/extensions/experimental/collator.h"
#include "src/extensions/experimental/i18n-locale.h"
#include "src/extensions/experimental/i18n-natives.h"
namespace v8 {
namespace internal {
I18NExtension* I18NExtension::extension_ = NULL;
// 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::Extension("v8/i18n", I18Natives::GetScriptSource()) {
}
v8::Handle<v8::FunctionTemplate> I18NExtension::GetNativeFunction(
......
......@@ -28,7 +28,7 @@
#ifndef V8_EXTENSIONS_EXPERIMENTAL_I18N_EXTENSION_H_
#define V8_EXTENSIONS_EXPERIMENTAL_I18N_EXTENSION_H_
#include <v8.h>
#include "include/v8.h"
namespace v8 {
namespace internal {
......
#!/usr/bin/env python
#
# Copyright 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.
# This is a utility for converting I18N JavaScript source code into C-style
# char arrays. It is used for embedded JavaScript code in the V8
# library.
# This is a pared down copy of v8/tools/js2c.py that avoids use of
# v8/src/natives.h and produces different cc template.
import os, re, sys, string
def ToCArray(lines):
result = []
for chr in lines:
value = ord(chr)
assert value < 128
result.append(str(value))
result.append("0")
return ", ".join(result)
def RemoveCommentsAndTrailingWhitespace(lines):
lines = re.sub(r'//.*\n', '\n', lines) # end-of-line comments
lines = re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', lines) # comments.
lines = re.sub(r'\s+\n+', '\n', lines) # trailing whitespace
return lines
def ReadFile(filename):
file = open(filename, "rt")
try:
lines = file.read()
finally:
file.close()
return lines
EVAL_PATTERN = re.compile(r'\beval\s*\(');
WITH_PATTERN = re.compile(r'\bwith\s*\(');
def Validate(lines, file):
lines = RemoveCommentsAndTrailingWhitespace(lines)
# Because of simplified context setup, eval and with is not
# allowed in the natives files.
eval_match = EVAL_PATTERN.search(lines)
if eval_match:
raise ("Eval disallowed in natives: %s" % file)
with_match = WITH_PATTERN.search(lines)
if with_match:
raise ("With statements disallowed in natives: %s" % file)
HEADER_TEMPLATE = """\
// Copyright 2011 Google Inc. All Rights Reserved.
// This file was generated from .js source files by gyp. If you
// want to make changes to this file you should either change the
// javascript source files or the i18n-js2c.py script.
#include "src/extensions/experimental/i18n-natives.h"
namespace v8 {
namespace internal {
// static
const char* I18Natives::GetScriptSource() {
// JavaScript source gets injected here.
static const char i18n_source[] = {%s};
return i18n_source;
}
} // internal
} // v8
"""
def JS2C(source, target):
filename = str(source)
lines = ReadFile(filename)
Validate(lines, filename)
data = ToCArray(lines)
# Emit result
output = open(target, "w")
output.write(HEADER_TEMPLATE % data)
output.close()
def main():
target = sys.argv[1]
source = sys.argv[2]
JS2C(source, target)
if __name__ == "__main__":
main()
......@@ -25,13 +25,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "i18n-locale.h"
#include "src/extensions/experimental/i18n-locale.h"
#include "i18n-utils.h"
#include "language-matcher.h"
#include "src/extensions/experimental/i18n-utils.h"
#include "src/extensions/experimental/language-matcher.h"
#include "unicode/locid.h"
#include "unicode/uloc.h"
#include "utils.h"
namespace v8 {
namespace internal {
......
......@@ -28,7 +28,7 @@
#ifndef V8_EXTENSIONS_EXPERIMENTAL_I18N_LOCALE_H_
#define V8_EXTENSIONS_EXPERIMENTAL_I18N_LOCALE_H_
#include <v8.h>
#include "include/v8.h"
namespace v8 {
namespace internal {
......
// Copyright 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.
#ifndef V8_EXTENSIONS_EXPERIMENTAL_I18N_NATIVES_H_
#define V8_EXTENSIONS_EXPERIMENTAL_I18N_NATIVES_H_
namespace v8 {
namespace internal {
class I18Natives {
public:
// Gets script source from generated file.
// Source is statically allocated string.
static const char* GetScriptSource();
};
} } // namespace v8::internal
#endif // V8_EXTENSIONS_EXPERIMENTAL_I18N_NATIVES_H_
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "i18n-utils.h"
#include "src/extensions/experimental/i18n-utils.h"
#include <string.h>
......
......@@ -28,13 +28,14 @@
// TODO(cira): Remove LanguageMatcher from v8 when ICU implements
// language matching API.
#include "language-matcher.h"
#include "src/extensions/experimental/language-matcher.h"
#include "i18n-utils.h"
#include <string.h>
#include "src/extensions/experimental/i18n-utils.h"
#include "unicode/datefmt.h" // For getAvailableLocales
#include "unicode/locid.h"
#include "unicode/uloc.h"
#include "utils.h"
namespace v8 {
namespace internal {
......
......@@ -28,7 +28,7 @@
#ifndef V8_EXTENSIONS_EXPERIMENTAL_LANGUAGE_MATCHER_H_
#define V8_EXTENSIONS_EXPERIMENTAL_LANGUAGE_MATCHER_H_
#include <v8.h>
#include "include/v8.h"
#include "unicode/uloc.h"
......
......@@ -36,7 +36,7 @@ typedef bool (*NativeSourceCallback)(Vector<const char> name,
int index);
enum NativeType {
CORE, EXPERIMENTAL, D8, I18N
CORE, EXPERIMENTAL, D8
};
template <NativeType type>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment