OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/dart_entry.h" | 5 #include "vm/dart_entry.h" |
6 | 6 |
7 #include "vm/code_generator.h" | 7 #include "vm/code_generator.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
10 #include "vm/resolver.h" | 10 #include "vm/resolver.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 const Array& args = Array::Handle(Array::New(kNumArguments)); | 364 const Array& args = Array::Handle(Array::New(kNumArguments)); |
365 args.SetAt(0, left); | 365 args.SetAt(0, left); |
366 args.SetAt(1, right); | 366 args.SetAt(1, right); |
367 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function, | 367 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function, |
368 args)); | 368 args)); |
369 ASSERT(result.IsInstance() || result.IsError()); | 369 ASSERT(result.IsInstance() || result.IsError()); |
370 return result.raw(); | 370 return result.raw(); |
371 } | 371 } |
372 | 372 |
373 | 373 |
374 RawObject* DartLibraryCalls::LookupReceivePort(Dart_Port port_id) { | 374 RawObject* DartLibraryCalls::HandleMessage(Dart_Port dest_port_id, |
375 Isolate* isolate = Isolate::Current(); | |
376 Function& function = | |
377 Function::Handle(isolate, | |
378 isolate->object_store()->lookup_receive_port_function()); | |
379 const int kNumArguments = 1; | |
380 if (function.IsNull()) { | |
381 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | |
382 ASSERT(!isolate_lib.IsNull()); | |
383 const String& public_class_name = | |
384 String::Handle(Symbols::New("_ReceivePortImpl")); | |
385 const String& class_name = | |
386 String::Handle(isolate_lib.PrivateName(public_class_name)); | |
387 const String& function_name = | |
388 String::Handle(Symbols::New("_lookupReceivePort")); | |
389 const Array& kNoArgumentNames = Array::Handle(); | |
390 function = Resolver::ResolveStatic(isolate_lib, | |
391 class_name, | |
392 function_name, | |
393 kNumArguments, | |
394 kNoArgumentNames, | |
395 Resolver::kIsQualified); | |
396 isolate->object_store()->set_lookup_receive_port_function(function); | |
397 } | |
398 const Array& args = Array::Handle(Array::New(kNumArguments)); | |
399 args.SetAt(0, Integer::Handle(Integer::New(port_id))); | |
400 const Object& result = | |
401 Object::Handle(DartEntry::InvokeStatic(function, args)); | |
402 return result.raw(); | |
403 } | |
404 | |
405 | |
406 RawObject* DartLibraryCalls::HandleMessage(const Object& receive_port, | |
407 Dart_Port reply_port_id, | 375 Dart_Port reply_port_id, |
408 const Instance& message) { | 376 const Instance& message) { |
409 Isolate* isolate = Isolate::Current(); | 377 Isolate* isolate = Isolate::Current(); |
410 Function& function = | 378 Function& function = |
411 Function::Handle(isolate, | 379 Function::Handle(isolate, |
412 isolate->object_store()->handle_message_function()); | 380 isolate->object_store()->handle_message_function()); |
413 const int kNumArguments = 3; | 381 const int kNumArguments = 3; |
414 if (function.IsNull()) { | 382 if (function.IsNull()) { |
415 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 383 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); |
416 ASSERT(!isolate_lib.IsNull()); | 384 ASSERT(!isolate_lib.IsNull()); |
417 const String& public_class_name = | 385 const String& public_class_name = |
418 String::Handle(Symbols::New("_ReceivePortImpl")); | 386 String::Handle(Symbols::New("_ReceivePortImpl")); |
419 const String& class_name = | 387 const String& class_name = |
420 String::Handle(isolate_lib.PrivateName(public_class_name)); | 388 String::Handle(isolate_lib.PrivateName(public_class_name)); |
421 const String& function_name = | 389 const String& function_name = |
422 String::Handle(Symbols::New("_handleMessage")); | 390 String::Handle(Symbols::New("_handleMessage")); |
423 const Array& kNoArgumentNames = Array::Handle(); | 391 const Array& kNoArgumentNames = Array::Handle(); |
424 function = Resolver::ResolveStatic(isolate_lib, | 392 function = Resolver::ResolveStatic(isolate_lib, |
425 class_name, | 393 class_name, |
426 function_name, | 394 function_name, |
427 kNumArguments, | 395 kNumArguments, |
428 kNoArgumentNames, | 396 kNoArgumentNames, |
429 Resolver::kIsQualified); | 397 Resolver::kIsQualified); |
430 isolate->object_store()->set_handle_message_function(function); | 398 isolate->object_store()->set_handle_message_function(function); |
431 } | 399 } |
432 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); | 400 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); |
433 args.SetAt(0, receive_port); | 401 args.SetAt(0, Integer::Handle(isolate, Integer::New(dest_port_id))); |
434 args.SetAt(1, Integer::Handle(isolate, Integer::New(reply_port_id))); | 402 args.SetAt(1, Integer::Handle(isolate, Integer::New(reply_port_id))); |
435 args.SetAt(2, message); | 403 args.SetAt(2, message); |
436 const Object& result = | 404 const Object& result = |
437 Object::Handle(isolate, DartEntry::InvokeStatic(function, args)); | 405 Object::Handle(isolate, DartEntry::InvokeStatic(function, args)); |
438 ASSERT(result.IsNull() || result.IsError()); | 406 ASSERT(result.IsNull() || result.IsError()); |
439 return result.raw(); | 407 return result.raw(); |
440 } | 408 } |
441 | 409 |
442 | 410 |
443 RawObject* DartLibraryCalls::NewSendPort(intptr_t port_id) { | 411 RawObject* DartLibraryCalls::NewSendPort(intptr_t port_id) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 const String& func_name = String::Handle(Field::GetterName(field_name)); | 455 const String& func_name = String::Handle(Field::GetterName(field_name)); |
488 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); | 456 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); |
489 ASSERT(!func.IsNull()); | 457 ASSERT(!func.IsNull()); |
490 const Array& args = Array::Handle(Array::New(1)); | 458 const Array& args = Array::Handle(Array::New(1)); |
491 args.SetAt(0, port); | 459 args.SetAt(0, port); |
492 return DartEntry::InvokeDynamic(func, args); | 460 return DartEntry::InvokeDynamic(func, args); |
493 } | 461 } |
494 | 462 |
495 | 463 |
496 } // namespace dart | 464 } // namespace dart |
OLD | NEW |