-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.js
76 lines (59 loc) · 2.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
var fs = require('fs');
var vm = require('vm');
/* eslint-disable no-native-reassign */
if (typeof __dirname === 'undefined') {
__dirname = '';
}
/* eslint-enable no-native-reassign */
class ModelAPI {
constructor(events) {
// Everything happens in a sandboxed vm context, to keep globals and natives separate.
// First, sandboxed contexts don't have any globals from node, so we whitelist a few we'll provide for it.
var glob = {require: require, global: global, console: console, __dirname: __dirname};
// We read in our script to run, and create a vm.Script object
/* eslint-disable no-path-concat */
var script = new vm.Script(fs.readFileSync(__dirname + '/lib/timeline-model.js', 'utf8'));
/* eslint-enable no-path-concat */
// We create a new V8 context with our globals
var ctx = vm.createContext(glob);
// We evaluate the `vm.Script` in the new context
script.runInContext(ctx);
// We pull the local `instance` variable out, to use as our proxy object
this.sandbox = ctx.sandboxedModel;
this.sandbox.init(events);
return this;
}
timelineModel() {
return this.sandbox.timelineModel();
}
tracingModel() {
return this.sandbox.tracingModel();
}
topDown(startTime = 0, endTime = Infinity) {
return this.sandbox.topDown(startTime, endTime);
}
topDownGroupBy(grouping, startTime = 0, endTime = Infinity) {
return this.sandbox.topDownGroupBy(grouping, startTime, endTime);
}
bottomUp(startTime = 0, endTime = Infinity) {
return this.sandbox.bottomUp(startTime, endTime);
}
/**
* @ param {!String} grouping Allowed values: None Category Subdomain Domain URL Name
* @ return {!WebInspector.TimelineProfileTree.Node} A grouped and sorted tree
*/
bottomUpGroupBy(grouping, startTime = 0, endTime = Infinity) {
return this.sandbox.bottomUpGroupBy(grouping, startTime, endTime);
}
frameModel() {
return this.sandbox.frameModel();
}
filmStripModel() {
return this.sandbox.filmStripModel();
}
interactionModel() {
return this.sandbox.interactionModel();
}
}
module.exports = ModelAPI;