| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BIN_ISOLATE_DATA_H_ | 5 #ifndef BIN_ISOLATE_DATA_H_ |
| 6 #define BIN_ISOLATE_DATA_H_ | 6 #define BIN_ISOLATE_DATA_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/globals.h" | 10 #include "platform/globals.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 namespace bin { | 13 namespace bin { |
| 14 | 14 |
| 15 // Forward declaration. | 15 // Forward declaration. |
| 16 class EventHandler; | 16 class EventHandler; |
| 17 class Loader; | 17 class Loader; |
| 18 | 18 |
| 19 typedef void (*ExitHook)(int64_t exit_code); |
| 20 |
| 19 // Data associated with every isolate in the standalone VM | 21 // Data associated with every isolate in the standalone VM |
| 20 // embedding. This is used to free external resources for each isolate | 22 // embedding. This is used to free external resources for each isolate |
| 21 // when the isolate shuts down. | 23 // when the isolate shuts down. |
| 22 class IsolateData { | 24 class IsolateData { |
| 23 public: | 25 public: |
| 24 IsolateData(const char* url, | 26 IsolateData(const char* url, |
| 25 const char* package_root, | 27 const char* package_root, |
| 26 const char* packages_file) | 28 const char* packages_file) |
| 27 : script_url((url != NULL) ? strdup(url) : NULL), | 29 : script_url((url != NULL) ? strdup(url) : NULL), |
| 28 package_root(NULL), | 30 package_root(NULL), |
| 29 packages_file(NULL), | 31 packages_file(NULL), |
| 30 udp_receive_buffer(NULL), | 32 udp_receive_buffer(NULL), |
| 31 builtin_lib_(NULL), | 33 builtin_lib_(NULL), |
| 32 loader_(NULL) { | 34 loader_(NULL), |
| 35 exit_hook_(NULL) { |
| 33 if (package_root != NULL) { | 36 if (package_root != NULL) { |
| 34 ASSERT(packages_file == NULL); | 37 ASSERT(packages_file == NULL); |
| 35 this->package_root = strdup(package_root); | 38 this->package_root = strdup(package_root); |
| 36 } else if (packages_file != NULL) { | 39 } else if (packages_file != NULL) { |
| 37 this->packages_file = strdup(packages_file); | 40 this->packages_file = strdup(packages_file); |
| 38 } | 41 } |
| 39 } | 42 } |
| 40 | 43 |
| 41 ~IsolateData() { | 44 ~IsolateData() { |
| 42 free(script_url); | 45 free(script_url); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 57 ASSERT(!Dart_IsError(builtin_lib_)); | 60 ASSERT(!Dart_IsError(builtin_lib_)); |
| 58 return builtin_lib_; | 61 return builtin_lib_; |
| 59 } | 62 } |
| 60 void set_builtin_lib(Dart_Handle lib) { | 63 void set_builtin_lib(Dart_Handle lib) { |
| 61 ASSERT(builtin_lib_ == NULL); | 64 ASSERT(builtin_lib_ == NULL); |
| 62 ASSERT(lib != NULL); | 65 ASSERT(lib != NULL); |
| 63 ASSERT(!Dart_IsError(lib)); | 66 ASSERT(!Dart_IsError(lib)); |
| 64 builtin_lib_ = Dart_NewPersistentHandle(lib); | 67 builtin_lib_ = Dart_NewPersistentHandle(lib); |
| 65 } | 68 } |
| 66 | 69 |
| 70 ExitHook exit_hook() const { return exit_hook_; } |
| 71 void set_exit_hook(ExitHook hook) { exit_hook_ = hook; } |
| 72 |
| 67 char* script_url; | 73 char* script_url; |
| 68 char* package_root; | 74 char* package_root; |
| 69 char* packages_file; | 75 char* packages_file; |
| 70 uint8_t* udp_receive_buffer; | 76 uint8_t* udp_receive_buffer; |
| 71 | 77 |
| 72 // While loading a loader is associated with the isolate. | 78 // While loading a loader is associated with the isolate. |
| 73 bool HasLoader() const { return loader_ != NULL; } | 79 bool HasLoader() const { return loader_ != NULL; } |
| 74 Loader* loader() const { | 80 Loader* loader() const { |
| 75 ASSERT(loader_ != NULL); | 81 ASSERT(loader_ != NULL); |
| 76 return loader_; | 82 return loader_; |
| 77 } | 83 } |
| 78 void set_loader(Loader* loader) { | 84 void set_loader(Loader* loader) { |
| 79 ASSERT((loader_ == NULL) || (loader == NULL)); | 85 ASSERT((loader_ == NULL) || (loader == NULL)); |
| 80 loader_ = loader; | 86 loader_ = loader; |
| 81 } | 87 } |
| 82 | 88 |
| 83 private: | 89 private: |
| 84 Dart_Handle builtin_lib_; | 90 Dart_Handle builtin_lib_; |
| 85 Loader* loader_; | 91 Loader* loader_; |
| 92 ExitHook exit_hook_; |
| 86 | 93 |
| 87 DISALLOW_COPY_AND_ASSIGN(IsolateData); | 94 DISALLOW_COPY_AND_ASSIGN(IsolateData); |
| 88 }; | 95 }; |
| 89 | 96 |
| 90 } // namespace bin | 97 } // namespace bin |
| 91 } // namespace dart | 98 } // namespace dart |
| 92 | 99 |
| 93 #endif // BIN_ISOLATE_DATA_H_ | 100 #endif // BIN_ISOLATE_DATA_H_ |
| OLD | NEW |