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

Side by Side Diff: tests/compiler/dart2js_native/subclassing_constructor_1_test.dart

Issue 25675002: Generative constructor factories for native objects (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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) 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, findConstructorForWebComponentType;
10
11 // Test that subclasses of native classes can be initialized by calling the
12 // 'upgrade' constructor.
13
14 var trace = [];
15
16 var log;
17
18 class A native "A" {
19 final a1 = log(101); // Only initialized IF named constructor called.
20 final a2; // Initialized by native constructor.
21 final a3; // Initialized only by A.two.
22 var a4 = log(104);
23
24 A.one();
25
26 A.two() : a3 = log(103) {
27 log('body(A.two)');
28 log(a4 += increment);
29 }
30
31 get increment => 10;
32 }
33
34 class B extends A {
35 final b1;
36 final b2 = log(202);
37 var b3;
38
39 B.one() : super.one();
40
41 B.two() : b1 = log(201), super.two(), b3 = log(203) {
42 log('body(B.two)');
43 }
44
45 get increment => 20;
46 }
47
48
49 makeB() native;
50
51 @Creates('=Object')
52 getBPrototype() native;
53
54 void setup() native r"""
55 function B() { this.a2 = 102; }
56
57 makeB = function(){return new B;};
58
59 getBPrototype = function(){return B.prototype;};
60 """;
61
62
63 test_one() {
64 trace = [];
65 var constructor = findConstructorForWebComponentType(B, 'one');
66 Expect.isNotNull(constructor);
67 Expect.isNull(findConstructorForWebComponentType(B, 'Missing'));
68
69 var b = makeB();
70 Expect.isTrue(b is B);
71 // Call constructor to initialize native object.
72 var b2 = JS('', '#(#)', constructor, b);
73 Expect.identical(b, b2);
74 Expect.isTrue(b is B);
75
76 Expect.equals(101, b.a1);
77 Expect.equals(102, b.a2);
78 Expect.equals(null, b.a3);
79 Expect.equals(104, b.a4);
80 Expect.equals(null, b.b1);
81 Expect.equals(202, b.b2);
82 Expect.equals(null, b.b3);
83
84 Expect.equals('[202, 101, 104]', '$trace');
85 }
86
87 test_two() {
88 trace = [];
89 var constructor = findConstructorForWebComponentType(B, 'two');
90 Expect.isNotNull(constructor);
91
92 var b = makeB();
93 Expect.isTrue(b is B);
94 // Call constructor to initialize native object.
95 JS('', '#(#)', constructor, b);
96 Expect.isTrue(b is B);
97
98 Expect.equals(101, b.a1);
99 Expect.equals(102, b.a2);
100 Expect.equals(103, b.a3);
101 Expect.equals(124, b.a4);
102 Expect.equals(201, b.b1);
103 Expect.equals(202, b.b2);
104 Expect.equals(203, b.b3);
105
106 Expect.equals(
107 '[202, 201, 101, 104, 103, 203, body(A.two), 124, body(B.two)]',
108 '$trace');
109 }
110
111 main() {
112 setup();
113
114 log = (message) {
115 trace.add('$message');
116 return message;
117 };
118
119 setNativeSubclassDispatchRecord(getBPrototype(), findInterceptorForType(B));
120
121 test_one();
122 test_two();
123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698