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

Unified Diff: runtime/vm/exceptions.cc

Issue 10659005: Implement type cast in the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/exceptions.h ('k') | runtime/vm/flow_graph_builder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/exceptions.cc
===================================================================
--- runtime/vm/exceptions.cc (revision 9069)
+++ runtime/vm/exceptions.cc (working copy)
@@ -16,6 +16,10 @@
DEFINE_FLAG(bool, print_stack_trace_at_throw, false,
"Prints a stack trace everytime a throw occurs.");
+
+const char* Exceptions::kCastExceptionDstName = "type cast";
+
+
// Iterate through the stack frames and try to find a frame with an
// exception handler. Once found, set the pc, sp and fp so that execution
// can continue in that frame.
@@ -182,13 +186,21 @@
const String& dst_type_name,
const String& dst_name,
const String& malformed_error) {
- // Allocate a new instance of TypeError.
- const Instance& type_error = Instance::Handle(NewInstance("TypeError"));
+ // Allocate a new instance of TypeError or CastException.
+ Instance& type_error = Instance::Handle();
+ Class& cls = Class::Handle();
+ if (dst_name.Equals(kCastExceptionDstName)) {
+ type_error = NewInstance("CastException");
+ cls = type_error.clazz();
+ cls = cls.SuperClass();
+ } else {
+ type_error = NewInstance("TypeError");
+ cls = type_error.clazz();
+ }
// Initialize 'url', 'line', and 'column' fields.
DartFrameIterator iterator;
const Script& script = Script::Handle(GetCallerScript(&iterator));
- const Class& cls = Class::Handle(type_error.clazz());
// Location fields are defined in AssertionError, the superclass of TypeError.
const Class& assertion_error_class = Class::Handle(cls.SuperClass());
SetLocationFields(type_error, assertion_error_class, script, location);
« no previous file with comments | « runtime/vm/exceptions.h ('k') | runtime/vm/flow_graph_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698