Add ignoreAllErrors option to dart:_runtime

Supports users who want to try to run broken code while porting a Dart
app to strong mode.

BUG=
R=alanknight@google.com

Review-Url: https://codereview.chromium.org/2893803006 .
This commit is contained in:
Jacob Richman 2017-05-19 15:53:01 -07:00
parent 00525a056c
commit 58851f2f06
12 changed files with 116 additions and 25 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -17,6 +17,10 @@ void ignoreWhitelistedErrors(bool flag) {
JS('', 'dart.__ignoreWhitelistedErrors = #', flag);
}
void ignoreAllErrors(bool flag) {
JS('', 'dart.__ignoreAllErrors = #', flag);
}
/// Throw an exception on `is` checks that would return an unsound answer in
/// non-strong mode Dart.
///

View file

@ -511,9 +511,14 @@ instanceOf(obj, type) => JS(
if (result !== null) return result;
if (!dart.__failForWeakModeIsChecks) return false;
let actual = $getReifiedType($obj);
$throwStrongModeError('Strong mode is-check failure: ' +
$typeName(actual) + ' does not soundly subtype ' +
$typeName($type));
let message = 'Strong mode is-check failure: ' +
$typeName(actual) + ' does not soundly subtype ' +
$typeName($type);
if (!dart.__ignoreAllErrors) {
$throwStrongModeError(message);
}
console.error(message);
return true; // Match Dart 1.0 Semantics when ignoring errors.
})()''');
@JSExportName('as')
@ -521,14 +526,24 @@ cast(obj, type) {
if (JS('bool', '# == #', type, dynamic) || obj == null) return obj;
bool result = strongInstanceOf(obj, type, true);
if (JS('bool', '#', result)) return obj;
_throwCastError(obj, type, result);
if (JS('bool', '!dart.__ignoreAllErrors')) {
_throwCastError(obj, type, result);
}
JS('', 'console.error(#)',
'Actual: ${typeName(getReifiedType(obj))} Expected: ${typeName(type)}');
return obj;
}
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);
if (JS('bool', '!dart.__ignoreAllErrors')) {
_throwTypeError(obj, type, result);
}
JS('', 'console.error(#)',
'Actual: ${typeName(getReifiedType(obj))} Expected: ${typeName(type)}');
return obj;
}
bool test(obj) {

View file

@ -107,6 +107,10 @@ final global_ = JS(
$ignoreWhitelistedErrors(
'ignoreWhitelistedErrors' in settings ?
settings.ignoreWhitelistedErrors : true);
$ignoreAllErrors(
'ignoreAllErrors' in settings ?settings.ignoreAllErrors : false);
$failForWeakModeIsChecks(
'failForWeakModeIsChecks' in settings ?
settings.failForWeakModeIsChecks : true);