2020-12-01 19:37:17 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2021-05-25 08:49:11 +00:00
|
|
|
import {SelectRelatedEvent} from './events.mjs';
|
|
|
|
import {CollapsableElement, DOM, formatBytes, formatMicroSeconds} from './helper.mjs';
|
2020-12-01 19:37:17 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
DOM.defineCustomElement('view/code-panel',
|
|
|
|
(templateText) =>
|
2021-05-03 12:50:10 +00:00
|
|
|
class CodePanel extends CollapsableElement {
|
2020-12-13 19:33:07 +00:00
|
|
|
_timeline;
|
|
|
|
_selectedEntries;
|
|
|
|
_entry;
|
2020-12-01 19:37:17 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
constructor() {
|
|
|
|
super(templateText);
|
|
|
|
this._codeSelectNode.onchange = this._handleSelectCode.bind(this);
|
2021-01-07 09:22:38 +00:00
|
|
|
this.$('#selectedRelatedButton').onclick =
|
|
|
|
this._handleSelectRelated.bind(this)
|
2020-12-13 19:33:07 +00:00
|
|
|
}
|
2020-12-01 19:37:17 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
set timeline(timeline) {
|
|
|
|
this._timeline = timeline;
|
|
|
|
this.$('.panel').style.display = timeline.isEmpty() ? 'none' : 'inherit';
|
2021-05-03 12:50:10 +00:00
|
|
|
this.requestUpdate();
|
2020-12-13 19:33:07 +00:00
|
|
|
}
|
2020-12-01 19:37:17 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
set selectedEntries(entries) {
|
|
|
|
this._selectedEntries = entries;
|
|
|
|
this.entry = entries.first();
|
|
|
|
}
|
2020-12-01 19:37:17 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
set entry(entry) {
|
|
|
|
this._entry = entry;
|
2021-05-03 12:50:10 +00:00
|
|
|
this.requestUpdate();
|
2020-12-13 19:33:07 +00:00
|
|
|
}
|
2020-12-01 19:37:17 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
get _disassemblyNode() {
|
|
|
|
return this.$('#disassembly');
|
|
|
|
}
|
2020-12-09 08:01:26 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
get _sourceNode() {
|
|
|
|
return this.$('#sourceCode');
|
|
|
|
}
|
2020-12-09 08:01:26 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
get _codeSelectNode() {
|
|
|
|
return this.$('#codeSelect');
|
|
|
|
}
|
2020-12-01 19:37:17 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
_update() {
|
2021-05-03 12:50:10 +00:00
|
|
|
this._updateSelect();
|
2021-05-25 08:49:11 +00:00
|
|
|
this._disassemblyNode.innerText = this._entry?.code ?? '';
|
2020-12-13 19:33:07 +00:00
|
|
|
this._sourceNode.innerText = this._entry?.source ?? '';
|
|
|
|
}
|
2020-12-09 08:01:26 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
_updateSelect() {
|
|
|
|
const select = this._codeSelectNode;
|
2021-05-03 12:50:10 +00:00
|
|
|
if (select.data === this._selectedEntries) return;
|
|
|
|
select.data = this._selectedEntries;
|
2020-12-13 19:33:07 +00:00
|
|
|
select.options.length = 0;
|
|
|
|
const sorted =
|
|
|
|
this._selectedEntries.slice().sort((a, b) => a.time - b.time);
|
|
|
|
for (const code of this._selectedEntries) {
|
|
|
|
const option = DOM.element('option');
|
|
|
|
option.text =
|
2021-06-15 08:55:33 +00:00
|
|
|
`${code.functionName}(...) t=${formatMicroSeconds(code.time)} size=${
|
2020-12-13 19:33:07 +00:00
|
|
|
formatBytes(code.size)} script=${code.script?.toString()}`;
|
|
|
|
option.data = code;
|
|
|
|
select.add(option);
|
|
|
|
}
|
|
|
|
}
|
2021-01-07 09:22:38 +00:00
|
|
|
|
2020-12-13 19:33:07 +00:00
|
|
|
_handleSelectCode() {
|
|
|
|
this.entry = this._codeSelectNode.selectedOptions[0].data;
|
|
|
|
}
|
2021-01-07 09:22:38 +00:00
|
|
|
|
|
|
|
_handleSelectRelated(e) {
|
|
|
|
if (!this._entry) return;
|
|
|
|
this.dispatchEvent(new SelectRelatedEvent(this._entry));
|
|
|
|
}
|
2020-12-13 19:33:07 +00:00
|
|
|
});
|