| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart.h" | 8 #include "vm/dart.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 free(class_name); | 198 free(class_name); |
| 199 result = isolate->StandardRunLoop(); | 199 result = isolate->StandardRunLoop(); |
| 200 if (result.IsError()) { | 200 if (result.IsError()) { |
| 201 ProcessError(result); | 201 ProcessError(result); |
| 202 } | 202 } |
| 203 ASSERT(result.IsNull()); | 203 ASSERT(result.IsNull()); |
| 204 | 204 |
| 205 } else { | 205 } else { |
| 206 Zone zone(isolate); | 206 Zone zone(isolate); |
| 207 HandleScope handle_scope(isolate); | 207 HandleScope handle_scope(isolate); |
| 208 const String& error = String::Handle( | 208 const Error& error = Error::Handle( |
| 209 Isolate::Current()->object_store()->sticky_error()); | 209 Isolate::Current()->object_store()->sticky_error()); |
| 210 const char* errmsg = error.ToCString(); | 210 const char* errmsg = error.ToErrorCString(); |
| 211 OS::PrintErr("%s\n", errmsg); | 211 OS::PrintErr("%s\n", errmsg); |
| 212 exit(255); | 212 exit(255); |
| 213 } | 213 } |
| 214 isolate->set_long_jump_base(base); | 214 isolate->set_long_jump_base(base); |
| 215 Dart::ShutdownIsolate(); | 215 Dart::ShutdownIsolate(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 | 218 |
| 219 static bool CheckArguments(const char* library_url, const char* class_name) { | 219 static bool CheckArguments(const char* library_url, const char* class_name) { |
| 220 Isolate* isolate = Isolate::Current(); | 220 Isolate* isolate = Isolate::Current(); |
| 221 Zone zone(isolate); | 221 Zone zone(isolate); |
| 222 HandleScope handle_scope(isolate); | 222 HandleScope handle_scope(isolate); |
| 223 String& name = String::Handle(); | 223 String& name = String::Handle(); |
| 224 if (!ClassFinalizer::FinalizePendingClasses()) { | 224 if (!ClassFinalizer::FinalizePendingClasses()) { |
| 225 return false; | 225 return false; |
| 226 } | 226 } |
| 227 // Lookup the target class by name, create an instance and call the run | 227 // Lookup the target class by name, create an instance and call the run |
| 228 // method. | 228 // method. |
| 229 name ^= String::NewSymbol(library_url); | 229 name ^= String::NewSymbol(library_url); |
| 230 const Library& lib = Library::Handle(Library::LookupLibrary(name)); | 230 const Library& lib = Library::Handle(Library::LookupLibrary(name)); |
| 231 if (lib.IsNull()) { | 231 if (lib.IsNull()) { |
| 232 const String& error = String::Handle( | 232 const String& error_str = String::Handle( |
| 233 String::New("Error starting Isolate, library not loaded : ")); | 233 String::New("Error starting Isolate, library not loaded : ")); |
| 234 const Error& error = Error::Handle(LanguageError::New(error_str)); |
| 234 Isolate::Current()->object_store()->set_sticky_error(error); | 235 Isolate::Current()->object_store()->set_sticky_error(error); |
| 235 return false; | 236 return false; |
| 236 } | 237 } |
| 237 name ^= String::NewSymbol(class_name); | 238 name ^= String::NewSymbol(class_name); |
| 238 const Class& target_class = Class::Handle(lib.LookupClass(name)); | 239 const Class& target_class = Class::Handle(lib.LookupClass(name)); |
| 239 if (target_class.IsNull()) { | 240 if (target_class.IsNull()) { |
| 240 const String& error = String::Handle( | 241 const String& error_str = String::Handle( |
| 241 String::New("Error starting Isolate, class not loaded : ")); | 242 String::New("Error starting Isolate, class not loaded : ")); |
| 243 const Error& error = Error::Handle(LanguageError::New(error_str)); |
| 242 Isolate::Current()->object_store()->set_sticky_error(error); | 244 Isolate::Current()->object_store()->set_sticky_error(error); |
| 243 return false; | 245 return false; |
| 244 } | 246 } |
| 245 return true; // No errors. | 247 return true; // No errors. |
| 246 } | 248 } |
| 247 | 249 |
| 248 | 250 |
| 249 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) { | 251 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) { |
| 250 Isolate* preserved_isolate = Isolate::Current(); | 252 Isolate* preserved_isolate = Isolate::Current(); |
| 251 const Instance& runnable = Instance::CheckedHandle(arguments->At(0)); | 253 const Instance& runnable = Instance::CheckedHandle(arguments->At(0)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 278 new Thread(RunIsolate, data); | 280 new Thread(RunIsolate, data); |
| 279 } else { | 281 } else { |
| 280 // Error spawning the isolate, maybe due to initialization errors or | 282 // Error spawning the isolate, maybe due to initialization errors or |
| 281 // errors while loading the application into spawned isolate, shut | 283 // errors while loading the application into spawned isolate, shut |
| 282 // it down and report error. | 284 // it down and report error. |
| 283 // Make sure to grab the error message out of the isolate before it has | 285 // Make sure to grab the error message out of the isolate before it has |
| 284 // been shutdown and to allocate it in the preserved isolates zone. | 286 // been shutdown and to allocate it in the preserved isolates zone. |
| 285 { | 287 { |
| 286 Zone zone(spawned_isolate); | 288 Zone zone(spawned_isolate); |
| 287 HandleScope scope(spawned_isolate); | 289 HandleScope scope(spawned_isolate); |
| 288 const String& errmsg = String::Handle( | 290 const Error& err_obj = Error::Handle( |
| 289 spawned_isolate->object_store()->sticky_error()); | 291 spawned_isolate->object_store()->sticky_error()); |
| 290 error = strdup(errmsg.ToCString()); | 292 error = strdup(err_obj.ToErrorCString()); |
| 291 } | 293 } |
| 292 Dart::ShutdownIsolate(); | 294 Dart::ShutdownIsolate(); |
| 293 spawned_isolate = NULL; | 295 spawned_isolate = NULL; |
| 294 } | 296 } |
| 295 } | 297 } |
| 296 | 298 |
| 297 // Switch back to the original isolate and return. | 299 // Switch back to the original isolate and return. |
| 298 Isolate::SetCurrent(preserved_isolate); | 300 Isolate::SetCurrent(preserved_isolate); |
| 299 if (spawned_isolate == NULL) { | 301 if (spawned_isolate == NULL) { |
| 300 // Unable to spawn isolate correctly, throw exception. | 302 // Unable to spawn isolate correctly, throw exception. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); | 338 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); |
| 337 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); | 339 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); |
| 338 // TODO(iposva): Allow for arbitrary messages to be sent. | 340 // TODO(iposva): Allow for arbitrary messages to be sent. |
| 339 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); | 341 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); |
| 340 | 342 |
| 341 // TODO(turnidge): Throw an exception when the return value is false? | 343 // TODO(turnidge): Throw an exception when the return value is false? |
| 342 PortMap::PostMessage(send_id, reply_id, Api::CastMessage(data)); | 344 PortMap::PostMessage(send_id, reply_id, Api::CastMessage(data)); |
| 343 } | 345 } |
| 344 | 346 |
| 345 } // namespace dart | 347 } // namespace dart |
| OLD | NEW |