| OLD | NEW |
| 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" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 SetField(instance, cls, "column", Smi::Handle(Smi::New(column))); | 175 SetField(instance, cls, "column", Smi::Handle(Smi::New(column))); |
| 176 } | 176 } |
| 177 | 177 |
| 178 | 178 |
| 179 // Allocate, initialize, and throw a TypeError. | 179 // Allocate, initialize, and throw a TypeError. |
| 180 void Exceptions::CreateAndThrowTypeError(intptr_t location, | 180 void Exceptions::CreateAndThrowTypeError(intptr_t location, |
| 181 const String& src_type_name, | 181 const String& src_type_name, |
| 182 const String& dst_type_name, | 182 const String& dst_type_name, |
| 183 const String& dst_name, | 183 const String& dst_name, |
| 184 const String& malformed_error) { | 184 const String& malformed_error) { |
| 185 // Allocate a new instance of TypeError. | 185 // Allocate a new instance of TypeError or CastException. |
| 186 const Instance& type_error = Instance::Handle(NewInstance("TypeError")); | 186 Instance& type_error = Instance::Handle(); |
| 187 Class& cls = Class::Handle(); |
| 188 if (dst_name.Equals("type cast")) { |
| 189 type_error = NewInstance("CastException"); |
| 190 cls = type_error.clazz(); |
| 191 cls = cls.SuperClass(); |
| 192 } else { |
| 193 type_error = NewInstance("TypeError"); |
| 194 cls = type_error.clazz(); |
| 195 } |
| 187 | 196 |
| 188 // Initialize 'url', 'line', and 'column' fields. | 197 // Initialize 'url', 'line', and 'column' fields. |
| 189 DartFrameIterator iterator; | 198 DartFrameIterator iterator; |
| 190 const Script& script = Script::Handle(GetCallerScript(&iterator)); | 199 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. | 200 // Location fields are defined in AssertionError, the superclass of TypeError. |
| 193 const Class& assertion_error_class = Class::Handle(cls.SuperClass()); | 201 const Class& assertion_error_class = Class::Handle(cls.SuperClass()); |
| 194 SetLocationFields(type_error, assertion_error_class, script, location); | 202 SetLocationFields(type_error, assertion_error_class, script, location); |
| 195 | 203 |
| 196 // Initialize field 'failedAssertion' in AssertionError superclass. | 204 // Initialize field 'failedAssertion' in AssertionError superclass. |
| 197 // Printing the src_obj value would be possible, but ToString() is expensive | 205 // 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...'. | 206 // and not meaningful for all classes, so we just print '$expr instanceof...'. |
| 199 // Users should look at TypeError.ToString(), which contains more useful | 207 // Users should look at TypeError.ToString(), which contains more useful |
| 200 // information than AssertionError.failedAssertion. | 208 // information than AssertionError.failedAssertion. |
| 201 String& failed_assertion = String::Handle(String::New("$expr instanceof ")); | 209 String& failed_assertion = String::Handle(String::New("$expr instanceof ")); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 case kIsolateSpawn: | 367 case kIsolateSpawn: |
| 360 library = Library::IsolateLibrary(); | 368 library = Library::IsolateLibrary(); |
| 361 class_name = String::NewSymbol("IsolateSpawnException"); | 369 class_name = String::NewSymbol("IsolateSpawnException"); |
| 362 break; | 370 break; |
| 363 } | 371 } |
| 364 | 372 |
| 365 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); | 373 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); |
| 366 } | 374 } |
| 367 | 375 |
| 368 } // namespace dart | 376 } // namespace dart |
| OLD | NEW |