Chromium Code Reviews| 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 Dart_ClosePortCallback close_port_callback) { | 671 Dart_ClosePortCallback close_port_callback) { |
| 672 Isolate* isolate = Isolate::Current(); | 672 Isolate* isolate = Isolate::Current(); |
| 673 CHECK_ISOLATE(isolate); | 673 CHECK_ISOLATE(isolate); |
| 674 ASSERT(post_message_callback != NULL); | 674 ASSERT(post_message_callback != NULL); |
| 675 ASSERT(close_port_callback != NULL); | 675 ASSERT(close_port_callback != NULL); |
| 676 isolate->set_post_message_callback(post_message_callback); | 676 isolate->set_post_message_callback(post_message_callback); |
| 677 isolate->set_close_port_callback(close_port_callback); | 677 isolate->set_close_port_callback(close_port_callback); |
| 678 } | 678 } |
| 679 | 679 |
| 680 | 680 |
| 681 DART_EXPORT Dart_Handle Dart_RunLoop() { | |
| 682 Isolate* isolate = Isolate::Current(); | |
| 683 DARTSCOPE(isolate); | |
| 684 | |
| 685 LongJump* base = isolate->long_jump_base(); | |
| 686 LongJump jump; | |
| 687 Dart_Handle result; | |
| 688 isolate->set_long_jump_base(&jump); | |
| 689 if (setjmp(*jump.Set()) == 0) { | |
| 690 const Object& obj = Object::Handle(isolate->StandardRunLoop()); | |
| 691 if (obj.IsUnhandledException()) { | |
| 692 result = Api::ErrorFromException(obj); | |
| 693 } else { | |
| 694 ASSERT(obj.IsNull()); | |
| 695 result = Api::Success(); | |
| 696 } | |
| 697 } else { | |
| 698 SetupErrorResult(&result); | |
| 699 } | |
| 700 isolate->set_long_jump_base(base); | |
| 701 return result; | |
| 702 } | |
| 703 | |
| 704 | |
| 681 static RawInstance* DeserializeMessage(void* data) { | 705 static RawInstance* DeserializeMessage(void* data) { |
| 682 // Create a snapshot object using the buffer. | 706 // Create a snapshot object using the buffer. |
| 683 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | 707 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); |
| 684 ASSERT(snapshot->IsMessageSnapshot()); | 708 ASSERT(snapshot->IsMessageSnapshot()); |
| 685 | 709 |
| 686 // Read object back from the snapshot. | 710 // Read object back from the snapshot. |
| 687 Isolate* isolate = Isolate::Current(); | 711 Isolate* isolate = Isolate::Current(); |
| 688 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); | 712 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); |
| 689 Instance& instance = Instance::Handle(); | 713 Instance& instance = Instance::Handle(); |
| 690 instance ^= reader.ReadObject(); | 714 instance ^= reader.ReadObject(); |
| 691 return instance.raw(); | 715 return instance.raw(); |
| 692 } | 716 } |
| 693 | 717 |
| 694 | 718 |
| 695 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port_id, | 719 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port_id, |
| 696 Dart_Port reply_port_id, | 720 Dart_Port reply_port_id, |
| 697 Dart_Message dart_message) { | 721 Dart_Message dart_message) { |
| 698 DARTSCOPE(Isolate::Current()); | 722 DARTSCOPE(Isolate::Current()); |
| 699 | |
| 700 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); | 723 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); |
| 701 const String& class_name = | 724 // TODO(turnidge): Should this call should be wrapped in a longjmp? |
|
tobyr
2011/12/14 17:48:32
s/should be/be
turnidge
2011/12/14 18:26:55
Done.
| |
| 702 String::Handle(String::NewSymbol("ReceivePortImpl")); | 725 const Object& result = |
| 703 const String& function_name = | 726 Object::Handle(DartLibraryCalls::HandleMessage(dest_port_id, |
| 704 String::Handle(String::NewSymbol("_handleMessage")); | 727 reply_port_id, |
| 705 const int kNumArguments = 3; | 728 msg)); |
| 706 const Array& kNoArgumentNames = Array::Handle(); | |
| 707 const Function& function = Function::Handle( | |
| 708 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | |
| 709 class_name, | |
| 710 function_name, | |
| 711 kNumArguments, | |
| 712 kNoArgumentNames, | |
| 713 Resolver::kIsQualified)); | |
| 714 GrowableArray<const Object*> arguments(kNumArguments); | |
| 715 arguments.Add(&Integer::Handle(Integer::New(dest_port_id))); | |
| 716 arguments.Add(&Integer::Handle(Integer::New(reply_port_id))); | |
| 717 arguments.Add(&msg); | |
| 718 // TODO(turnidge): This call should be wrapped in a longjmp | |
| 719 const Object& result = Object::Handle( | |
| 720 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | |
| 721 if (result.IsUnhandledException()) { | 729 if (result.IsUnhandledException()) { |
| 722 return Api::ErrorFromException(result); | 730 return Api::ErrorFromException(result); |
| 723 } | 731 } |
| 724 ASSERT(result.IsNull()); | 732 ASSERT(result.IsNull()); |
| 725 return Api::Success(); | 733 return Api::Success(); |
| 726 } | 734 } |
| 727 | 735 |
| 728 | 736 |
| 729 DART_EXPORT Dart_Handle Dart_RunLoop() { | |
| 730 Isolate* isolate = Isolate::Current(); | |
| 731 DARTSCOPE(isolate); | |
| 732 | |
| 733 LongJump* base = isolate->long_jump_base(); | |
| 734 LongJump jump; | |
| 735 Dart_Handle result; | |
| 736 isolate->set_long_jump_base(&jump); | |
| 737 if (setjmp(*jump.Set()) == 0) { | |
| 738 isolate->StandardRunLoop(); | |
| 739 result = Api::Success(); | |
| 740 } else { | |
| 741 SetupErrorResult(&result); | |
| 742 } | |
| 743 isolate->set_long_jump_base(base); | |
| 744 return result; | |
| 745 } | |
| 746 | |
| 747 | |
| 748 DART_EXPORT bool Dart_HasLivePorts() { | 737 DART_EXPORT bool Dart_HasLivePorts() { |
| 749 Isolate* isolate = Isolate::Current(); | 738 Isolate* isolate = Isolate::Current(); |
| 750 ASSERT(isolate); | 739 ASSERT(isolate); |
| 751 return isolate->live_ports() > 0; | 740 return isolate->live_ports() > 0; |
| 752 } | 741 } |
| 753 | 742 |
| 754 | 743 |
| 755 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 744 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 756 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 745 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 757 return reinterpret_cast<uint8_t*>(new_ptr); | 746 return reinterpret_cast<uint8_t*>(new_ptr); |
| (...skipping 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2514 } | 2503 } |
| 2515 delete debug_region; | 2504 delete debug_region; |
| 2516 } else { | 2505 } else { |
| 2517 *buffer = NULL; | 2506 *buffer = NULL; |
| 2518 *buffer_size = 0; | 2507 *buffer_size = 0; |
| 2519 } | 2508 } |
| 2520 } | 2509 } |
| 2521 | 2510 |
| 2522 | 2511 |
| 2523 } // namespace dart | 2512 } // namespace dart |
| OLD | NEW |