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 // SharedOptions=--trust-type-annotations |
| 6 @JS() |
| 7 library js_function_getter_trust_types_test; |
| 8 |
| 9 import 'dart:html'; |
| 10 |
| 11 import 'package:js/js.dart'; |
| 12 import 'package:unittest/unittest.dart'; |
| 13 import 'package:unittest/html_config.dart'; |
| 14 import 'package:unittest/html_individual_config.dart'; |
| 15 |
| 16 _injectJs() { |
| 17 document.body.append(new ScriptElement() |
| 18 ..type = 'text/javascript' |
| 19 ..innerHtml = r""" |
| 20 var bar = { }; |
| 21 |
| 22 bar.nonFunctionStatic = function() { |
| 23 return arguments.length * 2; |
| 24 }; |
| 25 |
| 26 bar.add = function(a, b) { |
| 27 return a + b; |
| 28 }; |
| 29 |
| 30 var foo = { 'bar' : bar }; |
| 31 """); |
| 32 } |
| 33 |
| 34 typedef int AddFn(int x, int y); |
| 35 |
| 36 @JS() |
| 37 class NotAFn { } |
| 38 |
| 39 @JS() |
| 40 abstract class Bar { |
| 41 external AddFn get add; |
| 42 external NotAFn get nonFunctionStatic; |
| 43 } |
| 44 |
| 45 @JS() |
| 46 abstract class Foo { |
| 47 external Bar get bar; |
| 48 } |
| 49 |
| 50 @JS() |
| 51 external Foo get foo; |
| 52 |
| 53 main() { |
| 54 _injectJs(); |
| 55 |
| 56 useHtmlIndividualConfiguration(); |
| 57 |
| 58 group('trust types', () { |
| 59 test('static nonFunctionStatic', () { |
| 60 expect(() => foo.bar.nonFunctionStatic(), throws); |
| 61 expect(() => foo.bar.nonFunctionStatic(0), throws); |
| 62 expect(() => foo.bar.nonFunctionStatic(0,0), throws); |
| 63 expect(() => foo.bar.nonFunctionStatic(0,0,0,0,0,0), throws); |
| 64 }); |
| 65 |
| 66 test('typedef function', () { |
| 67 expect(() => foo.bar.add(4), throws); |
| 68 expect(() => foo.bar.add(4,5,10), throws); |
| 69 expect(foo.bar.add(4,5), equals(9)); |
| 70 }); |
| 71 }); |
| 72 } |
OLD | NEW |