OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium 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 "tonic/dart_vm.h" | 5 #include "tonic/dart_vm.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "tonic/dart_debugger.h" | 8 #include "tonic/dart_debugger.h" |
9 | 9 |
10 namespace tonic { | 10 namespace tonic { |
11 | 11 |
12 static char* dart_vm_error_ = NULL; | 12 static char* dart_vm_error_ = NULL; |
13 | 13 |
14 DartVM::Config::Config() { | 14 DartVM::Config::Config() { |
15 vm_isolate_snapshot = nullptr; | 15 vm_isolate_snapshot = nullptr; |
16 instructions_snapshot = nullptr; | 16 instructions_snapshot = nullptr; |
17 data_snapshot = nullptr; | 17 data_snapshot = nullptr; |
18 create = nullptr; | 18 create = nullptr; |
19 interrupt = nullptr; | 19 interrupt = nullptr; |
20 unhandled_exception = nullptr; | 20 unhandled_exception = nullptr; |
21 shutdown = nullptr; | 21 shutdown = nullptr; |
| 22 thread_exit = nullptr; |
22 file_open = nullptr; | 23 file_open = nullptr; |
23 file_read = nullptr; | 24 file_read = nullptr; |
24 file_write = nullptr; | 25 file_write = nullptr; |
25 file_close = nullptr; | 26 file_close = nullptr; |
26 entropy_source = nullptr; | 27 entropy_source = nullptr; |
27 get_service_assets = nullptr; | 28 get_service_assets = nullptr; |
28 } | 29 } |
29 | 30 |
30 bool DartVM::Initialize(const Config& config, | 31 bool DartVM::Initialize(const Config& config, |
31 const std::vector<const char*>& flags) { | 32 const std::vector<const char*>& flags) { |
32 CHECK(dart_vm_error_ == NULL); | 33 CHECK(dart_vm_error_ == NULL); |
33 | 34 |
34 // Set the flags before calling Dart_Initialize. | 35 // Set the flags before calling Dart_Initialize. |
35 if (!Dart_SetVMFlags(flags.size(), const_cast<const char**>(flags.data()))) { | 36 if (!Dart_SetVMFlags(flags.size(), const_cast<const char**>(flags.data()))) { |
36 dart_vm_error_ = strdup("Error in Dart_SetVMFlags."); | 37 dart_vm_error_ = strdup("Error in Dart_SetVMFlags."); |
37 LOG(ERROR) << "Dart_SetVMFlags: " << dart_vm_error_; | 38 LOG(ERROR) << "Dart_SetVMFlags: " << dart_vm_error_; |
38 return false; | 39 return false; |
39 } | 40 } |
40 | 41 |
41 // Initialize debugger before calling Dart_Initialize. | 42 // Initialize debugger before calling Dart_Initialize. |
42 DartDebugger::InitDebugger(); | 43 DartDebugger::InitDebugger(); |
43 | 44 |
44 dart_vm_error_ = Dart_Initialize(config.vm_isolate_snapshot, | 45 dart_vm_error_ = Dart_Initialize(config.vm_isolate_snapshot, |
45 config.instructions_snapshot, | 46 config.instructions_snapshot, |
46 config.data_snapshot, | 47 config.data_snapshot, |
47 config.create, | 48 config.create, |
48 config.interrupt, | 49 config.interrupt, |
49 config.unhandled_exception, | 50 config.unhandled_exception, |
50 config.shutdown, | 51 config.shutdown, |
| 52 config.thread_exit, |
51 config.file_open, | 53 config.file_open, |
52 config.file_read, | 54 config.file_read, |
53 config.file_write, | 55 config.file_write, |
54 config.file_close, | 56 config.file_close, |
55 config.entropy_source, | 57 config.entropy_source, |
56 config.get_service_assets); | 58 config.get_service_assets); |
57 if (dart_vm_error_ != NULL) { | 59 if (dart_vm_error_ != NULL) { |
58 LOG(ERROR) << "Dart_Initialize: " << dart_vm_error_; | 60 LOG(ERROR) << "Dart_Initialize: " << dart_vm_error_; |
59 } | 61 } |
60 return dart_vm_error_ == NULL; | 62 return dart_vm_error_ == NULL; |
61 } | 63 } |
62 | 64 |
63 bool DartVM::Cleanup() { | 65 bool DartVM::Cleanup() { |
64 CHECK(dart_vm_error_ == NULL); | 66 CHECK(dart_vm_error_ == NULL); |
65 dart_vm_error_ = Dart_Cleanup(); | 67 dart_vm_error_ = Dart_Cleanup(); |
66 if (dart_vm_error_ != NULL) { | 68 if (dart_vm_error_ != NULL) { |
67 LOG(ERROR) << "Dart_Cleanup: " << dart_vm_error_; | 69 LOG(ERROR) << "Dart_Cleanup: " << dart_vm_error_; |
68 } | 70 } |
69 return dart_vm_error_ == NULL; | 71 return dart_vm_error_ == NULL; |
70 } | 72 } |
71 | 73 |
72 const char* DartVM::error() { | 74 const char* DartVM::error() { |
73 CHECK(dart_vm_error_ != NULL); | 75 CHECK(dart_vm_error_ != NULL); |
74 return dart_vm_error_; | 76 return dart_vm_error_; |
75 } | 77 } |
76 | 78 |
77 } // namespace tonic | 79 } // namespace tonic |
OLD | NEW |