Index: tool/input_sdk/private/ddc_runtime/operations.dart |
diff --git a/tool/input_sdk/private/ddc_runtime/operations.dart b/tool/input_sdk/private/ddc_runtime/operations.dart |
index 92f62e2ba2a968c8ec46fb76989d01db13f42f22..1b5a9008d2a1f27277566d56f1b450da52548fe1 100644 |
--- a/tool/input_sdk/private/ddc_runtime/operations.dart |
+++ b/tool/input_sdk/private/ddc_runtime/operations.dart |
@@ -246,7 +246,7 @@ instanceOf(obj, type) => JS('', '''(() => { |
let result = $strongInstanceOf($obj, $type); |
if (result !== null) return result; |
let actual = $getReifiedType($obj); |
- $throwStrongModeError('Strong mode is check failure: ' + |
+ $throwStrongModeError('Strong mode is-check failure: ' + |
$typeName(actual) + ' does not soundly subtype ' + |
$typeName($type)); |
})()'''); |
@@ -259,6 +259,13 @@ cast(obj, type) { |
_throwCastError(obj, type, result); |
} |
+check(obj, type) { |
+ if (JS('bool', '# == #', type, dynamic) || obj == null) return obj; |
+ bool result = strongInstanceOf(obj, type, true); |
+ if (JS('bool', '#', result)) return obj; |
+ _throwTypeError(obj, type, result); |
+} |
+ |
bool test(obj) { |
if (obj is bool) return obj; |
return booleanConversionFailed(obj); |
@@ -277,17 +284,23 @@ bool booleanConversionFailed(obj) { |
void _throwCastError(obj, type, bool result) { |
var actual = getReifiedType(obj); |
- if (result == false) throwCastError(actual, type); |
+ if (result == false) throwCastError(obj, actual, type); |
+ |
+ throwStrongModeCastError(obj, actual, type); |
+} |
+ |
+void _throwTypeError(obj, type, bool result) { |
+ var actual = getReifiedType(obj); |
+ if (result == false) throwTypeError(obj, actual, type); |
- throwStrongModeError('Strong mode cast failure from ' + |
- typeName(actual) + ' to ' + typeName(type)); |
+ throwStrongModeTypeError(obj, actual, type); |
} |
asInt(obj) { |
if (obj == null) return null; |
if (JS('bool', 'Math.floor(#) != #', obj, obj)) { |
- throwCastError(getReifiedType(obj), JS('', '#', int)); |
+ throwCastError(obj, getReifiedType(obj), JS('', '#', int)); |
} |
return obj; |
} |