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

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
« no previous file with comments | « runtime/vm/exceptions.h ('k') | runtime/vm/intermediate_language.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/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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 317 }
318 318
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 Error& error) {
328 ASSERT(Isolate::Current()->top_exit_frame_info() != 0); 328 ASSERT(Isolate::Current()->top_exit_frame_info() != 0);
329 Error& error = Error::Handle();
330 error ^= obj.raw();
331 if (error.IsUnhandledException()) { 329 if (error.IsUnhandledException()) {
332 // If the error object represents an unhandled exception, then 330 // If the error object represents an unhandled exception, then
333 // rethrow the exception in the normal fashion. 331 // rethrow the exception in the normal fashion.
334 UnhandledException& uhe = UnhandledException::Handle(); 332 const UnhandledException& uhe = UnhandledException::Cast(error);
335 uhe ^= error.raw();
336 const Instance& exc = Instance::Handle(uhe.exception()); 333 const Instance& exc = Instance::Handle(uhe.exception());
337 const Instance& stk = Instance::Handle(uhe.stacktrace()); 334 const Instance& stk = Instance::Handle(uhe.stacktrace());
338 Exceptions::ReThrow(exc, stk); 335 Exceptions::ReThrow(exc, stk);
339 } else { 336 } else {
340 // Return to the invocation stub and return this error object. The 337 // Return to the invocation stub and return this error object. The
341 // C++ code which invoked this dart sequence can check and do the 338 // C++ code which invoked this dart sequence can check and do the
342 // appropriate thing. 339 // appropriate thing.
343 uword handler_pc = 0; 340 uword handler_pc = 0;
344 uword handler_sp = 0; 341 uword handler_sp = 0;
345 uword handler_fp = 0; 342 uword handler_fp = 0;
346 FindErrorHandler(&handler_pc, &handler_sp, &handler_fp); 343 FindErrorHandler(&handler_pc, &handler_sp, &handler_fp);
347 JumpToErrorHandler(handler_pc, handler_sp, handler_fp, error); 344 JumpToErrorHandler(handler_pc, handler_sp, handler_fp, error);
348 } 345 }
349 UNREACHABLE(); 346 UNREACHABLE();
350 } 347 }
351 348
352 349
353 void Exceptions::ThrowByType( 350 void Exceptions::ThrowByType(
354 ExceptionType type, const GrowableArray<const Object*>& arguments) { 351 ExceptionType type, const GrowableArray<const Object*>& arguments) {
355 const Object& result = Object::Handle(Create(type, arguments)); 352 const Object& result = Object::Handle(Create(type, arguments));
356 if (result.IsError()) { 353 if (result.IsError()) {
357 // We got an error while constructing the exception object. 354 // We got an error while constructing the exception object.
358 // Propagate the error instead of throwing the exception. 355 // Propagate the error instead of throwing the exception.
359 Error& error = Error::Handle(); 356 PropagateError(Error::Cast(result));
360 error ^= result.raw();
361 PropagateError(error);
362 } else { 357 } else {
363 ASSERT(result.IsInstance()); 358 ASSERT(result.IsInstance());
364 Instance& exception = Instance::Handle(); 359 Throw(Instance::Cast(result));
365 exception ^= result.raw();
366 Throw(exception);
367 } 360 }
368 } 361 }
369 362
370 363
371 RawObject* Exceptions::Create( 364 RawObject* Exceptions::Create(
372 ExceptionType type, const GrowableArray<const Object*>& arguments) { 365 ExceptionType type, const GrowableArray<const Object*>& arguments) {
373 Library& library = Library::Handle(); 366 Library& library = Library::Handle();
374 String& class_name = String::Handle(); 367 String& class_name = String::Handle();
375 switch (type) { 368 switch (type) {
376 case kIndexOutOfRange: 369 case kIndexOutOfRange:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 case kIsolateSpawn: 417 case kIsolateSpawn:
425 library = Library::IsolateLibrary(); 418 library = Library::IsolateLibrary();
426 class_name = String::NewSymbol("IsolateSpawnException"); 419 class_name = String::NewSymbol("IsolateSpawnException");
427 break; 420 break;
428 } 421 }
429 422
430 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); 423 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments);
431 } 424 }
432 425
433 } // namespace dart 426 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/exceptions.h ('k') | runtime/vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698