2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart = 2.9
6
-
7
5
import 'dart:async' ;
8
6
7
+ import 'package:dwds/asset_reader.dart' ;
8
+ import 'package:dwds/expression_compiler.dart' ;
9
9
import 'package:dwds/src/debugging/classes.dart' ;
10
10
import 'package:dwds/src/debugging/execution_context.dart' ;
11
11
import 'package:dwds/src/debugging/inspector.dart' ;
12
12
import 'package:dwds/src/debugging/instance.dart' ;
13
13
import 'package:dwds/src/debugging/libraries.dart' ;
14
+ import 'package:dwds/src/debugging/metadata/provider.dart' ;
14
15
import 'package:dwds/src/debugging/modules.dart' ;
15
16
import 'package:dwds/src/debugging/remote_debugger.dart' ;
16
17
import 'package:dwds/src/debugging/webkit_debugger.dart' ;
17
18
import 'package:dwds/src/handlers/socket_connections.dart' ;
18
19
import 'package:dwds/src/loaders/require.dart' ;
19
20
import 'package:dwds/src/loaders/strategy.dart' ;
21
+ import 'package:shelf/shelf.dart' as shelf;
20
22
import 'package:vm_service/vm_service.dart' ;
21
23
22
24
/// A library of fake/stub implementations of our classes and their supporting
@@ -44,44 +46,48 @@ Isolate get simpleIsolate => Isolate(
44
46
);
45
47
46
48
class FakeInspector implements AppInspector {
47
- FakeInspector ({this .fakeIsolate});
49
+ FakeInspector ({required this .fakeIsolate});
48
50
49
51
Isolate fakeIsolate;
50
52
51
- final _instanceHelper = InstanceHelper (null , null );
52
-
53
53
@override
54
54
Object noSuchMethod (Invocation invocation) {
55
55
throw UnsupportedError ('This is a fake' );
56
56
}
57
57
58
58
@override
59
59
Future <void > initialize (LibraryHelper libraryHelper, ClassHelper classHelper,
60
- InstanceHelper instanceHelper) =>
61
- null ;
60
+ InstanceHelper instanceHelper) async =>
61
+ {} ;
62
62
63
63
@override
64
- Future <InstanceRef > instanceRefFor (Object value) =>
65
- _instanceHelper. instanceRefFor (value) ;
64
+ Future <InstanceRef ? > instanceRefFor (Object value) async =>
65
+ InstanceHelper .kNullInstanceRef ;
66
66
67
67
@override
68
- Future <Obj > getObject (String objectId, {int offset, int count}) => null ;
68
+ Future <Obj > getObject (String objectId, {int ? offset, int ? count}) async =>
69
+ Obj .parse ({})! ;
69
70
70
71
@override
71
- Future <ScriptList > getScripts () => null ;
72
+ Future <ScriptList > getScripts () async => ScriptList (scripts : []) ;
72
73
73
74
@override
74
- Future <ScriptRef > scriptRefFor (String uri) =>
75
- Future . value ( ScriptRef (id: 'fake' , uri: 'fake://uri' ) );
75
+ Future <ScriptRef > scriptRefFor (String uri) async =>
76
+ ScriptRef (id: 'fake' , uri: 'fake://uri' );
76
77
77
78
@override
78
- ScriptRef scriptWithId (String scriptId) => null ;
79
+ ScriptRef ? scriptWithId (String ? scriptId) => null ;
79
80
80
81
@override
81
82
Isolate get isolate => fakeIsolate;
82
83
83
84
@override
84
- IsolateRef get isolateRef => null ;
85
+ IsolateRef get isolateRef => IsolateRef (
86
+ id: fakeIsolate.id,
87
+ number: fakeIsolate.number,
88
+ name: fakeIsolate.name,
89
+ isSystemIsolate: fakeIsolate.isSystemIsolate,
90
+ );
85
91
}
86
92
87
93
class FakeSseConnection implements SseSocketConnection {
@@ -130,105 +136,108 @@ class FakeModules implements Modules {
130
136
}
131
137
132
138
class FakeWebkitDebugger implements WebkitDebugger {
133
- final Map <String , WipScript > _scripts;
139
+ final Map <String , WipScript >? _scripts;
134
140
@override
135
- Future disable () => null ;
141
+ Future disable () async => null ;
136
142
137
143
@override
138
- Future enable () => null ;
144
+ Future enable () async => null ;
139
145
140
- FakeWebkitDebugger ({Map <String , WipScript > scripts}) : _scripts = scripts {
146
+ FakeWebkitDebugger ({Map <String , WipScript >? scripts}) : _scripts = scripts {
141
147
globalLoadStrategy = RequireStrategy (
142
- ReloadConfiguration .none,
143
- (_) async => {},
144
- (_) async => {},
145
- (_, __) async => null ,
146
- (_, __) async => null ,
147
- (_, __) async => null ,
148
- null ,
149
- (_) async => null ,
150
- null );
148
+ ReloadConfiguration .none,
149
+ (_) async => {},
150
+ (_) async => {},
151
+ (_, __) async => null ,
152
+ (MetadataProvider _, String __) async => '' ,
153
+ (MetadataProvider _, String __) async => '' ,
154
+ (String _) => '' ,
155
+ (MetadataProvider _) async => < String , ModuleInfo > {},
156
+ FakeAssetReader (),
157
+ );
151
158
}
152
159
153
160
@override
154
161
Stream <T > eventStream <T >(String method, WipEventTransformer <T > transformer) =>
155
- null ;
162
+ Stream . empty () ;
156
163
157
164
@override
158
- Future <String > getScriptSource (String scriptId) => null ;
165
+ Future <String > getScriptSource (String scriptId) async => '' ;
159
166
160
- Stream <WipDomain > get onClosed => null ;
167
+ Stream <WipDomain >? get onClosed => null ;
161
168
162
169
@override
163
- Stream <GlobalObjectClearedEvent > get onGlobalObjectCleared => null ;
170
+ Stream <GlobalObjectClearedEvent > get onGlobalObjectCleared => Stream . empty () ;
164
171
165
172
@override
166
- Stream <DebuggerPausedEvent > onPaused;
173
+ late Stream <DebuggerPausedEvent > onPaused;
167
174
168
175
@override
169
- Stream <DebuggerResumedEvent > get onResumed => null ;
176
+ Stream <DebuggerResumedEvent > get onResumed => Stream . empty () ;
170
177
171
178
@override
172
- Stream <ScriptParsedEvent > get onScriptParsed => null ;
179
+ Stream <ScriptParsedEvent > get onScriptParsed => Stream . empty () ;
173
180
174
181
@override
175
- Stream <TargetCrashedEvent > get onTargetCrashed => null ;
182
+ Stream <TargetCrashedEvent > get onTargetCrashed => Stream . empty () ;
176
183
177
184
@override
178
- Future <WipResponse > pause () => null ;
185
+ Future <WipResponse > pause () async => WipResponse ({}) ;
179
186
180
187
@override
181
- Future <WipResponse > resume () => null ;
188
+ Future <WipResponse > resume () async => WipResponse ({}) ;
182
189
183
190
@override
184
- Map <String , WipScript > get scripts => _scripts;
191
+ Map <String , WipScript > get scripts => _scripts! ;
185
192
186
193
List <WipResponse > results = variables1;
187
194
int resultsReturned = 0 ;
188
195
189
196
@override
190
- Future <WipResponse > sendCommand (
191
- String method, {
192
- Map <String , dynamic > params,
193
- }) async {
197
+ Future <WipResponse > sendCommand (String command,
198
+ {Map <String , dynamic >? params}) async {
194
199
// Force the results that we expect for looking up the variables.
195
- if (method == 'Runtime.getProperties' ) {
200
+ if (command == 'Runtime.getProperties' ) {
196
201
return results[resultsReturned++ ];
197
202
}
198
- return null ;
203
+ return WipResponse ({}) ;
199
204
}
200
205
201
206
@override
202
- Future <WipResponse > setPauseOnExceptions (PauseState state) => null ;
207
+ Future <WipResponse > setPauseOnExceptions (PauseState state) async =>
208
+ WipResponse ({});
203
209
204
210
@override
205
- Future <WipResponse > removeBreakpoint (String breakpointId) => null ;
211
+ Future <WipResponse > removeBreakpoint (String breakpointId) async =>
212
+ WipResponse ({});
206
213
207
214
@override
208
- Future <WipResponse > stepInto ({Map <String , dynamic > params}) => null ;
215
+ Future <WipResponse > stepInto ({Map <String , dynamic >? params}) async =>
216
+ WipResponse ({});
209
217
210
218
@override
211
- Future <WipResponse > stepOut () => null ;
219
+ Future <WipResponse > stepOut () async => WipResponse ({}) ;
212
220
213
221
@override
214
- Future <WipResponse > stepOver ({Map <String , dynamic > params}) => null ;
222
+ Future <WipResponse > stepOver ({Map <String , dynamic >? params}) async =>
223
+ WipResponse ({});
215
224
216
225
@override
217
- Stream <ConsoleAPIEvent > get onConsoleAPICalled => null ;
226
+ Stream <ConsoleAPIEvent > get onConsoleAPICalled => Stream . empty () ;
218
227
219
228
@override
220
- Stream <ExceptionThrownEvent > get onExceptionThrown => null ;
229
+ Stream <ExceptionThrownEvent > get onExceptionThrown => Stream . empty () ;
221
230
222
231
@override
223
232
void close () {}
224
233
225
234
@override
226
- Stream <WipConnection > get onClose => null ;
235
+ Stream <WipConnection > get onClose => Stream . empty () ;
227
236
228
237
@override
229
238
Future <RemoteObject > evaluate (String expression,
230
- {bool returnByValue, int contextId}) =>
231
- null ;
239
+ {bool ? returnByValue, int ? contextId}) async =>
240
+ RemoteObject ({}) ;
232
241
233
242
@override
234
243
Future <RemoteObject > evaluateOnCallFrame (
@@ -237,14 +246,15 @@ class FakeWebkitDebugger implements WebkitDebugger {
237
246
}
238
247
239
248
@override
240
- Future <List <WipBreakLocation >> getPossibleBreakpoints (WipLocation start) =>
241
- null ;
249
+ Future <List <WipBreakLocation >> getPossibleBreakpoints (
250
+ WipLocation start) async =>
251
+ [];
242
252
243
253
@override
244
- Future <WipResponse > enablePage () => null ;
254
+ Future <WipResponse > enablePage () async => WipResponse ({}) ;
245
255
246
256
@override
247
- Future <WipResponse > pageReload () => null ;
257
+ Future <WipResponse > pageReload () async => WipResponse ({}) ;
248
258
}
249
259
250
260
/// Fake execution context that is needed for id only
@@ -256,3 +266,102 @@ class FakeExecutionContext extends ExecutionContext {
256
266
257
267
FakeExecutionContext ();
258
268
}
269
+
270
+ class FakeStrategy implements LoadStrategy {
271
+ @override
272
+ Future <String > bootstrapFor (String entrypoint) async => 'dummy_bootstrap' ;
273
+
274
+ @override
275
+ shelf.Handler get handler =>
276
+ (request) => (request.url.path == 'someDummyPath' )
277
+ ? shelf.Response .ok ('some dummy response' )
278
+ : shelf.Response .notFound ('someDummyPath' );
279
+
280
+ @override
281
+ String get id => 'dummy-id' ;
282
+
283
+ @override
284
+ String get moduleFormat => 'dummy-format' ;
285
+
286
+ @override
287
+ String get loadLibrariesModule => '' ;
288
+
289
+ @override
290
+ String get loadLibrariesSnippet => '' ;
291
+
292
+ @override
293
+ String loadLibrarySnippet (String libraryUri) => '' ;
294
+
295
+ @override
296
+ String get loadModuleSnippet => '' ;
297
+
298
+ @override
299
+ ReloadConfiguration get reloadConfiguration => ReloadConfiguration .none;
300
+
301
+ @override
302
+ String loadClientSnippet (String clientScript) => 'dummy-load-client-snippet' ;
303
+
304
+ @override
305
+ Future <String > moduleForServerPath (
306
+ String entrypoint, String serverPath) async =>
307
+ '' ;
308
+
309
+ @override
310
+ Future <String > serverPathForModule (String entrypoint, String module) async =>
311
+ '' ;
312
+
313
+ @override
314
+ Future <String > sourceMapPathForModule (
315
+ String entrypoint, String module) async =>
316
+ '' ;
317
+
318
+ @override
319
+ String serverPathForAppUri (String appUri) => '' ;
320
+
321
+ @override
322
+ MetadataProvider metadataProviderFor (String entrypoint) =>
323
+ MetadataProvider (entrypoint, FakeAssetReader ());
324
+
325
+ @override
326
+ void trackEntrypoint (String entrypoint) {}
327
+
328
+ @override
329
+ Future <Map <String , ModuleInfo >> moduleInfoForEntrypoint (String entrypoint) =>
330
+ throw UnimplementedError ();
331
+ }
332
+
333
+ class FakeAssetReader implements AssetReader {
334
+ final String ? _metadata;
335
+ final String ? _dartSource;
336
+ final String ? _sourceMap;
337
+ FakeAssetReader ({
338
+ metadata,
339
+ dartSource,
340
+ sourceMap,
341
+ }) : _metadata = metadata,
342
+ _dartSource = dartSource,
343
+ _sourceMap = sourceMap;
344
+
345
+ @override
346
+ Future <String > dartSourceContents (String serverPath) {
347
+ return _throwUnimplementedOrReturnContents (_dartSource);
348
+ }
349
+
350
+ @override
351
+ Future <String > metadataContents (String serverPath) {
352
+ return _throwUnimplementedOrReturnContents (_metadata);
353
+ }
354
+
355
+ @override
356
+ Future <String > sourceMapContents (String serverPath) {
357
+ return _throwUnimplementedOrReturnContents (_sourceMap);
358
+ }
359
+
360
+ @override
361
+ Future <void > close () async {}
362
+
363
+ Future <String > _throwUnimplementedOrReturnContents (String ? contents) async {
364
+ if (contents == null ) throw UnimplementedError ();
365
+ return contents;
366
+ }
367
+ }
0 commit comments