Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: runtime/vm/isolate.cc

Issue 68813002: Fix VM not accepting static methods for Isolate.spawn. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rule out anonymous closures. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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),
1017 function_name_(NULL), 1021 function_name_(NULL),
1018 exception_callback_name_(NULL) { 1022 exception_callback_name_(NULL) {
1019 script_url_ = strdup(script_url); 1023 script_url_ = strdup(script_url);
1020 library_url_ = NULL; 1024 library_url_ = NULL;
1021 function_name_ = strdup("main"); 1025 function_name_ = strdup("main");
1022 exception_callback_name_ = strdup("_unhandledExceptionCallback"); 1026 exception_callback_name_ = strdup("_unhandledExceptionCallback");
1023 } 1027 }
1024 1028
1025 1029
1026 IsolateSpawnState::~IsolateSpawnState() { 1030 IsolateSpawnState::~IsolateSpawnState() {
1027 free(script_url_); 1031 free(script_url_);
1028 free(library_url_); 1032 free(library_url_);
1029 free(function_name_); 1033 free(function_name_);
1034 free(class_name_);
1030 free(exception_callback_name_); 1035 free(exception_callback_name_);
1031 } 1036 }
1032 1037
1033 1038
1034 RawObject* IsolateSpawnState::ResolveFunction() { 1039 RawObject* IsolateSpawnState::ResolveFunction() {
1035 // Resolve the library. 1040 // Resolve the library.
1036 Library& lib = Library::Handle(); 1041 Library& lib = Library::Handle();
1037 if (library_url()) { 1042 if (library_url()) {
1038 const String& lib_url = String::Handle(String::New(library_url())); 1043 const String& lib_url = String::Handle(String::New(library_url()));
1039 lib = Library::LookupLibrary(lib_url); 1044 lib = Library::LookupLibrary(lib_url);
1040 if (lib.IsNull() || lib.IsError()) { 1045 if (lib.IsNull() || lib.IsError()) {
1041 const String& msg = String::Handle(String::NewFormatted( 1046 const String& msg = String::Handle(String::NewFormatted(
1042 "Unable to find library '%s'.", library_url())); 1047 "Unable to find library '%s'.", library_url()));
1043 return LanguageError::New(msg); 1048 return LanguageError::New(msg);
1044 } 1049 }
1045 } else { 1050 } else {
1046 lib = isolate()->object_store()->root_library(); 1051 lib = isolate()->object_store()->root_library();
1047 } 1052 }
1048 ASSERT(!lib.IsNull()); 1053 ASSERT(!lib.IsNull());
1049 1054
1050 // Resolve the function. 1055 // Resolve the function.
1051 const String& func_name = 1056 const String& func_name = String::Handle(String::New(function_name()));
1052 String::Handle(String::New(function_name())); 1057
1053 const Function& func = Function::Handle(lib.LookupLocalFunction(func_name)); 1058 if (class_name() == NULL) {
1059 const Function& func = Function::Handle(lib.LookupLocalFunction(func_name));
1060 if (func.IsNull()) {
1061 const String& msg = String::Handle(String::NewFormatted(
1062 "Unable to resolve function '%s' in library '%s'.",
1063 function_name(),
1064 (library_url() != NULL ? library_url() : script_url())));
1065 return LanguageError::New(msg);
1066 }
1067 return func.raw();
1068 }
1069
1070 const String& cls_name = String::Handle(String::New(class_name()));
1071 const Class& cls = Class::Handle(lib.LookupLocalClass(cls_name));
1072 if (cls.IsNull()) {
1073 const String& msg = String::Handle(String::NewFormatted(
1074 "Unable to resolve class '%s' in library '%s'.",
1075 class_name(),
1076 (library_url() != NULL ? library_url() : script_url())));
1077 return LanguageError::New(msg);
1078 }
1079 const Function& func =
1080 Function::Handle(cls.LookupStaticFunctionAllowPrivate(func_name));
1054 if (func.IsNull()) { 1081 if (func.IsNull()) {
1055 const String& msg = String::Handle(String::NewFormatted( 1082 const String& msg = String::Handle(String::NewFormatted(
1056 "Unable to resolve function '%s' in library '%s'.", 1083 "Unable to resolve static method '%s.%s' in library '%s'.",
1057 function_name(), (library_url() ? library_url() : script_url()))); 1084 class_name(), function_name(),
1085 (library_url() != NULL ? library_url() : script_url())));
1058 return LanguageError::New(msg); 1086 return LanguageError::New(msg);
1059 } 1087 }
1060 return func.raw(); 1088 return func.raw();
1061 } 1089 }
1062 1090
1063 1091
1064 void IsolateSpawnState::Cleanup() { 1092 void IsolateSpawnState::Cleanup() {
1065 SwitchIsolateScope switch_scope(isolate()); 1093 SwitchIsolateScope switch_scope(isolate());
1066 Dart::ShutdownIsolate(); 1094 Dart::ShutdownIsolate();
1067 } 1095 }
1068 1096
1069 } // namespace dart 1097 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698