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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 result = state->ResolveFunction(); | 512 result = state->ResolveFunction(); |
513 delete state; | 513 delete state; |
514 state = NULL; | 514 state = NULL; |
515 if (result.IsError()) { | 515 if (result.IsError()) { |
516 StoreError(isolate, result); | 516 StoreError(isolate, result); |
517 return false; | 517 return false; |
518 } | 518 } |
519 ASSERT(result.IsFunction()); | 519 ASSERT(result.IsFunction()); |
520 Function& func = Function::Handle(isolate); | 520 Function& func = Function::Handle(isolate); |
521 func ^= result.raw(); | 521 func ^= result.raw(); |
522 result = DartEntry::InvokeFunction(func, Object::empty_array()); | 522 func = func.ImplicitClosureFunction(); |
| 523 |
| 524 const Array& args = Array::Handle(Array::New(1)); |
| 525 args.SetAt(0, Instance::Handle(func.ImplicitStaticClosure())); |
| 526 |
| 527 const Library& lib = Library::Handle(Library::IsolateLibrary()); |
| 528 const String& entry_name = String::Handle(String::New("_startIsolate")); |
| 529 const Function& entry_point = |
| 530 Function::Handle(lib.LookupLocalFunction(entry_name)); |
| 531 ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); |
| 532 |
| 533 result = DartEntry::InvokeFunction(entry_point, args); |
523 if (result.IsError()) { | 534 if (result.IsError()) { |
524 StoreError(isolate, result); | 535 StoreError(isolate, result); |
525 return false; | 536 return false; |
526 } | 537 } |
527 } | 538 } |
528 return true; | 539 return true; |
529 } | 540 } |
530 | 541 |
531 | 542 |
532 static void ShutdownIsolate(uword parameter) { | 543 static void ShutdownIsolate(uword parameter) { |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 | 981 |
971 static char* GetRootScriptUri(Isolate* isolate) { | 982 static char* GetRootScriptUri(Isolate* isolate) { |
972 const Library& library = | 983 const Library& library = |
973 Library::Handle(isolate->object_store()->root_library()); | 984 Library::Handle(isolate->object_store()->root_library()); |
974 ASSERT(!library.IsNull()); | 985 ASSERT(!library.IsNull()); |
975 const String& script_name = String::Handle(library.url()); | 986 const String& script_name = String::Handle(library.url()); |
976 return isolate->current_zone()->MakeCopyOfString(script_name.ToCString()); | 987 return isolate->current_zone()->MakeCopyOfString(script_name.ToCString()); |
977 } | 988 } |
978 | 989 |
979 | 990 |
980 IsolateSpawnState::IsolateSpawnState(const Function& func, | 991 IsolateSpawnState::IsolateSpawnState(const Function& func) |
981 const Function& callback_func) | |
982 : isolate_(NULL), | 992 : isolate_(NULL), |
983 script_url_(NULL), | 993 script_url_(NULL), |
984 library_url_(NULL), | 994 library_url_(NULL), |
985 function_name_(NULL), | 995 function_name_(NULL), |
986 exception_callback_name_(NULL) { | 996 exception_callback_name_(NULL) { |
987 script_url_ = strdup(GetRootScriptUri(Isolate::Current())); | 997 script_url_ = strdup(GetRootScriptUri(Isolate::Current())); |
988 const Class& cls = Class::Handle(func.Owner()); | 998 const Class& cls = Class::Handle(func.Owner()); |
989 ASSERT(cls.IsTopLevel()); | 999 ASSERT(cls.IsTopLevel()); |
990 const Library& lib = Library::Handle(cls.library()); | 1000 const Library& lib = Library::Handle(cls.library()); |
991 const String& lib_url = String::Handle(lib.url()); | 1001 const String& lib_url = String::Handle(lib.url()); |
992 library_url_ = strdup(lib_url.ToCString()); | 1002 library_url_ = strdup(lib_url.ToCString()); |
993 | 1003 |
994 const String& func_name = String::Handle(func.name()); | 1004 const String& func_name = String::Handle(func.name()); |
995 function_name_ = strdup(func_name.ToCString()); | 1005 function_name_ = strdup(func_name.ToCString()); |
996 if (!callback_func.IsNull()) { | 1006 exception_callback_name_ = strdup("_unhandledExceptionCallback"); |
997 const String& callback_name = String::Handle(callback_func.name()); | |
998 exception_callback_name_ = strdup(callback_name.ToCString()); | |
999 } else { | |
1000 exception_callback_name_ = strdup("_unhandledExceptionCallback"); | |
1001 } | |
1002 } | 1007 } |
1003 | 1008 |
1004 | 1009 |
1005 IsolateSpawnState::IsolateSpawnState(const char* script_url) | 1010 IsolateSpawnState::IsolateSpawnState(const char* script_url) |
1006 : isolate_(NULL), | 1011 : isolate_(NULL), |
1007 library_url_(NULL), | 1012 library_url_(NULL), |
1008 function_name_(NULL), | 1013 function_name_(NULL), |
1009 exception_callback_name_(NULL) { | 1014 exception_callback_name_(NULL) { |
1010 script_url_ = strdup(script_url); | 1015 script_url_ = strdup(script_url); |
1011 library_url_ = NULL; | 1016 library_url_ = NULL; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 return func.raw(); | 1056 return func.raw(); |
1052 } | 1057 } |
1053 | 1058 |
1054 | 1059 |
1055 void IsolateSpawnState::Cleanup() { | 1060 void IsolateSpawnState::Cleanup() { |
1056 SwitchIsolateScope switch_scope(isolate()); | 1061 SwitchIsolateScope switch_scope(isolate()); |
1057 Dart::ShutdownIsolate(); | 1062 Dart::ShutdownIsolate(); |
1058 } | 1063 } |
1059 | 1064 |
1060 } // namespace dart | 1065 } // namespace dart |
OLD | NEW |