aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFraser Adams <fraser.adams@blueyonder.co.uk>2014-01-06 14:49:50 +0000
committerFraser Adams <fraser.adams@blueyonder.co.uk>2014-01-06 14:49:50 +0000
commit3bdbd008f9f95e6a1d8da42e61a751289db17b60 (patch)
tree2dab07ecaf099c22750bc9b954e17b9944411723 /src
parent385a660a1868dc1777b251dfcf83371ccd388b02 (diff)
changed != to !== in a couple of places. Added fix to prevent closure minifying crypto randomBytes etc. this fix makes use of closure externs so I've added a closure-externs.js to hold the definitions and modified tools/shared.py closure_compiler method to point to closure-externs.js. I've added externs to fix minification of the ws library used in library_sockfs.js too
Diffstat (limited to 'src')
-rw-r--r--src/closure-externs.js110
-rw-r--r--src/library_uuid.js4
2 files changed, 112 insertions, 2 deletions
diff --git a/src/closure-externs.js b/src/closure-externs.js
new file mode 100644
index 00000000..a82aa669
--- /dev/null
+++ b/src/closure-externs.js
@@ -0,0 +1,110 @@
+/**
+ * This file contains definitions for things that we'd really rather the closure compiler *didn't* minify.
+ * See http://code.google.com/p/closure-compiler/wiki/FAQ#How_do_I_write_an_externs_file
+ * See also the discussion here: https://github.com/kripken/emscripten/issues/1979
+ *
+ * The closure_compiler() method in tools/shared.py refers to this file when calling closure.
+ */
+
+// Closure externs used by library_uuid.js
+
+/**
+ * @param {Array} typedArray
+ */
+crypto.getRandomValues = function(typedArray) {};
+
+/**
+ BEGIN_NODE_INCLUDE
+ var crypto = require('crypto');
+ END_NODE_INCLUDE
+ */
+
+/**
+ * @type {Object.<string,*>}
+ */
+var crypto = {};
+
+/**
+ * @param {number} size
+ * @param {function(Error, buffer.Buffer)} callback
+ */
+crypto.randomBytes = function(size, callback) {};
+
+
+// Closure externs used by library_sockfs.js
+
+/**
+ BEGIN_NODE_INCLUDE
+ var ws = require('ws');
+ END_NODE_INCLUDE
+ */
+
+/**
+ * @type {Object.<string,*>}
+ */
+var ws = {};
+
+/**
+ * @param {string} event
+ * @param {function()} callback
+ */
+ws.on = function(event, callback) {};
+
+/**
+ * @param {Object} data
+ * @param {Object} flags
+ * @param {function()=} callback
+ */
+ws.send = function(data, flags, callback) {};
+
+/**
+* @type {boolean}
+*/
+ws.binaryType;
+
+/**
+ * @type {Object.<string,*>}
+ */
+var wss = ws.Server;
+
+/**
+ * @param {string} event
+ * @param {function()} callback
+ */
+wss.on = function(event, callback) {};
+
+/**
+ * @param {function()} callback
+ */
+wss.broadcast = function(callback) {};
+
+/**
+* @type {Object.<string,*>}
+*/
+wss._socket;
+
+/**
+* @type {string}
+*/
+wss.url;
+
+/**
+* @type {string}
+*/
+wss._socket.remoteAddress;
+
+/**
+* @type {number}
+*/
+wss._socket.remotePort;
+
+/**
+* @type {Object.<string,*>}
+*/
+var flags = {};
+/**
+* @type {boolean}
+*/
+flags.binary;
+
+
diff --git a/src/library_uuid.js b/src/library_uuid.js
index cce0a4f8..9a0377ae 100644
--- a/src/library_uuid.js
+++ b/src/library_uuid.js
@@ -35,8 +35,8 @@ mergeInto(LibraryManager.library, {
var rb = require('crypto').randomBytes;
uuid = rb(16);
} catch(e) {}
- } else if (typeof(window.crypto) != 'undefined' &&
- typeof(window.crypto.getRandomValues) != 'undefined') {
+ } else if (typeof(window.crypto) !== 'undefined' &&
+ typeof(window.crypto.getRandomValues) !== 'undefined') {
// If crypto.getRandomValues is available try to use it.
uuid = new Uint8Array(16);
window.crypto.getRandomValues(uuid);