OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 part of service; | 5 part of service; |
6 | 6 |
7 // Some value smaller than the object ring, so requesting a large array | 7 // Some value smaller than the object ring, so requesting a large array |
8 // doesn't result in an expired ref because the elements lapped it in the | 8 // doesn't result in an expired ref because the elements lapped it in the |
9 // object ring. | 9 // object ring. |
10 const int kDefaultFieldLimit = 100; | 10 const int kDefaultFieldLimit = 100; |
11 | 11 |
12 /// Helper function for canceling a Future<StreamSubscription>. | 12 /// Helper function for canceling a Future<StreamSubscription>. |
13 Future cancelFutureSubscription( | 13 Future cancelFutureSubscription( |
14 Future<StreamSubscription> subscriptionFuture) async { | 14 Future<StreamSubscription> subscriptionFuture) async { |
15 if (subscriptionFuture != null) { | 15 if (subscriptionFuture != null) { |
16 var subscription = await subscriptionFuture; | 16 var subscription = await subscriptionFuture; |
17 return subscription.cancel(); | 17 return subscription.cancel(); |
18 } else { | 18 } else { |
19 return null; | 19 return null; |
20 } | 20 } |
21 } | 21 } |
22 | 22 |
23 /// An RpcException represents an exceptional event that happened | 23 /// An RpcException represents an exceptional event that happened |
24 /// while invoking an rpc. | 24 /// while invoking an rpc. |
25 abstract class RpcException implements Exception { | 25 abstract class RpcException implements Exception, M.BasicException { |
26 RpcException(this.message); | 26 RpcException(this.message); |
27 | 27 |
28 String message; | 28 String message; |
29 } | 29 } |
30 | 30 |
31 /// A ServerRpcException represents an error returned by the VM. | 31 /// A ServerRpcException represents an error returned by the VM. |
32 class ServerRpcException extends RpcException { | 32 class ServerRpcException extends RpcException implements M.RequestException { |
33 /// A list of well-known server error codes. | 33 /// A list of well-known server error codes. |
34 static const kParseError = -32700; | 34 static const kParseError = -32700; |
35 static const kInvalidRequest = -32600; | 35 static const kInvalidRequest = -32600; |
36 static const kMethodNotFound = -32601; | 36 static const kMethodNotFound = -32601; |
37 static const kInvalidParams = -32602; | 37 static const kInvalidParams = -32602; |
38 static const kInternalError = -32603; | 38 static const kInternalError = -32603; |
39 static const kFeatureDisabled = 100; | 39 static const kFeatureDisabled = 100; |
40 static const kCannotAddBreakpoint = 102; | 40 static const kCannotAddBreakpoint = 102; |
41 static const kStreamAlreadySubscribed = 103; | 41 static const kStreamAlreadySubscribed = 103; |
42 static const kStreamNotSubscribed = 104; | 42 static const kStreamNotSubscribed = 104; |
(...skipping 20 matching lines...) Expand all Loading... |
63 ServerRpcException.fromMap(Map errorMap) : super(_getMessage(errorMap)) { | 63 ServerRpcException.fromMap(Map errorMap) : super(_getMessage(errorMap)) { |
64 code = errorMap['code']; | 64 code = errorMap['code']; |
65 data = errorMap['data']; | 65 data = errorMap['data']; |
66 } | 66 } |
67 | 67 |
68 String toString() => 'ServerRpcException(${message})'; | 68 String toString() => 'ServerRpcException(${message})'; |
69 } | 69 } |
70 | 70 |
71 /// A NetworkRpcException is used to indicate that an rpc has | 71 /// A NetworkRpcException is used to indicate that an rpc has |
72 /// been canceled due to network error. | 72 /// been canceled due to network error. |
73 class NetworkRpcException extends RpcException { | 73 class NetworkRpcException extends RpcException |
| 74 implements M.ConnectionException { |
74 NetworkRpcException(String message) : super(message); | 75 NetworkRpcException(String message) : super(message); |
75 | 76 |
76 String toString() => 'NetworkRpcException(${message})'; | 77 String toString() => 'NetworkRpcException(${message})'; |
77 } | 78 } |
78 | 79 |
79 class MalformedResponseRpcException extends RpcException { | 80 class MalformedResponseRpcException extends RpcException { |
80 MalformedResponseRpcException(String message, this.response) | 81 MalformedResponseRpcException(String message, this.response) |
81 : super(message); | 82 : super(message); |
82 | 83 |
83 Map response; | 84 Map response; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 /// be [loaded]. | 418 /// be [loaded]. |
418 ServiceObject getFromMap(ObservableMap map); | 419 ServiceObject getFromMap(ObservableMap map); |
419 } | 420 } |
420 | 421 |
421 abstract class Location { | 422 abstract class Location { |
422 Script get script; | 423 Script get script; |
423 int get tokenPos; | 424 int get tokenPos; |
424 } | 425 } |
425 | 426 |
426 /// A [SourceLocation] represents a location or range in the source code. | 427 /// A [SourceLocation] represents a location or range in the source code. |
427 class SourceLocation extends ServiceObject implements Location { | 428 class SourceLocation extends ServiceObject implements Location, |
| 429 M.SourceLocation { |
428 Script script; | 430 Script script; |
429 int tokenPos; | 431 int tokenPos; |
430 int endTokenPos; | 432 int endTokenPos; |
431 | 433 |
432 Future<int> getLine() async { | 434 Future<int> getLine() async { |
433 await script.load(); | 435 await script.load(); |
434 return script.tokenToLine(tokenPos); | 436 return script.tokenToLine(tokenPos); |
435 } | 437 } |
436 | 438 |
437 Future<int> getColumn() async { | 439 Future<int> getColumn() async { |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 print("${obj.runtimeType} should be a HeapObject"); | 1114 print("${obj.runtimeType} should be a HeapObject"); |
1113 } | 1115 } |
1114 return obj; | 1116 return obj; |
1115 })); | 1117 })); |
1116 } | 1118 } |
1117 return result; | 1119 return result; |
1118 } | 1120 } |
1119 } | 1121 } |
1120 | 1122 |
1121 /// State for a running isolate. | 1123 /// State for a running isolate. |
1122 class Isolate extends ServiceObjectOwner implements M.IsolateRef { | 1124 class Isolate extends ServiceObjectOwner implements M.Isolate { |
1123 static const kLoggingStream = '_Logging'; | 1125 static const kLoggingStream = '_Logging'; |
1124 static const kExtensionStream = 'Extension'; | 1126 static const kExtensionStream = 'Extension'; |
1125 | 1127 |
1126 @reflectable VM get vm => owner; | 1128 @reflectable VM get vm => owner; |
1127 @reflectable Isolate get isolate => this; | 1129 @reflectable Isolate get isolate => this; |
1128 @observable int number; | 1130 @observable int number; |
1129 @observable int originNumber; | 1131 @observable int originNumber; |
1130 @observable DateTime startTime; | 1132 @observable DateTime startTime; |
1131 @observable Duration get upTime { | 1133 @observable Duration get upTime { |
1132 if (startTime == null) { | 1134 if (startTime == null) { |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 if (data == null) { | 2031 if (data == null) { |
2030 return "ServiceEvent(owner='${ownerName}', kind='${kind}', " | 2032 return "ServiceEvent(owner='${ownerName}', kind='${kind}', " |
2031 "time=${timestamp})"; | 2033 "time=${timestamp})"; |
2032 } else { | 2034 } else { |
2033 return "ServiceEvent(owner='${ownerName}', kind='${kind}', " | 2035 return "ServiceEvent(owner='${ownerName}', kind='${kind}', " |
2034 "data.lengthInBytes=${data.lengthInBytes}, time=${timestamp})"; | 2036 "data.lengthInBytes=${data.lengthInBytes}, time=${timestamp})"; |
2035 } | 2037 } |
2036 } | 2038 } |
2037 } | 2039 } |
2038 | 2040 |
2039 class Breakpoint extends ServiceObject { | 2041 class Breakpoint extends ServiceObject implements M.Breakpoint { |
2040 Breakpoint._empty(ServiceObjectOwner owner) : super._empty(owner); | 2042 Breakpoint._empty(ServiceObjectOwner owner) : super._empty(owner); |
2041 | 2043 |
2042 // TODO(turnidge): Add state to track if a breakpoint has been | 2044 // TODO(turnidge): Add state to track if a breakpoint has been |
2043 // removed from the program. Remove from the cache when deleted. | 2045 // removed from the program. Remove from the cache when deleted. |
2044 bool get canCache => true; | 2046 bool get canCache => true; |
2045 bool get immutable => false; | 2047 bool get immutable => false; |
2046 | 2048 |
2047 // A unique integer identifier for this breakpoint. | 2049 // A unique integer identifier for this breakpoint. |
2048 @observable int number; | 2050 @observable int number; |
2049 | 2051 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 | 2127 |
2126 LibraryDependency._(this.isImport, this.isDeferred, this.prefix, this.target); | 2128 LibraryDependency._(this.isImport, this.isDeferred, this.prefix, this.target); |
2127 | 2129 |
2128 static _fromMap(map) => new LibraryDependency._(map["isImport"], | 2130 static _fromMap(map) => new LibraryDependency._(map["isImport"], |
2129 map["isDeferred"], | 2131 map["isDeferred"], |
2130 map["prefix"], | 2132 map["prefix"], |
2131 map["target"]); | 2133 map["target"]); |
2132 } | 2134 } |
2133 | 2135 |
2134 | 2136 |
2135 class Library extends HeapObject { | 2137 class Library extends HeapObject implements M.LibraryRef { |
2136 @observable String uri; | 2138 @observable String uri; |
2137 @reflectable final dependencies = new ObservableList<LibraryDependency>(); | 2139 @reflectable final dependencies = new ObservableList<LibraryDependency>(); |
2138 @reflectable final scripts = new ObservableList<Script>(); | 2140 @reflectable final scripts = new ObservableList<Script>(); |
2139 @reflectable final classes = new ObservableList<Class>(); | 2141 @reflectable final classes = new ObservableList<Class>(); |
2140 @reflectable final variables = new ObservableList<Field>(); | 2142 @reflectable final variables = new ObservableList<Field>(); |
2141 @reflectable final functions = new ObservableList<ServiceFunction>(); | 2143 @reflectable final functions = new ObservableList<ServiceFunction>(); |
2142 | 2144 |
2143 bool get canCache => true; | 2145 bool get canCache => true; |
2144 bool get immutable => false; | 2146 bool get immutable => false; |
2145 | 2147 |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2922 } | 2924 } |
2923 | 2925 |
2924 /// The location of a local variable reference in a script. | 2926 /// The location of a local variable reference in a script. |
2925 class LocalVarLocation { | 2927 class LocalVarLocation { |
2926 final int line; | 2928 final int line; |
2927 final int column; | 2929 final int column; |
2928 final int endColumn; | 2930 final int endColumn; |
2929 LocalVarLocation(this.line, this.column, this.endColumn); | 2931 LocalVarLocation(this.line, this.column, this.endColumn); |
2930 } | 2932 } |
2931 | 2933 |
2932 class Script extends HeapObject { | 2934 class Script extends HeapObject implements M.Script { |
2933 final lines = new ObservableList<ScriptLine>(); | 2935 final lines = new ObservableList<ScriptLine>(); |
2934 @observable String uri; | 2936 @observable String uri; |
2935 @observable String kind; | 2937 @observable String kind; |
2936 @observable DateTime loadTime; | 2938 @observable DateTime loadTime; |
2937 @observable int firstTokenPos; | 2939 @observable int firstTokenPos; |
2938 @observable int lastTokenPos; | 2940 @observable int lastTokenPos; |
2939 @observable int lineOffset; | 2941 @observable int lineOffset; |
2940 @observable int columnOffset; | 2942 @observable int columnOffset; |
2941 @observable Library library; | 2943 @observable Library library; |
2942 | 2944 |
| 2945 String source; |
| 2946 |
2943 bool get immutable => true; | 2947 bool get immutable => true; |
2944 | 2948 |
2945 String _shortUri; | 2949 String _shortUri; |
2946 | 2950 |
2947 Script._empty(ServiceObjectOwner owner) : super._empty(owner); | 2951 Script._empty(ServiceObjectOwner owner) : super._empty(owner); |
2948 | 2952 |
2949 ScriptLine getLine(int line) { | 2953 ScriptLine getLine(int line) { |
2950 assert(_loaded); | 2954 assert(_loaded); |
2951 assert(line >= 1); | 2955 assert(line >= 1); |
2952 return lines[line - lineOffset - 1]; | 2956 return lines[line - lineOffset - 1]; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3034 vmName = uri; | 3038 vmName = uri; |
3035 if (mapIsRef) { | 3039 if (mapIsRef) { |
3036 return; | 3040 return; |
3037 } | 3041 } |
3038 _loaded = true; | 3042 _loaded = true; |
3039 int loadTimeMillis = map['_loadTime']; | 3043 int loadTimeMillis = map['_loadTime']; |
3040 loadTime = new DateTime.fromMillisecondsSinceEpoch(loadTimeMillis); | 3044 loadTime = new DateTime.fromMillisecondsSinceEpoch(loadTimeMillis); |
3041 lineOffset = map['lineOffset']; | 3045 lineOffset = map['lineOffset']; |
3042 columnOffset = map['columnOffset']; | 3046 columnOffset = map['columnOffset']; |
3043 _parseTokenPosTable(map['tokenPosTable']); | 3047 _parseTokenPosTable(map['tokenPosTable']); |
| 3048 source = map['source']; |
3044 _processSource(map['source']); | 3049 _processSource(map['source']); |
3045 library = map['library']; | 3050 library = map['library']; |
3046 } | 3051 } |
3047 | 3052 |
3048 void _parseTokenPosTable(List<List<int>> table) { | 3053 void _parseTokenPosTable(List<List<int>> table) { |
3049 if (table == null) { | 3054 if (table == null) { |
3050 return; | 3055 return; |
3051 } | 3056 } |
3052 _tokenToLine.clear(); | 3057 _tokenToLine.clear(); |
3053 _tokenToCol.clear(); | 3058 _tokenToCol.clear(); |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3991 void _onPoll(_) { | 3996 void _onPoll(_) { |
3992 // Reload metrics and add a sample to each. | 3997 // Reload metrics and add a sample to each. |
3993 for (var metric in metrics) { | 3998 for (var metric in metrics) { |
3994 metric.reload().then((m) { | 3999 metric.reload().then((m) { |
3995 m.addSample(new MetricSample(m.value)); | 4000 m.addSample(new MetricSample(m.value)); |
3996 }); | 4001 }); |
3997 } | 4002 } |
3998 } | 4003 } |
3999 } | 4004 } |
4000 | 4005 |
4001 class Frame extends ServiceObject { | 4006 class Frame extends ServiceObject implements M.Frame { |
4002 @observable int index; | 4007 @observable int index; |
4003 @observable ServiceFunction function; | 4008 @observable ServiceFunction function; |
4004 @observable SourceLocation location; | 4009 @observable SourceLocation location; |
4005 @observable Code code; | 4010 @observable Code code; |
4006 @observable List<ServiceMap> variables = new ObservableList<ServiceMap>(); | 4011 @observable List<ServiceMap> variables = new ObservableList<ServiceMap>(); |
4007 | 4012 |
4008 Frame._empty(ServiceObject owner) : super._empty(owner); | 4013 Frame._empty(ServiceObject owner) : super._empty(owner); |
4009 | 4014 |
4010 void _update(ObservableMap map, bool mapIsRef) { | 4015 void _update(ObservableMap map, bool mapIsRef) { |
4011 assert(!mapIsRef); | 4016 assert(!mapIsRef); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4126 var v = list[i]; | 4131 var v = list[i]; |
4127 if ((v is ObservableMap) && _isServiceMap(v)) { | 4132 if ((v is ObservableMap) && _isServiceMap(v)) { |
4128 list[i] = owner.getFromMap(v); | 4133 list[i] = owner.getFromMap(v); |
4129 } else if (v is ObservableList) { | 4134 } else if (v is ObservableList) { |
4130 _upgradeObservableList(v, owner); | 4135 _upgradeObservableList(v, owner); |
4131 } else if (v is ObservableMap) { | 4136 } else if (v is ObservableMap) { |
4132 _upgradeObservableMap(v, owner); | 4137 _upgradeObservableMap(v, owner); |
4133 } | 4138 } |
4134 } | 4139 } |
4135 } | 4140 } |
OLD | NEW |