diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 3 | ||||
-rw-r--r-- | src/proxyWorker.js | 53 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 3d8059b1..a3b26aa9 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1843,6 +1843,9 @@ function JSify(data, functionsOnly, givenFunctions) { print(read('headless.js').replace("'%s'", "'http://emscripten.org'").replace("'?%s'", "''").replace("'?%s'", "'/'").replace('%s,', 'null,').replace('%d', '0')); print('}'); } + if (PROXY_TO_WORKER) { + print(read('proxyWorker.js')); + } if (RUNTIME_TYPE_INFO) { Types.cleanForRuntime(); print('Runtime.typeInfo = ' + JSON.stringify(Types.types)); diff --git a/src/proxyWorker.js b/src/proxyWorker.js new file mode 100644 index 00000000..2798b3d0 --- /dev/null +++ b/src/proxyWorker.js @@ -0,0 +1,53 @@ + +function EventListener() { + this.listeners = {}; + + this.addEventListener = function(event, func) { + if (!this.listeners[event]) this.listeners[event] = []; + this.listeners[event].push(func); + }; +}; + +var window = new EventListener(); +var document = new EventListener(); + +document.createElement = function(what) { + switch(what) { + case 'canvas': { + var canvas = new EventListener(); + canvas.ensureData = function() { + if (!canvas.data || canvas.data.width !== canvas.width || canvas.data.height !== canvas.height) { + canvas.data = { + width: canvas.width, + height: canvas.height, + buffer: new Uint8Array(canvas.width*canvas.height*4) + }; + } + }; + canvas.getContext = function(type) { + assert(type == '2d'); + return { + getImageData: function(x, y, w, h) { + assert(x == 0 && y == 0 && w == canvas.width && h == canvas.height); + canvas.ensureData(); + return { + width: canvas.data.width, + height: canvas.data.height, + data: new Uint8Array(canvas.data.buffer) // TODO: can we avoid this copy? + }; + }, + putImageData: function(image, x, y) { + canvas.ensureData(); + assert(x == 0 && y == 0 && image.width == canvas.width && image.height == canvas.height); + canvas.data.buffer.set(image.data); // TODO: can we avoid this copy? + } + }; + }; + return canvas; + } + default: throw 'document.createElement ' + what; + } +}; + +Module.canvas = document.createElement('canvas'); + |