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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 bool HandleMessage(Message* message); | 43 bool HandleMessage(Message* message); |
44 | 44 |
45 #if defined(DEBUG) | 45 #if defined(DEBUG) |
46 // Check that it is safe to access this handler. | 46 // Check that it is safe to access this handler. |
47 void CheckAccess(); | 47 void CheckAccess(); |
48 #endif | 48 #endif |
49 bool IsCurrentIsolate() const; | 49 bool IsCurrentIsolate() const; |
50 virtual Isolate* GetIsolate() const { return isolate_; } | 50 virtual Isolate* GetIsolate() const { return isolate_; } |
51 | 51 |
52 private: | 52 private: |
| 53 bool ProcessUnhandledException(const Object& result); |
| 54 |
53 Isolate* isolate_; | 55 Isolate* isolate_; |
54 }; | 56 }; |
55 | 57 |
56 | 58 |
57 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) | 59 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) |
58 : isolate_(isolate) { | 60 : isolate_(isolate) { |
59 } | 61 } |
60 | 62 |
61 | 63 |
62 IsolateMessageHandler::~IsolateMessageHandler() { | 64 IsolateMessageHandler::~IsolateMessageHandler() { |
(...skipping 19 matching lines...) Expand all Loading... |
82 | 84 |
83 bool IsolateMessageHandler::HandleMessage(Message* message) { | 85 bool IsolateMessageHandler::HandleMessage(Message* message) { |
84 StartIsolateScope start_scope(isolate_); | 86 StartIsolateScope start_scope(isolate_); |
85 StackZone zone(isolate_); | 87 StackZone zone(isolate_); |
86 HandleScope handle_scope(isolate_); | 88 HandleScope handle_scope(isolate_); |
87 | 89 |
88 // Parse the message. | 90 // Parse the message. |
89 SnapshotReader reader(message->data(), message->len(), | 91 SnapshotReader reader(message->data(), message->len(), |
90 Snapshot::kMessage, Isolate::Current()); | 92 Snapshot::kMessage, Isolate::Current()); |
91 const Object& msg_obj = Object::Handle(reader.ReadObject()); | 93 const Object& msg_obj = Object::Handle(reader.ReadObject()); |
| 94 if (msg_obj.IsError()) { |
| 95 // An error occurred while reading the message. |
| 96 return ProcessUnhandledException(msg_obj); |
| 97 } |
92 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) { | 98 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) { |
93 // TODO(turnidge): We need to decide what an isolate does with | 99 // TODO(turnidge): We need to decide what an isolate does with |
94 // malformed messages. If they (eventually) come from a remote | 100 // malformed messages. If they (eventually) come from a remote |
95 // machine, then it might make sense to drop the message entirely. | 101 // machine, then it might make sense to drop the message entirely. |
96 // In the case that the message originated locally, which is | 102 // In the case that the message originated locally, which is |
97 // always true for now, then this should never occur. | 103 // always true for now, then this should never occur. |
98 UNREACHABLE(); | 104 UNREACHABLE(); |
99 } | 105 } |
100 | 106 |
101 Instance& msg = Instance::Handle(); | 107 Instance& msg = Instance::Handle(); |
102 msg ^= msg_obj.raw(); // Can't use Instance::Cast because may be null. | 108 msg ^= msg_obj.raw(); // Can't use Instance::Cast because may be null. |
103 | 109 |
104 if (message->IsOOB()) { | 110 if (message->IsOOB()) { |
105 // For now the only OOB messages are Mirrors messages. | 111 // For now the only OOB messages are Mirrors messages. |
106 HandleMirrorsMessage(isolate_, message->reply_port(), msg); | 112 HandleMirrorsMessage(isolate_, message->reply_port(), msg); |
107 delete message; | 113 delete message; |
108 } else { | 114 } else { |
109 const Object& result = Object::Handle( | 115 const Object& result = Object::Handle( |
110 DartLibraryCalls::HandleMessage( | 116 DartLibraryCalls::HandleMessage( |
111 message->dest_port(), message->reply_port(), msg)); | 117 message->dest_port(), message->reply_port(), msg)); |
112 delete message; | 118 delete message; |
113 if (result.IsError() || result.IsUnhandledException()) { | 119 if (result.IsError()) { |
114 if (result.IsError()) { | 120 return ProcessUnhandledException(result); |
115 isolate_->object_store()->set_sticky_error(Error::Cast(result)); | |
116 } | |
117 if (Isolate::UnhandledExceptionCallback() != NULL) { | |
118 Dart_EnterScope(); | |
119 Dart_Handle error = Api::NewHandle(isolate_, result.raw()); | |
120 (Isolate::UnhandledExceptionCallback())(error); | |
121 Dart_ExitScope(); | |
122 } | |
123 return false; | |
124 } | 121 } |
125 ASSERT(result.IsNull()); | 122 ASSERT(result.IsNull()); |
126 } | 123 } |
127 return true; | 124 return true; |
128 } | 125 } |
129 | 126 |
130 | 127 |
131 #if defined(DEBUG) | 128 #if defined(DEBUG) |
132 void IsolateMessageHandler::CheckAccess() { | 129 void IsolateMessageHandler::CheckAccess() { |
133 ASSERT(IsCurrentIsolate()); | 130 ASSERT(IsCurrentIsolate()); |
134 } | 131 } |
135 #endif | 132 #endif |
136 | 133 |
137 | 134 |
138 bool IsolateMessageHandler::IsCurrentIsolate() const { | 135 bool IsolateMessageHandler::IsCurrentIsolate() const { |
139 return (isolate_ == Isolate::Current()); | 136 return (isolate_ == Isolate::Current()); |
140 } | 137 } |
141 | 138 |
142 | 139 |
| 140 bool IsolateMessageHandler::ProcessUnhandledException(const Object& result) { |
| 141 isolate_->object_store()->set_sticky_error(Error::Cast(result)); |
| 142 // Invoke the dart unhandled exception callback if there is one. |
| 143 if (Isolate::UnhandledExceptionCallback() != NULL) { |
| 144 Dart_EnterScope(); |
| 145 Dart_Handle error = Api::NewHandle(isolate_, result.raw()); |
| 146 (Isolate::UnhandledExceptionCallback())(error); |
| 147 Dart_ExitScope(); |
| 148 } |
| 149 return false; |
| 150 } |
| 151 |
| 152 |
143 #if defined(DEBUG) | 153 #if defined(DEBUG) |
144 // static | 154 // static |
145 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { | 155 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { |
146 ASSERT(isolate == Isolate::Current()); | 156 ASSERT(isolate == Isolate::Current()); |
147 } | 157 } |
148 #endif | 158 #endif |
149 | 159 |
150 | 160 |
151 Isolate::Isolate() | 161 Isolate::Isolate() |
152 : store_buffer_block_(), | 162 : store_buffer_block_(), |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 511 |
502 | 512 |
503 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, | 513 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, |
504 bool visit_prologue_weak_handles) { | 514 bool visit_prologue_weak_handles) { |
505 if (api_state() != NULL) { | 515 if (api_state() != NULL) { |
506 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); | 516 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); |
507 } | 517 } |
508 } | 518 } |
509 | 519 |
510 } // namespace dart | 520 } // namespace dart |
OLD | NEW |