| 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 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 namespace bin { | 14 namespace bin { |
| 15 | 15 |
| 16 // Forward declaration. | 16 // Forward declaration. |
| 17 class EventHandler; | 17 class EventHandler; |
| 18 | 18 |
| 19 // Data associated with every isolate in the standalone VM | 19 // Data associated with every isolate in the standalone VM |
| 20 // embedding. This is used to free external resources for each isolate | 20 // embedding. This is used to free external resources for each isolate |
| 21 // when the isolate shuts down. | 21 // when the isolate shuts down. |
| 22 class IsolateData { | 22 class IsolateData { |
| 23 public: | 23 public: |
| 24 IsolateData(const char* url, | 24 IsolateData(const char* url, |
| 25 const char* package_root, | 25 const char* package_root, |
| 26 const char* packages_file) | 26 const char* packages_file) |
| 27 : script_url(strdup(url)), | 27 : script_url((url != NULL) ? strdup(url) : NULL), |
| 28 package_root(NULL), | 28 package_root(NULL), |
| 29 packages_file(NULL), | 29 packages_file(NULL), |
| 30 udp_receive_buffer(NULL), | 30 udp_receive_buffer(NULL), |
| 31 load_async_id(-1) { | 31 load_async_id(-1), |
| 32 builtin_lib_(NULL) { |
| 32 if (package_root != NULL) { | 33 if (package_root != NULL) { |
| 33 ASSERT(packages_file == NULL); | 34 ASSERT(packages_file == NULL); |
| 34 this->package_root = strdup(package_root); | 35 this->package_root = strdup(package_root); |
| 35 } else if (packages_file != NULL) { | 36 } else if (packages_file != NULL) { |
| 36 this->packages_file = strdup(packages_file); | 37 this->packages_file = strdup(packages_file); |
| 37 } | 38 } |
| 38 } | 39 } |
| 39 | 40 |
| 40 ~IsolateData() { | 41 ~IsolateData() { |
| 41 free(script_url); | 42 free(script_url); |
| 42 script_url = NULL; | 43 script_url = NULL; |
| 43 free(package_root); | 44 free(package_root); |
| 44 package_root = NULL; | 45 package_root = NULL; |
| 45 free(packages_file); | 46 free(packages_file); |
| 46 packages_file = NULL; | 47 packages_file = NULL; |
| 47 free(udp_receive_buffer); | 48 free(udp_receive_buffer); |
| 48 udp_receive_buffer = NULL; | 49 udp_receive_buffer = NULL; |
| 50 if (builtin_lib_ != NULL) { |
| 51 Dart_DeletePersistentHandle(builtin_lib_); |
| 52 } |
| 53 } |
| 54 |
| 55 Dart_Handle builtin_lib() const { |
| 56 ASSERT(builtin_lib_ != NULL); |
| 57 ASSERT(!Dart_IsError(builtin_lib_)); |
| 58 return builtin_lib_; |
| 59 } |
| 60 void set_builtin_lib(Dart_Handle lib) { |
| 61 ASSERT(builtin_lib_ == NULL); |
| 62 ASSERT(lib != NULL); |
| 63 ASSERT(!Dart_IsError(lib)); |
| 64 builtin_lib_ = Dart_NewPersistentHandle(lib); |
| 49 } | 65 } |
| 50 | 66 |
| 51 char* script_url; | 67 char* script_url; |
| 52 char* package_root; | 68 char* package_root; |
| 53 char* packages_file; | 69 char* packages_file; |
| 54 uint8_t* udp_receive_buffer; | 70 uint8_t* udp_receive_buffer; |
| 55 int64_t load_async_id; | 71 int64_t load_async_id; |
| 56 | 72 |
| 57 private: | 73 private: |
| 74 Dart_Handle builtin_lib_; |
| 75 |
| 58 DISALLOW_COPY_AND_ASSIGN(IsolateData); | 76 DISALLOW_COPY_AND_ASSIGN(IsolateData); |
| 59 }; | 77 }; |
| 60 | 78 |
| 61 } // namespace bin | 79 } // namespace bin |
| 62 } // namespace dart | 80 } // namespace dart |
| 63 | 81 |
| 64 #endif // BIN_ISOLATE_DATA_H_ | 82 #endif // BIN_ISOLATE_DATA_H_ |
| OLD | NEW |