OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 @JS() | 5 @JS() |
6 library js_typed_interop_test; | 6 library js_typed_interop_test; |
7 | 7 |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 | 9 |
10 import 'package:js/js.dart'; | 10 import 'package:js/js.dart'; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 function confuse(obj) { return obj; } | 79 function confuse(obj) { return obj; } |
80 | 80 |
81 function StringWrapper(str) { | 81 function StringWrapper(str) { |
82 this.str = str; | 82 this.str = str; |
83 } | 83 } |
84 StringWrapper.prototype = { | 84 StringWrapper.prototype = { |
85 charCodeAt: function(index) { | 85 charCodeAt: function(index) { |
86 return this.str.charCodeAt(index); | 86 return this.str.charCodeAt(index); |
87 } | 87 } |
88 }; | 88 }; |
89 function getCanvasContext() { | |
90 return document.createElement('canvas').getContext('2d'); | |
91 } | |
92 window.windowProperty = 42; | |
93 document.documentProperty = 45; | |
89 """); | 94 """); |
90 } | 95 } |
91 | 96 |
92 class RegularClass { | 97 class RegularClass { |
93 factory RegularClass(a) { | 98 factory RegularClass(a) { |
94 return new RegularClass.fooConstructor(a); | 99 return new RegularClass.fooConstructor(a); |
95 } | 100 } |
96 RegularClass.fooConstructor(this.a); | 101 RegularClass.fooConstructor(this.a); |
97 var a; | 102 var a; |
98 } | 103 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 @JS() | 174 @JS() |
170 class StringWrapper { | 175 class StringWrapper { |
171 external StringWrapper(String str); | 176 external StringWrapper(String str); |
172 external int charCodeAt(int i); | 177 external int charCodeAt(int i); |
173 } | 178 } |
174 | 179 |
175 // Defeat JS type inference by calling through JavaScript interop. | 180 // Defeat JS type inference by calling through JavaScript interop. |
176 @JS() | 181 @JS() |
177 external confuse(obj); | 182 external confuse(obj); |
178 | 183 |
184 @JS() | |
185 external CanvasRenderingContext2D getCanvasContext(); | |
186 | |
187 @JS('window.window.document.documentProperty') | |
188 external num get propertyOnDocument; | |
189 | |
190 @JS('window.self.window.window.windowProperty') | |
191 external num get propertyOnWindow; | |
192 | |
179 main() { | 193 main() { |
180 _injectJs(); | 194 _injectJs(); |
181 | 195 |
182 useHtmlIndividualConfiguration(); | 196 useHtmlIndividualConfiguration(); |
183 | 197 |
184 group('object literal', () { | 198 group('object literal', () { |
185 test('simple', () { | 199 test('simple', () { |
186 var l = new ExampleLiteral(x: 3, y: "foo"); | 200 var l = new ExampleLiteral(x: 3, y: "foo"); |
187 expect(l.x, equals(3)); | 201 expect(l.x, equals(3)); |
188 expect(l.y, equals("foo")); | 202 expect(l.y, equals("foo")); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 | 381 |
368 // We do know at runtime whether something is a JsArray or not. | 382 // We do know at runtime whether something is a JsArray or not. |
369 expect(foo is List, isFalse); | 383 expect(foo is List, isFalse); |
370 }); | 384 }); |
371 | 385 |
372 test('dart interfaces', () { | 386 test('dart interfaces', () { |
373 expect(foo is Function, isFalse); | 387 expect(foo is Function, isFalse); |
374 expect(selection is List, isTrue); | 388 expect(selection is List, isTrue); |
375 }); | 389 }); |
376 }); | 390 }); |
391 group('html', () { | |
392 test('return html type', () { | |
393 expect(getCanvasContext() is CanvasRenderingContext2D, isTrue); | |
394 }); | |
395 test('js path contains html types', () { | |
Alan Knight
2015/11/04 18:44:14
nit: Not clear to me what this testing.
Jacob
2015/11/04 19:01:30
This case would fail previously
note the path to
| |
396 expect(propertyOnWindow, equals(42)); | |
397 expect(propertyOnDocument, equals(45)); | |
398 }); | |
399 }); | |
377 } | 400 } |
OLD | NEW |