Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / trace_model / stack_frame.js
1 // Copyright (c) 2014 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.exportTo('tracing.trace_model', function() {
8   function StackFrame(parentFrame, id, category, title, colorId) {
9     if (id === undefined)
10       throw new Error('id must be given');
11     this.parentFrame_ = parentFrame;
12     this.id = id;
13     this.category = category || '';
14     this.title = title;
15     this.colorId = colorId;
16     this.children = [];
17
18     if (this.parentFrame_)
19       this.parentFrame_.addChild(this);
20   }
21
22   StackFrame.prototype = {
23     get parentFrame() {
24       return this.parentFrame_;
25     },
26
27     set parentFrame(parentFrame) {
28       if (this.parentFrame_)
29         this.parentFrame_.removeChild(this);
30       this.parentFrame_ = parentFrame;
31       if (this.parentFrame_)
32         this.parentFrame_.addChild(this);
33     },
34
35     addChild: function(child) {
36       this.children.push(child);
37     },
38
39     removeChild: function(child) {
40       var i = this.children.indexOf(child.id);
41       if (i == -1)
42         throw new Error('omg');
43       this.children.splice(i, 1);
44     },
45
46     removeAllChildren: function() {
47       for (var i = 0; i < this.children.length; i++)
48         this.children[i].parentFrame_ = undefined;
49       this.children.splice(0, this.children.length);
50     },
51
52     toJSON: function() {
53       return {};
54     }
55   };
56
57   return {
58     StackFrame: StackFrame
59   };
60 });