Chromium Code Reviews| 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_function_spawn = state->library_url() != NULL; | |
|
Ivan Posva
2013/10/25 07:01:46
I find this is rather brittle and would suggest th
floitsch
2013/10/25 13:11:01
Done.
| |
| 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 | |
|
Ivan Posva
2013/10/25 07:01:46
This trampoline through _startIsolate will have th
floitsch
2013/10/25 13:11:01
Yes. It's something we can live with in the near f
| |
| 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_function_spawn ? 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 970 | 991 |
| 971 static char* GetRootScriptUri(Isolate* isolate) { | 992 static char* GetRootScriptUri(Isolate* isolate) { |
| 972 const Library& library = | 993 const Library& library = |
| 973 Library::Handle(isolate->object_store()->root_library()); | 994 Library::Handle(isolate->object_store()->root_library()); |
| 974 ASSERT(!library.IsNull()); | 995 ASSERT(!library.IsNull()); |
| 975 const String& script_name = String::Handle(library.url()); | 996 const String& script_name = String::Handle(library.url()); |
| 976 return isolate->current_zone()->MakeCopyOfString(script_name.ToCString()); | 997 return isolate->current_zone()->MakeCopyOfString(script_name.ToCString()); |
| 977 } | 998 } |
| 978 | 999 |
| 979 | 1000 |
| 980 IsolateSpawnState::IsolateSpawnState(const Function& func, | 1001 IsolateSpawnState::IsolateSpawnState(const Function& func) |
| 981 const Function& callback_func) | |
| 982 : isolate_(NULL), | 1002 : isolate_(NULL), |
| 983 script_url_(NULL), | 1003 script_url_(NULL), |
| 984 library_url_(NULL), | 1004 library_url_(NULL), |
| 985 function_name_(NULL), | 1005 function_name_(NULL), |
| 986 exception_callback_name_(NULL) { | 1006 exception_callback_name_(NULL) { |
| 987 script_url_ = strdup(GetRootScriptUri(Isolate::Current())); | 1007 script_url_ = strdup(GetRootScriptUri(Isolate::Current())); |
|
Ivan Posva
2013/10/25 07:01:46
There have been changes in this area, so you'll ne
floitsch
2013/10/25 13:11:01
Done.
| |
| 988 const Class& cls = Class::Handle(func.Owner()); | 1008 const Class& cls = Class::Handle(func.Owner()); |
| 989 ASSERT(cls.IsTopLevel()); | 1009 ASSERT(cls.IsTopLevel()); |
| 990 const Library& lib = Library::Handle(cls.library()); | 1010 const Library& lib = Library::Handle(cls.library()); |
| 991 const String& lib_url = String::Handle(lib.url()); | 1011 const String& lib_url = String::Handle(lib.url()); |
| 992 library_url_ = strdup(lib_url.ToCString()); | 1012 library_url_ = strdup(lib_url.ToCString()); |
| 993 | 1013 |
| 994 const String& func_name = String::Handle(func.name()); | 1014 const String& func_name = String::Handle(func.name()); |
| 995 function_name_ = strdup(func_name.ToCString()); | 1015 function_name_ = strdup(func_name.ToCString()); |
| 996 if (!callback_func.IsNull()) { | 1016 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 } | 1017 } |
| 1003 | 1018 |
| 1004 | 1019 |
| 1005 IsolateSpawnState::IsolateSpawnState(const char* script_url) | 1020 IsolateSpawnState::IsolateSpawnState(const char* script_url) |
| 1006 : isolate_(NULL), | 1021 : isolate_(NULL), |
| 1007 library_url_(NULL), | 1022 library_url_(NULL), |
| 1008 function_name_(NULL), | 1023 function_name_(NULL), |
| 1009 exception_callback_name_(NULL) { | 1024 exception_callback_name_(NULL) { |
| 1010 script_url_ = strdup(script_url); | 1025 script_url_ = strdup(script_url); |
| 1011 library_url_ = NULL; | 1026 library_url_ = NULL; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1051 return func.raw(); | 1066 return func.raw(); |
| 1052 } | 1067 } |
| 1053 | 1068 |
| 1054 | 1069 |
| 1055 void IsolateSpawnState::Cleanup() { | 1070 void IsolateSpawnState::Cleanup() { |
| 1056 SwitchIsolateScope switch_scope(isolate()); | 1071 SwitchIsolateScope switch_scope(isolate()); |
| 1057 Dart::ShutdownIsolate(); | 1072 Dart::ShutdownIsolate(); |
| 1058 } | 1073 } |
| 1059 | 1074 |
| 1060 } // namespace dart | 1075 } // namespace dart |
| OLD | NEW |