aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library_fs.js16
-rw-r--r--src/proxyWorker.js69
-rw-r--r--src/webGLWorker.js14
3 files changed, 71 insertions, 28 deletions
diff --git a/src/library_fs.js b/src/library_fs.js
index a6bca77c..7932385e 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -1211,8 +1211,20 @@ mergeInto(LibraryManager.library, {
FS.mkdev('/dev/tty', FS.makedev(5, 0));
FS.mkdev('/dev/tty1', FS.makedev(6, 0));
// setup /dev/[u]random
- FS.createDevice('/dev', 'random', function() { return Math.floor(Math.random()*256); });
- FS.createDevice('/dev', 'urandom', function() { return Math.floor(Math.random()*256); });
+ var random_device;
+ if (typeof crypto !== 'undefined') {
+ // for modern web browsers
+ var randomBuffer = new Uint8Array(1);
+ random_device = function() { crypto.getRandomValues(randomBuffer); return randomBuffer[0]; };
+ } else if (ENVIRONMENT_IS_NODE) {
+ // for nodejs
+ random_device = function() { return require('crypto').randomBytes(1)[0]; };
+ } else {
+ // default for ES5 platforms
+ random_device = function() { return Math.floor(Math.random()*256); };
+ }
+ FS.createDevice('/dev', 'random', random_device);
+ FS.createDevice('/dev', 'urandom', random_device);
// we're not going to emulate the actual shm device,
// just create the tmp dirs that reside in it commonly
FS.mkdir('/dev/shm');
diff --git a/src/proxyWorker.js b/src/proxyWorker.js
index a0ab4fe3..032568b0 100644
--- a/src/proxyWorker.js
+++ b/src/proxyWorker.js
@@ -1,3 +1,37 @@
+
+if (typeof console === 'undefined') {
+ // we can't call Module.printErr because that might be circular
+ var console = {
+ log: function(x) {
+ if (typeof dump === 'function') dump('log: ' + x + '\n');
+ },
+ debug: function(x) {
+ if (typeof dump === 'function') dump('debug: ' + x + '\n');
+ },
+ info: function(x) {
+ if (typeof dump === 'function') dump('info: ' + x + '\n');
+ },
+ warn: function(x) {
+ if (typeof dump === 'function') dump('warn: ' + x + '\n');
+ },
+ error: function(x) {
+ if (typeof dump === 'function') dump('error: ' + x + '\n');
+ },
+ };
+}
+
+/*
+function proxify(object, nick) {
+ return new Proxy(object, {
+ get: function(target, name) {
+ var ret = target[name];
+ if (ret === undefined) console.log('PROXY ' + [nick, target, name, ret, typeof ret]);
+ return ret;
+ }
+ });
+}
+*/
+
function FPSTracker(text) {
var last = 0;
var mean = 0;
@@ -18,7 +52,6 @@ function FPSTracker(text) {
function Element() { throw 'TODO: Element' }
function HTMLCanvasElement() { throw 'TODO: HTMLCanvasElement' }
-function HTMLImageElement() { throw 'TODO: HTMLImageElement' }
function HTMLVideoElement() { throw 'TODO: HTMLVideoElement' }
function PropertyBag() {
@@ -64,6 +97,7 @@ function EventListener() {
function Image() {
IndexedObjects.add(this);
+ EventListener.call(this);
var src = '';
Object.defineProperty(this, 'src', {
set: function(value) {
@@ -76,10 +110,11 @@ function Image() {
}
});
}
-Image.prototype = new EventListener();
Image.prototype.onload = function(){};
Image.prototype.onerror = function(){};
+var HTMLImageElement = Image;
+
var window = this;
var windowExtra = new EventListener();
for (var x in windowExtra) window[x] = windowExtra[x];
@@ -88,6 +123,11 @@ window.close = function window_close() {
postMessage({ target: 'window', method: 'close' });
};
+window.alert = function(text) {
+ Module.printErr('alert forever: ' + text);
+ while (1){};
+};
+
window.scrollX = window.scrollY = 0; // TODO: proxy these
window.WebGLRenderingContext = WebGLWorker;
@@ -184,8 +224,8 @@ document.createElement = function document_createElement(what) {
canvas.style = new PropertyBag();
canvas.exitPointerLock = function(){};
- canvas.width_ = canvas.width;
- canvas.height_ = canvas.height;
+ canvas.width_ = 400; // TODO: get the screen canvas size before we start up, use that
+ canvas.height_ = 400;
Object.defineProperty(canvas, 'width', {
set: function(value) {
canvas.width_ = value;
@@ -250,27 +290,6 @@ Audio.prototype.cloneNode = function() {
return new Audio;
}
-if (typeof console === 'undefined') {
- // we can't call Module.printErr because that might be circular
- var console = {
- log: function(x) {
- if (typeof dump === 'function') dump('log: ' + x + '\n');
- },
- debug: function(x) {
- if (typeof dump === 'function') dump('debug: ' + x + '\n');
- },
- info: function(x) {
- if (typeof dump === 'function') dump('info: ' + x + '\n');
- },
- warn: function(x) {
- if (typeof dump === 'function') dump('warn: ' + x + '\n');
- },
- error: function(x) {
- if (typeof dump === 'function') dump('error: ' + x + '\n');
- },
- };
-}
-
Module.canvas = document.createElement('canvas');
Module.setStatus = function(){};
diff --git a/src/webGLWorker.js b/src/webGLWorker.js
index 8136f064..f0fbc59d 100644
--- a/src/webGLWorker.js
+++ b/src/webGLWorker.js
@@ -815,7 +815,19 @@ function WebGLWorker() {
commandBuffer.push(39, target, pname, param);
};
this.texImage2D = function(target, level, internalformat, width, height, border, format, type, pixels) {
- assert(pixels || pixels === null); // we do not support the overloads that have fewer params
+ if (pixels === undefined) {
+ format = width; // width, height, border do not exist in the shorter overload
+ type = height;
+ pixels = border;
+ assert(pixels instanceof Image);
+ assert(internalformat === format && format === this.RGBA); // HTML Images are RGBA, 8-bit
+ assert(type === this.UNSIGNED_BYTE);
+ var data = pixels.data;
+ width = data.width;
+ height = data.height;
+ border = 0;
+ pixels = new Uint8Array(data.data); // XXX transform from clamped to normal, could have been done in duplicate
+ }
commandBuffer.push(40, target, level, internalformat, width, height, border, format, type, duplicate(pixels));
};
this.compressedTexImage2D = function(target, level, internalformat, width, height, border, pixels) {