OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_native_test; | 6 library js_native_test; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:html'; | 9 import 'dart:html'; |
10 import 'dart:typed_data' show ByteBuffer, Int32List; | 10 import 'dart:typed_data' show ByteBuffer, Int32List; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 document.body.append(script); | 61 document.body.append(script); |
62 } | 62 } |
63 | 63 |
64 @JS() | 64 @JS() |
65 external bool checkMap(m, String, value); | 65 external bool checkMap(m, String, value); |
66 | 66 |
67 @JS('JSON.stringify') | 67 @JS('JSON.stringify') |
68 external String stringify(o); | 68 external String stringify(o); |
69 | 69 |
70 @JS('Node') | 70 @JS('Node') |
71 external Function get JSNodeType; | 71 external get JSNodeType; |
72 | 72 |
73 @JS('Element') | 73 @JS('Element') |
74 external Function get JSElementType; | 74 external get JSElementType; |
75 | 75 |
76 @JS('Text') | 76 @JS('Text') |
77 external Function get JSTextType; | 77 external get JSTextType; |
78 | 78 |
79 @JS('HTMLCanvasElement') | 79 @JS('HTMLCanvasElement') |
80 external Function get JSHtmlCanvasElementType; | 80 external get JSHtmlCanvasElementType; |
81 | 81 |
82 @JS() | 82 @JS() |
83 class Foo { | 83 class Foo { |
84 external Foo(num a); | 84 external Foo(num a); |
85 | 85 |
86 external num get a; | 86 external num get a; |
87 external num bar(); | 87 external num bar(); |
88 } | 88 } |
89 | 89 |
90 @JS('Foo') | 90 @JS('Foo') |
91 external Function get JSFooType; | 91 external get JSFooType; |
92 | 92 |
93 @JS() | 93 @JS() |
94 @anonymous | 94 @anonymous |
95 class ExampleTypedLiteral { | 95 class ExampleTypedLiteral { |
96 external factory ExampleTypedLiteral({a, b, JS$_c, JS$class}); | 96 external factory ExampleTypedLiteral({a, b, JS$_c, JS$class}); |
97 | 97 |
98 external get a; | 98 external get a; |
99 external get b; | 99 external get b; |
100 external get JS$_c; | 100 external get JS$_c; |
101 external set JS$_c(v); | 101 external set JS$_c(v); |
102 // Identical to JS$_c but only accessible within the library. | 102 // Identical to JS$_c but only accessible within the library. |
103 external get _c; | 103 external get _c; |
104 external get JS$class; | 104 external get JS$class; |
105 external set JS$class(v); | 105 external set JS$class(v); |
106 } | 106 } |
107 | 107 |
108 @JS("Object.prototype.hasOwnProperty") | 108 @JS("Object.prototype.hasOwnProperty") |
109 external Function get _hasOwnProperty; | 109 external get _hasOwnProperty; |
110 | 110 |
111 bool hasOwnProperty(o, String name) { | 111 bool hasOwnProperty(o, String name) { |
112 return js_util.callMethod(_hasOwnProperty, 'call', [o, name]); | 112 return js_util.callMethod(_hasOwnProperty, 'call', [o, name]); |
113 } | 113 } |
114 | 114 |
115 main() { | 115 main() { |
116 _injectJs(); | 116 _injectJs(); |
117 useHtmlIndividualConfiguration(); | 117 useHtmlIndividualConfiguration(); |
118 | 118 |
119 group('js_util.jsify()', () { | 119 group('js_util.jsify()', () { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 expect(textNode is Text, isTrue); | 338 expect(textNode is Text, isTrue); |
339 expect(textNode.text, equals('foo')); | 339 expect(textNode.text, equals('foo')); |
340 }); | 340 }); |
341 | 341 |
342 test('typed object', () { | 342 test('typed object', () { |
343 Foo f = js_util.callConstructor(JSFooType, [42]); | 343 Foo f = js_util.callConstructor(JSFooType, [42]); |
344 expect(f.a, equals(42)); | 344 expect(f.a, equals(42)); |
345 }); | 345 }); |
346 }); | 346 }); |
347 } | 347 } |
OLD | NEW |