Skip to content

Commit f346cb7

Browse files
vsmenoncommit-bot@chromium.org
authored andcommitted
Fix ddc debugger_test
This CL: - Fixes #43987 (an exception in custom formatting code) - Restores (most of) debugger_test.dart to passing (which tests above) - Fixes a type caching error also exposed by the above test Note, this skips the golden file comparison. That appears to be very broken (see comment). Change-Id: I283b66a710f17765faed47aa099b0b8570e6cac1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170022 Reviewed-by: Gary Roumanis <[email protected]> Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Vijay Menon <[email protected]>
1 parent 47b5a1e commit f346cb7

File tree

7 files changed

+2897
-926
lines changed

7 files changed

+2897
-926
lines changed

pkg/dev_compiler/lib/src/kernel/compiler.dart

+2-5
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
581581

582582
var finishGenericTypeTest = _emitClassTypeTests(c, className, body);
583583

584-
// Attach caches on all canonicalized types not in our runtime.
585-
// Types in the runtime will have caches attached in their constructors.
586-
if (!isSdkInternalRuntime(_currentLibrary)) {
587-
body.add(runtimeStatement('addTypeCaches(#)', [className]));
588-
}
584+
// Attach caches on all canonicalized types.
585+
body.add(runtimeStatement('addTypeCaches(#)', [className]));
589586

590587
_emitVirtualFieldSymbols(c, body);
591588
_emitClassSignature(c, className, body);

sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ final mixinOn = JS('', 'Symbol("mixinOn")');
107107
@JSExportName('implements')
108108
final implements_ = JS('', 'Symbol("implements")');
109109

110-
List? Function() getImplements(clazz) => JS(
110+
/// Either `null` if `clazz` doesn't directly implement any interfaces or a
111+
/// list of type objects if it does. Note, indirectly (e.g., via superclass)
112+
/// implemented interfaces aren't included here.
113+
/// See compiler.dart for when/how it is emitted.
114+
List Function()? getImplements(clazz) => JS(
111115
'',
112116
'Object.hasOwnProperty.call(#, #) ? #[#] : null',
113117
clazz,

sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,7 @@ Object? _getMatchingSupertype(Object? subtype, Object supertype) {
20452045
// Check interfaces.
20462046
var getInterfaces = getImplements(subtype);
20472047
if (getInterfaces != null) {
2048-
for (var iface in getInterfaces()!) {
2048+
for (var iface in getInterfaces()) {
20492049
result = _getMatchingSupertype(iface, supertype);
20502050
if (result != null) return result;
20512051
}

sdk/lib/_internal/js_dev_runtime/private/debugger.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class HeritageClause {
264264
final List types;
265265
}
266266

267-
Object safeGetProperty(Object protoChain, Object name) {
267+
Object? safeGetProperty(Object protoChain, Object name) {
268268
try {
269269
return JSNative.getProperty(protoChain, name);
270270
} catch (e) {
@@ -609,7 +609,7 @@ class LibraryModuleFormatter implements Formatter {
609609
for (var name in getOwnPropertyNames(object)) {
610610
var value = safeGetProperty(object, name);
611611
children.add(NameValuePair(
612-
name: name, value: Library(name, value), hideName: true));
612+
name: name, value: Library(name, value!), hideName: true));
613613
}
614614
return children.toList();
615615
}
@@ -907,10 +907,10 @@ class ClassFormatter implements Formatter {
907907
bool accept(object, config) => config == JsonMLConfig.asClass;
908908

909909
String preview(type) {
910-
var implements = dart.getImplements(type)();
910+
var implements = dart.getImplements(type);
911911
var typeName = getTypeName(type);
912912
if (implements != null) {
913-
var typeNames = implements.map(getTypeName);
913+
var typeNames = implements().map(getTypeName);
914914
return '${typeName} implements ${typeNames.join(", ")}';
915915
} else {
916916
return typeName;

tests/dartdevc/debugger/debugger_test.dart

+16-10
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ replacer(String key, value) {
8181
return value;
8282
}
8383

84-
String format(value) {
84+
String? format(value) {
8585
// Avoid double-escaping strings.
8686
if (value is String) return value;
8787
return stringify(value, allowInterop(replacer), 4);
@@ -90,8 +90,8 @@ String format(value) {
9090
class FormattedObject {
9191
FormattedObject(this.object, this.config);
9292

93-
Object object;
94-
Object config;
93+
Object? object;
94+
Object? config;
9595
}
9696

9797
/// Extract all object tags from a json ml expression to enable
@@ -130,14 +130,14 @@ main() async {
130130
var goldenUrl = '/root_dart/tests/dartdevc_2/debugger/'
131131
'debugger_test_golden.txt?cacheBlock=$cacheBlocker';
132132

133-
String golden;
133+
String? golden;
134134
try {
135135
golden = (await HttpRequest.getString(goldenUrl)).trim();
136136
} catch (e) {
137137
print("Warning: couldn't load golden file from $goldenUrl");
138138
}
139139

140-
document.body.append(new ScriptElement()
140+
document.body!.append(new ScriptElement()
141141
..type = 'text/javascript'
142142
..innerHtml = r"""
143143
window.ExampleJSClass = function ExampleJSClass(x) {
@@ -333,16 +333,16 @@ window.ExampleJSClass = function ExampleJSClass(x) {
333333
print(helpMessage);
334334
// Copy text to clipboard on page click. We can't copy to the clipboard
335335
// without a click due to Chrome security.
336-
TextAreaElement textField = new Element.tag('textarea');
336+
var textField = new Element.tag('textarea') as TextAreaElement;
337337
textField.maxLength = 100000000;
338338
textField.text = actualStr;
339339
textField.style
340340
..width = '800px'
341341
..height = '400px';
342-
document.body.append(new Element.tag('h3')
342+
document.body!.append(new Element.tag('h3')
343343
..innerHtml = helpMessage.replaceAll('\n', '<br>'));
344-
document.body.append(textField);
345-
document.body.onClick.listen((_) {
344+
document.body!.append(textField);
345+
document.body!.onClick.listen((_) {
346346
textField.select();
347347
var result = document.execCommand('copy');
348348
if (result) {
@@ -352,6 +352,12 @@ window.ExampleJSClass = function ExampleJSClass(x) {
352352
}
353353
});
354354
}
355-
expect(actualStr == golden, isTrue);
355+
// TODO(vsm): This comparison appears to be badly broken for several
356+
// reasons:
357+
// (1) The golden file isn't properly read on the bots or locally (see try
358+
// / catch above).
359+
// (2) The actual string appears to vary locally vs on the bots.
360+
// (3) Because of (2), visualizing the diff is difficult.
361+
// expect(actualStr == golden, isTrue);
356362
});
357363
}

tests/dartdevc_2/debugger/debugger_test.dart

+7-1
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ window.ExampleJSClass = function ExampleJSClass(x) {
354354
}
355355
});
356356
}
357-
expect(actualStr == golden, isTrue);
357+
// TODO(vsm): This comparison appears to be badly broken for several
358+
// reasons:
359+
// (1) The golden file isn't properly read on the bots or locally (see try
360+
// / catch above).
361+
// (2) The actual string appears to vary locally vs on the bots.
362+
// (3) Because of (2), visualizing the diff is difficult.
363+
// expect(actualStr == golden, isTrue);
358364
});
359365
}

0 commit comments

Comments
 (0)