Fix two null errors in toJson of vm protocol objects (#699)
diff --git a/dwds/lib/src/debugging/debugger.dart b/dwds/lib/src/debugging/debugger.dart
index d65e149..efe5781 100644
--- a/dwds/lib/src/debugging/debugger.dart
+++ b/dwds/lib/src/debugging/debugger.dart
@@ -390,6 +390,10 @@
if (bestLocation == null) return null;
var script =
await inspector?.scriptRefFor(bestLocation.dartLocation.uri.serverPath);
+ // We think we found a location, but for some reason we can't find the script.
+ // Just drop the frame.
+ // TODO(#700): Understand when this can happen and have a better fix.
+ if (script == null) return null;
return Frame()
..code = (CodeRef(id: createId(), name: 'DartCode', kind: CodeKind.kDart))
..location = (SourceLocation()
diff --git a/dwds/lib/src/debugging/instance.dart b/dwds/lib/src/debugging/instance.dart
index 9d3d184..e71fb49 100644
--- a/dwds/lib/src/debugging/instance.dart
+++ b/dwds/lib/src/debugging/instance.dart
@@ -33,6 +33,9 @@
// TODO(grouma) - orgnaize our static classRefs better.
final _classRefForClosure = ClassRef(name: 'Closure', id: createId());
+/// A hard-coded ClassRef for a (non-existent) class called Unknown.
+final _classRefForUnknown = ClassRef(name: 'Unknown', id: createId());
+
/// Contains a set of methods for getting [Instance]s and [InstanceRef]s.
class InstanceHelper extends Domain {
final Debugger _debugger;
@@ -173,7 +176,8 @@
..closureFunction = FuncRef(
name: functionMetaData.name,
id: createId(),
- owner: null,
+ // TODO(alanknight): The right ClassRef
+ owner: _classRefForUnknown,
isConst: false,
isStatic: false)
..closureContext = (ContextRef()..length = 0);
diff --git a/dwds/test/fixtures/fakes.dart b/dwds/test/fixtures/fakes.dart
index b799888..0de5e4f 100644
--- a/dwds/test/fixtures/fakes.dart
+++ b/dwds/test/fixtures/fakes.dart
@@ -40,7 +40,8 @@
@override
Future<ScriptList> getScripts(String isolateId) => null;
@override
- Future<ScriptRef> scriptRefFor(String uri) => null;
+ Future<ScriptRef> scriptRefFor(String uri) =>
+ Future.value(ScriptRef(id: 'fake', uri: 'fake://uri'));
@override
Future<ScriptRef> scriptWithId(String scriptId) => null;
@override