• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5const KB = 1024;
6const MB = KB * KB;
7const GB = MB * KB;
8const kMillis2Seconds = 1 / 1000;
9
10function formatBytes(bytes) {
11  const units = [' B', ' KB', ' MB', ' GB'];
12  const divisor = 1024;
13  let index = 0;
14  while (index < units.length && bytes >= divisor) {
15    index++;
16    bytes /= divisor;
17  }
18  return bytes.toFixed(2) + units[index];
19}
20
21function formatSeconds(millis) {
22  return (millis * kMillis2Seconds).toFixed(2) + 's';
23}
24
25function defineCustomElement(name, generator) {
26  let htmlTemplatePath = name + '-template.html';
27  fetch(htmlTemplatePath)
28    .then(stream => stream.text())
29    .then(templateText => customElements.define(name, generator(templateText)));
30}
31