Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: test/browser/runtime_tests.js

Issue 1138793002: Tag closures with their types (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/browser/runtime_tests.js
diff --git a/test/browser/runtime_tests.js b/test/browser/runtime_tests.js
index 59d48d5603c7eed09f3083f71b0132cf54362fea..5a225576ba83adeb49e18bc6c1e5d965f582d539 100644
--- a/test/browser/runtime_tests.js
+++ b/test/browser/runtime_tests.js
@@ -155,6 +155,22 @@ suite('instanceOf', () => {
function bar8(b, s, o) { return null; }
setRuntimeType(bar8, functionType(B, [B, String], {p: Object}));
+ let cls1 = dart.fn((c, s) => { return null; }, A, [C, String]);
+
+ let cls2 = dart.fn((b, s) => { return null; }, dynamic, [B, String]);
+
+ let cls3 = dart.fn((b, o) => { return null; }, B, [B, Object]);
+
+ let cls4 = dart.fn((b, o) => { return null; }, B, [B, dynamic]);
+
+ let cls5 = dart.fn((a, o) => { return null; }, C, [A, Object]);
+
+ let cls6 = dart.fn((b, s, o) => { return null; }, B, [B, String, String]);
+
+ let cls7 = dart.fn((b, s, o) => { return null; }, B, [B, String], [Object]);
+
+ let cls8 = dart.fn((b, s, o) => { return null; }, B, [B, String], {p: Object});
+
function checkType(x, type, expectedTrue) {
if (expectedTrue === undefined) expectedTrue = true;
expect(instanceOf(x, type), expectedTrue);
@@ -331,32 +347,160 @@ suite('instanceOf', () => {
expect(isGroundType(Foo), false);
expect(isGroundType(functionType(B, [B, String])), false);
checkType(bar1, Foo, false);
+ checkType(cls1, Foo, false);
checkType(bar1, functionType(B, [B, String]), false);
+ checkType(cls1, functionType(B, [B, String]), false);
checkType(bar2, Foo, false);
+ checkType(cls2, Foo, false);
checkType(bar2, functionType(B, [B, String]), false);
+ checkType(cls2, functionType(B, [B, String]), false);
checkType(bar3, Foo);
+ checkType(cls3, Foo);
checkType(bar3, functionType(B, [B, String]));
+ checkType(cls3, functionType(B, [B, String]));
checkType(bar4, Foo, false);
+ checkType(cls4, Foo, false);
// TODO(vsm): Revisit. bar4 is (B, *) -> B. Perhaps it should be treated as top for a reified object.
checkType(bar4, functionType(B, [B, String]), false);
+ checkType(cls4, functionType(B, [B, String]), false);
checkType(bar5, Foo);
+ checkType(cls5, Foo);
checkType(bar5, functionType(B, [B, String]));
+ checkType(cls5, functionType(B, [B, String]));
checkType(bar6, Foo, false);
+ checkType(cls6, Foo, false);
checkType(bar6, functionType(B, [B, String]), false);
+ checkType(cls6, functionType(B, [B, String]), false);
checkType(bar7, Foo);
+ checkType(cls7, Foo);
checkType(bar7, functionType(B, [B, String]));
+ checkType(cls7, functionType(B, [B, String]));
checkType(bar7, runtimeType(bar6));
+ checkType(cls7, runtimeType(bar6));
checkType(bar8, Foo);
+ checkType(cls8, Foo);
checkType(bar8, functionType(B, [B, String]));
+ checkType(cls8, functionType(B, [B, String]));
checkType(bar8, runtimeType(bar6), false);
+ checkType(cls8, runtimeType(bar6), false);
checkType(bar7, runtimeType(bar8), false);
+ checkType(cls7, runtimeType(bar8), false);
checkType(bar8, runtimeType(bar7), false);
+ checkType(cls8, runtimeType(bar7), false);
// Parameterized typedefs
expect(isGroundType(FuncG), true);
expect(isGroundType(FuncG$(B, String)), false);
checkType(bar1, FuncG$(B, String), false);
+ checkType(cls1, FuncG$(B, String), false);
checkType(bar3, FuncG$(B, String));
+ checkType(cls3, FuncG$(B, String));
+ });
+
+ test('dcall', () => {
+ function dd2d(x, y) {return x};
+ dart.fn(dd2d);
+ function ii2i(x, y) {return x};
+ dart.fn(ii2i, core.int, [core.int, core.int]);
+ function ii_2i(x, y) {return x};
+ dart.fn(ii_2i, core.int, [core.int], [core.int]);
+ function i_i2i(x, opts) {return x};
+ dart.fn(i_i2i, core.int, [core.int], {extra: core.int});
+
+ assert.equal(dart.dcall(dd2d, 0, 1), 0);
+ assert.equal(dart.dcall(dd2d, "hello", "world"), "hello");
+ assert.throws(() => dart.dcall(dd2d, 0));
+ assert.throws(() => dart.dcall(dd2d, 0, 1, 2));
+ assert.throws(() => dart.dcall(dd2d, 0, 1, {extra : 3}));
+// This should throw but currently doesn't.
vsm 2015/05/18 17:35:10 Nit: indent
Leaf 2015/05/19 00:02:21 Done.
+// assert.throws(() => dart.dcall(dd2d, 0, {extra:3}));
+
+ assert.equal(dart.dcall(ii2i, 0, 1), 0);
+ assert.throws(() => dart.dcall(ii2i, "hello", "world"));
+ assert.throws(() => dart.dcall(ii2i, 0));
+ assert.throws(() => dart.dcall(ii2i, 0, 1, 2));
+
+ assert.equal(dart.dcall(ii_2i, 0, 1), 0);
+ assert.throws(() => dart.dcall(ii_2i, "hello", "world"));
+ assert.equal(dart.dcall(ii_2i, 0), 0);
+ assert.throws(() => dart.dcall(ii_2i, 0, 1, 2));
+
+ assert.throws(() => dart.dcall(i_i2i, 0, 1));
+ assert.throws(() => dart.dcall(i_i2i, "hello", "world"));
+ assert.equal(dart.dcall(i_i2i, 0), 0);
+ assert.throws(() => dart.dcall(i_i2i, 0, 1, 2));
+ assert.equal(dart.dcall(i_i2i, 0, {extra: 3}), 0);
+ });
+
+ test('Types on top level functions', () => {
+ // Test some generated code
+ // Test the lazy path
+ checkType(core.identityHashCode, dart.functionType(core.int, [core.Object]));
+ // Test the normal path
+ checkType(core.identical, dart.functionType(core.bool, [core.Object, core.Object]));
vsm 2015/05/18 17:35:10 line len
Leaf 2015/05/19 00:02:21 Done.
+
+ // Hand crafted tests
+ // All dynamic
+ function dd2d(x, y) {return x};
+ dart.fn(dd2d);
+ checkType(dd2d, dart.functionType(dart.dynamic, [dart.dynamic, dart.dynamic]));
+
+ // Set the type eagerly
+ function ii2i(x, y) {return x};
+ dart.fn(ii2i, core.int, [core.int, core.int]);
+ checkType(ii2i, dart.functionType(core.int, [core.int, core.int]));
+
+ // Set the type lazily
+ function ss2s(x, y) {return x};
+ var coreString;
+ dart.fn(ss2s, () => dart.functionType(coreString, [coreString, coreString]));
+ coreString = core.String;
+ checkType(ss2s, dart.functionType(core.String, [core.String, core.String]));
+
+ // Optional types
+ function ii_2i(x, y) {return x};
+ dart.fn(ii_2i, core.int, [core.int], [core.int]);
+ checkType(ii_2i, dart.functionType(core.int, [core.int], [core.int]));
+ checkType(ii_2i, dart.functionType(core.int, [core.int, core.int]));
+ checkType(ii_2i, dart.functionType(core.int, [], [core.int, core.int]), false);
+ checkType(ii_2i, dart.functionType(core.int, [core.int], {extra: core.int}), false);
+
+ // Named types
+ function i_i2i(x, opts) {return x};
+ dart.fn(i_i2i, core.int, [core.int], {extra: core.int});
+ checkType(i_i2i, dart.functionType(core.int, [core.int], {extra: core.int}));
+ checkType(i_i2i, dart.functionType(core.int, [core.int, core.int]), false);
+ checkType(i_i2i, dart.functionType(core.int, [core.int], {}));
+ checkType(i_i2i, dart.functionType(core.int, [], {extra: core.int, also: core.int}), false);
+ checkType(i_i2i, dart.functionType(core.int, [core.int], [core.int]), false);
+ });
+
+ test('Method tearoffs', () => {
+ let c = collection;
+ // Tear off of an inherited method
+ let map = new (Map$(core.int, core.String))();
+ checkType(dart.tearoff(map, 'toString'), dart.functionType(String, []));
+ checkType(dart.tearoff(map, 'toString'), dart.functionType(int, []), false);
+
+ // Tear off of a method directly on the object
+ let smap = new (c.SplayTreeMap$(core.int, core.String))();
+ checkType(dart.tearoff(smap, 'forEach'), dart.functionType(dart.void, [dart.functionType(dart.void, [core.int, core.String])]));
+ checkType(dart.tearoff(smap, 'forEach'), dart.functionType(dart.void, [dart.functionType(dart.void, [core.String, core.String])]), false);
+
+ // Tear off of a mixed in method
+ let mapB = new (c.MapBase$(core.int, core.int))();
+ checkType(dart.tearoff(mapB, 'forEach'), dart.functionType(dart.void, [dart.functionType(dart.void, [core.int, core.int])]));
+ checkType(dart.tearoff(mapB, 'forEach'), dart.functionType(dart.void, [dart.functionType(dart.void, [core.int, core.String])]), false);
+
+ // Tear off of a method with a symbol name
+ let listB = new (c.ListBase$(core.int))();
+ checkType(dart.tearoff(listB, core.$add), dart.functionType(dart.void, [core.int]));
+ checkType(dart.tearoff(listB, core.$add), dart.functionType(dart.void, [core.String]), false);
+
+ // Tear off of a static method
+ checkType(c.ListBase.listToString, dart.functionType(core.String, [core.List]));
+ checkType(c.ListBase.listToString, dart.functionType(core.String, [core.String]), false);
+
});
test('Object members', () => {

Powered by Google App Engine
This is Rietveld 408576698