| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 js_tests; | 5 library js_tests; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 | 8 |
| 9 import 'package:js/js.dart' as js; | 9 import 'package:js/js.dart' as js; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 }); | 45 }); |
| 46 | 46 |
| 47 test('read global field with underscore', () { | 47 test('read global field with underscore', () { |
| 48 js.scoped(() { | 48 js.scoped(() { |
| 49 expect(js.context._x, equals(123)); | 49 expect(js.context._x, equals(123)); |
| 50 expect(js.context['_x'], equals(123)); | 50 expect(js.context['_x'], equals(123)); |
| 51 expect(() => js.context._y, throwsA(isNoSuchMethodError)); | 51 expect(() => js.context._y, throwsA(isNoSuchMethodError)); |
| 52 }); | 52 }); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 test('js instantiation : new Foo()', () { |
| 56 js.scoped(() { |
| 57 final Foo2 = js.context.container.Foo; |
| 58 final foo = new js.Proxy(Foo2, 42); |
| 59 expect(foo.a, 42); |
| 60 expect(Foo2.b, 38); |
| 61 }); |
| 62 }); |
| 63 |
| 55 test('js instantiation : new Array()', () { | 64 test('js instantiation : new Array()', () { |
| 56 js.scoped(() { | 65 js.scoped(() { |
| 57 final a = new js.Proxy(js.context.Array); | 66 final a = new js.Proxy(js.context.Array); |
| 58 expect(a, isNotNull); | 67 expect(a, isNotNull); |
| 59 expect(a.length, equals(0)); | 68 expect(a.length, equals(0)); |
| 60 | 69 |
| 61 a.push("value 1"); | 70 a.push("value 1"); |
| 62 expect(a.length, equals(1)); | 71 expect(a.length, equals(1)); |
| 63 expect(a[0], equals("value 1")); | 72 expect(a[0], equals("value 1")); |
| 64 | 73 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 130 |
| 122 test(r'js instantiation : new RegExp("^\w+$")', () { | 131 test(r'js instantiation : new RegExp("^\w+$")', () { |
| 123 js.scoped(() { | 132 js.scoped(() { |
| 124 final a = new js.Proxy(js.context.RegExp, r'^\w+$'); | 133 final a = new js.Proxy(js.context.RegExp, r'^\w+$'); |
| 125 expect(a, isNotNull); | 134 expect(a, isNotNull); |
| 126 expect(a.test('true'), isTrue); | 135 expect(a.test('true'), isTrue); |
| 127 expect(a.test(' false'), isFalse); | 136 expect(a.test(' false'), isFalse); |
| 128 }); | 137 }); |
| 129 }); | 138 }); |
| 130 | 139 |
| 140 test('js instantiation via map notation : new Array()', () { |
| 141 js.scoped(() { |
| 142 final a = new js.Proxy(js.context['Array']); |
| 143 expect(a, isNotNull); |
| 144 expect(a['length'], equals(0)); |
| 145 |
| 146 a['push']("value 1"); |
| 147 expect(a['length'], equals(1)); |
| 148 expect(a[0], equals("value 1")); |
| 149 |
| 150 a['pop'](); |
| 151 expect(a['length'], equals(0)); |
| 152 }); |
| 153 }); |
| 154 |
| 155 test('js instantiation via map notation : new Date()', () { |
| 156 js.scoped(() { |
| 157 final a = new js.Proxy(js.context['Date']); |
| 158 expect(a['getTime'](), isNotNull); |
| 159 }); |
| 160 }); |
| 161 |
| 131 test('js instantiation : typed array', () { | 162 test('js instantiation : typed array', () { |
| 132 js.scoped(() { | 163 js.scoped(() { |
| 133 final codeUnits = "test".codeUnits; | 164 final codeUnits = "test".codeUnits; |
| 134 final buf = new js.Proxy(js.context.ArrayBuffer, codeUnits.length); | 165 final buf = new js.Proxy(js.context.ArrayBuffer, codeUnits.length); |
| 135 final bufView = new js.Proxy(js.context.Uint8Array, buf); | 166 final bufView = new js.Proxy(js.context.Uint8Array, buf); |
| 136 for (var i = 0; i < codeUnits.length; i++) { | 167 for (var i = 0; i < codeUnits.length; i++) { |
| 137 bufView[i] = codeUnits[i]; | 168 bufView[i] = codeUnits[i]; |
| 138 } | 169 } |
| 139 }); | 170 }); |
| 140 }); | 171 }); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 154 }); | 185 }); |
| 155 }); | 186 }); |
| 156 | 187 |
| 157 test('call JS function', () { | 188 test('call JS function', () { |
| 158 js.scoped(() { | 189 js.scoped(() { |
| 159 expect(js.context.razzle(), equals(42)); | 190 expect(js.context.razzle(), equals(42)); |
| 160 expect(() => js.context.dazzle(), throwsA(isNoSuchMethodError)); | 191 expect(() => js.context.dazzle(), throwsA(isNoSuchMethodError)); |
| 161 }); | 192 }); |
| 162 }); | 193 }); |
| 163 | 194 |
| 195 test('call JS function via map notation', () { |
| 196 js.scoped(() { |
| 197 expect(js.context['razzle'](), equals(42)); |
| 198 expect(() => js.context['dazzle'](), throwsA(isNoSuchMethodError)); |
| 199 }); |
| 200 }); |
| 201 |
| 202 test('call JS function with varargs', () { |
| 203 js.scoped(() { |
| 204 expect(js.context.varArgs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
| 205 equals(55)); |
| 206 }); |
| 207 }); |
| 208 |
| 164 test('allocate JS object', () { | 209 test('allocate JS object', () { |
| 165 js.scoped(() { | 210 js.scoped(() { |
| 166 var foo = new js.Proxy(js.context.Foo, 42); | 211 var foo = new js.Proxy(js.context.Foo, 42); |
| 167 expect(foo.a, equals(42)); | 212 expect(foo.a, equals(42)); |
| 168 expect(foo.bar(), equals(42)); | 213 expect(foo.bar(), equals(42)); |
| 169 expect(() => foo.baz(), throwsA(isNoSuchMethodError)); | 214 expect(() => foo.baz(), throwsA(isNoSuchMethodError)); |
| 170 }); | 215 }); |
| 171 }); | 216 }); |
| 172 | 217 |
| 173 test('allocate simple JS array', () { | 218 test('allocate simple JS array', () { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 }); | 504 }); |
| 460 | 505 |
| 461 test('usage of Serializable', () { | 506 test('usage of Serializable', () { |
| 462 js.scoped(() { | 507 js.scoped(() { |
| 463 final red = Color.RED; | 508 final red = Color.RED; |
| 464 js.context.color = red; | 509 js.context.color = red; |
| 465 expect(js.context.color, equals(red._value)); | 510 expect(js.context.color, equals(red._value)); |
| 466 }); | 511 }); |
| 467 }); | 512 }); |
| 468 } | 513 } |
| OLD | NEW |