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

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: 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/js/dartium/js_dartium.dart ('k') | no next file » | 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 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 group('identity', () {
155 var c1 = context; 161
156 var c2 = context; 162 test('context instances should be identical', () {
157 expect(identical(c1, c2), isTrue); 163 var c1 = context;
164 var c2 = context;
165 expect(identical(c1, c2), isTrue);
166 });
167
168 test('identical JS objects should have identical proxies', () {
169 var o1 = new JsObject(context['Foo'], [1]);
170 context['f1'] = o1;
171 var o2 = context['f1'];
172 expect(identical(o1, o2), isTrue);
173 });
174
175 test('identical JS functions should have identical proxies', () {
176 var f1 = context['Object'];
177 var f2 = context['Object'];
178 expect(identical(f1, f2), isTrue);
179 });
180
181 test('identical Dart objects should have identical proxies', () {
182 var o1 = new TestDartObject();
183 expect(context.callMethod('identical', [o1, o1]), isTrue);
184 });
185
186 test('identical Dart functions should have identical proxies', () {
187 var f1 = () => print("I'm a Function!");
188 expect(context.callMethod('identical', [f1, f1]), isTrue);
189 });
190
191 // TODO(justinfagnani): old tests duplicate checks above, remove
192 // on test next cleanup pass
193 test('test proxy equality', () {
194 var foo1 = new JsObject(context['Foo'], [1]);
195 var foo2 = new JsObject(context['Foo'], [2]);
196 context['foo1'] = foo1;
197 context['foo2'] = foo2;
198 expect(foo1, isNot(equals(context['foo2'])));
199 expect(foo2, same(context['foo2']));
200 context.deleteProperty('foo1');
201 context.deleteProperty('foo2');
202 });
203
204 test('retrieve same dart Object', () {
205 final date = new DateTime.now();
206 context['dartDate'] = date;
207 expect(context['dartDate'], same(date));
208 context.deleteProperty('dartDate');
209 });
210
158 }); 211 });
159 212
160 test('read global field', () { 213 test('read global field', () {
161 expect(context['x'], equals(42)); 214 expect(context['x'], equals(42));
162 expect(context['y'], isNull); 215 expect(context['y'], isNull);
163 }); 216 });
164 217
165 test('read global field with underscore', () { 218 test('read global field with underscore', () {
166 expect(context['_x'], equals(123)); 219 expect(context['_x'], equals(123));
167 expect(context['y'], isNull); 220 expect(context['y'], isNull);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 p8, p9, p10, p11) => '$p1$p2$p3$p4$p5$p6$p7$p8$p9$p10$p11'); 457 p8, p9, p10, p11) => '$p1$p2$p3$p4$p5$p6$p7$p8$p9$p10$p11');
405 expect(context.callMethod('invokeCallbackWith11params'), 458 expect(context.callMethod('invokeCallbackWith11params'),
406 equals('1234567891011')); 459 equals('1234567891011'));
407 }); 460 });
408 461
409 test('return a JS proxy to JavaScript', () { 462 test('return a JS proxy to JavaScript', () {
410 var result = context.callMethod('testJsMap', [() => jsify({'value': 42})]); 463 var result = context.callMethod('testJsMap', [() => jsify({'value': 42})]);
411 expect(result, 42); 464 expect(result, 42);
412 }); 465 });
413 466
414 test('test proxy equality', () {
415 var foo1 = new JsObject(context['Foo'], [1]);
416 var foo2 = new JsObject(context['Foo'], [2]);
417 context['foo'] = foo1;
418 context['foo'] = foo2;
419 expect(foo1, isNot(equals(context['foo'])));
420 expect(foo2, equals(context['foo']));
421 });
422
423 test('test instanceof', () { 467 test('test instanceof', () {
424 var foo = new JsObject(context['Foo'], [1]); 468 var foo = new JsObject(context['Foo'], [1]);
425 expect(foo.instanceof(context['Foo']), isTrue); 469 expect(foo.instanceof(context['Foo']), isTrue);
426 expect(foo.instanceof(context['Object']), isTrue); 470 expect(foo.instanceof(context['Object']), isTrue);
427 expect(foo.instanceof(context['String']), isFalse); 471 expect(foo.instanceof(context['String']), isFalse);
428 }); 472 });
429 473
430 test('test deleteProperty', () { 474 test('test deleteProperty', () {
431 var object = jsify({}); 475 var object = jsify({});
432 object['a'] = 1; 476 object['a'] = 1;
(...skipping 21 matching lines...) Expand all
454 final foo = new JsObject(context['Foo'], [1]); 498 final foo = new JsObject(context['Foo'], [1]);
455 foo["getAge"] = () => 10; 499 foo["getAge"] = () => 10;
456 expect(foo.callMethod('getAge'), equals(10)); 500 expect(foo.callMethod('getAge'), equals(10));
457 }); 501 });
458 502
459 test('access a property of a function', () { 503 test('access a property of a function', () {
460 expect(context.callMethod('Bar'), "ret_value"); 504 expect(context.callMethod('Bar'), "ret_value");
461 expect(context['Bar']['foo'], "property_value"); 505 expect(context['Bar']['foo'], "property_value");
462 }); 506 });
463 507
464 test('retrieve same dart Object', () {
465 final date = new DateTime.now();
466 context['dartDate'] = date;
467 expect(context['dartDate'], equals(date));
468 });
469
470 test('usage of Serializable', () { 508 test('usage of Serializable', () {
471 final red = Color.RED; 509 final red = Color.RED;
472 context['color'] = red; 510 context['color'] = red;
473 expect(context['color'], equals(red._value)); 511 expect(context['color'], equals(red._value));
474 }); 512 });
475 } 513 }
OLDNEW
« no previous file with comments | « 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