| 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 // Dart test program for checking implemention of MirrorSystem when | 5 // Dart test program for checking implemention of MirrorSystem when |
| 6 // inspecting the current isolate. | 6 // inspecting the current isolate. |
| 7 | 7 |
| 8 #library('isolate_mirror_local_test'); | 8 #library('isolate_mirror_local_test'); |
| 9 | 9 |
| 10 #import('dart:isolate'); | 10 #import('dart:isolate'); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 Expect.equals('isolate_mirror_local_test', lib_mirror.simpleName); | 93 Expect.equals('isolate_mirror_local_test', lib_mirror.simpleName); |
| 94 Expect.isTrue(lib_mirror.url.contains('isolate_mirror_local_test.dart')); | 94 Expect.isTrue(lib_mirror.url.contains('isolate_mirror_local_test.dart')); |
| 95 Expect.equals("LibraryMirror on 'isolate_mirror_local_test'", | 95 Expect.equals("LibraryMirror on 'isolate_mirror_local_test'", |
| 96 lib_mirror.toString()); | 96 lib_mirror.toString()); |
| 97 | 97 |
| 98 // Test library invocation by calling function(123). | 98 // Test library invocation by calling function(123). |
| 99 Expect.equals(0, global_var); | 99 Expect.equals(0, global_var); |
| 100 lib_mirror.invoke('function', [ 123 ]).then( | 100 lib_mirror.invoke('function', [ 123 ]).then( |
| 101 (InstanceMirror retval) { | 101 (InstanceMirror retval) { |
| 102 Expect.equals(123, global_var); | 102 Expect.equals(123, global_var); |
| 103 Expect.equals('int', retval.getClass().simpleName); | 103 Expect.equals('int', retval.type.simpleName); |
| 104 Expect.isTrue(retval.hasReflectee); | 104 Expect.isTrue(retval.hasReflectee); |
| 105 Expect.equals(124, retval.reflectee); | 105 Expect.equals(124, retval.reflectee); |
| 106 testDone('testRootLibraryMirror'); | 106 testDone('testRootLibraryMirror'); |
| 107 }); | 107 }); |
| 108 | 108 |
| 109 // Check that the members map is complete. | 109 // Check that the members map is complete. |
| 110 List keys = lib_mirror.members().getKeys(); | 110 List keys = lib_mirror.members.getKeys(); |
| 111 sort(keys); | 111 sort(keys); |
| 112 Expect.equals('[' | 112 Expect.equals('[' |
| 113 'MyClass, ' | 113 'MyClass, ' |
| 114 'MyException, ' | 114 'MyException, ' |
| 115 'MyInterface, ' | 115 'MyInterface, ' |
| 116 'MySuperClass, ' | 116 'MySuperClass, ' |
| 117 '_stringCompare, ' | 117 '_stringCompare, ' |
| 118 'buildMethodString, ' | 118 'buildMethodString, ' |
| 119 'buildVariableString, ' | 119 'buildVariableString, ' |
| 120 'exit_port, ' | 120 'exit_port, ' |
| (...skipping 13 matching lines...) Expand all Loading... |
| 134 'testIntegerInstanceMirror, ' | 134 'testIntegerInstanceMirror, ' |
| 135 'testLibrariesMap, ' | 135 'testLibrariesMap, ' |
| 136 'testMirrorErrors, ' | 136 'testMirrorErrors, ' |
| 137 'testMirrorSystem, ' | 137 'testMirrorSystem, ' |
| 138 'testNullInstanceMirror, ' | 138 'testNullInstanceMirror, ' |
| 139 'testRootLibraryMirror, ' | 139 'testRootLibraryMirror, ' |
| 140 'testStringInstanceMirror]', | 140 'testStringInstanceMirror]', |
| 141 '$keys'); | 141 '$keys'); |
| 142 | 142 |
| 143 // Check that the classes map is complete. | 143 // Check that the classes map is complete. |
| 144 keys = lib_mirror.classes().getKeys(); | 144 keys = lib_mirror.classes.getKeys(); |
| 145 sort(keys); | 145 sort(keys); |
| 146 Expect.equals('[' | 146 Expect.equals('[' |
| 147 'MyClass, ' | 147 'MyClass, ' |
| 148 'MyException, ' | 148 'MyException, ' |
| 149 'MyInterface, ' | 149 'MyInterface, ' |
| 150 'MySuperClass]', | 150 'MySuperClass]', |
| 151 '$keys'); | 151 '$keys'); |
| 152 | 152 |
| 153 // Check that the functions map is complete. | 153 // Check that the functions map is complete. |
| 154 keys = lib_mirror.functions().getKeys(); | 154 keys = lib_mirror.functions.getKeys(); |
| 155 sort(keys); | 155 sort(keys); |
| 156 Expect.equals('[' | 156 Expect.equals('[' |
| 157 '_stringCompare, ' | 157 '_stringCompare, ' |
| 158 'buildMethodString, ' | 158 'buildMethodString, ' |
| 159 'buildVariableString, ' | 159 'buildVariableString, ' |
| 160 'function, ' | 160 'function, ' |
| 161 'main, ' | 161 'main, ' |
| 162 'methodWithError, ' | 162 'methodWithError, ' |
| 163 'methodWithException, ' | 163 'methodWithException, ' |
| 164 'myVar, ' | 164 'myVar, ' |
| 165 'myVar=, ' | 165 'myVar=, ' |
| 166 'sort, ' | 166 'sort, ' |
| 167 'testBoolInstanceMirror, ' | 167 'testBoolInstanceMirror, ' |
| 168 'testCustomInstanceMirror, ' | 168 'testCustomInstanceMirror, ' |
| 169 'testDone, ' | 169 'testDone, ' |
| 170 'testIntegerInstanceMirror, ' | 170 'testIntegerInstanceMirror, ' |
| 171 'testLibrariesMap, ' | 171 'testLibrariesMap, ' |
| 172 'testMirrorErrors, ' | 172 'testMirrorErrors, ' |
| 173 'testMirrorSystem, ' | 173 'testMirrorSystem, ' |
| 174 'testNullInstanceMirror, ' | 174 'testNullInstanceMirror, ' |
| 175 'testRootLibraryMirror, ' | 175 'testRootLibraryMirror, ' |
| 176 'testStringInstanceMirror]', | 176 'testStringInstanceMirror]', |
| 177 '$keys'); | 177 '$keys'); |
| 178 | 178 |
| 179 // Check that the variables map is complete. | 179 // Check that the variables map is complete. |
| 180 keys = lib_mirror.variables().getKeys(); | 180 keys = lib_mirror.variables.getKeys(); |
| 181 sort(keys); | 181 sort(keys); |
| 182 Expect.equals('[' | 182 Expect.equals('[' |
| 183 'exit_port, ' | 183 'exit_port, ' |
| 184 'expectedTests, ' | 184 'expectedTests, ' |
| 185 'final_global_var, ' | 185 'final_global_var, ' |
| 186 'global_var]', | 186 'global_var]', |
| 187 '$keys'); | 187 '$keys'); |
| 188 | 188 |
| 189 InterfaceMirror cls_mirror = lib_mirror.members()['MyClass']; | 189 ClassMirror cls_mirror = lib_mirror.members['MyClass']; |
| 190 | 190 |
| 191 // Test function mirrors. | 191 // Test function mirrors. |
| 192 MethodMirror func = lib_mirror.members()['function']; | 192 MethodMirror func = lib_mirror.members['function']; |
| 193 Expect.isTrue(func is MethodMirror); | 193 Expect.isTrue(func is MethodMirror); |
| 194 Expect.equals('function toplevel static method', buildMethodString(func)); | 194 Expect.equals('function toplevel static method', buildMethodString(func)); |
| 195 | 195 |
| 196 func = lib_mirror.members()['myVar']; | 196 func = lib_mirror.members['myVar']; |
| 197 Expect.isTrue(func is MethodMirror); | 197 Expect.isTrue(func is MethodMirror); |
| 198 Expect.equals('myVar toplevel static getter', buildMethodString(func)); | 198 Expect.equals('myVar toplevel static getter', buildMethodString(func)); |
| 199 | 199 |
| 200 func = lib_mirror.members()['myVar=']; | 200 func = lib_mirror.members['myVar=']; |
| 201 Expect.isTrue(func is MethodMirror); | 201 Expect.isTrue(func is MethodMirror); |
| 202 Expect.equals('myVar= toplevel static setter', buildMethodString(func)); | 202 Expect.equals('myVar= toplevel static setter', buildMethodString(func)); |
| 203 | 203 |
| 204 func = cls_mirror.members()['method']; | 204 func = cls_mirror.members['method']; |
| 205 Expect.isTrue(func is MethodMirror); | 205 Expect.isTrue(func is MethodMirror); |
| 206 Expect.equals('method method', buildMethodString(func)); | 206 Expect.equals('method method', buildMethodString(func)); |
| 207 | 207 |
| 208 func = cls_mirror.members()['MyClass']; | 208 func = cls_mirror.members['MyClass']; |
| 209 Expect.isTrue(func is MethodMirror); | 209 Expect.isTrue(func is MethodMirror); |
| 210 Expect.equals('MyClass constructor', buildMethodString(func)); | 210 Expect.equals('MyClass constructor', buildMethodString(func)); |
| 211 | 211 |
| 212 // Test variable mirrors. | 212 // Test variable mirrors. |
| 213 VariableMirror variable = lib_mirror.members()['global_var']; | 213 VariableMirror variable = lib_mirror.members['global_var']; |
| 214 Expect.isTrue(variable is VariableMirror); | 214 Expect.isTrue(variable is VariableMirror); |
| 215 Expect.equals('global_var toplevel static', buildVariableString(variable)); | 215 Expect.equals('global_var toplevel static', buildVariableString(variable)); |
| 216 | 216 |
| 217 variable = lib_mirror.members()['final_global_var']; | 217 variable = lib_mirror.members['final_global_var']; |
| 218 Expect.isTrue(variable is VariableMirror); | 218 Expect.isTrue(variable is VariableMirror); |
| 219 Expect.equals('final_global_var toplevel static final', | 219 Expect.equals('final_global_var toplevel static final', |
| 220 buildVariableString(variable)); | 220 buildVariableString(variable)); |
| 221 | 221 |
| 222 variable = cls_mirror.members()['value']; | 222 variable = cls_mirror.members['value']; |
| 223 Expect.isTrue(variable is VariableMirror); | 223 Expect.isTrue(variable is VariableMirror); |
| 224 Expect.equals('value final', buildVariableString(variable)); | 224 Expect.equals('value final', buildVariableString(variable)); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void testLibrariesMap(Map libraries) { | 227 void testLibrariesMap(Map libraries) { |
| 228 // Just look for a couple of well-known libs. | 228 // Just look for a couple of well-known libs. |
| 229 LibraryMirror core_lib = libraries['dart:core']; | 229 LibraryMirror core_lib = libraries['dart:core']; |
| 230 Expect.isTrue(core_lib is LibraryMirror); | 230 Expect.isTrue(core_lib is LibraryMirror); |
| 231 | 231 |
| 232 LibraryMirror mirror_lib = libraries['dart:mirrors']; | 232 LibraryMirror mirror_lib = libraries['dart:mirrors']; |
| 233 Expect.isTrue(mirror_lib is LibraryMirror); | 233 Expect.isTrue(mirror_lib is LibraryMirror); |
| 234 | 234 |
| 235 // Lookup an interface from a library and make sure it is sane. | 235 // Lookup an interface from a library and make sure it is sane. |
| 236 InterfaceMirror list_intf = core_lib.members()['List']; | 236 ClassMirror list_intf = core_lib.members['List']; |
| 237 Expect.isTrue(list_intf is InterfaceMirror); | 237 Expect.isTrue(list_intf is ClassMirror); |
| 238 Expect.equals('List', list_intf.simpleName); | 238 Expect.equals('List', list_intf.simpleName); |
| 239 Expect.equals('Object', list_intf.superclass().simpleName); | 239 Expect.equals('Object', list_intf.superclass.simpleName); |
| 240 Expect.equals('ListFactory', list_intf.defaultFactory().simpleName); | 240 Expect.equals('ListFactory', list_intf.defaultFactory.simpleName); |
| 241 Expect.equals('dart:core', list_intf.library.simpleName); | 241 Expect.equals('dart:core', list_intf.library.simpleName); |
| 242 Expect.isFalse(list_intf.isClass); | 242 Expect.isFalse(list_intf.isClass); |
| 243 Expect.equals('Collection', list_intf.superinterfaces()[0].simpleName); | 243 Expect.equals('Collection', list_intf.superinterfaces[0].simpleName); |
| 244 Expect.equals("InterfaceMirror on 'List'", list_intf.toString()); | 244 Expect.equals("ClassMirror on 'List'", list_intf.toString()); |
| 245 | 245 |
| 246 // Lookup a class from a library and make sure it is sane. | 246 // Lookup a class from a library and make sure it is sane. |
| 247 InterfaceMirror oom_cls = core_lib.members()['OutOfMemoryException']; | 247 ClassMirror oom_cls = core_lib.members['OutOfMemoryException']; |
| 248 Expect.isTrue(oom_cls is InterfaceMirror); | 248 Expect.isTrue(oom_cls is ClassMirror); |
| 249 Expect.equals('OutOfMemoryException', oom_cls.simpleName); | 249 Expect.equals('OutOfMemoryException', oom_cls.simpleName); |
| 250 Expect.equals('Object', oom_cls.superclass().simpleName); | 250 Expect.equals('Object', oom_cls.superclass.simpleName); |
| 251 Expect.isTrue(oom_cls.defaultFactory() === null); | 251 Expect.isTrue(oom_cls.defaultFactory === null); |
| 252 Expect.equals('dart:core', oom_cls.library.simpleName); | 252 Expect.equals('dart:core', oom_cls.library.simpleName); |
| 253 Expect.isTrue(oom_cls.isClass); | 253 Expect.isTrue(oom_cls.isClass); |
| 254 Expect.equals('Exception', oom_cls.superinterfaces()[0].simpleName); | 254 Expect.equals('Exception', oom_cls.superinterfaces[0].simpleName); |
| 255 Expect.equals("InterfaceMirror on 'OutOfMemoryException'", | 255 Expect.equals("ClassMirror on 'OutOfMemoryException'", |
| 256 oom_cls.toString()); | 256 oom_cls.toString()); |
| 257 testDone('testLibrariesMap'); | 257 testDone('testLibrariesMap'); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void testMirrorSystem(MirrorSystem mirrors) { | 260 void testMirrorSystem(MirrorSystem mirrors) { |
| 261 Expect.isTrue(mirrors.isolate.debugName.contains('main')); | 261 Expect.isTrue(mirrors.isolate.debugName.contains('main')); |
| 262 testRootLibraryMirror(mirrors.rootLibrary); | 262 testRootLibraryMirror(mirrors.isolate.rootLibrary); |
| 263 testLibrariesMap(mirrors.libraries()); | 263 testLibrariesMap(mirrors.libraries); |
| 264 Expect.equals('void', mirrors.voidType.simpleName); |
| 265 Expect.equals('Dynamic', mirrors.dynamicType.simpleName); |
| 264 testDone('testMirrorSystem'); | 266 testDone('testMirrorSystem'); |
| 265 } | 267 } |
| 266 | 268 |
| 267 void testIntegerInstanceMirror(InstanceMirror mirror) { | 269 void testIntegerInstanceMirror(InstanceMirror mirror) { |
| 268 Expect.equals('int', mirror.getClass().simpleName); | 270 Expect.equals('int', mirror.type.simpleName); |
| 269 Expect.isTrue(mirror.hasReflectee); | 271 Expect.isTrue(mirror.hasReflectee); |
| 270 Expect.equals(1001, mirror.reflectee); | 272 Expect.equals(1001, mirror.reflectee); |
| 271 Expect.equals("InstanceMirror on <1001>", mirror.toString()); | 273 Expect.equals("InstanceMirror on <1001>", mirror.toString()); |
| 272 | 274 |
| 273 // Invoke (mirror + mirror). | 275 // Invoke (mirror + mirror). |
| 274 mirror.invoke('+', [ mirror ]).then( | 276 mirror.invoke('+', [ mirror ]).then( |
| 275 (InstanceMirror retval) { | 277 (InstanceMirror retval) { |
| 276 Expect.equals('int', retval.getClass().simpleName); | 278 Expect.equals('int', retval.type.simpleName); |
| 277 Expect.isTrue(retval.hasReflectee); | 279 Expect.isTrue(retval.hasReflectee); |
| 278 Expect.equals(2002, retval.reflectee); | 280 Expect.equals(2002, retval.reflectee); |
| 279 testDone('testIntegerInstanceMirror'); | 281 testDone('testIntegerInstanceMirror'); |
| 280 }); | 282 }); |
| 281 } | 283 } |
| 282 | 284 |
| 283 void testStringInstanceMirror(InstanceMirror mirror) { | 285 void testStringInstanceMirror(InstanceMirror mirror) { |
| 284 Expect.equals('String', mirror.getClass().simpleName); | 286 Expect.equals('String', mirror.type.simpleName); |
| 285 Expect.isTrue(mirror.hasReflectee); | 287 Expect.isTrue(mirror.hasReflectee); |
| 286 Expect.equals('This\nis\na\nString', mirror.reflectee); | 288 Expect.equals('This\nis\na\nString', mirror.reflectee); |
| 287 Expect.equals("InstanceMirror on <'This\\nis\\na\\nString'>", | 289 Expect.equals("InstanceMirror on <'This\\nis\\na\\nString'>", |
| 288 mirror.toString()); | 290 mirror.toString()); |
| 289 | 291 |
| 290 // Invoke mirror[0]. | 292 // Invoke mirror[0]. |
| 291 mirror.invoke('[]', [ 0 ]).then( | 293 mirror.invoke('[]', [ 0 ]).then( |
| 292 (InstanceMirror retval) { | 294 (InstanceMirror retval) { |
| 293 Expect.equals('String', retval.getClass().simpleName); | 295 Expect.equals('String', retval.type.simpleName); |
| 294 Expect.isTrue(retval.hasReflectee); | 296 Expect.isTrue(retval.hasReflectee); |
| 295 Expect.equals('T', retval.reflectee); | 297 Expect.equals('T', retval.reflectee); |
| 296 testDone('testStringInstanceMirror'); | 298 testDone('testStringInstanceMirror'); |
| 297 }); | 299 }); |
| 298 } | 300 } |
| 299 | 301 |
| 300 void testBoolInstanceMirror(InstanceMirror mirror) { | 302 void testBoolInstanceMirror(InstanceMirror mirror) { |
| 301 Expect.equals('bool', mirror.getClass().simpleName); | 303 Expect.equals('bool', mirror.type.simpleName); |
| 302 Expect.isTrue(mirror.hasReflectee); | 304 Expect.isTrue(mirror.hasReflectee); |
| 303 Expect.equals(true, mirror.reflectee); | 305 Expect.equals(true, mirror.reflectee); |
| 304 Expect.equals("InstanceMirror on <true>", mirror.toString()); | 306 Expect.equals("InstanceMirror on <true>", mirror.toString()); |
| 305 testDone('testBoolInstanceMirror'); | 307 testDone('testBoolInstanceMirror'); |
| 306 } | 308 } |
| 307 | 309 |
| 308 void testNullInstanceMirror(InstanceMirror mirror) { | 310 void testNullInstanceMirror(InstanceMirror mirror) { |
| 309 // TODO(turnidge): This is returning the wrong class. Fix it. | 311 // TODO(turnidge): This is returning the wrong class. Fix it. |
| 310 Expect.equals('Object', mirror.getClass().simpleName); | 312 Expect.equals('Object', mirror.type.simpleName); |
| 311 Expect.isTrue(mirror.hasReflectee); | 313 Expect.isTrue(mirror.hasReflectee); |
| 312 Expect.equals(null, mirror.reflectee); | 314 Expect.equals(null, mirror.reflectee); |
| 313 Expect.equals("InstanceMirror on <null>", mirror.toString()); | 315 Expect.equals("InstanceMirror on <null>", mirror.toString()); |
| 314 testDone('testNullInstanceMirror'); | 316 testDone('testNullInstanceMirror'); |
| 315 } | 317 } |
| 316 | 318 |
| 317 class MySuperClass { | 319 class MySuperClass { |
| 318 } | 320 } |
| 319 | 321 |
| 320 class MyInterface { | 322 class MyInterface { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 334 Expect.isTrue(mirror.hasReflectee); | 336 Expect.isTrue(mirror.hasReflectee); |
| 335 bool saw_exception = false; | 337 bool saw_exception = false; |
| 336 try { | 338 try { |
| 337 mirror.reflectee; | 339 mirror.reflectee; |
| 338 } catch (MirrorException me) { | 340 } catch (MirrorException me) { |
| 339 saw_exception = true; | 341 saw_exception = true; |
| 340 } | 342 } |
| 341 Expect.isFalse(saw_exception); | 343 Expect.isFalse(saw_exception); |
| 342 Expect.equals("InstanceMirror on instance of 'MyClass'", mirror.toString()); | 344 Expect.equals("InstanceMirror on instance of 'MyClass'", mirror.toString()); |
| 343 | 345 |
| 344 InterfaceMirror cls = mirror.getClass(); | 346 ClassMirror cls = mirror.type; |
| 345 Expect.isTrue(cls is InterfaceMirror); | 347 Expect.isTrue(cls is ClassMirror); |
| 346 Expect.equals('MyClass', cls.simpleName); | 348 Expect.equals('MyClass', cls.simpleName); |
| 347 Expect.equals('MySuperClass', cls.superclass().simpleName); | 349 Expect.equals('MySuperClass', cls.superclass.simpleName); |
| 348 Expect.isTrue(cls.defaultFactory() === null); | 350 Expect.isTrue(cls.defaultFactory === null); |
| 349 Expect.equals('isolate_mirror_local_test', cls.library.simpleName); | 351 Expect.equals('isolate_mirror_local_test', cls.library.simpleName); |
| 350 Expect.isTrue(cls.isClass); | 352 Expect.isTrue(cls.isClass); |
| 351 Expect.equals('MyInterface', cls.superinterfaces()[0].simpleName); | 353 Expect.equals('MyInterface', cls.superinterfaces[0].simpleName); |
| 352 Expect.equals("InterfaceMirror on 'MyClass'", | 354 Expect.equals("ClassMirror on 'MyClass'", |
| 353 cls.toString()); | 355 cls.toString()); |
| 354 | 356 |
| 355 // Invoke mirror.method(1000). | 357 // Invoke mirror.method(1000). |
| 356 mirror.invoke('method', [ 1000 ]).then( | 358 mirror.invoke('method', [ 1000 ]).then( |
| 357 (InstanceMirror retval) { | 359 (InstanceMirror retval) { |
| 358 Expect.equals('int', retval.getClass().simpleName); | 360 Expect.equals('int', retval.type.simpleName); |
| 359 Expect.isTrue(retval.hasReflectee); | 361 Expect.isTrue(retval.hasReflectee); |
| 360 Expect.equals(1017, retval.reflectee); | 362 Expect.equals(1017, retval.reflectee); |
| 361 testDone('testCustomInstanceMirror'); | 363 testDone('testCustomInstanceMirror'); |
| 362 }); | 364 }); |
| 363 | 365 |
| 364 } | 366 } |
| 365 | 367 |
| 366 class MyException implements Exception { | 368 class MyException implements Exception { |
| 367 MyException(this._message); | 369 MyException(this._message); |
| 368 final String _message; | 370 final String _message; |
| 369 String toString() { return 'MyException: $_message'; } | 371 String toString() { return 'MyException: $_message'; } |
| 370 } | 372 } |
| 371 | 373 |
| 372 void methodWithException() { | 374 void methodWithException() { |
| 373 throw new MyException("from methodWithException"); | 375 throw new MyException("from methodWithException"); |
| 374 } | 376 } |
| 375 | 377 |
| 376 void methodWithError() { | 378 void methodWithError() { |
| 377 // We get a parse error when we try to run this function. | 379 // We get a parse error when we try to run this function. |
| 378 +++; | 380 +++; |
| 379 } | 381 } |
| 380 | 382 |
| 381 void testMirrorErrors(MirrorSystem mirrors) { | 383 void testMirrorErrors(MirrorSystem mirrors) { |
| 382 LibraryMirror lib_mirror = mirrors.rootLibrary; | 384 LibraryMirror lib_mirror = mirrors.isolate.rootLibrary; |
| 383 | 385 |
| 384 Future<InstanceMirror> future = | 386 Future<InstanceMirror> future = |
| 385 lib_mirror.invoke('methodWithException', []); | 387 lib_mirror.invoke('methodWithException', []); |
| 386 future.handleException( | 388 future.handleException( |
| 387 (MirroredError exc) { | 389 (MirroredError exc) { |
| 388 Expect.isTrue(exc is MirroredUncaughtExceptionError); | 390 Expect.isTrue(exc is MirroredUncaughtExceptionError); |
| 389 Expect.equals('MyException', | 391 Expect.equals('MyException', |
| 390 exc.exception_mirror.getClass().simpleName); | 392 exc.exception_mirror.type.simpleName); |
| 391 Expect.equals('MyException: from methodWithException', | 393 Expect.equals('MyException: from methodWithException', |
| 392 exc.exception_string); | 394 exc.exception_string); |
| 393 Expect.isTrue(exc.stacktrace.toString().contains( | 395 Expect.isTrue(exc.stacktrace.toString().contains( |
| 394 'isolate_mirror_local_test.dart')); | 396 'isolate_mirror_local_test.dart')); |
| 395 testDone('testMirrorErrors1'); | 397 testDone('testMirrorErrors1'); |
| 396 return true; | 398 return true; |
| 397 }); | 399 }); |
| 398 future.then( | 400 future.then( |
| 399 (InstanceMirror retval) { | 401 (InstanceMirror retval) { |
| 400 // Should not reach here. | 402 // Should not reach here. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 'testBoolInstanceMirror', | 450 'testBoolInstanceMirror', |
| 449 'testNullInstanceMirror', | 451 'testNullInstanceMirror', |
| 450 'testCustomInstanceMirror', | 452 'testCustomInstanceMirror', |
| 451 'testMirrorErrors1', | 453 'testMirrorErrors1', |
| 452 'testMirrorErrors2', | 454 'testMirrorErrors2', |
| 453 'testMirrorErrors3']); | 455 'testMirrorErrors3']); |
| 454 | 456 |
| 455 // Test that an isolate can reflect on itself. | 457 // Test that an isolate can reflect on itself. |
| 456 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); | 458 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); |
| 457 | 459 |
| 458 MirrorSystem mirrors = currentMirrorSystem(); | 460 testIntegerInstanceMirror(reflect(1001)); |
| 459 testIntegerInstanceMirror(mirrors.mirrorOf(1001)); | 461 testStringInstanceMirror(reflect('This\nis\na\nString')); |
| 460 testStringInstanceMirror(mirrors.mirrorOf('This\nis\na\nString')); | 462 testBoolInstanceMirror(reflect(true)); |
| 461 testBoolInstanceMirror(mirrors.mirrorOf(true)); | 463 testNullInstanceMirror(reflect(null)); |
| 462 testNullInstanceMirror(mirrors.mirrorOf(null)); | 464 testCustomInstanceMirror(reflect(new MyClass(17))); |
| 463 testCustomInstanceMirror(mirrors.mirrorOf(new MyClass(17))); | |
| 464 testMirrorErrors(currentMirrorSystem()); | 465 testMirrorErrors(currentMirrorSystem()); |
| 465 } | 466 } |
| OLD | NEW |