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

Unified Diff: runtime/bin/vmservice/observatory/test/contexts_test.dart

Issue 532063002: Teach the Observatory about Contexts. Factor out object graph information from the instance view. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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
« no previous file with comments | « runtime/bin/vmservice/observatory/lib/src/service/object.dart ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/vmservice/observatory/test/contexts_test.dart
diff --git a/runtime/bin/vmservice/observatory/test/contexts_test.dart b/runtime/bin/vmservice/observatory/test/contexts_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..47c04415433c5ed71c195941935b3ab63b5f0218
--- /dev/null
+++ b/runtime/bin/vmservice/observatory/test/contexts_test.dart
@@ -0,0 +1,119 @@
+// Copyright (c) 2014, 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.
+
+library inbound_references_test;
+
+import 'dart:async';
+import 'package:observatory/service_io.dart';
+import 'package:unittest/unittest.dart';
+import 'test_helper.dart';
+
+var cleanBlock, copyingBlock, fullBlock, fullBlockWithChain;
+
+Function genCleanBlock() {
+ block(x) => x;
+ return block;
+}
+
+Function genCopyingBlock() {
+ final x = 'I could be copied into the block';
+ block() => x;
+ return block;
+}
+
+Function genFullBlock() {
+ var x = 42; // I must captured in a context.
+ block() => x;
+ x++;
+ return block;
+}
+
+Function genFullBlockWithChain() {
+ var x = 420; // I must captured in a context.
+ outerBlock() {
+ var y = 4200;
+ innerBlock() => x + y;
+ y++;
+ return innerBlock;
+ }
+ x++;
+ return outerBlock();
+}
+
+void script() {
+ cleanBlock = genCleanBlock();
+ copyingBlock = genCopyingBlock();
+ fullBlock = genFullBlock();
+ fullBlockWithChain = genFullBlockWithChain();
+}
+
+var tests = [
+
+(Isolate isolate) =>
+ isolate.rootLib.load().then((Library lib) {
+ ServiceObject field = lib.variables.singleWhere((v) => v.name == 'cleanBlock');
+ return field['value'].load().then((Instance block) {
+ expect(block.isClosure, isTrue);
+ expect(block.closureCtxt.isContext, isTrue);
+ expect(block.closureCtxt.length, equals(0));
+ return block.closureCtxt.load().then((Context ctxt) {
+ expect(ctxt.parentContext.isNull, isTrue);
+ });
+ });
+ }),
+
+(Isolate isolate) =>
+ isolate.rootLib.load().then((Library lib) {
+ ServiceObject field = lib.variables.singleWhere((v) => v.name == 'copyingBlock');
+ return field['value'].load().then((Instance block) {
+ expect(block.isClosure, isTrue);
+ expect(block.closureCtxt.isContext, isTrue);
+ expect(block.closureCtxt.length, equals(1));
+ return block.closureCtxt.load().then((Context ctxt) {
+ expect(ctxt.variables.single['value'].isString, isTrue);
+ expect(ctxt.variables.single['value'].valueAsString, equals('"I could be copied into the block"'));
+ expect(block.closureCtxt.parentContext.isNull, isTrue);
+ });
+ });
+ }),
+
+(Isolate isolate) =>
+ isolate.rootLib.load().then((Library lib) {
+ ServiceObject field = lib.variables.singleWhere((v) => v.name == 'fullBlock');
+ return field['value'].load().then((Instance block) {
+ expect(block.isClosure, isTrue);
+ expect(block.closureCtxt.isContext, isTrue);
+ expect(block.closureCtxt.length, equals(1));
+ return block.closureCtxt.load().then((ctxt) {
+ expect(ctxt.variables.single['value'].isInt, isTrue);
+ expect(ctxt.variables.single['value'].valueAsString, equals('43'));
+ expect(ctxt.parentContext.isNull, isTrue);
+ });
+ });
+ }),
+
+(Isolate isolate) =>
+ isolate.rootLib.load().then((Library lib) {
+ ServiceObject field = lib.variables.singleWhere((v) => v.name == 'fullBlockWithChain');
+ return field['value'].load().then((Instance block) {
+ expect(block.isClosure, isTrue);
+ expect(block.closureCtxt.isContext, isTrue);
+ expect(block.closureCtxt.length, equals(1));
+ return block.closureCtxt.load().then((Context ctxt) {
+ expect(ctxt.variables.single['value'].isInt, isTrue);
+ expect(ctxt.variables.single['value'].valueAsString, equals('4201'));
+ expect(ctxt.parentContext.isContext, isTrue);
+ expect(ctxt.parentContext.length, equals(1));
+ return ctxt.parentContext.load().then((Context outerCtxt) {
+ expect(outerCtxt.variables.single['value'].isInt, isTrue);
+ expect(outerCtxt.variables.single['value'].valueAsString, equals('421'));
+ expect(outerCtxt.parentContext.isNull, isTrue);
+ });
+ });
+ });
+ }),
+
+];
+
+main(args) => runIsolateTests(args, tests, testeeBefore: script);
« no previous file with comments | « runtime/bin/vmservice/observatory/lib/src/service/object.dart ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698