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

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_class_inheritance4_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 // Additional Dart code may be 'placed on' hidden native classes. With
6 // inheritance, the superclass method must not be reached by a call on the
7 // subclass.
8
9 import "package:expect/expect.dart";
10 import 'native_metadata.dart';
11
12 @Native("*A")
13 class A {
14 var _field;
15
16 int get X => _field;
17 void set X(int x) { _field = x; }
18
19 int method(int z) => _field + z;
20 }
21
22 @Native("*B")
23 class B extends A {
24 var _field2;
25
26 int get X => _field2;
27 void set X(int x) { _field2 = x; }
28
29 int method(int z) => _field2 + z;
30 }
31
32 @native A makeA() { return new A(); }
33 @native B makeB() { return new B(); }
34
35 @Native(r"""
36 function inherits(child, parent) {
37 if (child.prototype.__proto__) {
38 child.prototype.__proto__ = parent.prototype;
39 } else {
40 function tmp() {};
41 tmp.prototype = parent.prototype;
42 child.prototype = new tmp();
43 child.prototype.constructor = child;
44 }
45 }
46
47 function A(){}
48 function B(){}
49 inherits(B, A);
50 makeA = function(){return new A;};
51 makeB = function(){return new B;};
52 """)
53 void setup();
54
55 testBasicA_dynamic() {
56 setup(); // Fresh constructors.
57
58 var a = [makeA()][0];
59
60 a.X = 100;
61 Expect.equals(100, a._field);
62 Expect.equals(100, a.X);
63 Expect.equals(150, a.method(50));
64 }
65
66 testBasicA_typed() {
67 setup(); // Fresh constructors.
68
69 A a = makeA();
70
71 a.X = 100;
72 Expect.equals(100, a._field);
73 Expect.equals(100, a.X);
74 Expect.equals(150, a.method(50));
75 }
76
77 testBasicB_dynamic() {
78 setup(); // Fresh constructors.
79
80 var b = [makeB()][0];
81
82 b._field = 1;
83 b.X = 123;
84 Expect.equals(1, b._field);
85 Expect.equals(123, b._field2);
86 Expect.equals(123, b.X);
87 Expect.equals(200, b.method(77));
88 }
89
90 testBasicB_typed() {
91 setup(); // Fresh constructors.
92
93 B b = makeB();
94
95 b._field = 1;
96 b.X = 123;
97 Expect.equals(1, b._field);
98 Expect.equals(123, b._field2);
99 Expect.equals(123, b.X);
100 Expect.equals(200, b.method(77));
101 }
102
103 testAB_dynamic() {
104 setup(); // Fresh constructors.
105
106 var things = [makeA(), makeB()];
107 var a = things[0];
108 var b = things[1];
109
110 a.X = 100;
111 Expect.equals(100, a._field);
112 Expect.equals(100, a.X);
113 Expect.equals(150, a.method(50));
114
115 b._field = 1;
116 b._field2 = 2;
117 b.X = 123;
118 Expect.equals(1, b._field);
119 Expect.equals(123, b._field2);
120 Expect.equals(123, b.X);
121 Expect.equals(200, b.method(77));
122 }
123
124 testAB_typed() {
125 setup(); // Fresh constructors.
126
127 A a = makeA();
128 B b = makeB();
129
130 a.X = 100;
131 Expect.equals(100, a._field);
132 Expect.equals(100, a.X);
133 Expect.equals(150, a.method(50));
134
135 b._field = 1;
136 b._field2 = 2;
137 b.X = 123;
138 Expect.equals(1, b._field);
139 Expect.equals(123, b._field2);
140 Expect.equals(123, b.X);
141 Expect.equals(200, b.method(77));
142 }
143
144 main() {
145 testBasicA_dynamic();
146 testBasicA_typed();
147 testBasicB_dynamic();
148 testBasicB_typed();
149 testAB_dynamic();
150 testAB_typed();
151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698