From 2ef46a1ffffc8d7cac78c6a3ede422ff93a95261 Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Tue, 7 Nov 2023 00:48:58 +0000 Subject: [PATCH] [ddc] Fix custom formatter for classes Classes were mistakenly being formatted by the function formatter. Change-Id: I6c513803c7c211f02bb9267914b5988cd6c02c5e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334005 Commit-Queue: Nicholas Shahan Reviewed-by: Sigmund Cherem --- pkg/dev_compiler/lib/src/kernel/compiler.dart | 6 +- .../private/ddc_runtime/types.dart | 37 +++-- .../js_dev_runtime/private/debugger.dart | 7 +- .../debugger/debugger_test_golden.txt | 149 +++++++++++++++++- .../debugger/debugger_test_golden.txt | 149 +++++++++++++++++- 5 files changed, 329 insertions(+), 19 deletions(-) diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 83f0eb477a6..b65d82ce360 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -1870,9 +1870,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor // Add static property dart._runtimeType to Object. // All other Dart classes will (statically) inherit this property. - if (c == _coreTypes.objectClass) { - body.add(runtimeStatement('lazyFn(#, () => #.#)', - [className, emitLibraryName(_coreTypes.coreLibrary), 'Type'])); + if (!_options.newRuntimeTypes && c == _coreTypes.objectClass) { + body.add(runtimeStatement('lazyFn(#, () => #)', + [className, _emitType(_coreTypes.typeNonNullableRawType)])); } _classEmittingSignatures = savedClass; diff --git a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart index 989694c2767..8c24b93081b 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart @@ -221,15 +221,34 @@ F assertInterop(F f) { return f; } -bool isDartFunction(obj) => - JS('!', '# instanceof Function', obj) && - JS( - '!', - '#[#] != null', - obj, - JS_GET_FLAG("NEW_RUNTIME_TYPES") - ? JS_GET_NAME(JsGetName.SIGNATURE_NAME) - : _runtimeType); +/// Returns `true` when [obj] represents a Dart class. +@notNull +bool isDartClass(Object? obj) { + // All Dart classes are instances of JavaScript functions. + if (!JS('!', '# instanceof Function', obj)) return false; + if (JS_GET_FLAG("NEW_RUNTIME_TYPES")) { + // All Dart classes have an interface type recipe attached to them. + return JS('', '#.#', obj, rti.interfaceTypeRecipePropertyName) != null; + } else { + // All Dart classes inherit this type tag from the Dart Core Object class. + return _equalType(JS('!', '#[#]', obj, _runtimeType), Type); + } +} + +/// Returns `true` when [obj] represents a Dart function. +@notNull +bool isDartFunction(Object? obj) { + if (!JS('!', '# instanceof Function', obj)) return false; + if (JS_GET_FLAG("NEW_RUNTIME_TYPES")) { + // All Dart functions have a signature attached to them. + return JS('!', '#[#]', obj, JS_GET_NAME(JsGetName.SIGNATURE_NAME)) != null; + } else { + // All Dart functions have a signature attached to them but we must test + // that it is a function type to differentiate from Dart classes. + return _jsInstanceOf( + JS('!', '#[#]', obj, _runtimeType), AbstractFunctionType); + } +} Expando _assertInteropExpando = Expando(); diff --git a/sdk/lib/_internal/js_dev_runtime/private/debugger.dart b/sdk/lib/_internal/js_dev_runtime/private/debugger.dart index 8ec6eb4a002..d1c36748720 100644 --- a/sdk/lib/_internal/js_dev_runtime/private/debugger.dart +++ b/sdk/lib/_internal/js_dev_runtime/private/debugger.dart @@ -653,10 +653,7 @@ class LibraryFormatter implements Formatter { /// we can distinguish them based on whether they have been tagged with /// runtime type information. class FunctionFormatter implements Formatter { - bool accept(object, config) { - if (_typeof(object) != 'function') return false; - return dart.getReifiedType(object) != null; - } + bool accept(object, config) => dart.isDartFunction(object); bool hasChildren(object) => true; @@ -904,7 +901,7 @@ class StackTraceFormatter implements Formatter { } class ClassFormatter implements Formatter { - bool accept(object, config) => config == JsonMLConfig.asClass; + bool accept(object, config) => dart.isDartClass(object); String preview(type) { return getTypeName(type); diff --git a/tests/dartdevc/debugger/debugger_test_golden.txt b/tests/dartdevc/debugger/debugger_test_golden.txt index 6cb1b8726e6..49f2a39c140 100644 --- a/tests/dartdevc/debugger/debugger_test_golden.txt +++ b/tests/dartdevc/debugger/debugger_test_golden.txt @@ -4929,7 +4929,154 @@ Value: "ol", { "style": "list-style-type: none;padding-left: 0px;margin-top: 0px;margin-bottom: 0px;margin-left: 12px;" - } + }, + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + {}, + [ + "span", + { + "style": "" + }, + "[[Instance Methods]]" + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "addOne: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "last: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "nameAndDate: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "returnObject: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "[[base class]]: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ] ] ----------------------------------- Test: Object formatting header diff --git a/tests/dartdevc_2/debugger/debugger_test_golden.txt b/tests/dartdevc_2/debugger/debugger_test_golden.txt index 6cb1b8726e6..49f2a39c140 100644 --- a/tests/dartdevc_2/debugger/debugger_test_golden.txt +++ b/tests/dartdevc_2/debugger/debugger_test_golden.txt @@ -4929,7 +4929,154 @@ Value: "ol", { "style": "list-style-type: none;padding-left: 0px;margin-top: 0px;margin-bottom: 0px;margin-left: 12px;" - } + }, + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + {}, + [ + "span", + { + "style": "" + }, + "[[Instance Methods]]" + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "addOne: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "last: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "nameAndDate: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "returnObject: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ], + [ + "li", + { + "style": "padding-left: 13px;" + }, + [ + "span", + { + "style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px" + }, + "[[base class]]: " + ], + [ + "span", + { + "style": "margin-left: 13px" + }, + [ + "object", + { + "object": "", + "config": {} + } + ] + ] + ] ] ----------------------------------- Test: Object formatting header