• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2013 The Chromium 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
5'use strict';
6
7base.exportTo('tracing.trace_model', function() {
8  /**
9   * A snapshot of an object instance, at a given moment in time.
10   *
11   * Initialization of snapshots and instances is three phased:
12   *
13   * 1. Instances and snapshots are constructed. This happens during event
14   *    importing. Little should be done here, because the object's data
15   *    are still being used by the importer to reconstruct object references.
16   *
17   * 2. Instances and snapshtos are preinitialized. This happens after implicit
18   *    objects have been found, but before any references have been found and
19   *    switched to direct references. Thus, every snapshot stands on its own.
20   *    This is a good time to do global field renaming and type conversion,
21   *    e.g. recognizing domain-specific types and converting from C++ naming
22   *    convention to JS.
23   *
24   * 3. Instances and snapshtos are initialized. At this point, {id_ref:
25   *    '0x1000'} fields have been converted to snapshot references. This is a
26   *    good time to generic initialization steps and argument verification.
27   *
28   * @constructor
29   */
30  function ObjectSnapshot(objectInstance, ts, args) {
31    this.objectInstance = objectInstance;
32    this.ts = ts;
33    this.args = args;
34    this.selected = false;
35  }
36
37  ObjectSnapshot.prototype = {
38    __proto__: Object.prototype,
39
40    /**
41     * See ObjectSnapshot constructor notes on object initialization.
42     */
43    preInitialize: function() {
44    },
45
46    /**
47     * See ObjectSnapshot constructor notes on object initialization.
48     */
49    initialize: function() {
50    }
51  };
52
53  ObjectSnapshot.nameToConstructorMap_ = {};
54  ObjectSnapshot.register = function(name, constructor) {
55    if (ObjectSnapshot.nameToConstructorMap_[name])
56      throw new Error('Constructor already registerd for ' + name);
57    ObjectSnapshot.nameToConstructorMap_[name] = constructor;
58  };
59
60  ObjectSnapshot.unregister = function(name) {
61    delete ObjectSnapshot.nameToConstructorMap_[name];
62  };
63
64  ObjectSnapshot.getConstructor = function(name) {
65    if (ObjectSnapshot.nameToConstructorMap_[name])
66      return ObjectSnapshot.nameToConstructorMap_[name];
67    return ObjectSnapshot;
68  };
69
70  return {
71    ObjectSnapshot: ObjectSnapshot
72  };
73});
74