From 518ca395ccbdc79aacd9fc50f17ef9ec749280d5 Mon Sep 17 00:00:00 2001 From: "jochen@chromium.org" Date: Tue, 9 Jul 2013 12:26:07 +0000 Subject: [PATCH] Initialize ICU data files in d8 and disable i18n for other code samples BUG=v8:2745 R=jkummerow@chromium.org Review URL: https://codereview.chromium.org/18899002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15572 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- samples/lineprocessor.cc | 2 ++ samples/process.cc | 3 ++ samples/shell.cc | 2 ++ src/d8.cc | 7 +++++ src/d8.gyp | 10 +++++++ src/icu_util.cc | 60 ++++++++++++++++++++++++++++++++++++++++ src/icu_util.h | 40 +++++++++++++++++++++++++++ 7 files changed, 124 insertions(+) create mode 100644 src/icu_util.cc create mode 100644 src/icu_util.h diff --git a/samples/lineprocessor.cc b/samples/lineprocessor.cc index adc5b13e4d..0c84419d3a 100644 --- a/samples/lineprocessor.cc +++ b/samples/lineprocessor.cc @@ -137,6 +137,8 @@ void DispatchDebugMessages() { int RunMain(int argc, char* argv[]) { v8::V8::SetFlagsFromCommandLine(&argc, argv, true); + v8::V8::SetFlagsFromString("--noenable_i18n", + static_cast(strlen("--noenable_i18n"))); v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handle_scope(isolate); diff --git a/samples/process.cc b/samples/process.cc index 1f1f92b5f5..80805d2c29 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -27,6 +27,7 @@ #include +#include #include #include @@ -634,6 +635,8 @@ int main(int argc, char* argv[]) { fprintf(stderr, "No script was specified.\n"); return 1; } + V8::SetFlagsFromString("--noenable_i18n", + static_cast(strlen("--noenable_i18n"))); Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); Handle source = ReadFile(file); diff --git a/samples/shell.cc b/samples/shell.cc index a0af931b23..5c5f056ed1 100644 --- a/samples/shell.cc +++ b/samples/shell.cc @@ -67,6 +67,8 @@ static bool run_shell; int main(int argc, char* argv[]) { v8::V8::SetFlagsFromCommandLine(&argc, argv, true); + v8::V8::SetFlagsFromString("--noenable_i18n", + static_cast(strlen("--noenable_i18n"))); v8::Isolate* isolate = v8::Isolate::GetCurrent(); run_shell = (argc == 1); int result; diff --git a/src/d8.cc b/src/d8.cc index cb43d2f9c2..21daa0bf5c 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -68,6 +68,10 @@ #include "v8.h" #endif // V8_SHARED +#if defined(V8_I18N_SUPPORT) +#include "icu_util.h" +#endif + #if !defined(_WIN32) && !defined(_WIN64) #include // NOLINT #endif @@ -1582,6 +1586,9 @@ class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { int Shell::Main(int argc, char* argv[]) { if (!SetOptions(argc, argv)) return 1; +#if defined(V8_I18N_SUPPORT) + InitializeICU(); +#endif #ifndef V8_SHARED i::FLAG_harmony_array_buffer = true; i::FLAG_harmony_typed_arrays = true; diff --git a/src/d8.gyp b/src/d8.gyp index 47a7cc0118..40d2f14dab 100644 --- a/src/d8.gyp +++ b/src/d8.gyp @@ -31,6 +31,7 @@ 'console%': '', # Enable support for Intel VTune. Supported on ia32/x64 only 'v8_enable_vtunejit%': 0, + 'v8_enable_i18n_support%': 0, }, 'includes': ['../build/common.gypi'], 'targets': [ @@ -78,6 +79,15 @@ '../src/third_party/vtune/v8vtune.gyp:v8_vtune', ], }], + ['v8_enable_i18n_support==1', { + 'sources': [ + 'icu_util.cc', + 'icu_util.h', + ], + 'dependencies': [ + '<(DEPTH)/third_party/icu/icu.gyp:*', + ], + }], ], }, { diff --git a/src/icu_util.cc b/src/icu_util.cc new file mode 100644 index 0000000000..aaafadc3ee --- /dev/null +++ b/src/icu_util.cc @@ -0,0 +1,60 @@ +// Copyright 2013 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. + +#include "icu_util.h" + +#if defined(_WIN32) +#include + +#include "unicode/putil.h" +#include "unicode/udata.h" + +#define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" +#define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" +#endif + +namespace v8 { + +bool InitializeICU() { +#if defined(_WIN32) + // 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; + + FARPROC addr = GetProcAddress(module, ICU_UTIL_DATA_SYMBOL); + if (!addr) return false; + + UErrorCode err = U_ZERO_ERROR; + udata_setCommonData(reinterpret_cast(addr), &err); + return err == U_ZERO_ERROR; +#else + // Mac/Linux bundle the ICU data in. + return true; +#endif +} + +} // namespace v8 diff --git a/src/icu_util.h b/src/icu_util.h new file mode 100644 index 0000000000..d7961b9d36 --- /dev/null +++ b/src/icu_util.h @@ -0,0 +1,40 @@ +// Copyright 2013 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_ICU_UTIL_H_ +#define V8_ICU_UTIL_H_ + +namespace v8 { + +// Call this function to load ICU's data tables for the current process. This +// function should be called before ICU is used. +bool InitializeICU(); + +} // namespace v8 + +#endif // V8_ICU_UTIL_H_