Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: src/startup-data-util.cc

Issue 2042253002: [icu] Support loading data file from default location (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Format Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/snapshot/mksnapshot.cc ('k') | src/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/startup-data-util.h" 5 #include "src/startup-data-util.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "src/base/file-utils.h"
10 #include "src/base/logging.h" 11 #include "src/base/logging.h"
11 #include "src/base/platform/platform.h" 12 #include "src/base/platform/platform.h"
12 #include "src/utils.h" 13 #include "src/utils.h"
13 14
14 15
15 namespace v8 { 16 namespace v8 {
16 namespace internal { 17 namespace internal {
17 18
18 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 19 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
19 20
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 71 }
71 72
72 73
73 void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) { 74 void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) {
74 Load(natives_blob, &g_natives, v8::V8::SetNativesDataBlob); 75 Load(natives_blob, &g_natives, v8::V8::SetNativesDataBlob);
75 Load(snapshot_blob, &g_snapshot, v8::V8::SetSnapshotDataBlob); 76 Load(snapshot_blob, &g_snapshot, v8::V8::SetSnapshotDataBlob);
76 77
77 atexit(&FreeStartupData); 78 atexit(&FreeStartupData);
78 } 79 }
79 80
80
81 char* RelativePath(char** buffer, const char* exec_path, const char* name) {
82 DCHECK(exec_path);
83 int path_separator = static_cast<int>(strlen(exec_path)) - 1;
84 while (path_separator >= 0 &&
85 !base::OS::isDirectorySeparator(exec_path[path_separator])) {
86 path_separator--;
87 }
88 if (path_separator >= 0) {
89 int name_length = static_cast<int>(strlen(name));
90 *buffer =
91 reinterpret_cast<char*>(calloc(path_separator + name_length + 2, 1));
92 *buffer[0] = '\0';
93 strncat(*buffer, exec_path, path_separator + 1);
94 strncat(*buffer, name, name_length);
95 } else {
96 *buffer = strdup(name);
97 }
98 return *buffer;
99 }
100
101 } // namespace 81 } // namespace
102 #endif // V8_USE_EXTERNAL_STARTUP_DATA 82 #endif // V8_USE_EXTERNAL_STARTUP_DATA
103 83
104 84
105 void InitializeExternalStartupData(const char* directory_path) { 85 void InitializeExternalStartupData(const char* directory_path) {
106 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 86 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
107 char* natives; 87 char* natives;
108 char* snapshot; 88 char* snapshot;
109 LoadFromFiles(RelativePath(&natives, directory_path, "natives_blob.bin"), 89 LoadFromFiles(RelativePath(&natives, directory_path, "natives_blob.bin"),
110 RelativePath(&snapshot, directory_path, "snapshot_blob.bin")); 90 RelativePath(&snapshot, directory_path, "snapshot_blob.bin"));
111 free(natives); 91 free(natives);
112 free(snapshot); 92 free(snapshot);
113 #endif // V8_USE_EXTERNAL_STARTUP_DATA 93 #endif // V8_USE_EXTERNAL_STARTUP_DATA
114 } 94 }
115 95
116 96
117 void InitializeExternalStartupData(const char* natives_blob, 97 void InitializeExternalStartupData(const char* natives_blob,
118 const char* snapshot_blob) { 98 const char* snapshot_blob) {
119 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 99 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
120 LoadFromFiles(natives_blob, snapshot_blob); 100 LoadFromFiles(natives_blob, snapshot_blob);
121 #endif // V8_USE_EXTERNAL_STARTUP_DATA 101 #endif // V8_USE_EXTERNAL_STARTUP_DATA
122 } 102 }
123 103
124 } // namespace internal 104 } // namespace internal
125 } // namespace v8 105 } // namespace v8
OLDNEW
« no previous file with comments | « src/snapshot/mksnapshot.cc ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698