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

Side by Side Diff: tests/html/js_test.dart

Issue 26092003: Maintain referential integrity of proxy instances in dart:js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add proxy stability for Dart->JS 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
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 library jsTest; 5 library jsTest;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:js'; 9 import 'dart:js';
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 this.f3 = p3; 117 this.f3 = p3;
118 this.f4 = p4; 118 this.f4 = p4;
119 this.f5 = p5; 119 this.f5 = p5;
120 this.f6 = p6; 120 this.f6 = p6;
121 this.f7 = p7; 121 this.f7 = p7;
122 this.f8 = p8; 122 this.f8 = p8;
123 this.f9 = p9; 123 this.f9 = p9;
124 this.f10 = p10; 124 this.f10 = p10;
125 this.f11 = p11; 125 this.f11 = p11;
126 } 126 }
127
128 function identical(o1, o2) {
129 return o1 === o2;
130 }
127 """; 131 """;
128 document.body.append(script); 132 document.body.append(script);
129 } 133 }
130 134
131 class Foo implements Serializable<JsObject> { 135 class Foo implements Serializable<JsObject> {
132 final JsObject _proxy; 136 final JsObject _proxy;
133 137
134 Foo(num a) : this._proxy = new JsObject(context['Foo'], [a]); 138 Foo(num a) : this._proxy = new JsObject(context['Foo'], [a]);
135 139
136 JsObject toJs() => _proxy; 140 JsObject toJs() => _proxy;
137 141
138 num get a => _proxy['a']; 142 num get a => _proxy['a'];
139 num bar() => _proxy.callMethod('bar'); 143 num bar() => _proxy.callMethod('bar');
140 } 144 }
141 145
142 class Color implements Serializable<String> { 146 class Color implements Serializable<String> {
143 static final RED = new Color._("red"); 147 static final RED = new Color._("red");
144 static final BLUE = new Color._("blue"); 148 static final BLUE = new Color._("blue");
145 String _value; 149 String _value;
146 Color._(this._value); 150 Color._(this._value);
147 String toJs() => this._value; 151 String toJs() => this._value;
148 } 152 }
149 153
154 class TestDartObject {}
155
150 main() { 156 main() {
151 _injectJs(); 157 _injectJs();
152 useHtmlConfiguration(); 158 useHtmlConfiguration();
153 159
154 test('context instances should be identical', () { 160 test('context instances should be identical', () {
155 var c1 = context; 161 var c1 = context;
156 var c2 = context; 162 var c2 = context;
157 expect(identical(c1, c2), isTrue); 163 expect(identical(c1, c2), isTrue);
158 }); 164 });
159 165
166 test('identical JS objects should have identical proxies', () {
167 var o1 = context['location'];
168 var o2 = context['location'];
169 expect(identical(o1, o2), isTrue);
170 });
171
172 test('identical JS functions should have identical proxies', () {
173 var f1 = context['Object'];
174 var f2 = context['Object'];
175 expect(identical(f1, f2), isTrue);
176 });
177
178 test('identical Dart objects should have identical proxies', () {
179 var o1 = new TestDartObject();
180 expect(context.callMethod('identical', [o1, o1]), isTrue);
181 });
182
183 test('identical Dart functions should have identical proxies', () {
184 var f1 = () => print("I'm a Function!");
185 expect(context.callMethod('identical', [f1, f1]), isTrue);
186 });
187
160 test('read global field', () { 188 test('read global field', () {
161 expect(context['x'], equals(42)); 189 expect(context['x'], equals(42));
162 expect(context['y'], isNull); 190 expect(context['y'], isNull);
163 }); 191 });
164 192
165 test('read global field with underscore', () { 193 test('read global field with underscore', () {
166 expect(context['_x'], equals(123)); 194 expect(context['_x'], equals(123));
167 expect(context['y'], isNull); 195 expect(context['y'], isNull);
168 }); 196 });
169 197
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 context['dartDate'] = date; 494 context['dartDate'] = date;
467 expect(context['dartDate'], equals(date)); 495 expect(context['dartDate'], equals(date));
468 }); 496 });
469 497
470 test('usage of Serializable', () { 498 test('usage of Serializable', () {
471 final red = Color.RED; 499 final red = Color.RED;
472 context['color'] = red; 500 context['color'] = red;
473 expect(context['color'], equals(red._value)); 501 expect(context['color'], equals(red._value));
474 }); 502 });
475 } 503 }
OLDNEW
« sdk/lib/js/dart2js/js_dart2js.dart ('K') | « sdk/lib/js/dartium/js_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698