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:_js_helper' show Creates, setNativeSubclassDispatchRecord; |
| 7 import 'dart:_interceptors' show findInterceptorForType; |
| 8 |
| 9 // Test that subclasses of native classes can be defined by setting the dispatch |
| 10 // record. |
| 11 |
| 12 class A native "A" { |
| 13 foo(x) => '$x,${this.oof()}'; |
| 14 oof() => 'A'; |
| 15 } |
| 16 |
| 17 class B extends A { |
| 18 oof() => 'B'; |
| 19 } |
| 20 |
| 21 B makeB1() native; |
| 22 B makeB2() native; |
| 23 B makeC() native; |
| 24 |
| 25 @Creates('=Object') |
| 26 getBPrototype() native; |
| 27 |
| 28 @Creates('=Object') |
| 29 getCPrototype() native; |
| 30 |
| 31 void setup() native r""" |
| 32 function A() {} |
| 33 function B() {} |
| 34 function C() {} |
| 35 makeA = function(){return new A;}; |
| 36 makeB1 = function(){return new B;}; |
| 37 makeB2 = function(){return new B;}; |
| 38 makeC = function(){return new C;}; |
| 39 |
| 40 getBPrototype = function(){return B.prototype;}; |
| 41 getCPrototype = function(){return C.prototype;}; |
| 42 """; |
| 43 |
| 44 main() { |
| 45 setup(); |
| 46 |
| 47 setNativeSubclassDispatchRecord(getBPrototype(), findInterceptorForType(B)); |
| 48 setNativeSubclassDispatchRecord(getCPrototype(), findInterceptorForType(B)); |
| 49 |
| 50 B b1 = makeB1(); |
| 51 Expect.equals('1,B', b1.foo(1)); |
| 52 |
| 53 B b2 = makeB2(); |
| 54 Expect.equals('2,B', b2.foo(2)); |
| 55 |
| 56 B b3 = makeC(); |
| 57 Expect.equals('3,B', b3.foo(3)); |
| 58 } |
OLD | NEW |