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

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

Issue 28173002: Code review changes for ngeoffray's comments on r28278 (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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tools/dom/src/dart2js_CustomElementSupport.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:_foreign_helper' show JS; 6 import 'dart:_foreign_helper' show JS;
7 import 'dart:_js_helper' show Creates, setNativeSubclassDispatchRecord; 7 import 'dart:_js_helper' show Creates, setNativeSubclassDispatchRecord;
8 import 'dart:_interceptors' show 8 import 'dart:_interceptors' show
9 findInterceptorForType, findConstructorForWebComponentType; 9 findInterceptorForType, findConstructorForNativeSubclassType;
10 10
11 // Test that subclasses of native classes can be initialized by calling the 11 // Test that subclasses of native classes can be initialized by calling the
12 // 'upgrade' constructor. 12 // 'upgrade' constructor.
13 13
14 var trace = []; 14 var trace = [];
15 15
16 var log; 16 var log;
17 17
18 class A native "A" { 18 class A native "A" {
19 final a1 = log(101); // Only initialized IF named constructor called. 19 final a1 = log(101); // Only initialized IF named constructor called.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 function B() { this.a2 = 102; } 62 function B() { this.a2 = 102; }
63 63
64 makeB = function(){return new B;}; 64 makeB = function(){return new B;};
65 65
66 getBPrototype = function(){return B.prototype;}; 66 getBPrototype = function(){return B.prototype;};
67 """; 67 """;
68 68
69 69
70 test_one() { 70 test_one() {
71 trace = []; 71 trace = [];
72 var constructor = findConstructorForWebComponentType(B, 'one'); 72 var constructor = findConstructorForNativeSubclassType(B, 'one');
73 Expect.isNotNull(constructor); 73 Expect.isNotNull(constructor);
74 Expect.isNull(findConstructorForWebComponentType(B, 'Missing')); 74 Expect.isNull(findConstructorForNativeSubclassType(B, 'Missing'));
75 75
76 var b = makeB(); 76 var b = makeB();
77 Expect.isTrue(b is B); 77 Expect.isTrue(b is B);
78 // Call constructor to initialize native object. 78 // Call constructor to initialize native object.
79 var b2 = JS('', '#(#)', constructor, b); 79 var b2 = JS('', '#(#)', constructor, b);
80 Expect.identical(b, b2); 80 Expect.identical(b, b2);
81 Expect.isTrue(b is B); 81 Expect.isTrue(b is B);
82 82
83 Expect.equals(101, b.a1); 83 Expect.equals(101, b.a1);
84 Expect.equals(102, b.a2); 84 Expect.equals(102, b.a2);
85 Expect.equals(null, b.a3); 85 Expect.equals(null, b.a3);
86 Expect.equals(104, b.a4); 86 Expect.equals(104, b.a4);
87 Expect.equals(null, b.b1); 87 Expect.equals(null, b.b1);
88 Expect.equals(202, b.b2); 88 Expect.equals(202, b.b2);
89 Expect.equals(null, b.b3); 89 Expect.equals(null, b.b3);
90 90
91 Expect.equals('[202, 101, 104]', '$trace'); 91 Expect.equals('[202, 101, 104]', '$trace');
92 } 92 }
93 93
94 test_two() { 94 test_two() {
95 trace = []; 95 trace = [];
96 var constructor = findConstructorForWebComponentType(B, 'two'); 96 var constructor = findConstructorForNativeSubclassType(B, 'two');
97 Expect.isNotNull(constructor); 97 Expect.isNotNull(constructor);
98 98
99 var b = makeB(); 99 var b = makeB();
100 Expect.isTrue(b is B); 100 Expect.isTrue(b is B);
101 // Call constructor to initialize native object. 101 // Call constructor to initialize native object.
102 JS('', '#(#)', constructor, b); 102 JS('', '#(#)', constructor, b);
103 Expect.isTrue(b is B); 103 Expect.isTrue(b is B);
104 104
105 Expect.equals(101, b.a1); 105 Expect.equals(101, b.a1);
106 Expect.equals(102, b.a2); 106 Expect.equals(102, b.a2);
107 Expect.equals(103, b.a3); 107 Expect.equals(103, b.a3);
108 Expect.equals(124, b.a4); 108 Expect.equals(124, b.a4);
109 Expect.equals(201, b.b1); 109 Expect.equals(201, b.b1);
110 Expect.equals(202, b.b2); 110 Expect.equals(202, b.b2);
111 Expect.equals(203, b.b3); 111 Expect.equals(203, b.b3);
112 112
113 Expect.equals( 113 Expect.equals(
114 '[202, 201, 101, 104, 103, 203, body(A.two), 124, body(B.two)]', 114 '[202, 201, 101, 104, 103, 203, body(A.two), 124, body(B.two)]',
115 '$trace'); 115 '$trace');
116 } 116 }
117 117
118 test_three() { 118 test_three() {
119 trace = []; 119 trace = [];
120 var constructor = findConstructorForWebComponentType(B, 'three'); 120 var constructor = findConstructorForNativeSubclassType(B, 'three');
121 Expect.isNotNull(constructor); 121 Expect.isNotNull(constructor);
122 122
123 var b = makeB(); 123 var b = makeB();
124 Expect.isTrue(b is B); 124 Expect.isTrue(b is B);
125 // Call constructor to initialize native object. 125 // Call constructor to initialize native object.
126 // 126 //
127 // Since the constructor takes some optional arguments that are not passed, it 127 // Since the constructor takes some optional arguments that are not passed, it
128 // is as though the web components runtime explicitly passed `null` for all 128 // is as though the web components runtime explicitly passed `null` for all
129 // parameters. 129 // parameters.
130 // 130 //
131 // TODO(sra): The constructor returned by findConstructorForWebComponentType 131 // TODO(sra): The constructor returned by findConstructorForNativeSubclassType
132 // should be a function that fills in the default values. 132 // should be a function that fills in the default values.
133 JS('', '#(#)', constructor, b); 133 JS('', '#(#)', constructor, b);
134 Expect.isTrue(b is B); 134 Expect.isTrue(b is B);
135 135
136 Expect.equals(101, b.a1); 136 Expect.equals(101, b.a1);
137 Expect.equals(102, b.a2); 137 Expect.equals(102, b.a2);
138 Expect.equals(null, b.a3); 138 Expect.equals(null, b.a3);
139 Expect.equals('(null, 205)', b.a4); 139 Expect.equals('(null, 205)', b.a4);
140 Expect.equals(null, b.b1); 140 Expect.equals(null, b.b1);
141 Expect.equals(202, b.b2); 141 Expect.equals(202, b.b2);
(...skipping 25 matching lines...) Expand all
167 return message; 167 return message;
168 }; 168 };
169 169
170 setNativeSubclassDispatchRecord(getBPrototype(), findInterceptorForType(B)); 170 setNativeSubclassDispatchRecord(getBPrototype(), findInterceptorForType(B));
171 171
172 test_one(); 172 test_one();
173 test_two(); 173 test_two();
174 test_three(); 174 test_three();
175 test_new(); 175 test_new();
176 } 176 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tools/dom/src/dart2js_CustomElementSupport.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698