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/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" |
11 #include "vm/stack_frame.h" | 11 #include "vm/stack_frame.h" |
12 #include "vm/stub_code.h" | 12 #include "vm/stub_code.h" |
| 13 #include "vm/symbols.h" |
13 | 14 |
14 namespace dart { | 15 namespace dart { |
15 | 16 |
16 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, | 17 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, |
17 "Prints a stack trace everytime a throw occurs."); | 18 "Prints a stack trace everytime a throw occurs."); |
18 | 19 |
19 | 20 |
20 const char* Exceptions::kCastExceptionDstName = "type cast"; | 21 const char* Exceptions::kCastExceptionDstName = "type cast"; |
21 | 22 |
22 | 23 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 ASSERT(!caller.IsNull()); | 192 ASSERT(!caller.IsNull()); |
192 const Class& caller_class = Class::Handle(caller.owner()); | 193 const Class& caller_class = Class::Handle(caller.owner()); |
193 return caller_class.script(); | 194 return caller_class.script(); |
194 } | 195 } |
195 | 196 |
196 | 197 |
197 // Allocate a new instance of the given class name. | 198 // Allocate a new instance of the given class name. |
198 // TODO(hausner): Rename this NewCoreInstance to call out the fact that | 199 // TODO(hausner): Rename this NewCoreInstance to call out the fact that |
199 // the class name is resolved in the core library implicitly? | 200 // the class name is resolved in the core library implicitly? |
200 RawInstance* Exceptions::NewInstance(const char* class_name) { | 201 RawInstance* Exceptions::NewInstance(const char* class_name) { |
201 const String& cls_name = String::Handle(String::NewSymbol(class_name)); | 202 const String& cls_name = String::Handle(Symbols::New(class_name)); |
202 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 203 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
203 Class& cls = Class::Handle(core_lib.LookupClass(cls_name)); | 204 Class& cls = Class::Handle(core_lib.LookupClass(cls_name)); |
204 ASSERT(!cls.IsNull()); | 205 ASSERT(!cls.IsNull()); |
205 // There are no parameterized error types, so no need to set type arguments. | 206 // There are no parameterized error types, so no need to set type arguments. |
206 return Instance::New(cls); | 207 return Instance::New(cls); |
207 } | 208 } |
208 | 209 |
209 | 210 |
210 // Assign the value to the field given by its name in the given instance. | 211 // Assign the value to the field given by its name in the given instance. |
211 void Exceptions::SetField(const Instance& instance, | 212 void Exceptions::SetField(const Instance& instance, |
212 const Class& cls, | 213 const Class& cls, |
213 const char* field_name, | 214 const char* field_name, |
214 const Object& value) { | 215 const Object& value) { |
215 const Field& field = Field::Handle(cls.LookupInstanceField( | 216 const Field& field = Field::Handle(cls.LookupInstanceField( |
216 String::Handle(String::NewSymbol(field_name)))); | 217 String::Handle(Symbols::New(field_name)))); |
217 ASSERT(!field.IsNull()); | 218 ASSERT(!field.IsNull()); |
218 instance.SetField(field, value); | 219 instance.SetField(field, value); |
219 } | 220 } |
220 | 221 |
221 | 222 |
222 // Initialize the fields 'url', 'line', and 'column' in the given instance | 223 // Initialize the fields 'url', 'line', and 'column' in the given instance |
223 // according to the given token location in the given script. | 224 // according to the given token location in the given script. |
224 void Exceptions::SetLocationFields(const Instance& instance, | 225 void Exceptions::SetLocationFields(const Instance& instance, |
225 const Class& cls, | 226 const Class& cls, |
226 const Script& script, | 227 const Script& script, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 } | 362 } |
362 | 363 |
363 | 364 |
364 RawObject* Exceptions::Create( | 365 RawObject* Exceptions::Create( |
365 ExceptionType type, const GrowableArray<const Object*>& arguments) { | 366 ExceptionType type, const GrowableArray<const Object*>& arguments) { |
366 Library& library = Library::Handle(); | 367 Library& library = Library::Handle(); |
367 String& class_name = String::Handle(); | 368 String& class_name = String::Handle(); |
368 switch (type) { | 369 switch (type) { |
369 case kIndexOutOfRange: | 370 case kIndexOutOfRange: |
370 library = Library::CoreLibrary(); | 371 library = Library::CoreLibrary(); |
371 class_name = String::NewSymbol("IndexOutOfRangeException"); | 372 class_name = Symbols::New("IndexOutOfRangeException"); |
372 break; | 373 break; |
373 case kIllegalArgument: | 374 case kIllegalArgument: |
374 library = Library::CoreLibrary(); | 375 library = Library::CoreLibrary(); |
375 class_name = String::NewSymbol("IllegalArgumentException"); | 376 class_name = Symbols::New("IllegalArgumentException"); |
376 break; | 377 break; |
377 case kNoSuchMethod: | 378 case kNoSuchMethod: |
378 library = Library::CoreLibrary(); | 379 library = Library::CoreLibrary(); |
379 class_name = String::NewSymbol("NoSuchMethodException"); | 380 class_name = Symbols::New("NoSuchMethodException"); |
380 break; | 381 break; |
381 case kClosureArgumentMismatch: | 382 case kClosureArgumentMismatch: |
382 library = Library::CoreLibrary(); | 383 library = Library::CoreLibrary(); |
383 class_name = String::NewSymbol("ClosureArgumentMismatchException"); | 384 class_name = Symbols::New("ClosureArgumentMismatchException"); |
384 break; | 385 break; |
385 case kObjectNotClosure: | 386 case kObjectNotClosure: |
386 library = Library::CoreLibrary(); | 387 library = Library::CoreLibrary(); |
387 class_name = String::NewSymbol("ObjectNotClosureException"); | 388 class_name = Symbols::New("ObjectNotClosureException"); |
388 break; | 389 break; |
389 case kBadNumberFormat: | 390 case kBadNumberFormat: |
390 library = Library::CoreLibrary(); | 391 library = Library::CoreLibrary(); |
391 class_name = String::NewSymbol("BadNumberFormatException"); | 392 class_name = Symbols::New("BadNumberFormatException"); |
392 break; | 393 break; |
393 case kStackOverflow: | 394 case kStackOverflow: |
394 library = Library::CoreLibrary(); | 395 library = Library::CoreLibrary(); |
395 class_name = String::NewSymbol("StackOverflowException"); | 396 class_name = Symbols::New("StackOverflowException"); |
396 break; | 397 break; |
397 case kOutOfMemory: | 398 case kOutOfMemory: |
398 library = Library::CoreLibrary(); | 399 library = Library::CoreLibrary(); |
399 class_name = String::NewSymbol("OutOfMemoryException"); | 400 class_name = Symbols::New("OutOfMemoryException"); |
400 break; | 401 break; |
401 case kWrongArgumentCount: | 402 case kWrongArgumentCount: |
402 library = Library::CoreLibrary(); | 403 library = Library::CoreLibrary(); |
403 class_name = String::NewSymbol("WrongArgumentCountException"); | 404 class_name = Symbols::New("WrongArgumentCountException"); |
404 break; | 405 break; |
405 case kInternalError: | 406 case kInternalError: |
406 library = Library::CoreLibrary(); | 407 library = Library::CoreLibrary(); |
407 class_name = String::NewSymbol("InternalError"); | 408 class_name = Symbols::New("InternalError"); |
408 break; | 409 break; |
409 case kNullPointer: | 410 case kNullPointer: |
410 library = Library::CoreLibrary(); | 411 library = Library::CoreLibrary(); |
411 class_name = String::NewSymbol("NullPointerException"); | 412 class_name = Symbols::New("NullPointerException"); |
412 break; | 413 break; |
413 case kIllegalJSRegExp: | 414 case kIllegalJSRegExp: |
414 library = Library::CoreLibrary(); | 415 library = Library::CoreLibrary(); |
415 class_name = String::NewSymbol("IllegalJSRegExpException"); | 416 class_name = Symbols::New("IllegalJSRegExpException"); |
416 break; | 417 break; |
417 case kIsolateSpawn: | 418 case kIsolateSpawn: |
418 library = Library::IsolateLibrary(); | 419 library = Library::IsolateLibrary(); |
419 class_name = String::NewSymbol("IsolateSpawnException"); | 420 class_name = Symbols::New("IsolateSpawnException"); |
420 break; | 421 break; |
421 } | 422 } |
422 | 423 |
423 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); | 424 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); |
424 } | 425 } |
425 | 426 |
426 } // namespace dart | 427 } // namespace dart |
OLD | NEW |