Skip to content

Commit 5016cbc

Browse files
committed
Fixed type error in MapEntry and added keyToStringConfig to display the toString() of a key in a MapEntry preview.
BUG= [email protected] Review URL: https://codereview.chromium.org/2033433007 .
1 parent 68f90ac commit 5016cbc

File tree

3 files changed

+69
-31
lines changed

3 files changed

+69
-31
lines changed

pkg/dev_compiler/lib/runtime/dart_sdk.js

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,25 @@ dart_library.library('dart_sdk', null, /* Imports */[
22542254
dart._typeFormalCount = Symbol("_typeFormalCount");
22552255
dart.isSubtype = dart._subtypeMemo((t1, t2) => t1 === t2 || dart._isSubtype(t1, t2, true));
22562256
dart.hasOwnProperty = Object.prototype.hasOwnProperty;
2257-
_debugger.skipDartConfig = dart.const(new core.Object());
2257+
_debugger.JsonMLConfig = class JsonMLConfig extends core.Object {
2258+
new(name) {
2259+
this.name = name;
2260+
}
2261+
};
2262+
dart.setSignature(_debugger.JsonMLConfig, {
2263+
constructors: () => ({new: dart.definiteFunctionType(_debugger.JsonMLConfig, [core.String])})
2264+
});
2265+
dart.defineLazy(_debugger.JsonMLConfig, {
2266+
get none() {
2267+
return dart.const(new _debugger.JsonMLConfig("none"));
2268+
},
2269+
get skipDart() {
2270+
return dart.const(new _debugger.JsonMLConfig("skipDart"));
2271+
},
2272+
get keyToString() {
2273+
return dart.const(new _debugger.JsonMLConfig("keyToString"));
2274+
}
2275+
});
22582276
_debugger.maxIterableChildrenToDisplay = 50;
22592277
dart.defineLazy(_debugger, {
22602278
get _devtoolsFormatter() {
@@ -2337,10 +2355,10 @@ dart_library.library('dart_sdk', null, /* Imports */[
23372355
new(opts) {
23382356
let name = opts && 'name' in opts ? opts.name : null;
23392357
let value = opts && 'value' in opts ? opts.value : null;
2340-
let skipDart = opts && 'skipDart' in opts ? opts.skipDart : null;
2358+
let config = opts && 'config' in opts ? opts.config : _debugger.JsonMLConfig.none;
23412359
this.name = name;
23422360
this.value = value;
2343-
this.skipDart = skipDart == true;
2361+
this.config = config;
23442362
}
23452363
['=='](other) {
23462364
return _debugger.NameValuePair.is(other) && other.name == this.name;
@@ -2350,7 +2368,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
23502368
}
23512369
};
23522370
dart.setSignature(_debugger.NameValuePair, {
2353-
constructors: () => ({new: dart.definiteFunctionType(_debugger.NameValuePair, [], {name: core.String, value: core.Object, skipDart: core.bool})})
2371+
constructors: () => ({new: dart.definiteFunctionType(_debugger.NameValuePair, [], {name: core.String, value: core.Object, config: _debugger.JsonMLConfig})})
23542372
});
23552373
_debugger.MapEntry = class MapEntry extends core.Object {
23562374
new(opts) {
@@ -2361,7 +2379,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
23612379
}
23622380
};
23632381
dart.setSignature(_debugger.MapEntry, {
2364-
constructors: () => ({new: dart.definiteFunctionType(_debugger.MapEntry, [], {key: core.String, value: core.Object})})
2382+
constructors: () => ({new: dart.definiteFunctionType(_debugger.MapEntry, [], {key: core.Object, value: core.Object})})
23652383
});
23662384
_debugger.ClassMetadata = class ClassMetadata extends core.Object {
23672385
new(object) {
@@ -2448,11 +2466,14 @@ dart_library.library('dart_sdk', null, /* Imports */[
24482466
this[_simpleFormatter] = simpleFormatter;
24492467
}
24502468
header(object, config) {
2451-
if (core.identical(config, _debugger.skipDartConfig) || dart.test(_debugger.isNativeJavaScriptObject(object))) {
2469+
if (dart.equals(config, _debugger.JsonMLConfig.skipDart) || dart.test(_debugger.isNativeJavaScriptObject(object))) {
24522470
return null;
24532471
}
24542472
let c = this[_simpleFormatter].preview(object);
24552473
if (c == null) return null;
2474+
if (dart.equals(config, _debugger.JsonMLConfig.keyToString)) {
2475+
c = dart.toString(object);
2476+
}
24562477
let element = new _debugger.JsonMLElement('span');
24572478
element.setStyle('background-color: #d9edf7');
24582479
element.createTextChild(c);
@@ -2474,9 +2495,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
24742495
nameSpan.addStyle("padding-left: 13px;");
24752496
li.appendChild(nameSpan);
24762497
let objectTag = li.createObjectTag(child.value);
2477-
if (dart.test(child.skipDart)) {
2478-
objectTag.addAttribute('config', _debugger.skipDartConfig);
2479-
}
2498+
objectTag.addAttribute('config', child.config);
24802499
if (!dart.test(this[_simpleFormatter].hasChildren(child.value))) {
24812500
li.setStyle("padding-left: 13px;");
24822501
}
@@ -2653,7 +2672,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
26532672
return core.String._check(dart.typeName(dart.getReifiedType(object)));
26542673
}
26552674
children(object) {
2656-
return JSArrayOfNameValuePair().of([new _debugger.NameValuePair({name: 'signature', value: this.preview(object)}), new _debugger.NameValuePair({name: 'JavaScript Function', value: object, skipDart: true})]);
2675+
return JSArrayOfNameValuePair().of([new _debugger.NameValuePair({name: 'signature', value: this.preview(object)}), new _debugger.NameValuePair({name: 'JavaScript Function', value: object, config: _debugger.JsonMLConfig.skipDart})]);
26572676
}
26582677
};
26592678
dart.setSignature(_debugger.FunctionFormatter, {
@@ -2679,7 +2698,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
26792698
let map = core.Map._check(object);
26802699
let entries = LinkedHashSetOfNameValuePair().new();
26812700
map[dartx.forEach](dart.fn((key, value) => {
2682-
let entryWrapper = new _debugger.MapEntry({key: core.String._check(key), value: value});
2701+
let entryWrapper = new _debugger.MapEntry({key: key, value: value});
26832702
entries.add(new _debugger.NameValuePair({name: dart.toString(entries.length), value: entryWrapper}));
26842703
}, dynamicAnddynamicTovoid()));
26852704
this.addMetadataChildren(object, entries);
@@ -2747,9 +2766,9 @@ dart_library.library('dart_sdk', null, /* Imports */[
27472766
if (mixins != null && dart.test(dart.dload(mixins, 'isNotEmpty'))) {
27482767
ret[dartx.add](new _debugger.NameValuePair({name: '[[Mixins]]', value: new _debugger.HeritageClause('mixins', core.List._check(mixins))}));
27492768
}
2750-
ret[dartx.add](new _debugger.NameValuePair({name: '[[JavaScript View]]', value: entry.object, skipDart: true}));
2769+
ret[dartx.add](new _debugger.NameValuePair({name: '[[JavaScript View]]', value: entry.object, config: _debugger.JsonMLConfig.skipDart}));
27512770
if (!core.Type.is(entry.object)) {
2752-
ret[dartx.add](new _debugger.NameValuePair({name: '[[JavaScript Constructor]]', value: _debugger.JSNative.getProperty(entry.object, 'constructor'), skipDart: true}));
2771+
ret[dartx.add](new _debugger.NameValuePair({name: '[[JavaScript Constructor]]', value: _debugger.JSNative.getProperty(entry.object, 'constructor'), config: _debugger.JsonMLConfig.skipDart}));
27532772
}
27542773
return ret;
27552774
}
@@ -2776,7 +2795,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
27762795
return true;
27772796
}
27782797
children(object) {
2779-
return JSArrayOfNameValuePair().of([new _debugger.NameValuePair({name: 'key', value: dart.dload(object, 'key')}), new _debugger.NameValuePair({name: 'value', value: dart.dload(object, 'value')})]);
2798+
return JSArrayOfNameValuePair().of([new _debugger.NameValuePair({name: 'key', value: dart.dload(object, 'key'), config: _debugger.JsonMLConfig.keyToString}), new _debugger.NameValuePair({name: 'value', value: dart.dload(object, 'value')})]);
27802799
}
27812800
};
27822801
_debugger.MapEntryFormatter[dart.implements] = () => [_debugger.Formatter];

pkg/dev_compiler/tool/input_sdk/private/debugger.dart

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@ import 'dart:core';
1010
import 'dart:collection';
1111
import 'dart:html' as html;
1212

13-
/// Config object to pass to devtools to signal that an object should not be
14-
/// formatted by the Dart formatter. This is used to specify that an Object
13+
/// JsonMLConfig object to pass to devtools to specify how an Object should
14+
/// be displayed. skipDart signals that an object should not be formatted
15+
/// by the Dart formatter. This is used to specify that an Object
1516
/// should just be displayed using the regular JavaScript view instead of a
1617
/// custom Dart view. For example, this is used to display the JavaScript view
17-
/// of a Dart Function as a child of the regular Function object.
18-
const skipDartConfig = const Object();
18+
/// of a Dart Function as a child of the regular Function object. keyToString
19+
/// signals that a map key object should have its toString() displayed by
20+
/// the Dart formatter.
21+
///
22+
/// We'd like this to be an enum, but we can't because it's a dev_compiler bug.
23+
class JsonMLConfig {
24+
const JsonMLConfig(this.name);
25+
26+
final String name;
27+
static const none = const JsonMLConfig("none");
28+
static const skipDart = const JsonMLConfig("skipDart");
29+
static const keyToString = const JsonMLConfig("keyToString");
30+
}
31+
1932
final int maxIterableChildrenToDisplay = 50;
2033

2134
var _devtoolsFormatter = new JsonMLFormatter(new DartFormatter());
@@ -85,8 +98,7 @@ bool hasMethod(object, String name) {
8598

8699
/// [JsonMLFormatter] consumes [NameValuePair] objects and
87100
class NameValuePair {
88-
NameValuePair({this.name, this.value, bool skipDart})
89-
: skipDart = skipDart == true;
101+
NameValuePair({this.name, this.value, this.config: JsonMLConfig.none});
90102

91103
// Define equality and hashCode so that NameValuePair can be used
92104
// in a Set to dedupe entries with duplicate names.
@@ -95,13 +107,13 @@ class NameValuePair {
95107

96108
final String name;
97109
final Object value;
98-
final bool skipDart;
110+
final JsonMLConfig config;
99111
}
100112

101113
class MapEntry {
102114
MapEntry({this.key, this.value});
103115

104-
final String key;
116+
final Object key;
105117
final Object value;
106118
}
107119

@@ -193,13 +205,17 @@ class JsonMLFormatter {
193205
JsonMLFormatter(this._simpleFormatter);
194206

195207
header(object, config) {
196-
if (identical(config, skipDartConfig) || isNativeJavaScriptObject(object)) {
208+
if (config == JsonMLConfig.skipDart || isNativeJavaScriptObject(object)) {
197209
return null;
198210
}
199211

200212
var c = _simpleFormatter.preview(object);
201213
if (c == null) return null;
202214

215+
if (config == JsonMLConfig.keyToString) {
216+
c = object.toString();
217+
}
218+
203219
// Indicate this is a Dart Object by using a Dart background color.
204220
// This is stylistically a bit ugly but it eases distinguishing Dart and
205221
// JS objects.
@@ -230,9 +246,7 @@ class JsonMLFormatter {
230246

231247
li.appendChild(nameSpan);
232248
var objectTag = li.createObjectTag(child.value);
233-
if (child.skipDart) {
234-
objectTag.addAttribute('config', skipDartConfig);
235-
}
249+
objectTag.addAttribute('config', child.config);
236250
if (!_simpleFormatter.hasChildren(child.value)) {
237251
li.setStyle("padding-left: 13px;");
238252
}
@@ -426,7 +440,9 @@ class FunctionFormatter extends Formatter {
426440
List<NameValuePair> children(object) => <NameValuePair>[
427441
new NameValuePair(name: 'signature', value: preview(object)),
428442
new NameValuePair(
429-
name: 'JavaScript Function', value: object, skipDart: true)
443+
name: 'JavaScript Function',
444+
value: object,
445+
config: JsonMLConfig.skipDart)
430446
];
431447
}
432448

@@ -532,7 +548,9 @@ class ClassMetadataFormatter implements Formatter {
532548
name: '[[Mixins]]', value: new HeritageClause('mixins', mixins)));
533549
}
534550
ret.add(new NameValuePair(
535-
name: '[[JavaScript View]]', value: entry.object, skipDart: true));
551+
name: '[[JavaScript View]]',
552+
value: entry.object,
553+
config: JsonMLConfig.skipDart));
536554

537555
// TODO(jacobr): provide a link to the base class or perhaps the entire
538556
// base class hierarchy as a flat list.
@@ -541,7 +559,7 @@ class ClassMetadataFormatter implements Formatter {
541559
ret.add(new NameValuePair(
542560
name: '[[JavaScript Constructor]]',
543561
value: JSNative.getProperty(entry.object, 'constructor'),
544-
skipDart: true));
562+
config: JsonMLConfig.skipDart));
545563
// TODO(jacobr): add constructors, methods, extended class, and static
546564
}
547565
return ret;
@@ -561,7 +579,8 @@ class MapEntryFormatter implements Formatter {
561579
bool hasChildren(object) => true;
562580

563581
List<NameValuePair> children(object) => <NameValuePair>[
564-
new NameValuePair(name: 'key', value: object.key),
582+
new NameValuePair(
583+
name: 'key', value: object.key, config: JsonMLConfig.keyToString),
565584
new NameValuePair(name: 'value', value: object.value)
566585
];
567586
}

pkg/dev_compiler/tool/sdk_expected_errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
[error] The part was not supplied as an input to the compiler. (dart:html_common/filtered_element_list.dart, line 1, col 1)
3232
[error] The part was not supplied as an input to the compiler. (dart:html_common/lists.dart, line 1, col 1)
3333
[error] Invalid override. The type of JsArray.[]= ((Object, E) → void) is not a subtype of JsObject.[]= ((Object, dynamic) → dynamic). (dart:js, line 363, col 3)
34-
[warning] Unsound implicit cast from dynamic to List<String> (dart:_debugger, line 25, col 45)
34+
[warning] Unsound implicit cast from dynamic to List<String> (dart:_debugger, line 38, col 45)
3535
[warning] Unsound implicit cast from dynamic to List<String> (dart:_isolate_helper, line 839, col 37)
3636
[warning] Unsound implicit cast from dynamic to List<String> (dart:_isolate_helper, line 886, col 11)
3737
[warning] Unsound implicit cast from dynamic to E (dart:_interceptors/js_array.dart, line 117, col 12)

0 commit comments

Comments
 (0)