OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "package:expect/expect.dart"; |
| 6 import 'dart:_foreign_helper' show JS; |
| 7 import 'dart:_js_helper' show Creates, setNativeSubclassDispatchRecord; |
| 8 import 'dart:_interceptors' show |
| 9 findInterceptorForType, findConstructorForNativeSubclassType; |
| 10 |
| 11 // Test for fields with same name as native fields. We expect N.foo to have the |
| 12 // property name 'foo' and A.foo and B.foo to have non-conflicting names. |
| 13 |
| 14 class N native "N" { |
| 15 var foo; |
| 16 N.init(); |
| 17 } |
| 18 |
| 19 class A extends N { |
| 20 var foo = 222; |
| 21 A.init() : super.init(); |
| 22 Nfoo() => super.foo; // TODO(sra): Fix compiler assert. |
| 23 } |
| 24 |
| 25 class B extends A { |
| 26 var foo = 333; |
| 27 B.init() : super.init(); |
| 28 Afoo() => super.foo; |
| 29 Bfoo() => foo; |
| 30 |
| 31 toString() => '[N.foo = ${Nfoo()}, A.foo = ${Afoo()}, B.foo = ${Bfoo()}]'; |
| 32 } |
| 33 |
| 34 B makeB() native; |
| 35 |
| 36 @Creates('=Object') |
| 37 getBPrototype() native; |
| 38 |
| 39 void setup() native r""" |
| 40 function B() { this.foo = 111; } // N.foo |
| 41 makeB = function(){return new B;}; |
| 42 |
| 43 getBPrototype = function(){return B.prototype;}; |
| 44 """; |
| 45 |
| 46 var inscrutable; |
| 47 |
| 48 main() { |
| 49 setup(); |
| 50 inscrutable = (x) => x; |
| 51 |
| 52 setNativeSubclassDispatchRecord(getBPrototype(), findInterceptorForType(B)); |
| 53 |
| 54 B b = makeB(); |
| 55 |
| 56 var constructor = findConstructorForNativeSubclassType(B, 'init'); |
| 57 Expect.isNotNull(constructor); |
| 58 JS('', '#(#)', constructor, b); |
| 59 |
| 60 print(b); |
| 61 |
| 62 Expect.equals(333, inscrutable(b).Bfoo()); |
| 63 Expect.equals(222, inscrutable(b).Afoo()); |
| 64 Expect.equals(111, inscrutable(b).Nfoo()); |
| 65 |
| 66 Expect.equals(333, b.Bfoo()); |
| 67 Expect.equals(222, b.Afoo()); |
| 68 Expect.equals(111, b.Nfoo()); |
| 69 } |
OLD | NEW |