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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 arguments.Add(&Integer::Handle(Integer::New(port_id))); | 102 arguments.Add(&Integer::Handle(Integer::New(port_id))); |
103 const Object& result = Object::Handle( | 103 const Object& result = Object::Handle( |
104 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | 104 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
105 if (!result.IsError()) { | 105 if (!result.IsError()) { |
106 PortMap::SetLive(port_id); | 106 PortMap::SetLive(port_id); |
107 } | 107 } |
108 return result.raw(); | 108 return result.raw(); |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 // TODO(turnidge): Move to DartLibraryCalls. | |
113 static RawObject* SendPortCreate(intptr_t port_id) { | |
114 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | |
115 ASSERT(!isolate_lib.IsNull()); | |
116 const String& class_name = | |
117 String::Handle(isolate_lib.PrivateName("_SendPortImpl")); | |
118 const String& function_name = String::Handle(String::NewSymbol("_create")); | |
119 const int kNumArguments = 1; | |
120 const Array& kNoArgumentNames = Array::Handle(); | |
121 const Function& function = Function::Handle( | |
122 Resolver::ResolveStatic(isolate_lib, | |
123 class_name, | |
124 function_name, | |
125 kNumArguments, | |
126 kNoArgumentNames, | |
127 Resolver::kIsQualified)); | |
128 GrowableArray<const Object*> arguments(kNumArguments); | |
129 arguments.Add(&Integer::Handle(Integer::New(port_id))); | |
130 const Object& result = Object::Handle( | |
131 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | |
132 return result.raw(); | |
133 } | |
134 | |
135 | |
136 static void RunIsolate(uword parameter) { | 112 static void RunIsolate(uword parameter) { |
137 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter); | 113 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter); |
138 Isolate* isolate = data->isolate_; | 114 Isolate* isolate = data->isolate_; |
139 char* library_url = data->library_url_; | 115 char* library_url = data->library_url_; |
140 char* class_name = data->class_name_; | 116 char* class_name = data->class_name_; |
141 intptr_t port_id = data->port_id_; | 117 intptr_t port_id = data->port_id_; |
142 delete data; | 118 delete data; |
143 | 119 |
144 Isolate::SetCurrent(isolate); | 120 Isolate::SetCurrent(isolate); |
145 // Intialize stack limit in case we are running isolate in a | 121 // Intialize stack limit in case we are running isolate in a |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // Unable to spawn isolate correctly, throw exception. | 311 // Unable to spawn isolate correctly, throw exception. |
336 ThrowErrorException(Exceptions::kIllegalArgument, | 312 ThrowErrorException(Exceptions::kIllegalArgument, |
337 error, | 313 error, |
338 library_url, | 314 library_url, |
339 class_name); | 315 class_name); |
340 } | 316 } |
341 | 317 |
342 // TODO(turnidge): Move this code up before we launch the new | 318 // TODO(turnidge): Move this code up before we launch the new |
343 // thread. That way we won't have a thread hanging around that we | 319 // thread. That way we won't have a thread hanging around that we |
344 // can't talk to. | 320 // can't talk to. |
345 const Object& port = Object::Handle(SendPortCreate(port_id)); | 321 const Object& port = Object::Handle(DartLibraryCalls::NewSendPort(port_id)); |
346 if (port.IsError()) { | 322 if (port.IsError()) { |
347 Exceptions::PropagateError(port); | 323 Exceptions::PropagateError(port); |
348 } | 324 } |
349 arguments->SetReturn(port); | 325 arguments->SetReturn(port); |
350 } | 326 } |
351 | 327 |
352 | 328 |
353 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { | 329 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { |
354 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); | 330 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); |
355 intptr_t port_id = | 331 intptr_t port_id = |
(...skipping 17 matching lines...) Expand all Loading... |
373 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); | 349 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); |
374 // TODO(iposva): Allow for arbitrary messages to be sent. | 350 // TODO(iposva): Allow for arbitrary messages to be sent. |
375 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); | 351 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); |
376 | 352 |
377 // TODO(turnidge): Throw an exception when the return value is false? | 353 // TODO(turnidge): Throw an exception when the return value is false? |
378 PortMap::PostMessage(new Message( | 354 PortMap::PostMessage(new Message( |
379 send_id, reply_id, data, Message::kNormalPriority)); | 355 send_id, reply_id, data, Message::kNormalPriority)); |
380 } | 356 } |
381 | 357 |
382 } // namespace dart | 358 } // namespace dart |
OLD | NEW |