| 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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 | 584 |
| 585 // Set up specific unhandled exception handler. | 585 // Set up specific unhandled exception handler. |
| 586 const String& callback_name = String::Handle( | 586 const String& callback_name = String::Handle( |
| 587 isolate, String::New(state->exception_callback_name())); | 587 isolate, String::New(state->exception_callback_name())); |
| 588 isolate->object_store()-> | 588 isolate->object_store()-> |
| 589 set_unhandled_exception_handler(callback_name); | 589 set_unhandled_exception_handler(callback_name); |
| 590 | 590 |
| 591 Object& result = Object::Handle(); | 591 Object& result = Object::Handle(); |
| 592 result = state->ResolveFunction(); | 592 result = state->ResolveFunction(); |
| 593 bool is_spawn_uri = state->is_spawn_uri(); | 593 bool is_spawn_uri = state->is_spawn_uri(); |
| 594 |
| 595 Instance& entryFunc = Instance::Handle(isolate); |
| 594 if (result.IsError()) { | 596 if (result.IsError()) { |
| 595 StoreError(isolate, result); | 597 if (is_spawn_uri) { |
| 596 return false; | 598 // Report failure to look up "main" in isolate when we have a |
| 599 // port to reply it to. |
| 600 entryFunc ^= Object::null_instance().raw(); |
| 601 } else { |
| 602 StoreError(isolate, result); |
| 603 return false; |
| 604 } |
| 605 } else { |
| 606 ASSERT(result.IsFunction()); |
| 607 Function& function = Function::Handle(isolate); |
| 608 function ^= result.raw(); |
| 609 function = function.ImplicitClosureFunction(); |
| 610 entryFunc ^= function.ImplicitStaticClosure(); |
| 597 } | 611 } |
| 598 ASSERT(result.IsFunction()); | |
| 599 Function& func = Function::Handle(isolate); | |
| 600 func ^= result.raw(); | |
| 601 func = func.ImplicitClosureFunction(); | |
| 602 | 612 |
| 603 // Instead of directly invoking the entry point we call '_startIsolate' with | 613 // Instead of directly invoking the entry point we call '_startIsolate' with |
| 604 // the entry point as argument. The '_startIsolate' function will | 614 // the entry point as argument. The '_startIsolate' function will |
| 605 // communicate with the spawner to receive the initial message before it | 615 // communicate with the spawner to receive the initial message before it |
| 606 // executes the real entry point. | 616 // executes the real entry point. |
| 607 // Since this function ("RunIsolate") is used for both Isolate.spawn and | 617 // Since this function ("RunIsolate") is used for both Isolate.spawn and |
| 608 // Isolate.spawnUri we also send a boolean flag as argument so that the | 618 // Isolate.spawnUri we also send a boolean flag as argument so that the |
| 609 // "_startIsolate" function can act corresponding to how the isolate was | 619 // "_startIsolate" function can act corresponding to how the isolate was |
| 610 // created. | 620 // created. |
| 611 const Array& args = Array::Handle(Array::New(2)); | 621 const Array& args = Array::Handle(Array::New(2)); |
| 612 args.SetAt(0, Instance::Handle(func.ImplicitStaticClosure())); | 622 args.SetAt(0, entryFunc); |
| 613 args.SetAt(1, is_spawn_uri ? Bool::True() : Bool::False()); | 623 args.SetAt(1, is_spawn_uri ? Bool::True() : Bool::False()); |
| 614 | 624 |
| 615 const Library& lib = Library::Handle(Library::IsolateLibrary()); | 625 const Library& lib = Library::Handle(Library::IsolateLibrary()); |
| 616 const String& entry_name = String::Handle(String::New("_startIsolate")); | 626 const String& entry_name = String::Handle(String::New("_startIsolate")); |
| 617 const Function& entry_point = | 627 const Function& entry_point = |
| 618 Function::Handle(lib.LookupLocalFunction(entry_name)); | 628 Function::Handle(lib.LookupLocalFunction(entry_name)); |
| 619 ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); | 629 ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); |
| 620 | 630 |
| 621 result = DartEntry::InvokeFunction(entry_point, args); | 631 result = DartEntry::InvokeFunction(entry_point, args); |
| 622 if (result.IsError()) { | 632 if (result.IsError()) { |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 return func.raw(); | 1207 return func.raw(); |
| 1198 } | 1208 } |
| 1199 | 1209 |
| 1200 | 1210 |
| 1201 void IsolateSpawnState::Cleanup() { | 1211 void IsolateSpawnState::Cleanup() { |
| 1202 SwitchIsolateScope switch_scope(isolate()); | 1212 SwitchIsolateScope switch_scope(isolate()); |
| 1203 Dart::ShutdownIsolate(); | 1213 Dart::ShutdownIsolate(); |
| 1204 } | 1214 } |
| 1205 | 1215 |
| 1206 } // namespace dart | 1216 } // namespace dart |
| OLD | NEW |