Chromium Code Reviews| Index: runtime/vm/exceptions.cc |
| diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc |
| index b1555642cbad814fcff2959b33a97a991c06c279..e8931539745861dd3a223f2bc5973e49a7b93546 100644 |
| --- a/runtime/vm/exceptions.cc |
| +++ b/runtime/vm/exceptions.cc |
| @@ -413,17 +413,20 @@ void Exceptions::SetField(const Instance& instance, |
| } |
| -// Initialize the fields 'url', 'line', and 'column' in the given instance |
| +// Set the fields 'url', 'line', and 'column' in the given instance |
| // according to the given token location in the given script. |
| -void Exceptions::SetLocationFields(const Instance& instance, |
| - const Class& cls, |
| - const Script& script, |
| - intptr_t location) { |
| - SetField(instance, cls, "url", String::Handle(script.url())); |
| +// |
| +// Returns the number of items that have been added to the 'args' array. |
| +intptr_t Exceptions::SetLocationFields(const Array& args, |
| + intptr_t index, |
| + const Script& script, |
| + intptr_t location) { |
| + args.SetAt(index, String::Handle(script.url())); |
| intptr_t line, column; |
| script.GetTokenLocation(location, &line, &column); |
| - SetField(instance, cls, "line", Smi::Handle(Smi::New(line))); |
| - SetField(instance, cls, "column", Smi::Handle(Smi::New(column))); |
| + args.SetAt(index + 1, Smi::Handle(Smi::New(line))); |
| + args.SetAt(index + 2, Smi::Handle(Smi::New(column))); |
| + return 3; |
| } |
| @@ -433,48 +436,33 @@ void Exceptions::CreateAndThrowTypeError(intptr_t location, |
| const String& dst_type_name, |
| const String& dst_name, |
| const String& malformed_error) { |
| - // Allocate a new instance of TypeError or CastError. |
| - Instance& type_error = Instance::Handle(); |
| - Class& cls = Class::Handle(); |
| - if (dst_name.Equals(kCastErrorDstName)) { |
| - type_error = NewInstance("CastErrorImplementation"); |
| - cls = type_error.clazz(); |
| - cls = cls.SuperClass(); |
| - } else { |
| - type_error = NewInstance("TypeErrorImplementation"); |
| - cls = type_error.clazz(); |
| - } |
| + const Array& args = Array::Handle(Array::New(8)); |
| - // Initialize 'url', 'line', and 'column' fields. |
| - DartFrameIterator iterator; |
| - const Script& script = Script::Handle(GetCallerScript(&iterator)); |
| - // 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); |
| + ExceptionType exception_type = |
| + dst_name.Equals(kCastErrorDstName) ? kCast : kType; |
| - // Initialize field 'failedAssertion' in AssertionError superclass. |
| + // Initialize argument 'failedAssertion'. |
| // Printing the src_obj value would be possible, but ToString() is expensive |
| // and not meaningful for all classes, so we just print '$expr instanceof...'. |
| // Users should look at TypeError.ToString(), which contains more useful |
| // information than AssertionError.failedAssertion. |
| String& failed_assertion = String::Handle(String::New("$expr instanceof ")); |
| failed_assertion = String::Concat(failed_assertion, dst_type_name); |
| - SetField(type_error, |
| - assertion_error_class, |
| - "failedAssertion", |
| - failed_assertion); |
| - |
| - // Initialize field 'srcType'. |
| - SetField(type_error, cls, "srcType", src_type_name); |
| + intptr_t args_index = 0; |
| + args.SetAt(args_index++, failed_assertion); |
| - // Initialize field 'dstType'. |
| - SetField(type_error, cls, "dstType", dst_type_name); |
| - |
| - // Initialize field 'dstName'. |
| - SetField(type_error, cls, "dstName", dst_name); |
| + // Initialize 'url', 'line', and 'column' arguments. |
| + DartFrameIterator iterator; |
| + const Script& script = Script::Handle(GetCallerScript(&iterator)); |
| + args_index += SetLocationFields(args, args_index, script, location); |
| + ASSERT(args_index == 4); |
| - // Initialize field 'malformedError'. |
| - SetField(type_error, cls, "malformedError", malformed_error); |
| + // Initialize argument 'srcType'. |
| + args.SetAt(args_index++, src_type_name); |
| + args.SetAt(args_index++, dst_type_name); |
| + args.SetAt(args_index++, dst_name); |
| + args.SetAt(args_index++, malformed_error); |
| + ASSERT(args_index == args.Length()); |
|
siva
2013/07/12 16:49:36
ditto comment about using 0, 1, 2 etc. instead of
floitsch
2013/07/12 17:12:36
Done.
|
| // Type errors in the core library may be difficult to diagnose. |
| // Print type error information before throwing the error when debugging. |
| @@ -496,7 +484,7 @@ void Exceptions::CreateAndThrowTypeError(intptr_t location, |
| } |
| } |
| // Throw TypeError instance. |
| - Exceptions::Throw(type_error); |
| + Exceptions::ThrowByType(exception_type, args); |
| UNREACHABLE(); |
| } |
| @@ -626,6 +614,26 @@ RawObject* Exceptions::Create(ExceptionType type, const Array& arguments) { |
| library = Library::CoreLibrary(); |
| class_name = &Symbols::FiftyThreeBitOverflowError(); |
| break; |
| + case kAssertion: |
| + library = Library::CoreLibrary(); |
| + class_name = &Symbols::AssertionError(); |
| + break; |
| + case kCast: |
| + library = Library::CoreLibrary(); |
| + class_name = &Symbols::CastError(); |
| + break; |
| + case kType: |
| + library = Library::CoreLibrary(); |
| + class_name = &Symbols::TypeError(); |
| + break; |
| + case kFallThrough: |
| + library = Library::CoreLibrary(); |
| + class_name = &Symbols::FallThroughError(); |
| + break; |
| + case kAbstractClassInstantiation: |
| + library = Library::CoreLibrary(); |
| + class_name = &Symbols::AbstractClassInstantiationError(); |
| + break; |
| } |
| return DartLibraryCalls::ExceptionCreate(library, |