Skip to content

Commit aa07477

Browse files
committed
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core into gh-pages
2 parents 4caf406 + 979404d commit aa07477

38 files changed

+949
-283
lines changed

demos/tom/Sections.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ export class TraceSection {
6464
}
6565
}
6666

67+
export class PluginSection extends TraceSection {
68+
constructor(name, nodeID, entries = []) {
69+
super(name, entries);
70+
71+
this.nodeID = nodeID;
72+
}
73+
}
74+
6775
export class FunctionSection extends TraceSection {
6876
constructor() {
6977
super(...arguments);

demos/tom/TraceLogParser.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, eventTypes } from 'demos/tom/Events.js';
2-
import { FunctionSection, TraceSection } from 'demos/tom/Sections.js';
2+
import { FunctionSection, PluginSection, TraceSection } from 'demos/tom/Sections.js';
33

44
class EarlyReturn {
55
constructor(type) {
@@ -18,7 +18,7 @@ export default class TraceLogParser {
1818
return this.trace._log;
1919
}
2020

21-
/* Parsing primitives */
21+
/*MD ## Parsing primitives MD*/
2222

2323
peek() {
2424
if(this.index < this.log.length) {
@@ -59,7 +59,7 @@ export default class TraceLogParser {
5959
return object.isEarlyReturn && object.type === type;
6060
}
6161

62-
/* Parse methods */
62+
/*MD ## Parse methods MD*/
6363

6464
instantiateEvent(entry) {
6565
const eventClass = eventTypes[entry.__type__];
@@ -128,7 +128,8 @@ export default class TraceLogParser {
128128

129129
parseTraversePlugin(section, higherSections) {
130130
const entry = this.consume();
131-
const plugin = new TraceSection('TraversePlugin:' + entry.data);
131+
const plugin = new PluginSection('TraversePlugin:' + entry.data[0], entry.data[1]);
132+
plugin.position = this.peek().position;
132133

133134
section.addEntry(plugin);
134135

@@ -179,7 +180,7 @@ export default class TraceLogParser {
179180
}
180181

181182
parsePlugin(sections) {
182-
const plugin = new TraceSection(this.consume().data);
183+
const plugin = new PluginSection(...this.consume().data);
183184
sections.push(plugin);
184185
this.defaultParse(plugin, []);
185186
return plugin;

demos/tom/babel-plugin-tracer.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Trace from 'demos/tom/trace.js';
22
import wrapAST from 'demos/tom/wrapAST.js';
33

4+
'hello world'
5+
46
let pluginDefinedTrace = false;
57

68
export default function({ types: t }) {
@@ -37,9 +39,7 @@ export default function({ types: t }) {
3739

3840
function modifyFunction(name, path, state) {
3941
const body = path.get('body');
40-
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t
41-
.stringLiteral(name)
42-
])));
42+
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t.stringLiteral(name)])));
4343
body.pushContainer('body', t.expressionStatement(callOnTrace('leave', [location(path.node, state)])));
4444
path.traverse(returnVisitor, state);
4545
}
@@ -101,6 +101,8 @@ export default function({ types: t }) {
101101
name = t.stringLiteral(callee.node.name || 'anonymous function');
102102
}
103103

104+
105+
104106
const loc = location(callee.node, this);
105107

106108
const aboutToEnter = callOnTrace('aboutToEnter',

demos/tom/plugin-backup.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ export default function({ types: t }) {
3737

3838
function modifyFunction(name, path, state) {
3939
const body = path.get('body');
40-
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t
41-
.stringLiteral(name)
42-
])));
40+
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t.stringLiteral(name)])));
4341
body.pushContainer('body', t.expressionStatement(callOnTrace('leave', [location(path.node, state)])));
4442
path.traverse(returnVisitor, state);
4543
}
@@ -88,7 +86,6 @@ export default function({ types: t }) {
8886
path.node.alreadyVisited = true;
8987
let callee = path.get('callee');
9088
let name;
91-
debugger
9289

9390
if (t.isMemberExpression(callee)) {
9491
if(callee.node.computed) {

demos/tom/plugin-explorer-worker.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,36 @@ function decorateNodePathTraverse(plugin, trace) {
7676
for (const name in visitors) {
7777
if (typeof visitors[name] === 'function') {
7878
const fn = visitors[name];
79-
newVisitors[name] = function() {
80-
trace.startTraversePlugin(name);
81-
fn(...arguments);
79+
newVisitors[name] = function(path, ...rest) {
80+
trace.startTraversePlugin(name, path.node.traceID);
81+
fn(path, ...rest);
8282
trace.endTraversePlugin(name);
8383
};
8484
} else if (typeof visitors[name] === 'object') {
85-
debugger
85+
const obj = visitors[name];
86+
87+
// Todo: what is if already decorated
88+
if(obj.enter) {
89+
obj.enter = obj.enter.map(fn => function(path, ...rest) {
90+
trace.startTraversePlugin(name, path.node.traceID);
91+
fn(path, ...rest);
92+
trace.endTraversePlugin(name);
93+
})
94+
}
95+
96+
if(obj.exit) {
97+
obj.exit = obj.exit.map(fn => function(path, ...rest) {
98+
trace.startTraversePlugin(name, path.node.traceID);
99+
fn(path, ...rest);
100+
trace.endTraversePlugin(name);
101+
})
102+
}
103+
104+
newVisitors[name] = obj;
86105
}
87106

88107
}
89108

90-
visitors = newVisitors;
91109
oldTraverse.call(this, newVisitors, ...rest);
92110

93111
}
@@ -116,8 +134,8 @@ async function importPlugin(url) {
116134
return modifiedPlugin;
117135
}
118136

119-
function importPlugins(urls) {
120-
return Promise.all(urls.map(url => importPlugin(url)))
137+
function importPlugins(pluginData) {
138+
return Promise.all(pluginData.map(({url, data}) => importPlugin(url)))
121139
.then(plugins => {
122140
let counter = 0;
123141
for (const plugin of plugins) {
@@ -162,16 +180,16 @@ self.onmessage = function(msg) {
162180
return trace.createTraceID();
163181
}
164182

165-
importPlugins(msg.data.urls)
183+
importPlugins(msg.data.pluginData)
166184
.then(function(modules) {
167185
config.plugins = modules;
168186
config.sourceFileName = 'tmpfile.js';
169187
config.sourceMaps = true;
170188

171189
config.wrapPluginVisitorMethod = (pluginAlias, visitorType, callback) => {
172-
return (...args) => {
173-
trace.enterPlugin(pluginAlias);
174-
callback(...args);
190+
return (path, ...rest) => {
191+
trace.enterPlugin(pluginAlias, path.node.traceID);
192+
callback(path, ...rest);
175193
trace.leavePlugin(pluginAlias);
176194
}
177195
};

demos/tom/plugin-load-promise.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function(source, urls) {
1+
export default function(source, pluginData) {
22
return new Promise((resolve, reject) => {
33
const worker = new Worker('demos/tom/plugin-explorer-worker.js')
44
worker.onmessage = function(msg) {
@@ -9,6 +9,6 @@ export default function(source, urls) {
99
reject(msg);
1010
worker.terminate();
1111
}
12-
worker.postMessage({source, urls})
12+
worker.postMessage({source, pluginData})
1313
})
1414
}

demos/tom/trace.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export default class Trace {
6767
return trace;
6868
}
6969

70-
static async on(source, pluginsUrls) {
71-
const data = await loadPlugin(source, pluginsUrls);
70+
static async on(source, pluginData) {
71+
const data = await loadPlugin(source, pluginData);
7272
const obj = {
7373
locations: data.locations,
7474
oldAST: JSON.parse(data.oldAST),
@@ -140,17 +140,17 @@ export default class Trace {
140140

141141
/*MD ## Plugins MD*/
142142

143-
enterPlugin(name) {
144-
this.log(new Event('enterPlugin', name));
143+
enterPlugin(name, traceID) {
144+
this.log(new Event('enterPlugin', [name, traceID]));
145145
this.pluginRound++;
146146
}
147147

148148
leavePlugin(name) {
149149
this.log(new Event('leavePlugin', name));
150150
}
151151

152-
startTraversePlugin(name) {
153-
this.log(new Event('enterTraversePlugin', name));
152+
startTraversePlugin(name, traceID) {
153+
this.log(new Event('enterTraversePlugin', [name, traceID]));
154154
}
155155

156156
endTraversePlugin(name) {

src/client/files.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,14 @@ export default class Files {
261261
}).then(resp => resp.status == 200);
262262
}
263263

264-
var resp = (await fetch(urlString, {method: "OPTIONS"}))
265-
if (resp.status != 200) return false
266-
var stats = await resp.json()
267-
return stats.error ? false : true
264+
try {
265+
var resp = (await fetch(urlString, {method: "OPTIONS"}))
266+
if (resp.status != 200) return false
267+
var stats = await resp.json()
268+
return stats.error ? false : true
269+
} catch (e) {
270+
return false;
271+
}
268272
}
269273

270274

0 commit comments

Comments
 (0)