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

Unified Diff: lib/runtime/_operations.js

Issue 1298893003: Enable is and as checks on non-ground types (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Minor fixes Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/runtime/_errors.js ('k') | lib/runtime/dart_library.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/runtime/_operations.js
diff --git a/lib/runtime/_operations.js b/lib/runtime/_operations.js
index 1d3997d06e5e16f62c869ce4e210b1755048615f..b6085e9a38059e8007e32718e5d072e3171dd8ba 100644
--- a/lib/runtime/_operations.js
+++ b/lib/runtime/_operations.js
@@ -191,26 +191,46 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
return false;
}
- function instanceOf(obj, type) {
+ function strongInstanceOf(obj, type) {
return types.isSubtype(rtti.realRuntimeType(obj), type);
}
- exports.instanceOf = instanceOf;
+ exports.strongInstanceOf = strongInstanceOf;
function instanceOfOrNull(obj, type) {
- if ((obj == null) || instanceOf(obj, type)) return true;
- let actual = rtti.realRuntimeType(obj);
- if (_ignoreTypeFailure(actual, type)) return true;
+ if ((obj == null) || strongInstanceOf(obj, type)) return true;
return false;
}
- exports.instanceOfOrNull = instanceOfOrNull;
+
+ function instanceOf(obj, type) {
+ if (strongInstanceOf(obj, type)) return true;
+ // TODO(vsm): This is perhaps too eager to throw a StrongModeError?
+ // It will throw on <int>[] is List<String>.
+ // TODO(vsm): We can statically detect many cases where this
+ // check is unnecessary.
+ if (types.isGroundType(type)) return false;
+ let actual = rtti.realRuntimeType(obj);
+ dart_utils.throwStrongModeError('Strong mode cast failure from ' +
Leaf 2015/08/18 23:31:11 Calling this a "cast failure" is a bit misleading,
+ types.typeName(actual) + ' to ' + types.typeName(type));
+ }
+ exports.instanceOf = instanceOf;
function cast(obj, type) {
// TODO(vsm): handle non-nullable types
- if (obj == null) return obj;
+ if (instanceOfOrNull(obj, type)) return obj;
let actual = rtti.realRuntimeType(obj);
- if (types.isSubtype(actual, type)) return obj;
- if (_ignoreTypeFailure(actual, type)) return obj;
- errors.throwCastError(actual, type);
+ if (_ignoreTypeFailure(actual, type)) {
+ // TODO(vsm): track why this is happening in our async / await tests.
+ if (types.isGroundType(type)) {
+ console.error('Should not ignore cast failure from ' +
+ types.typeName(actual) + ' to ' + types.typeName(type));
+ }
+ return obj;
+ }
+ if (types.isGroundType(type)) {
+ errors.throwCastError(actual, type);
+ }
+ dart_utils.throwStrongModeError('Strong mode cast failure from ' +
+ types.typeName(actual) + ' to ' + types.typeName(type));
}
exports.cast = cast;
@@ -230,8 +250,7 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
/** Checks that `x` is not null or undefined. */
function notNull(x) {
- // TODO(leafp): This is probably not the right error to throw.
- if (x == null) throwError('expected not-null value');
+ if (x == null) errors.throwNullValueError();
return x;
}
exports.notNull = notNull;
« no previous file with comments | « lib/runtime/_errors.js ('k') | lib/runtime/dart_library.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698