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