var assert = require('assert'); var fs = require('fs'); var vm = require('vm'); var worker = {}; global.window = global; global.exports = {}; global.self = global; global.location = {href:'.'}; global.require = (modname) => { console.log("REQUIRE",modname); if (modname == 'path') return require(modname); }; global.btoa = require('btoa'); global.atob = require('atob'); global.includeInThisContext = function(path) { var code = fs.readFileSync(path); vm.runInThisContext(code, path); }; global.importScripts = function(path) { includeInThisContext('gen/worker/'+path); } function Blob(blob) { this.size = blob.length; this.length = blob.length; this.slice = function(a,b) { var data = blob.slice(a,b); var b = new Blob(data); //console.log(a, b, data.length, data.slice(0,64)); //console.log(new Error().stack); return b; } this.arrayBuffer = this.asArrayBuffer = function() { var buf = new ArrayBuffer(blob.length); var arr = new Uint8Array(buf); for (var i=0; i { try { var bin = fs.readFileSync(path, {encoding:'binary'}); var response = new Blob(bin); resolve(response); } catch (e) { reject(e); } }); }