[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 <nshahan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
committed by
Commit Queue
parent
406e92dba6
commit
2ef46a1fff
@@ -1870,9 +1870,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
||||
|
||||
// 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;
|
||||
|
||||
@@ -221,15 +221,34 @@ F assertInterop<F extends Function?>(F f) {
|
||||
return f;
|
||||
}
|
||||
|
||||
bool isDartFunction(obj) =>
|
||||
JS<bool>('!', '# instanceof Function', obj) &&
|
||||
JS<bool>(
|
||||
'!',
|
||||
'#[#] != 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<bool>('!', '# 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<bool>('!', '# 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<Function> _assertInteropExpando = Expando<Function>();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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": "<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": "<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": "<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": "<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": "<OBJECT>",
|
||||
"config": {}
|
||||
}
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
-----------------------------------
|
||||
Test: Object formatting header
|
||||
|
||||
@@ -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": "<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": "<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": "<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": "<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": "<OBJECT>",
|
||||
"config": {}
|
||||
}
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
-----------------------------------
|
||||
Test: Object formatting header
|
||||
|
||||
Reference in New Issue
Block a user