mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 13:28:03 +00:00
Migrate language_2/interceptor to NNBD.
Change-Id: Ibbc89b68ef980e1ff9913c299c05d5117b249477 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148949 Auto-Submit: Bob Nystrom <rnystrom@google.com> Commit-Queue: Erik Ernst <eernst@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
This commit is contained in:
parent
0e6c8683e3
commit
9c2075be49
25
tests/language/interceptor/interceptor2_test.dart
Normal file
25
tests/language/interceptor/interceptor2_test.dart
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
// Regression test for issue http://dartbug.com/6903: dart2js used to
|
||||
// not generate an interceptor forwarder when a getter call and a
|
||||
// method call on an intercepted method were both used.
|
||||
|
||||
class A {
|
||||
get iterator => () => 499;
|
||||
}
|
||||
|
||||
main() {
|
||||
var a = <dynamic>[
|
||||
new A(),
|
||||
[1, 1]
|
||||
];
|
||||
Expect.equals(499, a[0].iterator());
|
||||
Expect.equals(499, (a[0].iterator)());
|
||||
for (var i in a[1]) {
|
||||
Expect.equals(1, i);
|
||||
}
|
||||
}
|
17
tests/language/interceptor/interceptor3_test.dart
Normal file
17
tests/language/interceptor/interceptor3_test.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
// Test that code motion in the presence of interceptors work in dart2js.
|
||||
|
||||
main() {
|
||||
var a = <dynamic>[2, '2'];
|
||||
var b = a[1];
|
||||
if (a[0] == 2 && b is String) {
|
||||
Expect.isTrue(b.contains('2'));
|
||||
} else {
|
||||
b.isEven();
|
||||
}
|
||||
}
|
14
tests/language/interceptor/interceptor4_test.dart
Normal file
14
tests/language/interceptor/interceptor4_test.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
// Test that dart2js gets the right interceptor for an int.
|
||||
|
||||
main() {
|
||||
var a = [1];
|
||||
var b = a[0];
|
||||
Expect.equals('1', b.toString());
|
||||
Expect.isTrue(b.isOdd);
|
||||
}
|
11
tests/language/interceptor/interceptor5_test.dart
Normal file
11
tests/language/interceptor/interceptor5_test.dart
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
get X => [() => 123];
|
||||
|
||||
main() {
|
||||
Expect.equals(123, X.last());
|
||||
}
|
16
tests/language/interceptor/interceptor7_test.dart
Normal file
16
tests/language/interceptor/interceptor7_test.dart
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Test that dart2js uses the right interceptor when call a method on
|
||||
// something that has type number.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
var array = <dynamic>[];
|
||||
|
||||
main() {
|
||||
array.add(false);
|
||||
dynamic x = array[0] ? 1.5 : 2;
|
||||
Expect.isTrue(x.isEven);
|
||||
}
|
12
tests/language/interceptor/interceptor8_test.dart
Normal file
12
tests/language/interceptor/interceptor8_test.dart
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Regression test for dart2js whose codegen used to not consider a double
|
||||
// could be instantiated when doing int / int.
|
||||
|
||||
var a = [5, 2];
|
||||
|
||||
main() {
|
||||
print(a[0] / a[1]);
|
||||
}
|
32
tests/language/interceptor/interceptor9_test.dart
Normal file
32
tests/language/interceptor/interceptor9_test.dart
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Regression test for dart2js whose codegen in some cases did not take is
|
||||
// tests into account when computing the set of classes for interceptors.
|
||||
// See http://dartbug.com/17325
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "dart:typed_data";
|
||||
|
||||
confuse(x, [y = null]) => new DateTime.now().day == 42 ? y : x;
|
||||
|
||||
boom() {
|
||||
var x = confuse(new Uint8List(22), "");
|
||||
Expect.isTrue(x is Uint8List);
|
||||
x.startsWith("a");
|
||||
x.endsWith("u");
|
||||
}
|
||||
|
||||
main() {
|
||||
try {
|
||||
var f;
|
||||
if (confuse(true)) {
|
||||
// prevent inlining
|
||||
f = boom;
|
||||
}
|
||||
f();
|
||||
} catch (e) {
|
||||
if (e is ExpectException) throw e;
|
||||
}
|
||||
}
|
35
tests/language/interceptor/interceptor_test.dart
Normal file
35
tests/language/interceptor/interceptor_test.dart
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
// Test that interceptors (that is, methods in classes implemented as
|
||||
// JavaScript primitives) in dart2js work.
|
||||
|
||||
class A {
|
||||
codeUnitAt(a) => a;
|
||||
}
|
||||
|
||||
main() {
|
||||
var res = <dynamic>[[], 1, 'foo', new A()];
|
||||
Expect.throws(() => res[0].codeUnitAt(1));
|
||||
Expect.throws(() => (res[0].codeUnitAt)(1));
|
||||
|
||||
Expect.throws(() => res[1].codeUnitAt(1));
|
||||
Expect.throws(() => (res[1].codeUnitAt)(1));
|
||||
|
||||
Expect.equals(111, res[2].codeUnitAt(1));
|
||||
Expect.equals(111, (res[2].codeUnitAt)(1));
|
||||
Expect.throws(() => res[2].codeUnitAt(1, 4));
|
||||
Expect.throws(() => res[2].codeUnitAt());
|
||||
Expect.throws(() => (res[2].codeUnitAt)(1, 4));
|
||||
Expect.throws(() => (res[2].codeUnitAt)());
|
||||
|
||||
Expect.equals(1, res[3].codeUnitAt(1));
|
||||
Expect.equals(1, (res[3].codeUnitAt)(1));
|
||||
Expect.throws(() => res[3].codeUnitAt(1, 4));
|
||||
Expect.throws(() => res[3].codeUnitAt());
|
||||
Expect.throws(() => (res[3].codeUnitAt)(1, 4));
|
||||
Expect.throws(() => (res[3].codeUnitAt)());
|
||||
}
|
Loading…
Reference in a new issue