1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-29 14:51:17 +00:00

worker handleMessage()

This commit is contained in:
Steven Hugg 2018-03-02 20:16:25 -06:00
parent 4b68296bab
commit 7fd94e4a98

View File

@ -1301,22 +1301,32 @@ var TOOL_PRELOADFS = {
'sdcc': 'sdcc', 'sdcc': 'sdcc',
} }
onmessage = function(e) { function handleMessage(data) {
// (preload) if (data.preload) {
if (e.data.preload) { var fs = TOOL_PRELOADFS[data.preload];
var fs = TOOL_PRELOADFS[e.data.preload];
if (fs && !fsMeta[fs]) loadFilesystem(fs); if (fs && !fsMeta[fs]) loadFilesystem(fs);
return; return;
} }
// (code,platform,tool) // (code,platform,tool)
var code = e.data.code; var code = data.code;
var platform = e.data.platform; var platform = data.platform;
var toolfn = TOOLS[e.data.tool]; var toolfn = TOOLS[data.tool];
if (!toolfn) throw "no tool named " + e.data.tool; if (!toolfn) throw "no tool named " + data.tool;
var dependencies = e.data.dependencies; var dependencies = data.dependencies;
var result = toolfn(code, platform, e.data); var result = toolfn(code, platform, data);
result.params = PLATFORM_PARAMS[platform]; result.params = PLATFORM_PARAMS[platform];
if (result) { return result;
postMessage(result); }
var ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof require === 'function';
var ENVIRONMENT_IS_WEB = typeof window === 'object';
var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
if (ENVIRONMENT_IS_WORKER) {
onmessage = function(e) {
var result = handleMessage(e.data);
if (result) {
postMessage(result);
}
} }
} }