| 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 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked | |
| 5 | |
| 6 library inbound_references_test; | |
| 7 | |
| 8 import 'package:observatory/service_io.dart'; | |
| 9 import 'package:unittest/unittest.dart'; | |
| 10 import 'test_helper.dart'; | |
| 11 | |
| 12 var cleanBlock, copyingBlock, fullBlock, fullBlockWithChain; | |
| 13 | |
| 14 Function genCleanBlock() { | |
| 15 block(x) => x; | |
| 16 return block; | |
| 17 } | |
| 18 | |
| 19 Function genCopyingBlock() { | |
| 20 final x = 'I could be copied into the block'; | |
| 21 block() => x; | |
| 22 return block; | |
| 23 } | |
| 24 | |
| 25 Function genFullBlock() { | |
| 26 var x = 42; // I must captured in a context. | |
| 27 block() => x; | |
| 28 x++; | |
| 29 return block; | |
| 30 } | |
| 31 | |
| 32 Function genFullBlockWithChain() { | |
| 33 var x = 420; // I must captured in a context. | |
| 34 outerBlock() { | |
| 35 var y = 4200; | |
| 36 innerBlock() => x + y; | |
| 37 y++; | |
| 38 return innerBlock; | |
| 39 } | |
| 40 x++; | |
| 41 return outerBlock(); | |
| 42 } | |
| 43 | |
| 44 void script() { | |
| 45 cleanBlock = genCleanBlock(); | |
| 46 copyingBlock = genCopyingBlock(); | |
| 47 fullBlock = genFullBlock(); | |
| 48 fullBlockWithChain = genFullBlockWithChain(); | |
| 49 } | |
| 50 | |
| 51 var tests = [ | |
| 52 | |
| 53 (Isolate isolate) => | |
| 54 isolate.rootLib.load().then((Library lib) { | |
| 55 Field field = lib.variables.singleWhere((v) => v.name == 'cleanBlock'); | |
| 56 return field.value.load().then((Instance block) { | |
| 57 expect(block.isClosure, isTrue); | |
| 58 expect(block.closureCtxt.isContext, isTrue); | |
| 59 expect(block.closureCtxt.length, equals(0)); | |
| 60 return block.closureCtxt.load().then((Context ctxt) { | |
| 61 expect(ctxt.parentContext.isNull, isTrue); | |
| 62 }); | |
| 63 }); | |
| 64 }), | |
| 65 | |
| 66 (Isolate isolate) => | |
| 67 isolate.rootLib.load().then((Library lib) { | |
| 68 Field field = lib.variables.singleWhere((v) => v.name == 'copyingBlock'); | |
| 69 return field.value.load().then((Instance block) { | |
| 70 expect(block.isClosure, isTrue); | |
| 71 expect(block.closureCtxt.isContext, isTrue); | |
| 72 expect(block.closureCtxt.length, equals(1)); | |
| 73 return block.closureCtxt.load().then((Context ctxt) { | |
| 74 expect(ctxt.variables.single['value'].isString, isTrue); | |
| 75 expect(ctxt.variables.single['value'].valueAsString, equals('I could be
copied into the block')); | |
| 76 expect(ctxt.parentContext.isContext, isTrue); | |
| 77 expect(ctxt.parentContext.length, equals(0)); | |
| 78 return ctxt.parentContext.load().then((Context outerCtxt) { | |
| 79 expect(outerCtxt.parentContext.isNull, isTrue); | |
| 80 }); | |
| 81 }); | |
| 82 }); | |
| 83 }), | |
| 84 | |
| 85 (Isolate isolate) => | |
| 86 isolate.rootLib.load().then((Library lib) { | |
| 87 Field field = lib.variables.singleWhere((v) => v.name == 'fullBlock'); | |
| 88 return field.value.load().then((Instance block) { | |
| 89 expect(block.isClosure, isTrue); | |
| 90 expect(block.closureCtxt.isContext, isTrue); | |
| 91 expect(block.closureCtxt.length, equals(1)); | |
| 92 return block.closureCtxt.load().then((ctxt) { | |
| 93 expect(ctxt.variables.single['value'].isInt, isTrue); | |
| 94 expect(ctxt.variables.single['value'].valueAsString, equals('43')); | |
| 95 expect(ctxt.parentContext.isContext, isTrue); | |
| 96 expect(ctxt.parentContext.length, equals(0)); | |
| 97 return ctxt.parentContext.load().then((Context outerCtxt) { | |
| 98 expect(outerCtxt.parentContext.isNull, isTrue); | |
| 99 }); | |
| 100 }); | |
| 101 }); | |
| 102 }), | |
| 103 | |
| 104 (Isolate isolate) => | |
| 105 isolate.rootLib.load().then((Library lib) { | |
| 106 Field field = lib.variables.singleWhere((v) => v.name == 'fullBlockWithChain
'); | |
| 107 return field.value.load().then((Instance block) { | |
| 108 expect(block.isClosure, isTrue); | |
| 109 expect(block.closureCtxt.isContext, isTrue); | |
| 110 expect(block.closureCtxt.length, equals(1)); | |
| 111 return block.closureCtxt.load().then((Context ctxt) { | |
| 112 expect(ctxt.variables.single['value'].isInt, isTrue); | |
| 113 expect(ctxt.variables.single['value'].valueAsString, equals('4201')); | |
| 114 expect(ctxt.parentContext.isContext, isTrue); | |
| 115 expect(ctxt.parentContext.length, equals(1)); | |
| 116 return ctxt.parentContext.load().then((Context outerCtxt) { | |
| 117 expect(outerCtxt.variables.single['value'].isInt, isTrue); | |
| 118 expect(outerCtxt.variables.single['value'].valueAsString, equals('421'
)); | |
| 119 expect(outerCtxt.parentContext.isContext, isTrue); | |
| 120 expect(outerCtxt.parentContext.length, equals(0)); | |
| 121 return outerCtxt.parentContext.load().then((Context outerCtxt2) { | |
| 122 expect(outerCtxt2.parentContext.isNull, isTrue); | |
| 123 }); | |
| 124 }); | |
| 125 }); | |
| 126 }); | |
| 127 }), | |
| 128 | |
| 129 ]; | |
| 130 | |
| 131 main(args) => runIsolateTests(args, tests, testeeBefore: script); | |
| OLD | NEW |