Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1151)

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_class_inheritance2_test.dart

Issue 23477028: Remove dart2js_foreign. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 // Test to see if resolving a hidden native class's method interferes with
6 // subsequent resolving the subclass's method. This might happen if the
7 // superclass caches the method in the prototype, so shadowing the dispatcher
8 // stored on Object.prototype.
9
10 import "package:expect/expect.dart";
11 import 'native_metadata.dart';
12
13 @Native("*A")
14 class A {
15 @native foo([a=100]);
16 }
17
18 @Native("*B")
19 class B extends A {
20 }
21
22 @Native("*C")
23 class C extends B {
24 @native foo([z=300]);
25 }
26
27 @Native("*D")
28 class D extends C {
29 }
30
31 @native makeA();
32 @native makeB();
33 @native makeC();
34 @native makeD();
35
36 @Native("""
37 // This code is all inside 'setup' and so not accesible from the global scope.
38 function inherits(child, parent) {
39 if (child.prototype.__proto__) {
40 child.prototype.__proto__ = parent.prototype;
41 } else {
42 function tmp() {};
43 tmp.prototype = parent.prototype;
44 child.prototype = new tmp();
45 child.prototype.constructor = child;
46 }
47 }
48
49 function A(){}
50 function B(){}
51 inherits(B, A);
52 function C(){}
53 inherits(C, B);
54 function D(){}
55 inherits(D, C);
56
57 A.prototype.foo = function(a){return 'A.foo(' + a + ')';}
58 C.prototype.foo = function(z){return 'C.foo(' + z + ')';}
59
60 makeA = function(){return new A};
61 makeB = function(){return new B};
62 makeC = function(){return new C};
63 makeD = function(){return new D};
64 """)
65 void setup();
66
67
68 main() {
69 setup();
70
71 var a = makeA();
72 var b = makeB();
73 var c = makeC();
74 var d = makeD();
75
76 Expect.equals('A.foo(100)', b.foo());
77 Expect.equals('C.foo(300)', d.foo());
78 // If the above line fails with C.foo(100) then the dispatch to fill in the
79 // default got the wrong one, followed by a second dispatch that resolved to
80 // the correct native method.
81
82 Expect.equals('A.foo(1)', a.foo(1));
83 Expect.equals('A.foo(2)', b.foo(2));
84 Expect.equals('C.foo(3)', c.foo(3));
85 Expect.equals('C.foo(4)', d.foo(4));
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698