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