OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2014 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2014 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/base/base.html"> | 8 <link rel="import" href="/tracing/base/base.html"> |
9 | 9 |
10 <script> | 10 <script> |
11 'use strict'; | 11 'use strict'; |
12 | 12 |
13 tr.exportTo('tr.b', function() { | 13 tr.exportTo('tr.b', function() { |
14 /** | 14 /** |
15 * Adds a {@code getInstance} static method that always return the same | 15 * Adds a {@code getInstance} static method that always return the same |
16 * instance object. | 16 * instance object. |
17 * @param {!Function} ctor The constructor for the class to add the static | 17 * @param {!Function} ctor The constructor for the class to add the static |
18 * method to. | 18 * method to. |
19 */ | 19 */ |
20 function addSingletonGetter(ctor) { | 20 function addSingletonGetter(ctor) { |
21 ctor.getInstance = function() { | 21 ctor.getInstance = function() { |
22 return ctor.instance_ || (ctor.instance_ = new ctor()); | 22 return ctor.instance_ || (ctor.instance_ = new ctor()); |
23 }; | 23 }; |
24 } | 24 } |
25 | 25 |
26 function deepCopy(value) { | 26 function deepCopy(value) { |
27 if (!(value instanceof Object)) { | 27 if (!(value instanceof Object)) { |
28 if (value === undefined || value === null) | 28 if (value === undefined || value === null) return value; |
29 return value; | 29 if (typeof value === 'string') return value.substring(); |
30 if (typeof value === 'string') | 30 if (typeof value === 'boolean') return value; |
31 return value.substring(); | 31 if (typeof value === 'number') return value; |
32 if (typeof value === 'boolean') | |
33 return value; | |
34 if (typeof value === 'number') | |
35 return value; | |
36 throw new Error('Unrecognized: ' + typeof value); | 32 throw new Error('Unrecognized: ' + typeof value); |
37 } | 33 } |
38 | 34 |
39 var object = value; | 35 var object = value; |
40 if (object instanceof Array) { | 36 if (object instanceof Array) { |
41 var res = new Array(object.length); | 37 var res = new Array(object.length); |
42 for (var i = 0; i < object.length; i++) | 38 for (var i = 0; i < object.length; i++) { |
43 res[i] = deepCopy(object[i]); | 39 res[i] = deepCopy(object[i]); |
| 40 } |
44 return res; | 41 return res; |
45 } | 42 } |
46 | 43 |
47 if (object.__proto__ !== Object.prototype) | 44 if (object.__proto__ !== Object.prototype) { |
48 throw new Error('Can only clone simple types'); | 45 throw new Error('Can only clone simple types'); |
| 46 } |
49 var res = {}; | 47 var res = {}; |
50 for (var key in object) { | 48 for (var key in object) { |
51 res[key] = deepCopy(object[key]); | 49 res[key] = deepCopy(object[key]); |
52 } | 50 } |
53 return res; | 51 return res; |
54 } | 52 } |
55 | 53 |
56 function normalizeException(e) { | 54 function normalizeException(e) { |
57 if (e === undefined || e === null) { | 55 if (e === undefined || e === null) { |
58 return { | 56 return { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 formatDate, | 189 formatDate, |
192 numberToJson, | 190 numberToJson, |
193 numberFromJson, | 191 numberFromJson, |
194 | 192 |
195 getUsingPath, | 193 getUsingPath, |
196 | 194 |
197 runLengthEncoding, | 195 runLengthEncoding, |
198 }; | 196 }; |
199 }); | 197 }); |
200 </script> | 198 </script> |
OLD | NEW |