| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 | 5 |
| 6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
| 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
| 8 #define V8_SHARED | 8 #define V8_SHARED |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 1548 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 1549 class StartupDataHandler { | 1549 class StartupDataHandler { |
| 1550 public: | 1550 public: |
| 1551 StartupDataHandler(const char* exec_path, const char* natives_blob, | 1551 StartupDataHandler(const char* exec_path, const char* natives_blob, |
| 1552 const char* snapshot_blob) { | 1552 const char* snapshot_blob) { |
| 1553 // If we have (at least one) explicitly given blob, use those. | 1553 // If we have (at least one) explicitly given blob, use those. |
| 1554 // If not, use the default blob locations next to the d8 binary. | 1554 // If not, use the default blob locations next to the d8 binary. |
| 1555 if (natives_blob || snapshot_blob) { | 1555 if (natives_blob || snapshot_blob) { |
| 1556 LoadFromFiles(natives_blob, snapshot_blob); | 1556 LoadFromFiles(natives_blob, snapshot_blob); |
| 1557 } else { | 1557 } else { |
| 1558 char natives[100], snapshot[100]; | 1558 char* natives; |
| 1559 LoadFromFiles( | 1559 char* snapshot; |
| 1560 RelativePath(natives, exec_path, "natives_blob.bin", sizeof(natives)), | 1560 LoadFromFiles(RelativePath(&natives, exec_path, "natives_blob.bin"), |
| 1561 RelativePath(snapshot, exec_path, "snapshot_blob.bin", | 1561 RelativePath(&snapshot, exec_path, "snapshot_blob.bin")); |
| 1562 sizeof(snapshot))); | 1562 |
| 1563 free(natives); |
| 1564 free(snapshot); |
| 1563 } | 1565 } |
| 1564 } | 1566 } |
| 1565 | 1567 |
| 1566 ~StartupDataHandler() { | 1568 ~StartupDataHandler() { |
| 1567 delete[] natives_.data; | 1569 delete[] natives_.data; |
| 1568 delete[] snapshot_.data; | 1570 delete[] snapshot_.data; |
| 1569 } | 1571 } |
| 1570 | 1572 |
| 1571 private: | 1573 private: |
| 1572 static char* RelativePath(char* buffer, const char* exec_path, | 1574 static char* RelativePath(char** buffer, const char* exec_path, |
| 1573 const char* name, int buffer_length) { | 1575 const char* name) { |
| 1574 DCHECK(exec_path); | 1576 DCHECK(exec_path); |
| 1575 const char* last_slash = strrchr(exec_path, '/'); | 1577 const char* last_slash = strrchr(exec_path, '/'); |
| 1576 if (last_slash) { | 1578 if (last_slash) { |
| 1577 int after_slash = last_slash - exec_path + 1; | 1579 int after_slash = last_slash - exec_path + 1; |
| 1578 DCHECK(buffer_length > after_slash); | 1580 int name_length = strlen(name); |
| 1579 strncpy(buffer, exec_path, after_slash); | 1581 *buffer = |
| 1580 buffer[after_slash] = '\0'; | 1582 reinterpret_cast<char*>(calloc(after_slash + name_length + 1, 1)); |
| 1581 return strncat(buffer, name, buffer_length); | 1583 strncpy(*buffer, exec_path, after_slash); |
| 1584 strncat(*buffer, name, name_length); |
| 1582 } else { | 1585 } else { |
| 1583 return strncpy(buffer, name, buffer_length); | 1586 *buffer = strdup(name); |
| 1584 } | 1587 } |
| 1588 return *buffer; |
| 1585 } | 1589 } |
| 1586 | 1590 |
| 1587 void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) { | 1591 void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) { |
| 1588 Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob); | 1592 Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob); |
| 1589 Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob); | 1593 Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob); |
| 1590 } | 1594 } |
| 1591 | 1595 |
| 1592 void Load(const char* blob_file, | 1596 void Load(const char* blob_file, |
| 1593 v8::StartupData* startup_data, | 1597 v8::StartupData* startup_data, |
| 1594 void (*setter_fn)(v8::StartupData*)) { | 1598 void (*setter_fn)(v8::StartupData*)) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1746 } | 1750 } |
| 1747 | 1751 |
| 1748 } // namespace v8 | 1752 } // namespace v8 |
| 1749 | 1753 |
| 1750 | 1754 |
| 1751 #ifndef GOOGLE3 | 1755 #ifndef GOOGLE3 |
| 1752 int main(int argc, char* argv[]) { | 1756 int main(int argc, char* argv[]) { |
| 1753 return v8::Shell::Main(argc, argv); | 1757 return v8::Shell::Main(argc, argv); |
| 1754 } | 1758 } |
| 1755 #endif | 1759 #endif |
| OLD | NEW |