From: jochen@chromium.org Date: Tue, 25 Mar 2014 12:05:33 +0000 (+0000) Subject: Roll ICU 239289:258359 and add support for external ICU data tables X-Git-Tag: upstream/4.7.83~10021 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04eefb86f46a43d56f19b4c63581c03eec08b2f4;p=platform%2Fupstream%2Fv8.git Roll ICU 239289:258359 and add support for external ICU data tables The only binary that supports ICU data tables is d8. The location of the data table file has to be passed via a command line switch: $ out/x64.optdebug/d8 --icu-data-file=out/x64.optdebug/icudtl.dat BUG=72633,v8:3142 R=danno@chromium.org LOG=y Review URL: https://codereview.chromium.org/209323014 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20239 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/DEPS b/DEPS index 66d21eb..353c5c8 100644 --- a/DEPS +++ b/DEPS @@ -8,7 +8,7 @@ deps = { "http://gyp.googlecode.com/svn/trunk@1831", "v8/third_party/icu": - "https://src.chromium.org/chrome/trunk/deps/third_party/icu46@239289", + "https://src.chromium.org/chrome/trunk/deps/third_party/icu46@258359", } deps_os = { diff --git a/Makefile b/Makefile index 6bd9bac..f390028 100644 --- a/Makefile +++ b/Makefile @@ -465,4 +465,4 @@ dependencies: --revision 1831 svn checkout --force \ https://src.chromium.org/chrome/trunk/deps/third_party/icu46 \ - third_party/icu --revision 239289 + third_party/icu --revision 258359 diff --git a/include/v8.h b/include/v8.h index 3687485..6590ed5 100644 --- a/include/v8.h +++ b/include/v8.h @@ -4975,8 +4975,11 @@ class V8_EXPORT V8 { /** * Initialize the ICU library bundled with V8. The embedder should only * invoke this method when using the bundled ICU. Returns true on success. + * + * If V8 was compiled with the ICU data in an external file, the location + * of the data file has to be provided. */ - static bool InitializeICU(); + static bool InitializeICU(const char* icu_data_file = NULL); /** * Sets the v8::Platform to use. This should be invoked before V8 is diff --git a/src/api.cc b/src/api.cc index ea2edbc..f5ae10d 100644 --- a/src/api.cc +++ b/src/api.cc @@ -5112,8 +5112,8 @@ int v8::V8::ContextDisposedNotification() { } -bool v8::V8::InitializeICU() { - return i::InitializeICU(); +bool v8::V8::InitializeICU(const char* icu_data_file) { + return i::InitializeICU(icu_data_file); } diff --git a/src/d8.cc b/src/d8.cc index d071105..7ac0c65 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -1440,6 +1440,9 @@ bool Shell::SetOptions(int argc, char* argv[]) { } else if (strcmp(argv[i], "--throws") == 0) { options.expected_to_throw = true; argv[i] = NULL; + } else if (strncmp(argv[i], "--icu-data-file=", 16) == 0) { + options.icu_data_file = argv[i] + 16; + argv[i] = NULL; } #ifdef V8_SHARED else if (strcmp(argv[i], "--dump-counters") == 0) { @@ -1674,7 +1677,7 @@ class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { int Shell::Main(int argc, char* argv[]) { if (!SetOptions(argc, argv)) return 1; - v8::V8::InitializeICU(); + v8::V8::InitializeICU(options.icu_data_file); #ifndef V8_SHARED i::FLAG_trace_hydrogen_file = "hydrogen.cfg"; i::FLAG_redirect_code_traces_to = "code.asm"; diff --git a/src/d8.h b/src/d8.h index db2edb9..3edd8a7 100644 --- a/src/d8.h +++ b/src/d8.h @@ -233,7 +233,8 @@ class ShellOptions { expected_to_throw(false), mock_arraybuffer_allocator(false), num_isolates(1), - isolate_sources(NULL) { } + isolate_sources(NULL), + icu_data_file(NULL) { } ~ShellOptions() { #ifndef V8_SHARED @@ -258,6 +259,7 @@ class ShellOptions { bool mock_arraybuffer_allocator; int num_isolates; SourceGroup* isolate_sources; + const char* icu_data_file; }; #ifdef V8_SHARED diff --git a/src/icu_util.cc b/src/icu_util.cc index b9bd65e..6441dbd 100644 --- a/src/icu_util.cc +++ b/src/icu_util.cc @@ -27,12 +27,20 @@ #include "icu_util.h" -#if defined(_WIN32) && defined(V8_I18N_SUPPORT) +#if defined(_WIN32) #include +#endif + +#if defined(V8_I18N_SUPPORT) +#include #include "unicode/putil.h" #include "unicode/udata.h" +#define ICU_UTIL_DATA_FILE 0 +#define ICU_UTIL_DATA_SHARED 1 +#define ICU_UTIL_DATA_STATIC 2 + #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" #endif @@ -41,8 +49,11 @@ namespace v8 { namespace internal { -bool InitializeICU() { -#if defined(_WIN32) && defined(V8_I18N_SUPPORT) +bool InitializeICU(const char* icu_data_file) { +#if !defined(V8_I18N_SUPPORT) + return true; +#else +#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED // We expect to find the ICU data module alongside the current module. HMODULE module = LoadLibraryA(ICU_UTIL_DATA_SHARED_MODULE_NAME); if (!module) return false; @@ -53,9 +64,30 @@ bool InitializeICU() { UErrorCode err = U_ZERO_ERROR; udata_setCommonData(reinterpret_cast(addr), &err); return err == U_ZERO_ERROR; -#else +#elif ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC // Mac/Linux bundle the ICU data in. return true; +#elif ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE + if (!icu_data_file) return false; + + FILE* inf = fopen(icu_data_file, "rb"); + if (!inf) return false; + + fseek(inf, 0, SEEK_END); + size_t size = ftell(inf); + rewind(inf); + + char* addr = new char[size]; + if (fread(addr, 1, size, inf) != size) { + delete[] addr; + fclose(inf); + return false; + } + fclose(inf); + UErrorCode err = U_ZERO_ERROR; + udata_setCommonData(reinterpret_cast(addr), &err); + return err == U_ZERO_ERROR; +#endif #endif } diff --git a/src/icu_util.h b/src/icu_util.h index 478abce..6b50c18 100644 --- a/src/icu_util.h +++ b/src/icu_util.h @@ -35,7 +35,7 @@ namespace internal { // Call this function to load ICU's data tables for the current process. This // function should be called before ICU is used. -bool InitializeICU(); +bool InitializeICU(const char* icu_data_file); } } // namespace v8::internal diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index be2dfd3..52143e9 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -27,6 +27,7 @@ { 'variables': { + 'icu_use_data_file_flag%': 0, 'v8_code': 1, 'v8_random_seed%': 314159265, }, @@ -1020,6 +1021,17 @@ '../../src/default-platform.h', ], }], + ['icu_use_data_file_flag==1', { + 'defines': ['ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE'], + }, { # else icu_use_data_file_flag !=1 + 'conditions': [ + ['OS=="win"', { + 'defines': ['ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_SHARED'], + }, { + 'defines': ['ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC'], + }], + ], + }], ], }, {