OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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=--error_on_bad_type --error_on_bad_override |
| 5 |
| 6 import 'dart:async'; |
| 7 import 'dart:developer'; |
| 8 import 'package:observatory/service_io.dart'; |
| 9 import 'package:unittest/unittest.dart'; |
| 10 import 'service_test_common.dart'; |
| 11 import 'test_helper.dart'; |
| 12 |
| 13 var thing1; |
| 14 var thing2; |
| 15 |
| 16 testeeMain() { |
| 17 thing1 = 3; |
| 18 thing2 = 4; |
| 19 foo(42, 1984); |
| 20 } |
| 21 |
| 22 foo(x, y) { |
| 23 var local = x + y; |
| 24 debugger(); |
| 25 return local; |
| 26 } |
| 27 |
| 28 var tests = [ |
| 29 hasStoppedAtBreakpoint, |
| 30 (Isolate isolate) async { |
| 31 // Make sure we are in the right place. |
| 32 var stack = await isolate.getStack(); |
| 33 expect(stack.type, equals('Stack')); |
| 34 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
| 35 expect(stack['frames'][0].function.name, equals('foo')); |
| 36 |
| 37 var lib = await isolate.rootLibrary.load(); |
| 38 var thing1 = |
| 39 (await lib.variables.singleWhere((v) => v.name == "thing1").load()) |
| 40 .staticValue; |
| 41 print(thing1); |
| 42 var thing2 = |
| 43 (await lib.variables.singleWhere((v) => v.name == "thing2").load()) |
| 44 .staticValue; |
| 45 print(thing2); |
| 46 |
| 47 var result = await isolate |
| 48 .evalFrame(0, "x + y + a + b", scope: {"a": thing1, "b": thing2}); |
| 49 print(result); |
| 50 expect(result.valueAsString, equals('2033')); |
| 51 |
| 52 result = await isolate |
| 53 .evalFrame(0, "local + a + b", scope: {"a": thing1, "b": thing2}); |
| 54 print(result); |
| 55 expect(result.valueAsString, equals('2033')); |
| 56 |
| 57 // Note the eval's scope is shadowing the locals' scope. |
| 58 result = |
| 59 await isolate.evalFrame(0, "x + y", scope: {"x": thing1, "y": thing2}); |
| 60 print(result); |
| 61 expect(result.valueAsString, equals('7')); |
| 62 |
| 63 bool didThrow = false; |
| 64 try { |
| 65 await lib.evaluate("x + y", scope: {"x": lib, "y": lib}); |
| 66 } catch (e) { |
| 67 didThrow = true; |
| 68 expect(e.toString(), |
| 69 contains("Cannot evaluate against a VM-internal object")); |
| 70 } |
| 71 expect(didThrow, isTrue); |
| 72 |
| 73 didThrow = false; |
| 74 try { |
| 75 result = |
| 76 await lib.evaluate("x + y", scope: {"not&an&identifier": thing1}); |
| 77 print(result); |
| 78 } catch (e) { |
| 79 didThrow = true; |
| 80 expect(e.toString(), contains("invalid 'scope' parameter")); |
| 81 } |
| 82 expect(didThrow, isTrue); |
| 83 }, |
| 84 ]; |
| 85 |
| 86 main(args) => runIsolateTests(args, tests, testeeConcurrent: testeeMain); |
OLD | NEW |