| 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 "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "platform/json.h" | 9 #include "platform/json.h" |
| 10 #include "lib/mirrors.h" | 10 #include "lib/mirrors.h" |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 599 |
| 600 // Set up specific unhandled exception handler. | 600 // Set up specific unhandled exception handler. |
| 601 const String& callback_name = String::Handle( | 601 const String& callback_name = String::Handle( |
| 602 isolate, String::New(state->exception_callback_name())); | 602 isolate, String::New(state->exception_callback_name())); |
| 603 isolate->object_store()-> | 603 isolate->object_store()-> |
| 604 set_unhandled_exception_handler(callback_name); | 604 set_unhandled_exception_handler(callback_name); |
| 605 | 605 |
| 606 Object& result = Object::Handle(); | 606 Object& result = Object::Handle(); |
| 607 result = state->ResolveFunction(); | 607 result = state->ResolveFunction(); |
| 608 bool is_spawn_uri = state->is_spawn_uri(); | 608 bool is_spawn_uri = state->is_spawn_uri(); |
| 609 | |
| 610 Instance& entryFunc = Instance::Handle(isolate); | |
| 611 if (result.IsError()) { | 609 if (result.IsError()) { |
| 612 if (is_spawn_uri) { | 610 StoreError(isolate, result); |
| 613 // Report failure to look up "main" in isolate when we have a | 611 return false; |
| 614 // port to reply it to. | |
| 615 entryFunc ^= Object::null_instance().raw(); | |
| 616 } else { | |
| 617 StoreError(isolate, result); | |
| 618 return false; | |
| 619 } | |
| 620 } else { | |
| 621 ASSERT(result.IsFunction()); | |
| 622 Function& function = Function::Handle(isolate); | |
| 623 function ^= result.raw(); | |
| 624 function = function.ImplicitClosureFunction(); | |
| 625 entryFunc ^= function.ImplicitStaticClosure(); | |
| 626 } | 612 } |
| 613 ASSERT(result.IsFunction()); |
| 614 Function& func = Function::Handle(isolate); |
| 615 func ^= result.raw(); |
| 616 func = func.ImplicitClosureFunction(); |
| 627 | 617 |
| 628 // Instead of directly invoking the entry point we call '_startIsolate' with | 618 // Instead of directly invoking the entry point we call '_startIsolate' with |
| 629 // the entry point as argument. The '_startIsolate' function will | 619 // the entry point as argument. The '_startIsolate' function will |
| 630 // communicate with the spawner to receive the initial message before it | 620 // communicate with the spawner to receive the initial message before it |
| 631 // executes the real entry point. | 621 // executes the real entry point. |
| 632 // Since this function ("RunIsolate") is used for both Isolate.spawn and | 622 // Since this function ("RunIsolate") is used for both Isolate.spawn and |
| 633 // Isolate.spawnUri we also send a boolean flag as argument so that the | 623 // Isolate.spawnUri we also send a boolean flag as argument so that the |
| 634 // "_startIsolate" function can act corresponding to how the isolate was | 624 // "_startIsolate" function can act corresponding to how the isolate was |
| 635 // created. | 625 // created. |
| 636 const Array& args = Array::Handle(Array::New(2)); | 626 const Array& args = Array::Handle(Array::New(2)); |
| 637 args.SetAt(0, entryFunc); | 627 args.SetAt(0, Instance::Handle(func.ImplicitStaticClosure())); |
| 638 args.SetAt(1, is_spawn_uri ? Bool::True() : Bool::False()); | 628 args.SetAt(1, is_spawn_uri ? Bool::True() : Bool::False()); |
| 639 | 629 |
| 640 const Library& lib = Library::Handle(Library::IsolateLibrary()); | 630 const Library& lib = Library::Handle(Library::IsolateLibrary()); |
| 641 const String& entry_name = String::Handle(String::New("_startIsolate")); | 631 const String& entry_name = String::Handle(String::New("_startIsolate")); |
| 642 const Function& entry_point = | 632 const Function& entry_point = |
| 643 Function::Handle(lib.LookupLocalFunction(entry_name)); | 633 Function::Handle(lib.LookupLocalFunction(entry_name)); |
| 644 ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); | 634 ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); |
| 645 | 635 |
| 646 result = DartEntry::InvokeFunction(entry_point, args); | 636 result = DartEntry::InvokeFunction(entry_point, args); |
| 647 if (result.IsError()) { | 637 if (result.IsError()) { |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 return func.raw(); | 1231 return func.raw(); |
| 1242 } | 1232 } |
| 1243 | 1233 |
| 1244 | 1234 |
| 1245 void IsolateSpawnState::Cleanup() { | 1235 void IsolateSpawnState::Cleanup() { |
| 1246 SwitchIsolateScope switch_scope(isolate()); | 1236 SwitchIsolateScope switch_scope(isolate()); |
| 1247 Dart::ShutdownIsolate(); | 1237 Dart::ShutdownIsolate(); |
| 1248 } | 1238 } |
| 1249 | 1239 |
| 1250 } // namespace dart | 1240 } // namespace dart |
| OLD | NEW |