<commit_before><!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/base/math/rect.html">
<link rel="import" href="/tracing/base/scalar.html">
<link rel="import" href="/tracing/base/utils.html">
<link rel="import" href="/tracing/model/event_set.html">
<link rel="import" href="/tracing/model/object_instance.html">
<link rel="import" href="/tracing/model/object_snapshot.html">
<link rel="import" href="/tracing/ui/analysis/analysis_link.html">
<link rel="import" href="/tracing/ui/base/table.html">
<link rel="import" href="/tracing/ui/base/ui.html">
<link rel="import" href="/tracing/value/ui/scalar_span.html">

<dom-module id='tr-ui-a-generic-object-view'>
  <template>
    <style>
    :host {
      display: block;
      font-family: monospace;
    }
    </style>
    <div id="content">
    </div>
  </template>
</dom-module>
<script>
'use strict';

function isTable(object) {
  if (!(object instanceof Array) ||
      (object.length < 2)) return false;
  for (const colName in object[0]) {
    if (typeof colName !== 'string') return false;
  }
  for (let i = 0; i < object.length; ++i) {
    if (!(object[i] instanceof Object)) return false;
    for (const colName in object[i]) {
      if (i && (object[0][colName] === undefined)) return false;
      const cellType = typeof object[i][colName];
      if (cellType !== 'string' && cellType !== 'number') return false;
    }
    if (i) {
      for (const colName in object[0]) {
        if (object[i][colName] === undefined) return false;
      }
    }
  }
  return true;
}

Polymer({
  is: 'tr-ui-a-generic-object-view',

  ready() {
    this.object_ = undefined;
  },

  get object() {
    return this.object_;
  },

  set object(object) {
    this.object_ = object;
    this.updateContents_();
  },

  updateContents_() {
    Polymer.dom(this.$.content).textContent = '';
    this.appendElementsForType_('', this.object_, 0, 0, 5, '');
  },

  appendElementsForType_(
      label, object, indent, depth, maxDepth, suffix) {
    if (depth > maxDepth) {
      this.appendSimpleText_(
          label, indent, '<recursion limit reached>', suffix);
      return;
    }

    if (object === undefined) {
      this.appendSimpleText_(label, indent, 'undefined', suffix);
      return;
    }

    if (object === null) {
      this.appendSimpleText_(label, indent, 'null', suffix);
      return;
    }

    if (!(object instanceof Object)) {
      const type = typeof object;
      if (type !== 'string') {
        return this.appendSimpleText_(label, indent, object, suffix);
      }
      let objectReplaced = false;
      if ((object[0] === '{' && object[object.length - 1] === '}') ||
          (object[0] === '[' && object[object.length - 1] === ']')) {
        try {
          object = JSON.parse(object);
          objectReplaced = true;
        } catch (e) {
        }
      }
      if (!objectReplaced) {
        if (object.includes('\n')) {
          const lines = object.split('\n');
          lines.forEach(function(line, i) {
            let text;<commit_msg>[trace-viewer] Fix displaying args when value is 0.<commit_after><!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/base/math/rect.html">
<link rel="import" href="/tracing/base/scalar.html">
<link rel="import" href="/tracing/base/utils.html">
<link rel="import" href="/tracing/model/event_set.html">
<link rel="import" href="/tracing/model/object_instance.html">
<link rel="import" href="/tracing/model/object_snapshot.html">
<link rel="import" href="/tracing/ui/analysis/analysis_link.html">
<link rel="import" href="/tracing/ui/base/table.html">
<link rel="import" href="/tracing/ui/base/ui.html">
<link rel="import" href="/tracing/value/ui/scalar_span.html">

<dom-module id='tr-ui-a-generic-object-view'>
  <template>
    <style>
    :host {
      display: block;
      font-family: monospace;
    }
    </style>
    <div id="content">
    </div>
  </template>
</dom-module>
<script>
'use strict';

function isTable(object) {
  if (!(object instanceof Array) ||
      (object.length < 2)) return false;
  for (const colName in object[0]) {
    if (typeof colName !== 'string') return false;
  }
  for (let i = 0; i < object.length; ++i) {
    if (!(object[i] instanceof Object)) return false;
    for (const colName in object[i]) {
      if (i && (object[0][colName] === undefined)) return false;
      const cellType = typeof object[i][colName];
      if (cellType !== 'string' && cellType !== 'number') return false;
    }
    if (i) {
      for (const colName in object[0]) {
        if (object[i][colName] === undefined) return false;
      }
    }
  }
  return true;
}

Polymer({
  is: 'tr-ui-a-generic-object-view',

  ready() {
    this.object_ = undefined;
  },

  get object() {
    return this.object_;
  },

  set object(object) {
    this.object_ = object;
    this.updateContents_();
  },

  updateContents_() {
    Polymer.dom(this.$.content).textContent = '';
    this.appendElementsForType_('', this.object_, 0, 0, 5, '');
  },

  appendElementsForType_(
      label, object, indent, depth, maxDepth, suffix) {
    if (depth > maxDepth) {
      this.appendSimpleText_(
          label, indent, '<recursion limit reached>', suffix);
      return;
    }

    if (object === undefined) {
      this.appendSimpleText_(label, indent, 'undefined', suffix);
      return;
    }

    if (object === null) {
      this.appendSimpleText_(label, indent, 'null', suffix);
      return;
    }

    if (!(object instanceof Object)) {
      const type = typeof object;
      if (type !== 'string') {
        return this.appendSimpleText_(label, indent, String(object), suffix);
      }
      let objectReplaced = false;
      if ((object[0] === '{' && object[object.length - 1] === '}') ||
          (object[0] === '[' && object[object.length - 1] === ']')) {
        try {
          object = JSON.parse(object);
          objectReplaced = true;
        } catch (e) {
        }
      }
      if (!objectReplaced) {
        if (object.includes('\n')) {
          const lines = object.split('\n');
          lines.forEach(function(line, i) {
            let text;
{'fraction_non_alphanumeric': 0.1706102117061021, 'fraction_numerical': 0.005136986301369863, 'mean_word_length': 2.8704819277108435, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3134159', 'n_tokens_mistral': 2097, 'n_tokens_neox': 2044, 'n_words': 502}