Revision: 15572
Author:   [email protected]
Date:     Tue Jul  9 05:26:07 2013
Log: Initialize ICU data files in d8 and disable i18n for other code samples

BUG=v8:2745
[email protected]

Review URL: https://codereview.chromium.org/18899002
http://code.google.com/p/v8/source/detail?r=15572

Added:
 /branches/bleeding_edge/src/icu_util.cc
 /branches/bleeding_edge/src/icu_util.h
Modified:
 /branches/bleeding_edge/samples/lineprocessor.cc
 /branches/bleeding_edge/samples/process.cc
 /branches/bleeding_edge/samples/shell.cc
 /branches/bleeding_edge/src/d8.cc
 /branches/bleeding_edge/src/d8.gyp

=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/icu_util.cc     Tue Jul  9 05:26:07 2013
@@ -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 <windows.h>
+
+#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<void*>(addr), &err);
+  return err == U_ZERO_ERROR;
+#else
+  // Mac/Linux bundle the ICU data in.
+  return true;
+#endif
+}
+
+}  // namespace v8
=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/icu_util.h      Tue Jul  9 05:26:07 2013
@@ -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_
=======================================
--- /branches/bleeding_edge/samples/lineprocessor.cc Fri Jul 5 02:52:11 2013 +++ /branches/bleeding_edge/samples/lineprocessor.cc Tue Jul 9 05:26:07 2013
@@ -137,6 +137,8 @@

 int RunMain(int argc, char* argv[]) {
   v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
+  v8::V8::SetFlagsFromString("--noenable_i18n",
+                             static_cast<int>(strlen("--noenable_i18n")));
   v8::Isolate* isolate = v8::Isolate::GetCurrent();
   v8::HandleScope handle_scope(isolate);

=======================================
--- /branches/bleeding_edge/samples/process.cc  Fri Jul  5 02:52:11 2013
+++ /branches/bleeding_edge/samples/process.cc  Tue Jul  9 05:26:07 2013
@@ -27,6 +27,7 @@

 #include <v8.h>

+#include <cstring>
 #include <string>
 #include <map>

@@ -634,6 +635,8 @@
     fprintf(stderr, "No script was specified.\n");
     return 1;
   }
+  V8::SetFlagsFromString("--noenable_i18n",
+                         static_cast<int>(strlen("--noenable_i18n")));
   Isolate* isolate = Isolate::GetCurrent();
   HandleScope scope(isolate);
   Handle<String> source = ReadFile(file);
=======================================
--- /branches/bleeding_edge/samples/shell.cc    Wed Jun  5 05:36:33 2013
+++ /branches/bleeding_edge/samples/shell.cc    Tue Jul  9 05:26:07 2013
@@ -67,6 +67,8 @@

 int main(int argc, char* argv[]) {
   v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
+  v8::V8::SetFlagsFromString("--noenable_i18n",
+                             static_cast<int>(strlen("--noenable_i18n")));
   v8::Isolate* isolate = v8::Isolate::GetCurrent();
   run_shell = (argc == 1);
   int result;
=======================================
--- /branches/bleeding_edge/src/d8.cc   Fri Jul  5 02:52:11 2013
+++ /branches/bleeding_edge/src/d8.cc   Tue Jul  9 05:26:07 2013
@@ -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 <unistd.h>  // NOLINT
 #endif
@@ -1582,6 +1586,9 @@

 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;
=======================================
--- /branches/bleeding_edge/src/d8.gyp  Fri Jun 28 08:22:46 2013
+++ /branches/bleeding_edge/src/d8.gyp  Tue Jul  9 05:26:07 2013
@@ -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:*',
+          ],
+        }],
       ],
     },
     {

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to