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 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 options.icu_data_file = argv[i] + 16; | 1320 options.icu_data_file = argv[i] + 16; |
1321 argv[i] = NULL; | 1321 argv[i] = NULL; |
1322 #ifdef V8_SHARED | 1322 #ifdef V8_SHARED |
1323 } else if (strcmp(argv[i], "--dump-counters") == 0) { | 1323 } else if (strcmp(argv[i], "--dump-counters") == 0) { |
1324 printf("D8 with shared library does not include counters\n"); | 1324 printf("D8 with shared library does not include counters\n"); |
1325 return false; | 1325 return false; |
1326 } else if (strcmp(argv[i], "--debugger") == 0) { | 1326 } else if (strcmp(argv[i], "--debugger") == 0) { |
1327 printf("Javascript debugger not included\n"); | 1327 printf("Javascript debugger not included\n"); |
1328 return false; | 1328 return false; |
1329 #endif // V8_SHARED | 1329 #endif // V8_SHARED |
| 1330 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 1331 } else if (strncmp(argv[i], "--natives_blob=", 15) == 0) { |
| 1332 options.natives_blob = argv[i] + 15; |
| 1333 argv[i] = NULL; |
| 1334 } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) { |
| 1335 options.snapshot_blob = argv[i] + 16; |
| 1336 argv[i] = NULL; |
| 1337 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
1330 } | 1338 } |
1331 } | 1339 } |
1332 | 1340 |
1333 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 1341 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
1334 | 1342 |
1335 // Set up isolated source groups. | 1343 // Set up isolated source groups. |
1336 options.isolate_sources = new SourceGroup[options.num_isolates]; | 1344 options.isolate_sources = new SourceGroup[options.num_isolates]; |
1337 SourceGroup* current = options.isolate_sources; | 1345 SourceGroup* current = options.isolate_sources; |
1338 current->Begin(argv, 1); | 1346 current->Begin(argv, 1); |
1339 for (int i = 1; i < argc; i++) { | 1347 for (int i = 1; i < argc; i++) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 } | 1486 } |
1479 virtual void* AllocateUninitialized(size_t length) V8_OVERRIDE { | 1487 virtual void* AllocateUninitialized(size_t length) V8_OVERRIDE { |
1480 return malloc(0); | 1488 return malloc(0); |
1481 } | 1489 } |
1482 virtual void Free(void* p, size_t) V8_OVERRIDE { | 1490 virtual void Free(void* p, size_t) V8_OVERRIDE { |
1483 free(p); | 1491 free(p); |
1484 } | 1492 } |
1485 }; | 1493 }; |
1486 | 1494 |
1487 | 1495 |
| 1496 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 1497 class StartupDataHandler { |
| 1498 public: |
| 1499 StartupDataHandler(const char* natives_blob, |
| 1500 const char* snapshot_blob) { |
| 1501 Load(natives_blob, &natives_, v8::V8::SetNativesDataBlob); |
| 1502 Load(snapshot_blob, &snapshot_, v8::V8::SetSnapshotDataBlob); |
| 1503 } |
| 1504 |
| 1505 ~StartupDataHandler() { |
| 1506 delete[] natives_.data; |
| 1507 delete[] snapshot_.data; |
| 1508 } |
| 1509 |
| 1510 private: |
| 1511 void Load(const char* blob_file, |
| 1512 v8::StartupData* startup_data, |
| 1513 void (*setter_fn)(v8::StartupData*)) { |
| 1514 startup_data->data = NULL; |
| 1515 startup_data->compressed_size = 0; |
| 1516 startup_data->raw_size = 0; |
| 1517 |
| 1518 if (!blob_file) |
| 1519 return; |
| 1520 |
| 1521 FILE* file = fopen(blob_file, "rb"); |
| 1522 if (!file) |
| 1523 return; |
| 1524 |
| 1525 fseek(file, 0, SEEK_END); |
| 1526 startup_data->raw_size = ftell(file); |
| 1527 rewind(file); |
| 1528 |
| 1529 startup_data->data = new char[startup_data->raw_size]; |
| 1530 startup_data->compressed_size = fread( |
| 1531 const_cast<char*>(startup_data->data), 1, startup_data->raw_size, |
| 1532 file); |
| 1533 fclose(file); |
| 1534 |
| 1535 if (startup_data->raw_size == startup_data->compressed_size) |
| 1536 (*setter_fn)(startup_data); |
| 1537 } |
| 1538 |
| 1539 v8::StartupData natives_; |
| 1540 v8::StartupData snapshot_; |
| 1541 |
| 1542 // Disallow copy & assign. |
| 1543 StartupDataHandler(const StartupDataHandler& other); |
| 1544 void operator=(const StartupDataHandler& other); |
| 1545 }; |
| 1546 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 1547 |
| 1548 |
1488 int Shell::Main(int argc, char* argv[]) { | 1549 int Shell::Main(int argc, char* argv[]) { |
1489 if (!SetOptions(argc, argv)) return 1; | 1550 if (!SetOptions(argc, argv)) return 1; |
1490 v8::V8::InitializeICU(options.icu_data_file); | 1551 v8::V8::InitializeICU(options.icu_data_file); |
| 1552 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 1553 StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob); |
| 1554 #endif |
1491 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); | 1555 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); |
1492 SetFlagsFromString("--redirect-code-traces-to=code.asm"); | 1556 SetFlagsFromString("--redirect-code-traces-to=code.asm"); |
1493 ShellArrayBufferAllocator array_buffer_allocator; | 1557 ShellArrayBufferAllocator array_buffer_allocator; |
1494 MockArrayBufferAllocator mock_arraybuffer_allocator; | 1558 MockArrayBufferAllocator mock_arraybuffer_allocator; |
1495 if (options.mock_arraybuffer_allocator) { | 1559 if (options.mock_arraybuffer_allocator) { |
1496 v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator); | 1560 v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator); |
1497 } else { | 1561 } else { |
1498 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); | 1562 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); |
1499 } | 1563 } |
1500 int result = 0; | 1564 int result = 0; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 } | 1633 } |
1570 | 1634 |
1571 } // namespace v8 | 1635 } // namespace v8 |
1572 | 1636 |
1573 | 1637 |
1574 #ifndef GOOGLE3 | 1638 #ifndef GOOGLE3 |
1575 int main(int argc, char* argv[]) { | 1639 int main(int argc, char* argv[]) { |
1576 return v8::Shell::Main(argc, argv); | 1640 return v8::Shell::Main(argc, argv); |
1577 } | 1641 } |
1578 #endif | 1642 #endif |
OLD | NEW |