OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "vm/isolate.h" | 5 #include "vm/isolate.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/text_buffer.h" | 10 #include "platform/text_buffer.h" |
(...skipping 2338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 size_t len = strlen(chars); | 2349 size_t len = strlen(chars); |
2350 char* mem = new char[len + 1]; | 2350 char* mem = new char[len + 1]; |
2351 memmove(mem, chars, len + 1); | 2351 memmove(mem, chars, len + 1); |
2352 return mem; | 2352 return mem; |
2353 } | 2353 } |
2354 | 2354 |
2355 | 2355 |
2356 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, | 2356 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, |
2357 Dart_Port origin_id, | 2357 Dart_Port origin_id, |
2358 void* init_data, | 2358 void* init_data, |
| 2359 const char* script_url, |
2359 const Function& func, | 2360 const Function& func, |
2360 const Instance& message, | 2361 const Instance& message, |
2361 Monitor* spawn_count_monitor, | 2362 Monitor* spawn_count_monitor, |
2362 intptr_t* spawn_count, | 2363 intptr_t* spawn_count, |
| 2364 const char* package_root, |
| 2365 const char* package_config, |
2363 bool paused, | 2366 bool paused, |
2364 bool errors_are_fatal, | 2367 bool errors_are_fatal, |
2365 Dart_Port on_exit_port, | 2368 Dart_Port on_exit_port, |
2366 Dart_Port on_error_port) | 2369 Dart_Port on_error_port) |
2367 : isolate_(NULL), | 2370 : isolate_(NULL), |
2368 parent_port_(parent_port), | 2371 parent_port_(parent_port), |
2369 origin_id_(origin_id), | 2372 origin_id_(origin_id), |
2370 init_data_(init_data), | 2373 init_data_(init_data), |
2371 on_exit_port_(on_exit_port), | 2374 on_exit_port_(on_exit_port), |
2372 on_error_port_(on_error_port), | 2375 on_error_port_(on_error_port), |
2373 script_url_(NULL), | 2376 script_url_(script_url), |
2374 package_root_(NULL), | 2377 package_root_(package_root), |
2375 package_map_(NULL), | 2378 package_config_(package_config), |
2376 library_url_(NULL), | 2379 library_url_(NULL), |
2377 class_name_(NULL), | 2380 class_name_(NULL), |
2378 function_name_(NULL), | 2381 function_name_(NULL), |
2379 serialized_args_(NULL), | 2382 serialized_args_(NULL), |
2380 serialized_args_len_(0), | 2383 serialized_args_len_(0), |
2381 serialized_message_(NULL), | 2384 serialized_message_(NULL), |
2382 serialized_message_len_(0), | 2385 serialized_message_len_(0), |
2383 spawn_count_monitor_(spawn_count_monitor), | 2386 spawn_count_monitor_(spawn_count_monitor), |
2384 spawn_count_(spawn_count), | 2387 spawn_count_(spawn_count), |
2385 isolate_flags_(), | 2388 isolate_flags_(), |
(...skipping 17 matching lines...) Expand all Loading... |
2403 can_send_any_object); | 2406 can_send_any_object); |
2404 // Inherit flags from spawning isolate. | 2407 // Inherit flags from spawning isolate. |
2405 isolate_flags()->CopyFrom(Isolate::Current()->flags()); | 2408 isolate_flags()->CopyFrom(Isolate::Current()->flags()); |
2406 } | 2409 } |
2407 | 2410 |
2408 | 2411 |
2409 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, | 2412 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, |
2410 void* init_data, | 2413 void* init_data, |
2411 const char* script_url, | 2414 const char* script_url, |
2412 const char* package_root, | 2415 const char* package_root, |
2413 const char** package_map, | 2416 const char* package_config, |
2414 const Instance& args, | 2417 const Instance& args, |
2415 const Instance& message, | 2418 const Instance& message, |
2416 Monitor* spawn_count_monitor, | 2419 Monitor* spawn_count_monitor, |
2417 intptr_t* spawn_count, | 2420 intptr_t* spawn_count, |
2418 bool paused, | 2421 bool paused, |
2419 bool errors_are_fatal, | 2422 bool errors_are_fatal, |
2420 Dart_Port on_exit_port, | 2423 Dart_Port on_exit_port, |
2421 Dart_Port on_error_port) | 2424 Dart_Port on_error_port) |
2422 : isolate_(NULL), | 2425 : isolate_(NULL), |
2423 parent_port_(parent_port), | 2426 parent_port_(parent_port), |
2424 origin_id_(ILLEGAL_PORT), | 2427 origin_id_(ILLEGAL_PORT), |
2425 init_data_(init_data), | 2428 init_data_(init_data), |
2426 on_exit_port_(on_exit_port), | 2429 on_exit_port_(on_exit_port), |
2427 on_error_port_(on_error_port), | 2430 on_error_port_(on_error_port), |
2428 script_url_(script_url), | 2431 script_url_(script_url), |
2429 package_root_(package_root), | 2432 package_root_(package_root), |
2430 package_map_(package_map), | 2433 package_config_(package_config), |
2431 library_url_(NULL), | 2434 library_url_(NULL), |
2432 class_name_(NULL), | 2435 class_name_(NULL), |
2433 function_name_(NULL), | 2436 function_name_(NULL), |
2434 serialized_args_(NULL), | 2437 serialized_args_(NULL), |
2435 serialized_args_len_(0), | 2438 serialized_args_len_(0), |
2436 serialized_message_(NULL), | 2439 serialized_message_(NULL), |
2437 serialized_message_len_(0), | 2440 serialized_message_len_(0), |
2438 spawn_count_monitor_(spawn_count_monitor), | 2441 spawn_count_monitor_(spawn_count_monitor), |
2439 spawn_count_(spawn_count), | 2442 spawn_count_(spawn_count), |
2440 isolate_flags_(), | 2443 isolate_flags_(), |
(...skipping 11 matching lines...) Expand all Loading... |
2452 can_send_any_object); | 2455 can_send_any_object); |
2453 // By default inherit flags from spawning isolate. These can be overridden | 2456 // By default inherit flags from spawning isolate. These can be overridden |
2454 // from the calling code. | 2457 // from the calling code. |
2455 isolate_flags()->CopyFrom(Isolate::Current()->flags()); | 2458 isolate_flags()->CopyFrom(Isolate::Current()->flags()); |
2456 } | 2459 } |
2457 | 2460 |
2458 | 2461 |
2459 IsolateSpawnState::~IsolateSpawnState() { | 2462 IsolateSpawnState::~IsolateSpawnState() { |
2460 delete[] script_url_; | 2463 delete[] script_url_; |
2461 delete[] package_root_; | 2464 delete[] package_root_; |
2462 for (int i = 0; package_map_ != NULL; i++) { | 2465 delete[] package_config_; |
2463 if (package_map_[i] != NULL) { | |
2464 delete[] package_map_[i]; | |
2465 } else { | |
2466 delete[] package_map_; | |
2467 package_map_ = NULL; | |
2468 } | |
2469 } | |
2470 delete[] library_url_; | 2466 delete[] library_url_; |
2471 delete[] class_name_; | 2467 delete[] class_name_; |
2472 delete[] function_name_; | 2468 delete[] function_name_; |
2473 free(serialized_args_); | 2469 free(serialized_args_); |
2474 free(serialized_message_); | 2470 free(serialized_message_); |
2475 } | 2471 } |
2476 | 2472 |
2477 | 2473 |
2478 RawObject* IsolateSpawnState::ResolveFunction() { | 2474 RawObject* IsolateSpawnState::ResolveFunction() { |
2479 const String& func_name = String::Handle(String::New(function_name())); | 2475 const String& func_name = String::Handle(String::New(function_name())); |
(...skipping 12 matching lines...) Expand all Loading... |
2492 } | 2488 } |
2493 if (func.IsNull()) { | 2489 if (func.IsNull()) { |
2494 const String& msg = String::Handle(String::NewFormatted( | 2490 const String& msg = String::Handle(String::NewFormatted( |
2495 "Unable to resolve function '%s' in script '%s'.", | 2491 "Unable to resolve function '%s' in script '%s'.", |
2496 function_name(), script_url())); | 2492 function_name(), script_url())); |
2497 return LanguageError::New(msg); | 2493 return LanguageError::New(msg); |
2498 } | 2494 } |
2499 return func.raw(); | 2495 return func.raw(); |
2500 } | 2496 } |
2501 | 2497 |
2502 ASSERT(script_url() == NULL); | 2498 // Lookup the to be spawned function for the Isolate.spawn implementation. |
2503 // Resolve the library. | 2499 // Resolve the library. |
2504 const String& lib_url = String::Handle(String::New(library_url())); | 2500 const String& lib_url = String::Handle(String::New(library_url())); |
2505 const Library& lib = Library::Handle(Library::LookupLibrary(lib_url)); | 2501 const Library& lib = Library::Handle(Library::LookupLibrary(lib_url)); |
2506 if (lib.IsNull() || lib.IsError()) { | 2502 if (lib.IsNull() || lib.IsError()) { |
2507 const String& msg = String::Handle(String::NewFormatted( | 2503 const String& msg = String::Handle(String::NewFormatted( |
2508 "Unable to find library '%s'.", library_url())); | 2504 "Unable to find library '%s'.", library_url())); |
2509 return LanguageError::New(msg); | 2505 return LanguageError::New(msg); |
2510 } | 2506 } |
2511 | 2507 |
2512 // Resolve the function. | 2508 // Resolve the function. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2557 void IsolateSpawnState::DecrementSpawnCount() { | 2553 void IsolateSpawnState::DecrementSpawnCount() { |
2558 ASSERT(spawn_count_monitor_ != NULL); | 2554 ASSERT(spawn_count_monitor_ != NULL); |
2559 ASSERT(spawn_count_ != NULL); | 2555 ASSERT(spawn_count_ != NULL); |
2560 MonitorLocker ml(spawn_count_monitor_); | 2556 MonitorLocker ml(spawn_count_monitor_); |
2561 ASSERT(*spawn_count_ > 0); | 2557 ASSERT(*spawn_count_ > 0); |
2562 *spawn_count_ = *spawn_count_ - 1; | 2558 *spawn_count_ = *spawn_count_ - 1; |
2563 ml.Notify(); | 2559 ml.Notify(); |
2564 } | 2560 } |
2565 | 2561 |
2566 } // namespace dart | 2562 } // namespace dart |
OLD | NEW |