OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 | 5 |
6 #include "bin/loader.h" | 6 #include "bin/loader.h" |
7 | 7 |
8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
10 #include "bin/extensions.h" | 10 #include "bin/extensions.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 ASSERT(isolate_data_ != NULL); | 30 ASSERT(isolate_data_ != NULL); |
31 port_ = Dart_NewNativePort("Loader", | 31 port_ = Dart_NewNativePort("Loader", |
32 Loader::NativeMessageHandler, | 32 Loader::NativeMessageHandler, |
33 false); | 33 false); |
34 isolate_data_->set_loader(this); | 34 isolate_data_->set_loader(this); |
35 AddLoader(port_, isolate_data_); | 35 AddLoader(port_, isolate_data_); |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 Loader::~Loader() { | 39 Loader::~Loader() { |
| 40 ASSERT(port_ != ILLEGAL_PORT); |
| 41 // Enter the monitor while we close the Dart port. After the Dart port is |
| 42 // closed, no more results can be queued. |
40 monitor_->Enter(); | 43 monitor_->Enter(); |
41 ASSERT(port_ != ILLEGAL_PORT); | |
42 Dart_CloseNativePort(port_); | 44 Dart_CloseNativePort(port_); |
| 45 monitor_->Exit(); |
43 RemoveLoader(port_); | 46 RemoveLoader(port_); |
44 monitor_->Exit(); | |
45 port_ = ILLEGAL_PORT; | 47 port_ = ILLEGAL_PORT; |
46 isolate_data_->set_loader(NULL); | 48 isolate_data_->set_loader(NULL); |
47 isolate_data_ = NULL; | 49 isolate_data_ = NULL; |
48 delete monitor_; | 50 delete monitor_; |
49 monitor_ = NULL; | 51 monitor_ = NULL; |
50 for (intptr_t i = 0; i < results_length_; i++) { | 52 for (intptr_t i = 0; i < results_length_; i++) { |
51 results_[i].Cleanup(); | 53 results_[i].Cleanup(); |
52 } | 54 } |
53 free(results_); | 55 free(results_); |
54 results_ = NULL; | 56 results_ = NULL; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 313 |
312 static bool IsWindowsHost() { | 314 static bool IsWindowsHost() { |
313 #if defined(TARGET_OS_WINDOWS) | 315 #if defined(TARGET_OS_WINDOWS) |
314 return true; | 316 return true; |
315 #else // defined(TARGET_OS_WINDOWS) | 317 #else // defined(TARGET_OS_WINDOWS) |
316 return false; | 318 return false; |
317 #endif // defined(TARGET_OS_WINDOWS) | 319 #endif // defined(TARGET_OS_WINDOWS) |
318 } | 320 } |
319 | 321 |
320 | 322 |
| 323 void Loader::InitForSnapshot(const char* snapshot_uri) { |
| 324 IsolateData* isolate_data = |
| 325 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
| 326 ASSERT(isolate_data != NULL); |
| 327 ASSERT(!isolate_data->HasLoader()); |
| 328 // Setup a loader. The constructor does a bunch of leg work. |
| 329 Loader* loader = new Loader(isolate_data); |
| 330 // Send the init message. |
| 331 loader->Init(isolate_data->package_root, |
| 332 isolate_data->packages_file, |
| 333 DartUtils::original_working_directory, |
| 334 snapshot_uri); |
| 335 // Destroy the loader. The destructor does a bunch of leg work. |
| 336 delete loader; |
| 337 } |
| 338 |
| 339 |
321 Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag, | 340 Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag, |
322 Dart_Handle library, | 341 Dart_Handle library, |
323 Dart_Handle url) { | 342 Dart_Handle url) { |
324 if (tag == Dart_kCanonicalizeUrl) { | 343 if (tag == Dart_kCanonicalizeUrl) { |
325 return Dart_DefaultCanonicalizeUrl(library, url); | 344 return Dart_DefaultCanonicalizeUrl(library, url); |
326 } | 345 } |
327 const char* url_string = NULL; | 346 const char* url_string = NULL; |
328 Dart_Handle result = Dart_StringToCString(url, &url_string); | 347 Dart_Handle result = Dart_StringToCString(url, &url_string); |
329 if (Dart_IsError(result)) { | 348 if (Dart_IsError(result)) { |
330 return result; | 349 return result; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 MutexLocker ml(&loader_infos_lock_); | 576 MutexLocker ml(&loader_infos_lock_); |
558 Loader* loader = LoaderForLocked(dest_port_id); | 577 Loader* loader = LoaderForLocked(dest_port_id); |
559 if (loader == NULL) { | 578 if (loader == NULL) { |
560 return; | 579 return; |
561 } | 580 } |
562 loader->QueueMessage(message); | 581 loader->QueueMessage(message); |
563 } | 582 } |
564 | 583 |
565 } // namespace bin | 584 } // namespace bin |
566 } // namespace dart | 585 } // namespace dart |
OLD | NEW |