OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 function TimelineModelDecorator() { | |
6 tracing.TimelineModel.apply(this, arguments); | |
7 } | |
8 | |
nduca
2012/07/20 07:13:13
I'm struggling with naming here. Decorator is not
| |
9 TimelineModelDecorator.prototype = { | |
10 __proto__: tracing.TimelineModel.prototype, | |
11 | |
12 invokeOnTimelineModel: function(methodName, args) { | |
nduca
2012/07/20 07:13:13
since you've made this a subclass of TimelineModel
| |
13 var sendToPython = function(obj) { | |
14 // We use sendJSON here because domAutomationController's send() chokes on | |
15 // large amounts of data. Inside of send() it converts the arg to JSON and | |
16 // invokes sendJSON. The JSON conversion is what fails. This way works | |
17 // around the bad code, but note that the recieving python converts from | |
18 // JSON before passing it back to the pyauto test. | |
19 window.domAutomationController.sendJSON( | |
20 JSON.stringify(obj) | |
21 ); | |
22 }; | |
23 var result; | |
24 try { | |
25 result = this[methodName].apply(this, JSON.parse(args)); | |
26 } catch( e ) { | |
27 var ret = { | |
28 success: false, | |
29 message: 'Unspecified error', | |
30 }; | |
31 // We'll try sending the entire exception. If that doesn't work, it's ok. | |
32 try { | |
33 ret.exception = JSON.stringify(e); | |
34 } catch(e2) {} | |
35 if( typeof(e) == 'string' || e instanceof String ) { | |
36 ret.message = e; | |
37 } else { | |
38 if( e.stack != undefined ) ret.stack = e.stack; | |
39 if( e.message != undefined ) ret.message = e.message; | |
40 } | |
41 sendToPython(ret); | |
42 throw e; | |
43 } | |
44 sendToPython({ | |
45 success: true, | |
46 data: result | |
47 }); | |
48 } | |
49 }, | |
50 | |
51 TimelineModelDecorator.recordTrace = function(callback) { | |
52 var handler = function() { | |
53 tracingController.removeEventListener('traceEnded', handler); | |
54 var model = new TimelineModelDecorator( | |
55 Array.prototype.slice.call(arguments, 1) | |
56 ); | |
57 var events = [tracingController.traceEvents_]; | |
58 if (tracingController.supportsSystemTracing) | |
59 events.push(tracingController.systemTraceEvents_); | |
60 model.importTraces(events); | |
61 callback(model); | |
62 }; | |
63 tracingController.addEventListener('traceEnded', handler); | |
64 } | |
65 | |
66 window.domAutomationController.send(''); | |
nduca
2012/07/20 07:13:13
Put a comment about what this does? It doesn't mak
| |
OLD | NEW |