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