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

Side by Side Diff: runtime/vm/exceptions.cc

Issue 10693071: Use VM type cast and save handles. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
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/exceptions.h" 5 #include "vm/exceptions.h"
6 6
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/debugger.h" 8 #include "vm/debugger.h"
9 #include "vm/flags.h" 9 #include "vm/flags.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 319
320 void Exceptions::ReThrow(const Instance& exception, 320 void Exceptions::ReThrow(const Instance& exception,
321 const Instance& stacktrace) { 321 const Instance& stacktrace) {
322 // Null object is a valid exception object. 322 // Null object is a valid exception object.
323 ThrowExceptionHelper(exception, stacktrace); 323 ThrowExceptionHelper(exception, stacktrace);
324 } 324 }
325 325
326 326
327 void Exceptions::PropagateError(const Object& obj) { 327 void Exceptions::PropagateError(const Object& obj) {
328 ASSERT(Isolate::Current()->top_exit_frame_info() != 0); 328 ASSERT(Isolate::Current()->top_exit_frame_info() != 0);
329 Error& error = Error::Handle(); 329 const Error& error = Error::Cast(obj);
330 error ^= obj.raw();
331 if (error.IsUnhandledException()) { 330 if (error.IsUnhandledException()) {
332 // If the error object represents an unhandled exception, then 331 // If the error object represents an unhandled exception, then
333 // rethrow the exception in the normal fashion. 332 // rethrow the exception in the normal fashion.
334 UnhandledException& uhe = UnhandledException::Handle(); 333 const UnhandledException& uhe = UnhandledException::Cast(obj);
335 uhe ^= error.raw();
336 const Instance& exc = Instance::Handle(uhe.exception()); 334 const Instance& exc = Instance::Handle(uhe.exception());
337 const Instance& stk = Instance::Handle(uhe.stacktrace()); 335 const Instance& stk = Instance::Handle(uhe.stacktrace());
338 Exceptions::ReThrow(exc, stk); 336 Exceptions::ReThrow(exc, stk);
339 } else { 337 } else {
340 // Return to the invocation stub and return this error object. The 338 // Return to the invocation stub and return this error object. The
341 // C++ code which invoked this dart sequence can check and do the 339 // C++ code which invoked this dart sequence can check and do the
342 // appropriate thing. 340 // appropriate thing.
343 uword handler_pc = 0; 341 uword handler_pc = 0;
344 uword handler_sp = 0; 342 uword handler_sp = 0;
345 uword handler_fp = 0; 343 uword handler_fp = 0;
346 FindErrorHandler(&handler_pc, &handler_sp, &handler_fp); 344 FindErrorHandler(&handler_pc, &handler_sp, &handler_fp);
347 JumpToErrorHandler(handler_pc, handler_sp, handler_fp, error); 345 JumpToErrorHandler(handler_pc, handler_sp, handler_fp, error);
348 } 346 }
349 UNREACHABLE(); 347 UNREACHABLE();
350 } 348 }
351 349
352 350
353 void Exceptions::ThrowByType( 351 void Exceptions::ThrowByType(
354 ExceptionType type, const GrowableArray<const Object*>& arguments) { 352 ExceptionType type, const GrowableArray<const Object*>& arguments) {
355 const Object& result = Object::Handle(Create(type, arguments)); 353 const Object& result = Object::Handle(Create(type, arguments));
356 if (result.IsError()) { 354 if (result.IsError()) {
357 // We got an error while constructing the exception object. 355 // We got an error while constructing the exception object.
358 // Propagate the error instead of throwing the exception. 356 // Propagate the error instead of throwing the exception.
359 Error& error = Error::Handle(); 357 PropagateError(result);
Ivan Posva 2012/07/02 21:01:38 I personally do not like how the type check and th
regis 2012/07/02 21:42:33 Done.
360 error ^= result.raw();
361 PropagateError(error);
362 } else { 358 } else {
363 ASSERT(result.IsInstance()); 359 ASSERT(result.IsInstance());
364 Instance& exception = Instance::Handle(); 360 Throw(Instance::Cast(result));
365 exception ^= result.raw();
366 Throw(exception);
367 } 361 }
368 } 362 }
369 363
370 364
371 RawObject* Exceptions::Create( 365 RawObject* Exceptions::Create(
372 ExceptionType type, const GrowableArray<const Object*>& arguments) { 366 ExceptionType type, const GrowableArray<const Object*>& arguments) {
373 Library& library = Library::Handle(); 367 Library& library = Library::Handle();
374 String& class_name = String::Handle(); 368 String& class_name = String::Handle();
375 switch (type) { 369 switch (type) {
376 case kIndexOutOfRange: 370 case kIndexOutOfRange:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 case kIsolateSpawn: 418 case kIsolateSpawn:
425 library = Library::IsolateLibrary(); 419 library = Library::IsolateLibrary();
426 class_name = String::NewSymbol("IsolateSpawnException"); 420 class_name = String::NewSymbol("IsolateSpawnException");
427 break; 421 break;
428 } 422 }
429 423
430 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); 424 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments);
431 } 425 }
432 426
433 } // namespace dart 427 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698