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 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); | 989 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); |
990 T::initializeHandle(handle, T::null()); | 990 T::initializeHandle(handle, T::null()); |
991 return handle; | 991 return handle; |
992 } | 992 } |
993 | 993 |
994 | 994 |
995 IsolateSpawnState::IsolateSpawnState(const Function& func) | 995 IsolateSpawnState::IsolateSpawnState(const Function& func) |
996 : isolate_(NULL), | 996 : isolate_(NULL), |
997 script_url_(NULL), | 997 script_url_(NULL), |
998 library_url_(NULL), | 998 library_url_(NULL), |
| 999 class_name_(NULL), |
999 function_name_(NULL), | 1000 function_name_(NULL), |
1000 exception_callback_name_(NULL) { | 1001 exception_callback_name_(NULL) { |
1001 script_url_ = NULL; | 1002 script_url_ = NULL; |
1002 const Class& cls = Class::Handle(func.Owner()); | 1003 const Class& cls = Class::Handle(func.Owner()); |
1003 ASSERT(cls.IsTopLevel()); | |
1004 const Library& lib = Library::Handle(cls.library()); | 1004 const Library& lib = Library::Handle(cls.library()); |
1005 const String& lib_url = String::Handle(lib.url()); | 1005 const String& lib_url = String::Handle(lib.url()); |
1006 library_url_ = strdup(lib_url.ToCString()); | 1006 library_url_ = strdup(lib_url.ToCString()); |
1007 | 1007 |
1008 const String& func_name = String::Handle(func.name()); | 1008 const String& func_name = String::Handle(func.name()); |
1009 function_name_ = strdup(func_name.ToCString()); | 1009 function_name_ = strdup(func_name.ToCString()); |
| 1010 if (!cls.IsTopLevel()) { |
| 1011 const String& class_name = String::Handle(cls.Name()); |
| 1012 class_name_ = strdup(class_name.ToCString()); |
| 1013 } |
1010 exception_callback_name_ = strdup("_unhandledExceptionCallback"); | 1014 exception_callback_name_ = strdup("_unhandledExceptionCallback"); |
1011 } | 1015 } |
1012 | 1016 |
1013 | 1017 |
1014 IsolateSpawnState::IsolateSpawnState(const char* script_url) | 1018 IsolateSpawnState::IsolateSpawnState(const char* script_url) |
1015 : isolate_(NULL), | 1019 : isolate_(NULL), |
1016 library_url_(NULL), | 1020 library_url_(NULL), |
| 1021 class_name_(NULL), |
1017 function_name_(NULL), | 1022 function_name_(NULL), |
1018 exception_callback_name_(NULL) { | 1023 exception_callback_name_(NULL) { |
1019 script_url_ = strdup(script_url); | 1024 script_url_ = strdup(script_url); |
1020 library_url_ = NULL; | 1025 library_url_ = NULL; |
1021 function_name_ = strdup("main"); | 1026 function_name_ = strdup("main"); |
1022 exception_callback_name_ = strdup("_unhandledExceptionCallback"); | 1027 exception_callback_name_ = strdup("_unhandledExceptionCallback"); |
1023 } | 1028 } |
1024 | 1029 |
1025 | 1030 |
1026 IsolateSpawnState::~IsolateSpawnState() { | 1031 IsolateSpawnState::~IsolateSpawnState() { |
1027 free(script_url_); | 1032 free(script_url_); |
1028 free(library_url_); | 1033 free(library_url_); |
1029 free(function_name_); | 1034 free(function_name_); |
| 1035 free(class_name_); |
1030 free(exception_callback_name_); | 1036 free(exception_callback_name_); |
1031 } | 1037 } |
1032 | 1038 |
1033 | 1039 |
1034 RawObject* IsolateSpawnState::ResolveFunction() { | 1040 RawObject* IsolateSpawnState::ResolveFunction() { |
1035 // Resolve the library. | 1041 // Resolve the library. |
1036 Library& lib = Library::Handle(); | 1042 Library& lib = Library::Handle(); |
1037 if (library_url()) { | 1043 if (library_url()) { |
1038 const String& lib_url = String::Handle(String::New(library_url())); | 1044 const String& lib_url = String::Handle(String::New(library_url())); |
1039 lib = Library::LookupLibrary(lib_url); | 1045 lib = Library::LookupLibrary(lib_url); |
1040 if (lib.IsNull() || lib.IsError()) { | 1046 if (lib.IsNull() || lib.IsError()) { |
1041 const String& msg = String::Handle(String::NewFormatted( | 1047 const String& msg = String::Handle(String::NewFormatted( |
1042 "Unable to find library '%s'.", library_url())); | 1048 "Unable to find library '%s'.", library_url())); |
1043 return LanguageError::New(msg); | 1049 return LanguageError::New(msg); |
1044 } | 1050 } |
1045 } else { | 1051 } else { |
1046 lib = isolate()->object_store()->root_library(); | 1052 lib = isolate()->object_store()->root_library(); |
1047 } | 1053 } |
1048 ASSERT(!lib.IsNull()); | 1054 ASSERT(!lib.IsNull()); |
1049 | 1055 |
1050 // Resolve the function. | 1056 // Resolve the function. |
1051 const String& func_name = | 1057 const String& func_name = String::Handle(String::New(function_name())); |
1052 String::Handle(String::New(function_name())); | 1058 |
1053 const Function& func = Function::Handle(lib.LookupLocalFunction(func_name)); | 1059 if (class_name() == NULL) { |
| 1060 const Function& func = Function::Handle(lib.LookupLocalFunction(func_name)); |
| 1061 if (func.IsNull()) { |
| 1062 const String& msg = String::Handle(String::NewFormatted( |
| 1063 "Unable to resolve function '%s' in library '%s'.", |
| 1064 function_name(), |
| 1065 (library_url() != NULL ? library_url() : script_url()))); |
| 1066 return LanguageError::New(msg); |
| 1067 } |
| 1068 return func.raw(); |
| 1069 } |
| 1070 |
| 1071 const String& cls_name = String::Handle(String::New(class_name())); |
| 1072 const Class& cls = Class::Handle(lib.LookupLocalClass(cls_name)); |
| 1073 if (cls.IsNull()) { |
| 1074 const String& msg = String::Handle(String::NewFormatted( |
| 1075 "Unable to resolve class '%s' in library '%s'.", |
| 1076 class_name(), |
| 1077 (library_url() != NULL ? library_url() : script_url()))); |
| 1078 return LanguageError::New(msg); |
| 1079 } |
| 1080 const Function& func = |
| 1081 Function::Handle(cls.LookupStaticFunctionAllowPrivate(func_name)); |
1054 if (func.IsNull()) { | 1082 if (func.IsNull()) { |
1055 const String& msg = String::Handle(String::NewFormatted( | 1083 const String& msg = String::Handle(String::NewFormatted( |
1056 "Unable to resolve function '%s' in library '%s'.", | 1084 "Unable to resolve static method '%s.%s' in library '%s'.", |
1057 function_name(), (library_url() ? library_url() : script_url()))); | 1085 class_name(), function_name(), |
| 1086 (library_url() != NULL ? library_url() : script_url()))); |
1058 return LanguageError::New(msg); | 1087 return LanguageError::New(msg); |
1059 } | 1088 } |
1060 return func.raw(); | 1089 return func.raw(); |
1061 } | 1090 } |
1062 | 1091 |
1063 | 1092 |
1064 void IsolateSpawnState::Cleanup() { | 1093 void IsolateSpawnState::Cleanup() { |
1065 SwitchIsolateScope switch_scope(isolate()); | 1094 SwitchIsolateScope switch_scope(isolate()); |
1066 Dart::ShutdownIsolate(); | 1095 Dart::ShutdownIsolate(); |
1067 } | 1096 } |
1068 | 1097 |
1069 } // namespace dart | 1098 } // namespace dart |
OLD | NEW |