Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: runtime/vm/isolate.cc

Issue 1403693002: - Implement package map parameter when spawning isolate. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address review comments. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/service_isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/json.h" 10 #include "platform/json.h"
(...skipping 2388 matching lines...) Expand 10 before | Expand all | Expand 10 after
2399 MessageSnapshotReader reader(obj_data, obj_len, thread); 2399 MessageSnapshotReader reader(obj_data, obj_len, thread);
2400 Zone* zone = thread->zone(); 2400 Zone* zone = thread->zone();
2401 const Object& obj = Object::Handle(zone, reader.ReadObject()); 2401 const Object& obj = Object::Handle(zone, reader.ReadObject());
2402 ASSERT(!obj.IsError()); 2402 ASSERT(!obj.IsError());
2403 Instance& instance = Instance::Handle(zone); 2403 Instance& instance = Instance::Handle(zone);
2404 instance ^= obj.raw(); // Can't use Instance::Cast because may be null. 2404 instance ^= obj.raw(); // Can't use Instance::Cast because may be null.
2405 return instance.raw(); 2405 return instance.raw();
2406 } 2406 }
2407 2407
2408 2408
2409 static const char* NewConstChar(const char* chars) {
2410 size_t len = strlen(chars);
2411 char* mem = new char[len + 1];
2412 memmove(mem, chars, len + 1);
2413 return mem;
2414 }
2415
2416
2409 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, 2417 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port,
2410 const Function& func, 2418 const Function& func,
2411 const Instance& message, 2419 const Instance& message,
2412 bool paused, 2420 bool paused,
2413 bool errors_are_fatal, 2421 bool errors_are_fatal,
2414 Dart_Port on_exit_port, 2422 Dart_Port on_exit_port,
2415 Dart_Port on_error_port) 2423 Dart_Port on_error_port)
2416 : isolate_(NULL), 2424 : isolate_(NULL),
2417 parent_port_(parent_port), 2425 parent_port_(parent_port),
2418 on_exit_port_(on_exit_port), 2426 on_exit_port_(on_exit_port),
2419 on_error_port_(on_error_port), 2427 on_error_port_(on_error_port),
2420 script_url_(NULL), 2428 script_url_(NULL),
2421 package_root_(NULL), 2429 package_root_(NULL),
2430 package_map_(NULL),
2422 library_url_(NULL), 2431 library_url_(NULL),
2423 class_name_(NULL), 2432 class_name_(NULL),
2424 function_name_(NULL), 2433 function_name_(NULL),
2425 serialized_args_(NULL), 2434 serialized_args_(NULL),
2426 serialized_args_len_(0), 2435 serialized_args_len_(0),
2427 serialized_message_(NULL), 2436 serialized_message_(NULL),
2428 serialized_message_len_(0), 2437 serialized_message_len_(0),
2429 isolate_flags_(), 2438 isolate_flags_(),
2430 paused_(paused), 2439 paused_(paused),
2431 errors_are_fatal_(errors_are_fatal) { 2440 errors_are_fatal_(errors_are_fatal) {
2432 script_url_ = NULL;
2433 const Class& cls = Class::Handle(func.Owner()); 2441 const Class& cls = Class::Handle(func.Owner());
2434 const Library& lib = Library::Handle(cls.library()); 2442 const Library& lib = Library::Handle(cls.library());
2435 const String& lib_url = String::Handle(lib.url()); 2443 const String& lib_url = String::Handle(lib.url());
2436 library_url_ = strdup(lib_url.ToCString()); 2444 library_url_ = NewConstChar(lib_url.ToCString());
2437 2445
2438 const String& func_name = String::Handle(func.name()); 2446 const String& func_name = String::Handle(func.name());
2439 function_name_ = strdup(func_name.ToCString()); 2447 function_name_ = NewConstChar(func_name.ToCString());
2440 if (!cls.IsTopLevel()) { 2448 if (!cls.IsTopLevel()) {
2441 const String& class_name = String::Handle(cls.Name()); 2449 const String& class_name = String::Handle(cls.Name());
2442 class_name_ = strdup(class_name.ToCString()); 2450 class_name_ = NewConstChar(class_name.ToCString());
2443 } 2451 }
2444 bool can_send_any_object = true; 2452 bool can_send_any_object = true;
2445 SerializeObject(message, 2453 SerializeObject(message,
2446 &serialized_message_, 2454 &serialized_message_,
2447 &serialized_message_len_, 2455 &serialized_message_len_,
2448 can_send_any_object); 2456 can_send_any_object);
2449 // Inherit flags from spawning isolate. 2457 // Inherit flags from spawning isolate.
2450 isolate_flags()->CopyFrom(Isolate::Current()->flags()); 2458 isolate_flags()->CopyFrom(Isolate::Current()->flags());
2451 } 2459 }
2452 2460
2453 2461
2454 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, 2462 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port,
2455 const char* script_url, 2463 const char* script_url,
2456 const char* package_root, 2464 const char* package_root,
2465 const char** package_map,
2457 const Instance& args, 2466 const Instance& args,
2458 const Instance& message, 2467 const Instance& message,
2459 bool paused, 2468 bool paused,
2460 bool errors_are_fatal, 2469 bool errors_are_fatal,
2461 Dart_Port on_exit_port, 2470 Dart_Port on_exit_port,
2462 Dart_Port on_error_port) 2471 Dart_Port on_error_port)
2463 : isolate_(NULL), 2472 : isolate_(NULL),
2464 parent_port_(parent_port), 2473 parent_port_(parent_port),
2465 on_exit_port_(on_exit_port), 2474 on_exit_port_(on_exit_port),
2466 on_error_port_(on_error_port), 2475 on_error_port_(on_error_port),
2467 package_root_(NULL), 2476 script_url_(script_url),
2477 package_root_(package_root),
2478 package_map_(package_map),
2468 library_url_(NULL), 2479 library_url_(NULL),
2469 class_name_(NULL), 2480 class_name_(NULL),
2470 function_name_(NULL), 2481 function_name_(NULL),
2471 serialized_args_(NULL), 2482 serialized_args_(NULL),
2472 serialized_args_len_(0), 2483 serialized_args_len_(0),
2473 serialized_message_(NULL), 2484 serialized_message_(NULL),
2474 serialized_message_len_(0), 2485 serialized_message_len_(0),
2475 isolate_flags_(), 2486 isolate_flags_(),
2476 paused_(paused), 2487 paused_(paused),
2477 errors_are_fatal_(errors_are_fatal) { 2488 errors_are_fatal_(errors_are_fatal) {
2478 script_url_ = strdup(script_url); 2489 function_name_ = NewConstChar("main");
2479 if (package_root != NULL) {
2480 package_root_ = strdup(package_root);
2481 }
2482 library_url_ = NULL;
2483 function_name_ = strdup("main");
2484 bool can_send_any_object = false; 2490 bool can_send_any_object = false;
2485 SerializeObject(args, 2491 SerializeObject(args,
2486 &serialized_args_, 2492 &serialized_args_,
2487 &serialized_args_len_, 2493 &serialized_args_len_,
2488 can_send_any_object); 2494 can_send_any_object);
2489 SerializeObject(message, 2495 SerializeObject(message,
2490 &serialized_message_, 2496 &serialized_message_,
2491 &serialized_message_len_, 2497 &serialized_message_len_,
2492 can_send_any_object); 2498 can_send_any_object);
2493 // By default inherit flags from spawning isolate. These can be overridden 2499 // By default inherit flags from spawning isolate. These can be overridden
2494 // from the calling code. 2500 // from the calling code.
2495 isolate_flags()->CopyFrom(Isolate::Current()->flags()); 2501 isolate_flags()->CopyFrom(Isolate::Current()->flags());
2496 } 2502 }
2497 2503
2498 2504
2499 IsolateSpawnState::~IsolateSpawnState() { 2505 IsolateSpawnState::~IsolateSpawnState() {
2500 free(script_url_); 2506 delete script_url_;
2501 free(package_root_); 2507 delete package_root_;
2502 free(library_url_); 2508 for (int i = 0; package_map_ != NULL; i++) {
2503 free(function_name_); 2509 if (package_map_[i] != NULL) {
2504 free(class_name_); 2510 delete package_map_[i];
2511 } else {
2512 delete package_map_;
2513 package_map_ = NULL;
2514 }
2515 }
2516 delete library_url_;
2517 delete class_name_;
2518 delete function_name_;
2505 free(serialized_args_); 2519 free(serialized_args_);
2506 free(serialized_message_); 2520 free(serialized_message_);
2507 } 2521 }
2508 2522
2509 2523
2510 RawObject* IsolateSpawnState::ResolveFunction() { 2524 RawObject* IsolateSpawnState::ResolveFunction() {
2511 const String& func_name = String::Handle(String::New(function_name())); 2525 const String& func_name = String::Handle(String::New(function_name()));
2512 2526
2513 if (library_url() == NULL) { 2527 if (library_url() == NULL) {
2514 // Handle spawnUri lookup rules. 2528 // Handle spawnUri lookup rules.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 serialized_message_, serialized_message_len_); 2599 serialized_message_, serialized_message_len_);
2586 } 2600 }
2587 2601
2588 2602
2589 void IsolateSpawnState::Cleanup() { 2603 void IsolateSpawnState::Cleanup() {
2590 SwitchIsolateScope switch_scope(I); 2604 SwitchIsolateScope switch_scope(I);
2591 Dart::ShutdownIsolate(); 2605 Dart::ShutdownIsolate();
2592 } 2606 }
2593 2607
2594 } // namespace dart 2608 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/service_isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698