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

Side by Side Diff: runtime/vm/service.cc

Issue 514833003: Add a new Sentinel type for sentinel responses. (They are not Null). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: gen js, fix tests 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/service/protocol.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 4
5 #include "vm/service.h" 5 #include "vm/service.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 PrintError(js, "attempt to evaluate against internal VM object\n"); 1113 PrintError(js, "attempt to evaluate against internal VM object\n");
1114 return true; 1114 return true;
1115 } 1115 }
1116 const char* expr = js->LookupOption("expr"); 1116 const char* expr = js->LookupOption("expr");
1117 if (expr == NULL) { 1117 if (expr == NULL) {
1118 PrintError(js, "eval expects an 'expr' option\n", 1118 PrintError(js, "eval expects an 'expr' option\n",
1119 js->num_arguments()); 1119 js->num_arguments());
1120 return true; 1120 return true;
1121 } 1121 }
1122 const String& expr_str = String::Handle(isolate, String::New(expr)); 1122 const String& expr_str = String::Handle(isolate, String::New(expr));
1123 ASSERT(obj->IsInstance()); 1123 ASSERT(obj->IsInstance() || obj->IsNull());
1124 const Instance& instance = Instance::Cast(*obj); 1124 Instance& instance = Instance::Handle();
1125 instance ^= obj->raw();
1125 const Object& result = 1126 const Object& result =
1126 Object::Handle(instance.Evaluate(expr_str, 1127 Object::Handle(instance.Evaluate(expr_str,
1127 Array::empty_array(), 1128 Array::empty_array(),
1128 Array::empty_array())); 1129 Array::empty_array()));
1129 result.PrintJSON(js, true); 1130 result.PrintJSON(js, true);
1130 return true; 1131 return true;
1131 } else if (strcmp(action, "retained") == 0) { 1132 } else if (strcmp(action, "retained") == 0) {
1132 if (kind == ObjectIdRing::kCollected) { 1133 if (kind == ObjectIdRing::kCollected) {
1133 PrintErrorWithKind( 1134 PrintErrorWithKind(
1134 js, "RetainedCollected", 1135 js, "RetainedCollected",
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 } else { 1666 } else {
1666 PrintError(js, "Invalid sub collection %s", second); 1667 PrintError(js, "Invalid sub collection %s", second);
1667 return true; 1668 return true;
1668 } 1669 }
1669 } 1670 }
1670 UNREACHABLE(); 1671 UNREACHABLE();
1671 return true; 1672 return true;
1672 } 1673 }
1673 1674
1674 1675
1675 static void PrintPseudoNull(JSONStream* js, 1676 static void PrintSentinel(JSONStream* js,
1676 const char* id, 1677 const char* id,
1677 const char* preview) { 1678 const char* preview) {
1678 JSONObject jsobj(js); 1679 JSONObject jsobj(js);
1679 jsobj.AddProperty("type", "Null"); 1680 jsobj.AddProperty("type", "Sentinel");
1680 jsobj.AddProperty("id", id); 1681 jsobj.AddProperty("id", id);
1681 jsobj.AddProperty("valueAsString", preview); 1682 jsobj.AddProperty("valueAsString", preview);
1682 } 1683 }
1683 1684
1684 1685
1685 static RawObject* LookupObjectId(Isolate* isolate, 1686 static RawObject* LookupObjectId(Isolate* isolate,
1686 const char* arg, 1687 const char* arg,
1687 ObjectIdRing::LookupResult* kind) { 1688 ObjectIdRing::LookupResult* kind) {
1688 *kind = ObjectIdRing::kValid; 1689 *kind = ObjectIdRing::kValid;
1689 if (strncmp(arg, "int-", 4) == 0) { 1690 if (strncmp(arg, "int-", 4) == 0) {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 } else { 1858 } else {
1858 Symbols::OptimizedOut().PrintJSON(js, false); 1859 Symbols::OptimizedOut().PrintJSON(js, false);
1859 } 1860 }
1860 return true; 1861 return true;
1861 1862
1862 } else if (strcmp(arg, "collected") == 0) { 1863 } else if (strcmp(arg, "collected") == 0) {
1863 if (js->num_arguments() > 2) { 1864 if (js->num_arguments() > 2) {
1864 PrintError(js, "expected at most 2 arguments but found %" Pd "\n", 1865 PrintError(js, "expected at most 2 arguments but found %" Pd "\n",
1865 js->num_arguments()); 1866 js->num_arguments());
1866 } else { 1867 } else {
1867 PrintPseudoNull(js, "objects/collected", "<collected>"); 1868 PrintSentinel(js, "objects/collected", "<collected>");
1868 } 1869 }
1869 return true; 1870 return true;
1870 1871
1871 } else if (strcmp(arg, "expired") == 0) { 1872 } else if (strcmp(arg, "expired") == 0) {
1872 if (js->num_arguments() > 2) { 1873 if (js->num_arguments() > 2) {
1873 PrintError(js, "expected at most 2 arguments but found %" Pd "\n", 1874 PrintError(js, "expected at most 2 arguments but found %" Pd "\n",
1874 js->num_arguments()); 1875 js->num_arguments());
1875 } else { 1876 } else {
1876 PrintPseudoNull(js, "objects/expired", "<expired>"); 1877 PrintSentinel(js, "objects/expired", "<expired>");
1877 } 1878 }
1878 return true; 1879 return true;
1879 } 1880 }
1880 1881
1881 // Lookup the object. 1882 // Lookup the object.
1882 Object& obj = Object::Handle(isolate); 1883 Object& obj = Object::Handle(isolate);
1883 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid; 1884 ObjectIdRing::LookupResult kind = ObjectIdRing::kInvalid;
1884 obj = LookupObjectId(isolate, arg, &kind); 1885 obj = LookupObjectId(isolate, arg, &kind);
1885 if (kind == ObjectIdRing::kInvalid) { 1886 if (kind == ObjectIdRing::kInvalid) {
1886 PrintError(js, "unrecognized object id '%s'", arg); 1887 PrintError(js, "unrecognized object id '%s'", arg);
1887 return true; 1888 return true;
1888 } 1889 }
1889 if (js->num_arguments() == 2) { 1890 if (js->num_arguments() == 2) {
1890 // Print. 1891 // Print.
1891 if (kind == ObjectIdRing::kCollected) { 1892 if (kind == ObjectIdRing::kCollected) {
1892 // The object has been collected by the gc. 1893 // The object has been collected by the gc.
1893 PrintPseudoNull(js, "objects/collected", "<collected>"); 1894 PrintSentinel(js, "objects/collected", "<collected>");
1894 return true; 1895 return true;
1895 } else if (kind == ObjectIdRing::kExpired) { 1896 } else if (kind == ObjectIdRing::kExpired) {
1896 // The object id has expired. 1897 // The object id has expired.
1897 PrintPseudoNull(js, "objects/expired", "<expired>"); 1898 PrintSentinel(js, "objects/expired", "<expired>");
1898 return true; 1899 return true;
1899 } 1900 }
1900 obj.PrintJSON(js, false); 1901 obj.PrintJSON(js, false);
1901 return true; 1902 return true;
1902 } 1903 }
1903 return HandleInstanceCommands(isolate, &obj, kind, js, 2); 1904 return HandleInstanceCommands(isolate, &obj, kind, js, 2);
1904 } 1905 }
1905 1906
1906 1907
1907 static bool HandleScriptsEnumerate(Isolate* isolate, JSONStream* js) { 1908 static bool HandleScriptsEnumerate(Isolate* isolate, JSONStream* js) {
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
2709 while (current != NULL) { 2710 while (current != NULL) {
2710 if (strcmp(name, current->name()) == 0) { 2711 if (strcmp(name, current->name()) == 0) {
2711 return current; 2712 return current;
2712 } 2713 }
2713 current = current->next(); 2714 current = current->next();
2714 } 2715 }
2715 return NULL; 2716 return NULL;
2716 } 2717 }
2717 2718
2718 } // namespace dart 2719 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/service/protocol.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698