mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:37:53 +00:00
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:
parent
00525a056c
commit
58851f2f06
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.
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue