| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library vm_references_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:mirrors'; |
| 9 import 'package:observatory/service_io.dart'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 import 'test_helper.dart'; |
| 12 |
| 13 class Foo { } |
| 14 class Bar { } |
| 15 |
| 16 var expando; |
| 17 var key; |
| 18 var value; |
| 19 var weak_property; |
| 20 |
| 21 void script() { |
| 22 expando = new Expando('some debug name'); |
| 23 key = new Foo(); |
| 24 value = new Bar(); |
| 25 expando[key] = value; |
| 26 |
| 27 InstanceMirror expandoMirror = reflect(expando); |
| 28 LibraryMirror libcore = expandoMirror.type.owner; |
| 29 |
| 30 var entries = expandoMirror.getField(MirrorSystem.getSymbol('_data', libcore))
.reflectee; |
| 31 weak_property = entries.singleWhere((e) => e != null); |
| 32 print(weak_property); |
| 33 } |
| 34 |
| 35 var tests = [ |
| 36 |
| 37 (Isolate isolate) => |
| 38 isolate.rootLib.load().then((Library lib) { |
| 39 ServiceMap keyField = lib.variables.singleWhere((v) => v.name == 'key'); |
| 40 Instance key = keyField['value']; |
| 41 ServiceMap valueField = lib.variables.singleWhere((v) => v.name == 'value'); |
| 42 Instance value = valueField['value']; |
| 43 ServiceMap propField = lib.variables.singleWhere((v) => v.name == 'weak_prop
erty'); |
| 44 Instance prop = propField['value']; |
| 45 |
| 46 expect(key.isWeakProperty, isFalse); |
| 47 expect(value.isWeakProperty, isFalse); |
| 48 expect(prop.isWeakProperty, isTrue); |
| 49 expect(prop.key, isNull); |
| 50 expect(prop.value, isNull); |
| 51 return prop.load().then((Instance loadedProp) { |
| 52 // Object ids are not cannonicalized, so we rely on the key and value |
| 53 // being the sole instances of their classes to test we got the objects |
| 54 // we expect. |
| 55 expect(loadedProp.key, isNotNull); |
| 56 expect(loadedProp.key.clazz, equals(key.clazz)); |
| 57 expect(loadedProp.value, isNotNull); |
| 58 expect(loadedProp.value.clazz, equals(value.clazz)); |
| 59 }); |
| 60 }), |
| 61 |
| 62 ]; |
| 63 |
| 64 main(args) => runIsolateTests(args, tests, testeeBefore: script); |
| OLD | NEW |