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 "native_testing.dart"; | 5 import "package:expect/expect.dart"; |
6 import 'dart:_js_helper' show setNativeSubclassDispatchRecord; | 6 import 'dart:_foreign_helper' show JS; |
| 7 import 'dart:_js_helper' show Native, Creates, setNativeSubclassDispatchRecord; |
7 import 'dart:_interceptors' | 8 import 'dart:_interceptors' |
8 show findInterceptorForType, findConstructorForNativeSubclassType; | 9 show findInterceptorForType, findConstructorForNativeSubclassType; |
9 | 10 |
10 // Test for super access from classes that extend native classes. | 11 // Test for super access from classes that extend native classes. |
11 | 12 |
12 @Native("N1") | 13 @Native("N1") |
13 class N1 {} | 14 class N1 {} |
14 | 15 |
15 @Native("N2") | 16 @Native("N2") |
16 class N2 extends N1 { | 17 class N2 extends N1 { |
(...skipping 28 matching lines...) Expand all Loading... |
45 void setup() native r""" | 46 void setup() native r""" |
46 function N2() {} | 47 function N2() {} |
47 N2.prototype.foo = function() { return "foo:" + this.text; } | 48 N2.prototype.foo = function() { return "foo:" + this.text; } |
48 function BB() {} | 49 function BB() {} |
49 BB.prototype.__proto__ = N2.prototype; | 50 BB.prototype.__proto__ = N2.prototype; |
50 makeBB = function(){return new BB;}; | 51 makeBB = function(){return new BB;}; |
51 | 52 |
52 getBBPrototype = function(){return BB.prototype;}; | 53 getBBPrototype = function(){return BB.prototype;}; |
53 """; | 54 """; |
54 | 55 |
| 56 var inscrutable; |
| 57 |
55 testSuperOnNative() { | 58 testSuperOnNative() { |
56 BB b1 = makeBB(); | 59 BB b1 = makeBB(); |
57 BB b2 = makeBB(); | 60 BB b2 = makeBB(); |
58 | 61 |
59 var constructor = findConstructorForNativeSubclassType(BB, 'init'); | 62 var constructor = findConstructorForNativeSubclassType(BB, 'init'); |
60 Expect.isNotNull(constructor); | 63 Expect.isNotNull(constructor); |
61 JS('', '#(#)', constructor, b1); | 64 JS('', '#(#)', constructor, b1); |
62 JS('', '#(#)', constructor, b2); | 65 JS('', '#(#)', constructor, b2); |
63 | 66 |
64 b1.text = confuse('one'); | 67 b1.text = inscrutable('one'); |
65 b2.text = confuse('two'); | 68 b2.text = inscrutable('two'); |
66 | 69 |
67 print('b1.text ${confuse(b1).text}'); | 70 print('b1.text ${inscrutable(b1).text}'); |
68 print('b2.text ${confuse(b2).text}'); | 71 print('b2.text ${inscrutable(b2).text}'); |
69 | 72 |
70 print('b1.foo() ${confuse(b1).foo()}'); | 73 print('b1.foo() ${inscrutable(b1).foo()}'); |
71 print('b2.foo() ${confuse(b2).foo()}'); | 74 print('b2.foo() ${inscrutable(b2).foo()}'); |
72 | 75 |
73 Expect.equals('one', b1.text); | 76 Expect.equals('one', b1.text); |
74 Expect.equals('two', b2.text); | 77 Expect.equals('two', b2.text); |
75 | 78 |
76 Expect.equals('foo:one', b1.foo()); | 79 Expect.equals('foo:one', b1.foo()); |
77 Expect.equals('foo:two', b2.foo()); | 80 Expect.equals('foo:two', b2.foo()); |
78 | 81 |
79 confuse(b1).text = confuse('three'); | 82 inscrutable(b1).text = inscrutable('three'); |
80 confuse(b2).text = confuse('four'); | 83 inscrutable(b2).text = inscrutable('four'); |
81 | 84 |
82 Expect.equals('three', confuse(b1).text); | 85 Expect.equals('three', inscrutable(b1).text); |
83 Expect.equals('four', confuse(b2).text); | 86 Expect.equals('four', inscrutable(b2).text); |
84 | 87 |
85 Expect.equals('foo:three', confuse(b1).foo()); | 88 Expect.equals('foo:three', inscrutable(b1).foo()); |
86 Expect.equals('foo:four', confuse(b2).foo()); | 89 Expect.equals('foo:four', inscrutable(b2).foo()); |
87 } | 90 } |
88 | 91 |
89 testSuperOnSubclassOfNative() { | 92 testSuperOnSubclassOfNative() { |
90 BB b1 = makeBB(); | 93 BB b1 = makeBB(); |
91 BB b2 = makeBB(); | 94 BB b2 = makeBB(); |
92 | 95 |
93 var constructor = findConstructorForNativeSubclassType(BB, 'init'); | 96 var constructor = findConstructorForNativeSubclassType(BB, 'init'); |
94 Expect.isNotNull(constructor); | 97 Expect.isNotNull(constructor); |
95 JS('', '#(#)', constructor, b1); | 98 JS('', '#(#)', constructor, b1); |
96 JS('', '#(#)', constructor, b2); | 99 JS('', '#(#)', constructor, b2); |
97 | 100 |
98 b1.afield = confuse('one'); | 101 b1.afield = inscrutable('one'); |
99 b2.afield = confuse('two'); | 102 b2.afield = inscrutable('two'); |
100 | 103 |
101 print('b1.afield ${confuse(b1).afield}'); | 104 print('b1.afield ${inscrutable(b1).afield}'); |
102 print('b2.afield ${confuse(b2).afield}'); | 105 print('b2.afield ${inscrutable(b2).afield}'); |
103 | 106 |
104 print('b1.afun() ${confuse(b1).afun()}'); | 107 print('b1.afun() ${inscrutable(b1).afun()}'); |
105 print('b2.afun() ${confuse(b2).afun()}'); | 108 print('b2.afun() ${inscrutable(b2).afun()}'); |
106 | 109 |
107 Expect.equals('one', b1.afield); | 110 Expect.equals('one', b1.afield); |
108 Expect.equals('two', b2.afield); | 111 Expect.equals('two', b2.afield); |
109 | 112 |
110 Expect.equals('afun:one', b1.afun()); | 113 Expect.equals('afun:one', b1.afun()); |
111 Expect.equals('afun:two', b2.afun()); | 114 Expect.equals('afun:two', b2.afun()); |
112 | 115 |
113 confuse(b1).afield = confuse('three'); | 116 inscrutable(b1).afield = inscrutable('three'); |
114 confuse(b2).afield = confuse('four'); | 117 inscrutable(b2).afield = inscrutable('four'); |
115 | 118 |
116 Expect.equals('three', confuse(b1).afield); | 119 Expect.equals('three', inscrutable(b1).afield); |
117 Expect.equals('four', confuse(b2).afield); | 120 Expect.equals('four', inscrutable(b2).afield); |
118 | 121 |
119 Expect.equals('afun:three', confuse(b1).afun()); | 122 Expect.equals('afun:three', inscrutable(b1).afun()); |
120 Expect.equals('afun:four', confuse(b2).afun()); | 123 Expect.equals('afun:four', inscrutable(b2).afun()); |
121 } | 124 } |
122 | 125 |
123 main() { | 126 main() { |
124 nativeTesting(); | |
125 setup(); | 127 setup(); |
| 128 inscrutable = (x) => x; |
126 | 129 |
127 setNativeSubclassDispatchRecord(getBBPrototype(), findInterceptorForType(BB)); | 130 setNativeSubclassDispatchRecord(getBBPrototype(), findInterceptorForType(BB)); |
128 | 131 |
129 testSuperOnNative(); | 132 testSuperOnNative(); |
130 testSuperOnSubclassOfNative(); | 133 testSuperOnSubclassOfNative(); |
131 } | 134 } |
OLD | NEW |