monocle-rails 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/monocle/rails/version.rb +1 -1
- data/vendor/assets/.DS_Store +0 -0
- data/vendor/assets/javascripts/deflate.js +2088 -0
- data/vendor/assets/javascripts/inflate.js +2163 -0
- data/vendor/assets/javascripts/mime-types.js +1001 -0
- data/vendor/assets/javascripts/tests/arraybuffer.js +760 -0
- data/vendor/assets/javascripts/tests/base64.js +58 -0
- data/vendor/assets/javascripts/tests/dataview.js +212 -0
- data/vendor/assets/javascripts/tests/lorem.txt +1 -0
- data/vendor/assets/javascripts/tests/lorem.zip +0 -0
- data/vendor/assets/javascripts/tests/lorem2.zip +0 -0
- data/vendor/assets/javascripts/tests/lorem_store.zip +0 -0
- data/vendor/assets/javascripts/tests/test1.html +13 -0
- data/vendor/assets/javascripts/tests/test1.js +46 -0
- data/vendor/assets/javascripts/tests/test10.html +14 -0
- data/vendor/assets/javascripts/tests/test10.js +34 -0
- data/vendor/assets/javascripts/tests/test11.html +14 -0
- data/vendor/assets/javascripts/tests/test11.js +67 -0
- data/vendor/assets/javascripts/tests/test12.html +14 -0
- data/vendor/assets/javascripts/tests/test12.js +66 -0
- data/vendor/assets/javascripts/tests/test13.html +13 -0
- data/vendor/assets/javascripts/tests/test13.js +74 -0
- data/vendor/assets/javascripts/tests/test14.html +13 -0
- data/vendor/assets/javascripts/tests/test14.js +80 -0
- data/vendor/assets/javascripts/tests/test15.html +12 -0
- data/vendor/assets/javascripts/tests/test15.js +60 -0
- data/vendor/assets/javascripts/tests/test16.html +14 -0
- data/vendor/assets/javascripts/tests/test16.js +46 -0
- data/vendor/assets/javascripts/tests/test17.html +15 -0
- data/vendor/assets/javascripts/tests/test17.js +41 -0
- data/vendor/assets/javascripts/tests/test18.html +16 -0
- data/vendor/assets/javascripts/tests/test18.js +46 -0
- data/vendor/assets/javascripts/tests/test2.html +14 -0
- data/vendor/assets/javascripts/tests/test2.js +49 -0
- data/vendor/assets/javascripts/tests/test3.html +14 -0
- data/vendor/assets/javascripts/tests/test3.js +40 -0
- data/vendor/assets/javascripts/tests/test4.html +12 -0
- data/vendor/assets/javascripts/tests/test4.js +40 -0
- data/vendor/assets/javascripts/tests/test5.html +13 -0
- data/vendor/assets/javascripts/tests/test5.js +33 -0
- data/vendor/assets/javascripts/tests/test6.html +13 -0
- data/vendor/assets/javascripts/tests/test6.js +33 -0
- data/vendor/assets/javascripts/tests/test7.html +14 -0
- data/vendor/assets/javascripts/tests/test7.js +18 -0
- data/vendor/assets/javascripts/tests/test8.html +14 -0
- data/vendor/assets/javascripts/tests/test8.js +31 -0
- data/vendor/assets/javascripts/tests/test9.html +14 -0
- data/vendor/assets/javascripts/tests/test9.js +34 -0
- data/vendor/assets/javascripts/tests/util.js +16 -0
- data/vendor/assets/javascripts/zip-ext.js +241 -0
- data/vendor/assets/javascripts/zip-fs.js +538 -0
- data/vendor/assets/javascripts/zip.js +801 -0
- metadata +51 -1
@@ -0,0 +1,760 @@
|
|
1
|
+
// Code can be found at: http://www.calormen.com/polyfill/typedarray.js
|
2
|
+
|
3
|
+
/*
|
4
|
+
$LicenseInfo:firstyear=2010&license=mit$
|
5
|
+
|
6
|
+
Copyright (c) 2010, Linden Research, Inc.
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
10
|
+
in the Software without restriction, including without limitation the rights
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
13
|
+
furnished to do so, subject to the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
16
|
+
all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
THE SOFTWARE.
|
25
|
+
$/LicenseInfo$
|
26
|
+
*/
|
27
|
+
|
28
|
+
// Original can be found at: https://bitbucket.org/lindenlab/llsd
|
29
|
+
// Modifications by Joshua Bell inexorabletash@hotmail.com
|
30
|
+
// * Restructure the creation of types and exporting to global namespace
|
31
|
+
// * Allow no arguments to DataView constructor
|
32
|
+
// * Work cross-frame with native arrays/shimmed DataView
|
33
|
+
// * Corrected Object.defineProperty shim for IE8
|
34
|
+
// ES3/ES5 implementation of the Krhonos TypedArray Working Draft (work in progress):
|
35
|
+
// Ref: https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/TypedArray-spec.html
|
36
|
+
// Date: 2011-02-01
|
37
|
+
//
|
38
|
+
// Variations:
|
39
|
+
// * Float/Double -> Float32/Float64, per WebGL-Public mailing list conversations (post 5/17)
|
40
|
+
// * Allows typed_array.get/set() as alias for subscripts (typed_array[])
|
41
|
+
(function(global) {
|
42
|
+
"use strict";
|
43
|
+
|
44
|
+
var USE_NATIVE_IF_AVAILABLE = true;
|
45
|
+
|
46
|
+
// Approximations of internal ECMAScript conversion functions
|
47
|
+
var ECMAScript = (function() {
|
48
|
+
// Stash a copy in case other scripts modify these
|
49
|
+
var opts = Object.prototype.toString, ophop = Object.prototype.hasOwnProperty;
|
50
|
+
|
51
|
+
return {
|
52
|
+
// Class returns internal [[Class]] property, used to avoid cross-frame instanceof issues:
|
53
|
+
Class : function(v) {
|
54
|
+
return opts.call(v).replace(/^\[object *|\]$/g, '');
|
55
|
+
},
|
56
|
+
HasProperty : function(o, p) {
|
57
|
+
return p in o;
|
58
|
+
},
|
59
|
+
HasOwnProperty : function(o, p) {
|
60
|
+
return ophop.call(o, p);
|
61
|
+
},
|
62
|
+
IsCallable : function(o) {
|
63
|
+
return typeof o === 'function';
|
64
|
+
},
|
65
|
+
ToInt32 : function(v) {
|
66
|
+
return v >> 0;
|
67
|
+
},
|
68
|
+
ToUint32 : function(v) {
|
69
|
+
return v >>> 0;
|
70
|
+
}
|
71
|
+
};
|
72
|
+
}());
|
73
|
+
|
74
|
+
// Create an INDEX_SIZE_ERR event - intentionally induces a DOM error if possible
|
75
|
+
|
76
|
+
function new_INDEX_SIZE_ERR() {
|
77
|
+
try {
|
78
|
+
if (document) {
|
79
|
+
// raises DOMException(INDEX_SIZE_ERR)
|
80
|
+
document.createTextNode("").splitText(1);
|
81
|
+
}
|
82
|
+
return new RangeError("INDEX_SIZE_ERR");
|
83
|
+
} catch (e) {
|
84
|
+
return e;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
// ES5: lock down object properties
|
89
|
+
|
90
|
+
function configureProperties(obj) {
|
91
|
+
if (Object.getOwnPropertyNames && Object.defineProperty) {
|
92
|
+
var props = Object.getOwnPropertyNames(obj), i;
|
93
|
+
for (i = 0; i < props.length; i += 1) {
|
94
|
+
Object.defineProperty(obj, props[i], {
|
95
|
+
value : obj[props[i]],
|
96
|
+
writable : false,
|
97
|
+
enumerable : false,
|
98
|
+
configurable : false
|
99
|
+
});
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
// emulate ES5 getter/setter API using legacy APIs
|
105
|
+
// http://blogs.msdn.com/b/ie/archive/2010/09/07/transitioning-existing-code-to-the-es5-getter-setter-apis.aspx
|
106
|
+
// (second clause tests for Object.defineProperty() in IE<9 that only supports extending DOM prototypes, but
|
107
|
+
// note that IE<9 does not support __defineGetter__ or __defineSetter__ so it just renders the method harmless)
|
108
|
+
if (!Object.defineProperty || !(function() {
|
109
|
+
try {
|
110
|
+
Object.defineProperty({}, 'x', {});
|
111
|
+
return true;
|
112
|
+
} catch (e) {
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
}())) {
|
116
|
+
Object.defineProperty = function(o, p, desc) {
|
117
|
+
if (!o === Object(o)) {
|
118
|
+
throw new TypeError("Object.defineProperty called on non-object");
|
119
|
+
}
|
120
|
+
if (ECMAScript.HasProperty(desc, 'get') && Object.prototype.__defineGetter__) {
|
121
|
+
Object.prototype.__defineGetter__.call(o, p, desc.get);
|
122
|
+
}
|
123
|
+
if (ECMAScript.HasProperty(desc, 'set') && Object.prototype.__defineSetter__) {
|
124
|
+
Object.prototype.__defineSetter__.call(o, p, desc.set);
|
125
|
+
}
|
126
|
+
if (ECMAScript.HasProperty(desc, 'value')) {
|
127
|
+
o[p] = desc.value;
|
128
|
+
}
|
129
|
+
return o;
|
130
|
+
};
|
131
|
+
}
|
132
|
+
|
133
|
+
if (!Object.getOwnPropertyNames) {
|
134
|
+
Object.getOwnPropertyNames = function getOwnPropertyNames(o) {
|
135
|
+
if (o !== Object(o)) {
|
136
|
+
throw new TypeError("Object.getOwnPropertyNames called on non-object");
|
137
|
+
}
|
138
|
+
var props = [], p;
|
139
|
+
for (p in o) {
|
140
|
+
if (ECMAScript.HasOwnProperty(o, p)) {
|
141
|
+
props.push(p);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
return props;
|
145
|
+
};
|
146
|
+
}
|
147
|
+
|
148
|
+
// ES5: Make obj[index] an alias for obj._getter(index)/obj._setter(index, value)
|
149
|
+
// for index in 0 ... obj.length
|
150
|
+
|
151
|
+
function makeArrayAccessors(obj) {
|
152
|
+
if (!Object.defineProperty) {
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
|
156
|
+
function makeArrayAccessor(index) {
|
157
|
+
Object.defineProperty(obj, index, {
|
158
|
+
'get' : function() {
|
159
|
+
return obj._getter(index);
|
160
|
+
},
|
161
|
+
'set' : function(v) {
|
162
|
+
obj._setter(index, v);
|
163
|
+
},
|
164
|
+
enumerable : true,
|
165
|
+
configurable : false
|
166
|
+
});
|
167
|
+
}
|
168
|
+
|
169
|
+
var i;
|
170
|
+
for (i = 0; i < obj.length; i += 1) {
|
171
|
+
makeArrayAccessor(i);
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
// Internal conversion functions:
|
176
|
+
// pack<Type>() - take a number (interpreted as Type), output a byte array
|
177
|
+
// unpack<Type>() - take a byte array, output a Type-like number
|
178
|
+
|
179
|
+
function as_signed(value, bits) {
|
180
|
+
var s = 32 - bits;
|
181
|
+
return (value << s) >> s;
|
182
|
+
}
|
183
|
+
|
184
|
+
function as_unsigned(value, bits) {
|
185
|
+
var s = 32 - bits;
|
186
|
+
return (value << s) >>> s;
|
187
|
+
}
|
188
|
+
|
189
|
+
function packInt8(n) {
|
190
|
+
return [ n & 0xff ];
|
191
|
+
}
|
192
|
+
|
193
|
+
function unpackInt8(bytes) {
|
194
|
+
return as_signed(bytes[0], 8);
|
195
|
+
}
|
196
|
+
|
197
|
+
function packUint8(n) {
|
198
|
+
return [ n & 0xff ];
|
199
|
+
}
|
200
|
+
|
201
|
+
function unpackUint8(bytes) {
|
202
|
+
return as_unsigned(bytes[0], 8);
|
203
|
+
}
|
204
|
+
|
205
|
+
function packInt16(n) {
|
206
|
+
return [ (n >> 8) & 0xff, n & 0xff ];
|
207
|
+
}
|
208
|
+
|
209
|
+
function unpackInt16(bytes) {
|
210
|
+
return as_signed(bytes[0] << 8 | bytes[1], 16);
|
211
|
+
}
|
212
|
+
|
213
|
+
function packUint16(n) {
|
214
|
+
return [ (n >> 8) & 0xff, n & 0xff ];
|
215
|
+
}
|
216
|
+
|
217
|
+
function unpackUint16(bytes) {
|
218
|
+
return as_unsigned(bytes[0] << 8 | bytes[1], 16);
|
219
|
+
}
|
220
|
+
|
221
|
+
function packInt32(n) {
|
222
|
+
return [ (n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff ];
|
223
|
+
}
|
224
|
+
|
225
|
+
function unpackInt32(bytes) {
|
226
|
+
return as_signed(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32);
|
227
|
+
}
|
228
|
+
|
229
|
+
function packUint32(n) {
|
230
|
+
return [ (n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff ];
|
231
|
+
}
|
232
|
+
|
233
|
+
function unpackUint32(bytes) {
|
234
|
+
return as_unsigned(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32);
|
235
|
+
}
|
236
|
+
|
237
|
+
function packIEEE754(v, ebits, fbits) {
|
238
|
+
|
239
|
+
var bias = (1 << (ebits - 1)) - 1, s, e, f, ln, i, bits, str, bytes;
|
240
|
+
|
241
|
+
// Compute sign, exponent, fraction
|
242
|
+
if (v !== v) {
|
243
|
+
// NaN
|
244
|
+
// http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping
|
245
|
+
e = (1 << bias) - 1;
|
246
|
+
f = Math.pow(2, fbits - 1);
|
247
|
+
s = 0;
|
248
|
+
} else if (v === Infinity || v === -Infinity) {
|
249
|
+
e = (1 << bias) - 1;
|
250
|
+
f = 0;
|
251
|
+
s = (v < 0) ? 1 : 0;
|
252
|
+
} else if (v === 0) {
|
253
|
+
e = 0;
|
254
|
+
f = 0;
|
255
|
+
s = (1 / v === -Infinity) ? 1 : 0;
|
256
|
+
} else {
|
257
|
+
s = v < 0;
|
258
|
+
v = Math.abs(v);
|
259
|
+
|
260
|
+
if (v >= Math.pow(2, 1 - bias)) {
|
261
|
+
// Normalized
|
262
|
+
ln = Math.min(Math.floor(Math.log(v) / Math.LN2), bias);
|
263
|
+
e = ln + bias;
|
264
|
+
f = Math.round(v * Math.pow(2, fbits - ln) - Math.pow(2, fbits));
|
265
|
+
} else {
|
266
|
+
// Denormalized
|
267
|
+
e = 0;
|
268
|
+
f = Math.round(v / Math.pow(2, 1 - bias - fbits));
|
269
|
+
}
|
270
|
+
}
|
271
|
+
|
272
|
+
// Pack sign, exponent, fraction
|
273
|
+
bits = [];
|
274
|
+
for (i = fbits; i; i -= 1) {
|
275
|
+
bits.push(f % 2 ? 1 : 0);
|
276
|
+
f = Math.floor(f / 2);
|
277
|
+
}
|
278
|
+
for (i = ebits; i; i -= 1) {
|
279
|
+
bits.push(e % 2 ? 1 : 0);
|
280
|
+
e = Math.floor(e / 2);
|
281
|
+
}
|
282
|
+
bits.push(s ? 1 : 0);
|
283
|
+
bits.reverse();
|
284
|
+
str = bits.join('');
|
285
|
+
|
286
|
+
// Bits to bytes
|
287
|
+
bytes = [];
|
288
|
+
while (str.length) {
|
289
|
+
bytes.push(parseInt(str.substring(0, 8), 2));
|
290
|
+
str = str.substring(8);
|
291
|
+
}
|
292
|
+
return bytes;
|
293
|
+
}
|
294
|
+
|
295
|
+
function unpackIEEE754(bytes, ebits, fbits) {
|
296
|
+
|
297
|
+
// Bytes to bits
|
298
|
+
var bits = [], i, j, b, str, bias, s, e, f;
|
299
|
+
|
300
|
+
for (i = bytes.length; i; i -= 1) {
|
301
|
+
b = bytes[i - 1];
|
302
|
+
for (j = 8; j; j -= 1) {
|
303
|
+
bits.push(b % 2 ? 1 : 0);
|
304
|
+
b = b >> 1;
|
305
|
+
}
|
306
|
+
}
|
307
|
+
bits.reverse();
|
308
|
+
str = bits.join('');
|
309
|
+
|
310
|
+
// Unpack sign, exponent, fraction
|
311
|
+
bias = (1 << (ebits - 1)) - 1;
|
312
|
+
s = parseInt(str.substring(0, 1), 2) ? -1 : 1;
|
313
|
+
e = parseInt(str.substring(1, 1 + ebits), 2);
|
314
|
+
f = parseInt(str.substring(1 + ebits), 2);
|
315
|
+
|
316
|
+
// Produce number
|
317
|
+
if (e === (1 << ebits) - 1) {
|
318
|
+
return f !== 0 ? NaN : s * Infinity;
|
319
|
+
} else if (e > 0) {
|
320
|
+
// Normalized
|
321
|
+
return s * Math.pow(2, e - bias) * (1 + f / Math.pow(2, fbits));
|
322
|
+
} else if (f !== 0) {
|
323
|
+
// Denormalized
|
324
|
+
return s * Math.pow(2, -(bias - 1)) * (f / Math.pow(2, fbits));
|
325
|
+
} else {
|
326
|
+
return s < 0 ? -0 : 0;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
function unpackFloat64(b) {
|
331
|
+
return unpackIEEE754(b, 11, 52);
|
332
|
+
}
|
333
|
+
|
334
|
+
function packFloat64(v) {
|
335
|
+
return packIEEE754(v, 11, 52);
|
336
|
+
}
|
337
|
+
|
338
|
+
function unpackFloat32(b) {
|
339
|
+
return unpackIEEE754(b, 8, 23);
|
340
|
+
}
|
341
|
+
|
342
|
+
function packFloat32(v) {
|
343
|
+
return packIEEE754(v, 8, 23);
|
344
|
+
}
|
345
|
+
|
346
|
+
//
|
347
|
+
// 3 The ArrayBuffer Type
|
348
|
+
//
|
349
|
+
(function() {
|
350
|
+
|
351
|
+
/** @constructor */
|
352
|
+
var ArrayBuffer = function ArrayBuffer(length) {
|
353
|
+
length = ECMAScript.ToInt32(length);
|
354
|
+
if (length < 0) {
|
355
|
+
throw new RangeError('ArrayBuffer size is not a small enough positive integer.');
|
356
|
+
}
|
357
|
+
|
358
|
+
this.byteLength = length;
|
359
|
+
this._bytes = [];
|
360
|
+
this._bytes.length = length;
|
361
|
+
|
362
|
+
var i;
|
363
|
+
for (i = 0; i < this.byteLength; i += 1) {
|
364
|
+
this._bytes[i] = 0;
|
365
|
+
}
|
366
|
+
|
367
|
+
configureProperties(this);
|
368
|
+
};
|
369
|
+
|
370
|
+
//
|
371
|
+
// 4 The ArrayBufferView Type
|
372
|
+
//
|
373
|
+
// NOTE: this constructor is not exported
|
374
|
+
/** @constructor */
|
375
|
+
var ArrayBufferView = function ArrayBufferView() {
|
376
|
+
// this.buffer = null;
|
377
|
+
// this.byteOffset = 0;
|
378
|
+
// this.byteLength = 0;
|
379
|
+
};
|
380
|
+
|
381
|
+
//
|
382
|
+
// 5 The Typed Array View Types
|
383
|
+
//
|
384
|
+
|
385
|
+
function makeTypedArrayConstructor(bytesPerElement, pack, unpack) {
|
386
|
+
// Each TypedArray type requires a distinct constructor instance with
|
387
|
+
// identical logic, which this produces.
|
388
|
+
var ctor;
|
389
|
+
ctor = function(buffer, byteOffset, length) {
|
390
|
+
var array, sequence, i, s;
|
391
|
+
|
392
|
+
if (!arguments.length || typeof arguments[0] === 'number') {
|
393
|
+
// Constructor(unsigned long length)
|
394
|
+
this.length = ECMAScript.ToInt32(arguments[0]);
|
395
|
+
if (length < 0) {
|
396
|
+
throw new RangeError('ArrayBufferView size is not a small enough positive integer.');
|
397
|
+
}
|
398
|
+
|
399
|
+
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
400
|
+
this.buffer = new ArrayBuffer(this.byteLength);
|
401
|
+
this.byteOffset = 0;
|
402
|
+
} else if (typeof arguments[0] === 'object' && arguments[0].constructor === ctor) {
|
403
|
+
// Constructor(TypedArray array)
|
404
|
+
array = arguments[0];
|
405
|
+
|
406
|
+
this.length = array.length;
|
407
|
+
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
408
|
+
this.buffer = new ArrayBuffer(this.byteLength);
|
409
|
+
this.byteOffset = 0;
|
410
|
+
|
411
|
+
for (i = 0; i < this.length; i += 1) {
|
412
|
+
this._setter(i, array._getter(i));
|
413
|
+
}
|
414
|
+
} else if (typeof arguments[0] === 'object' && !(arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
|
415
|
+
// Constructor(sequence<type> array)
|
416
|
+
sequence = arguments[0];
|
417
|
+
|
418
|
+
this.length = ECMAScript.ToUint32(sequence.length);
|
419
|
+
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
420
|
+
this.buffer = new ArrayBuffer(this.byteLength);
|
421
|
+
this.byteOffset = 0;
|
422
|
+
|
423
|
+
for (i = 0; i < this.length; i += 1) {
|
424
|
+
s = sequence[i];
|
425
|
+
this._setter(i, Number(s));
|
426
|
+
}
|
427
|
+
} else if (typeof arguments[0] === 'object' && (arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
|
428
|
+
// Constructor(ArrayBuffer buffer,
|
429
|
+
// optional unsigned long byteOffset, optional unsigned long length)
|
430
|
+
this.buffer = buffer;
|
431
|
+
|
432
|
+
this.byteOffset = ECMAScript.ToUint32(byteOffset);
|
433
|
+
if (this.byteOffset > this.buffer.byteLength) {
|
434
|
+
throw new_INDEX_SIZE_ERR(); // byteOffset out of range
|
435
|
+
}
|
436
|
+
|
437
|
+
if (this.byteOffset % this.BYTES_PER_ELEMENT) {
|
438
|
+
// The given byteOffset must be a multiple of the element
|
439
|
+
// size of the specific type, otherwise an exception is raised.
|
440
|
+
// throw new_INDEX_SIZE_ERR();
|
441
|
+
throw new RangeError("ArrayBuffer length minus the byteOffset is not a multiple of the element size.");
|
442
|
+
}
|
443
|
+
|
444
|
+
if (arguments.length < 3) {
|
445
|
+
this.byteLength = this.buffer.byteLength - this.byteOffset;
|
446
|
+
|
447
|
+
if (this.byteLength % this.BYTES_PER_ELEMENT) {
|
448
|
+
throw new_INDEX_SIZE_ERR(); // length of buffer minus byteOffset not a multiple of the element size
|
449
|
+
}
|
450
|
+
this.length = this.byteLength / this.BYTES_PER_ELEMENT;
|
451
|
+
} else {
|
452
|
+
this.length = ECMAScript.ToUint32(length);
|
453
|
+
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
454
|
+
}
|
455
|
+
|
456
|
+
if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
|
457
|
+
throw new_INDEX_SIZE_ERR(); // byteOffset and length reference an area beyond the end of the buffer
|
458
|
+
}
|
459
|
+
} else {
|
460
|
+
throw new TypeError("Unexpected argument type(s)");
|
461
|
+
}
|
462
|
+
|
463
|
+
this.constructor = ctor;
|
464
|
+
|
465
|
+
configureProperties(this);
|
466
|
+
makeArrayAccessors(this);
|
467
|
+
};
|
468
|
+
|
469
|
+
ctor.prototype = new ArrayBufferView();
|
470
|
+
ctor.prototype.BYTES_PER_ELEMENT = bytesPerElement;
|
471
|
+
ctor.prototype._pack = pack;
|
472
|
+
ctor.prototype._unpack = unpack;
|
473
|
+
ctor.BYTES_PER_ELEMENT = bytesPerElement;
|
474
|
+
|
475
|
+
// getter type (unsigned long index);
|
476
|
+
ctor.prototype._getter = function(index) {
|
477
|
+
if (arguments.length < 1) {
|
478
|
+
throw new SyntaxError("Not enough arguments");
|
479
|
+
}
|
480
|
+
|
481
|
+
index = ECMAScript.ToUint32(index);
|
482
|
+
if (index >= this.length) {
|
483
|
+
// throw new_INDEX_SIZE_ERR(); // Array index out of range
|
484
|
+
return (void 0); // undefined
|
485
|
+
}
|
486
|
+
|
487
|
+
var bytes = [], i, o;
|
488
|
+
for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT; i < this.BYTES_PER_ELEMENT; i += 1, o += 1) {
|
489
|
+
bytes.push(this.buffer._bytes[o]);
|
490
|
+
}
|
491
|
+
return this._unpack(bytes);
|
492
|
+
};
|
493
|
+
|
494
|
+
// NONSTANDARD: convenience alias for getter: type get(unsigned long index);
|
495
|
+
ctor.prototype.get = ctor.prototype._getter;
|
496
|
+
|
497
|
+
// setter void (unsigned long index, type value);
|
498
|
+
ctor.prototype._setter = function(index, value) {
|
499
|
+
if (arguments.length < 2) {
|
500
|
+
throw new SyntaxError("Not enough arguments");
|
501
|
+
}
|
502
|
+
|
503
|
+
index = ECMAScript.ToUint32(index);
|
504
|
+
if (index >= this.length) {
|
505
|
+
// throw new_INDEX_SIZE_ERR(); // Array index out of range
|
506
|
+
return;
|
507
|
+
}
|
508
|
+
|
509
|
+
var bytes = this._pack(value), i, o;
|
510
|
+
for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT; i < this.BYTES_PER_ELEMENT; i += 1, o += 1) {
|
511
|
+
this.buffer._bytes[o] = bytes[i];
|
512
|
+
}
|
513
|
+
};
|
514
|
+
|
515
|
+
// void set(TypedArray array, optional unsigned long offset);
|
516
|
+
// void set(sequence<type> array, optional unsigned long offset);
|
517
|
+
ctor.prototype.set = function(index, value) {
|
518
|
+
if (arguments.length < 1) {
|
519
|
+
throw new SyntaxError("Not enough arguments");
|
520
|
+
}
|
521
|
+
var array, sequence, offset, len, i, s, d, byteOffset, byteLength, tmp;
|
522
|
+
|
523
|
+
if (typeof arguments[0] === 'object' && arguments[0].constructor === this.constructor) {
|
524
|
+
// void set(TypedArray array, optional unsigned long offset);
|
525
|
+
array = arguments[0];
|
526
|
+
offset = ECMAScript.ToUint32(arguments[1]);
|
527
|
+
|
528
|
+
if (offset + array.length > this.length) {
|
529
|
+
throw new_INDEX_SIZE_ERR(); // Offset plus length of array is out of range
|
530
|
+
}
|
531
|
+
|
532
|
+
byteOffset = this.byteOffset + offset * this.BYTES_PER_ELEMENT;
|
533
|
+
byteLength = array.length * this.BYTES_PER_ELEMENT;
|
534
|
+
|
535
|
+
if (array.buffer === this.buffer) {
|
536
|
+
tmp = [];
|
537
|
+
for (i = 0, s = array.byteOffset; i < byteLength; i += 1, s += 1) {
|
538
|
+
tmp[i] = array.buffer._bytes[s];
|
539
|
+
}
|
540
|
+
for (i = 0, d = byteOffset; i < byteLength; i += 1, d += 1) {
|
541
|
+
this.buffer._bytes[d] = tmp[i];
|
542
|
+
}
|
543
|
+
} else {
|
544
|
+
for (i = 0, s = array.byteOffset, d = byteOffset; i < byteLength; i += 1, s += 1, d += 1) {
|
545
|
+
this.buffer._bytes[d] = array.buffer._bytes[s];
|
546
|
+
}
|
547
|
+
}
|
548
|
+
} else if (typeof arguments[0] === 'object' && typeof arguments[0].length !== 'undefined') {
|
549
|
+
// void set(sequence<type> array, optional unsigned long offset);
|
550
|
+
sequence = arguments[0];
|
551
|
+
len = ECMAScript.ToUint32(sequence.length);
|
552
|
+
offset = ECMAScript.ToUint32(arguments[1]);
|
553
|
+
|
554
|
+
if (offset + len > this.length) {
|
555
|
+
throw new_INDEX_SIZE_ERR(); // Offset plus length of array is out of range
|
556
|
+
}
|
557
|
+
|
558
|
+
for (i = 0; i < len; i += 1) {
|
559
|
+
s = sequence[i];
|
560
|
+
this._setter(offset + i, Number(s));
|
561
|
+
}
|
562
|
+
} else {
|
563
|
+
throw new TypeError("Unexpected argument type(s)");
|
564
|
+
}
|
565
|
+
};
|
566
|
+
|
567
|
+
// TypedArray subarray(long begin, optional long end);
|
568
|
+
ctor.prototype.subarray = function(start, end) {
|
569
|
+
function clamp(v, min, max) {
|
570
|
+
return v < min ? min : v > max ? max : v;
|
571
|
+
}
|
572
|
+
|
573
|
+
start = ECMAScript.ToInt32(start);
|
574
|
+
end = ECMAScript.ToInt32(end);
|
575
|
+
|
576
|
+
if (arguments.length < 1) {
|
577
|
+
start = 0;
|
578
|
+
}
|
579
|
+
if (arguments.length < 2) {
|
580
|
+
end = this.length;
|
581
|
+
}
|
582
|
+
|
583
|
+
if (start < 0) {
|
584
|
+
start = this.length + start;
|
585
|
+
}
|
586
|
+
if (end < 0) {
|
587
|
+
end = this.length + end;
|
588
|
+
}
|
589
|
+
|
590
|
+
start = clamp(start, 0, this.length);
|
591
|
+
end = clamp(end, 0, this.length);
|
592
|
+
|
593
|
+
var len = end - start;
|
594
|
+
if (len < 0) {
|
595
|
+
len = 0;
|
596
|
+
}
|
597
|
+
|
598
|
+
return new this.constructor(this.buffer, start * this.BYTES_PER_ELEMENT, len);
|
599
|
+
};
|
600
|
+
|
601
|
+
return ctor;
|
602
|
+
}
|
603
|
+
|
604
|
+
var Int8Array = makeTypedArrayConstructor(1, packInt8, unpackInt8);
|
605
|
+
var Uint8Array = makeTypedArrayConstructor(1, packUint8, unpackUint8);
|
606
|
+
var Int16Array = makeTypedArrayConstructor(2, packInt16, unpackInt16);
|
607
|
+
var Uint16Array = makeTypedArrayConstructor(2, packUint16, unpackUint16);
|
608
|
+
var Int32Array = makeTypedArrayConstructor(4, packInt32, unpackInt32);
|
609
|
+
var Uint32Array = makeTypedArrayConstructor(4, packUint32, unpackUint32);
|
610
|
+
var Float32Array = makeTypedArrayConstructor(4, packFloat32, unpackFloat32);
|
611
|
+
var Float64Array = makeTypedArrayConstructor(8, packFloat64, unpackFloat64);
|
612
|
+
|
613
|
+
if (USE_NATIVE_IF_AVAILABLE) {
|
614
|
+
global.ArrayBuffer = global.ArrayBuffer || ArrayBuffer;
|
615
|
+
global.Int8Array = global.Int8Array || Int8Array;
|
616
|
+
global.Uint8Array = global.Uint8Array || Uint8Array;
|
617
|
+
global.Int16Array = global.Int16Array || Int16Array;
|
618
|
+
global.Uint16Array = global.Uint16Array || Uint16Array;
|
619
|
+
global.Int32Array = global.Int32Array || Int32Array;
|
620
|
+
global.Uint32Array = global.Uint32Array || Uint32Array;
|
621
|
+
global.Float32Array = global.Float32Array || Float32Array;
|
622
|
+
global.Float64Array = global.Float64Array || Float64Array;
|
623
|
+
} else {
|
624
|
+
global.ArrayBuffer = ArrayBuffer;
|
625
|
+
global.Int8Array = Int8Array;
|
626
|
+
global.Uint8Array = Uint8Array;
|
627
|
+
global.Int16Array = Int16Array;
|
628
|
+
global.Uint16Array = Uint16Array;
|
629
|
+
global.Int32Array = Int32Array;
|
630
|
+
global.Uint32Array = Uint32Array;
|
631
|
+
global.Float32Array = Float32Array;
|
632
|
+
global.Float64Array = Float64Array;
|
633
|
+
}
|
634
|
+
}());
|
635
|
+
|
636
|
+
//
|
637
|
+
// 6 The DataView View Type
|
638
|
+
//
|
639
|
+
(function() {
|
640
|
+
function r(array, index) {
|
641
|
+
return ECMAScript.IsCallable(array.get) ? array.get(index) : array[index];
|
642
|
+
}
|
643
|
+
|
644
|
+
var IS_BIG_ENDIAN = (function() {
|
645
|
+
var u16array = new Uint16Array([ 0x1234 ]), u8array = new Uint8Array(u16array.buffer);
|
646
|
+
return r(u8array, 0) === 0x12;
|
647
|
+
}());
|
648
|
+
|
649
|
+
// Constructor(ArrayBuffer buffer,
|
650
|
+
// optional unsigned long byteOffset,
|
651
|
+
// optional unsigned long byteLength)
|
652
|
+
/** @constructor */
|
653
|
+
var DataView = function DataView(buffer, byteOffset, byteLength) {
|
654
|
+
if (arguments.length === 0) {
|
655
|
+
buffer = new ArrayBuffer(0);
|
656
|
+
} else if (!(buffer instanceof ArrayBuffer || ECMAScript.Class(buffer) === 'ArrayBuffer')) {
|
657
|
+
throw new TypeError("TypeError");
|
658
|
+
}
|
659
|
+
|
660
|
+
this.buffer = buffer || new ArrayBuffer(0);
|
661
|
+
|
662
|
+
this.byteOffset = ECMAScript.ToUint32(byteOffset);
|
663
|
+
if (this.byteOffset > this.buffer.byteLength) {
|
664
|
+
throw new_INDEX_SIZE_ERR(); // byteOffset out of range
|
665
|
+
}
|
666
|
+
|
667
|
+
if (arguments.length < 3) {
|
668
|
+
this.byteLength = this.buffer.byteLength - this.byteOffset;
|
669
|
+
} else {
|
670
|
+
this.byteLength = ECMAScript.ToUint32(byteLength);
|
671
|
+
}
|
672
|
+
|
673
|
+
if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
|
674
|
+
throw new_INDEX_SIZE_ERR(); // byteOffset and length reference an area beyond the end of the buffer
|
675
|
+
}
|
676
|
+
|
677
|
+
configureProperties(this);
|
678
|
+
};
|
679
|
+
|
680
|
+
// TODO: Reintroduce this to get correct hierarchy
|
681
|
+
// if (typeof ArrayBufferView === 'function') {
|
682
|
+
// DataView.prototype = new ArrayBufferView();
|
683
|
+
// }
|
684
|
+
|
685
|
+
function makeDataView_getter(arrayType) {
|
686
|
+
return function(byteOffset, littleEndian) {
|
687
|
+
|
688
|
+
byteOffset = ECMAScript.ToUint32(byteOffset);
|
689
|
+
|
690
|
+
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
|
691
|
+
throw new_INDEX_SIZE_ERR(); // Array index out of range
|
692
|
+
}
|
693
|
+
byteOffset += this.byteOffset;
|
694
|
+
|
695
|
+
var uint8Array = new Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT), bytes = [], i;
|
696
|
+
for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
|
697
|
+
bytes.push(r(uint8Array, i));
|
698
|
+
}
|
699
|
+
|
700
|
+
if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
|
701
|
+
bytes.reverse();
|
702
|
+
}
|
703
|
+
|
704
|
+
return r(new arrayType(new Uint8Array(bytes).buffer), 0);
|
705
|
+
};
|
706
|
+
}
|
707
|
+
|
708
|
+
DataView.prototype.getUint8 = makeDataView_getter(Uint8Array);
|
709
|
+
DataView.prototype.getInt8 = makeDataView_getter(Int8Array);
|
710
|
+
DataView.prototype.getUint16 = makeDataView_getter(Uint16Array);
|
711
|
+
DataView.prototype.getInt16 = makeDataView_getter(Int16Array);
|
712
|
+
DataView.prototype.getUint32 = makeDataView_getter(Uint32Array);
|
713
|
+
DataView.prototype.getInt32 = makeDataView_getter(Int32Array);
|
714
|
+
DataView.prototype.getFloat32 = makeDataView_getter(Float32Array);
|
715
|
+
DataView.prototype.getFloat64 = makeDataView_getter(Float64Array);
|
716
|
+
|
717
|
+
function makeDataView_setter(arrayType) {
|
718
|
+
return function(byteOffset, value, littleEndian) {
|
719
|
+
|
720
|
+
byteOffset = ECMAScript.ToUint32(byteOffset);
|
721
|
+
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
|
722
|
+
throw new_INDEX_SIZE_ERR(); // Array index out of range
|
723
|
+
}
|
724
|
+
|
725
|
+
// Get bytes
|
726
|
+
var typeArray = new arrayType([ value ]), byteArray = new Uint8Array(typeArray.buffer), bytes = [], i, byteView;
|
727
|
+
|
728
|
+
for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
|
729
|
+
bytes.push(r(byteArray, i));
|
730
|
+
}
|
731
|
+
|
732
|
+
// Flip if necessary
|
733
|
+
if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
|
734
|
+
bytes.reverse();
|
735
|
+
}
|
736
|
+
|
737
|
+
// Write them
|
738
|
+
byteView = new Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT);
|
739
|
+
byteView.set(bytes);
|
740
|
+
};
|
741
|
+
}
|
742
|
+
|
743
|
+
DataView.prototype.setUint8 = makeDataView_setter(Uint8Array);
|
744
|
+
DataView.prototype.setInt8 = makeDataView_setter(Int8Array);
|
745
|
+
DataView.prototype.setUint16 = makeDataView_setter(Uint16Array);
|
746
|
+
DataView.prototype.setInt16 = makeDataView_setter(Int16Array);
|
747
|
+
DataView.prototype.setUint32 = makeDataView_setter(Uint32Array);
|
748
|
+
DataView.prototype.setInt32 = makeDataView_setter(Int32Array);
|
749
|
+
DataView.prototype.setFloat32 = makeDataView_setter(Float32Array);
|
750
|
+
DataView.prototype.setFloat64 = makeDataView_setter(Float64Array);
|
751
|
+
|
752
|
+
if (USE_NATIVE_IF_AVAILABLE) {
|
753
|
+
global.DataView = global.DataView || DataView;
|
754
|
+
} else {
|
755
|
+
global.DataView = DataView;
|
756
|
+
}
|
757
|
+
|
758
|
+
}());
|
759
|
+
|
760
|
+
}(this));
|