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

Side by Side Diff: lib/compiler/implementation/lib/js_helper.dart

Issue 10905235: Check boolean conversion in checked mode. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
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 4
5 #library('dart:_js_helper'); 5 #library('dart:_js_helper');
6 6
7 #import('coreimpl.dart'); 7 #import('coreimpl.dart');
8 8
9 #source('constant_map.dart'); 9 #source('constant_map.dart');
10 #source('native_helper.dart'); 10 #source('native_helper.dart');
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 // TODO(ngeoffray): Make the object a top-level field to avoid 970 // TODO(ngeoffray): Make the object a top-level field to avoid
971 // allocating a new object every single time. 971 // allocating a new object every single time.
972 return (res == null) ? JS('var', '{}') : res; 972 return (res == null) ? JS('var', '{}') : res;
973 } 973 }
974 974
975 /** 975 /**
976 * The following methods are called by the runtime to implement 976 * The following methods are called by the runtime to implement
977 * checked mode and casts. We specialize each primitive type (eg int, bool), and 977 * checked mode and casts. We specialize each primitive type (eg int, bool), and
978 * use the compiler's convention to do is-checks on regular objects. 978 * use the compiler's convention to do is-checks on regular objects.
979 */ 979 */
980 boolConversionCheck(value) {
981 boolTypeCheck(value);
kasperl 2012/09/13 10:34:19 Wouldn't it be more logical to just check that val
ngeoffray 2012/09/13 10:52:32 As discussed, this method is implementing what the
982 assert(value != null);
983 return value;
984 }
985
980 stringTypeCheck(value) { 986 stringTypeCheck(value) {
981 if (value === null) return value; 987 if (value === null) return value;
982 if (value is String) return value; 988 if (value is String) return value;
983 throw new TypeErrorImplementation('$value does not implement String'); 989 throw new TypeErrorImplementation('$value does not implement String');
984 } 990 }
985 991
986 stringTypeCast(value) { 992 stringTypeCast(value) {
987 if (value is String || value === null) return value; 993 if (value is String || value === null) return value;
988 // TODO(lrn): When reified types are available, pass value.class and String. 994 // TODO(lrn): When reified types are available, pass value.class and String.
989 throw new CastExceptionImplementation( 995 throw new CastExceptionImplementation(
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 class FallThroughErrorImplementation implements FallThroughError { 1259 class FallThroughErrorImplementation implements FallThroughError {
1254 const FallThroughErrorImplementation(); 1260 const FallThroughErrorImplementation();
1255 String toString() => "Switch case fall-through."; 1261 String toString() => "Switch case fall-through.";
1256 } 1262 }
1257 1263
1258 /** 1264 /**
1259 * Helper function for implementing asserts. The compiler treats this specially. 1265 * Helper function for implementing asserts. The compiler treats this specially.
1260 */ 1266 */
1261 void assert(condition) { 1267 void assert(condition) {
1262 if (condition is Function) condition = condition(); 1268 if (condition is Function) condition = condition();
1263 if (!condition) throw new AssertionError(); 1269 if (condition is !bool) {
1270 throw new TypeErrorImplementation('$condition does not implement bool');
1271 }
1272 // Compare to true to avoid boolean conversion check in checked
1273 // mode.
1274 if (condition !== true) throw new AssertionError();
1264 } 1275 }
1265 1276
1266 /** 1277 /**
1267 * Called by generated code when a method that must be statically 1278 * Called by generated code when a method that must be statically
1268 * resolved cannot be found. 1279 * resolved cannot be found.
1269 */ 1280 */
1270 void throwNoSuchMethod(obj, name, arguments) { 1281 void throwNoSuchMethod(obj, name, arguments) {
1271 throw new NoSuchMethodError(obj, name, arguments); 1282 throw new NoSuchMethodError(obj, name, arguments);
1272 } 1283 }
1273 1284
1274 /** 1285 /**
1275 * Called by generated code when a static field's initializer references the 1286 * Called by generated code when a static field's initializer references the
1276 * field that is currently being initialized. 1287 * field that is currently being initialized.
1277 */ 1288 */
1278 void throwCyclicInit(String staticName) { 1289 void throwCyclicInit(String staticName) {
1279 throw new RuntimeError("Cyclic initialization for static $staticName"); 1290 throw new RuntimeError("Cyclic initialization for static $staticName");
1280 } 1291 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/builder.dart » ('j') | lib/compiler/implementation/ssa/builder.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698