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

Side by Side Diff: tool/input_sdk/private/js_helper.dart

Issue 2026133002: Throw TypeError instead of CastError for type coercions. (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « tool/input_sdk/private/ddc_runtime/utils.dart ('k') | tool/sdk_expected_errors.txt » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart._js_helper; 5 library dart._js_helper;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'dart:_foreign_helper' show 9 import 'dart:_foreign_helper' show
10 JS, 10 JS,
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 // TODO(lrn): These exceptions should be implemented in core. 775 // TODO(lrn): These exceptions should be implemented in core.
776 // When they are, remove the 'Implementation' here. 776 // When they are, remove the 'Implementation' here.
777 777
778 /** Thrown by type assertions that fail. */ 778 /** Thrown by type assertions that fail. */
779 class TypeErrorImplementation extends Error implements TypeError { 779 class TypeErrorImplementation extends Error implements TypeError {
780 final String message; 780 final String message;
781 781
782 /** 782 /**
783 * Normal type error caused by a failed subtype test. 783 * Normal type error caused by a failed subtype test.
784 */ 784 */
785 TypeErrorImplementation(Object value, String type) 785 TypeErrorImplementation(Object value, Object actualType, Object expectedType)
786 : message = "type '${Primitives.objectTypeName(value)}' is not a subtype " 786 : message = "Type '${actualType}' is not a subtype "
787 "of type '$type'"; 787 "of type '${expectedType}'";
788 788
789 TypeErrorImplementation.fromMessage(String this.message); 789 TypeErrorImplementation.fromMessage(String this.message);
790 790
791 String toString() => message; 791 String toString() => message;
792 } 792 }
793 793
794 /** Thrown by the 'as' operator if the cast isn't valid. */ 794 /** Thrown by the 'as' operator if the cast isn't valid. */
795 class CastErrorImplementation extends Error implements CastError { 795 class CastErrorImplementation extends Error implements CastError {
796 // TODO(lrn): Rename to CastError (and move implementation into core). 796 // TODO(lrn): Rename to CastError (and move implementation into core).
797 final String message; 797 final String message;
798 798
799 /** 799 /**
800 * Normal cast error caused by a failed type cast. 800 * Normal cast error caused by a failed type cast.
801 */ 801 */
802 CastErrorImplementation(Object actualType, Object expectedType) 802 CastErrorImplementation(Object value, Object actualType, Object expectedType)
Leaf 2016/06/01 17:01:51 Why the unused "value" parameter?
sra1 2016/06/01 17:07:13 I will add a TODO, but I would eventually like the
803 : message = "CastError: Casting value of type $actualType to" 803 : message = "CastError: Casting value of type '$actualType' to"
804 " incompatible type $expectedType"; 804 " incompatible type '$expectedType'";
805 805
806 String toString() => message; 806 String toString() => message;
807 } 807 }
808 808
809 /// Thrown by type assertions that fail in strong mode that would have passed in
810 /// standard Dart.
811 class StrongModeTypeError extends Error implements TypeError, StrongModeError {
812 final String message;
813 StrongModeTypeError(Object value, Object actualType, Object expectedType)
814 : message = "Type '${actualType}' is not a subtype "
815 "of type '${expectedType}' in strong mode";
816 String toString() => message;
817 }
818
819 /// Thrown by casts that fail in strong mode that would have passed in standard
820 /// Dart.
821 class StrongModeCastError extends Error implements CastError, StrongModeError {
822 final String message;
823 StrongModeCastError(Object value, Object actualType, Object expectedType)
824 : message = "CastError: Casting value of type '$actualType' to"
825 " type '$expectedType' which is incompatible in strong mode";
826 String toString() => message;
827 }
828
829 /// Used for Strong-mode errors other than type assertions and casts.
830 class StrongModeErrorImplementation extends Error implements StrongModeError {
831 final String message;
832 StrongModeErrorImplementation(this.message);
833 String toString() => message;
834 }
835
809 class FallThroughErrorImplementation extends FallThroughError { 836 class FallThroughErrorImplementation extends FallThroughError {
810 FallThroughErrorImplementation(); 837 FallThroughErrorImplementation();
811 String toString() => "Switch case fall-through."; 838 String toString() => "Switch case fall-through.";
812 } 839 }
813 840
814 /** 841 /**
815 * Error thrown when a runtime error occurs. 842 * Error thrown when a runtime error occurs.
816 */ 843 */
817 class RuntimeError extends Error { 844 class RuntimeError extends Error {
818 final message; 845 final message;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 // we have no way of telling the compiler yet, so it will generate an extra 891 // we have no way of telling the compiler yet, so it will generate an extra
865 // layer of indirection that wraps the SyncIterator. 892 // layer of indirection that wraps the SyncIterator.
866 _jsIterator() => JS('', '#(...#)', _generator, _args); 893 _jsIterator() => JS('', '#(...#)', _generator, _args);
867 894
868 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator()); 895 Iterator<E> get iterator => new SyncIterator<E>(_jsIterator());
869 } 896 }
870 897
871 class BooleanConversionAssertionError extends AssertionError { 898 class BooleanConversionAssertionError extends AssertionError {
872 toString() => 'Failed assertion: boolean expression must not be null'; 899 toString() => 'Failed assertion: boolean expression must not be null';
873 } 900 }
OLDNEW
« no previous file with comments | « tool/input_sdk/private/ddc_runtime/utils.dart ('k') | tool/sdk_expected_errors.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698