OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 @JS() |
| 6 library js_function_getter_test; |
| 7 |
| 8 import 'dart:html'; |
| 9 |
| 10 import 'package:js/js.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
| 12 import 'package:unittest/html_config.dart'; |
| 13 import 'package:unittest/html_individual_config.dart'; |
| 14 |
| 15 _injectJs() { |
| 16 document.body.append(new ScriptElement() |
| 17 ..type = 'text/javascript' |
| 18 ..innerHtml = r""" |
| 19 var bar = { }; |
| 20 |
| 21 bar.instanceMember = function() { |
| 22 if (this !== bar) { |
| 23 throw 'Unexpected this!'; |
| 24 } |
| 25 return arguments.length; |
| 26 }; |
| 27 |
| 28 bar.staticMember = function() { |
| 29 return arguments.length * 2; |
| 30 }; |
| 31 |
| 32 bar.dynamicStatic = function() { |
| 33 return arguments.length; |
| 34 }; |
| 35 |
| 36 bar.add = function(a, b) { |
| 37 return a + b; |
| 38 }; |
| 39 |
| 40 var foo = { 'bar' : bar }; |
| 41 """); |
| 42 } |
| 43 |
| 44 typedef int AddFn(int x, int y); |
| 45 |
| 46 @JS() |
| 47 abstract class Bar { |
| 48 external Function get staticMember; |
| 49 external Function get instanceMember; |
| 50 external AddFn get add; |
| 51 external get dynamicStatic; |
| 52 external num get nonFunctionStatic; |
| 53 } |
| 54 |
| 55 @JS() |
| 56 abstract class Foo { |
| 57 external Bar get bar; |
| 58 } |
| 59 |
| 60 @JS() |
| 61 external Foo get foo; |
| 62 |
| 63 main() { |
| 64 _injectJs(); |
| 65 |
| 66 useHtmlIndividualConfiguration(); |
| 67 |
| 68 group('call getter as function', () { |
| 69 test('member function', () { |
| 70 expect(foo.bar.instanceMember(), equals(0)); |
| 71 expect(foo.bar.instanceMember(0), equals(1)); |
| 72 expect(foo.bar.instanceMember(0,0), equals(2)); |
| 73 expect(foo.bar.instanceMember(0,0,0,0,0,0), equals(6)); |
| 74 var instanceMember = foo.bar.instanceMember; |
| 75 expect(() => instanceMember(), throws); |
| 76 expect(() => instanceMember(0), throws); |
| 77 expect(() => instanceMember(0,0), throws); |
| 78 expect(() => instanceMember(0,0,0,0,0,0), throws); |
| 79 }); |
| 80 |
| 81 test('static function', () { |
| 82 expect(foo.bar.staticMember(), equals(0)); |
| 83 expect(foo.bar.staticMember(0), equals(2)); |
| 84 expect(foo.bar.staticMember(0,0), equals(4)); |
| 85 expect(foo.bar.staticMember(0,0,0,0,0,0), equals(12)); |
| 86 var staticMember = foo.bar.staticMember; |
| 87 expect(staticMember(), equals(0)); |
| 88 expect(staticMember(0), equals(2)); |
| 89 expect(staticMember(0,0), equals(4)); |
| 90 expect(staticMember(0,0,0,0,0,0), equals(12)); |
| 91 }); |
| 92 |
| 93 test('static dynamicStatic', () { |
| 94 expect(foo.bar.dynamicStatic(), equals(0)); |
| 95 expect(foo.bar.dynamicStatic(0), equals(1)); |
| 96 expect(foo.bar.dynamicStatic(0,0), equals(2)); |
| 97 expect(foo.bar.dynamicStatic(0,0,0,0,0,0), equals(6)); |
| 98 var dynamicStatic = foo.bar.dynamicStatic; |
| 99 expect(dynamicStatic(), equals(0)); |
| 100 expect(dynamicStatic(0), equals(1)); |
| 101 expect(dynamicStatic(0,0), equals(2)); |
| 102 expect(dynamicStatic(0,0,0,0,0,0), equals(6)); |
| 103 }); |
| 104 |
| 105 test('typedef function', () { |
| 106 expect(foo.bar.add(4,5), equals(9)); |
| 107 }); |
| 108 }); |
| 109 } |
OLD | NEW |