| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 Isolate* isolate = reinterpret_cast<Isolate*>(parameter); | 84 Isolate* isolate = reinterpret_cast<Isolate*>(parameter); |
| 85 { | 85 { |
| 86 // Print the error if there is one. This may execute dart code to | 86 // Print the error if there is one. This may execute dart code to |
| 87 // print the exception object, so we need to use a StartIsolateScope. | 87 // print the exception object, so we need to use a StartIsolateScope. |
| 88 StartIsolateScope start_scope(isolate); | 88 StartIsolateScope start_scope(isolate); |
| 89 StackZone zone(isolate); | 89 StackZone zone(isolate); |
| 90 HandleScope handle_scope(isolate); | 90 HandleScope handle_scope(isolate); |
| 91 Error& error = Error::Handle(); | 91 Error& error = Error::Handle(); |
| 92 error = isolate->object_store()->sticky_error(); | 92 error = isolate->object_store()->sticky_error(); |
| 93 if (!error.IsNull()) { | 93 if (!error.IsNull()) { |
| 94 OS::PrintErr("%s\n", error.ToErrorCString()); | 94 OS::PrintErr("in ShutdownIsolate: %s\n", error.ToErrorCString()); |
| 95 exit(255); | |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 { | 97 { |
| 99 // Shut the isolate down. | 98 // Shut the isolate down. |
| 100 SwitchIsolateScope switch_scope(isolate); | 99 SwitchIsolateScope switch_scope(isolate); |
| 101 Dart::ShutdownIsolate(); | 100 Dart::ShutdownIsolate(); |
| 102 } | 101 } |
| 103 } | 102 } |
| 104 | 103 |
| 105 | 104 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 380 |
| 382 // Try to create a SendPort for the new isolate. | 381 // Try to create a SendPort for the new isolate. |
| 383 const Object& port = Object::Handle( | 382 const Object& port = Object::Handle( |
| 384 DartLibraryCalls::NewSendPort(state->isolate()->main_port())); | 383 DartLibraryCalls::NewSendPort(state->isolate()->main_port())); |
| 385 if (port.IsError()) { | 384 if (port.IsError()) { |
| 386 state->Cleanup(); | 385 state->Cleanup(); |
| 387 delete state; | 386 delete state; |
| 388 Exceptions::PropagateError(Error::Cast(port)); | 387 Exceptions::PropagateError(Error::Cast(port)); |
| 389 } | 388 } |
| 390 | 389 |
| 390 // If specified, set the new isolate's uncaught exception handler. |
| 391 ASSERT(arguments->NativeArgCount() == 2); |
| 392 const Object& arg = Object::Handle(arguments->NativeArgAt(1)); |
| 393 if (!arg.IsNull()) { |
| 394 const Instance& callback = Instance::Cast(arg); |
| 395 state->isolate()->object_store()->set_unhandled_exception_closure(callback); |
| 396 } |
| 397 |
| 391 // Start the new isolate. | 398 // Start the new isolate. |
| 392 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state)); | 399 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state)); |
| 393 state->isolate()->message_handler()->Run( | 400 state->isolate()->message_handler()->Run( |
| 394 Dart::thread_pool(), RunIsolate, ShutdownIsolate, | 401 Dart::thread_pool(), RunIsolate, ShutdownIsolate, |
| 395 reinterpret_cast<uword>(state->isolate())); | 402 reinterpret_cast<uword>(state->isolate())); |
| 396 | 403 |
| 397 return port.raw(); | 404 return port.raw(); |
| 398 } | 405 } |
| 399 | 406 |
| 400 | 407 |
| 401 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 1) { | 408 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 2) { |
| 402 GET_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); | 409 GET_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
| 403 bool throw_exception = false; | 410 bool throw_exception = false; |
| 404 Function& func = Function::Handle(); | 411 Function& func = Function::Handle(); |
| 405 if (closure.IsClosure()) { | 412 if (closure.IsClosure()) { |
| 406 func ^= Closure::function(closure); | 413 func ^= Closure::function(closure); |
| 407 const Class& cls = Class::Handle(func.Owner()); | 414 const Class& cls = Class::Handle(func.Owner()); |
| 408 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { | 415 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { |
| 409 throw_exception = true; | 416 throw_exception = true; |
| 410 } | 417 } |
| 411 } else { | 418 } else { |
| 412 throw_exception = true; | 419 throw_exception = true; |
| 413 } | 420 } |
| 414 if (throw_exception) { | 421 if (throw_exception) { |
| 415 const String& msg = String::Handle(String::New( | 422 const String& msg = String::Handle(String::New( |
| 416 "spawnFunction expects to be passed a closure to a top-level static " | 423 "spawnFunction expects to be passed a closure to a top-level static " |
| 417 "function")); | 424 "function")); |
| 418 ThrowIllegalArgException(msg); | 425 ThrowIllegalArgException(msg); |
| 419 } | 426 } |
| 420 | 427 |
| 421 #if defined(DEBUG) | 428 #if defined(DEBUG) |
| 422 const Context& ctx = Context::Handle(Closure::context(closure)); | 429 const Context& ctx = Context::Handle(Closure::context(closure)); |
| 423 ASSERT(ctx.num_variables() == 0); | 430 ASSERT(ctx.num_variables() == 0); |
| 424 #endif | 431 #endif |
| 425 | 432 |
| 426 return Spawn(arguments, new SpawnState(func)); | 433 return Spawn(arguments, new SpawnState(func)); |
| 427 } | 434 } |
| 428 | 435 |
| 429 | 436 |
| 430 DEFINE_NATIVE_ENTRY(isolate_spawnUri, 1) { | 437 DEFINE_NATIVE_ENTRY(isolate_spawnUri, 2) { |
| 431 GET_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); | 438 GET_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); |
| 432 | 439 |
| 433 // Canonicalize the uri with respect to the current isolate. | 440 // Canonicalize the uri with respect to the current isolate. |
| 434 char* error = NULL; | 441 char* error = NULL; |
| 435 char* canonical_uri = NULL; | 442 char* canonical_uri = NULL; |
| 436 const Library& root_lib = | 443 const Library& root_lib = |
| 437 Library::Handle(arguments->isolate()->object_store()->root_library()); | 444 Library::Handle(arguments->isolate()->object_store()->root_library()); |
| 438 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, | 445 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, |
| 439 &canonical_uri, &error)) { | 446 &canonical_uri, &error)) { |
| 440 const String& msg = String::Handle(String::New(error)); | 447 const String& msg = String::Handle(String::New(error)); |
| 441 free(error); | 448 free(error); |
| 442 ThrowIsolateSpawnException(msg); | 449 ThrowIsolateSpawnException(msg); |
| 443 } | 450 } |
| 444 | 451 |
| 445 return Spawn(arguments, new SpawnState(canonical_uri)); | 452 return Spawn(arguments, new SpawnState(canonical_uri)); |
| 446 } | 453 } |
| 447 | 454 |
| 448 | 455 |
| 449 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { | 456 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { |
| 450 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); | 457 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); |
| 451 if (port.IsError()) { | 458 if (port.IsError()) { |
| 452 Exceptions::PropagateError(Error::Cast(port)); | 459 Exceptions::PropagateError(Error::Cast(port)); |
| 453 } | 460 } |
| 454 return port.raw(); | 461 return port.raw(); |
| 455 } | 462 } |
| 456 | 463 |
| 457 } // namespace dart | 464 } // namespace dart |
| OLD | NEW |