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