Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Unified Diff: runtime/observatory/tests/service/evaluate_in_frame_with_scope_test.dart

Issue 2872503004: vm-service: Add optional 'scope' parameter to 'evaluate' and 'evaluateInFrame'. (Closed)
Patch Set: review Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/observatory/tests/service/evaluate_in_frame_with_scope_test.dart
diff --git a/runtime/observatory/tests/service/evaluate_in_frame_with_scope_test.dart b/runtime/observatory/tests/service/evaluate_in_frame_with_scope_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b6e68756779d226bf0c1c03956e57182023b5cf8
--- /dev/null
+++ b/runtime/observatory/tests/service/evaluate_in_frame_with_scope_test.dart
@@ -0,0 +1,86 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// VMOptions=--error_on_bad_type --error_on_bad_override
+
+import 'dart:async';
+import 'dart:developer';
+import 'package:observatory/service_io.dart';
+import 'package:unittest/unittest.dart';
+import 'service_test_common.dart';
+import 'test_helper.dart';
+
+var thing1;
+var thing2;
+
+testeeMain() {
+ thing1 = 3;
+ thing2 = 4;
+ foo(42, 1984);
+}
+
+foo(x, y) {
+ var local = x + y;
+ debugger();
+ return local;
+}
+
+var tests = [
+ hasStoppedAtBreakpoint,
+ (Isolate isolate) async {
+ // Make sure we are in the right place.
+ var stack = await isolate.getStack();
+ expect(stack.type, equals('Stack'));
+ expect(stack['frames'].length, greaterThanOrEqualTo(1));
+ expect(stack['frames'][0].function.name, equals('foo'));
+
+ var lib = await isolate.rootLibrary.load();
+ var thing1 =
+ (await lib.variables.singleWhere((v) => v.name == "thing1").load())
+ .staticValue;
+ print(thing1);
+ var thing2 =
+ (await lib.variables.singleWhere((v) => v.name == "thing2").load())
+ .staticValue;
+ print(thing2);
+
+ var result = await isolate
+ .evalFrame(0, "x + y + a + b", scope: {"a": thing1, "b": thing2});
+ print(result);
+ expect(result.valueAsString, equals('2033'));
+
+ result = await isolate
+ .evalFrame(0, "local + a + b", scope: {"a": thing1, "b": thing2});
+ print(result);
+ expect(result.valueAsString, equals('2033'));
+
+ // Note the eval's scope is shadowing the locals' scope.
+ result =
+ await isolate.evalFrame(0, "x + y", scope: {"x": thing1, "y": thing2});
+ print(result);
+ expect(result.valueAsString, equals('7'));
+
+ bool didThrow = false;
+ try {
+ await lib.evaluate("x + y", scope: {"x": lib, "y": lib});
+ } catch (e) {
+ didThrow = true;
+ expect(e.toString(),
+ contains("Cannot evaluate against a VM-internal object"));
+ }
+ expect(didThrow, isTrue);
+
+ didThrow = false;
+ try {
+ result =
+ await lib.evaluate("x + y", scope: {"not&an&identifier": thing1});
+ print(result);
+ } catch (e) {
+ didThrow = true;
+ expect(e.toString(), contains("invalid 'scope' parameter"));
+ }
+ expect(didThrow, isTrue);
+ },
+];
+
+main(args) => runIsolateTests(args, tests, testeeConcurrent: testeeMain);
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/observatory/tests/service/evaluate_with_scope_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698