2014-04-18 17:59:08 -04:00
|
|
|
var window = self;
|
|
|
|
var Global = self;
|
|
|
|
|
2014-05-09 18:22:23 -04:00
|
|
|
importScripts("/javascripts/lodash.js", "/javascripts/aether.js");
|
2014-08-21 19:27:52 -04:00
|
|
|
//console.log("Aether Tome worker has finished importing scripts.");
|
2014-04-18 17:59:08 -04:00
|
|
|
var aethers = {};
|
|
|
|
|
|
|
|
var createAether = function (spellKey, options)
|
|
|
|
{
|
|
|
|
aethers[spellKey] = new Aether(options);
|
|
|
|
return JSON.stringify({
|
|
|
|
"message": "Created aether for " + spellKey,
|
|
|
|
"function": "createAether"
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var hasChangedSignificantly = function(spellKey, a,b,careAboutLineNumbers,careAboutLint) {
|
|
|
|
|
|
|
|
var hasChanged = aethers[spellKey].hasChangedSignificantly(a,b,careAboutLineNumbers,careAboutLint);
|
|
|
|
var functionName = "hasChangedSignificantly";
|
|
|
|
var returnObject = {
|
|
|
|
"function":functionName,
|
2014-04-22 14:04:56 -04:00
|
|
|
"hasChanged": hasChanged,
|
|
|
|
"spellKey": spellKey
|
2014-04-18 17:59:08 -04:00
|
|
|
};
|
|
|
|
return JSON.stringify(returnObject);
|
|
|
|
};
|
|
|
|
|
|
|
|
var updateLanguageAether = function(newLanguage)
|
|
|
|
{
|
|
|
|
for (var spellKey in aethers)
|
|
|
|
{
|
|
|
|
if (aethers.hasOwnProperty(spellKey))
|
|
|
|
{
|
|
|
|
aethers[spellKey].setLanguage(newLanguage);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var lint = function(spellKey, source)
|
|
|
|
{
|
2014-04-22 14:46:17 -04:00
|
|
|
var currentAether = aethers[spellKey];
|
2014-04-18 17:59:08 -04:00
|
|
|
var lintMessages = currentAether.lint(source);
|
|
|
|
var functionName = "lint";
|
|
|
|
var returnObject = {
|
|
|
|
"lintMessages": lintMessages,
|
|
|
|
"function": functionName
|
|
|
|
};
|
|
|
|
return JSON.stringify(returnObject);
|
|
|
|
};
|
2014-04-22 14:46:17 -04:00
|
|
|
|
|
|
|
var transpile = function(spellKey, source)
|
|
|
|
{
|
|
|
|
var currentAether = aethers[spellKey];
|
|
|
|
currentAether.transpile(source);
|
|
|
|
var functionName = "transpile";
|
|
|
|
var returnObject = {
|
|
|
|
"problems": currentAether.problems,
|
|
|
|
"function": functionName,
|
|
|
|
"spellKey": spellKey
|
|
|
|
};
|
|
|
|
return JSON.stringify(returnObject);
|
|
|
|
};
|
2014-04-18 17:59:08 -04:00
|
|
|
self.addEventListener('message', function(e) {
|
|
|
|
var data = JSON.parse(e.data);
|
|
|
|
if (data.function == "createAether")
|
|
|
|
{
|
|
|
|
self.postMessage(createAether(data.spellKey, data.options));
|
|
|
|
}
|
|
|
|
else if (data.function == "updateLanguageAether")
|
|
|
|
{
|
|
|
|
updateLanguageAether(data.newLanguage)
|
|
|
|
}
|
|
|
|
else if (data.function == "hasChangedSignificantly")
|
|
|
|
{
|
|
|
|
self.postMessage(hasChangedSignificantly(
|
|
|
|
data.spellKey,
|
|
|
|
data.a,
|
|
|
|
data.b,
|
|
|
|
data.careAboutLineNumbers,
|
|
|
|
data.careAboutLint
|
|
|
|
));
|
|
|
|
}
|
|
|
|
else if (data.function == "lint")
|
|
|
|
{
|
|
|
|
self.postMessage(lint(data.spellKey, data.source));
|
|
|
|
}
|
2014-04-22 14:46:17 -04:00
|
|
|
else if (data.function == "transpile")
|
|
|
|
{
|
|
|
|
self.postMessage(transpile(data.spellKey, data.source));
|
|
|
|
}
|
2014-04-18 17:59:08 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
var message = "Didn't execute any function...";
|
|
|
|
var returnObject = {"message":message, "function":"none"};
|
|
|
|
self.postMessage(JSON.stringify(returnObject));
|
|
|
|
}
|
2014-05-02 15:32:41 -04:00
|
|
|
}, false);
|