Skip to content

Commit 86c4dc0

Browse files
committed
Only use white list on indefinite checks
BUG= [email protected] Review URL: https://codereview.chromium.org/1953823005 .
1 parent a5d1626 commit 86c4dc0

File tree

4 files changed

+49
-29
lines changed

4 files changed

+49
-29
lines changed

pkg/dev_compiler/lib/runtime/dart_sdk.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
531531
let actual = dart.getReifiedType(obj);
532532
let result = dart.isSubtype(actual, type);
533533
if (result || actual == dart.jsobject || actual == core.int && type == core.double) return true;
534+
if (result === false) return false;
534535
if (ignoreFromWhiteList == void 0) return result;
535536
if (dart._ignoreTypeFailure(actual, type)) return true;
536537
return result;
@@ -13395,9 +13396,9 @@ dart_library.library('dart_sdk', null, /* Imports */[
1339513396
async._registerErrorHandler = function(R) {
1339613397
return (errorHandler, zone) => {
1339713398
if (dart.is(errorHandler, async.ZoneBinaryCallback)) {
13398-
return zone.registerBinaryCallback(R, dart.dynamic, core.StackTrace)(dart.as(errorHandler, async.ZoneBinaryCallback$(R, dart.dynamic, core.StackTrace)));
13399+
return zone.registerBinaryCallback(dart.dynamic, dart.dynamic, core.StackTrace)(dart.as(errorHandler, async.ZoneBinaryCallback$(dart.dynamic, dart.dynamic, core.StackTrace)));
1339913400
} else {
13400-
return zone.registerUnaryCallback(R, dart.dynamic)(dart.as(errorHandler, async.ZoneUnaryCallback$(R, dart.dynamic)));
13401+
return zone.registerUnaryCallback(dart.dynamic, dart.dynamic)(dart.as(errorHandler, async.ZoneUnaryCallback));
1340113402
}
1340213403
};
1340313404
};

pkg/dev_compiler/test/codegen/lib/typed_data/typed_data_list_test.dart

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:expect/expect.dart';
99
@NoInline()
1010
confuse(x) => x;
1111

12-
void testListFunctions(list, first, last, toElementType) {
12+
void testListFunctions/*<T>*/(list, first, last, /*=T*/ toElementType(dynamic x)) {
1313
assert(list.length > 0);
1414

1515
var reversed = list.reversed;
@@ -20,16 +20,21 @@ void testListFunctions(list, first, last, toElementType) {
2020
index--;
2121
}
2222

23+
var zero = toElementType(0);
24+
var one = toElementType(1);
25+
var two = toElementType(2);
2326
// Typed lists are fixed length.
24-
Expect.throws(() => list.add(0), (e) => e is UnsupportedError);
25-
Expect.throws(() => list.addAll([1, 2]), (e) => e is UnsupportedError);
27+
Expect.throws(() => list.add(zero), (e) => e is UnsupportedError);
28+
Expect.throws(() => list.addAll([one, two]), (e) => e is UnsupportedError);
2629
Expect.throws(() => list.clear(), (e) => e is UnsupportedError);
27-
Expect.throws(() => list.insert(0, 0), (e) => e is UnsupportedError);
28-
Expect.throws(() => list.insertAll(0, [1, 2]), (e) => e is UnsupportedError);
29-
Expect.throws(() => list.remove(0), (e) => e is UnsupportedError);
30+
Expect.throws(() => list.insert(0, zero), (e) => e is UnsupportedError);
31+
Expect.throws(() => list.insertAll(0, [one, two]),
32+
(e) => e is UnsupportedError);
33+
Expect.throws(() => list.remove(zero), (e) => e is UnsupportedError);
3034
Expect.throws(() => list.removeAt(0), (e) => e is UnsupportedError);
3135
Expect.throws(() => list.removeLast(), (e) => e is UnsupportedError);
32-
Expect.throws(() => list.removeRange(0, 1), (e) => e is UnsupportedError);
36+
Expect.throws(() => list.removeRange(0, 1),
37+
(e) => e is UnsupportedError);
3338
Expect.throws(() => list.removeWhere((x) => true),
3439
(e) => e is UnsupportedError);
3540
Expect.throws(() => list.replaceRange(0, 1, []),
@@ -123,21 +128,24 @@ void testListFunctions(list, first, last, toElementType) {
123128
(e) => e is RangeError);
124129
}
125130

126-
void emptyChecks(list) {
131+
void emptyChecks/*<T>*/(list, /*=T*/ toElementType(dynamic c)) {
127132
assert(list.length == 0);
128133

129134
Expect.isTrue(list.isEmpty);
130135

131136
var reversed = list.reversed;
132137
Expect.listEquals(list, reversed.toList().reversed.toList());
133138

139+
var zero = toElementType(0);
140+
var one = toElementType(1);
141+
var two = toElementType(2);
134142
// Typed lists are fixed length. Even when they are empty.
135-
Expect.throws(() => list.add(0), (e) => e is UnsupportedError);
136-
Expect.throws(() => list.addAll([1, 2]), (e) => e is UnsupportedError);
143+
Expect.throws(() => list.add(zero), (e) => e is UnsupportedError);
144+
Expect.throws(() => list.addAll([one, two]), (e) => e is UnsupportedError);
137145
Expect.throws(() => list.clear(), (e) => e is UnsupportedError);
138-
Expect.throws(() => list.insert(0, 0), (e) => e is UnsupportedError);
139-
Expect.throws(() => list.insertAll(0, [1, 2]), (e) => e is UnsupportedError);
140-
Expect.throws(() => list.remove(0), (e) => e is UnsupportedError);
146+
Expect.throws(() => list.insert(0, zero), (e) => e is UnsupportedError);
147+
Expect.throws(() => list.insertAll(0, [one, two]), (e) => e is UnsupportedError);
148+
Expect.throws(() => list.remove(zero), (e) => e is UnsupportedError);
141149
Expect.throws(() => list.removeAt(0), (e) => e is UnsupportedError);
142150
Expect.throws(() => list.removeLast(), (e) => e is UnsupportedError);
143151
Expect.throws(() => list.removeRange(0, 1), (e) => e is UnsupportedError);
@@ -174,8 +182,8 @@ void emptyChecks(list) {
174182
}
175183

176184
main() {
177-
toDouble(x) => x.toDouble();
178-
toInt(x) => x.toInt();
185+
double toDouble(x) => x.toDouble();
186+
int toInt(x) => x.toInt();
179187

180188
testListFunctions(new Float32List.fromList([1.5, 6.3, 9.5]),
181189
1.5, 9.5, toDouble);
@@ -188,12 +196,12 @@ main() {
188196
testListFunctions(new Uint16List.fromList([3, 5, 9]), 3, 9, toInt);
189197
testListFunctions(new Uint32List.fromList([3, 5, 9]), 3, 9, toInt);
190198

191-
emptyChecks(new Float32List(0));
192-
emptyChecks(new Float64List(0));
193-
emptyChecks(new Int8List(0));
194-
emptyChecks(new Int16List(0));
195-
emptyChecks(new Int32List(0));
196-
emptyChecks(new Uint8List(0));
197-
emptyChecks(new Uint16List(0));
198-
emptyChecks(new Uint32List(0));
199+
emptyChecks(new Float32List(0), toDouble);
200+
emptyChecks(new Float64List(0), toDouble);
201+
emptyChecks(new Int8List(0), toInt);
202+
emptyChecks(new Int16List(0), toInt);
203+
emptyChecks(new Int32List(0), toInt);
204+
emptyChecks(new Uint8List(0), toInt);
205+
emptyChecks(new Uint16List(0), toInt);
206+
emptyChecks(new Uint32List(0), toInt);
199207
}

pkg/dev_compiler/tool/input_sdk/lib/async/async_error.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ _invokeErrorHandler(Function errorHandler,
1616

1717
Function _registerErrorHandler/*<R>*/(Function errorHandler, Zone zone) {
1818
if (errorHandler is ZoneBinaryCallback) {
19-
return zone.registerBinaryCallback/*<R, dynamic, StackTrace>*/(
20-
errorHandler as dynamic/*=ZoneBinaryCallback<R, dynamic, StackTrace>*/);
19+
// TODO(leafp): These are commented out, because the async libraries
20+
// pass a (...) -> void into this function which fails whenever R
21+
// is something interesting. This needs to be sorted out in the main
22+
// SDK as to what the intent is here: if this is really supposed to
23+
// return an R, then the function that gets passed in is wrong. If not,
24+
// then this code doesn't need to track the return type at all.
25+
// return zone.registerBinaryCallback/*<R, dynamic, StackTrace>*/(
26+
// errorHandler as dynamic/*=ZoneBinaryCallback<R, dynamic, StackTrace>*/);
27+
return zone.registerBinaryCallback/*<dynamic, dynamic, StackTrace>*/(
28+
errorHandler as dynamic/*=ZoneBinaryCallback<dynamic, dynamic, StackTrace>*/);
2129
} else {
22-
return zone.registerUnaryCallback/*<R, dynamic>*/(
23-
errorHandler as dynamic/*=ZoneUnaryCallback<R, dynamic>*/);
30+
// return zone.registerUnaryCallback/*<R, dynamic>*/(
31+
// errorHandler as dynamic/*=ZoneUnaryCallback<R, dynamic>*/);
32+
return zone.registerUnaryCallback/*<dynamic, dynamic>*/(
33+
errorHandler as dynamic/*=ZoneUnaryCallback<dynamic, dynamic>*/);
2434
}
2535
}
2636

pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ strongInstanceOf(obj, type, ignoreFromWhiteList) => JS('', '''(() => {
204204
let result = $isSubtype(actual, $type);
205205
if (result || actual == $jsobject ||
206206
actual == $int && type == $double) return true;
207+
if (result === false) return false;
207208
if ($ignoreFromWhiteList == void 0) return result;
208209
if ($_ignoreTypeFailure(actual, $type)) return true;
209210
return result;

0 commit comments

Comments
 (0)