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

Side by Side 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, 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/flow_graph_builder.h » ('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/cpu.h" 7 #include "vm/cpu.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/debugger.h" 9 #include "vm/debugger.h"
10 #include "vm/flags.h" 10 #include "vm/flags.h"
11 #include "vm/object.h" 11 #include "vm/object.h"
12 #include "vm/stack_frame.h" 12 #include "vm/stack_frame.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 DEFINE_FLAG(bool, print_stack_trace_at_throw, false, 16 DEFINE_FLAG(bool, print_stack_trace_at_throw, false,
17 "Prints a stack trace everytime a throw occurs."); 17 "Prints a stack trace everytime a throw occurs.");
18 18
19
20 const char* Exceptions::kCastExceptionDstName = "type cast";
21
22
19 // Iterate through the stack frames and try to find a frame with an 23 // Iterate through the stack frames and try to find a frame with an
20 // exception handler. Once found, set the pc, sp and fp so that execution 24 // exception handler. Once found, set the pc, sp and fp so that execution
21 // can continue in that frame. 25 // can continue in that frame.
22 static bool FindExceptionHandler(uword* handler_pc, 26 static bool FindExceptionHandler(uword* handler_pc,
23 uword* handler_sp, 27 uword* handler_sp,
24 uword* handler_fp, 28 uword* handler_fp,
25 GrowableArray<uword>* stack_frame_pcs) { 29 GrowableArray<uword>* stack_frame_pcs) {
26 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); 30 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames);
27 StackFrame* frame = frames.NextFrame(); 31 StackFrame* frame = frames.NextFrame();
28 ASSERT(frame != NULL); 32 ASSERT(frame != NULL);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 SetField(instance, cls, "column", Smi::Handle(Smi::New(column))); 179 SetField(instance, cls, "column", Smi::Handle(Smi::New(column)));
176 } 180 }
177 181
178 182
179 // Allocate, initialize, and throw a TypeError. 183 // Allocate, initialize, and throw a TypeError.
180 void Exceptions::CreateAndThrowTypeError(intptr_t location, 184 void Exceptions::CreateAndThrowTypeError(intptr_t location,
181 const String& src_type_name, 185 const String& src_type_name,
182 const String& dst_type_name, 186 const String& dst_type_name,
183 const String& dst_name, 187 const String& dst_name,
184 const String& malformed_error) { 188 const String& malformed_error) {
185 // Allocate a new instance of TypeError. 189 // Allocate a new instance of TypeError or CastException.
186 const Instance& type_error = Instance::Handle(NewInstance("TypeError")); 190 Instance& type_error = Instance::Handle();
191 Class& cls = Class::Handle();
192 if (dst_name.Equals(kCastExceptionDstName)) {
193 type_error = NewInstance("CastException");
194 cls = type_error.clazz();
195 cls = cls.SuperClass();
196 } else {
197 type_error = NewInstance("TypeError");
198 cls = type_error.clazz();
199 }
187 200
188 // Initialize 'url', 'line', and 'column' fields. 201 // Initialize 'url', 'line', and 'column' fields.
189 DartFrameIterator iterator; 202 DartFrameIterator iterator;
190 const Script& script = Script::Handle(GetCallerScript(&iterator)); 203 const Script& script = Script::Handle(GetCallerScript(&iterator));
191 const Class& cls = Class::Handle(type_error.clazz());
192 // Location fields are defined in AssertionError, the superclass of TypeError. 204 // Location fields are defined in AssertionError, the superclass of TypeError.
193 const Class& assertion_error_class = Class::Handle(cls.SuperClass()); 205 const Class& assertion_error_class = Class::Handle(cls.SuperClass());
194 SetLocationFields(type_error, assertion_error_class, script, location); 206 SetLocationFields(type_error, assertion_error_class, script, location);
195 207
196 // Initialize field 'failedAssertion' in AssertionError superclass. 208 // Initialize field 'failedAssertion' in AssertionError superclass.
197 // Printing the src_obj value would be possible, but ToString() is expensive 209 // Printing the src_obj value would be possible, but ToString() is expensive
198 // and not meaningful for all classes, so we just print '$expr instanceof...'. 210 // and not meaningful for all classes, so we just print '$expr instanceof...'.
199 // Users should look at TypeError.ToString(), which contains more useful 211 // Users should look at TypeError.ToString(), which contains more useful
200 // information than AssertionError.failedAssertion. 212 // information than AssertionError.failedAssertion.
201 String& failed_assertion = String::Handle(String::New("$expr instanceof ")); 213 String& failed_assertion = String::Handle(String::New("$expr instanceof "));
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 case kIsolateSpawn: 371 case kIsolateSpawn:
360 library = Library::IsolateLibrary(); 372 library = Library::IsolateLibrary();
361 class_name = String::NewSymbol("IsolateSpawnException"); 373 class_name = String::NewSymbol("IsolateSpawnException");
362 break; 374 break;
363 } 375 }
364 376
365 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); 377 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments);
366 } 378 }
367 379
368 } // namespace dart 380 } // namespace dart
OLDNEW
« 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