Chromium Code Reviews| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 name ^= String::New(":"); | 73 name ^= String::New(":"); |
| 74 str ^= String::Concat(str, name); | 74 str ^= String::Concat(str, name); |
| 75 name ^= String::NewSymbol(class_name); | 75 name ^= String::NewSymbol(class_name); |
| 76 str ^= String::Concat(str, name); | 76 str ^= String::Concat(str, name); |
| 77 GrowableArray<const Object*> arguments(1); | 77 GrowableArray<const Object*> arguments(1); |
| 78 arguments.Add(&str); | 78 arguments.Add(&str); |
| 79 Exceptions::ThrowByType(type, arguments); | 79 Exceptions::ThrowByType(type, arguments); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 RawInstance* ReceivePortCreate(intptr_t port_id) { | 83 // TODO(turnidge): Move to DartLibraryCalls. |
| 84 RawObject* ReceivePortCreate(intptr_t port_id) { | |
| 84 const String& class_name = | 85 const String& class_name = |
| 85 String::Handle(String::NewSymbol("ReceivePortImpl")); | 86 String::Handle(String::NewSymbol("ReceivePortImpl")); |
| 86 const String& function_name = | 87 const String& function_name = |
| 87 String::Handle(String::NewSymbol("_get_or_create")); | 88 String::Handle(String::NewSymbol("_get_or_create")); |
| 88 const int kNumArguments = 1; | 89 const int kNumArguments = 1; |
| 89 const Array& kNoArgumentNames = Array::Handle(); | 90 const Array& kNoArgumentNames = Array::Handle(); |
| 90 const Function& function = Function::Handle( | 91 const Function& function = Function::Handle( |
| 91 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | 92 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
| 92 class_name, | 93 class_name, |
| 93 function_name, | 94 function_name, |
| 94 kNumArguments, | 95 kNumArguments, |
| 95 kNoArgumentNames, | 96 kNoArgumentNames, |
| 96 Resolver::kIsQualified)); | 97 Resolver::kIsQualified)); |
| 97 GrowableArray<const Object*> arguments(kNumArguments); | 98 GrowableArray<const Object*> arguments(kNumArguments); |
| 98 arguments.Add(&Integer::Handle(Integer::New(port_id))); | 99 arguments.Add(&Integer::Handle(Integer::New(port_id))); |
| 99 const Instance& result = Instance::Handle( | 100 const Object& result = Object::Handle( |
| 100 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | 101 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
| 101 if (result.IsError()) { | 102 if (result.IsInstance()) { |
|
siva
2012/01/31 00:52:34
Why not
if (!result.IsError()) {
PortMap::SetLiv
turnidge
2012/01/31 21:56:31
Done.
| |
| 102 ProcessError(result); | |
| 103 } else { | |
| 104 PortMap::SetLive(port_id); | 103 PortMap::SetLive(port_id); |
| 105 } | 104 } |
| 106 return result.raw(); | 105 return result.raw(); |
| 107 } | 106 } |
| 108 | 107 |
| 109 | 108 |
| 110 static RawInstance* SendPortCreate(intptr_t port_id) { | 109 // TODO(turnidge): Move to DartLibraryCalls. |
| 110 static RawObject* SendPortCreate(intptr_t port_id) { | |
| 111 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl")); | 111 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl")); |
| 112 const String& function_name = String::Handle(String::NewSymbol("_create")); | 112 const String& function_name = String::Handle(String::NewSymbol("_create")); |
| 113 const int kNumArguments = 1; | 113 const int kNumArguments = 1; |
| 114 const Array& kNoArgumentNames = Array::Handle(); | 114 const Array& kNoArgumentNames = Array::Handle(); |
| 115 const Function& function = Function::Handle( | 115 const Function& function = Function::Handle( |
| 116 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | 116 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
| 117 class_name, | 117 class_name, |
| 118 function_name, | 118 function_name, |
| 119 kNumArguments, | 119 kNumArguments, |
| 120 kNoArgumentNames, | 120 kNoArgumentNames, |
| 121 Resolver::kIsQualified)); | 121 Resolver::kIsQualified)); |
| 122 GrowableArray<const Object*> arguments(kNumArguments); | 122 GrowableArray<const Object*> arguments(kNumArguments); |
| 123 arguments.Add(&Integer::Handle(Integer::New(port_id))); | 123 arguments.Add(&Integer::Handle(Integer::New(port_id))); |
| 124 const Instance& result = Instance::Handle( | 124 const Object& result = Object::Handle( |
| 125 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | 125 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
| 126 return result.raw(); | 126 return result.raw(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 | 129 |
| 130 static void RunIsolate(uword parameter) { | 130 static void RunIsolate(uword parameter) { |
| 131 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter); | 131 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter); |
| 132 Isolate* isolate = data->isolate_; | 132 Isolate* isolate = data->isolate_; |
| 133 char* library_url = data->library_url_; | 133 char* library_url = data->library_url_; |
| 134 char* class_name = data->class_name_; | 134 char* class_name = data->class_name_; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 } | 176 } |
| 177 ASSERT(result.IsNull()); | 177 ASSERT(result.IsNull()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Invoke the "_run" method. | 180 // Invoke the "_run" method. |
| 181 const Function& target_function = Function::Handle(Resolver::ResolveDynamic( | 181 const Function& target_function = Function::Handle(Resolver::ResolveDynamic( |
| 182 target, String::Handle(String::NewSymbol("_run")), 2, 0)); | 182 target, String::Handle(String::NewSymbol("_run")), 2, 0)); |
| 183 // TODO(iposva): Proper error checking here. | 183 // TODO(iposva): Proper error checking here. |
| 184 ASSERT(!target_function.IsNull()); | 184 ASSERT(!target_function.IsNull()); |
| 185 // TODO(iposva): Allocate the proper port number here. | 185 // TODO(iposva): Allocate the proper port number here. |
| 186 const Instance& local_port = Instance::Handle(ReceivePortCreate(port_id)); | 186 const Object& local_port = Object::Handle(ReceivePortCreate(port_id)); |
| 187 if (local_port.IsError()) { | |
| 188 ProcessError(local_port); | |
| 189 } | |
| 187 GrowableArray<const Object*> arguments(1); | 190 GrowableArray<const Object*> arguments(1); |
| 188 arguments.Add(&local_port); | 191 arguments.Add(&local_port); |
| 189 const Array& kNoArgumentNames = Array::Handle(); | 192 const Array& kNoArgumentNames = Array::Handle(); |
| 190 result = DartEntry::InvokeDynamic(target, | 193 result = DartEntry::InvokeDynamic(target, |
| 191 target_function, | 194 target_function, |
| 192 arguments, | 195 arguments, |
| 193 kNoArgumentNames); | 196 kNoArgumentNames); |
| 194 if (result.IsError()) { | 197 if (result.IsError()) { |
| 195 ProcessError(result); | 198 ProcessError(result); |
| 196 } | 199 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 | 321 |
| 319 // Switch back to the original isolate and return. | 322 // Switch back to the original isolate and return. |
| 320 Isolate::SetCurrent(preserved_isolate); | 323 Isolate::SetCurrent(preserved_isolate); |
| 321 if (spawned_isolate == NULL) { | 324 if (spawned_isolate == NULL) { |
| 322 // Unable to spawn isolate correctly, throw exception. | 325 // Unable to spawn isolate correctly, throw exception. |
| 323 ThrowErrorException(Exceptions::kIllegalArgument, | 326 ThrowErrorException(Exceptions::kIllegalArgument, |
| 324 error, | 327 error, |
| 325 library_url, | 328 library_url, |
| 326 class_name); | 329 class_name); |
| 327 } | 330 } |
| 328 const Instance& port = Instance::Handle(SendPortCreate(port_id)); | 331 |
| 332 // TODO(turnidge): Move this code up before we launch the new | |
| 333 // thread. That way we won't have a thread hanging around that we | |
| 334 // can't talk to. | |
| 335 const Object& port = Object::Handle(SendPortCreate(port_id)); | |
| 329 if (port.IsError()) { | 336 if (port.IsError()) { |
| 330 if (port.IsUnhandledException()) { | 337 Error& error = Error::Handle(); |
| 331 ThrowErrorException(Exceptions::kInternalError, | 338 error ^= port.raw(); |
| 332 "Unable to create send port to isolate", | 339 Exceptions::PropagateError(error); |
| 333 library_url, | |
| 334 class_name); | |
| 335 } else { | |
| 336 ProcessError(port); | |
| 337 } | |
| 338 } | 340 } |
| 339 arguments->SetReturn(port); | 341 arguments->SetReturn(port); |
| 340 } | 342 } |
| 341 | 343 |
| 342 | 344 |
| 343 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { | 345 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { |
| 344 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); | 346 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); |
| 345 intptr_t port_id = PortMap::CreatePort(); | 347 intptr_t port_id = PortMap::CreatePort(); |
| 346 const Instance& port = Instance::Handle(ReceivePortCreate(port_id)); | 348 const Object& port = Object::Handle(ReceivePortCreate(port_id)); |
| 349 if (port.IsError()) { | |
| 350 Error& error = Error::Handle(); | |
| 351 error ^= port.raw(); | |
| 352 Exceptions::PropagateError(error); | |
| 353 } | |
| 347 arguments->SetReturn(port); | 354 arguments->SetReturn(port); |
| 348 } | 355 } |
| 349 | 356 |
| 350 | 357 |
| 351 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) { | 358 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) { |
| 352 intptr_t id = Smi::CheckedHandle(arguments->At(0)).Value(); | 359 intptr_t id = Smi::CheckedHandle(arguments->At(0)).Value(); |
| 353 PortMap::ClosePort(id); | 360 PortMap::ClosePort(id); |
| 354 } | 361 } |
| 355 | 362 |
| 356 | 363 |
| 357 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { | 364 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { |
| 358 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); | 365 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); |
| 359 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); | 366 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); |
| 360 // TODO(iposva): Allow for arbitrary messages to be sent. | 367 // TODO(iposva): Allow for arbitrary messages to be sent. |
| 361 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); | 368 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); |
| 362 | 369 |
| 363 // TODO(turnidge): Throw an exception when the return value is false? | 370 // TODO(turnidge): Throw an exception when the return value is false? |
| 364 PortMap::PostMessage(send_id, reply_id, Api::CastMessage(data)); | 371 PortMap::PostMessage(send_id, reply_id, Api::CastMessage(data)); |
| 365 } | 372 } |
| 366 | 373 |
| 367 } // namespace dart | 374 } // namespace dart |
| OLD | NEW |