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 "testing/utils/path_service.h" | 10 #include "testing/utils/path_service.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 return result; | 38 return result; |
39 } | 39 } |
40 | 40 |
41 bool GetExternalData(const std::string& exe_path, | 41 bool GetExternalData(const std::string& exe_path, |
42 const std::string& bin_dir, | 42 const std::string& bin_dir, |
43 const std::string& filename, | 43 const std::string& filename, |
44 v8::StartupData* result_data) { | 44 v8::StartupData* result_data) { |
45 std::string full_path = | 45 std::string full_path = |
46 GetFullPathForSnapshotFile(exe_path, bin_dir, filename); | 46 GetFullPathForSnapshotFile(exe_path, bin_dir, filename); |
47 size_t data_length = 0; | 47 size_t data_length = 0; |
48 char* data_buffer = GetFileContents(full_path.c_str(), &data_length); | 48 std::unique_ptr<char, pdfium::FreeDeleter> data_buffer = |
49 if (!data_buffer) { | 49 GetFileContents(full_path.c_str(), &data_length); |
| 50 if (!data_buffer) |
50 return false; | 51 return false; |
51 } | 52 |
52 result_data->data = const_cast<const char*>(data_buffer); | 53 result_data->data = data_buffer.release(); |
53 result_data->raw_size = data_length; | 54 result_data->raw_size = data_length; |
54 return true; | 55 return true; |
55 } | 56 } |
56 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 57 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
57 | 58 |
58 void InitializeV8Common(v8::Platform** platform) { | 59 void InitializeV8Common(v8::Platform** platform) { |
59 v8::V8::InitializeICU(); | 60 v8::V8::InitializeICU(); |
60 | 61 |
61 *platform = v8::platform::CreateDefaultPlatform(); | 62 *platform = v8::platform::CreateDefaultPlatform(); |
62 v8::V8::InitializePlatform(*platform); | 63 v8::V8::InitializePlatform(*platform); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 unsigned long pos, | 165 unsigned long pos, |
165 unsigned char* pBuf, | 166 unsigned char* pBuf, |
166 unsigned long size) { | 167 unsigned long size) { |
167 TestLoader* pLoader = static_cast<TestLoader*>(param); | 168 TestLoader* pLoader = static_cast<TestLoader*>(param); |
168 if (pos + size < pos || pos + size > pLoader->m_Len) | 169 if (pos + size < pos || pos + size > pLoader->m_Len) |
169 return 0; | 170 return 0; |
170 | 171 |
171 memcpy(pBuf, pLoader->m_pBuf + pos, size); | 172 memcpy(pBuf, pLoader->m_pBuf + pos, size); |
172 return 1; | 173 return 1; |
173 } | 174 } |
OLD | NEW |