A bit more Worker hardening.

This commit is contained in:
Nick Winter 2014-06-04 15:47:09 -06:00
parent f493f407c2
commit 0b2d5c251d
2 changed files with 8 additions and 7 deletions

View file

@ -1,2 +0,0 @@
self._noTransferable = true;
self.onmessage = function(e) { eval(e.data); };

View file

@ -60,11 +60,14 @@ self.console = console;
self.importScripts('/javascripts/world.js', '/javascripts/lodash.js', '/javascripts/aether.js');
// We could do way more from this: http://stackoverflow.com/questions/10653809/making-webworkers-a-safe-environment
Object.defineProperty(self, "XMLHttpRequest", {
get: function() { throw new Error("Access to XMLHttpRequest is forbidden."); },
configurable: false
});
var restricted = ["XMLHttpRequest", "importScripts", "Worker"];
for(var i = 0; i < restricted.length; ++i) {
// We could do way more from this: http://stackoverflow.com/questions/10653809/making-webworkers-a-safe-environment
Object.defineProperty(self, restricted[i], {
get: function() { throw new Error("Access to that global property is forbidden."); },
configurable: false
});
}
self.transferableSupported = function transferableSupported() {
if (typeof self._transferableSupported !== 'undefined') return self._transferableSupported;