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:
Robert Nystrom 2020-05-26 16:04:15 +00:00 committed by commit-bot@chromium.org
parent 0e6c8683e3
commit 9c2075be49
8 changed files with 162 additions and 0 deletions

View 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);
}
}

View 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();
}
}

View 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);
}

View 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());
}

View 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);
}

View 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]);
}

View 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;
}
}

View 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)());
}