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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 const String& error_str = String::Handle( | 241 const String& error_str = String::Handle( |
242 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)); | 243 const Error& error = Error::Handle(LanguageError::New(error_str)); |
244 Isolate::Current()->object_store()->set_sticky_error(error); | 244 Isolate::Current()->object_store()->set_sticky_error(error); |
245 return false; | 245 return false; |
246 } | 246 } |
247 return true; // No errors. | 247 return true; // No errors. |
248 } | 248 } |
249 | 249 |
250 | 250 |
| 251 static char* BuildIsolateName(const char* script_name, |
| 252 const char* class_name, |
| 253 const char* func_name) { |
| 254 // Skip past any slashes in the script name. |
| 255 const char* last_slash = strrchr(script_name, '/'); |
| 256 if (last_slash != NULL) { |
| 257 script_name = last_slash + 1; |
| 258 } |
| 259 |
| 260 const char* kFormat = "%s/%s.%s"; |
| 261 intptr_t len = OS::SNPrint(NULL, 0, kFormat, script_name, class_name, |
| 262 func_name) + 1; |
| 263 char* chars = reinterpret_cast<char*>( |
| 264 Isolate::Current()->current_zone()->Allocate(len)); |
| 265 OS::SNPrint(chars, len, kFormat, script_name, class_name, func_name); |
| 266 return chars; |
| 267 } |
| 268 |
| 269 |
251 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) { | 270 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) { |
252 Isolate* preserved_isolate = Isolate::Current(); | 271 Isolate* preserved_isolate = Isolate::Current(); |
253 const Instance& runnable = Instance::CheckedHandle(arguments->At(0)); | 272 const Instance& runnable = Instance::CheckedHandle(arguments->At(0)); |
254 const Class& runnable_class = Class::Handle(runnable.clazz()); | 273 const Class& runnable_class = Class::Handle(runnable.clazz()); |
255 const char* class_name = String::Handle(runnable_class.Name()).ToCString(); | 274 const char* class_name = String::Handle(runnable_class.Name()).ToCString(); |
256 const Library& library = Library::Handle(runnable_class.library()); | 275 const Library& library = Library::Handle(runnable_class.library()); |
257 ASSERT(!library.IsNull()); | 276 ASSERT(!library.IsNull()); |
258 const char* library_url = String::Handle(library.url()).ToCString(); | 277 const char* library_url = String::Handle(library.url()).ToCString(); |
259 intptr_t port_id = 0; | 278 intptr_t port_id = 0; |
260 LongJump jump; | 279 LongJump jump; |
261 bool init_successful = true; | 280 bool init_successful = true; |
262 Isolate* spawned_isolate = NULL; | 281 Isolate* spawned_isolate = NULL; |
263 void* callback_data = preserved_isolate->init_callback_data(); | 282 void* callback_data = preserved_isolate->init_callback_data(); |
264 char* error = NULL; | 283 char* error = NULL; |
265 Dart_IsolateCreateCallback callback = Isolate::CreateCallback(); | 284 Dart_IsolateCreateCallback callback = Isolate::CreateCallback(); |
| 285 const char* isolate_name = BuildIsolateName(library_url, class_name, "main"); |
266 if (callback == NULL) { | 286 if (callback == NULL) { |
267 error = strdup("Null callback specified for isolate creation\n"); | 287 error = strdup("Null callback specified for isolate creation\n"); |
268 } else if (callback(callback_data, &error)) { | 288 } else if (callback(isolate_name, callback_data, &error)) { |
269 spawned_isolate = Isolate::Current(); | 289 spawned_isolate = Isolate::Current(); |
270 ASSERT(spawned_isolate != NULL); | 290 ASSERT(spawned_isolate != NULL); |
271 // Check arguments to see if the specified library and classes are | 291 // Check arguments to see if the specified library and classes are |
272 // loaded, this check will throw an exception if they are not loaded. | 292 // loaded, this check will throw an exception if they are not loaded. |
273 if (init_successful && CheckArguments(library_url, class_name)) { | 293 if (init_successful && CheckArguments(library_url, class_name)) { |
274 port_id = spawned_isolate->main_port(); | 294 port_id = spawned_isolate->main_port(); |
275 uword data = reinterpret_cast<uword>( | 295 uword data = reinterpret_cast<uword>( |
276 new IsolateStartData(spawned_isolate, | 296 new IsolateStartData(spawned_isolate, |
277 strdup(library_url), | 297 strdup(library_url), |
278 strdup(class_name), | 298 strdup(class_name), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); | 358 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); |
339 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); | 359 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); |
340 // TODO(iposva): Allow for arbitrary messages to be sent. | 360 // TODO(iposva): Allow for arbitrary messages to be sent. |
341 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); | 361 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); |
342 | 362 |
343 // TODO(turnidge): Throw an exception when the return value is false? | 363 // TODO(turnidge): Throw an exception when the return value is false? |
344 PortMap::PostMessage(send_id, reply_id, Api::CastMessage(data)); | 364 PortMap::PostMessage(send_id, reply_id, Api::CastMessage(data)); |
345 } | 365 } |
346 | 366 |
347 } // namespace dart | 367 } // namespace dart |
OLD | NEW |