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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 } | 503 } |
504 | 504 |
505 // Set up specific unhandled exception handler. | 505 // Set up specific unhandled exception handler. |
506 const String& callback_name = String::Handle( | 506 const String& callback_name = String::Handle( |
507 isolate, String::New(state->exception_callback_name())); | 507 isolate, String::New(state->exception_callback_name())); |
508 isolate->object_store()-> | 508 isolate->object_store()-> |
509 set_unhandled_exception_handler(callback_name); | 509 set_unhandled_exception_handler(callback_name); |
510 | 510 |
511 Object& result = Object::Handle(); | 511 Object& result = Object::Handle(); |
512 result = state->ResolveFunction(); | 512 result = state->ResolveFunction(); |
| 513 bool is_spawn_uri = state->is_spawn_uri(); |
513 delete state; | 514 delete state; |
514 state = NULL; | 515 state = NULL; |
515 if (result.IsError()) { | 516 if (result.IsError()) { |
516 StoreError(isolate, result); | 517 StoreError(isolate, result); |
517 return false; | 518 return false; |
518 } | 519 } |
519 ASSERT(result.IsFunction()); | 520 ASSERT(result.IsFunction()); |
520 Function& func = Function::Handle(isolate); | 521 Function& func = Function::Handle(isolate); |
521 func ^= result.raw(); | 522 func ^= result.raw(); |
522 result = DartEntry::InvokeFunction(func, Object::empty_array()); | 523 func = func.ImplicitClosureFunction(); |
| 524 |
| 525 // Instead of directly invoking the entry point we call '_startIsolate' with |
| 526 // the entry point as argument. The '_startIsolate' function will |
| 527 // communicate with the spawner to receive the initial message before it |
| 528 // executes the real entry point. |
| 529 // Since this function ("RunIsolate") is used for both Isolate.spawn and |
| 530 // Isolate.spawnUri we also send a boolean flag as argument so that the |
| 531 // "_startIsolate" function can act corresponding to how the isolate was |
| 532 // created. |
| 533 const Array& args = Array::Handle(Array::New(2)); |
| 534 args.SetAt(0, Instance::Handle(func.ImplicitStaticClosure())); |
| 535 args.SetAt(1, is_spawn_uri ? Bool::True() : Bool::False()); |
| 536 |
| 537 const Library& lib = Library::Handle(Library::IsolateLibrary()); |
| 538 const String& entry_name = String::Handle(String::New("_startIsolate")); |
| 539 const Function& entry_point = |
| 540 Function::Handle(lib.LookupLocalFunction(entry_name)); |
| 541 ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); |
| 542 |
| 543 result = DartEntry::InvokeFunction(entry_point, args); |
523 if (result.IsError()) { | 544 if (result.IsError()) { |
524 StoreError(isolate, result); | 545 StoreError(isolate, result); |
525 return false; | 546 return false; |
526 } | 547 } |
527 } | 548 } |
528 return true; | 549 return true; |
529 } | 550 } |
530 | 551 |
531 | 552 |
532 static void ShutdownIsolate(uword parameter) { | 553 static void ShutdownIsolate(uword parameter) { |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 982 |
962 | 983 |
963 template<class T> | 984 template<class T> |
964 T* Isolate::AllocateReusableHandle() { | 985 T* Isolate::AllocateReusableHandle() { |
965 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); | 986 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); |
966 T::initializeHandle(handle, T::null()); | 987 T::initializeHandle(handle, T::null()); |
967 return handle; | 988 return handle; |
968 } | 989 } |
969 | 990 |
970 | 991 |
971 IsolateSpawnState::IsolateSpawnState(const Function& func, | 992 IsolateSpawnState::IsolateSpawnState(const Function& func) |
972 const Function& callback_func) | |
973 : isolate_(NULL), | 993 : isolate_(NULL), |
974 script_url_(NULL), | 994 script_url_(NULL), |
975 library_url_(NULL), | 995 library_url_(NULL), |
976 function_name_(NULL), | 996 function_name_(NULL), |
977 exception_callback_name_(NULL) { | 997 exception_callback_name_(NULL) { |
978 script_url_ = NULL; | 998 script_url_ = NULL; |
979 const Class& cls = Class::Handle(func.Owner()); | 999 const Class& cls = Class::Handle(func.Owner()); |
980 ASSERT(cls.IsTopLevel()); | 1000 ASSERT(cls.IsTopLevel()); |
981 const Library& lib = Library::Handle(cls.library()); | 1001 const Library& lib = Library::Handle(cls.library()); |
982 const String& lib_url = String::Handle(lib.url()); | 1002 const String& lib_url = String::Handle(lib.url()); |
983 library_url_ = strdup(lib_url.ToCString()); | 1003 library_url_ = strdup(lib_url.ToCString()); |
984 | 1004 |
985 const String& func_name = String::Handle(func.name()); | 1005 const String& func_name = String::Handle(func.name()); |
986 function_name_ = strdup(func_name.ToCString()); | 1006 function_name_ = strdup(func_name.ToCString()); |
987 if (!callback_func.IsNull()) { | 1007 exception_callback_name_ = strdup("_unhandledExceptionCallback"); |
988 const String& callback_name = String::Handle(callback_func.name()); | |
989 exception_callback_name_ = strdup(callback_name.ToCString()); | |
990 } else { | |
991 exception_callback_name_ = strdup("_unhandledExceptionCallback"); | |
992 } | |
993 } | 1008 } |
994 | 1009 |
995 | 1010 |
996 IsolateSpawnState::IsolateSpawnState(const char* script_url) | 1011 IsolateSpawnState::IsolateSpawnState(const char* script_url) |
997 : isolate_(NULL), | 1012 : isolate_(NULL), |
998 library_url_(NULL), | 1013 library_url_(NULL), |
999 function_name_(NULL), | 1014 function_name_(NULL), |
1000 exception_callback_name_(NULL) { | 1015 exception_callback_name_(NULL) { |
1001 script_url_ = strdup(script_url); | 1016 script_url_ = strdup(script_url); |
1002 library_url_ = NULL; | 1017 library_url_ = NULL; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 return func.raw(); | 1057 return func.raw(); |
1043 } | 1058 } |
1044 | 1059 |
1045 | 1060 |
1046 void IsolateSpawnState::Cleanup() { | 1061 void IsolateSpawnState::Cleanup() { |
1047 SwitchIsolateScope switch_scope(isolate()); | 1062 SwitchIsolateScope switch_scope(isolate()); |
1048 Dart::ShutdownIsolate(); | 1063 Dart::ShutdownIsolate(); |
1049 } | 1064 } |
1050 | 1065 |
1051 } // namespace dart | 1066 } // namespace dart |
OLD | NEW |