Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: runtime/lib/isolate.cc

Issue 9148048: Standardize error printing a bit by moving it to the Error object and (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart.h" 9 #include "vm/dart.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 static uint8_t* SerializeObject(const Instance& obj) { 47 static uint8_t* SerializeObject(const Instance& obj) {
48 uint8_t* result = NULL; 48 uint8_t* result = NULL;
49 SnapshotWriter writer(Snapshot::kMessage, &result, &allocator); 49 SnapshotWriter writer(Snapshot::kMessage, &result, &allocator);
50 writer.WriteObject(obj.raw()); 50 writer.WriteObject(obj.raw());
51 writer.FinalizeBuffer(); 51 writer.FinalizeBuffer();
52 return result; 52 return result;
53 } 53 }
54 54
55 55
56 static void ProcessUnhandledException(const UnhandledException& uhe) { 56 static void ProcessError(const Object& obj) {
57 const Instance& exception = Instance::Handle(uhe.exception()); 57 ASSERT(obj.IsError());
58 Instance& string = Instance::Handle(DartLibraryCalls::ToString(exception)); 58 Error& error = Error::Handle();
59 const char* str = string.ToCString(); 59 error ^= obj.raw();
60 fprintf(stderr, "%s\n", str); 60 fprintf(stderr, "%s\n", error.ToErrorCString());
cshapiro 2012/01/12 00:37:39 Why not use OS::PrintErr instead of fprintf?
turnidge 2012/01/12 19:15:39 Done.
61 const Instance& stack = Instance::Handle(uhe.stacktrace());
62 string = DartLibraryCalls::ToString(stack);
63 str = string.ToCString();
64 fprintf(stderr, "%s\n", str);
65 exit(255); 61 exit(255);
66 } 62 }
67 63
68 64
69 static void ThrowErrorException(Exceptions::ExceptionType type, 65 static void ThrowErrorException(Exceptions::ExceptionType type,
70 const char* error_msg, 66 const char* error_msg,
71 const char* library_url, 67 const char* library_url,
72 const char* class_name) { 68 const char* class_name) {
73 String& str = String::Handle(); 69 String& str = String::Handle();
74 String& name = String::Handle(); 70 String& name = String::Handle();
(...skipping 21 matching lines...) Expand all
96 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), 92 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()),
97 class_name, 93 class_name,
98 function_name, 94 function_name,
99 kNumArguments, 95 kNumArguments,
100 kNoArgumentNames, 96 kNoArgumentNames,
101 Resolver::kIsQualified)); 97 Resolver::kIsQualified));
102 GrowableArray<const Object*> arguments(kNumArguments); 98 GrowableArray<const Object*> arguments(kNumArguments);
103 arguments.Add(&Integer::Handle(Integer::New(port_id))); 99 arguments.Add(&Integer::Handle(Integer::New(port_id)));
104 const Instance& result = Instance::Handle( 100 const Instance& result = Instance::Handle(
105 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); 101 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
106 if (result.IsUnhandledException()) { 102 if (result.IsError()) {
107 UnhandledException& uhe = UnhandledException::Handle(); 103 ProcessError(result);
108 uhe ^= result.raw();
109 ProcessUnhandledException(uhe);
110 } else { 104 } else {
111 PortMap::SetLive(port_id); 105 PortMap::SetLive(port_id);
112 } 106 }
113 return result.raw(); 107 return result.raw();
114 } 108 }
115 109
116 110
117 static RawInstance* SendPortCreate(intptr_t port_id) { 111 static RawInstance* SendPortCreate(intptr_t port_id) {
118 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl")); 112 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl"));
119 const String& function_name = String::Handle(String::NewSymbol("_create")); 113 const String& function_name = String::Handle(String::NewSymbol("_create"));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 const Function& default_constructor = 165 const Function& default_constructor =
172 Function::Handle(target_class.LookupConstructor(constructor_name)); 166 Function::Handle(target_class.LookupConstructor(constructor_name));
173 if (!default_constructor.IsNull()) { 167 if (!default_constructor.IsNull()) {
174 GrowableArray<const Object*> arguments(1); 168 GrowableArray<const Object*> arguments(1);
175 arguments.Add(&target); 169 arguments.Add(&target);
176 arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll))); 170 arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
177 const Array& kNoArgumentNames = Array::Handle(); 171 const Array& kNoArgumentNames = Array::Handle();
178 result = DartEntry::InvokeStatic(default_constructor, 172 result = DartEntry::InvokeStatic(default_constructor,
179 arguments, 173 arguments,
180 kNoArgumentNames); 174 kNoArgumentNames);
181 if (result.IsUnhandledException()) { 175 if (result.IsError()) {
182 UnhandledException& uhe = UnhandledException::Handle(); 176 ProcessError(result);
183 uhe ^= result.raw();
184 ProcessUnhandledException(uhe);
185 } 177 }
186 ASSERT(result.IsNull()); 178 ASSERT(result.IsNull());
187 } 179 }
188 180
189 // Invoke the "_run" method. 181 // Invoke the "_run" method.
190 const Function& target_function = Function::Handle(Resolver::ResolveDynamic( 182 const Function& target_function = Function::Handle(Resolver::ResolveDynamic(
191 target, String::Handle(String::NewSymbol("_run")), 2, 0)); 183 target, String::Handle(String::NewSymbol("_run")), 2, 0));
192 // TODO(iposva): Proper error checking here. 184 // TODO(iposva): Proper error checking here.
193 ASSERT(!target_function.IsNull()); 185 ASSERT(!target_function.IsNull());
194 // TODO(iposva): Allocate the proper port number here. 186 // TODO(iposva): Allocate the proper port number here.
195 const Instance& local_port = Instance::Handle(ReceivePortCreate(port_id)); 187 const Instance& local_port = Instance::Handle(ReceivePortCreate(port_id));
196 GrowableArray<const Object*> arguments(1); 188 GrowableArray<const Object*> arguments(1);
197 arguments.Add(&local_port); 189 arguments.Add(&local_port);
198 const Array& kNoArgumentNames = Array::Handle(); 190 const Array& kNoArgumentNames = Array::Handle();
199 result = DartEntry::InvokeDynamic(target, 191 result = DartEntry::InvokeDynamic(target,
200 target_function, 192 target_function,
201 arguments, 193 arguments,
202 kNoArgumentNames); 194 kNoArgumentNames);
203 if (result.IsUnhandledException()) { 195 if (result.IsError()) {
204 UnhandledException& uhe = UnhandledException::Handle(); 196 ProcessError(result);
205 uhe ^= result.raw();
206 ProcessUnhandledException(uhe);
207 } 197 }
208 ASSERT(result.IsNull()); 198 ASSERT(result.IsNull());
209 free(class_name); 199 free(class_name);
210 result = isolate->StandardRunLoop(); 200 result = isolate->StandardRunLoop();
211 if (result.IsUnhandledException()) { 201 if (result.IsError()) {
212 UnhandledException& uhe = UnhandledException::Handle(); 202 ProcessError(result);
213 uhe ^= result.raw();
214 ProcessUnhandledException(uhe);
215 } 203 }
216 ASSERT(result.IsNull()); 204 ASSERT(result.IsNull());
217 205
218 } else { 206 } else {
219 Zone zone(isolate); 207 Zone zone(isolate);
220 HandleScope handle_scope(isolate); 208 HandleScope handle_scope(isolate);
221 const String& error = String::Handle( 209 const String& error = String::Handle(
222 Isolate::Current()->object_store()->sticky_error()); 210 Isolate::Current()->object_store()->sticky_error());
223 const char* errmsg = error.ToCString(); 211 const char* errmsg = error.ToCString();
224 fprintf(stderr, "%s\n", errmsg); 212 fprintf(stderr, "%s\n", errmsg);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // Switch back to the original isolate and return. 298 // Switch back to the original isolate and return.
311 Isolate::SetCurrent(preserved_isolate); 299 Isolate::SetCurrent(preserved_isolate);
312 if (spawned_isolate == NULL) { 300 if (spawned_isolate == NULL) {
313 // Unable to spawn isolate correctly, throw exception. 301 // Unable to spawn isolate correctly, throw exception.
314 ThrowErrorException(Exceptions::kIllegalArgument, 302 ThrowErrorException(Exceptions::kIllegalArgument,
315 error, 303 error,
316 library_url, 304 library_url,
317 class_name); 305 class_name);
318 } 306 }
319 const Instance& port = Instance::Handle(SendPortCreate(port_id)); 307 const Instance& port = Instance::Handle(SendPortCreate(port_id));
320 if (port.IsUnhandledException()) { 308 if (port.IsError()) {
321 ThrowErrorException(Exceptions::kInternalError, 309 if (port.IsUnhandledException()) {
322 "Unable to create send port to isolate", 310 ThrowErrorException(Exceptions::kInternalError,
323 library_url, 311 "Unable to create send port to isolate",
324 class_name); 312 library_url,
313 class_name);
314 } else {
315 ProcessError(port);
316 }
325 } 317 }
326 arguments->SetReturn(port); 318 arguments->SetReturn(port);
327 } 319 }
328 320
329 321
330 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { 322 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) {
331 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); 323 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull());
332 intptr_t port_id = PortMap::CreatePort(); 324 intptr_t port_id = PortMap::CreatePort();
333 const Instance& port = Instance::Handle(ReceivePortCreate(port_id)); 325 const Instance& port = Instance::Handle(ReceivePortCreate(port_id));
334 arguments->SetReturn(port); 326 arguments->SetReturn(port);
(...skipping 10 matching lines...) Expand all
345 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); 337 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value();
346 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); 338 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value();
347 // TODO(iposva): Allow for arbitrary messages to be sent. 339 // TODO(iposva): Allow for arbitrary messages to be sent.
348 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); 340 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2)));
349 341
350 // TODO(turnidge): Throw an exception when the return value is false? 342 // TODO(turnidge): Throw an exception when the return value is false?
351 PortMap::PostMessage(send_id, reply_id, Api::CastMessage(data)); 343 PortMap::PostMessage(send_id, reply_id, Api::CastMessage(data));
352 } 344 }
353 345
354 } // namespace dart 346 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698