| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Errors are created and thrown by DartVM only. | 4 // Errors are created and thrown by DartVM only. |
| 5 // Changes here should also be reflected in corelib/error.dart as well | 5 // Changes here should also be reflected in corelib/error.dart as well |
| 6 | 6 |
| 7 class _AssertionErrorImplementation extends AssertionError { | 7 class AssertionErrorImplementation extends AssertionError { |
| 8 _AssertionErrorImplementation( | 8 factory AssertionErrorImplementation._uninstantiable() { |
| 9 this.failedAssertion, this.url, this.line, this.column); | 9 throw new UnsupportedError( |
| 10 | 10 "AssertionError can only be allocated by the VM"); |
| 11 } |
| 11 static _throwNew(int assertionStart, int assertionEnd) | 12 static _throwNew(int assertionStart, int assertionEnd) |
| 12 native "AssertionError_throwNew"; | 13 native "AssertionError_throwNew"; |
| 13 | |
| 14 String toString() { | 14 String toString() { |
| 15 return "'$url': Failed assertion: line $line pos $_column: " | 15 return "'$url': Failed assertion: line $line pos $column: " |
| 16 "'$failedAssertion' is not true."; | 16 "'$failedAssertion' is not true."; |
| 17 } | 17 } |
| 18 final String failedAssertion; | 18 final String failedAssertion; |
| 19 final String url; | 19 final String url; |
| 20 final int line; | 20 final int line; |
| 21 final int column; | 21 final int column; |
| 22 } | 22 } |
| 23 | 23 |
| 24 class _TypeErrorImplementation | 24 class TypeErrorImplementation |
| 25 extends _AssertionErrorImplementation | 25 extends AssertionErrorImplementation |
| 26 implements TypeError { | 26 implements TypeError { |
| 27 | 27 factory TypeErrorImplementation._uninstantiable() { |
| 28 _TypeErrorImplementation( | 28 throw new UnsupportedError( |
| 29 String failedAssertion, String url, int line, int column, | 29 "TypeError can only be allocated by the VM"); |
| 30 this.srcType, this.dstType, this.dstName, this._malformedError) | 30 } |
| 31 : super(failedAssertion, url, line, column); | |
| 32 | |
| 33 static _throwNew(int location, | 31 static _throwNew(int location, |
| 34 Object src_value, | 32 Object src_value, |
| 35 String dst_type_name, | 33 String dst_type_name, |
| 36 String dst_name, | 34 String dst_name, |
| 37 String malformed_error) | 35 String malformed_error) |
| 38 native "TypeError_throwNew"; | 36 native "TypeError_throwNew"; |
| 39 | |
| 40 String toString() { | 37 String toString() { |
| 41 String str = (_malformedError != null) ? _malformedError : ""; | 38 String str = (malformedError != null) ? malformedError : ""; |
| 42 if ((dstName != null) && (dstName.length > 0)) { | 39 if ((dstName != null) && (dstName.length > 0)) { |
| 43 str = "${str}type '$srcType' is not a subtype of " | 40 str = "${str}type '$srcType' is not a subtype of " |
| 44 "type '$dstType' of '$dstName'."; | 41 "type '$dstType' of '$dstName'."; |
| 45 } else { | 42 } else { |
| 46 str = "${str}malformed type used."; | 43 str = "${str}malformed type used."; |
| 47 } | 44 } |
| 48 return str; | 45 return str; |
| 49 } | 46 } |
| 50 | |
| 51 final String srcType; | 47 final String srcType; |
| 52 final String dstType; | 48 final String dstType; |
| 53 final String dstName; | 49 final String dstName; |
| 54 final String _malformedError; | 50 final String malformedError; |
| 55 } | 51 } |
| 56 | 52 |
| 57 class _CastErrorImplementation | 53 class CastErrorImplementation |
| 58 extends _TypeErrorImplementation | 54 extends TypeErrorImplementation |
| 59 implements CastError { | 55 implements CastError { |
| 60 | 56 factory CastErrorImplementation._uninstantiable() { |
| 61 _CastErrorImplementation( | 57 throw new UnsupportedError( |
| 62 String failedAssertion, String url, int line, int column, | 58 "CastError can only be allocated by the VM"); |
| 63 String srcType, String dstType, String dstName, String malformedError) | 59 } |
| 64 : super(failedAssertion, url, line, column, | |
| 65 srcType, dstType, dstName, malformedError); | |
| 66 | |
| 67 // A CastError is allocated by TypeError._throwNew() when dst_name equals | 60 // A CastError is allocated by TypeError._throwNew() when dst_name equals |
| 68 // Exceptions::kCastErrorDstName. | 61 // Exceptions::kCastErrorDstName. |
| 69 String toString() { | 62 String toString() { |
| 70 String str = (_malformedError != null) ? _malformedError : ""; | 63 String str = (malformedError != null) ? malformedError : ""; |
| 71 if ((dstName != null) && (dstName.length > 0)) { | 64 if ((dstName != null) && (dstName.length > 0)) { |
| 72 str = "${str}type '$srcType' is not a subtype of " | 65 str = "${str}type '$srcType' is not a subtype of " |
| 73 "type '$dstType' in type cast."; | 66 "type '$dstType' in type cast."; |
| 74 } else { | 67 } else { |
| 75 str = "${str}malformed type used in type cast."; | 68 str = "${str}malformed type used in type cast."; |
| 76 } | 69 } |
| 77 return str; | 70 return str; |
| 78 } | 71 } |
| 79 } | 72 } |
| 80 | 73 |
| 81 class _FallThroughErrorImplementation extends FallThroughError { | 74 class FallThroughErrorImplementation extends FallThroughError { |
| 82 | 75 factory FallThroughErrorImplementation._uninstantiable() { |
| 83 _FallThroughErrorImplementation(this._url, this._line); | 76 throw new UnsupportedError( |
| 84 | 77 "FallThroughError can only be allocated by the VM"); |
| 78 } |
| 85 static _throwNew(int case_clause_pos) native "FallThroughError_throwNew"; | 79 static _throwNew(int case_clause_pos) native "FallThroughError_throwNew"; |
| 86 | |
| 87 String toString() { | 80 String toString() { |
| 88 return "'$_url': Switch case fall-through at line $_line."; | 81 return "'$url': Switch case fall-through at line $line."; |
| 89 } | 82 } |
| 90 | 83 final String url; |
| 91 final String _url; | 84 final int line; |
| 92 final int _line; | |
| 93 } | 85 } |
| 94 | 86 |
| 95 class _InternalError { | 87 class InternalError { |
| 96 const _InternalError(this._msg); | 88 const InternalError(this._msg); |
| 97 String toString() => "InternalError: '${_msg}'"; | 89 String toString() => "InternalError: '${_msg}'"; |
| 98 final String _msg; | 90 final String _msg; |
| 99 } | 91 } |
| 100 | 92 |
| 101 | 93 |
| 102 class _AbstractClassInstantiationErrorImplementation | 94 class AbstractClassInstantiationErrorImplementation |
| 103 extends AbstractClassInstantiationError { | 95 extends AbstractClassInstantiationError { |
| 104 | 96 |
| 105 _AbstractClassInstantiationErrorImplementation( | 97 factory AbstractClassInstantiationErrorImplementation._uninstantiable() { |
| 106 String className, this._url, this._line) | 98 throw new UnsupportedError( |
| 107 : super(className); | 99 "AbstractClassInstantiationError can only be allocated by the VM"); |
| 100 } |
| 108 | 101 |
| 109 static _throwNew(int case_clause_pos, String className) | 102 static _throwNew(int case_clause_pos, String className) |
| 110 native "AbstractClassInstantiationError_throwNew"; | 103 native "AbstractClassInstantiationError_throwNew"; |
| 111 | 104 |
| 112 String toString() { | 105 String toString() { |
| 113 return "Cannot instantiate abstract class $_className: " | 106 return "Cannot instantiate abstract class $className: " |
| 114 "_url '$_url' line $_line"; | 107 "url '$url' line $line"; |
| 115 } | 108 } |
| 116 | 109 |
| 117 final String _url; | 110 final String className; |
| 118 final int _line; | 111 final String url; |
| 112 final int line; |
| 119 } | 113 } |
| OLD | NEW |