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 import "package:expect/expect.dart"; | 5 import 'native_testing.dart'; |
6 import 'dart:_js_helper' show Native, Creates, setNativeSubclassDispatchRecord; | 6 import 'dart:_js_helper' show setNativeSubclassDispatchRecord; |
7 import 'dart:_interceptors' | 7 import 'dart:_interceptors' |
8 show | 8 show |
9 JSObject, // The interface, which may be re-exported by a | 9 JSObject, // The interface, which may be re-exported by a |
10 // js-interop library. | 10 // js-interop library. |
11 JavaScriptObject, // The interceptor abstract class. | 11 JavaScriptObject, // The interceptor abstract class. |
12 PlainJavaScriptObject, // The interceptor concrete class. | 12 PlainJavaScriptObject, // The interceptor concrete class. |
13 UnknownJavaScriptObject, // The interceptor concrete class. | 13 UnknownJavaScriptObject, // The interceptor concrete class. |
14 Interceptor; | 14 Interceptor; |
15 | 15 |
16 // Test for JavaScript objects from outside the Dart program. Although we only | 16 // Test for JavaScript objects from outside the Dart program. Although we only |
17 // export the interface [JSObject] to user level code, this test makes sure we | 17 // export the interface [JSObject] to user level code, this test makes sure we |
18 // can distinguish plain JavaScript objects from ones with a complex prototype. | 18 // can distinguish plain JavaScript objects from ones with a complex prototype. |
19 | 19 |
20 @Native('QQ') | 20 @Native('QQ') |
21 class Q {} | 21 class Q {} |
22 | 22 |
23 makeA() native ; | 23 makeA() native ; |
24 makeB() native ; | 24 makeB() native ; |
25 makeQ() native ; | 25 makeQ() native ; |
26 | 26 |
27 void setup() native r""" | 27 void setup() native r""" |
28 makeA = function(){return {hello: 123};}; | 28 makeA = function(){return {hello: 123};}; |
29 | 29 |
30 function BB(){} | 30 function BB(){} |
31 makeB = function(){return new BB();}; | 31 makeB = function(){return new BB();}; |
32 | 32 |
33 function QQ(){} | 33 function QQ(){} |
34 makeQ = function(){return new QQ();}; | 34 makeQ = function(){return new QQ();}; |
| 35 |
| 36 self.nativeConstructor(QQ); |
35 """; | 37 """; |
36 | 38 |
37 class Is<T> { | 39 class Is<T> { |
38 bool check(x) => x is T; | 40 bool check(x) => x is T; |
39 } | 41 } |
40 | 42 |
41 static_test() { | 43 static_test() { |
42 var x = makeA(); | 44 var x = makeA(); |
43 Expect.isTrue(x is JSObject); | 45 Expect.isTrue(x is JSObject); |
44 Expect.isTrue(x is JavaScriptObject); | 46 Expect.isTrue(x is JavaScriptObject); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 x = makeQ(); | 88 x = makeQ(); |
87 Expect.isFalse(isJSObject(x)); | 89 Expect.isFalse(isJSObject(x)); |
88 Expect.isFalse(isJavaScriptObject(x)); | 90 Expect.isFalse(isJavaScriptObject(x)); |
89 Expect.isFalse(isPlainJavaScriptObject(x)); | 91 Expect.isFalse(isPlainJavaScriptObject(x)); |
90 Expect.isFalse(isUnknownJavaScriptObject(x)); | 92 Expect.isFalse(isUnknownJavaScriptObject(x)); |
91 Expect.isTrue(isQ(x)); | 93 Expect.isTrue(isQ(x)); |
92 Expect.isFalse(x.runtimeType == JSObject); | 94 Expect.isFalse(x.runtimeType == JSObject); |
93 } | 95 } |
94 | 96 |
95 main() { | 97 main() { |
| 98 nativeTesting(); |
96 setup(); | 99 setup(); |
97 | 100 |
98 dynamic_test(); | 101 dynamic_test(); |
99 static_test(); | 102 static_test(); |
100 } | 103 } |
OLD | NEW |