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 "vm/isolate.h" | 5 #include "vm/isolate.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "lib/mirrors.h" | 9 #include "lib/mirrors.h" |
10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt); | 73 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt); |
74 } | 74 } |
75 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback(); | 75 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback(); |
76 if (callback) { | 76 if (callback) { |
77 // Allow the embedder to handle message notification. | 77 // Allow the embedder to handle message notification. |
78 (*callback)(Api::CastIsolate(isolate_)); | 78 (*callback)(Api::CastIsolate(isolate_)); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 static RawInstance* DeserializeMessage(void* data) { | |
84 // Create a snapshot object using the buffer. | |
85 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | |
86 ASSERT(snapshot->IsMessageSnapshot()); | |
87 | |
88 // Read object back from the snapshot. | |
89 SnapshotReader reader(snapshot, Isolate::Current()); | |
90 Instance& instance = Instance::Handle(); | |
91 instance ^= reader.ReadObject(); | |
92 return instance.raw(); | |
93 } | |
94 | |
95 | |
96 bool IsolateMessageHandler::HandleMessage(Message* message) { | 83 bool IsolateMessageHandler::HandleMessage(Message* message) { |
97 StartIsolateScope start_scope(isolate_); | 84 StartIsolateScope start_scope(isolate_); |
98 Zone zone(isolate_); | 85 Zone zone(isolate_); |
99 HandleScope handle_scope(isolate_); | 86 HandleScope handle_scope(isolate_); |
100 | 87 |
101 const Instance& msg = | 88 const Snapshot* snapshot = Snapshot::SetupFromBuffer(message->data(), |
102 Instance::Handle(DeserializeMessage(message->data())); | 89 message->len()); |
90 if (snapshot == NULL || !snapshot->IsMessageSnapshot()) { | |
91 if (message->IsLocal()) { | |
92 FATAL("IsolateMessageHandler saw malformed message. Exiting."); | |
siva
2012/08/22 23:30:39
Do these really need to be fatal errors?
We could
turnidge
2012/08/23 18:37:57
I believe it should be fatal, yes. Made this UNRE
| |
93 } | |
94 delete message; | |
95 return true; | |
96 } | |
97 | |
98 // Read object back from the snapshot. | |
99 SnapshotReader reader(snapshot, Isolate::Current()); | |
100 const Object& msg_obj = Object::Handle(reader.ReadObject()); | |
101 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) { | |
102 if (message->IsLocal()) { | |
103 FATAL("IsolateMessageHandler saw malformed message. Exiting."); | |
siva
2012/08/22 23:30:39
Ditto comment.
turnidge
2012/08/23 18:37:57
This goes away in new revision.
| |
104 } | |
105 delete message; | |
106 return true; | |
107 } | |
108 | |
109 Instance& msg = Instance::Handle(); | |
110 msg ^= msg_obj.raw(); // Can't use Instance::Cast because may be null. | |
111 | |
103 if (message->IsOOB()) { | 112 if (message->IsOOB()) { |
104 // For now the only OOB messages are Mirrors messages. | 113 // For now the only OOB messages are Mirrors messages. |
105 HandleMirrorsMessage(isolate_, message->reply_port(), msg); | 114 HandleMirrorsMessage(isolate_, message->reply_port(), msg); |
106 delete message; | 115 delete message; |
107 } else { | 116 } else { |
108 const Object& result = Object::Handle( | 117 const Object& result = Object::Handle( |
109 DartLibraryCalls::HandleMessage( | 118 DartLibraryCalls::HandleMessage( |
110 message->dest_port(), message->reply_port(), msg)); | 119 message->dest_port(), message->reply_port(), msg)); |
111 delete message; | 120 delete message; |
112 if (result.IsError()) { | 121 if (result.IsError()) { |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 | 477 |
469 | 478 |
470 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, | 479 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, |
471 bool visit_prologue_weak_handles) { | 480 bool visit_prologue_weak_handles) { |
472 if (api_state() != NULL) { | 481 if (api_state() != NULL) { |
473 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); | 482 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); |
474 } | 483 } |
475 } | 484 } |
476 | 485 |
477 } // namespace dart | 486 } // namespace dart |
OLD | NEW |