OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium 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 "testing/test_support.h" | 5 #include "testing/test_support.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 GetFileContents(full_path.c_str(), &data_length); | 51 GetFileContents(full_path.c_str(), &data_length); |
52 if (!data_buffer) | 52 if (!data_buffer) |
53 return false; | 53 return false; |
54 | 54 |
55 result_data->data = data_buffer.release(); | 55 result_data->data = data_buffer.release(); |
56 result_data->raw_size = data_length; | 56 result_data->raw_size = data_length; |
57 return true; | 57 return true; |
58 } | 58 } |
59 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 59 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
60 | 60 |
61 void InitializeV8Common(v8::Platform** platform) { | 61 void InitializeV8Common(const char* exe_path, v8::Platform** platform) { |
62 v8::V8::InitializeICU(); | 62 v8::V8::InitializeICUDefaultLocation(exe_path); |
63 | 63 |
64 *platform = v8::platform::CreateDefaultPlatform(); | 64 *platform = v8::platform::CreateDefaultPlatform(); |
65 v8::V8::InitializePlatform(*platform); | 65 v8::V8::InitializePlatform(*platform); |
66 v8::V8::Initialize(); | 66 v8::V8::Initialize(); |
67 | 67 |
68 // By enabling predictable mode, V8 won't post any background tasks. | 68 // By enabling predictable mode, V8 won't post any background tasks. |
69 const char predictable_flag[] = "--predictable"; | 69 const char predictable_flag[] = "--predictable"; |
70 v8::V8::SetFlagsFromString(predictable_flag, | 70 v8::V8::SetFlagsFromString(predictable_flag, |
71 static_cast<int>(strlen(predictable_flag))); | 71 static_cast<int>(strlen(predictable_flag))); |
72 } | 72 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return result; | 149 return result; |
150 } | 150 } |
151 | 151 |
152 #ifdef PDF_ENABLE_V8 | 152 #ifdef PDF_ENABLE_V8 |
153 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 153 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
154 bool InitializeV8ForPDFium(const std::string& exe_path, | 154 bool InitializeV8ForPDFium(const std::string& exe_path, |
155 const std::string& bin_dir, | 155 const std::string& bin_dir, |
156 v8::StartupData* natives_blob, | 156 v8::StartupData* natives_blob, |
157 v8::StartupData* snapshot_blob, | 157 v8::StartupData* snapshot_blob, |
158 v8::Platform** platform) { | 158 v8::Platform** platform) { |
159 InitializeV8Common(platform); | 159 InitializeV8Common(exe_path.c_str(), platform); |
160 if (!GetExternalData(exe_path, bin_dir, "natives_blob.bin", natives_blob)) | 160 if (!GetExternalData(exe_path, bin_dir, "natives_blob.bin", natives_blob)) |
161 return false; | 161 return false; |
162 if (!GetExternalData(exe_path, bin_dir, "snapshot_blob.bin", snapshot_blob)) | 162 if (!GetExternalData(exe_path, bin_dir, "snapshot_blob.bin", snapshot_blob)) |
163 return false; | 163 return false; |
164 v8::V8::SetNativesDataBlob(natives_blob); | 164 v8::V8::SetNativesDataBlob(natives_blob); |
165 v8::V8::SetSnapshotDataBlob(snapshot_blob); | 165 v8::V8::SetSnapshotDataBlob(snapshot_blob); |
166 return true; | 166 return true; |
167 } | 167 } |
168 #else // V8_USE_EXTERNAL_STARTUP_DATA | 168 #else // V8_USE_EXTERNAL_STARTUP_DATA |
169 bool InitializeV8ForPDFium(v8::Platform** platform) { | 169 bool InitializeV8ForPDFium(const std::string& exe_path, |
170 InitializeV8Common(platform); | 170 v8::Platform** platform) { |
| 171 InitializeV8Common(exe_path.c_str(), platform); |
171 return true; | 172 return true; |
172 } | 173 } |
173 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 174 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
174 #endif // PDF_ENABLE_V8 | 175 #endif // PDF_ENABLE_V8 |
175 | 176 |
176 TestLoader::TestLoader(const char* pBuf, size_t len) | 177 TestLoader::TestLoader(const char* pBuf, size_t len) |
177 : m_pBuf(pBuf), m_Len(len) { | 178 : m_pBuf(pBuf), m_Len(len) { |
178 } | 179 } |
179 | 180 |
180 // static | 181 // static |
(...skipping 19 matching lines...) Expand all Loading... |
200 } | 201 } |
201 | 202 |
202 // static | 203 // static |
203 int TestSaver::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, | 204 int TestSaver::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, |
204 const void* data, | 205 const void* data, |
205 unsigned long size) { | 206 unsigned long size) { |
206 TestSaver* pThis = static_cast<TestSaver*>(pFileWrite); | 207 TestSaver* pThis = static_cast<TestSaver*>(pFileWrite); |
207 pThis->m_String.append(static_cast<const char*>(data), size); | 208 pThis->m_String.append(static_cast<const char*>(data), size); |
208 return 1; | 209 return 1; |
209 } | 210 } |
OLD | NEW |