Permalink
Browse files

clean up dependencies, use rserve.js from github/cscheid/rserve-js

  • Loading branch information...
1 parent b01a3a9 commit bc6a2688d3e47efac0d497d9b0397b18ab0fd720 Carlos Scheidegger committed Mar 15, 2013
View
@@ -5,11 +5,7 @@ all: rcloud_bundle.js rcloud_bundle.min.js
rcloud_bundle.js: \
chart.js \
facet_chart.js \
- websockets.js \
- rserve.js \
rclient.js \
- polyfill_dataview.js \
- endian_aware_dataview.js \
rcloud.js \
notebook/_begin.js \
notebook/cell/_begin.js \
@@ -1,93 +0,0 @@
-(function(global) {
- var _is_little_endian;
-
- (function() {
- var x = new ArrayBuffer(4);
- var bytes = new Uint8Array(x),
- words = new Uint32Array(x);
- bytes[0] = 1;
- if (words[0] === 1) {
- _is_little_endian = true;
- } else if (words[0] === 16777216) {
- _is_little_endian = false;
- } else {
- throw "we're bizarro endian, refusing to continue";
- }
- })();
-
- global.EndianAwareDataView = (function() {
-
- var proto = {
- 'setInt8': function(i, v) { return this.view.setInt8(i, v); },
- 'setUint8': function(i, v) { return this.view.setUint8(i, v); },
- 'getInt8': function(i) { return this.view.getInt8(i); },
- 'getUint8': function(i) { return this.view.getUint8(i); }
- };
-
- var setters = ['setInt32', 'setInt16', 'setUint32', 'setUint16',
- 'setFloat32', 'setFloat64'];
- var getters = ['getInt32', 'getInt16', 'getUint32', 'getUint16',
- 'getFloat32', 'getFloat64'];
-
- for (var i=0; i<setters.length; ++i) {
- var name = setters[i];
- proto[name]= (function(name) {
- return function(byteOffset, value) {
- return this.view[name](byteOffset, value, _is_little_endian); };
- })(name);
- }
- for (i=0; i<getters.length; ++i) {
- var name = getters[i];
- proto[name]= (function(name) {
- return function(byteOffset) {
- return this.view[name](byteOffset, _is_little_endian);
- };
- })(name);
- }
-
- function my_dataView(buffer, byteOffset, byteLength) {
- if (byteOffset === undefined) {
- this.view = new DataView(buffer);
- } else {
- this.view = new DataView(buffer, byteOffset, byteLength);
- }
- };
- my_dataView.prototype = proto;
- return my_dataView;
- })();
-
- global.my_ArrayBufferView = function(b, o, l) {
- o = _.isUndefined(o) ? 0 : o;
- l = _.isUndefined(l) ? b.byteLength : l;
- return {
- buffer: b,
- offset: o,
- length: l,
- make: function(ctor, new_offset, new_length) {
- new_offset = _.isUndefined(new_offset) ? 0 : new_offset;
- new_length = _.isUndefined(new_length) ? this.length : new_length;
- var element_size = ctor.BYTES_PER_ELEMENT || 1;
- var n_els = new_length / element_size;
- if ((this.offset + new_offset) % element_size != 0) {
- var view = new DataView(this.buffer, this.offset + new_offset, new_length);
- var output_buffer = new ArrayBuffer(new_length);
- var out_view = new DataView(output_buffer);
- for (var i=0; i < new_length; ++i) {
- out_view.setUint8(i, view.getUint8(i));
- }
- return new ctor(output_buffer);
- } else {
- return new ctor(this.buffer,
- this.offset + new_offset,
- n_els);
- }
- },
- view: function(new_offset, new_length) {
- // FIXME Needs bounds checking
- return my_ArrayBufferView(this.buffer, this.offset + new_offset, new_length);
- }
- };
- };
-
-})(this);
-
@@ -1,83 +0,0 @@
-(function(global) {
- var _is_little_endian;
-
- (function() {
- var x = new ArrayBuffer(4);
- var bytes = new Uint8Array(x),
- words = new Uint32Array(x);
- bytes[0] = 1;
- if (words[0] === 1) {
- _is_little_endian = true;
- } else if (words[0] === 16777216) {
- _is_little_endian = false;
- } else {
- throw "we're bizarro endian, refusing to continue";
- }
- })();
-
- if (!global.DataView) {
- var data_types = ['Int32', 'Int16', 'Uint32', 'Uint16',
- 'Float32', 'Float64'];
- var setters = ['setInt32', 'setInt16', 'setUint32', 'setUint16',
- 'setFloat32', 'setFloat64'];
- var getters = ['getInt32', 'getInt16', 'getUint32', 'getUint16',
- 'getFloat32', 'getFloat64'];
-
- console.log("polyfilling DataView");
-
- var helpers = {};
- for (var i=0; i<data_types.length; ++i) {
- var cls = this[data_types[i] + 'Array'];
- var sz = cls.BYTES_PER_ELEMENT;
- var buf = new ArrayBuffer(sz);
- var original_array = new cls(buf);
- var byte_array = new Uint8Array(buf);
- helpers[data_types[i]] = (function(original_array, byte_array) {
- return function(output, sz, ix, v) {
- original_array[0] = v;
- for (var i=0; i<sz; ++i) {
- output[ix + i] = byte_array[i];
- }
- };
- })(original_array, byte_array);
- }
-
- function MyDataView(buffer, byteOffset, byteLength) {
- this.buffer = buffer;
- this.byteOffset = _.isUndefined(byteOffset) ? 0 : byteOffset;
- this.byteLength = _.isUndefined(byteLength) ? buffer.byteLength : byteLength;
- this.view = new jDataView(buffer, byteOffset, byteLength, _is_little_endian);
- this.byte_array = new Uint8Array(buffer);
- }
-
- var proto = {};
- MyDataView.prototype = proto;
- for (i=0; i<data_types.length; ++i) {
- var getter = 'get' + data_types[i];
- proto[getter] = (function(name) {
- return function(i) { return this.view[name](i); };
- })(getter);
- var setter = 'set' + data_types[i];
- var sz = this[data_types[i] + 'Array'].BYTES_PER_ELEMENT;
- proto[setter] = (function(sz, name) {
- return function(byteOffset, v) {
- console.log(name);
- console.log(helpers);
- helpers[name](this.byte_array, sz, byteOffset, v);
- };
- })(sz, data_types[i]);
- }
-
- proto.setUint8 = function(ix, v) {
- this.byte_array[ix] = v;
- };
- proto.setInt8 = function(ix, v) {
- if (v < 0) v += 256;
- this.byte_array[ix] = v;
- };
- proto.getInt8 = function(ix) { return this.view.GetInt8(ix); };
- proto.getUint8 = function(ix) { /* return this.view.GetUint8(ix); // <-- doesn't work in FF! */ return this.byte_array[ix]; };
-
- global.DataView = MyDataView;
- }
-})(this);
Oops, something went wrong.

0 comments on commit bc6a268

Please sign in to comment.