Skip to content

Commit

Permalink
Disallow ignore on any explicit cast failures
Browse files Browse the repository at this point in the history
See #27223

Change-Id: I9689ce9a72597b3e5c945f9787f2de6c5e8c2074
Reviewed-on: https://dart-review.googlesource.com/54701
Commit-Queue: Vijay Menon <vsm@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Jenny Messerly <jmesserly@google.com>
  • Loading branch information
vsmenon authored and commit-bot@chromium.org committed May 21, 2018
1 parent 1cf871a commit bea580c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
10 changes: 7 additions & 3 deletions pkg/dev_compiler/tool/ddb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import 'dart:io';
import 'package:args/args.dart' show ArgParser;
import 'package:path/path.dart' as path;

// TODO(vsm): Remove this once we stop ignoring. It's off here, but
// configurable for manual testing.
const ignoreWhitelistedErrors = false;

void main(List<String> args) {
// Parse flags.
var parser = new ArgParser()
Expand Down Expand Up @@ -139,7 +143,7 @@ void main(List<String> args) {
function(sdk, app) {
'use strict';
sdk._debugger.registerDevtoolsFormatter();
sdk.dart.ignoreWhitelistedErrors(false);
sdk.dart.ignoreWhitelistedErrors($ignoreWhitelistedErrors);
sdk._isolate_helper.startRootIsolate(() => {}, []);
app.$basename.main();
});
Expand All @@ -162,7 +166,7 @@ void main(List<String> args) {
}
let sdk = require(\"dart_sdk\");
let main = require(\"./$basename\").$basename.main;
sdk.dart.ignoreWhitelistedErrors(false);
sdk.dart.ignoreWhitelistedErrors($ignoreWhitelistedErrors);
try {
sdk._isolate_helper.startRootIsolate(main, []);
} catch(e) {
Expand All @@ -186,7 +190,7 @@ void main(List<String> args) {
import { dart, _isolate_helper } from '$sdkJsPath/dart_sdk.js';
import { $basename } from '$basename.js';
let main = $basename.main;
dart.ignoreWhitelistedErrors(false);
dart.ignoreWhitelistedErrors($ignoreWhitelistedErrors);
try {
_isolate_helper.startRootIsolate(() => {}, []);
main();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@ throwNullValueError() {
null, new Symbol('<Unexpected Null Value>'), null, null, null);
}

castError(obj, expectedType, [bool typeError = undefined]) {
castError(obj, expectedType, [@js_helper.notNull bool isImplicit = false]) {
var actualType = getReifiedType(obj);
var message = _castErrorMessage(actualType, expectedType);
if (JS('!', 'dart.__ignoreAllErrors')) {
JS('', 'console.error(#)', message);
return obj;
}
if (JS('!', 'dart.__trapRuntimeErrors')) JS('', 'debugger');
var error = JS<bool>('!', '#', typeError)
? new TypeErrorImpl(message)
: new CastErrorImpl(message);
var error =
isImplicit ? new TypeErrorImpl(message) : new CastErrorImpl(message);
throw error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ bool instanceOf(obj, type) {
}

@JSExportName('as')
cast(obj, type, bool isExplicit) {
cast(obj, type, @js_helper.notNull bool isImplicit) {
if (obj == null) return obj;
var actual = getReifiedType(obj);
var result = isSubtype(actual, type);
Expand All @@ -454,13 +454,13 @@ cast(obj, type, bool isExplicit) {
'dart.__ignoreWhitelistedErrors && #(#, #)',
result,
result,
isExplicit,
isImplicit,
_ignoreTypeFailure,
actual,
type)) {
return obj;
}
return castError(obj, type, isExplicit);
return castError(obj, type, isImplicit);
}

bool test(bool obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'dart:_js_helper'
PrivateSymbol,
ReifyFunctionTypes,
NoReifyGeneric;
import 'dart:_js_helper' as js_helper show notNull;
import 'dart:_debugger' show trackCall;

export 'dart:_debugger'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class FunctionType extends AbstractFunctionType {
}))()''');

@JSExportName('as')
as_T(obj, [bool typeError]) {
as_T(obj, [@js_helper.notNull bool isImplicit = false]) {
if (obj == null) return obj;
if (JS('bool', 'typeof # == "function"', obj)) {
var actual = JS('', '#[#]', obj, _runtimeType);
Expand All @@ -436,12 +436,14 @@ class FunctionType extends AbstractFunctionType {
if (actual == null) return obj;
var result = isSubtype(actual, this);
if (result == true) return obj;
if (result == null && JS('bool', 'dart.__ignoreWhitelistedErrors')) {
if (result == null &&
isImplicit &&
JS<bool>('!', 'dart.__ignoreWhitelistedErrors')) {
_logIgnoredCast(actual, this);
return obj;
}
}
return castError(obj, this, typeError);
return castError(obj, this, isImplicit);
}

@JSExportName('_check')
Expand Down

0 comments on commit bea580c

Please sign in to comment.