|
|
|
|
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
|
|
|
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"26sEV7":[function(require,module,exports){
|
|
|
|
|
var base64 = require('base64-js')
|
|
|
|
|
var TA = require('typedarray')
|
|
|
|
|
|
|
|
|
|
exports.Buffer = Buffer
|
|
|
|
|
exports.SlowBuffer = Buffer
|
|
|
|
|
exports.INSPECT_MAX_BYTES = 50
|
|
|
|
|
Buffer.poolSize = 8192
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Use a shim for browsers that lack Typed Array support (< IE 9, < FF 3.6,
|
|
|
|
|
* < Chrome 6, < Safari 5, < Opera 11.5, < iOS 4.1).
|
|
|
|
|
*/
|
|
|
|
|
var xDataView = typeof DataView === 'undefined'
|
|
|
|
|
? TA.DataView : DataView
|
|
|
|
|
var xArrayBuffer = typeof ArrayBuffer === 'undefined'
|
|
|
|
|
? TA.ArrayBuffer : ArrayBuffer
|
|
|
|
|
var xUint8Array = typeof Uint8Array === 'undefined'
|
|
|
|
|
? TA.Uint8Array : Uint8Array
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Does the browser support adding properties to `Uint8Array` instances? If
|
|
|
|
|
* not, then use the shim even if the browser supports typed arrays; we need
|
|
|
|
|
* to be able to add all the node Buffer API methods. We could use an ES6
|
|
|
|
|
* Proxy to intercept method calls and simulate adding function properties in
|
|
|
|
|
* Firefox, but that adds a huge performance penalty.
|
|
|
|
|
*
|
|
|
|
|
* Firefox bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=695438
|
|
|
|
|
*/
|
|
|
|
|
var supportsAugment = (function () {
|
|
|
|
|
try {
|
|
|
|
|
var arr = new xUint8Array(0)
|
|
|
|
|
arr.foo = function () { return 42 }
|
|
|
|
|
return 42 === arr.foo()
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})()
|
|
|
|
|
if (!supportsAugment) {
|
|
|
|
|
xDataView = TA.DataView
|
|
|
|
|
xArrayBuffer = TA.ArrayBuffer
|
|
|
|
|
xUint8Array = TA.Uint8Array
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class: Buffer
|
|
|
|
|
* =============
|
|
|
|
|
*
|
|
|
|
|
* The Buffer constructor returns instances of `Uint8Array` that are augmented
|
|
|
|
|
* with function properties for all the node `Buffer` API functions. We use
|
|
|
|
|
* `Uint8Array` so that square bracket notation works as expected -- it returns
|
|
|
|
|
* a single octet.
|
|
|
|
|
*
|
|
|
|
|
* By augmenting the instances, we can avoid modifying the `Uint8Array`
|
|
|
|
|
* prototype.
|
|
|
|
|
*/
|
|
|
|
|
function Buffer (subject, encoding) {
|
|
|
|
|
var type = typeof subject
|
|
|
|
|
|
|
|
|
|
// Work-around: node's base64 implementation
|
|
|
|
|
// allows for non-padded strings while base64-js
|
|
|
|
|
// does not..
|
|
|
|
|
if (encoding === 'base64' && type === 'string') {
|
|
|
|
|
subject = stringtrim(subject)
|
|
|
|
|
while (subject.length % 4 !== 0) {
|
|
|
|
|
subject = subject + '='
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find the length
|
|
|
|
|
var length
|
|
|
|
|
if (type === 'number')
|
|
|
|
|
length = coerce(subject)
|
|
|
|
|
else if (type === 'string')
|
|
|
|
|
length = Buffer.byteLength(subject, encoding)
|
|
|
|
|
else if (type === 'object')
|
|
|
|
|
length = coerce(subject.length) // Assume object is an array
|
|
|
|
|
else
|
|
|
|
|
throw new Error('First argument needs to be a number, array or string.')
|
|
|
|
|
|
|
|
|
|
var buf = augment(new xUint8Array(length))
|
|
|
|
|
if (Buffer.isBuffer(subject)) {
|
|
|
|
|
// Speed optimization -- use set if we're copying from a Uint8Array
|
|
|
|
|
buf.set(subject)
|
|
|
|
|
} else if (isArrayIsh(subject)) {
|
|
|
|
|
// Treat array-ish objects as a byte array.
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
if (Buffer.isBuffer(subject))
|
|
|
|
|
buf[i] = subject.readUInt8(i)
|
|
|
|
|
else
|
|
|
|
|
buf[i] = subject[i]
|
|
|
|
|
}
|
|
|
|
|
} else if (type === 'string') {
|
|
|
|
|
buf.write(subject, 0, encoding)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// STATIC METHODS
|
|
|
|
|
// ==============
|
|
|
|
|
|
|
|
|
|
Buffer.isEncoding = function(encoding) {
|
|
|
|
|
switch ((encoding + '').toLowerCase()) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
case 'ascii':
|
|
|
|
|
case 'binary':
|
|
|
|
|
case 'base64':
|
|
|
|
|
case 'ucs2':
|
|
|
|
|
case 'ucs-2':
|
|
|
|
|
case 'utf16le':
|
|
|
|
|
case 'utf-16le':
|
|
|
|
|
case 'raw':
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.isBuffer = function (b) {
|
|
|
|
|
return b && b._isBuffer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.byteLength = function (str, encoding) {
|
|
|
|
|
switch (encoding || 'utf8') {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return str.length / 2
|
|
|
|
|
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
return utf8ToBytes(str).length
|
|
|
|
|
|
|
|
|
|
case 'ascii':
|
|
|
|
|
case 'binary':
|
|
|
|
|
return str.length
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return base64ToBytes(str).length
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown encoding')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.concat = function (list, totalLength) {
|
|
|
|
|
if (!isArray(list)) {
|
|
|
|
|
throw new Error('Usage: Buffer.concat(list, [totalLength])\n' +
|
|
|
|
|
'list should be an Array.')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var i
|
|
|
|
|
var buf
|
|
|
|
|
|
|
|
|
|
if (list.length === 0) {
|
|
|
|
|
return new Buffer(0)
|
|
|
|
|
} else if (list.length === 1) {
|
|
|
|
|
return list[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof totalLength !== 'number') {
|
|
|
|
|
totalLength = 0
|
|
|
|
|
for (i = 0; i < list.length; i++) {
|
|
|
|
|
buf = list[i]
|
|
|
|
|
totalLength += buf.length
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var buffer = new Buffer(totalLength)
|
|
|
|
|
var pos = 0
|
|
|
|
|
for (i = 0; i < list.length; i++) {
|
|
|
|
|
buf = list[i]
|
|
|
|
|
buf.copy(buffer, pos)
|
|
|
|
|
pos += buf.length
|
|
|
|
|
}
|
|
|
|
|
return buffer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BUFFER INSTANCE METHODS
|
|
|
|
|
// =======================
|
|
|
|
|
|
|
|
|
|
function _hexWrite (buf, string, offset, length) {
|
|
|
|
|
offset = Number(offset) || 0
|
|
|
|
|
var remaining = buf.length - offset
|
|
|
|
|
if (!length) {
|
|
|
|
|
length = remaining
|
|
|
|
|
} else {
|
|
|
|
|
length = Number(length)
|
|
|
|
|
if (length > remaining) {
|
|
|
|
|
length = remaining
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// must be an even number of digits
|
|
|
|
|
var strLen = string.length
|
|
|
|
|
if (strLen % 2 !== 0) {
|
|
|
|
|
throw new Error('Invalid hex string')
|
|
|
|
|
}
|
|
|
|
|
if (length > strLen / 2) {
|
|
|
|
|
length = strLen / 2
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
var byte = parseInt(string.substr(i * 2, 2), 16)
|
|
|
|
|
if (isNaN(byte)) throw new Error('Invalid hex string')
|
|
|
|
|
buf[offset + i] = byte
|
|
|
|
|
}
|
|
|
|
|
Buffer._charsWritten = i * 2
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _utf8Write (buf, string, offset, length) {
|
|
|
|
|
var bytes, pos
|
|
|
|
|
return Buffer._charsWritten = blitBuffer(utf8ToBytes(string), buf, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _asciiWrite (buf, string, offset, length) {
|
|
|
|
|
var bytes, pos
|
|
|
|
|
return Buffer._charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _binaryWrite (buf, string, offset, length) {
|
|
|
|
|
return _asciiWrite(buf, string, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _base64Write (buf, string, offset, length) {
|
|
|
|
|
var bytes, pos
|
|
|
|
|
return Buffer._charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWrite (string, offset, length, encoding) {
|
|
|
|
|
// Support both (string, offset, length, encoding)
|
|
|
|
|
// and the legacy (string, encoding, offset, length)
|
|
|
|
|
if (isFinite(offset)) {
|
|
|
|
|
if (!isFinite(length)) {
|
|
|
|
|
encoding = length
|
|
|
|
|
length = undefined
|
|
|
|
|
}
|
|
|
|
|
} else { // legacy
|
|
|
|
|
var swap = encoding
|
|
|
|
|
encoding = offset
|
|
|
|
|
offset = length
|
|
|
|
|
length = swap
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset = Number(offset) || 0
|
|
|
|
|
var remaining = this.length - offset
|
|
|
|
|
if (!length) {
|
|
|
|
|
length = remaining
|
|
|
|
|
} else {
|
|
|
|
|
length = Number(length)
|
|
|
|
|
if (length > remaining) {
|
|
|
|
|
length = remaining
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
encoding = String(encoding || 'utf8').toLowerCase()
|
|
|
|
|
|
|
|
|
|
switch (encoding) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return _hexWrite(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
return _utf8Write(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'ascii':
|
|
|
|
|
return _asciiWrite(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'binary':
|
|
|
|
|
return _binaryWrite(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return _base64Write(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown encoding')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferToString (encoding, start, end) {
|
|
|
|
|
var self = this
|
|
|
|
|
|
|
|
|
|
encoding = String(encoding || 'utf8').toLowerCase()
|
|
|
|
|
start = Number(start) || 0
|
|
|
|
|
end = (end !== undefined)
|
|
|
|
|
? Number(end)
|
|
|
|
|
: end = self.length
|
|
|
|
|
|
|
|
|
|
// Fastpath empty strings
|
|
|
|
|
if (end === start)
|
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
|
switch (encoding) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return _hexSlice(self, start, end)
|
|
|
|
|
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
return _utf8Slice(self, start, end)
|
|
|
|
|
|
|
|
|
|
case 'ascii':
|
|
|
|
|
return _asciiSlice(self, start, end)
|
|
|
|
|
|
|
|
|
|
case 'binary':
|
|
|
|
|
return _binarySlice(self, start, end)
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return _base64Slice(self, start, end)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown encoding')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferToJSON () {
|
|
|
|
|
return {
|
|
|
|
|
type: 'Buffer',
|
|
|
|
|
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
|
|
|
function BufferCopy (target, target_start, start, end) {
|
|
|
|
|
var source = this
|
|
|
|
|
|
|
|
|
|
if (!start) start = 0
|
|
|
|
|
if (!end && end !== 0) end = this.length
|
|
|
|
|
if (!target_start) target_start = 0
|
|
|
|
|
|
|
|
|
|
// Copy 0 bytes; we're done
|
|
|
|
|
if (end === start) return
|
|
|
|
|
if (target.length === 0 || source.length === 0) return
|
|
|
|
|
|
|
|
|
|
// Fatal error conditions
|
|
|
|
|
if (end < start)
|
|
|
|
|
throw new Error('sourceEnd < sourceStart')
|
|
|
|
|
if (target_start < 0 || target_start >= target.length)
|
|
|
|
|
throw new Error('targetStart out of bounds')
|
|
|
|
|
if (start < 0 || start >= source.length)
|
|
|
|
|
throw new Error('sourceStart out of bounds')
|
|
|
|
|
if (end < 0 || end > source.length)
|
|
|
|
|
throw new Error('sourceEnd out of bounds')
|
|
|
|
|
|
|
|
|
|
// Are we oob?
|
|
|
|
|
if (end > this.length)
|
|
|
|
|
end = this.length
|
|
|
|
|
if (target.length - target_start < end - start)
|
|
|
|
|
end = target.length - target_start + start
|
|
|
|
|
|
|
|
|
|
// copy!
|
|
|
|
|
for (var i = 0; i < end - start; i++)
|
|
|
|
|
target[i + target_start] = this[i + start]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _base64Slice (buf, start, end) {
|
|
|
|
|
if (start === 0 && end === buf.length) {
|
|
|
|
|
return base64.fromByteArray(buf)
|
|
|
|
|
} else {
|
|
|
|
|
return base64.fromByteArray(buf.slice(start, end))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _utf8Slice (buf, start, end) {
|
|
|
|
|
var res = ''
|
|
|
|
|
var tmp = ''
|
|
|
|
|
end = Math.min(buf.length, end)
|
|
|
|
|
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
if (buf[i] <= 0x7F) {
|
|
|
|
|
res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
|
|
|
|
|
tmp = ''
|
|
|
|
|
} else {
|
|
|
|
|
tmp += '%' + buf[i].toString(16)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res + decodeUtf8Char(tmp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _asciiSlice (buf, start, end) {
|
|
|
|
|
var ret = ''
|
|
|
|
|
end = Math.min(buf.length, end)
|
|
|
|
|
|
|
|
|
|
for (var i = start; i < end; i++)
|
|
|
|
|
ret += String.fromCharCode(buf[i])
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _binarySlice (buf, start, end) {
|
|
|
|
|
return _asciiSlice(buf, start, end)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _hexSlice (buf, start, end) {
|
|
|
|
|
var len = buf.length
|
|
|
|
|
|
|
|
|
|
if (!start || start < 0) start = 0
|
|
|
|
|
if (!end || end < 0 || end > len) end = len
|
|
|
|
|
|
|
|
|
|
var out = ''
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
out += toHex(buf[i])
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: add test that modifying the new buffer slice will modify memory in the
|
|
|
|
|
// original buffer! Use code from:
|
|
|
|
|
// http://nodejs.org/api/buffer.html#buffer_buf_slice_start_end
|
|
|
|
|
function BufferSlice (start, end) {
|
|
|
|
|
var len = this.length
|
|
|
|
|
start = clamp(start, len, 0)
|
|
|
|
|
end = clamp(end, len, len)
|
|
|
|
|
return augment(this.subarray(start, end)) // Uint8Array built-in method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt8 (offset, noAssert) {
|
|
|
|
|
var buf = this
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buf.length)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
return buf[offset]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readUInt16 (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 1 === len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(2))
|
|
|
|
|
dv.setUint8(0, buf[len - 1])
|
|
|
|
|
return dv.getUint16(0, littleEndian)
|
|
|
|
|
} else {
|
|
|
|
|
return buf._dataview.getUint16(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt16LE (offset, noAssert) {
|
|
|
|
|
return _readUInt16(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt16BE (offset, noAssert) {
|
|
|
|
|
return _readUInt16(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readUInt32 (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
dv.setUint8(i, buf[i + offset])
|
|
|
|
|
}
|
|
|
|
|
return dv.getUint32(0, littleEndian)
|
|
|
|
|
} else {
|
|
|
|
|
return buf._dataview.getUint32(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt32LE (offset, noAssert) {
|
|
|
|
|
return _readUInt32(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt32BE (offset, noAssert) {
|
|
|
|
|
return _readUInt32(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt8 (offset, noAssert) {
|
|
|
|
|
var buf = this
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset')
|
|
|
|
|
assert(offset < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buf.length)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
return buf._dataview.getInt8(offset)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readInt16 (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset')
|
|
|
|
|
assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 1 === len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(2))
|
|
|
|
|
dv.setUint8(0, buf[len - 1])
|
|
|
|
|
return dv.getInt16(0, littleEndian)
|
|
|
|
|
} else {
|
|
|
|
|
return buf._dataview.getInt16(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt16LE (offset, noAssert) {
|
|
|
|
|
return _readInt16(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt16BE (offset, noAssert) {
|
|
|
|
|
return _readInt16(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readInt32 (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
dv.setUint8(i, buf[i + offset])
|
|
|
|
|
}
|
|
|
|
|
return dv.getInt32(0, littleEndian)
|
|
|
|
|
} else {
|
|
|
|
|
return buf._dataview.getInt32(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt32LE (offset, noAssert) {
|
|
|
|
|
return _readInt32(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt32BE (offset, noAssert) {
|
|
|
|
|
return _readInt32(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readFloat (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf._dataview.getFloat32(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadFloatLE (offset, noAssert) {
|
|
|
|
|
return _readFloat(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadFloatBE (offset, noAssert) {
|
|
|
|
|
return _readFloat(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readDouble (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf._dataview.getFloat64(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadDoubleLE (offset, noAssert) {
|
|
|
|
|
return _readDouble(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadDoubleBE (offset, noAssert) {
|
|
|
|
|
return _readDouble(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt8 (value, offset, noAssert) {
|
|
|
|
|
var buf = this
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset < buf.length, 'trying to write beyond buffer length')
|
|
|
|
|
verifuint(value, 0xff)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buf.length) return
|
|
|
|
|
|
|
|
|
|
buf[offset] = value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeUInt16 (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
|
|
|
|
|
verifuint(value, 0xffff)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 1 === len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(2))
|
|
|
|
|
dv.setUint16(0, value, littleEndian)
|
|
|
|
|
buf[offset] = dv.getUint8(0)
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setUint16(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt16LE (value, offset, noAssert) {
|
|
|
|
|
_writeUInt16(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt16BE (value, offset, noAssert) {
|
|
|
|
|
_writeUInt16(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeUInt32 (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'trying to write beyond buffer length')
|
|
|
|
|
verifuint(value, 0xffffffff)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
dv.setUint32(0, value, littleEndian)
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
buf[i + offset] = dv.getUint8(i)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setUint32(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt32LE (value, offset, noAssert) {
|
|
|
|
|
_writeUInt32(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt32BE (value, offset, noAssert) {
|
|
|
|
|
_writeUInt32(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt8 (value, offset, noAssert) {
|
|
|
|
|
var buf = this
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset < buf.length, 'Trying to write beyond buffer length')
|
|
|
|
|
verifsint(value, 0x7f, -0x80)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buf.length) return
|
|
|
|
|
|
|
|
|
|
buf._dataview.setInt8(offset, value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeInt16 (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')
|
|
|
|
|
verifsint(value, 0x7fff, -0x8000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 1 === len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(2))
|
|
|
|
|
dv.setInt16(0, value, littleEndian)
|
|
|
|
|
buf[offset] = dv.getUint8(0)
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setInt16(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt16LE (value, offset, noAssert) {
|
|
|
|
|
_writeInt16(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt16BE (value, offset, noAssert) {
|
|
|
|
|
_writeInt16(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeInt32 (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
|
|
|
|
|
verifsint(value, 0x7fffffff, -0x80000000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
dv.setInt32(0, value, littleEndian)
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
buf[i + offset] = dv.getUint8(i)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setInt32(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt32LE (value, offset, noAssert) {
|
|
|
|
|
_writeInt32(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt32BE (value, offset, noAssert) {
|
|
|
|
|
_writeInt32(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
|
|
|
|
|
verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
dv.setFloat32(0, value, littleEndian)
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
buf[i + offset] = dv.getUint8(i)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setFloat32(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteFloatLE (value, offset, noAssert) {
|
|
|
|
|
_writeFloat(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteFloatBE (value, offset, noAssert) {
|
|
|
|
|
_writeFloat(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 7 < buf.length,
|
|
|
|
|
'Trying to write beyond buffer length')
|
|
|
|
|
verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 7 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(8))
|
|
|
|
|
dv.setFloat64(0, value, littleEndian)
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
buf[i + offset] = dv.getUint8(i)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setFloat64(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteDoubleLE (value, offset, noAssert) {
|
|
|
|
|
_writeDouble(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteDoubleBE (value, offset, noAssert) {
|
|
|
|
|
_writeDouble(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fill(value, start=0, end=buffer.length)
|
|
|
|
|
function BufferFill (value, start, end) {
|
|
|
|
|
if (!value) value = 0
|
|
|
|
|
if (!start) start = 0
|
|
|
|
|
if (!end) end = this.length
|
|
|
|
|
|
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
|
value = value.charCodeAt(0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof value !== 'number' || isNaN(value)) {
|
|
|
|
|
throw new Error('value is not a number')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end < start) throw new Error('end < start')
|
|
|
|
|
|
|
|
|
|
// Fill 0 bytes; we're done
|
|
|
|
|
if (end === start) return
|
|
|
|
|
if (this.length === 0) return
|
|
|
|
|
|
|
|
|
|
if (start < 0 || start >= this.length) {
|
|
|
|
|
throw new Error('start out of bounds')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end < 0 || end > this.length) {
|
|
|
|
|
throw new Error('end out of bounds')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
this[i] = value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferInspect () {
|
|
|
|
|
var out = []
|
|
|
|
|
var len = this.length
|
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
|
|
|
out[i] = toHex(this[i])
|
|
|
|
|
if (i === exports.INSPECT_MAX_BYTES) {
|
|
|
|
|
out[i + 1] = '...'
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return '<Buffer ' + out.join(' ') + '>'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
|
|
|
|
|
// Added in Node 0.12.
|
|
|
|
|
function BufferToArrayBuffer () {
|
|
|
|
|
return (new Buffer(this)).buffer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HELPER FUNCTIONS
|
|
|
|
|
// ================
|
|
|
|
|
|
|
|
|
|
function stringtrim (str) {
|
|
|
|
|
if (str.trim) return str.trim()
|
|
|
|
|
return str.replace(/^\s+|\s+$/g, '')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function augment (arr) {
|
|
|
|
|
arr._isBuffer = true
|
|
|
|
|
|
|
|
|
|
// Augment the Uint8Array *instance* (not the class!) with Buffer methods
|
|
|
|
|
arr.write = BufferWrite
|
|
|
|
|
arr.toString = BufferToString
|
|
|
|
|
arr.toLocaleString = BufferToString
|
|
|
|
|
arr.toJSON = BufferToJSON
|
|
|
|
|
arr.copy = BufferCopy
|
|
|
|
|
arr.slice = BufferSlice
|
|
|
|
|
arr.readUInt8 = BufferReadUInt8
|
|
|
|
|
arr.readUInt16LE = BufferReadUInt16LE
|
|
|
|
|
arr.readUInt16BE = BufferReadUInt16BE
|
|
|
|
|
arr.readUInt32LE = BufferReadUInt32LE
|
|
|
|
|
arr.readUInt32BE = BufferReadUInt32BE
|
|
|
|
|
arr.readInt8 = BufferReadInt8
|
|
|
|
|
arr.readInt16LE = BufferReadInt16LE
|
|
|
|
|
arr.readInt16BE = BufferReadInt16BE
|
|
|
|
|
arr.readInt32LE = BufferReadInt32LE
|
|
|
|
|
arr.readInt32BE = BufferReadInt32BE
|
|
|
|
|
arr.readFloatLE = BufferReadFloatLE
|
|
|
|
|
arr.readFloatBE = BufferReadFloatBE
|
|
|
|
|
arr.readDoubleLE = BufferReadDoubleLE
|
|
|
|
|
arr.readDoubleBE = BufferReadDoubleBE
|
|
|
|
|
arr.writeUInt8 = BufferWriteUInt8
|
|
|
|
|
arr.writeUInt16LE = BufferWriteUInt16LE
|
|
|
|
|
arr.writeUInt16BE = BufferWriteUInt16BE
|
|
|
|
|
arr.writeUInt32LE = BufferWriteUInt32LE
|
|
|
|
|
arr.writeUInt32BE = BufferWriteUInt32BE
|
|
|
|
|
arr.writeInt8 = BufferWriteInt8
|
|
|
|
|
arr.writeInt16LE = BufferWriteInt16LE
|
|
|
|
|
arr.writeInt16BE = BufferWriteInt16BE
|
|
|
|
|
arr.writeInt32LE = BufferWriteInt32LE
|
|
|
|
|
arr.writeInt32BE = BufferWriteInt32BE
|
|
|
|
|
arr.writeFloatLE = BufferWriteFloatLE
|
|
|
|
|
arr.writeFloatBE = BufferWriteFloatBE
|
|
|
|
|
arr.writeDoubleLE = BufferWriteDoubleLE
|
|
|
|
|
arr.writeDoubleBE = BufferWriteDoubleBE
|
|
|
|
|
arr.fill = BufferFill
|
|
|
|
|
arr.inspect = BufferInspect
|
|
|
|
|
|
|
|
|
|
// Only add `toArrayBuffer` if the browser supports ArrayBuffer natively
|
|
|
|
|
if (xUint8Array !== TA.Uint8Array)
|
|
|
|
|
arr.toArrayBuffer = BufferToArrayBuffer
|
|
|
|
|
|
|
|
|
|
if (arr.byteLength !== 0)
|
|
|
|
|
arr._dataview = new xDataView(arr.buffer, arr.byteOffset, arr.byteLength)
|
|
|
|
|
|
|
|
|
|
return arr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// slice(start, end)
|
|
|
|
|
function clamp (index, len, defaultValue) {
|
|
|
|
|
if (typeof index !== 'number') return defaultValue
|
|
|
|
|
index = ~~index; // Coerce to integer.
|
|
|
|
|
if (index >= len) return len
|
|
|
|
|
if (index >= 0) return index
|
|
|
|
|
index += len
|
|
|
|
|
if (index >= 0) return index
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function coerce (length) {
|
|
|
|
|
// Coerce length to a number (possibly NaN), round up
|
|
|
|
|
// in case it's fractional (e.g. 123.456) then do a
|
|
|
|
|
// double negate to coerce a NaN to 0. Easy, right?
|
|
|
|
|
length = ~~Math.ceil(+length)
|
|
|
|
|
return length < 0 ? 0 : length
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isArray (subject) {
|
|
|
|
|
return (Array.isArray || function (subject) {
|
|
|
|
|
return Object.prototype.toString.call(subject) === '[object Array]'
|
|
|
|
|
})(subject)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isArrayIsh (subject) {
|
|
|
|
|
return isArray(subject) || Buffer.isBuffer(subject) ||
|
|
|
|
|
subject && typeof subject === 'object' &&
|
|
|
|
|
typeof subject.length === 'number'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toHex (n) {
|
|
|
|
|
if (n < 16) return '0' + n.toString(16)
|
|
|
|
|
return n.toString(16)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function utf8ToBytes (str) {
|
|
|
|
|
var byteArray = []
|
|
|
|
|
for (var i = 0; i < str.length; i++)
|
|
|
|
|
if (str.charCodeAt(i) <= 0x7F)
|
|
|
|
|
byteArray.push(str.charCodeAt(i))
|
|
|
|
|
else {
|
|
|
|
|
var h = encodeURIComponent(str.charAt(i)).substr(1).split('%')
|
|
|
|
|
for (var j = 0; j < h.length; j++)
|
|
|
|
|
byteArray.push(parseInt(h[j], 16))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return byteArray
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function asciiToBytes (str) {
|
|
|
|
|
var byteArray = []
|
|
|
|
|
for (var i = 0; i < str.length; i++) {
|
|
|
|
|
// Node's code seems to be doing this and not & 0x7F..
|
|
|
|
|
byteArray.push(str.charCodeAt(i) & 0xFF)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return byteArray
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function base64ToBytes (str) {
|
|
|
|
|
return base64.toByteArray(str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function blitBuffer (src, dst, offset, length) {
|
|
|
|
|
var pos
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
if ((i + offset >= dst.length) || (i >= src.length))
|
|
|
|
|
break
|
|
|
|
|
dst[i + offset] = src[i]
|
|
|
|
|
}
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function decodeUtf8Char (str) {
|
|
|
|
|
try {
|
|
|
|
|
return decodeURIComponent(str)
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return String.fromCharCode(0xFFFD) // UTF 8 invalid char
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We have to make sure that the value is a valid integer. This means that it
|
|
|
|
|
* is non-negative. It has no fractional component and that it does not
|
|
|
|
|
* exceed the maximum allowed value.
|
|
|
|
|
*
|
|
|
|
|
* value The number to check for validity
|
|
|
|
|
*
|
|
|
|
|
* max The maximum value
|
|
|
|
|
*/
|
|
|
|
|
function verifuint (value, max) {
|
|
|
|
|
assert(typeof (value) == 'number', 'cannot write a non-number as a number')
|
|
|
|
|
assert(value >= 0,
|
|
|
|
|
'specified a negative value for writing an unsigned value')
|
|
|
|
|
assert(value <= max, 'value is larger than maximum value for type')
|
|
|
|
|
assert(Math.floor(value) === value, 'value has a fractional component')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A series of checks to make sure we actually have a signed 32-bit number
|
|
|
|
|
*/
|
|
|
|
|
function verifsint(value, max, min) {
|
|
|
|
|
assert(typeof (value) == 'number', 'cannot write a non-number as a number')
|
|
|
|
|
assert(value <= max, 'value larger than maximum allowed value')
|
|
|
|
|
assert(value >= min, 'value smaller than minimum allowed value')
|
|
|
|
|
assert(Math.floor(value) === value, 'value has a fractional component')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function verifIEEE754(value, max, min) {
|
|
|
|
|
assert(typeof (value) == 'number', 'cannot write a non-number as a number')
|
|
|
|
|
assert(value <= max, 'value larger than maximum allowed value')
|
|
|
|
|
assert(value >= min, 'value smaller than minimum allowed value')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assert (test, message) {
|
|
|
|
|
if (!test) throw new Error(message || 'Failed assertion')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},{"base64-js":3,"typedarray":4}],"native-buffer-browserify":[function(require,module,exports){
|
|
|
|
|
module.exports=require('26sEV7');
|
|
|
|
|
},{}],3:[function(require,module,exports){
|
|
|
|
|
(function (exports) {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
|
|
|
|
|
|
|
|
function b64ToByteArray(b64) {
|
|
|
|
|
var i, j, l, tmp, placeHolders, arr;
|
|
|
|
|
|
|
|
|
|
if (b64.length % 4 > 0) {
|
|
|
|
|
throw 'Invalid string. Length must be a multiple of 4';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the number of equal signs (place holders)
|
|
|
|
|
// if there are two placeholders, than the two characters before it
|
|
|
|
|
// represent one byte
|
|
|
|
|
// if there is only one, then the three characters before it represent 2 bytes
|
|
|
|
|
// this is just a cheap hack to not do indexOf twice
|
|
|
|
|
placeHolders = indexOf(b64, '=');
|
|
|
|
|
placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
|
|
|
|
|
|
|
|
|
|
// base64 is 4/3 + up to two characters of the original data
|
|
|
|
|
arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
|
|
|
|
|
|
|
|
|
|
// if there are placeholders, only get up to the last complete 4 chars
|
|
|
|
|
l = placeHolders > 0 ? b64.length - 4 : b64.length;
|
|
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
|
|
|
|
tmp = (indexOf(lookup, b64.charAt(i)) << 18) | (indexOf(lookup, b64.charAt(i + 1)) << 12) | (indexOf(lookup, b64.charAt(i + 2)) << 6) | indexOf(lookup, b64.charAt(i + 3));
|
|
|
|
|
arr.push((tmp & 0xFF0000) >> 16);
|
|
|
|
|
arr.push((tmp & 0xFF00) >> 8);
|
|
|
|
|
arr.push(tmp & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (placeHolders === 2) {
|
|
|
|
|
tmp = (indexOf(lookup, b64.charAt(i)) << 2) | (indexOf(lookup, b64.charAt(i + 1)) >> 4);
|
|
|
|
|
arr.push(tmp & 0xFF);
|
|
|
|
|
} else if (placeHolders === 1) {
|
|
|
|
|
tmp = (indexOf(lookup, b64.charAt(i)) << 10) | (indexOf(lookup, b64.charAt(i + 1)) << 4) | (indexOf(lookup, b64.charAt(i + 2)) >> 2);
|
|
|
|
|
arr.push((tmp >> 8) & 0xFF);
|
|
|
|
|
arr.push(tmp & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function uint8ToBase64(uint8) {
|
|
|
|
|
var i,
|
|
|
|
|
extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
|
|
|
|
|
output = "",
|
|
|
|
|
temp, length;
|
|
|
|
|
|
|
|
|
|
function tripletToBase64 (num) {
|
|
|
|
|
return lookup.charAt(num >> 18 & 0x3F) + lookup.charAt(num >> 12 & 0x3F) + lookup.charAt(num >> 6 & 0x3F) + lookup.charAt(num & 0x3F);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
|
|
|
for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
|
|
|
|
|
temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
|
|
|
|
|
output += tripletToBase64(temp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
|
|
|
switch (extraBytes) {
|
|
|
|
|
case 1:
|
|
|
|
|
temp = uint8[uint8.length - 1];
|
|
|
|
|
output += lookup.charAt(temp >> 2);
|
|
|
|
|
output += lookup.charAt((temp << 4) & 0x3F);
|
|
|
|
|
output += '==';
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
|
|
|
|
|
output += lookup.charAt(temp >> 10);
|
|
|
|
|
output += lookup.charAt((temp >> 4) & 0x3F);
|
|
|
|
|
output += lookup.charAt((temp << 2) & 0x3F);
|
|
|
|
|
output += '=';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports.toByteArray = b64ToByteArray;
|
|
|
|
|
module.exports.fromByteArray = uint8ToBase64;
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
function indexOf (arr, elt /*, from*/) {
|
|
|
|
|
var len = arr.length;
|
|
|
|
|
|
|
|
|
|
var from = Number(arguments[1]) || 0;
|
|
|
|
|
from = (from < 0)
|
|
|
|
|
? Math.ceil(from)
|
|
|
|
|
: Math.floor(from);
|
|
|
|
|
if (from < 0)
|
|
|
|
|
from += len;
|
|
|
|
|
|
|
|
|
|
for (; from < len; from++) {
|
|
|
|
|
if ((typeof arr === 'string' && arr.charAt(from) === elt) ||
|
|
|
|
|
(typeof arr !== 'string' && arr[from] === elt)) {
|
|
|
|
|
return from;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},{}],4:[function(require,module,exports){
|
|
|
|
|
var undefined = (void 0); // Paranoia
|
|
|
|
|
|
|
|
|
|
// Beyond this value, index getters/setters (i.e. array[0], array[1]) are so slow to
|
|
|
|
|
// create, and consume so much memory, that the browser appears frozen.
|
|
|
|
|
var MAX_ARRAY_LENGTH = 1e5;
|
|
|
|
|
|
|
|
|
|
// Approximations of internal ECMAScript conversion functions
|
|
|
|
|
var ECMAScript = (function() {
|
|
|
|
|
// Stash a copy in case other scripts modify these
|
|
|
|
|
var opts = Object.prototype.toString,
|
|
|
|
|
ophop = Object.prototype.hasOwnProperty;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
// Class returns internal [[Class]] property, used to avoid cross-frame instanceof issues:
|
|
|
|
|
Class: function(v) { return opts.call(v).replace(/^\[object *|\]$/g, ''); },
|
|
|
|
|
HasProperty: function(o, p) { return p in o; },
|
|
|
|
|
HasOwnProperty: function(o, p) { return ophop.call(o, p); },
|
|
|
|
|
IsCallable: function(o) { return typeof o === 'function'; },
|
|
|
|
|
ToInt32: function(v) { return v >> 0; },
|
|
|
|
|
ToUint32: function(v) { return v >>> 0; }
|
|
|
|
|
};
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
// Snapshot intrinsics
|
|
|
|
|
var LN2 = Math.LN2,
|
|
|
|
|
abs = Math.abs,
|
|
|
|
|
floor = Math.floor,
|
|
|
|
|
log = Math.log,
|
|
|
|
|
min = Math.min,
|
|
|
|
|
pow = Math.pow,
|
|
|
|
|
round = Math.round;
|
|
|
|
|
|
|
|
|
|
// ES5: lock down object properties
|
|
|
|
|
function configureProperties(obj) {
|
|
|
|
|
if (getOwnPropNames && defineProp) {
|
|
|
|
|
var props = getOwnPropNames(obj), i;
|
|
|
|
|
for (i = 0; i < props.length; i += 1) {
|
|
|
|
|
defineProp(obj, props[i], {
|
|
|
|
|
value: obj[props[i]],
|
|
|
|
|
writable: false,
|
|
|
|
|
enumerable: false,
|
|
|
|
|
configurable: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// emulate ES5 getter/setter API using legacy APIs
|
|
|
|
|
// http://blogs.msdn.com/b/ie/archive/2010/09/07/transitioning-existing-code-to-the-es5-getter-setter-apis.aspx
|
|
|
|
|
// (second clause tests for Object.defineProperty() in IE<9 that only supports extending DOM prototypes, but
|
|
|
|
|
// note that IE<9 does not support __defineGetter__ or __defineSetter__ so it just renders the method harmless)
|
|
|
|
|
var defineProp
|
|
|
|
|
if (Object.defineProperty && (function() {
|
|
|
|
|
try {
|
|
|
|
|
Object.defineProperty({}, 'x', {});
|
|
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
})()) {
|
|
|
|
|
defineProp = Object.defineProperty;
|
|
|
|
|
} else {
|
|
|
|
|
defineProp = function(o, p, desc) {
|
|
|
|
|
if (!o === Object(o)) throw new TypeError("Object.defineProperty called on non-object");
|
|
|
|
|
if (ECMAScript.HasProperty(desc, 'get') && Object.prototype.__defineGetter__) { Object.prototype.__defineGetter__.call(o, p, desc.get); }
|
|
|
|
|
if (ECMAScript.HasProperty(desc, 'set') && Object.prototype.__defineSetter__) { Object.prototype.__defineSetter__.call(o, p, desc.set); }
|
|
|
|
|
if (ECMAScript.HasProperty(desc, 'value')) { o[p] = desc.value; }
|
|
|
|
|
return o;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var getOwnPropNames = Object.getOwnPropertyNames || function (o) {
|
|
|
|
|
if (o !== Object(o)) throw new TypeError("Object.getOwnPropertyNames called on non-object");
|
|
|
|
|
var props = [], p;
|
|
|
|
|
for (p in o) {
|
|
|
|
|
if (ECMAScript.HasOwnProperty(o, p)) {
|
|
|
|
|
props.push(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return props;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ES5: Make obj[index] an alias for obj._getter(index)/obj._setter(index, value)
|
|
|
|
|
// for index in 0 ... obj.length
|
|
|
|
|
function makeArrayAccessors(obj) {
|
|
|
|
|
if (!defineProp) { return; }
|
|
|
|
|
|
|
|
|
|
if (obj.length > MAX_ARRAY_LENGTH) throw new RangeError("Array too large for polyfill");
|
|
|
|
|
|
|
|
|
|
function makeArrayAccessor(index) {
|
|
|
|
|
defineProp(obj, index, {
|
|
|
|
|
'get': function() { return obj._getter(index); },
|
|
|
|
|
'set': function(v) { obj._setter(index, v); },
|
|
|
|
|
enumerable: true,
|
|
|
|
|
configurable: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var i;
|
|
|
|
|
for (i = 0; i < obj.length; i += 1) {
|
|
|
|
|
makeArrayAccessor(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Internal conversion functions:
|
|
|
|
|
// pack<Type>() - take a number (interpreted as Type), output a byte array
|
|
|
|
|
// unpack<Type>() - take a byte array, output a Type-like number
|
|
|
|
|
|
|
|
|
|
function as_signed(value, bits) { var s = 32 - bits; return (value << s) >> s; }
|
|
|
|
|
function as_unsigned(value, bits) { var s = 32 - bits; return (value << s) >>> s; }
|
|
|
|
|
|
|
|
|
|
function packI8(n) { return [n & 0xff]; }
|
|
|
|
|
function unpackI8(bytes) { return as_signed(bytes[0], 8); }
|
|
|
|
|
|
|
|
|
|
function packU8(n) { return [n & 0xff]; }
|
|
|
|
|
function unpackU8(bytes) { return as_unsigned(bytes[0], 8); }
|
|
|
|
|
|
|
|
|
|
function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; }
|
|
|
|
|
|
|
|
|
|
function packI16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
|
|
|
|
|
function unpackI16(bytes) { return as_signed(bytes[0] << 8 | bytes[1], 16); }
|
|
|
|
|
|
|
|
|
|
function packU16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
|
|
|
|
|
function unpackU16(bytes) { return as_unsigned(bytes[0] << 8 | bytes[1], 16); }
|
|
|
|
|
|
|
|
|
|
function packI32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
|
|
|
|
|
function unpackI32(bytes) { return as_signed(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
|
|
|
|
|
|
|
|
|
|
function packU32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
|
|
|
|
|
function unpackU32(bytes) { return as_unsigned(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
|
|
|
|
|
|
|
|
|
|
function packIEEE754(v, ebits, fbits) {
|
|
|
|
|
|
|
|
|
|
var bias = (1 << (ebits - 1)) - 1,
|
|
|
|
|
s, e, f, ln,
|
|
|
|
|
i, bits, str, bytes;
|
|
|
|
|
|
|
|
|
|
function roundToEven(n) {
|
|
|
|
|
var w = floor(n), f = n - w;
|
|
|
|
|
if (f < 0.5)
|
|
|
|
|
return w;
|
|
|
|
|
if (f > 0.5)
|
|
|
|
|
return w + 1;
|
|
|
|
|
return w % 2 ? w + 1 : w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compute sign, exponent, fraction
|
|
|
|
|
if (v !== v) {
|
|
|
|
|
// NaN
|
|
|
|
|
// http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping
|
|
|
|
|
e = (1 << ebits) - 1; f = pow(2, fbits - 1); s = 0;
|
|
|
|
|
} else if (v === Infinity || v === -Infinity) {
|
|
|
|
|
e = (1 << ebits) - 1; f = 0; s = (v < 0) ? 1 : 0;
|
|
|
|
|
} else if (v === 0) {
|
|
|
|
|
e = 0; f = 0; s = (1 / v === -Infinity) ? 1 : 0;
|
|
|
|
|
} else {
|
|
|
|
|
s = v < 0;
|
|
|
|
|
v = abs(v);
|
|
|
|
|
|
|
|
|
|
if (v >= pow(2, 1 - bias)) {
|
|
|
|
|
e = min(floor(log(v) / LN2), 1023);
|
|
|
|
|
f = roundToEven(v / pow(2, e) * pow(2, fbits));
|
|
|
|
|
if (f / pow(2, fbits) >= 2) {
|
|
|
|
|
e = e + 1;
|
|
|
|
|
f = 1;
|
|
|
|
|
}
|
|
|
|
|
if (e > bias) {
|
|
|
|
|
// Overflow
|
|
|
|
|
e = (1 << ebits) - 1;
|
|
|
|
|
f = 0;
|
|
|
|
|
} else {
|
|
|
|
|
// Normalized
|
|
|
|
|
e = e + bias;
|
|
|
|
|
f = f - pow(2, fbits);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Denormalized
|
|
|
|
|
e = 0;
|
|
|
|
|
f = roundToEven(v / pow(2, 1 - bias - fbits));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pack sign, exponent, fraction
|
|
|
|
|
bits = [];
|
|
|
|
|
for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = floor(f / 2); }
|
|
|
|
|
for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = floor(e / 2); }
|
|
|
|
|
bits.push(s ? 1 : 0);
|
|
|
|
|
bits.reverse();
|
|
|
|
|
str = bits.join('');
|
|
|
|
|
|
|
|
|
|
// Bits to bytes
|
|
|
|
|
bytes = [];
|
|
|
|
|
while (str.length) {
|
|
|
|
|
bytes.push(parseInt(str.substring(0, 8), 2));
|
|
|
|
|
str = str.substring(8);
|
|
|
|
|
}
|
|
|
|
|
return bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unpackIEEE754(bytes, ebits, fbits) {
|
|
|
|
|
|
|
|
|
|
// Bytes to bits
|
|
|
|
|
var bits = [], i, j, b, str,
|
|
|
|
|
bias, s, e, f;
|
|
|
|
|
|
|
|
|
|
for (i = bytes.length; i; i -= 1) {
|
|
|
|
|
b = bytes[i - 1];
|
|
|
|
|
for (j = 8; j; j -= 1) {
|
|
|
|
|
bits.push(b % 2 ? 1 : 0); b = b >> 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bits.reverse();
|
|
|
|
|
str = bits.join('');
|
|
|
|
|
|
|
|
|
|
// Unpack sign, exponent, fraction
|
|
|
|
|
bias = (1 << (ebits - 1)) - 1;
|
|
|
|
|
s = parseInt(str.substring(0, 1), 2) ? -1 : 1;
|
|
|
|
|
e = parseInt(str.substring(1, 1 + ebits), 2);
|
|
|
|
|
f = parseInt(str.substring(1 + ebits), 2);
|
|
|
|
|
|
|
|
|
|
// Produce number
|
|
|
|
|
if (e === (1 << ebits) - 1) {
|
|
|
|
|
return f !== 0 ? NaN : s * Infinity;
|
|
|
|
|
} else if (e > 0) {
|
|
|
|
|
// Normalized
|
|
|
|
|
return s * pow(2, e - bias) * (1 + f / pow(2, fbits));
|
|
|
|
|
} else if (f !== 0) {
|
|
|
|
|
// Denormalized
|
|
|
|
|
return s * pow(2, -(bias - 1)) * (f / pow(2, fbits));
|
|
|
|
|
} else {
|
|
|
|
|
return s < 0 ? -0 : 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unpackF64(b) { return unpackIEEE754(b, 11, 52); }
|
|
|
|
|
function packF64(v) { return packIEEE754(v, 11, 52); }
|
|
|
|
|
function unpackF32(b) { return unpackIEEE754(b, 8, 23); }
|
|
|
|
|
function packF32(v) { return packIEEE754(v, 8, 23); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 3 The ArrayBuffer Type
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
|
|
/** @constructor */
|
|
|
|
|
var ArrayBuffer = function ArrayBuffer(length) {
|
|
|
|
|
length = ECMAScript.ToInt32(length);
|
|
|
|
|
if (length < 0) throw new RangeError('ArrayBuffer size is not a small enough positive integer');
|
|
|
|
|
|
|
|
|
|
this.byteLength = length;
|
|
|
|
|
this._bytes = [];
|
|
|
|
|
this._bytes.length = length;
|
|
|
|
|
|
|
|
|
|
var i;
|
|
|
|
|
for (i = 0; i < this.byteLength; i += 1) {
|
|
|
|
|
this._bytes[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureProperties(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.ArrayBuffer = exports.ArrayBuffer || ArrayBuffer;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 4 The ArrayBufferView Type
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// NOTE: this constructor is not exported
|
|
|
|
|
/** @constructor */
|
|
|
|
|
var ArrayBufferView = function ArrayBufferView() {
|
|
|
|
|
//this.buffer = null;
|
|
|
|
|
//this.byteOffset = 0;
|
|
|
|
|
//this.byteLength = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 5 The Typed Array View Types
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
function makeConstructor(bytesPerElement, pack, unpack) {
|
|
|
|
|
// Each TypedArray type requires a distinct constructor instance with
|
|
|
|
|
// identical logic, which this produces.
|
|
|
|
|
|
|
|
|
|
var ctor;
|
|
|
|
|
ctor = function(buffer, byteOffset, length) {
|
|
|
|
|
var array, sequence, i, s;
|
|
|
|
|
|
|
|
|
|
if (!arguments.length || typeof arguments[0] === 'number') {
|
|
|
|
|
// Constructor(unsigned long length)
|
|
|
|
|
this.length = ECMAScript.ToInt32(arguments[0]);
|
|
|
|
|
if (length < 0) throw new RangeError('ArrayBufferView size is not a small enough positive integer');
|
|
|
|
|
|
|
|
|
|
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
this.buffer = new ArrayBuffer(this.byteLength);
|
|
|
|
|
this.byteOffset = 0;
|
|
|
|
|
} else if (typeof arguments[0] === 'object' && arguments[0].constructor === ctor) {
|
|
|
|
|
// Constructor(TypedArray array)
|
|
|
|
|
array = arguments[0];
|
|
|
|
|
|
|
|
|
|
this.length = array.length;
|
|
|
|
|
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
this.buffer = new ArrayBuffer(this.byteLength);
|
|
|
|
|
this.byteOffset = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < this.length; i += 1) {
|
|
|
|
|
this._setter(i, array._getter(i));
|
|
|
|
|
}
|
|
|
|
|
} else if (typeof arguments[0] === 'object' &&
|
|
|
|
|
!(arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
|
|
|
|
|
// Constructor(sequence<type> array)
|
|
|
|
|
sequence = arguments[0];
|
|
|
|
|
|
|
|
|
|
this.length = ECMAScript.ToUint32(sequence.length);
|
|
|
|
|
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
this.buffer = new ArrayBuffer(this.byteLength);
|
|
|
|
|
this.byteOffset = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < this.length; i += 1) {
|
|
|
|
|
s = sequence[i];
|
|
|
|
|
this._setter(i, Number(s));
|
|
|
|
|
}
|
|
|
|
|
} else if (typeof arguments[0] === 'object' &&
|
|
|
|
|
(arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
|
|
|
|
|
// Constructor(ArrayBuffer buffer,
|
|
|
|
|
// optional unsigned long byteOffset, optional unsigned long length)
|
|
|
|
|
this.buffer = buffer;
|
|
|
|
|
|
|
|
|
|
this.byteOffset = ECMAScript.ToUint32(byteOffset);
|
|
|
|
|
if (this.byteOffset > this.buffer.byteLength) {
|
|
|
|
|
throw new RangeError("byteOffset out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.byteOffset % this.BYTES_PER_ELEMENT) {
|
|
|
|
|
// The given byteOffset must be a multiple of the element
|
|
|
|
|
// size of the specific type, otherwise an exception is raised.
|
|
|
|
|
throw new RangeError("ArrayBuffer length minus the byteOffset is not a multiple of the element size.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (arguments.length < 3) {
|
|
|
|
|
this.byteLength = this.buffer.byteLength - this.byteOffset;
|
|
|
|
|
|
|
|
|
|
if (this.byteLength % this.BYTES_PER_ELEMENT) {
|
|
|
|
|
throw new RangeError("length of buffer minus byteOffset not a multiple of the element size");
|
|
|
|
|
}
|
|
|
|
|
this.length = this.byteLength / this.BYTES_PER_ELEMENT;
|
|
|
|
|
} else {
|
|
|
|
|
this.length = ECMAScript.ToUint32(length);
|
|
|
|
|
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
|
|
|
|
|
throw new RangeError("byteOffset and length reference an area beyond the end of the buffer");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new TypeError("Unexpected argument type(s)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.constructor = ctor;
|
|
|
|
|
|
|
|
|
|
configureProperties(this);
|
|
|
|
|
makeArrayAccessors(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ctor.prototype = new ArrayBufferView();
|
|
|
|
|
ctor.prototype.BYTES_PER_ELEMENT = bytesPerElement;
|
|
|
|
|
ctor.prototype._pack = pack;
|
|
|
|
|
ctor.prototype._unpack = unpack;
|
|
|
|
|
ctor.BYTES_PER_ELEMENT = bytesPerElement;
|
|
|
|
|
|
|
|
|
|
// getter type (unsigned long index);
|
|
|
|
|
ctor.prototype._getter = function(index) {
|
|
|
|
|
if (arguments.length < 1) throw new SyntaxError("Not enough arguments");
|
|
|
|
|
|
|
|
|
|
index = ECMAScript.ToUint32(index);
|
|
|
|
|
if (index >= this.length) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bytes = [], i, o;
|
|
|
|
|
for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT;
|
|
|
|
|
i < this.BYTES_PER_ELEMENT;
|
|
|
|
|
i += 1, o += 1) {
|
|
|
|
|
bytes.push(this.buffer._bytes[o]);
|
|
|
|
|
}
|
|
|
|
|
return this._unpack(bytes);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// NONSTANDARD: convenience alias for getter: type get(unsigned long index);
|
|
|
|
|
ctor.prototype.get = ctor.prototype._getter;
|
|
|
|
|
|
|
|
|
|
// setter void (unsigned long index, type value);
|
|
|
|
|
ctor.prototype._setter = function(index, value) {
|
|
|
|
|
if (arguments.length < 2) throw new SyntaxError("Not enough arguments");
|
|
|
|
|
|
|
|
|
|
index = ECMAScript.ToUint32(index);
|
|
|
|
|
if (index >= this.length) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bytes = this._pack(value), i, o;
|
|
|
|
|
for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT;
|
|
|
|
|
i < this.BYTES_PER_ELEMENT;
|
|
|
|
|
i += 1, o += 1) {
|
|
|
|
|
this.buffer._bytes[o] = bytes[i];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// void set(TypedArray array, optional unsigned long offset);
|
|
|
|
|
// void set(sequence<type> array, optional unsigned long offset);
|
|
|
|
|
ctor.prototype.set = function(index, value) {
|
|
|
|
|
if (arguments.length < 1) throw new SyntaxError("Not enough arguments");
|
|
|
|
|
var array, sequence, offset, len,
|
|
|
|
|
i, s, d,
|
|
|
|
|
byteOffset, byteLength, tmp;
|
|
|
|
|
|
|
|
|
|
if (typeof arguments[0] === 'object' && arguments[0].constructor === this.constructor) {
|
|
|
|
|
// void set(TypedArray array, optional unsigned long offset);
|
|
|
|
|
array = arguments[0];
|
|
|
|
|
offset = ECMAScript.ToUint32(arguments[1]);
|
|
|
|
|
|
|
|
|
|
if (offset + array.length > this.length) {
|
|
|
|
|
throw new RangeError("Offset plus length of array is out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byteOffset = this.byteOffset + offset * this.BYTES_PER_ELEMENT;
|
|
|
|
|
byteLength = array.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
|
|
|
|
|
if (array.buffer === this.buffer) {
|
|
|
|
|
tmp = [];
|
|
|
|
|
for (i = 0, s = array.byteOffset; i < byteLength; i += 1, s += 1) {
|
|
|
|
|
tmp[i] = array.buffer._bytes[s];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0, d = byteOffset; i < byteLength; i += 1, d += 1) {
|
|
|
|
|
this.buffer._bytes[d] = tmp[i];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (i = 0, s = array.byteOffset, d = byteOffset;
|
|
|
|
|
i < byteLength; i += 1, s += 1, d += 1) {
|
|
|
|
|
this.buffer._bytes[d] = array.buffer._bytes[s];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (typeof arguments[0] === 'object' && typeof arguments[0].length !== 'undefined') {
|
|
|
|
|
// void set(sequence<type> array, optional unsigned long offset);
|
|
|
|
|
sequence = arguments[0];
|
|
|
|
|
len = ECMAScript.ToUint32(sequence.length);
|
|
|
|
|
offset = ECMAScript.ToUint32(arguments[1]);
|
|
|
|
|
|
|
|
|
|
if (offset + len > this.length) {
|
|
|
|
|
throw new RangeError("Offset plus length of array is out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i += 1) {
|
|
|
|
|
s = sequence[i];
|
|
|
|
|
this._setter(offset + i, Number(s));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new TypeError("Unexpected argument type(s)");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TypedArray subarray(long begin, optional long end);
|
|
|
|
|
ctor.prototype.subarray = function(start, end) {
|
|
|
|
|
function clamp(v, min, max) { return v < min ? min : v > max ? max : v; }
|
|
|
|
|
|
|
|
|
|
start = ECMAScript.ToInt32(start);
|
|
|
|
|
end = ECMAScript.ToInt32(end);
|
|
|
|
|
|
|
|
|
|
if (arguments.length < 1) { start = 0; }
|
|
|
|
|
if (arguments.length < 2) { end = this.length; }
|
|
|
|
|
|
|
|
|
|
if (start < 0) { start = this.length + start; }
|
|
|
|
|
if (end < 0) { end = this.length + end; }
|
|
|
|
|
|
|
|
|
|
start = clamp(start, 0, this.length);
|
|
|
|
|
end = clamp(end, 0, this.length);
|
|
|
|
|
|
|
|
|
|
var len = end - start;
|
|
|
|
|
if (len < 0) {
|
|
|
|
|
len = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new this.constructor(
|
|
|
|
|
this.buffer, this.byteOffset + start * this.BYTES_PER_ELEMENT, len);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ctor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Int8Array = makeConstructor(1, packI8, unpackI8);
|
|
|
|
|
var Uint8Array = makeConstructor(1, packU8, unpackU8);
|
|
|
|
|
var Uint8ClampedArray = makeConstructor(1, packU8Clamped, unpackU8);
|
|
|
|
|
var Int16Array = makeConstructor(2, packI16, unpackI16);
|
|
|
|
|
var Uint16Array = makeConstructor(2, packU16, unpackU16);
|
|
|
|
|
var Int32Array = makeConstructor(4, packI32, unpackI32);
|
|
|
|
|
var Uint32Array = makeConstructor(4, packU32, unpackU32);
|
|
|
|
|
var Float32Array = makeConstructor(4, packF32, unpackF32);
|
|
|
|
|
var Float64Array = makeConstructor(8, packF64, unpackF64);
|
|
|
|
|
|
|
|
|
|
exports.Int8Array = exports.Int8Array || Int8Array;
|
|
|
|
|
exports.Uint8Array = exports.Uint8Array || Uint8Array;
|
|
|
|
|
exports.Uint8ClampedArray = exports.Uint8ClampedArray || Uint8ClampedArray;
|
|
|
|
|
exports.Int16Array = exports.Int16Array || Int16Array;
|
|
|
|
|
exports.Uint16Array = exports.Uint16Array || Uint16Array;
|
|
|
|
|
exports.Int32Array = exports.Int32Array || Int32Array;
|
|
|
|
|
exports.Uint32Array = exports.Uint32Array || Uint32Array;
|
|
|
|
|
exports.Float32Array = exports.Float32Array || Float32Array;
|
|
|
|
|
exports.Float64Array = exports.Float64Array || Float64Array;
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 6 The DataView View Type
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
function r(array, index) {
|
|
|
|
|
return ECMAScript.IsCallable(array.get) ? array.get(index) : array[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var IS_BIG_ENDIAN = (function() {
|
|
|
|
|
var u16array = new(exports.Uint16Array)([0x1234]),
|
|
|
|
|
u8array = new(exports.Uint8Array)(u16array.buffer);
|
|
|
|
|
return r(u8array, 0) === 0x12;
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
// Constructor(ArrayBuffer buffer,
|
|
|
|
|
// optional unsigned long byteOffset,
|
|
|
|
|
// optional unsigned long byteLength)
|
|
|
|
|
/** @constructor */
|
|
|
|
|
var DataView = function DataView(buffer, byteOffset, byteLength) {
|
|
|
|
|
if (arguments.length === 0) {
|
|
|
|
|
buffer = new exports.ArrayBuffer(0);
|
|
|
|
|
} else if (!(buffer instanceof exports.ArrayBuffer || ECMAScript.Class(buffer) === 'ArrayBuffer')) {
|
|
|
|
|
throw new TypeError("TypeError");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.buffer = buffer || new exports.ArrayBuffer(0);
|
|
|
|
|
|
|
|
|
|
this.byteOffset = ECMAScript.ToUint32(byteOffset);
|
|
|
|
|
if (this.byteOffset > this.buffer.byteLength) {
|
|
|
|
|
throw new RangeError("byteOffset out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (arguments.length < 3) {
|
|
|
|
|
this.byteLength = this.buffer.byteLength - this.byteOffset;
|
|
|
|
|
} else {
|
|
|
|
|
this.byteLength = ECMAScript.ToUint32(byteLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
|
|
|
|
|
throw new RangeError("byteOffset and length reference an area beyond the end of the buffer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureProperties(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function makeGetter(arrayType) {
|
|
|
|
|
return function(byteOffset, littleEndian) {
|
|
|
|
|
|
|
|
|
|
byteOffset = ECMAScript.ToUint32(byteOffset);
|
|
|
|
|
|
|
|
|
|
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
|
|
|
|
|
throw new RangeError("Array index out of range");
|
|
|
|
|
}
|
|
|
|
|
byteOffset += this.byteOffset;
|
|
|
|
|
|
|
|
|
|
var uint8Array = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT),
|
|
|
|
|
bytes = [], i;
|
|
|
|
|
for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
|
|
|
|
|
bytes.push(r(uint8Array, i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
|
|
|
|
|
bytes.reverse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r(new arrayType(new exports.Uint8Array(bytes).buffer), 0);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataView.prototype.getUint8 = makeGetter(exports.Uint8Array);
|
|
|
|
|
DataView.prototype.getInt8 = makeGetter(exports.Int8Array);
|
|
|
|
|
DataView.prototype.getUint16 = makeGetter(exports.Uint16Array);
|
|
|
|
|
DataView.prototype.getInt16 = makeGetter(exports.Int16Array);
|
|
|
|
|
DataView.prototype.getUint32 = makeGetter(exports.Uint32Array);
|
|
|
|
|
DataView.prototype.getInt32 = makeGetter(exports.Int32Array);
|
|
|
|
|
DataView.prototype.getFloat32 = makeGetter(exports.Float32Array);
|
|
|
|
|
DataView.prototype.getFloat64 = makeGetter(exports.Float64Array);
|
|
|
|
|
|
|
|
|
|
function makeSetter(arrayType) {
|
|
|
|
|
return function(byteOffset, value, littleEndian) {
|
|
|
|
|
|
|
|
|
|
byteOffset = ECMAScript.ToUint32(byteOffset);
|
|
|
|
|
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
|
|
|
|
|
throw new RangeError("Array index out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get bytes
|
|
|
|
|
var typeArray = new arrayType([value]),
|
|
|
|
|
byteArray = new exports.Uint8Array(typeArray.buffer),
|
|
|
|
|
bytes = [], i, byteView;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
|
|
|
|
|
bytes.push(r(byteArray, i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Flip if necessary
|
|
|
|
|
if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
|
|
|
|
|
bytes.reverse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write them
|
|
|
|
|
byteView = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT);
|
|
|
|
|
byteView.set(bytes);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataView.prototype.setUint8 = makeSetter(exports.Uint8Array);
|
|
|
|
|
DataView.prototype.setInt8 = makeSetter(exports.Int8Array);
|
|
|
|
|
DataView.prototype.setUint16 = makeSetter(exports.Uint16Array);
|
|
|
|
|
DataView.prototype.setInt16 = makeSetter(exports.Int16Array);
|
|
|
|
|
DataView.prototype.setUint32 = makeSetter(exports.Uint32Array);
|
|
|
|
|
DataView.prototype.setInt32 = makeSetter(exports.Int32Array);
|
|
|
|
|
DataView.prototype.setFloat32 = makeSetter(exports.Float32Array);
|
|
|
|
|
DataView.prototype.setFloat64 = makeSetter(exports.Float64Array);
|
|
|
|
|
|
|
|
|
|
exports.DataView = exports.DataView || DataView;
|
|
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
},{}]},{},[])
|
|
|
|
|
;;module.exports=require("native-buffer-browserify").Buffer
|
|
|
|
|
|
|
|
|
|
},{}],2:[function(require,module,exports){
|
|
|
|
|
// shim for using process in browser
|
|
|
|
|
|
|
|
|
|
var process = module.exports = {};
|
|
|
|
|
|
|
|
|
|
process.nextTick = (function () {
|
|
|
|
|
var canSetImmediate = typeof window !== 'undefined'
|
|
|
|
|
&& window.setImmediate;
|
|
|
|
|
var canPost = typeof window !== 'undefined'
|
|
|
|
|
&& window.postMessage && window.addEventListener
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
if (canSetImmediate) {
|
|
|
|
|
return function (f) { return window.setImmediate(f) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (canPost) {
|
|
|
|
|
var queue = [];
|
|
|
|
|
window.addEventListener('message', function (ev) {
|
|
|
|
|
if (ev.source === window && ev.data === 'process-tick') {
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
if (queue.length > 0) {
|
|
|
|
|
var fn = queue.shift();
|
|
|
|
|
fn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
return function nextTick(fn) {
|
|
|
|
|
queue.push(fn);
|
|
|
|
|
window.postMessage('process-tick', '*');
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return function nextTick(fn) {
|
|
|
|
|
setTimeout(fn, 0);
|
|
|
|
|
};
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
process.title = 'browser';
|
|
|
|
|
process.browser = true;
|
|
|
|
|
process.env = {};
|
|
|
|
|
process.argv = [];
|
|
|
|
|
|
|
|
|
|
process.binding = function (name) {
|
|
|
|
|
throw new Error('process.binding is not supported');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(shtylman)
|
|
|
|
|
process.cwd = function () { return '/' };
|
|
|
|
|
process.chdir = function (dir) {
|
|
|
|
|
throw new Error('process.chdir is not supported');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
},{}],3:[function(require,module,exports){
|
|
|
|
|
var base64 = require('base64-js')
|
|
|
|
|
var TA = require('typedarray')
|
|
|
|
|
|
|
|
|
|
exports.Buffer = Buffer
|
|
|
|
|
exports.SlowBuffer = Buffer
|
|
|
|
|
exports.INSPECT_MAX_BYTES = 50
|
|
|
|
|
Buffer.poolSize = 8192
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Use a shim for browsers that lack Typed Array support (< IE 9, < FF 3.6,
|
|
|
|
|
* < Chrome 6, < Safari 5, < Opera 11.5, < iOS 4.1).
|
|
|
|
|
*/
|
|
|
|
|
var xDataView = typeof DataView === 'undefined'
|
|
|
|
|
? TA.DataView : DataView
|
|
|
|
|
var xArrayBuffer = typeof ArrayBuffer === 'undefined'
|
|
|
|
|
? TA.ArrayBuffer : ArrayBuffer
|
|
|
|
|
var xUint8Array = typeof Uint8Array === 'undefined'
|
|
|
|
|
? TA.Uint8Array : Uint8Array
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check to see if the browser supports augmenting a `Uint8Array` instance.
|
|
|
|
|
*/
|
|
|
|
|
var browserSupport = (function () {
|
|
|
|
|
try {
|
|
|
|
|
var arr = new xUint8Array(0)
|
|
|
|
|
arr.foo = function () { return 42 }
|
|
|
|
|
return 42 === arr.foo()
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})()
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Also use the shim in Firefox 4-17 (even though they have native Uint8Array),
|
|
|
|
|
* since they don't support Proxy. Without that, it is not possible to augment
|
|
|
|
|
* native Uint8Array instances in Firefox.
|
|
|
|
|
*/
|
|
|
|
|
if (xUint8Array !== TA.Uint8Array && !browserSupport) {
|
|
|
|
|
xDataView = TA.DataView
|
|
|
|
|
xArrayBuffer = TA.ArrayBuffer
|
|
|
|
|
xUint8Array = TA.Uint8Array
|
|
|
|
|
browserSupport = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class: Buffer
|
|
|
|
|
* =============
|
|
|
|
|
*
|
|
|
|
|
* The Buffer constructor returns instances of `Uint8Array` that are augmented
|
|
|
|
|
* with function properties for all the node `Buffer` API functions. We use
|
|
|
|
|
* `Uint8Array` so that square bracket notation works as expected -- it returns
|
|
|
|
|
* a single octet.
|
|
|
|
|
*
|
|
|
|
|
* By augmenting the instances, we can avoid modifying the `Uint8Array`
|
|
|
|
|
* prototype.
|
|
|
|
|
*
|
|
|
|
|
* Firefox is a special case because it doesn't allow augmenting "native" object
|
|
|
|
|
* instances. See `ProxyBuffer` below for more details.
|
|
|
|
|
*/
|
|
|
|
|
function Buffer (subject, encoding) {
|
|
|
|
|
var type = typeof subject
|
|
|
|
|
|
|
|
|
|
// Work-around: node's base64 implementation
|
|
|
|
|
// allows for non-padded strings while base64-js
|
|
|
|
|
// does not..
|
|
|
|
|
if (encoding === 'base64' && type === 'string') {
|
|
|
|
|
subject = stringtrim(subject)
|
|
|
|
|
while (subject.length % 4 !== 0) {
|
|
|
|
|
subject = subject + '='
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find the length
|
|
|
|
|
var length
|
|
|
|
|
if (type === 'number')
|
|
|
|
|
length = coerce(subject)
|
|
|
|
|
else if (type === 'string')
|
|
|
|
|
length = Buffer.byteLength(subject, encoding)
|
|
|
|
|
else if (type === 'object')
|
|
|
|
|
length = coerce(subject.length) // Assume object is an array
|
|
|
|
|
else
|
|
|
|
|
throw new Error('First argument needs to be a number, array or string.')
|
|
|
|
|
|
|
|
|
|
var buf = augment(new xUint8Array(length))
|
|
|
|
|
if (Buffer.isBuffer(subject)) {
|
|
|
|
|
// Speed optimization -- use set if we're copying from a Uint8Array
|
|
|
|
|
buf.set(subject)
|
|
|
|
|
} else if (isArrayIsh(subject)) {
|
|
|
|
|
// Treat array-ish objects as a byte array.
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
if (Buffer.isBuffer(subject))
|
|
|
|
|
buf[i] = subject.readUInt8(i)
|
|
|
|
|
else
|
|
|
|
|
buf[i] = subject[i]
|
|
|
|
|
}
|
|
|
|
|
} else if (type === 'string') {
|
|
|
|
|
buf.write(subject, 0, encoding)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// STATIC METHODS
|
|
|
|
|
// ==============
|
|
|
|
|
|
|
|
|
|
Buffer.isEncoding = function(encoding) {
|
|
|
|
|
switch ((encoding + '').toLowerCase()) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
case 'ascii':
|
|
|
|
|
case 'binary':
|
|
|
|
|
case 'base64':
|
|
|
|
|
case 'ucs2':
|
|
|
|
|
case 'ucs-2':
|
|
|
|
|
case 'utf16le':
|
|
|
|
|
case 'utf-16le':
|
|
|
|
|
case 'raw':
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.isBuffer = function (b) {
|
|
|
|
|
return b && b._isBuffer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.byteLength = function (str, encoding) {
|
|
|
|
|
switch (encoding || 'utf8') {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return str.length / 2
|
|
|
|
|
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
return utf8ToBytes(str).length
|
|
|
|
|
|
|
|
|
|
case 'ascii':
|
|
|
|
|
case 'binary':
|
|
|
|
|
return str.length
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return base64ToBytes(str).length
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown encoding')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.concat = function (list, totalLength) {
|
|
|
|
|
if (!isArray(list)) {
|
|
|
|
|
throw new Error('Usage: Buffer.concat(list, [totalLength])\n' +
|
|
|
|
|
'list should be an Array.')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var i
|
|
|
|
|
var buf
|
|
|
|
|
|
|
|
|
|
if (list.length === 0) {
|
|
|
|
|
return new Buffer(0)
|
|
|
|
|
} else if (list.length === 1) {
|
|
|
|
|
return list[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof totalLength !== 'number') {
|
|
|
|
|
totalLength = 0
|
|
|
|
|
for (i = 0; i < list.length; i++) {
|
|
|
|
|
buf = list[i]
|
|
|
|
|
totalLength += buf.length
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var buffer = new Buffer(totalLength)
|
|
|
|
|
var pos = 0
|
|
|
|
|
for (i = 0; i < list.length; i++) {
|
|
|
|
|
buf = list[i]
|
|
|
|
|
buf.copy(buffer, pos)
|
|
|
|
|
pos += buf.length
|
|
|
|
|
}
|
|
|
|
|
return buffer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BUFFER INSTANCE METHODS
|
|
|
|
|
// =======================
|
|
|
|
|
|
|
|
|
|
function _hexWrite (buf, string, offset, length) {
|
|
|
|
|
offset = Number(offset) || 0
|
|
|
|
|
var remaining = buf.length - offset
|
|
|
|
|
if (!length) {
|
|
|
|
|
length = remaining
|
|
|
|
|
} else {
|
|
|
|
|
length = Number(length)
|
|
|
|
|
if (length > remaining) {
|
|
|
|
|
length = remaining
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// must be an even number of digits
|
|
|
|
|
var strLen = string.length
|
|
|
|
|
if (strLen % 2 !== 0) {
|
|
|
|
|
throw new Error('Invalid hex string')
|
|
|
|
|
}
|
|
|
|
|
if (length > strLen / 2) {
|
|
|
|
|
length = strLen / 2
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
var byte = parseInt(string.substr(i * 2, 2), 16)
|
|
|
|
|
if (isNaN(byte)) throw new Error('Invalid hex string')
|
|
|
|
|
buf[offset + i] = byte
|
|
|
|
|
}
|
|
|
|
|
Buffer._charsWritten = i * 2
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _utf8Write (buf, string, offset, length) {
|
|
|
|
|
var bytes, pos
|
|
|
|
|
return Buffer._charsWritten = blitBuffer(utf8ToBytes(string), buf, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _asciiWrite (buf, string, offset, length) {
|
|
|
|
|
var bytes, pos
|
|
|
|
|
return Buffer._charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _binaryWrite (buf, string, offset, length) {
|
|
|
|
|
return _asciiWrite(buf, string, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _base64Write (buf, string, offset, length) {
|
|
|
|
|
var bytes, pos
|
|
|
|
|
return Buffer._charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWrite (string, offset, length, encoding) {
|
|
|
|
|
// Support both (string, offset, length, encoding)
|
|
|
|
|
// and the legacy (string, encoding, offset, length)
|
|
|
|
|
if (isFinite(offset)) {
|
|
|
|
|
if (!isFinite(length)) {
|
|
|
|
|
encoding = length
|
|
|
|
|
length = undefined
|
|
|
|
|
}
|
|
|
|
|
} else { // legacy
|
|
|
|
|
var swap = encoding
|
|
|
|
|
encoding = offset
|
|
|
|
|
offset = length
|
|
|
|
|
length = swap
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset = Number(offset) || 0
|
|
|
|
|
var remaining = this.length - offset
|
|
|
|
|
if (!length) {
|
|
|
|
|
length = remaining
|
|
|
|
|
} else {
|
|
|
|
|
length = Number(length)
|
|
|
|
|
if (length > remaining) {
|
|
|
|
|
length = remaining
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
encoding = String(encoding || 'utf8').toLowerCase()
|
|
|
|
|
|
|
|
|
|
switch (encoding) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return _hexWrite(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
return _utf8Write(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'ascii':
|
|
|
|
|
return _asciiWrite(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'binary':
|
|
|
|
|
return _binaryWrite(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return _base64Write(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown encoding')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferToString (encoding, start, end) {
|
|
|
|
|
var self = (this instanceof ProxyBuffer)
|
|
|
|
|
? this._proxy
|
|
|
|
|
: this
|
|
|
|
|
|
|
|
|
|
encoding = String(encoding || 'utf8').toLowerCase()
|
|
|
|
|
start = Number(start) || 0
|
|
|
|
|
end = (end !== undefined)
|
|
|
|
|
? Number(end)
|
|
|
|
|
: end = self.length
|
|
|
|
|
|
|
|
|
|
// Fastpath empty strings
|
|
|
|
|
if (end === start)
|
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
|
switch (encoding) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return _hexSlice(self, start, end)
|
|
|
|
|
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
return _utf8Slice(self, start, end)
|
|
|
|
|
|
|
|
|
|
case 'ascii':
|
|
|
|
|
return _asciiSlice(self, start, end)
|
|
|
|
|
|
|
|
|
|
case 'binary':
|
|
|
|
|
return _binarySlice(self, start, end)
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return _base64Slice(self, start, end)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown encoding')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferToJSON () {
|
|
|
|
|
return {
|
|
|
|
|
type: 'Buffer',
|
|
|
|
|
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
|
|
|
function BufferCopy (target, target_start, start, end) {
|
|
|
|
|
var source = this
|
|
|
|
|
|
|
|
|
|
if (!start) start = 0
|
|
|
|
|
if (!end && end !== 0) end = this.length
|
|
|
|
|
if (!target_start) target_start = 0
|
|
|
|
|
|
|
|
|
|
// Copy 0 bytes; we're done
|
|
|
|
|
if (end === start) return
|
|
|
|
|
if (target.length === 0 || source.length === 0) return
|
|
|
|
|
|
|
|
|
|
// Fatal error conditions
|
|
|
|
|
if (end < start)
|
|
|
|
|
throw new Error('sourceEnd < sourceStart')
|
|
|
|
|
if (target_start < 0 || target_start >= target.length)
|
|
|
|
|
throw new Error('targetStart out of bounds')
|
|
|
|
|
if (start < 0 || start >= source.length)
|
|
|
|
|
throw new Error('sourceStart out of bounds')
|
|
|
|
|
if (end < 0 || end > source.length)
|
|
|
|
|
throw new Error('sourceEnd out of bounds')
|
|
|
|
|
|
|
|
|
|
// Are we oob?
|
|
|
|
|
if (end > this.length)
|
|
|
|
|
end = this.length
|
|
|
|
|
if (target.length - target_start < end - start)
|
|
|
|
|
end = target.length - target_start + start
|
|
|
|
|
|
|
|
|
|
// copy!
|
|
|
|
|
for (var i = 0; i < end - start; i++)
|
|
|
|
|
target[i + target_start] = this[i + start]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _base64Slice (buf, start, end) {
|
|
|
|
|
if (start === 0 && end === buf.length) {
|
|
|
|
|
return base64.fromByteArray(buf)
|
|
|
|
|
} else {
|
|
|
|
|
return base64.fromByteArray(buf.slice(start, end))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _utf8Slice (buf, start, end) {
|
|
|
|
|
var res = ''
|
|
|
|
|
var tmp = ''
|
|
|
|
|
end = Math.min(buf.length, end)
|
|
|
|
|
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
if (buf[i] <= 0x7F) {
|
|
|
|
|
res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
|
|
|
|
|
tmp = ''
|
|
|
|
|
} else {
|
|
|
|
|
tmp += '%' + buf[i].toString(16)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res + decodeUtf8Char(tmp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _asciiSlice (buf, start, end) {
|
|
|
|
|
var ret = ''
|
|
|
|
|
end = Math.min(buf.length, end)
|
|
|
|
|
|
|
|
|
|
for (var i = start; i < end; i++)
|
|
|
|
|
ret += String.fromCharCode(buf[i])
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _binarySlice (buf, start, end) {
|
|
|
|
|
return _asciiSlice(buf, start, end)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _hexSlice (buf, start, end) {
|
|
|
|
|
var len = buf.length
|
|
|
|
|
|
|
|
|
|
if (!start || start < 0) start = 0
|
|
|
|
|
if (!end || end < 0 || end > len) end = len
|
|
|
|
|
|
|
|
|
|
var out = ''
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
out += toHex(buf[i])
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: add test that modifying the new buffer slice will modify memory in the
|
|
|
|
|
// original buffer! Use code from:
|
|
|
|
|
// http://nodejs.org/api/buffer.html#buffer_buf_slice_start_end
|
|
|
|
|
function BufferSlice (start, end) {
|
|
|
|
|
var len = this.length
|
|
|
|
|
start = clamp(start, len, 0)
|
|
|
|
|
end = clamp(end, len, len)
|
|
|
|
|
return augment(this.subarray(start, end)) // Uint8Array built-in method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt8 (offset, noAssert) {
|
|
|
|
|
var buf = this
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buf.length)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
return buf[offset]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readUInt16 (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 1 === len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(2))
|
|
|
|
|
dv.setUint8(0, buf[len - 1])
|
|
|
|
|
return dv.getUint16(0, littleEndian)
|
|
|
|
|
} else {
|
|
|
|
|
return buf._dataview.getUint16(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt16LE (offset, noAssert) {
|
|
|
|
|
return _readUInt16(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt16BE (offset, noAssert) {
|
|
|
|
|
return _readUInt16(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readUInt32 (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
dv.setUint8(i, buf[i + offset])
|
|
|
|
|
}
|
|
|
|
|
return dv.getUint32(0, littleEndian)
|
|
|
|
|
} else {
|
|
|
|
|
return buf._dataview.getUint32(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt32LE (offset, noAssert) {
|
|
|
|
|
return _readUInt32(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadUInt32BE (offset, noAssert) {
|
|
|
|
|
return _readUInt32(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt8 (offset, noAssert) {
|
|
|
|
|
var buf = this
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset')
|
|
|
|
|
assert(offset < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buf.length)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
return buf._dataview.getInt8(offset)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readInt16 (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset')
|
|
|
|
|
assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 1 === len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(2))
|
|
|
|
|
dv.setUint8(0, buf[len - 1])
|
|
|
|
|
return dv.getInt16(0, littleEndian)
|
|
|
|
|
} else {
|
|
|
|
|
return buf._dataview.getInt16(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt16LE (offset, noAssert) {
|
|
|
|
|
return _readInt16(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt16BE (offset, noAssert) {
|
|
|
|
|
return _readInt16(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readInt32 (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
dv.setUint8(i, buf[i + offset])
|
|
|
|
|
}
|
|
|
|
|
return dv.getInt32(0, littleEndian)
|
|
|
|
|
} else {
|
|
|
|
|
return buf._dataview.getInt32(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt32LE (offset, noAssert) {
|
|
|
|
|
return _readInt32(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadInt32BE (offset, noAssert) {
|
|
|
|
|
return _readInt32(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readFloat (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf._dataview.getFloat32(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadFloatLE (offset, noAssert) {
|
|
|
|
|
return _readFloat(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadFloatBE (offset, noAssert) {
|
|
|
|
|
return _readFloat(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _readDouble (buf, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf._dataview.getFloat64(offset, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadDoubleLE (offset, noAssert) {
|
|
|
|
|
return _readDouble(this, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferReadDoubleBE (offset, noAssert) {
|
|
|
|
|
return _readDouble(this, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt8 (value, offset, noAssert) {
|
|
|
|
|
var buf = this
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset < buf.length, 'trying to write beyond buffer length')
|
|
|
|
|
verifuint(value, 0xff)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buf.length) return
|
|
|
|
|
|
|
|
|
|
buf[offset] = value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeUInt16 (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
|
|
|
|
|
verifuint(value, 0xffff)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 1 === len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(2))
|
|
|
|
|
dv.setUint16(0, value, littleEndian)
|
|
|
|
|
buf[offset] = dv.getUint8(0)
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setUint16(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt16LE (value, offset, noAssert) {
|
|
|
|
|
_writeUInt16(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt16BE (value, offset, noAssert) {
|
|
|
|
|
_writeUInt16(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeUInt32 (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'trying to write beyond buffer length')
|
|
|
|
|
verifuint(value, 0xffffffff)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
dv.setUint32(0, value, littleEndian)
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
buf[i + offset] = dv.getUint8(i)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setUint32(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt32LE (value, offset, noAssert) {
|
|
|
|
|
_writeUInt32(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteUInt32BE (value, offset, noAssert) {
|
|
|
|
|
_writeUInt32(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt8 (value, offset, noAssert) {
|
|
|
|
|
var buf = this
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset < buf.length, 'Trying to write beyond buffer length')
|
|
|
|
|
verifsint(value, 0x7f, -0x80)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buf.length) return
|
|
|
|
|
|
|
|
|
|
buf._dataview.setInt8(offset, value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeInt16 (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')
|
|
|
|
|
verifsint(value, 0x7fff, -0x8000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 1 === len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(2))
|
|
|
|
|
dv.setInt16(0, value, littleEndian)
|
|
|
|
|
buf[offset] = dv.getUint8(0)
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setInt16(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt16LE (value, offset, noAssert) {
|
|
|
|
|
_writeInt16(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt16BE (value, offset, noAssert) {
|
|
|
|
|
_writeInt16(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeInt32 (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
|
|
|
|
|
verifsint(value, 0x7fffffff, -0x80000000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
dv.setInt32(0, value, littleEndian)
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
buf[i + offset] = dv.getUint8(i)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setInt32(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt32LE (value, offset, noAssert) {
|
|
|
|
|
_writeInt32(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteInt32BE (value, offset, noAssert) {
|
|
|
|
|
_writeInt32(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
|
|
|
|
|
verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 3 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(4))
|
|
|
|
|
dv.setFloat32(0, value, littleEndian)
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
buf[i + offset] = dv.getUint8(i)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setFloat32(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteFloatLE (value, offset, noAssert) {
|
|
|
|
|
_writeFloat(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteFloatBE (value, offset, noAssert) {
|
|
|
|
|
_writeFloat(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert(value !== undefined && value !== null, 'missing value')
|
|
|
|
|
assert(typeof (littleEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian')
|
|
|
|
|
assert(offset !== undefined && offset !== null, 'missing offset')
|
|
|
|
|
assert(offset + 7 < buf.length,
|
|
|
|
|
'Trying to write beyond buffer length')
|
|
|
|
|
verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var len = buf.length
|
|
|
|
|
if (offset >= len) {
|
|
|
|
|
return
|
|
|
|
|
} else if (offset + 7 >= len) {
|
|
|
|
|
var dv = new xDataView(new xArrayBuffer(8))
|
|
|
|
|
dv.setFloat64(0, value, littleEndian)
|
|
|
|
|
for (var i = 0; i + offset < len; i++) {
|
|
|
|
|
buf[i + offset] = dv.getUint8(i)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
buf._dataview.setFloat64(offset, value, littleEndian)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteDoubleLE (value, offset, noAssert) {
|
|
|
|
|
_writeDouble(this, value, offset, true, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferWriteDoubleBE (value, offset, noAssert) {
|
|
|
|
|
_writeDouble(this, value, offset, false, noAssert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fill(value, start=0, end=buffer.length)
|
|
|
|
|
function BufferFill (value, start, end) {
|
|
|
|
|
if (!value) value = 0
|
|
|
|
|
if (!start) start = 0
|
|
|
|
|
if (!end) end = this.length
|
|
|
|
|
|
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
|
value = value.charCodeAt(0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof value !== 'number' || isNaN(value)) {
|
|
|
|
|
throw new Error('value is not a number')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end < start) throw new Error('end < start')
|
|
|
|
|
|
|
|
|
|
// Fill 0 bytes; we're done
|
|
|
|
|
if (end === start) return
|
|
|
|
|
if (this.length === 0) return
|
|
|
|
|
|
|
|
|
|
if (start < 0 || start >= this.length) {
|
|
|
|
|
throw new Error('start out of bounds')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end < 0 || end > this.length) {
|
|
|
|
|
throw new Error('end out of bounds')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
this[i] = value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BufferInspect () {
|
|
|
|
|
var out = []
|
|
|
|
|
var len = this.length
|
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
|
|
|
out[i] = toHex(this[i])
|
|
|
|
|
if (i === exports.INSPECT_MAX_BYTES) {
|
|
|
|
|
out[i + 1] = '...'
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return '<Buffer ' + out.join(' ') + '>'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
|
|
|
|
|
// Added in Node 0.12.
|
|
|
|
|
function BufferToArrayBuffer () {
|
|
|
|
|
return (new Buffer(this)).buffer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HELPER FUNCTIONS
|
|
|
|
|
// ================
|
|
|
|
|
|
|
|
|
|
function stringtrim (str) {
|
|
|
|
|
if (str.trim) return str.trim()
|
|
|
|
|
return str.replace(/^\s+|\s+$/g, '')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class: ProxyBuffer
|
|
|
|
|
* ==================
|
|
|
|
|
*
|
|
|
|
|
* Only used in Firefox, since Firefox does not allow augmenting "native"
|
|
|
|
|
* objects (like Uint8Array instances) with new properties for some unknown
|
|
|
|
|
* (probably silly) reason. So we'll use an ES6 Proxy (supported since
|
|
|
|
|
* Firefox 18) to wrap the Uint8Array instance without actually adding any
|
|
|
|
|
* properties to it.
|
|
|
|
|
*
|
|
|
|
|
* Instances of this "fake" Buffer class are the "target" of the
|
|
|
|
|
* ES6 Proxy (see `augment` function).
|
|
|
|
|
*
|
|
|
|
|
* We couldn't just use the `Uint8Array` as the target of the `Proxy` because
|
|
|
|
|
* Proxies have an important limitation on trapping the `toString` method.
|
|
|
|
|
* `Object.prototype.toString.call(proxy)` gets called whenever something is
|
|
|
|
|
* implicitly cast to a String. Unfortunately, with a `Proxy` this
|
|
|
|
|
* unconditionally returns `Object.prototype.toString.call(target)` which would
|
|
|
|
|
* always return "[object Uint8Array]" if we used the `Uint8Array` instance as
|
|
|
|
|
* the target. And, remember, in Firefox we cannot redefine the `Uint8Array`
|
|
|
|
|
* instance's `toString` method.
|
|
|
|
|
*
|
|
|
|
|
* So, we use this `ProxyBuffer` class as the proxy's "target". Since this class
|
|
|
|
|
* has its own custom `toString` method, it will get called whenever `toString`
|
|
|
|
|
* gets called, implicitly or explicitly, on the `Proxy` instance.
|
|
|
|
|
*
|
|
|
|
|
* We also have to define the Uint8Array methods `subarray` and `set` on
|
|
|
|
|
* `ProxyBuffer` because if we didn't then `proxy.subarray(0)` would have its
|
|
|
|
|
* `this` set to `proxy` (a `Proxy` instance) which throws an exception in
|
|
|
|
|
* Firefox which expects it to be a `TypedArray` instance.
|
|
|
|
|
*/
|
|
|
|
|
function ProxyBuffer (arr) {
|
|
|
|
|
this._arr = arr
|
|
|
|
|
|
|
|
|
|
if (arr.byteLength !== 0)
|
|
|
|
|
this._dataview = new xDataView(arr.buffer, arr.byteOffset, arr.byteLength)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProxyBuffer.prototype = {
|
|
|
|
|
_isBuffer: true,
|
|
|
|
|
write: BufferWrite,
|
|
|
|
|
toString: BufferToString,
|
|
|
|
|
toLocaleString: BufferToString,
|
|
|
|
|
toJSON: BufferToJSON,
|
|
|
|
|
copy: BufferCopy,
|
|
|
|
|
slice: BufferSlice,
|
|
|
|
|
readUInt8: BufferReadUInt8,
|
|
|
|
|
readUInt16LE: BufferReadUInt16LE,
|
|
|
|
|
readUInt16BE: BufferReadUInt16BE,
|
|
|
|
|
readUInt32LE: BufferReadUInt32LE,
|
|
|
|
|
readUInt32BE: BufferReadUInt32BE,
|
|
|
|
|
readInt8: BufferReadInt8,
|
|
|
|
|
readInt16LE: BufferReadInt16LE,
|
|
|
|
|
readInt16BE: BufferReadInt16BE,
|
|
|
|
|
readInt32LE: BufferReadInt32LE,
|
|
|
|
|
readInt32BE: BufferReadInt32BE,
|
|
|
|
|
readFloatLE: BufferReadFloatLE,
|
|
|
|
|
readFloatBE: BufferReadFloatBE,
|
|
|
|
|
readDoubleLE: BufferReadDoubleLE,
|
|
|
|
|
readDoubleBE: BufferReadDoubleBE,
|
|
|
|
|
writeUInt8: BufferWriteUInt8,
|
|
|
|
|
writeUInt16LE: BufferWriteUInt16LE,
|
|
|
|
|
writeUInt16BE: BufferWriteUInt16BE,
|
|
|
|
|
writeUInt32LE: BufferWriteUInt32LE,
|
|
|
|
|
writeUInt32BE: BufferWriteUInt32BE,
|
|
|
|
|
writeInt8: BufferWriteInt8,
|
|
|
|
|
writeInt16LE: BufferWriteInt16LE,
|
|
|
|
|
writeInt16BE: BufferWriteInt16BE,
|
|
|
|
|
writeInt32LE: BufferWriteInt32LE,
|
|
|
|
|
writeInt32BE: BufferWriteInt32BE,
|
|
|
|
|
writeFloatLE: BufferWriteFloatLE,
|
|
|
|
|
writeFloatBE: BufferWriteFloatBE,
|
|
|
|
|
writeDoubleLE: BufferWriteDoubleLE,
|
|
|
|
|
writeDoubleBE: BufferWriteDoubleBE,
|
|
|
|
|
fill: BufferFill,
|
|
|
|
|
inspect: BufferInspect,
|
|
|
|
|
toArrayBuffer: BufferToArrayBuffer,
|
|
|
|
|
subarray: function () {
|
|
|
|
|
return this._arr.subarray.apply(this._arr, arguments)
|
|
|
|
|
},
|
|
|
|
|
set: function () {
|
|
|
|
|
return this._arr.set.apply(this._arr, arguments)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ProxyHandler = {
|
|
|
|
|
get: function (target, name) {
|
|
|
|
|
if (name in target) return target[name]
|
|
|
|
|
else return target._arr[name]
|
|
|
|
|
},
|
|
|
|
|
set: function (target, name, value) {
|
|
|
|
|
target._arr[name] = value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function augment (arr) {
|
|
|
|
|
if (browserSupport) {
|
|
|
|
|
arr._isBuffer = true
|
|
|
|
|
|
|
|
|
|
// Augment the Uint8Array *instance* (not the class!) with Buffer methods
|
|
|
|
|
arr.write = BufferWrite
|
|
|
|
|
arr.toString = BufferToString
|
|
|
|
|
arr.toLocaleString = BufferToString
|
|
|
|
|
arr.toJSON = BufferToJSON
|
|
|
|
|
arr.copy = BufferCopy
|
|
|
|
|
arr.slice = BufferSlice
|
|
|
|
|
arr.readUInt8 = BufferReadUInt8
|
|
|
|
|
arr.readUInt16LE = BufferReadUInt16LE
|
|
|
|
|
arr.readUInt16BE = BufferReadUInt16BE
|
|
|
|
|
arr.readUInt32LE = BufferReadUInt32LE
|
|
|
|
|
arr.readUInt32BE = BufferReadUInt32BE
|
|
|
|
|
arr.readInt8 = BufferReadInt8
|
|
|
|
|
arr.readInt16LE = BufferReadInt16LE
|
|
|
|
|
arr.readInt16BE = BufferReadInt16BE
|
|
|
|
|
arr.readInt32LE = BufferReadInt32LE
|
|
|
|
|
arr.readInt32BE = BufferReadInt32BE
|
|
|
|
|
arr.readFloatLE = BufferReadFloatLE
|
|
|
|
|
arr.readFloatBE = BufferReadFloatBE
|
|
|
|
|
arr.readDoubleLE = BufferReadDoubleLE
|
|
|
|
|
arr.readDoubleBE = BufferReadDoubleBE
|
|
|
|
|
arr.writeUInt8 = BufferWriteUInt8
|
|
|
|
|
arr.writeUInt16LE = BufferWriteUInt16LE
|
|
|
|
|
arr.writeUInt16BE = BufferWriteUInt16BE
|
|
|
|
|
arr.writeUInt32LE = BufferWriteUInt32LE
|
|
|
|
|
arr.writeUInt32BE = BufferWriteUInt32BE
|
|
|
|
|
arr.writeInt8 = BufferWriteInt8
|
|
|
|
|
arr.writeInt16LE = BufferWriteInt16LE
|
|
|
|
|
arr.writeInt16BE = BufferWriteInt16BE
|
|
|
|
|
arr.writeInt32LE = BufferWriteInt32LE
|
|
|
|
|
arr.writeInt32BE = BufferWriteInt32BE
|
|
|
|
|
arr.writeFloatLE = BufferWriteFloatLE
|
|
|
|
|
arr.writeFloatBE = BufferWriteFloatBE
|
|
|
|
|
arr.writeDoubleLE = BufferWriteDoubleLE
|
|
|
|
|
arr.writeDoubleBE = BufferWriteDoubleBE
|
|
|
|
|
arr.fill = BufferFill
|
|
|
|
|
arr.inspect = BufferInspect
|
|
|
|
|
|
|
|
|
|
// Only add `toArrayBuffer` if the browser supports ArrayBuffer natively
|
|
|
|
|
if (xUint8Array !== TA.Uint8Array)
|
|
|
|
|
arr.toArrayBuffer = BufferToArrayBuffer
|
|
|
|
|
|
|
|
|
|
if (arr.byteLength !== 0)
|
|
|
|
|
arr._dataview = new xDataView(arr.buffer, arr.byteOffset, arr.byteLength)
|
|
|
|
|
|
|
|
|
|
return arr
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// This is a browser that doesn't support augmenting the `Uint8Array`
|
|
|
|
|
// instance (*ahem* Firefox) so use an ES6 `Proxy`.
|
|
|
|
|
var proxyBuffer = new ProxyBuffer(arr)
|
|
|
|
|
var proxy = new Proxy(proxyBuffer, ProxyHandler)
|
|
|
|
|
proxyBuffer._proxy = proxy
|
|
|
|
|
return proxy
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// slice(start, end)
|
|
|
|
|
function clamp (index, len, defaultValue) {
|
|
|
|
|
if (typeof index !== 'number') return defaultValue
|
|
|
|
|
index = ~~index; // Coerce to integer.
|
|
|
|
|
if (index >= len) return len
|
|
|
|
|
if (index >= 0) return index
|
|
|
|
|
index += len
|
|
|
|
|
if (index >= 0) return index
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function coerce (length) {
|
|
|
|
|
// Coerce length to a number (possibly NaN), round up
|
|
|
|
|
// in case it's fractional (e.g. 123.456) then do a
|
|
|
|
|
// double negate to coerce a NaN to 0. Easy, right?
|
|
|
|
|
length = ~~Math.ceil(+length)
|
|
|
|
|
return length < 0 ? 0 : length
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isArray (subject) {
|
|
|
|
|
return (Array.isArray || function (subject) {
|
|
|
|
|
return Object.prototype.toString.call(subject) === '[object Array]'
|
|
|
|
|
})(subject)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isArrayIsh (subject) {
|
|
|
|
|
return isArray(subject) || Buffer.isBuffer(subject) ||
|
|
|
|
|
subject && typeof subject === 'object' &&
|
|
|
|
|
typeof subject.length === 'number'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toHex (n) {
|
|
|
|
|
if (n < 16) return '0' + n.toString(16)
|
|
|
|
|
return n.toString(16)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function utf8ToBytes (str) {
|
|
|
|
|
var byteArray = []
|
|
|
|
|
for (var i = 0; i < str.length; i++)
|
|
|
|
|
if (str.charCodeAt(i) <= 0x7F)
|
|
|
|
|
byteArray.push(str.charCodeAt(i))
|
|
|
|
|
else {
|
|
|
|
|
var h = encodeURIComponent(str.charAt(i)).substr(1).split('%')
|
|
|
|
|
for (var j = 0; j < h.length; j++)
|
|
|
|
|
byteArray.push(parseInt(h[j], 16))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return byteArray
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function asciiToBytes (str) {
|
|
|
|
|
var byteArray = []
|
|
|
|
|
for (var i = 0; i < str.length; i++) {
|
|
|
|
|
// Node's code seems to be doing this and not & 0x7F..
|
|
|
|
|
byteArray.push(str.charCodeAt(i) & 0xFF)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return byteArray
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function base64ToBytes (str) {
|
|
|
|
|
return base64.toByteArray(str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function blitBuffer (src, dst, offset, length) {
|
|
|
|
|
var pos
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
if ((i + offset >= dst.length) || (i >= src.length))
|
|
|
|
|
break
|
|
|
|
|
dst[i + offset] = src[i]
|
|
|
|
|
}
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function decodeUtf8Char (str) {
|
|
|
|
|
try {
|
|
|
|
|
return decodeURIComponent(str)
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return String.fromCharCode(0xFFFD) // UTF 8 invalid char
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We have to make sure that the value is a valid integer. This means that it
|
|
|
|
|
* is non-negative. It has no fractional component and that it does not
|
|
|
|
|
* exceed the maximum allowed value.
|
|
|
|
|
*
|
|
|
|
|
* value The number to check for validity
|
|
|
|
|
*
|
|
|
|
|
* max The maximum value
|
|
|
|
|
*/
|
|
|
|
|
function verifuint (value, max) {
|
|
|
|
|
assert(typeof (value) == 'number', 'cannot write a non-number as a number')
|
|
|
|
|
assert(value >= 0,
|
|
|
|
|
'specified a negative value for writing an unsigned value')
|
|
|
|
|
assert(value <= max, 'value is larger than maximum value for type')
|
|
|
|
|
assert(Math.floor(value) === value, 'value has a fractional component')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A series of checks to make sure we actually have a signed 32-bit number
|
|
|
|
|
*/
|
|
|
|
|
function verifsint(value, max, min) {
|
|
|
|
|
assert(typeof (value) == 'number', 'cannot write a non-number as a number')
|
|
|
|
|
assert(value <= max, 'value larger than maximum allowed value')
|
|
|
|
|
assert(value >= min, 'value smaller than minimum allowed value')
|
|
|
|
|
assert(Math.floor(value) === value, 'value has a fractional component')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function verifIEEE754(value, max, min) {
|
|
|
|
|
assert(typeof (value) == 'number', 'cannot write a non-number as a number')
|
|
|
|
|
assert(value <= max, 'value larger than maximum allowed value')
|
|
|
|
|
assert(value >= min, 'value smaller than minimum allowed value')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assert (test, message) {
|
|
|
|
|
if (!test) throw new Error(message || 'Failed assertion')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},{"base64-js":4,"typedarray":9}],4:[function(require,module,exports){
|
|
|
|
|
(function (exports) {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
|
|
|
|
|
|
|
|
function b64ToByteArray(b64) {
|
|
|
|
|
var i, j, l, tmp, placeHolders, arr;
|
|
|
|
|
|
|
|
|
|
if (b64.length % 4 > 0) {
|
|
|
|
|
throw 'Invalid string. Length must be a multiple of 4';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the number of equal signs (place holders)
|
|
|
|
|
// if there are two placeholders, than the two characters before it
|
|
|
|
|
// represent one byte
|
|
|
|
|
// if there is only one, then the three characters before it represent 2 bytes
|
|
|
|
|
// this is just a cheap hack to not do indexOf twice
|
|
|
|
|
placeHolders = indexOf(b64, '=');
|
|
|
|
|
placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
|
|
|
|
|
|
|
|
|
|
// base64 is 4/3 + up to two characters of the original data
|
|
|
|
|
arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
|
|
|
|
|
|
|
|
|
|
// if there are placeholders, only get up to the last complete 4 chars
|
|
|
|
|
l = placeHolders > 0 ? b64.length - 4 : b64.length;
|
|
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
|
|
|
|
tmp = (indexOf(lookup, b64.charAt(i)) << 18) | (indexOf(lookup, b64.charAt(i + 1)) << 12) | (indexOf(lookup, b64.charAt(i + 2)) << 6) | indexOf(lookup, b64.charAt(i + 3));
|
|
|
|
|
arr.push((tmp & 0xFF0000) >> 16);
|
|
|
|
|
arr.push((tmp & 0xFF00) >> 8);
|
|
|
|
|
arr.push(tmp & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (placeHolders === 2) {
|
|
|
|
|
tmp = (indexOf(lookup, b64.charAt(i)) << 2) | (indexOf(lookup, b64.charAt(i + 1)) >> 4);
|
|
|
|
|
arr.push(tmp & 0xFF);
|
|
|
|
|
} else if (placeHolders === 1) {
|
|
|
|
|
tmp = (indexOf(lookup, b64.charAt(i)) << 10) | (indexOf(lookup, b64.charAt(i + 1)) << 4) | (indexOf(lookup, b64.charAt(i + 2)) >> 2);
|
|
|
|
|
arr.push((tmp >> 8) & 0xFF);
|
|
|
|
|
arr.push(tmp & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function uint8ToBase64(uint8) {
|
|
|
|
|
var i,
|
|
|
|
|
extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
|
|
|
|
|
output = "",
|
|
|
|
|
temp, length;
|
|
|
|
|
|
|
|
|
|
function tripletToBase64 (num) {
|
|
|
|
|
return lookup.charAt(num >> 18 & 0x3F) + lookup.charAt(num >> 12 & 0x3F) + lookup.charAt(num >> 6 & 0x3F) + lookup.charAt(num & 0x3F);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
|
|
|
for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
|
|
|
|
|
temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
|
|
|
|
|
output += tripletToBase64(temp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
|
|
|
switch (extraBytes) {
|
|
|
|
|
case 1:
|
|
|
|
|
temp = uint8[uint8.length - 1];
|
|
|
|
|
output += lookup.charAt(temp >> 2);
|
|
|
|
|
output += lookup.charAt((temp << 4) & 0x3F);
|
|
|
|
|
output += '==';
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
|
|
|
|
|
output += lookup.charAt(temp >> 10);
|
|
|
|
|
output += lookup.charAt((temp >> 4) & 0x3F);
|
|
|
|
|
output += lookup.charAt((temp << 2) & 0x3F);
|
|
|
|
|
output += '=';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports.toByteArray = b64ToByteArray;
|
|
|
|
|
module.exports.fromByteArray = uint8ToBase64;
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
function indexOf (arr, elt /*, from*/) {
|
|
|
|
|
var len = arr.length;
|
|
|
|
|
|
|
|
|
|
var from = Number(arguments[1]) || 0;
|
|
|
|
|
from = (from < 0)
|
|
|
|
|
? Math.ceil(from)
|
|
|
|
|
: Math.floor(from);
|
|
|
|
|
if (from < 0)
|
|
|
|
|
from += len;
|
|
|
|
|
|
|
|
|
|
for (; from < len; from++) {
|
|
|
|
|
if ((typeof arr === 'string' && arr.charAt(from) === elt) ||
|
|
|
|
|
(typeof arr !== 'string' && arr[from] === elt)) {
|
|
|
|
|
return from;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},{}],5:[function(require,module,exports){
|
|
|
|
|
var process=require("__browserify_process"),global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/*!
|
|
|
|
|
* Benchmark.js v1.0.0 <http://benchmarkjs.com/>
|
|
|
|
|
* Copyright 2010-2012 Mathias Bynens <http://mths.be/>
|
|
|
|
|
* Based on JSLitmus.js, copyright Robert Kieffer <http://broofa.com/>
|
|
|
|
|
* Modified by John-David Dalton <http://allyoucanleet.com/>
|
|
|
|
|
* Available under MIT license <http://mths.be/mit>
|
|
|
|
|
*/
|
|
|
|
|
;(function(window, undefined) {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/** Used to assign each benchmark an incrimented id */
|
|
|
|
|
var counter = 0;
|
|
|
|
|
|
|
|
|
|
/** Detect DOM document object */
|
|
|
|
|
var doc = isHostType(window, 'document') && document;
|
|
|
|
|
|
|
|
|
|
/** Detect free variable `define` */
|
|
|
|
|
var freeDefine = typeof define == 'function' &&
|
|
|
|
|
typeof define.amd == 'object' && define.amd && define;
|
|
|
|
|
|
|
|
|
|
/** Detect free variable `exports` */
|
|
|
|
|
var freeExports = typeof exports == 'object' && exports &&
|
|
|
|
|
(typeof global == 'object' && global && global == global.global && (window = global), exports);
|
|
|
|
|
|
|
|
|
|
/** Detect free variable `require` */
|
|
|
|
|
var freeRequire = typeof require == 'function' && require;
|
|
|
|
|
|
|
|
|
|
/** Used to crawl all properties regardless of enumerability */
|
|
|
|
|
var getAllKeys = Object.getOwnPropertyNames;
|
|
|
|
|
|
|
|
|
|
/** Used to get property descriptors */
|
|
|
|
|
var getDescriptor = Object.getOwnPropertyDescriptor;
|
|
|
|
|
|
|
|
|
|
/** Used in case an object doesn't have its own method */
|
|
|
|
|
var hasOwnProperty = {}.hasOwnProperty;
|
|
|
|
|
|
|
|
|
|
/** Used to check if an object is extensible */
|
|
|
|
|
var isExtensible = Object.isExtensible || function() { return true; };
|
|
|
|
|
|
|
|
|
|
/** Used to access Wade Simmons' Node microtime module */
|
|
|
|
|
var microtimeObject = req('microtime');
|
|
|
|
|
|
|
|
|
|
/** Used to access the browser's high resolution timer */
|
|
|
|
|
var perfObject = isHostType(window, 'performance') && performance;
|
|
|
|
|
|
|
|
|
|
/** Used to call the browser's high resolution timer */
|
|
|
|
|
var perfName = perfObject && (
|
|
|
|
|
perfObject.now && 'now' ||
|
|
|
|
|
perfObject.webkitNow && 'webkitNow'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Used to access Node's high resolution timer */
|
|
|
|
|
var processObject = isHostType(window, 'process') && process;
|
|
|
|
|
|
|
|
|
|
/** Used to check if an own property is enumerable */
|
|
|
|
|
var propertyIsEnumerable = {}.propertyIsEnumerable;
|
|
|
|
|
|
|
|
|
|
/** Used to set property descriptors */
|
|
|
|
|
var setDescriptor = Object.defineProperty;
|
|
|
|
|
|
|
|
|
|
/** Used to resolve a value's internal [[Class]] */
|
|
|
|
|
var toString = {}.toString;
|
|
|
|
|
|
|
|
|
|
/** Used to prevent a `removeChild` memory leak in IE < 9 */
|
|
|
|
|
var trash = doc && doc.createElement('div');
|
|
|
|
|
|
|
|
|
|
/** Used to integrity check compiled tests */
|
|
|
|
|
var uid = 'uid' + (+new Date);
|
|
|
|
|
|
|
|
|
|
/** Used to avoid infinite recursion when methods call each other */
|
|
|
|
|
var calledBy = {};
|
|
|
|
|
|
|
|
|
|
/** Used to avoid hz of Infinity */
|
|
|
|
|
var divisors = {
|
|
|
|
|
'1': 4096,
|
|
|
|
|
'2': 512,
|
|
|
|
|
'3': 64,
|
|
|
|
|
'4': 8,
|
|
|
|
|
'5': 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* T-Distribution two-tailed critical values for 95% confidence
|
|
|
|
|
* http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm
|
|
|
|
|
*/
|
|
|
|
|
var tTable = {
|
|
|
|
|
'1': 12.706,'2': 4.303, '3': 3.182, '4': 2.776, '5': 2.571, '6': 2.447,
|
|
|
|
|
'7': 2.365, '8': 2.306, '9': 2.262, '10': 2.228, '11': 2.201, '12': 2.179,
|
|
|
|
|
'13': 2.16, '14': 2.145, '15': 2.131, '16': 2.12, '17': 2.11, '18': 2.101,
|
|
|
|
|
'19': 2.093, '20': 2.086, '21': 2.08, '22': 2.074, '23': 2.069, '24': 2.064,
|
|
|
|
|
'25': 2.06, '26': 2.056, '27': 2.052, '28': 2.048, '29': 2.045, '30': 2.042,
|
|
|
|
|
'infinity': 1.96
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Critical Mann-Whitney U-values for 95% confidence
|
|
|
|
|
* http://www.saburchill.com/IBbiology/stats/003.html
|
|
|
|
|
*/
|
|
|
|
|
var uTable = {
|
|
|
|
|
'5': [0, 1, 2],
|
|
|
|
|
'6': [1, 2, 3, 5],
|
|
|
|
|
'7': [1, 3, 5, 6, 8],
|
|
|
|
|
'8': [2, 4, 6, 8, 10, 13],
|
|
|
|
|
'9': [2, 4, 7, 10, 12, 15, 17],
|
|
|
|
|
'10': [3, 5, 8, 11, 14, 17, 20, 23],
|
|
|
|
|
'11': [3, 6, 9, 13, 16, 19, 23, 26, 30],
|
|
|
|
|
'12': [4, 7, 11, 14, 18, 22, 26, 29, 33, 37],
|
|
|
|
|
'13': [4, 8, 12, 16, 20, 24, 28, 33, 37, 41, 45],
|
|
|
|
|
'14': [5, 9, 13, 17, 22, 26, 31, 36, 40, 45, 50, 55],
|
|
|
|
|
'15': [5, 10, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64],
|
|
|
|
|
'16': [6, 11, 15, 21, 26, 31, 37, 42, 47, 53, 59, 64, 70, 75],
|
|
|
|
|
'17': [6, 11, 17, 22, 28, 34, 39, 45, 51, 57, 63, 67, 75, 81, 87],
|
|
|
|
|
'18': [7, 12, 18, 24, 30, 36, 42, 48, 55, 61, 67, 74, 80, 86, 93, 99],
|
|
|
|
|
'19': [7, 13, 19, 25, 32, 38, 45, 52, 58, 65, 72, 78, 85, 92, 99, 106, 113],
|
|
|
|
|
'20': [8, 14, 20, 27, 34, 41, 48, 55, 62, 69, 76, 83, 90, 98, 105, 112, 119, 127],
|
|
|
|
|
'21': [8, 15, 22, 29, 36, 43, 50, 58, 65, 73, 80, 88, 96, 103, 111, 119, 126, 134, 142],
|
|
|
|
|
'22': [9, 16, 23, 30, 38, 45, 53, 61, 69, 77, 85, 93, 101, 109, 117, 125, 133, 141, 150, 158],
|
|
|
|
|
'23': [9, 17, 24, 32, 40, 48, 56, 64, 73, 81, 89, 98, 106, 115, 123, 132, 140, 149, 157, 166, 175],
|
|
|
|
|
'24': [10, 17, 25, 33, 42, 50, 59, 67, 76, 85, 94, 102, 111, 120, 129, 138, 147, 156, 165, 174, 183, 192],
|
|
|
|
|
'25': [10, 18, 27, 35, 44, 53, 62, 71, 80, 89, 98, 107, 117, 126, 135, 145, 154, 163, 173, 182, 192, 201, 211],
|
|
|
|
|
'26': [11, 19, 28, 37, 46, 55, 64, 74, 83, 93, 102, 112, 122, 132, 141, 151, 161, 171, 181, 191, 200, 210, 220, 230],
|
|
|
|
|
'27': [11, 20, 29, 38, 48, 57, 67, 77, 87, 97, 107, 118, 125, 138, 147, 158, 168, 178, 188, 199, 209, 219, 230, 240, 250],
|
|
|
|
|
'28': [12, 21, 30, 40, 50, 60, 70, 80, 90, 101, 111, 122, 132, 143, 154, 164, 175, 186, 196, 207, 218, 228, 239, 250, 261, 272],
|
|
|
|
|
'29': [13, 22, 32, 42, 52, 62, 73, 83, 94, 105, 116, 127, 138, 149, 160, 171, 182, 193, 204, 215, 226, 238, 249, 260, 271, 282, 294],
|
|
|
|
|
'30': [13, 23, 33, 43, 54, 65, 76, 87, 98, 109, 120, 131, 143, 154, 166, 177, 189, 200, 212, 223, 235, 247, 258, 270, 282, 293, 305, 317]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An object used to flag environments/features.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
var support = {};
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect Adobe AIR.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
support.air = isClassOf(window.runtime, 'ScriptBridgingProxyObject');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect if `arguments` objects have the correct internal [[Class]] value.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
support.argumentsClass = isClassOf(arguments, 'Arguments');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect if in a browser environment.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
support.browser = doc && isHostType(window, 'navigator');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect if strings support accessing characters by index.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
support.charByIndex =
|
|
|
|
|
// IE 8 supports indexes on string literals but not string objects
|
|
|
|
|
('x'[0] + Object('x')[0]) == 'xx';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect if strings have indexes as own properties.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
support.charByOwnIndex =
|
|
|
|
|
// Narwhal, Rhino, RingoJS, IE 8, and Opera < 10.52 support indexes on
|
|
|
|
|
// strings but don't detect them as own properties
|
|
|
|
|
support.charByIndex && hasKey('x', '0');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect if Java is enabled/exposed.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
support.java = isClassOf(window.java, 'JavaPackage');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect if the Timers API exists.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
support.timeout = isHostType(window, 'setTimeout') && isHostType(window, 'clearTimeout');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect if functions support decompilation.
|
|
|
|
|
*
|
|
|
|
|
* @name decompilation
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
try {
|
|
|
|
|
// Safari 2.x removes commas in object literals
|
|
|
|
|
// from Function#toString results
|
|
|
|
|
// http://webk.it/11609
|
|
|
|
|
// Firefox 3.6 and Opera 9.25 strip grouping
|
|
|
|
|
// parentheses from Function#toString results
|
|
|
|
|
// http://bugzil.la/559438
|
|
|
|
|
support.decompilation = Function(
|
|
|
|
|
'return (' + (function(x) { return { 'x': '' + (1 + x) + '', 'y': 0 }; }) + ')'
|
|
|
|
|
)()(0).x === '1';
|
|
|
|
|
} catch(e) {
|
|
|
|
|
support.decompilation = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect ES5+ property descriptor API.
|
|
|
|
|
*
|
|
|
|
|
* @name descriptors
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
try {
|
|
|
|
|
var o = {};
|
|
|
|
|
support.descriptors = (setDescriptor(o, o, o), 'value' in getDescriptor(o, o));
|
|
|
|
|
} catch(e) {
|
|
|
|
|
support.descriptors = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect ES5+ Object.getOwnPropertyNames().
|
|
|
|
|
*
|
|
|
|
|
* @name getAllKeys
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
try {
|
|
|
|
|
support.getAllKeys = /\bvalueOf\b/.test(getAllKeys(Object.prototype));
|
|
|
|
|
} catch(e) {
|
|
|
|
|
support.getAllKeys = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect if own properties are iterated before inherited properties (all but IE < 9).
|
|
|
|
|
*
|
|
|
|
|
* @name iteratesOwnLast
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
support.iteratesOwnFirst = (function() {
|
|
|
|
|
var props = [];
|
|
|
|
|
function ctor() { this.x = 1; }
|
|
|
|
|
ctor.prototype = { 'y': 1 };
|
|
|
|
|
for (var prop in new ctor) { props.push(prop); }
|
|
|
|
|
return props[0] == 'x';
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect if a node's [[Class]] is resolvable (all but IE < 9)
|
|
|
|
|
* and that the JS engine errors when attempting to coerce an object to a
|
|
|
|
|
* string without a `toString` property value of `typeof` "function".
|
|
|
|
|
*
|
|
|
|
|
* @name nodeClass
|
|
|
|
|
* @memberOf Benchmark.support
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
try {
|
|
|
|
|
support.nodeClass = ({ 'toString': 0 } + '', toString.call(doc || 0) != '[object Object]');
|
|
|
|
|
} catch(e) {
|
|
|
|
|
support.nodeClass = true;
|
|
|
|
|
}
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Timer object used by `clock()` and `Deferred#resolve`.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
var timer = {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The timer namespace object or constructor.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @memberOf timer
|
|
|
|
|
* @type Function|Object
|
|
|
|
|
*/
|
|
|
|
|
'ns': Date,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Starts the deferred timer.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @memberOf timer
|
|
|
|
|
* @param {Object} deferred The deferred instance.
|
|
|
|
|
*/
|
|
|
|
|
'start': null, // lazy defined in `clock()`
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stops the deferred timer.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @memberOf timer
|
|
|
|
|
* @param {Object} deferred The deferred instance.
|
|
|
|
|
*/
|
|
|
|
|
'stop': null // lazy defined in `clock()`
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Shortcut for inverse results */
|
|
|
|
|
var noArgumentsClass = !support.argumentsClass,
|
|
|
|
|
noCharByIndex = !support.charByIndex,
|
|
|
|
|
noCharByOwnIndex = !support.charByOwnIndex;
|
|
|
|
|
|
|
|
|
|
/** Math shortcuts */
|
|
|
|
|
var abs = Math.abs,
|
|
|
|
|
floor = Math.floor,
|
|
|
|
|
max = Math.max,
|
|
|
|
|
min = Math.min,
|
|
|
|
|
pow = Math.pow,
|
|
|
|
|
sqrt = Math.sqrt;
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Benchmark constructor.
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @param {String} name A name to identify the benchmark.
|
|
|
|
|
* @param {Function|String} fn The test to benchmark.
|
|
|
|
|
* @param {Object} [options={}] Options object.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // basic usage (the `new` operator is optional)
|
|
|
|
|
* var bench = new Benchmark(fn);
|
|
|
|
|
*
|
|
|
|
|
* // or using a name first
|
|
|
|
|
* var bench = new Benchmark('foo', fn);
|
|
|
|
|
*
|
|
|
|
|
* // or with options
|
|
|
|
|
* var bench = new Benchmark('foo', fn, {
|
|
|
|
|
*
|
|
|
|
|
* // displayed by Benchmark#toString if `name` is not available
|
|
|
|
|
* 'id': 'xyz',
|
|
|
|
|
*
|
|
|
|
|
* // called when the benchmark starts running
|
|
|
|
|
* 'onStart': onStart,
|
|
|
|
|
*
|
|
|
|
|
* // called after each run cycle
|
|
|
|
|
* 'onCycle': onCycle,
|
|
|
|
|
*
|
|
|
|
|
* // called when aborted
|
|
|
|
|
* 'onAbort': onAbort,
|
|
|
|
|
*
|
|
|
|
|
* // called when a test errors
|
|
|
|
|
* 'onError': onError,
|
|
|
|
|
*
|
|
|
|
|
* // called when reset
|
|
|
|
|
* 'onReset': onReset,
|
|
|
|
|
*
|
|
|
|
|
* // called when the benchmark completes running
|
|
|
|
|
* 'onComplete': onComplete,
|
|
|
|
|
*
|
|
|
|
|
* // compiled/called before the test loop
|
|
|
|
|
* 'setup': setup,
|
|
|
|
|
*
|
|
|
|
|
* // compiled/called after the test loop
|
|
|
|
|
* 'teardown': teardown
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // or name and options
|
|
|
|
|
* var bench = new Benchmark('foo', {
|
|
|
|
|
*
|
|
|
|
|
* // a flag to indicate the benchmark is deferred
|
|
|
|
|
* 'defer': true,
|
|
|
|
|
*
|
|
|
|
|
* // benchmark test function
|
|
|
|
|
* 'fn': function(deferred) {
|
|
|
|
|
* // call resolve() when the deferred test is finished
|
|
|
|
|
* deferred.resolve();
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // or options only
|
|
|
|
|
* var bench = new Benchmark({
|
|
|
|
|
*
|
|
|
|
|
* // benchmark name
|
|
|
|
|
* 'name': 'foo',
|
|
|
|
|
*
|
|
|
|
|
* // benchmark test as a string
|
|
|
|
|
* 'fn': '[1,2,3,4].sort()'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // a test's `this` binding is set to the benchmark instance
|
|
|
|
|
* var bench = new Benchmark('foo', function() {
|
|
|
|
|
* 'My name is '.concat(this.name); // My name is foo
|
|
|
|
|
* });
|
|
|
|
|
*/
|
|
|
|
|
function Benchmark(name, fn, options) {
|
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
|
|
// allow instance creation without the `new` operator
|
|
|
|
|
if (me == null || me.constructor != Benchmark) {
|
|
|
|
|
return new Benchmark(name, fn, options);
|
|
|
|
|
}
|
|
|
|
|
// juggle arguments
|
|
|
|
|
if (isClassOf(name, 'Object')) {
|
|
|
|
|
// 1 argument (options)
|
|
|
|
|
options = name;
|
|
|
|
|
}
|
|
|
|
|
else if (isClassOf(name, 'Function')) {
|
|
|
|
|
// 2 arguments (fn, options)
|
|
|
|
|
options = fn;
|
|
|
|
|
fn = name;
|
|
|
|
|
}
|
|
|
|
|
else if (isClassOf(fn, 'Object')) {
|
|
|
|
|
// 2 arguments (name, options)
|
|
|
|
|
options = fn;
|
|
|
|
|
fn = null;
|
|
|
|
|
me.name = name;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// 3 arguments (name, fn [, options])
|
|
|
|
|
me.name = name;
|
|
|
|
|
}
|
|
|
|
|
setOptions(me, options);
|
|
|
|
|
me.id || (me.id = ++counter);
|
|
|
|
|
me.fn == null && (me.fn = fn);
|
|
|
|
|
me.stats = deepClone(me.stats);
|
|
|
|
|
me.times = deepClone(me.times);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Deferred constructor.
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Object} clone The cloned benchmark instance.
|
|
|
|
|
*/
|
|
|
|
|
function Deferred(clone) {
|
|
|
|
|
var me = this;
|
|
|
|
|
if (me == null || me.constructor != Deferred) {
|
|
|
|
|
return new Deferred(clone);
|
|
|
|
|
}
|
|
|
|
|
me.benchmark = clone;
|
|
|
|
|
clock(me);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Event constructor.
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {String|Object} type The event type.
|
|
|
|
|
*/
|
|
|
|
|
function Event(type) {
|
|
|
|
|
var me = this;
|
|
|
|
|
return (me == null || me.constructor != Event)
|
|
|
|
|
? new Event(type)
|
|
|
|
|
: (type instanceof Event)
|
|
|
|
|
? type
|
|
|
|
|
: extend(me, { 'timeStamp': +new Date }, typeof type == 'string' ? { 'type': type } : type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Suite constructor.
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {String} name A name to identify the suite.
|
|
|
|
|
* @param {Object} [options={}] Options object.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // basic usage (the `new` operator is optional)
|
|
|
|
|
* var suite = new Benchmark.Suite;
|
|
|
|
|
*
|
|
|
|
|
* // or using a name first
|
|
|
|
|
* var suite = new Benchmark.Suite('foo');
|
|
|
|
|
*
|
|
|
|
|
* // or with options
|
|
|
|
|
* var suite = new Benchmark.Suite('foo', {
|
|
|
|
|
*
|
|
|
|
|
* // called when the suite starts running
|
|
|
|
|
* 'onStart': onStart,
|
|
|
|
|
*
|
|
|
|
|
* // called between running benchmarks
|
|
|
|
|
* 'onCycle': onCycle,
|
|
|
|
|
*
|
|
|
|
|
* // called when aborted
|
|
|
|
|
* 'onAbort': onAbort,
|
|
|
|
|
*
|
|
|
|
|
* // called when a test errors
|
|
|
|
|
* 'onError': onError,
|
|
|
|
|
*
|
|
|
|
|
* // called when reset
|
|
|
|
|
* 'onReset': onReset,
|
|
|
|
|
*
|
|
|
|
|
* // called when the suite completes running
|
|
|
|
|
* 'onComplete': onComplete
|
|
|
|
|
* });
|
|
|
|
|
*/
|
|
|
|
|
function Suite(name, options) {
|
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
|
|
// allow instance creation without the `new` operator
|
|
|
|
|
if (me == null || me.constructor != Suite) {
|
|
|
|
|
return new Suite(name, options);
|
|
|
|
|
}
|
|
|
|
|
// juggle arguments
|
|
|
|
|
if (isClassOf(name, 'Object')) {
|
|
|
|
|
// 1 argument (options)
|
|
|
|
|
options = name;
|
|
|
|
|
} else {
|
|
|
|
|
// 2 arguments (name [, options])
|
|
|
|
|
me.name = name;
|
|
|
|
|
}
|
|
|
|
|
setOptions(me, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Note: Some array methods have been implemented in plain JavaScript to avoid
|
|
|
|
|
* bugs in IE, Opera, Rhino, and Mobile Safari.
|
|
|
|
|
*
|
|
|
|
|
* IE compatibility mode and IE < 9 have buggy Array `shift()` and `splice()`
|
|
|
|
|
* functions that fail to remove the last element, `object[0]`, of
|
|
|
|
|
* array-like-objects even though the `length` property is set to `0`.
|
|
|
|
|
* The `shift()` method is buggy in IE 8 compatibility mode, while `splice()`
|
|
|
|
|
* is buggy regardless of mode in IE < 9 and buggy in compatibility mode in IE 9.
|
|
|
|
|
*
|
|
|
|
|
* In Opera < 9.50 and some older/beta Mobile Safari versions using `unshift()`
|
|
|
|
|
* generically to augment the `arguments` object will pave the value at index 0
|
|
|
|
|
* without incrimenting the other values's indexes.
|
|
|
|
|
* https://github.com/documentcloud/underscore/issues/9
|
|
|
|
|
*
|
|
|
|
|
* Rhino and environments it powers, like Narwhal and RingoJS, may have
|
|
|
|
|
* buggy Array `concat()`, `reverse()`, `shift()`, `slice()`, `splice()` and
|
|
|
|
|
* `unshift()` functions that make sparse arrays non-sparse by assigning the
|
|
|
|
|
* undefined indexes a value of undefined.
|
|
|
|
|
* https://github.com/mozilla/rhino/commit/702abfed3f8ca043b2636efd31c14ba7552603dd
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an array containing the elements of the host array followed by the
|
|
|
|
|
* elements of each argument in order.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @returns {Array} The new array.
|
|
|
|
|
*/
|
|
|
|
|
function concat() {
|
|
|
|
|
var value,
|
|
|
|
|
j = -1,
|
|
|
|
|
length = arguments.length,
|
|
|
|
|
result = slice.call(this),
|
|
|
|
|
index = result.length;
|
|
|
|
|
|
|
|
|
|
while (++j < length) {
|
|
|
|
|
value = arguments[j];
|
|
|
|
|
if (isClassOf(value, 'Array')) {
|
|
|
|
|
for (var k = 0, l = value.length; k < l; k++, index++) {
|
|
|
|
|
if (k in value) {
|
|
|
|
|
result[index] = value[k];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result[index++] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Utility function used by `shift()`, `splice()`, and `unshift()`.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Number} start The index to start inserting elements.
|
|
|
|
|
* @param {Number} deleteCount The number of elements to delete from the insert point.
|
|
|
|
|
* @param {Array} elements The elements to insert.
|
|
|
|
|
* @returns {Array} An array of deleted elements.
|
|
|
|
|
*/
|
|
|
|
|
function insert(start, deleteCount, elements) {
|
|
|
|
|
// `result` should have its length set to the `deleteCount`
|
|
|
|
|
// see https://bugs.ecmascript.org/show_bug.cgi?id=332
|
|
|
|
|
var deleteEnd = start + deleteCount,
|
|
|
|
|
elementCount = elements ? elements.length : 0,
|
|
|
|
|
index = start - 1,
|
|
|
|
|
length = start + elementCount,
|
|
|
|
|
object = this,
|
|
|
|
|
result = Array(deleteCount),
|
|
|
|
|
tail = slice.call(object, deleteEnd);
|
|
|
|
|
|
|
|
|
|
// delete elements from the array
|
|
|
|
|
while (++index < deleteEnd) {
|
|
|
|
|
if (index in object) {
|
|
|
|
|
result[index - start] = object[index];
|
|
|
|
|
delete object[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// insert elements
|
|
|
|
|
index = start - 1;
|
|
|
|
|
while (++index < length) {
|
|
|
|
|
object[index] = elements[index - start];
|
|
|
|
|
}
|
|
|
|
|
// append tail elements
|
|
|
|
|
start = index--;
|
|
|
|
|
length = max(0, (object.length >>> 0) - deleteCount + elementCount);
|
|
|
|
|
while (++index < length) {
|
|
|
|
|
if ((index - start) in tail) {
|
|
|
|
|
object[index] = tail[index - start];
|
|
|
|
|
} else if (index in object) {
|
|
|
|
|
delete object[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// delete excess elements
|
|
|
|
|
deleteCount = deleteCount > elementCount ? deleteCount - elementCount : 0;
|
|
|
|
|
while (deleteCount--) {
|
|
|
|
|
index = length + deleteCount;
|
|
|
|
|
if (index in object) {
|
|
|
|
|
delete object[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
object.length = length;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Rearrange the host array's elements in reverse order.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @returns {Array} The reversed array.
|
|
|
|
|
*/
|
|
|
|
|
function reverse() {
|
|
|
|
|
var upperIndex,
|
|
|
|
|
value,
|
|
|
|
|
index = -1,
|
|
|
|
|
object = Object(this),
|
|
|
|
|
length = object.length >>> 0,
|
|
|
|
|
middle = floor(length / 2);
|
|
|
|
|
|
|
|
|
|
if (length > 1) {
|
|
|
|
|
while (++index < middle) {
|
|
|
|
|
upperIndex = length - index - 1;
|
|
|
|
|
value = upperIndex in object ? object[upperIndex] : uid;
|
|
|
|
|
if (index in object) {
|
|
|
|
|
object[upperIndex] = object[index];
|
|
|
|
|
} else {
|
|
|
|
|
delete object[upperIndex];
|
|
|
|
|
}
|
|
|
|
|
if (value != uid) {
|
|
|
|
|
object[index] = value;
|
|
|
|
|
} else {
|
|
|
|
|
delete object[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the first element of the host array and returns it.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @returns {Mixed} The first element of the array.
|
|
|
|
|
*/
|
|
|
|
|
function shift() {
|
|
|
|
|
return insert.call(this, 0, 1)[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an array of the host array's elements from the start index up to,
|
|
|
|
|
* but not including, the end index.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Number} start The starting index.
|
|
|
|
|
* @param {Number} end The end index.
|
|
|
|
|
* @returns {Array} The new array.
|
|
|
|
|
*/
|
|
|
|
|
function slice(start, end) {
|
|
|
|
|
var index = -1,
|
|
|
|
|
object = Object(this),
|
|
|
|
|
length = object.length >>> 0,
|
|
|
|
|
result = [];
|
|
|
|
|
|
|
|
|
|
start = toInteger(start);
|
|
|
|
|
start = start < 0 ? max(length + start, 0) : min(start, length);
|
|
|
|
|
start--;
|
|
|
|
|
end = end == null ? length : toInteger(end);
|
|
|
|
|
end = end < 0 ? max(length + end, 0) : min(end, length);
|
|
|
|
|
|
|
|
|
|
while ((++index, ++start) < end) {
|
|
|
|
|
if (start in object) {
|
|
|
|
|
result[index] = object[start];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Allows removing a range of elements and/or inserting elements into the
|
|
|
|
|
* host array.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Number} start The start index.
|
|
|
|
|
* @param {Number} deleteCount The number of elements to delete.
|
|
|
|
|
* @param {Mixed} [val1, val2, ...] values to insert at the `start` index.
|
|
|
|
|
* @returns {Array} An array of removed elements.
|
|
|
|
|
*/
|
|
|
|
|
function splice(start, deleteCount) {
|
|
|
|
|
var object = Object(this),
|
|
|
|
|
length = object.length >>> 0;
|
|
|
|
|
|
|
|
|
|
start = toInteger(start);
|
|
|
|
|
start = start < 0 ? max(length + start, 0) : min(start, length);
|
|
|
|
|
|
|
|
|
|
// support the de-facto SpiderMonkey extension
|
|
|
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice#Parameters
|
|
|
|
|
// https://bugs.ecmascript.org/show_bug.cgi?id=429
|
|
|
|
|
deleteCount = arguments.length == 1
|
|
|
|
|
? length - start
|
|
|
|
|
: min(max(toInteger(deleteCount), 0), length - start);
|
|
|
|
|
|
|
|
|
|
return insert.call(object, start, deleteCount, slice.call(arguments, 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts the specified `value` to an integer.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Mixed} value The value to convert.
|
|
|
|
|
* @returns {Number} The resulting integer.
|
|
|
|
|
*/
|
|
|
|
|
function toInteger(value) {
|
|
|
|
|
value = +value;
|
|
|
|
|
return value === 0 || !isFinite(value) ? value || 0 : value - (value % 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Appends arguments to the host array.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @returns {Number} The new length.
|
|
|
|
|
*/
|
|
|
|
|
function unshift() {
|
|
|
|
|
var object = Object(this);
|
|
|
|
|
insert.call(object, 0, 0, arguments);
|
|
|
|
|
return object.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A generic `Function#bind` like method.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Function} fn The function to be bound to `thisArg`.
|
|
|
|
|
* @param {Mixed} thisArg The `this` binding for the given function.
|
|
|
|
|
* @returns {Function} The bound function.
|
|
|
|
|
*/
|
|
|
|
|
function bind(fn, thisArg) {
|
|
|
|
|
return function() { fn.apply(thisArg, arguments); };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a function from the given arguments string and body.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {String} args The comma separated function arguments.
|
|
|
|
|
* @param {String} body The function body.
|
|
|
|
|
* @returns {Function} The new function.
|
|
|
|
|
*/
|
|
|
|
|
function createFunction() {
|
|
|
|
|
// lazy define
|
|
|
|
|
createFunction = function(args, body) {
|
|
|
|
|
var result,
|
|
|
|
|
anchor = freeDefine ? define.amd : Benchmark,
|
|
|
|
|
prop = uid + 'createFunction';
|
|
|
|
|
|
|
|
|
|
runScript((freeDefine ? 'define.amd.' : 'Benchmark.') + prop + '=function(' + args + '){' + body + '}');
|
|
|
|
|
result = anchor[prop];
|
|
|
|
|
delete anchor[prop];
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
// fix JaegerMonkey bug
|
|
|
|
|
// http://bugzil.la/639720
|
|
|
|
|
createFunction = support.browser && (createFunction('', 'return"' + uid + '"') || noop)() == uid ? createFunction : Function;
|
|
|
|
|
return createFunction.apply(null, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delay the execution of a function based on the benchmark's `delay` property.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Object} bench The benchmark instance.
|
|
|
|
|
* @param {Object} fn The function to execute.
|
|
|
|
|
*/
|
|
|
|
|
function delay(bench, fn) {
|
|
|
|
|
bench._timerId = setTimeout(fn, bench.delay * 1e3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destroys the given element.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Element} element The element to destroy.
|
|
|
|
|
*/
|
|
|
|
|
function destroyElement(element) {
|
|
|
|
|
trash.appendChild(element);
|
|
|
|
|
trash.innerHTML = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Iterates over an object's properties, executing the `callback` for each.
|
|
|
|
|
* Callbacks may terminate the loop by explicitly returning `false`.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Object} object The object to iterate over.
|
|
|
|
|
* @param {Function} callback The function executed per own property.
|
|
|
|
|
* @param {Object} options The options object.
|
|
|
|
|
* @returns {Object} Returns the object iterated over.
|
|
|
|
|
*/
|
|
|
|
|
function forProps() {
|
|
|
|
|
var forShadowed,
|
|
|
|
|
skipSeen,
|
|
|
|
|
forArgs = true,
|
|
|
|
|
shadowed = ['constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf'];
|
|
|
|
|
|
|
|
|
|
(function(enumFlag, key) {
|
|
|
|
|
// must use a non-native constructor to catch the Safari 2 issue
|
|
|
|
|
function Klass() { this.valueOf = 0; };
|
|
|
|
|
Klass.prototype.valueOf = 0;
|
|
|
|
|
// check various for-in bugs
|
|
|
|
|
for (key in new Klass) {
|
|
|
|
|
enumFlag += key == 'valueOf' ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
// check if `arguments` objects have non-enumerable indexes
|
|
|
|
|
for (key in arguments) {
|
|
|
|
|
key == '0' && (forArgs = false);
|
|
|
|
|
}
|
|
|
|
|
// Safari 2 iterates over shadowed properties twice
|
|
|
|
|
// http://replay.waybackmachine.org/20090428222941/http://tobielangel.com/2007/1/29/for-in-loop-broken-in-safari/
|
|
|
|
|
skipSeen = enumFlag == 2;
|
|
|
|
|
// IE < 9 incorrectly makes an object's properties non-enumerable if they have
|
|
|
|
|
// the same name as other non-enumerable properties in its prototype chain.
|
|
|
|
|
forShadowed = !enumFlag;
|
|
|
|
|
}(0));
|
|
|
|
|
|
|
|
|
|
// lazy define
|
|
|
|
|
forProps = function(object, callback, options) {
|
|
|
|
|
options || (options = {});
|
|
|
|
|
|
|
|
|
|
var result = object;
|
|
|
|
|
object = Object(object);
|
|
|
|
|
|
|
|
|
|
var ctor,
|
|
|
|
|
key,
|
|
|
|
|
keys,
|
|
|
|
|
skipCtor,
|
|
|
|
|
done = !result,
|
|
|
|
|
which = options.which,
|
|
|
|
|
allFlag = which == 'all',
|
|
|
|
|
index = -1,
|
|
|
|
|
iteratee = object,
|
|
|
|
|
length = object.length,
|
|
|
|
|
ownFlag = allFlag || which == 'own',
|
|
|
|
|
seen = {},
|
|
|
|
|
skipProto = isClassOf(object, 'Function'),
|
|
|
|
|
thisArg = options.bind;
|
|
|
|
|
|
|
|
|
|
if (thisArg !== undefined) {
|
|
|
|
|
callback = bind(callback, thisArg);
|
|
|
|
|
}
|
|
|
|
|
// iterate all properties
|
|
|
|
|
if (allFlag && support.getAllKeys) {
|
|
|
|
|
for (index = 0, keys = getAllKeys(object), length = keys.length; index < length; index++) {
|
|
|
|
|
key = keys[index];
|
|
|
|
|
if (callback(object[key], key, object) === false) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// else iterate only enumerable properties
|
|
|
|
|
else {
|
|
|
|
|
for (key in object) {
|
|
|
|
|
// Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
|
|
|
|
|
// (if the prototype or a property on the prototype has been set)
|
|
|
|
|
// incorrectly set a function's `prototype` property [[Enumerable]] value
|
|
|
|
|
// to `true`. Because of this we standardize on skipping the `prototype`
|
|
|
|
|
// property of functions regardless of their [[Enumerable]] value.
|
|
|
|
|
if ((done =
|
|
|
|
|
!(skipProto && key == 'prototype') &&
|
|
|
|
|
!(skipSeen && (hasKey(seen, key) || !(seen[key] = true))) &&
|
|
|
|
|
(!ownFlag || ownFlag && hasKey(object, key)) &&
|
|
|
|
|
callback(object[key], key, object) === false)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// in IE < 9 strings don't support accessing characters by index
|
|
|
|
|
if (!done && (forArgs && isArguments(object) ||
|
|
|
|
|
((noCharByIndex || noCharByOwnIndex) && isClassOf(object, 'String') &&
|
|
|
|
|
(iteratee = noCharByIndex ? object.split('') : object)))) {
|
|
|
|
|
while (++index < length) {
|
|
|
|
|
if ((done =
|
|
|
|
|
callback(iteratee[index], String(index), object) === false)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!done && forShadowed) {
|
|
|
|
|
// Because IE < 9 can't set the `[[Enumerable]]` attribute of an existing
|
|
|
|
|
// property and the `constructor` property of a prototype defaults to
|
|
|
|
|
// non-enumerable, we manually skip the `constructor` property when we
|
|
|
|
|
// think we are iterating over a `prototype` object.
|
|
|
|
|
ctor = object.constructor;
|
|
|
|
|
skipCtor = ctor && ctor.prototype && ctor.prototype.constructor === ctor;
|
|
|
|
|
for (index = 0; index < 7; index++) {
|
|
|
|
|
key = shadowed[index];
|
|
|
|
|
if (!(skipCtor && key == 'constructor') &&
|
|
|
|
|
hasKey(object, key) &&
|
|
|
|
|
callback(object[key], key, object) === false) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
return forProps.apply(null, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the name of the first argument from a function's source.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Function} fn The function.
|
|
|
|
|
* @returns {String} The argument name.
|
|
|
|
|
*/
|
|
|
|
|
function getFirstArgument(fn) {
|
|
|
|
|
return (!hasKey(fn, 'toString') &&
|
|
|
|
|
(/^[\s(]*function[^(]*\(([^\s,)]+)/.exec(fn) || 0)[1]) || '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Computes the arithmetic mean of a sample.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Array} sample The sample.
|
|
|
|
|
* @returns {Number} The mean.
|
|
|
|
|
*/
|
|
|
|
|
function getMean(sample) {
|
|
|
|
|
return reduce(sample, function(sum, x) {
|
|
|
|
|
return sum + x;
|
|
|
|
|
}) / sample.length || 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the source code of a function.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Function} fn The function.
|
|
|
|
|
* @param {String} altSource A string used when a function's source code is unretrievable.
|
|
|
|
|
* @returns {String} The function's source code.
|
|
|
|
|
*/
|
|
|
|
|
function getSource(fn, altSource) {
|
|
|
|
|
var result = altSource;
|
|
|
|
|
if (isStringable(fn)) {
|
|
|
|
|
result = String(fn);
|
|
|
|
|
} else if (support.decompilation) {
|
|
|
|
|
// escape the `{` for Firefox 1
|
|
|
|
|
result = (/^[^{]+\{([\s\S]*)}\s*$/.exec(fn) || 0)[1];
|
|
|
|
|
}
|
|
|
|
|
// trim string
|
|
|
|
|
result = (result || '').replace(/^\s+|\s+$/g, '');
|
|
|
|
|
|
|
|
|
|
// detect strings containing only the "use strict" directive
|
|
|
|
|
return /^(?:\/\*+[\w|\W]*?\*\/|\/\/.*?[\n\r\u2028\u2029]|\s)*(["'])use strict\1;?$/.test(result)
|
|
|
|
|
? ''
|
|
|
|
|
: result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if a value is an `arguments` object.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Mixed} value The value to check.
|
|
|
|
|
* @returns {Boolean} Returns `true` if the value is an `arguments` object, else `false`.
|
|
|
|
|
*/
|
|
|
|
|
function isArguments() {
|
|
|
|
|
// lazy define
|
|
|
|
|
isArguments = function(value) {
|
|
|
|
|
return toString.call(value) == '[object Arguments]';
|
|
|
|
|
};
|
|
|
|
|
if (noArgumentsClass) {
|
|
|
|
|
isArguments = function(value) {
|
|
|
|
|
return hasKey(value, 'callee') &&
|
|
|
|
|
!(propertyIsEnumerable && propertyIsEnumerable.call(value, 'callee'));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return isArguments(arguments[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if an object is of the specified class.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Mixed} value The value to check.
|
|
|
|
|
* @param {String} name The name of the class.
|
|
|
|
|
* @returns {Boolean} Returns `true` if the value is of the specified class, else `false`.
|
|
|
|
|
*/
|
|
|
|
|
function isClassOf(value, name) {
|
|
|
|
|
return value != null && toString.call(value) == '[object ' + name + ']';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Host objects can return type values that are different from their actual
|
|
|
|
|
* data type. The objects we are concerned with usually return non-primitive
|
|
|
|
|
* types of object, function, or unknown.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Mixed} object The owner of the property.
|
|
|
|
|
* @param {String} property The property to check.
|
|
|
|
|
* @returns {Boolean} Returns `true` if the property value is a non-primitive, else `false`.
|
|
|
|
|
*/
|
|
|
|
|
function isHostType(object, property) {
|
|
|
|
|
var type = object != null ? typeof object[property] : 'number';
|
|
|
|
|
return !/^(?:boolean|number|string|undefined)$/.test(type) &&
|
|
|
|
|
(type == 'object' ? !!object[property] : true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if a given `value` is an object created by the `Object` constructor
|
|
|
|
|
* assuming objects created by the `Object` constructor have no inherited
|
|
|
|
|
* enumerable properties and that there are no `Object.prototype` extensions.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Mixed} value The value to check.
|
|
|
|
|
* @returns {Boolean} Returns `true` if the `value` is a plain `Object` object, else `false`.
|
|
|
|
|
*/
|
|
|
|
|
function isPlainObject(value) {
|
|
|
|
|
// avoid non-objects and false positives for `arguments` objects in IE < 9
|
|
|
|
|
var result = false;
|
|
|
|
|
if (!(value && typeof value == 'object') || (noArgumentsClass && isArguments(value))) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
|
|
|
|
|
// methods that are `typeof` "string" and still can coerce nodes to strings.
|
|
|
|
|
// Also check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
|
|
|
|
var ctor = value.constructor;
|
|
|
|
|
if ((support.nodeClass || !(typeof value.toString != 'function' && typeof (value + '') == 'string')) &&
|
|
|
|
|
(!isClassOf(ctor, 'Function') || ctor instanceof ctor)) {
|
|
|
|
|
// In most environments an object's own properties are iterated before
|
|
|
|
|
// its inherited properties. If the last iterated property is an object's
|
|
|
|
|
// own property then there are no inherited enumerable properties.
|
|
|
|
|
if (support.iteratesOwnFirst) {
|
|
|
|
|
forProps(value, function(subValue, subKey) {
|
|
|
|
|
result = subKey;
|
|
|
|
|
});
|
|
|
|
|
return result === false || hasKey(value, result);
|
|
|
|
|
}
|
|
|
|
|
// IE < 9 iterates inherited properties before own properties. If the first
|
|
|
|
|
// iterated property is an object's own property then there are no inherited
|
|
|
|
|
// enumerable properties.
|
|
|
|
|
forProps(value, function(subValue, subKey) {
|
|
|
|
|
result = !hasKey(value, subKey);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
return result === false;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if a value can be safely coerced to a string.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Mixed} value The value to check.
|
|
|
|
|
* @returns {Boolean} Returns `true` if the value can be coerced, else `false`.
|
|
|
|
|
*/
|
|
|
|
|
function isStringable(value) {
|
|
|
|
|
return hasKey(value, 'toString') || isClassOf(value, 'String');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wraps a function and passes `this` to the original function as the
|
|
|
|
|
* first argument.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Function} fn The function to be wrapped.
|
|
|
|
|
* @returns {Function} The new function.
|
|
|
|
|
*/
|
|
|
|
|
function methodize(fn) {
|
|
|
|
|
return function() {
|
|
|
|
|
var args = [this];
|
|
|
|
|
args.push.apply(args, arguments);
|
|
|
|
|
return fn.apply(null, args);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A no-operation function.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function noop() {
|
|
|
|
|
// no operation performed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A wrapper around require() to suppress `module missing` errors.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {String} id The module id.
|
|
|
|
|
* @returns {Mixed} The exported module or `null`.
|
|
|
|
|
*/
|
|
|
|
|
function req(id) {
|
|
|
|
|
try {
|
|
|
|
|
var result = freeExports && freeRequire(id);
|
|
|
|
|
} catch(e) { }
|
|
|
|
|
return result || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Runs a snippet of JavaScript via script injection.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {String} code The code to run.
|
|
|
|
|
*/
|
|
|
|
|
function runScript(code) {
|
|
|
|
|
var anchor = freeDefine ? define.amd : Benchmark,
|
|
|
|
|
script = doc.createElement('script'),
|
|
|
|
|
sibling = doc.getElementsByTagName('script')[0],
|
|
|
|
|
parent = sibling.parentNode,
|
|
|
|
|
prop = uid + 'runScript',
|
|
|
|
|
prefix = '(' + (freeDefine ? 'define.amd.' : 'Benchmark.') + prop + '||function(){})();';
|
|
|
|
|
|
|
|
|
|
// Firefox 2.0.0.2 cannot use script injection as intended because it executes
|
|
|
|
|
// asynchronously, but that's OK because script injection is only used to avoid
|
|
|
|
|
// the previously commented JaegerMonkey bug.
|
|
|
|
|
try {
|
|
|
|
|
// remove the inserted script *before* running the code to avoid differences
|
|
|
|
|
// in the expected script element count/order of the document.
|
|
|
|
|
script.appendChild(doc.createTextNode(prefix + code));
|
|
|
|
|
anchor[prop] = function() { destroyElement(script); };
|
|
|
|
|
} catch(e) {
|
|
|
|
|
parent = parent.cloneNode(false);
|
|
|
|
|
sibling = null;
|
|
|
|
|
script.text = code;
|
|
|
|
|
}
|
|
|
|
|
parent.insertBefore(script, sibling);
|
|
|
|
|
delete anchor[prop];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A helper function for setting options/event handlers.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Object} bench The benchmark instance.
|
|
|
|
|
* @param {Object} [options={}] Options object.
|
|
|
|
|
*/
|
|
|
|
|
function setOptions(bench, options) {
|
|
|
|
|
options = extend({}, bench.constructor.options, options);
|
|
|
|
|
bench.options = forOwn(options, function(value, key) {
|
|
|
|
|
if (value != null) {
|
|
|
|
|
// add event listeners
|
|
|
|
|
if (/^on[A-Z]/.test(key)) {
|
|
|
|
|
forEach(key.split(' '), function(key) {
|
|
|
|
|
bench.on(key.slice(2).toLowerCase(), value);
|
|
|
|
|
});
|
|
|
|
|
} else if (!hasKey(bench, key)) {
|
|
|
|
|
bench[key] = deepClone(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles cycling/completing the deferred benchmark.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Deferred
|
|
|
|
|
*/
|
|
|
|
|
function resolve() {
|
|
|
|
|
var me = this,
|
|
|
|
|
clone = me.benchmark,
|
|
|
|
|
bench = clone._original;
|
|
|
|
|
|
|
|
|
|
if (bench.aborted) {
|
|
|
|
|
// cycle() -> clone cycle/complete event -> compute()'s invoked bench.run() cycle/complete
|
|
|
|
|
me.teardown();
|
|
|
|
|
clone.running = false;
|
|
|
|
|
cycle(me);
|
|
|
|
|
}
|
|
|
|
|
else if (++me.cycles < clone.count) {
|
|
|
|
|
// continue the test loop
|
|
|
|
|
if (support.timeout) {
|
|
|
|
|
// use setTimeout to avoid a call stack overflow if called recursively
|
|
|
|
|
setTimeout(function() { clone.compiled.call(me, timer); }, 0);
|
|
|
|
|
} else {
|
|
|
|
|
clone.compiled.call(me, timer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
timer.stop(me);
|
|
|
|
|
me.teardown();
|
|
|
|
|
delay(clone, function() { cycle(me); });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A deep clone utility.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Mixed} value The value to clone.
|
|
|
|
|
* @returns {Mixed} The cloned value.
|
|
|
|
|
*/
|
|
|
|
|
function deepClone(value) {
|
|
|
|
|
var accessor,
|
|
|
|
|
circular,
|
|
|
|
|
clone,
|
|
|
|
|
ctor,
|
|
|
|
|
descriptor,
|
|
|
|
|
extensible,
|
|
|
|
|
key,
|
|
|
|
|
length,
|
|
|
|
|
markerKey,
|
|
|
|
|
parent,
|
|
|
|
|
result,
|
|
|
|
|
source,
|
|
|
|
|
subIndex,
|
|
|
|
|
data = { 'value': value },
|
|
|
|
|
index = 0,
|
|
|
|
|
marked = [],
|
|
|
|
|
queue = { 'length': 0 },
|
|
|
|
|
unmarked = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An easily detectable decorator for cloned values.
|
|
|
|
|
*/
|
|
|
|
|
function Marker(object) {
|
|
|
|
|
this.raw = object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The callback used by `forProps()`.
|
|
|
|
|
*/
|
|
|
|
|
function forPropsCallback(subValue, subKey) {
|
|
|
|
|
// exit early to avoid cloning the marker
|
|
|
|
|
if (subValue && subValue.constructor == Marker) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// add objects to the queue
|
|
|
|
|
if (subValue === Object(subValue)) {
|
|
|
|
|
queue[queue.length++] = { 'key': subKey, 'parent': clone, 'source': value };
|
|
|
|
|
}
|
|
|
|
|
// assign non-objects
|
|
|
|
|
else {
|
|
|
|
|
try {
|
|
|
|
|
// will throw an error in strict mode if the property is read-only
|
|
|
|
|
clone[subKey] = subValue;
|
|
|
|
|
} catch(e) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets an available marker key for the given object.
|
|
|
|
|
*/
|
|
|
|
|
function getMarkerKey(object) {
|
|
|
|
|
// avoid collisions with existing keys
|
|
|
|
|
var result = uid;
|
|
|
|
|
while (object[result] && object[result].constructor != Marker) {
|
|
|
|
|
result += 1;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
key = data.key;
|
|
|
|
|
parent = data.parent;
|
|
|
|
|
source = data.source;
|
|
|
|
|
clone = value = source ? source[key] : data.value;
|
|
|
|
|
accessor = circular = descriptor = false;
|
|
|
|
|
|
|
|
|
|
// create a basic clone to filter out functions, DOM elements, and
|
|
|
|
|
// other non `Object` objects
|
|
|
|
|
if (value === Object(value)) {
|
|
|
|
|
// use custom deep clone function if available
|
|
|
|
|
if (isClassOf(value.deepClone, 'Function')) {
|
|
|
|
|
clone = value.deepClone();
|
|
|
|
|
} else {
|
|
|
|
|
ctor = value.constructor;
|
|
|
|
|
switch (toString.call(value)) {
|
|
|
|
|
case '[object Array]':
|
|
|
|
|
clone = new ctor(value.length);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '[object Boolean]':
|
|
|
|
|
clone = new ctor(value == true);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '[object Date]':
|
|
|
|
|
clone = new ctor(+value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '[object Object]':
|
|
|
|
|
isPlainObject(value) && (clone = {});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '[object Number]':
|
|
|
|
|
case '[object String]':
|
|
|
|
|
clone = new ctor(value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '[object RegExp]':
|
|
|
|
|
clone = ctor(value.source,
|
|
|
|
|
(value.global ? 'g' : '') +
|
|
|
|
|
(value.ignoreCase ? 'i' : '') +
|
|
|
|
|
(value.multiline ? 'm' : ''));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// continue clone if `value` doesn't have an accessor descriptor
|
|
|
|
|
// http://es5.github.com/#x8.10.1
|
|
|
|
|
if (clone && clone != value &&
|
|
|
|
|
!(descriptor = source && support.descriptors && getDescriptor(source, key),
|
|
|
|
|
accessor = descriptor && (descriptor.get || descriptor.set))) {
|
|
|
|
|
// use an existing clone (circular reference)
|
|
|
|
|
if ((extensible = isExtensible(value))) {
|
|
|
|
|
markerKey = getMarkerKey(value);
|
|
|
|
|
if (value[markerKey]) {
|
|
|
|
|
circular = clone = value[markerKey].raw;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// for frozen/sealed objects
|
|
|
|
|
for (subIndex = 0, length = unmarked.length; subIndex < length; subIndex++) {
|
|
|
|
|
data = unmarked[subIndex];
|
|
|
|
|
if (data.object === value) {
|
|
|
|
|
circular = clone = data.clone;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!circular) {
|
|
|
|
|
// mark object to allow quickly detecting circular references and tie it to its clone
|
|
|
|
|
if (extensible) {
|
|
|
|
|
value[markerKey] = new Marker(clone);
|
|
|
|
|
marked.push({ 'key': markerKey, 'object': value });
|
|
|
|
|
} else {
|
|
|
|
|
// for frozen/sealed objects
|
|
|
|
|
unmarked.push({ 'clone': clone, 'object': value });
|
|
|
|
|
}
|
|
|
|
|
// iterate over object properties
|
|
|
|
|
forProps(value, forPropsCallback, { 'which': 'all' });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (parent) {
|
|
|
|
|
// for custom property descriptors
|
|
|
|
|
if (accessor || (descriptor && !(descriptor.configurable && descriptor.enumerable && descriptor.writable))) {
|
|
|
|
|
if ('value' in descriptor) {
|
|
|
|
|
descriptor.value = clone;
|
|
|
|
|
}
|
|
|
|
|
setDescriptor(parent, key, descriptor);
|
|
|
|
|
}
|
|
|
|
|
// for default property descriptors
|
|
|
|
|
else {
|
|
|
|
|
parent[key] = clone;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result = clone;
|
|
|
|
|
}
|
|
|
|
|
} while ((data = queue[index++]));
|
|
|
|
|
|
|
|
|
|
// remove markers
|
|
|
|
|
for (index = 0, length = marked.length; index < length; index++) {
|
|
|
|
|
data = marked[index];
|
|
|
|
|
delete data.object[data.key];
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An iteration utility for arrays and objects.
|
|
|
|
|
* Callbacks may terminate the loop by explicitly returning `false`.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Array|Object} object The object to iterate over.
|
|
|
|
|
* @param {Function} callback The function called per iteration.
|
|
|
|
|
* @param {Mixed} thisArg The `this` binding for the callback.
|
|
|
|
|
* @returns {Array|Object} Returns the object iterated over.
|
|
|
|
|
*/
|
|
|
|
|
function each(object, callback, thisArg) {
|
|
|
|
|
var result = object;
|
|
|
|
|
object = Object(object);
|
|
|
|
|
|
|
|
|
|
var fn = callback,
|
|
|
|
|
index = -1,
|
|
|
|
|
length = object.length,
|
|
|
|
|
isSnapshot = !!(object.snapshotItem && (length = object.snapshotLength)),
|
|
|
|
|
isSplittable = (noCharByIndex || noCharByOwnIndex) && isClassOf(object, 'String'),
|
|
|
|
|
isConvertable = isSnapshot || isSplittable || 'item' in object,
|
|
|
|
|
origObject = object;
|
|
|
|
|
|
|
|
|
|
// in Opera < 10.5 `hasKey(object, 'length')` returns `false` for NodeLists
|
|
|
|
|
if (length === length >>> 0) {
|
|
|
|
|
if (isConvertable) {
|
|
|
|
|
// the third argument of the callback is the original non-array object
|
|
|
|
|
callback = function(value, index) {
|
|
|
|
|
return fn.call(this, value, index, origObject);
|
|
|
|
|
};
|
|
|
|
|
// in IE < 9 strings don't support accessing characters by index
|
|
|
|
|
if (isSplittable) {
|
|
|
|
|
object = object.split('');
|
|
|
|
|
} else {
|
|
|
|
|
object = [];
|
|
|
|
|
while (++index < length) {
|
|
|
|
|
// in Safari 2 `index in object` is always `false` for NodeLists
|
|
|
|
|
object[index] = isSnapshot ? result.snapshotItem(index) : result[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
forEach(object, callback, thisArg);
|
|
|
|
|
} else {
|
|
|
|
|
forOwn(object, callback, thisArg);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copies enumerable properties from the source(s) object to the destination object.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Object} destination The destination object.
|
|
|
|
|
* @param {Object} [source={}] The source object.
|
|
|
|
|
* @returns {Object} The destination object.
|
|
|
|
|
*/
|
|
|
|
|
function extend(destination, source) {
|
|
|
|
|
// Chrome < 14 incorrectly sets `destination` to `undefined` when we `delete arguments[0]`
|
|
|
|
|
// http://code.google.com/p/v8/issues/detail?id=839
|
|
|
|
|
var result = destination;
|
|
|
|
|
delete arguments[0];
|
|
|
|
|
|
|
|
|
|
forEach(arguments, function(source) {
|
|
|
|
|
forProps(source, function(value, key) {
|
|
|
|
|
result[key] = value;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A generic `Array#filter` like method.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Array} array The array to iterate over.
|
|
|
|
|
* @param {Function|String} callback The function/alias called per iteration.
|
|
|
|
|
* @param {Mixed} thisArg The `this` binding for the callback.
|
|
|
|
|
* @returns {Array} A new array of values that passed callback filter.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // get odd numbers
|
|
|
|
|
* Benchmark.filter([1, 2, 3, 4, 5], function(n) {
|
|
|
|
|
* return n % 2;
|
|
|
|
|
* }); // -> [1, 3, 5];
|
|
|
|
|
*
|
|
|
|
|
* // get fastest benchmarks
|
|
|
|
|
* Benchmark.filter(benches, 'fastest');
|
|
|
|
|
*
|
|
|
|
|
* // get slowest benchmarks
|
|
|
|
|
* Benchmark.filter(benches, 'slowest');
|
|
|
|
|
*
|
|
|
|
|
* // get benchmarks that completed without erroring
|
|
|
|
|
* Benchmark.filter(benches, 'successful');
|
|
|
|
|
*/
|
|
|
|
|
function filter(array, callback, thisArg) {
|
|
|
|
|
var result;
|
|
|
|
|
|
|
|
|
|
if (callback == 'successful') {
|
|
|
|
|
// callback to exclude those that are errored, unrun, or have hz of Infinity
|
|
|
|
|
callback = function(bench) { return bench.cycles && isFinite(bench.hz); };
|
|
|
|
|
}
|
|
|
|
|
else if (callback == 'fastest' || callback == 'slowest') {
|
|
|
|
|
// get successful, sort by period + margin of error, and filter fastest/slowest
|
|
|
|
|
result = filter(array, 'successful').sort(function(a, b) {
|
|
|
|
|
a = a.stats; b = b.stats;
|
|
|
|
|
return (a.mean + a.moe > b.mean + b.moe ? 1 : -1) * (callback == 'fastest' ? 1 : -1);
|
|
|
|
|
});
|
|
|
|
|
result = filter(result, function(bench) {
|
|
|
|
|
return result[0].compare(bench) == 0;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return result || reduce(array, function(result, value, index) {
|
|
|
|
|
return callback.call(thisArg, value, index, array) ? (result.push(value), result) : result;
|
|
|
|
|
}, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A generic `Array#forEach` like method.
|
|
|
|
|
* Callbacks may terminate the loop by explicitly returning `false`.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Array} array The array to iterate over.
|
|
|
|
|
* @param {Function} callback The function called per iteration.
|
|
|
|
|
* @param {Mixed} thisArg The `this` binding for the callback.
|
|
|
|
|
* @returns {Array} Returns the array iterated over.
|
|
|
|
|
*/
|
|
|
|
|
function forEach(array, callback, thisArg) {
|
|
|
|
|
var index = -1,
|
|
|
|
|
length = (array = Object(array)).length >>> 0;
|
|
|
|
|
|
|
|
|
|
if (thisArg !== undefined) {
|
|
|
|
|
callback = bind(callback, thisArg);
|
|
|
|
|
}
|
|
|
|
|
while (++index < length) {
|
|
|
|
|
if (index in array &&
|
|
|
|
|
callback(array[index], index, array) === false) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return array;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Iterates over an object's own properties, executing the `callback` for each.
|
|
|
|
|
* Callbacks may terminate the loop by explicitly returning `false`.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Object} object The object to iterate over.
|
|
|
|
|
* @param {Function} callback The function executed per own property.
|
|
|
|
|
* @param {Mixed} thisArg The `this` binding for the callback.
|
|
|
|
|
* @returns {Object} Returns the object iterated over.
|
|
|
|
|
*/
|
|
|
|
|
function forOwn(object, callback, thisArg) {
|
|
|
|
|
return forProps(object, callback, { 'bind': thisArg, 'which': 'own' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts a number to a more readable comma-separated string representation.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Number} number The number to convert.
|
|
|
|
|
* @returns {String} The more readable string representation.
|
|
|
|
|
*/
|
|
|
|
|
function formatNumber(number) {
|
|
|
|
|
number = String(number).split('.');
|
|
|
|
|
return number[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ',') +
|
|
|
|
|
(number[1] ? '.' + number[1] : '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if an object has the specified key as a direct property.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Object} object The object to check.
|
|
|
|
|
* @param {String} key The key to check for.
|
|
|
|
|
* @returns {Boolean} Returns `true` if key is a direct property, else `false`.
|
|
|
|
|
*/
|
|
|
|
|
function hasKey() {
|
|
|
|
|
// lazy define for worst case fallback (not as accurate)
|
|
|
|
|
hasKey = function(object, key) {
|
|
|
|
|
var parent = object != null && (object.constructor || Object).prototype;
|
|
|
|
|
return !!parent && key in Object(object) && !(key in parent && object[key] === parent[key]);
|
|
|
|
|
};
|
|
|
|
|
// for modern browsers
|
|
|
|
|
if (isClassOf(hasOwnProperty, 'Function')) {
|
|
|
|
|
hasKey = function(object, key) {
|
|
|
|
|
return object != null && hasOwnProperty.call(object, key);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
// for Safari 2
|
|
|
|
|
else if ({}.__proto__ == Object.prototype) {
|
|
|
|
|
hasKey = function(object, key) {
|
|
|
|
|
var result = false;
|
|
|
|
|
if (object != null) {
|
|
|
|
|
object = Object(object);
|
|
|
|
|
object.__proto__ = [object.__proto__, object.__proto__ = null, result = key in object][0];
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return hasKey.apply(this, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A generic `Array#indexOf` like method.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Array} array The array to iterate over.
|
|
|
|
|
* @param {Mixed} value The value to search for.
|
|
|
|
|
* @param {Number} [fromIndex=0] The index to start searching from.
|
|
|
|
|
* @returns {Number} The index of the matched value or `-1`.
|
|
|
|
|
*/
|
|
|
|
|
function indexOf(array, value, fromIndex) {
|
|
|
|
|
var index = toInteger(fromIndex),
|
|
|
|
|
length = (array = Object(array)).length >>> 0;
|
|
|
|
|
|
|
|
|
|
index = (index < 0 ? max(0, length + index) : index) - 1;
|
|
|
|
|
while (++index < length) {
|
|
|
|
|
if (index in array && value === array[index]) {
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Modify a string by replacing named tokens with matching object property values.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {String} string The string to modify.
|
|
|
|
|
* @param {Object} object The template object.
|
|
|
|
|
* @returns {String} The modified string.
|
|
|
|
|
*/
|
|
|
|
|
function interpolate(string, object) {
|
|
|
|
|
forOwn(object, function(value, key) {
|
|
|
|
|
// escape regexp special characters in `key`
|
|
|
|
|
string = string.replace(RegExp('#\\{' + key.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1') + '\\}', 'g'), value);
|
|
|
|
|
});
|
|
|
|
|
return string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Invokes a method on all items in an array.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Array} benches Array of benchmarks to iterate over.
|
|
|
|
|
* @param {String|Object} name The name of the method to invoke OR options object.
|
|
|
|
|
* @param {Mixed} [arg1, arg2, ...] Arguments to invoke the method with.
|
|
|
|
|
* @returns {Array} A new array of values returned from each method invoked.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // invoke `reset` on all benchmarks
|
|
|
|
|
* Benchmark.invoke(benches, 'reset');
|
|
|
|
|
*
|
|
|
|
|
* // invoke `emit` with arguments
|
|
|
|
|
* Benchmark.invoke(benches, 'emit', 'complete', listener);
|
|
|
|
|
*
|
|
|
|
|
* // invoke `run(true)`, treat benchmarks as a queue, and register invoke callbacks
|
|
|
|
|
* Benchmark.invoke(benches, {
|
|
|
|
|
*
|
|
|
|
|
* // invoke the `run` method
|
|
|
|
|
* 'name': 'run',
|
|
|
|
|
*
|
|
|
|
|
* // pass a single argument
|
|
|
|
|
* 'args': true,
|
|
|
|
|
*
|
|
|
|
|
* // treat as queue, removing benchmarks from front of `benches` until empty
|
|
|
|
|
* 'queued': true,
|
|
|
|
|
*
|
|
|
|
|
* // called before any benchmarks have been invoked.
|
|
|
|
|
* 'onStart': onStart,
|
|
|
|
|
*
|
|
|
|
|
* // called between invoking benchmarks
|
|
|
|
|
* 'onCycle': onCycle,
|
|
|
|
|
*
|
|
|
|
|
* // called after all benchmarks have been invoked.
|
|
|
|
|
* 'onComplete': onComplete
|
|
|
|
|
* });
|
|
|
|
|
*/
|
|
|
|
|
function invoke(benches, name) {
|
|
|
|
|
var args,
|
|
|
|
|
bench,
|
|
|
|
|
queued,
|
|
|
|
|
index = -1,
|
|
|
|
|
eventProps = { 'currentTarget': benches },
|
|
|
|
|
options = { 'onStart': noop, 'onCycle': noop, 'onComplete': noop },
|
|
|
|
|
result = map(benches, function(bench) { return bench; });
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Invokes the method of the current object and if synchronous, fetches the next.
|
|
|
|
|
*/
|
|
|
|
|
function execute() {
|
|
|
|
|
var listeners,
|
|
|
|
|
async = isAsync(bench);
|
|
|
|
|
|
|
|
|
|
if (async) {
|
|
|
|
|
// use `getNext` as the first listener
|
|
|
|
|
bench.on('complete', getNext);
|
|
|
|
|
listeners = bench.events.complete;
|
|
|
|
|
listeners.splice(0, 0, listeners.pop());
|
|
|
|
|
}
|
|
|
|
|
// execute method
|
|
|
|
|
result[index] = isClassOf(bench && bench[name], 'Function') ? bench[name].apply(bench, args) : undefined;
|
|
|
|
|
// if synchronous return true until finished
|
|
|
|
|
return !async && getNext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetches the next bench or executes `onComplete` callback.
|
|
|
|
|
*/
|
|
|
|
|
function getNext(event) {
|
|
|
|
|
var cycleEvent,
|
|
|
|
|
last = bench,
|
|
|
|
|
async = isAsync(last);
|
|
|
|
|
|
|
|
|
|
if (async) {
|
|
|
|
|
last.off('complete', getNext);
|
|
|
|
|
last.emit('complete');
|
|
|
|
|
}
|
|
|
|
|
// emit "cycle" event
|
|
|
|
|
eventProps.type = 'cycle';
|
|
|
|
|
eventProps.target = last;
|
|
|
|
|
cycleEvent = Event(eventProps);
|
|
|
|
|
options.onCycle.call(benches, cycleEvent);
|
|
|
|
|
|
|
|
|
|
// choose next benchmark if not exiting early
|
|
|
|
|
if (!cycleEvent.aborted && raiseIndex() !== false) {
|
|
|
|
|
bench = queued ? benches[0] : result[index];
|
|
|
|
|
if (isAsync(bench)) {
|
|
|
|
|
delay(bench, execute);
|
|
|
|
|
}
|
|
|
|
|
else if (async) {
|
|
|
|
|
// resume execution if previously asynchronous but now synchronous
|
|
|
|
|
while (execute()) { }
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// continue synchronous execution
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// emit "complete" event
|
|
|
|
|
eventProps.type = 'complete';
|
|
|
|
|
options.onComplete.call(benches, Event(eventProps));
|
|
|
|
|
}
|
|
|
|
|
// When used as a listener `event.aborted = true` will cancel the rest of
|
|
|
|
|
// the "complete" listeners because they were already called above and when
|
|
|
|
|
// used as part of `getNext` the `return false` will exit the execution while-loop.
|
|
|
|
|
if (event) {
|
|
|
|
|
event.aborted = true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if invoking `Benchmark#run` with asynchronous cycles.
|
|
|
|
|
*/
|
|
|
|
|
function isAsync(object) {
|
|
|
|
|
// avoid using `instanceof` here because of IE memory leak issues with host objects
|
|
|
|
|
var async = args[0] && args[0].async;
|
|
|
|
|
return Object(object).constructor == Benchmark && name == 'run' &&
|
|
|
|
|
((async == null ? object.options.async : async) && support.timeout || object.defer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Raises `index` to the next defined index or returns `false`.
|
|
|
|
|
*/
|
|
|
|
|
function raiseIndex() {
|
|
|
|
|
var length = result.length;
|
|
|
|
|
if (queued) {
|
|
|
|
|
// if queued remove the previous bench and subsequent skipped non-entries
|
|
|
|
|
do {
|
|
|
|
|
++index > 0 && shift.call(benches);
|
|
|
|
|
} while ((length = benches.length) && !('0' in benches));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
while (++index < length && !(index in result)) { }
|
|
|
|
|
}
|
|
|
|
|
// if we reached the last index then return `false`
|
|
|
|
|
return (queued ? length : index < length) ? index : (index = false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// juggle arguments
|
|
|
|
|
if (isClassOf(name, 'String')) {
|
|
|
|
|
// 2 arguments (array, name)
|
|
|
|
|
args = slice.call(arguments, 2);
|
|
|
|
|
} else {
|
|
|
|
|
// 2 arguments (array, options)
|
|
|
|
|
options = extend(options, name);
|
|
|
|
|
name = options.name;
|
|
|
|
|
args = isClassOf(args = 'args' in options ? options.args : [], 'Array') ? args : [args];
|
|
|
|
|
queued = options.queued;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// start iterating over the array
|
|
|
|
|
if (raiseIndex() !== false) {
|
|
|
|
|
// emit "start" event
|
|
|
|
|
bench = result[index];
|
|
|
|
|
eventProps.type = 'start';
|
|
|
|
|
eventProps.target = bench;
|
|
|
|
|
options.onStart.call(benches, Event(eventProps));
|
|
|
|
|
|
|
|
|
|
// end early if the suite was aborted in an "onStart" listener
|
|
|
|
|
if (benches.aborted && benches.constructor == Suite && name == 'run') {
|
|
|
|
|
// emit "cycle" event
|
|
|
|
|
eventProps.type = 'cycle';
|
|
|
|
|
options.onCycle.call(benches, Event(eventProps));
|
|
|
|
|
// emit "complete" event
|
|
|
|
|
eventProps.type = 'complete';
|
|
|
|
|
options.onComplete.call(benches, Event(eventProps));
|
|
|
|
|
}
|
|
|
|
|
// else start
|
|
|
|
|
else {
|
|
|
|
|
if (isAsync(bench)) {
|
|
|
|
|
delay(bench, execute);
|
|
|
|
|
} else {
|
|
|
|
|
while (execute()) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a string of joined array values or object key-value pairs.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Array|Object} object The object to operate on.
|
|
|
|
|
* @param {String} [separator1=','] The separator used between key-value pairs.
|
|
|
|
|
* @param {String} [separator2=': '] The separator used between keys and values.
|
|
|
|
|
* @returns {String} The joined result.
|
|
|
|
|
*/
|
|
|
|
|
function join(object, separator1, separator2) {
|
|
|
|
|
var result = [],
|
|
|
|
|
length = (object = Object(object)).length,
|
|
|
|
|
arrayLike = length === length >>> 0;
|
|
|
|
|
|
|
|
|
|
separator2 || (separator2 = ': ');
|
|
|
|
|
each(object, function(value, key) {
|
|
|
|
|
result.push(arrayLike ? value : key + separator2 + value);
|
|
|
|
|
});
|
|
|
|
|
return result.join(separator1 || ',');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A generic `Array#map` like method.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Array} array The array to iterate over.
|
|
|
|
|
* @param {Function} callback The function called per iteration.
|
|
|
|
|
* @param {Mixed} thisArg The `this` binding for the callback.
|
|
|
|
|
* @returns {Array} A new array of values returned by the callback.
|
|
|
|
|
*/
|
|
|
|
|
function map(array, callback, thisArg) {
|
|
|
|
|
return reduce(array, function(result, value, index) {
|
|
|
|
|
result[index] = callback.call(thisArg, value, index, array);
|
|
|
|
|
return result;
|
|
|
|
|
}, Array(Object(array).length >>> 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves the value of a specified property from all items in an array.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Array} array The array to iterate over.
|
|
|
|
|
* @param {String} property The property to pluck.
|
|
|
|
|
* @returns {Array} A new array of property values.
|
|
|
|
|
*/
|
|
|
|
|
function pluck(array, property) {
|
|
|
|
|
return map(array, function(object) {
|
|
|
|
|
return object == null ? undefined : object[property];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A generic `Array#reduce` like method.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Array} array The array to iterate over.
|
|
|
|
|
* @param {Function} callback The function called per iteration.
|
|
|
|
|
* @param {Mixed} accumulator Initial value of the accumulator.
|
|
|
|
|
* @returns {Mixed} The accumulator.
|
|
|
|
|
*/
|
|
|
|
|
function reduce(array, callback, accumulator) {
|
|
|
|
|
var noaccum = arguments.length < 3;
|
|
|
|
|
forEach(array, function(value, index) {
|
|
|
|
|
accumulator = noaccum ? (noaccum = false, value) : callback(accumulator, value, index, array);
|
|
|
|
|
});
|
|
|
|
|
return accumulator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Aborts all benchmarks in the suite.
|
|
|
|
|
*
|
|
|
|
|
* @name abort
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @returns {Object} The suite instance.
|
|
|
|
|
*/
|
|
|
|
|
function abortSuite() {
|
|
|
|
|
var event,
|
|
|
|
|
me = this,
|
|
|
|
|
resetting = calledBy.resetSuite;
|
|
|
|
|
|
|
|
|
|
if (me.running) {
|
|
|
|
|
event = Event('abort');
|
|
|
|
|
me.emit(event);
|
|
|
|
|
if (!event.cancelled || resetting) {
|
|
|
|
|
// avoid infinite recursion
|
|
|
|
|
calledBy.abortSuite = true;
|
|
|
|
|
me.reset();
|
|
|
|
|
delete calledBy.abortSuite;
|
|
|
|
|
|
|
|
|
|
if (!resetting) {
|
|
|
|
|
me.aborted = true;
|
|
|
|
|
invoke(me, 'abort');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a test to the benchmark suite.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {String} name A name to identify the benchmark.
|
|
|
|
|
* @param {Function|String} fn The test to benchmark.
|
|
|
|
|
* @param {Object} [options={}] Options object.
|
|
|
|
|
* @returns {Object} The benchmark instance.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // basic usage
|
|
|
|
|
* suite.add(fn);
|
|
|
|
|
*
|
|
|
|
|
* // or using a name first
|
|
|
|
|
* suite.add('foo', fn);
|
|
|
|
|
*
|
|
|
|
|
* // or with options
|
|
|
|
|
* suite.add('foo', fn, {
|
|
|
|
|
* 'onCycle': onCycle,
|
|
|
|
|
* 'onComplete': onComplete
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // or name and options
|
|
|
|
|
* suite.add('foo', {
|
|
|
|
|
* 'fn': fn,
|
|
|
|
|
* 'onCycle': onCycle,
|
|
|
|
|
* 'onComplete': onComplete
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // or options only
|
|
|
|
|
* suite.add({
|
|
|
|
|
* 'name': 'foo',
|
|
|
|
|
* 'fn': fn,
|
|
|
|
|
* 'onCycle': onCycle,
|
|
|
|
|
* 'onComplete': onComplete
|
|
|
|
|
* });
|
|
|
|
|
*/
|
|
|
|
|
function add(name, fn, options) {
|
|
|
|
|
var me = this,
|
|
|
|
|
bench = Benchmark(name, fn, options),
|
|
|
|
|
event = Event({ 'type': 'add', 'target': bench });
|
|
|
|
|
|
|
|
|
|
if (me.emit(event), !event.cancelled) {
|
|
|
|
|
me.push(bench);
|
|
|
|
|
}
|
|
|
|
|
return me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new suite with cloned benchmarks.
|
|
|
|
|
*
|
|
|
|
|
* @name clone
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Object} options Options object to overwrite cloned options.
|
|
|
|
|
* @returns {Object} The new suite instance.
|
|
|
|
|
*/
|
|
|
|
|
function cloneSuite(options) {
|
|
|
|
|
var me = this,
|
|
|
|
|
result = new me.constructor(extend({}, me.options, options));
|
|
|
|
|
|
|
|
|
|
// copy own properties
|
|
|
|
|
forOwn(me, function(value, key) {
|
|
|
|
|
if (!hasKey(result, key)) {
|
|
|
|
|
result[key] = value && isClassOf(value.clone, 'Function')
|
|
|
|
|
? value.clone()
|
|
|
|
|
: deepClone(value);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An `Array#filter` like method.
|
|
|
|
|
*
|
|
|
|
|
* @name filter
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Function|String} callback The function/alias called per iteration.
|
|
|
|
|
* @returns {Object} A new suite of benchmarks that passed callback filter.
|
|
|
|
|
*/
|
|
|
|
|
function filterSuite(callback) {
|
|
|
|
|
var me = this,
|
|
|
|
|
result = new me.constructor;
|
|
|
|
|
|
|
|
|
|
result.push.apply(result, filter(me, callback));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resets all benchmarks in the suite.
|
|
|
|
|
*
|
|
|
|
|
* @name reset
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @returns {Object} The suite instance.
|
|
|
|
|
*/
|
|
|
|
|
function resetSuite() {
|
|
|
|
|
var event,
|
|
|
|
|
me = this,
|
|
|
|
|
aborting = calledBy.abortSuite;
|
|
|
|
|
|
|
|
|
|
if (me.running && !aborting) {
|
|
|
|
|
// no worries, `resetSuite()` is called within `abortSuite()`
|
|
|
|
|
calledBy.resetSuite = true;
|
|
|
|
|
me.abort();
|
|
|
|
|
delete calledBy.resetSuite;
|
|
|
|
|
}
|
|
|
|
|
// reset if the state has changed
|
|
|
|
|
else if ((me.aborted || me.running) &&
|
|
|
|
|
(me.emit(event = Event('reset')), !event.cancelled)) {
|
|
|
|
|
me.running = false;
|
|
|
|
|
if (!aborting) {
|
|
|
|
|
invoke(me, 'reset');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Runs the suite.
|
|
|
|
|
*
|
|
|
|
|
* @name run
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Object} [options={}] Options object.
|
|
|
|
|
* @returns {Object} The suite instance.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // basic usage
|
|
|
|
|
* suite.run();
|
|
|
|
|
*
|
|
|
|
|
* // or with options
|
|
|
|
|
* suite.run({ 'async': true, 'queued': true });
|
|
|
|
|
*/
|
|
|
|
|
function runSuite(options) {
|
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
|
|
me.reset();
|
|
|
|
|
me.running = true;
|
|
|
|
|
options || (options = {});
|
|
|
|
|
|
|
|
|
|
invoke(me, {
|
|
|
|
|
'name': 'run',
|
|
|
|
|
'args': options,
|
|
|
|
|
'queued': options.queued,
|
|
|
|
|
'onStart': function(event) {
|
|
|
|
|
me.emit(event);
|
|
|
|
|
},
|
|
|
|
|
'onCycle': function(event) {
|
|
|
|
|
var bench = event.target;
|
|
|
|
|
if (bench.error) {
|
|
|
|
|
me.emit({ 'type': 'error', 'target': bench });
|
|
|
|
|
}
|
|
|
|
|
me.emit(event);
|
|
|
|
|
event.aborted = me.aborted;
|
|
|
|
|
},
|
|
|
|
|
'onComplete': function(event) {
|
|
|
|
|
me.running = false;
|
|
|
|
|
me.emit(event);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Executes all registered listeners of the specified event type.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark, Benchmark.Suite
|
|
|
|
|
* @param {String|Object} type The event type or object.
|
|
|
|
|
* @returns {Mixed} Returns the return value of the last listener executed.
|
|
|
|
|
*/
|
|
|
|
|
function emit(type) {
|
|
|
|
|
var listeners,
|
|
|
|
|
me = this,
|
|
|
|
|
event = Event(type),
|
|
|
|
|
events = me.events,
|
|
|
|
|
args = (arguments[0] = event, arguments);
|
|
|
|
|
|
|
|
|
|
event.currentTarget || (event.currentTarget = me);
|
|
|
|
|
event.target || (event.target = me);
|
|
|
|
|
delete event.result;
|
|
|
|
|
|
|
|
|
|
if (events && (listeners = hasKey(events, event.type) && events[event.type])) {
|
|
|
|
|
forEach(listeners.slice(), function(listener) {
|
|
|
|
|
if ((event.result = listener.apply(me, args)) === false) {
|
|
|
|
|
event.cancelled = true;
|
|
|
|
|
}
|
|
|
|
|
return !event.aborted;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return event.result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns an array of event listeners for a given type that can be manipulated
|
|
|
|
|
* to add or remove listeners.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark, Benchmark.Suite
|
|
|
|
|
* @param {String} type The event type.
|
|
|
|
|
* @returns {Array} The listeners array.
|
|
|
|
|
*/
|
|
|
|
|
function listeners(type) {
|
|
|
|
|
var me = this,
|
|
|
|
|
events = me.events || (me.events = {});
|
|
|
|
|
|
|
|
|
|
return hasKey(events, type) ? events[type] : (events[type] = []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unregisters a listener for the specified event type(s),
|
|
|
|
|
* or unregisters all listeners for the specified event type(s),
|
|
|
|
|
* or unregisters all listeners for all event types.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark, Benchmark.Suite
|
|
|
|
|
* @param {String} [type] The event type.
|
|
|
|
|
* @param {Function} [listener] The function to unregister.
|
|
|
|
|
* @returns {Object} The benchmark instance.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // unregister a listener for an event type
|
|
|
|
|
* bench.off('cycle', listener);
|
|
|
|
|
*
|
|
|
|
|
* // unregister a listener for multiple event types
|
|
|
|
|
* bench.off('start cycle', listener);
|
|
|
|
|
*
|
|
|
|
|
* // unregister all listeners for an event type
|
|
|
|
|
* bench.off('cycle');
|
|
|
|
|
*
|
|
|
|
|
* // unregister all listeners for multiple event types
|
|
|
|
|
* bench.off('start cycle complete');
|
|
|
|
|
*
|
|
|
|
|
* // unregister all listeners for all event types
|
|
|
|
|
* bench.off();
|
|
|
|
|
*/
|
|
|
|
|
function off(type, listener) {
|
|
|
|
|
var me = this,
|
|
|
|
|
events = me.events;
|
|
|
|
|
|
|
|
|
|
events && each(type ? type.split(' ') : events, function(listeners, type) {
|
|
|
|
|
var index;
|
|
|
|
|
if (typeof listeners == 'string') {
|
|
|
|
|
type = listeners;
|
|
|
|
|
listeners = hasKey(events, type) && events[type];
|
|
|
|
|
}
|
|
|
|
|
if (listeners) {
|
|
|
|
|
if (listener) {
|
|
|
|
|
index = indexOf(listeners, listener);
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
listeners.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
listeners.length = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Registers a listener for the specified event type(s).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark, Benchmark.Suite
|
|
|
|
|
* @param {String} type The event type.
|
|
|
|
|
* @param {Function} listener The function to register.
|
|
|
|
|
* @returns {Object} The benchmark instance.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // register a listener for an event type
|
|
|
|
|
* bench.on('cycle', listener);
|
|
|
|
|
*
|
|
|
|
|
* // register a listener for multiple event types
|
|
|
|
|
* bench.on('start cycle', listener);
|
|
|
|
|
*/
|
|
|
|
|
function on(type, listener) {
|
|
|
|
|
var me = this,
|
|
|
|
|
events = me.events || (me.events = {});
|
|
|
|
|
|
|
|
|
|
forEach(type.split(' '), function(type) {
|
|
|
|
|
(hasKey(events, type)
|
|
|
|
|
? events[type]
|
|
|
|
|
: (events[type] = [])
|
|
|
|
|
).push(listener);
|
|
|
|
|
});
|
|
|
|
|
return me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Aborts the benchmark without recording times.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @returns {Object} The benchmark instance.
|
|
|
|
|
*/
|
|
|
|
|
function abort() {
|
|
|
|
|
var event,
|
|
|
|
|
me = this,
|
|
|
|
|
resetting = calledBy.reset;
|
|
|
|
|
|
|
|
|
|
if (me.running) {
|
|
|
|
|
event = Event('abort');
|
|
|
|
|
me.emit(event);
|
|
|
|
|
if (!event.cancelled || resetting) {
|
|
|
|
|
// avoid infinite recursion
|
|
|
|
|
calledBy.abort = true;
|
|
|
|
|
me.reset();
|
|
|
|
|
delete calledBy.abort;
|
|
|
|
|
|
|
|
|
|
if (support.timeout) {
|
|
|
|
|
clearTimeout(me._timerId);
|
|
|
|
|
delete me._timerId;
|
|
|
|
|
}
|
|
|
|
|
if (!resetting) {
|
|
|
|
|
me.aborted = true;
|
|
|
|
|
me.running = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new benchmark using the same test and options.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Object} options Options object to overwrite cloned options.
|
|
|
|
|
* @returns {Object} The new benchmark instance.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* var bizarro = bench.clone({
|
|
|
|
|
* 'name': 'doppelganger'
|
|
|
|
|
* });
|
|
|
|
|
*/
|
|
|
|
|
function clone(options) {
|
|
|
|
|
var me = this,
|
|
|
|
|
result = new me.constructor(extend({}, me, options));
|
|
|
|
|
|
|
|
|
|
// correct the `options` object
|
|
|
|
|
result.options = extend({}, me.options, options);
|
|
|
|
|
|
|
|
|
|
// copy own custom properties
|
|
|
|
|
forOwn(me, function(value, key) {
|
|
|
|
|
if (!hasKey(result, key)) {
|
|
|
|
|
result[key] = deepClone(value);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determines if a benchmark is faster than another.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Object} other The benchmark to compare.
|
|
|
|
|
* @returns {Number} Returns `-1` if slower, `1` if faster, and `0` if indeterminate.
|
|
|
|
|
*/
|
|
|
|
|
function compare(other) {
|
|
|
|
|
var critical,
|
|
|
|
|
zStat,
|
|
|
|
|
me = this,
|
|
|
|
|
sample1 = me.stats.sample,
|
|
|
|
|
sample2 = other.stats.sample,
|
|
|
|
|
size1 = sample1.length,
|
|
|
|
|
size2 = sample2.length,
|
|
|
|
|
maxSize = max(size1, size2),
|
|
|
|
|
minSize = min(size1, size2),
|
|
|
|
|
u1 = getU(sample1, sample2),
|
|
|
|
|
u2 = getU(sample2, sample1),
|
|
|
|
|
u = min(u1, u2);
|
|
|
|
|
|
|
|
|
|
function getScore(xA, sampleB) {
|
|
|
|
|
return reduce(sampleB, function(total, xB) {
|
|
|
|
|
return total + (xB > xA ? 0 : xB < xA ? 1 : 0.5);
|
|
|
|
|
}, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getU(sampleA, sampleB) {
|
|
|
|
|
return reduce(sampleA, function(total, xA) {
|
|
|
|
|
return total + getScore(xA, sampleB);
|
|
|
|
|
}, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getZ(u) {
|
|
|
|
|
return (u - ((size1 * size2) / 2)) / sqrt((size1 * size2 * (size1 + size2 + 1)) / 12);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// exit early if comparing the same benchmark
|
|
|
|
|
if (me == other) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// reject the null hyphothesis the two samples come from the
|
|
|
|
|
// same population (i.e. have the same median) if...
|
|
|
|
|
if (size1 + size2 > 30) {
|
|
|
|
|
// ...the z-stat is greater than 1.96 or less than -1.96
|
|
|
|
|
// http://www.statisticslectures.com/topics/mannwhitneyu/
|
|
|
|
|
zStat = getZ(u);
|
|
|
|
|
return abs(zStat) > 1.96 ? (zStat > 0 ? -1 : 1) : 0;
|
|
|
|
|
}
|
|
|
|
|
// ...the U value is less than or equal the critical U value
|
|
|
|
|
// http://www.geoib.com/mann-whitney-u-test.html
|
|
|
|
|
critical = maxSize < 5 || minSize < 3 ? 0 : uTable[maxSize][minSize - 3];
|
|
|
|
|
return u <= critical ? (u == u1 ? 1 : -1) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset properties and abort if running.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @returns {Object} The benchmark instance.
|
|
|
|
|
*/
|
|
|
|
|
function reset() {
|
|
|
|
|
var data,
|
|
|
|
|
event,
|
|
|
|
|
me = this,
|
|
|
|
|
index = 0,
|
|
|
|
|
changes = { 'length': 0 },
|
|
|
|
|
queue = { 'length': 0 };
|
|
|
|
|
|
|
|
|
|
if (me.running && !calledBy.abort) {
|
|
|
|
|
// no worries, `reset()` is called within `abort()`
|
|
|
|
|
calledBy.reset = true;
|
|
|
|
|
me.abort();
|
|
|
|
|
delete calledBy.reset;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// a non-recursive solution to check if properties have changed
|
|
|
|
|
// http://www.jslab.dk/articles/non.recursive.preorder.traversal.part4
|
|
|
|
|
data = { 'destination': me, 'source': extend({}, me.constructor.prototype, me.options) };
|
|
|
|
|
do {
|
|
|
|
|
forOwn(data.source, function(value, key) {
|
|
|
|
|
var changed,
|
|
|
|
|
destination = data.destination,
|
|
|
|
|
currValue = destination[key];
|
|
|
|
|
|
|
|
|
|
if (value && typeof value == 'object') {
|
|
|
|
|
if (isClassOf(value, 'Array')) {
|
|
|
|
|
// check if an array value has changed to a non-array value
|
|
|
|
|
if (!isClassOf(currValue, 'Array')) {
|
|
|
|
|
changed = currValue = [];
|
|
|
|
|
}
|
|
|
|
|
// or has changed its length
|
|
|
|
|
if (currValue.length != value.length) {
|
|
|
|
|
changed = currValue = currValue.slice(0, value.length);
|
|
|
|
|
currValue.length = value.length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// check if an object has changed to a non-object value
|
|
|
|
|
else if (!currValue || typeof currValue != 'object') {
|
|
|
|
|
changed = currValue = {};
|
|
|
|
|
}
|
|
|
|
|
// register a changed object
|
|
|
|
|
if (changed) {
|
|
|
|
|
changes[changes.length++] = { 'destination': destination, 'key': key, 'value': currValue };
|
|
|
|
|
}
|
|
|
|
|
queue[queue.length++] = { 'destination': currValue, 'source': value };
|
|
|
|
|
}
|
|
|
|
|
// register a changed primitive
|
|
|
|
|
else if (value !== currValue && !(value == null || isClassOf(value, 'Function'))) {
|
|
|
|
|
changes[changes.length++] = { 'destination': destination, 'key': key, 'value': value };
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
while ((data = queue[index++]));
|
|
|
|
|
|
|
|
|
|
// if changed emit the `reset` event and if it isn't cancelled reset the benchmark
|
|
|
|
|
if (changes.length && (me.emit(event = Event('reset')), !event.cancelled)) {
|
|
|
|
|
forEach(changes, function(data) {
|
|
|
|
|
data.destination[data.key] = data.value;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Displays relevant benchmark information when coerced to a string.
|
|
|
|
|
*
|
|
|
|
|
* @name toString
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @returns {String} A string representation of the benchmark instance.
|
|
|
|
|
*/
|
|
|
|
|
function toStringBench() {
|
|
|
|
|
var me = this,
|
|
|
|
|
error = me.error,
|
|
|
|
|
hz = me.hz,
|
|
|
|
|
id = me.id,
|
|
|
|
|
stats = me.stats,
|
|
|
|
|
size = stats.sample.length,
|
|
|
|
|
pm = support.java ? '+/-' : '\xb1',
|
|
|
|
|
result = me.name || (isNaN(id) ? id : '<Test #' + id + '>');
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
result += ': ' + join(error);
|
|
|
|
|
} else {
|
|
|
|
|
result += ' x ' + formatNumber(hz.toFixed(hz < 100 ? 2 : 0)) + ' ops/sec ' + pm +
|
|
|
|
|
stats.rme.toFixed(2) + '% (' + size + ' run' + (size == 1 ? '' : 's') + ' sampled)';
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clocks the time taken to execute a test per cycle (secs).
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Object} bench The benchmark instance.
|
|
|
|
|
* @returns {Number} The time taken.
|
|
|
|
|
*/
|
|
|
|
|
function clock() {
|
|
|
|
|
var applet,
|
|
|
|
|
options = Benchmark.options,
|
|
|
|
|
template = { 'begin': 's$=new n$', 'end': 'r$=(new n$-s$)/1e3', 'uid': uid },
|
|
|
|
|
timers = [{ 'ns': timer.ns, 'res': max(0.0015, getRes('ms')), 'unit': 'ms' }];
|
|
|
|
|
|
|
|
|
|
// lazy define for hi-res timers
|
|
|
|
|
clock = function(clone) {
|
|
|
|
|
var deferred;
|
|
|
|
|
if (clone instanceof Deferred) {
|
|
|
|
|
deferred = clone;
|
|
|
|
|
clone = deferred.benchmark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bench = clone._original,
|
|
|
|
|
fn = bench.fn,
|
|
|
|
|
fnArg = deferred ? getFirstArgument(fn) || 'deferred' : '',
|
|
|
|
|
stringable = isStringable(fn);
|
|
|
|
|
|
|
|
|
|
var source = {
|
|
|
|
|
'setup': getSource(bench.setup, preprocess('m$.setup()')),
|
|
|
|
|
'fn': getSource(fn, preprocess('m$.fn(' + fnArg + ')')),
|
|
|
|
|
'fnArg': fnArg,
|
|
|
|
|
'teardown': getSource(bench.teardown, preprocess('m$.teardown()'))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var count = bench.count = clone.count,
|
|
|
|
|
decompilable = support.decompilation || stringable,
|
|
|
|
|
id = bench.id,
|
|
|
|
|
isEmpty = !(source.fn || stringable),
|
|
|
|
|
name = bench.name || (typeof id == 'number' ? '<Test #' + id + '>' : id),
|
|
|
|
|
ns = timer.ns,
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
|
|
// init `minTime` if needed
|
|
|
|
|
clone.minTime = bench.minTime || (bench.minTime = bench.options.minTime = options.minTime);
|
|
|
|
|
|
|
|
|
|
// repair nanosecond timer
|
|
|
|
|
// (some Chrome builds erase the `ns` variable after millions of executions)
|
|
|
|
|
if (applet) {
|
|
|
|
|
try {
|
|
|
|
|
ns.nanoTime();
|
|
|
|
|
} catch(e) {
|
|
|
|
|
// use non-element to avoid issues with libs that augment them
|
|
|
|
|
ns = timer.ns = new applet.Packages.nano;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compile in setup/teardown functions and the test loop.
|
|
|
|
|
// Create a new compiled test, instead of using the cached `bench.compiled`,
|
|
|
|
|
// to avoid potential engine optimizations enabled over the life of the test.
|
|
|
|
|
var compiled = bench.compiled = createFunction(preprocess('t$'), interpolate(
|
|
|
|
|
preprocess(deferred
|
|
|
|
|
? 'var d$=this,#{fnArg}=d$,m$=d$.benchmark._original,f$=m$.fn,su$=m$.setup,td$=m$.teardown;' +
|
|
|
|
|
// when `deferred.cycles` is `0` then...
|
|
|
|
|
'if(!d$.cycles){' +
|
|
|
|
|
// set `deferred.fn`
|
|
|
|
|
'd$.fn=function(){var #{fnArg}=d$;if(typeof f$=="function"){try{#{fn}\n}catch(e$){f$(d$)}}else{#{fn}\n}};' +
|
|
|
|
|
// set `deferred.teardown`
|
|
|
|
|
'd$.teardown=function(){d$.cycles=0;if(typeof td$=="function"){try{#{teardown}\n}catch(e$){td$()}}else{#{teardown}\n}};' +
|
|
|
|
|
// execute the benchmark's `setup`
|
|
|
|
|
'if(typeof su$=="function"){try{#{setup}\n}catch(e$){su$()}}else{#{setup}\n};' +
|
|
|
|
|
// start timer
|
|
|
|
|
't$.start(d$);' +
|
|
|
|
|
// execute `deferred.fn` and return a dummy object
|
|
|
|
|
'}d$.fn();return{}'
|
|
|
|
|
|
|
|
|
|
: 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count,n$=t$.ns;#{setup}\n#{begin};' +
|
|
|
|
|
'while(i$--){#{fn}\n}#{end};#{teardown}\nreturn{elapsed:r$,uid:"#{uid}"}'),
|
|
|
|
|
source
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (isEmpty) {
|
|
|
|
|
// Firefox may remove dead code from Function#toString results
|
|
|
|
|
// http://bugzil.la/536085
|
|
|
|
|
throw new Error('The test "' + name + '" is empty. This may be the result of dead code removal.');
|
|
|
|
|
}
|
|
|
|
|
else if (!deferred) {
|
|
|
|
|
// pretest to determine if compiled code is exits early, usually by a
|
|
|
|
|
// rogue `return` statement, by checking for a return object with the uid
|
|
|
|
|
bench.count = 1;
|
|
|
|
|
compiled = (compiled.call(bench, timer) || {}).uid == uid && compiled;
|
|
|
|
|
bench.count = count;
|
|
|
|
|
}
|
|
|
|
|
} catch(e) {
|
|
|
|
|
compiled = null;
|
|
|
|
|
clone.error = e || new Error(String(e));
|
|
|
|
|
bench.count = count;
|
|
|
|
|
}
|
|
|
|
|
// fallback when a test exits early or errors during pretest
|
|
|
|
|
if (decompilable && !compiled && !deferred && !isEmpty) {
|
|
|
|
|
compiled = createFunction(preprocess('t$'), interpolate(
|
|
|
|
|
preprocess(
|
|
|
|
|
(clone.error && !stringable
|
|
|
|
|
? 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count'
|
|
|
|
|
: 'function f$(){#{fn}\n}var r$,s$,m$=this,i$=m$.count'
|
|
|
|
|
) +
|
|
|
|
|
',n$=t$.ns;#{setup}\n#{begin};m$.f$=f$;while(i$--){m$.f$()}#{end};' +
|
|
|
|
|
'delete m$.f$;#{teardown}\nreturn{elapsed:r$}'
|
|
|
|
|
),
|
|
|
|
|
source
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// pretest one more time to check for errors
|
|
|
|
|
bench.count = 1;
|
|
|
|
|
compiled.call(bench, timer);
|
|
|
|
|
bench.compiled = compiled;
|
|
|
|
|
bench.count = count;
|
|
|
|
|
delete clone.error;
|
|
|
|
|
}
|
|
|
|
|
catch(e) {
|
|
|
|
|
bench.count = count;
|
|
|
|
|
if (clone.error) {
|
|
|
|
|
compiled = null;
|
|
|
|
|
} else {
|
|
|
|
|
bench.compiled = compiled;
|
|
|
|
|
clone.error = e || new Error(String(e));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// assign `compiled` to `clone` before calling in case a deferred benchmark
|
|
|
|
|
// immediately calls `deferred.resolve()`
|
|
|
|
|
clone.compiled = compiled;
|
|
|
|
|
// if no errors run the full test loop
|
|
|
|
|
if (!clone.error) {
|
|
|
|
|
result = compiled.call(deferred || bench, timer).elapsed;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current timer's minimum resolution (secs).
|
|
|
|
|
*/
|
|
|
|
|
function getRes(unit) {
|
|
|
|
|
var measured,
|
|
|
|
|
begin,
|
|
|
|
|
count = 30,
|
|
|
|
|
divisor = 1e3,
|
|
|
|
|
ns = timer.ns,
|
|
|
|
|
sample = [];
|
|
|
|
|
|
|
|
|
|
// get average smallest measurable time
|
|
|
|
|
while (count--) {
|
|
|
|
|
if (unit == 'us') {
|
|
|
|
|
divisor = 1e6;
|
|
|
|
|
if (ns.stop) {
|
|
|
|
|
ns.start();
|
|
|
|
|
while (!(measured = ns.microseconds())) { }
|
|
|
|
|
} else if (ns[perfName]) {
|
|
|
|
|
divisor = 1e3;
|
|
|
|
|
measured = Function('n', 'var r,s=n.' + perfName + '();while(!(r=n.' + perfName + '()-s)){};return r')(ns);
|
|
|
|
|
} else {
|
|
|
|
|
begin = ns();
|
|
|
|
|
while (!(measured = ns() - begin)) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (unit == 'ns') {
|
|
|
|
|
divisor = 1e9;
|
|
|
|
|
if (ns.nanoTime) {
|
|
|
|
|
begin = ns.nanoTime();
|
|
|
|
|
while (!(measured = ns.nanoTime() - begin)) { }
|
|
|
|
|
} else {
|
|
|
|
|
begin = (begin = ns())[0] + (begin[1] / divisor);
|
|
|
|
|
while (!(measured = ((measured = ns())[0] + (measured[1] / divisor)) - begin)) { }
|
|
|
|
|
divisor = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
begin = new ns;
|
|
|
|
|
while (!(measured = new ns - begin)) { }
|
|
|
|
|
}
|
|
|
|
|
// check for broken timers (nanoTime may have issues)
|
|
|
|
|
// http://alivebutsleepy.srnet.cz/unreliable-system-nanotime/
|
|
|
|
|
if (measured > 0) {
|
|
|
|
|
sample.push(measured);
|
|
|
|
|
} else {
|
|
|
|
|
sample.push(Infinity);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// convert to seconds
|
|
|
|
|
return getMean(sample) / divisor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Replaces all occurrences of `$` with a unique number and
|
|
|
|
|
* template tokens with content.
|
|
|
|
|
*/
|
|
|
|
|
function preprocess(code) {
|
|
|
|
|
return interpolate(code, template).replace(/\$/g, /\d+/.exec(uid));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
// detect nanosecond support from a Java applet
|
|
|
|
|
each(doc && doc.applets || [], function(element) {
|
|
|
|
|
return !(timer.ns = applet = 'nanoTime' in element && element);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// check type in case Safari returns an object instead of a number
|
|
|
|
|
try {
|
|
|
|
|
if (typeof timer.ns.nanoTime() == 'number') {
|
|
|
|
|
timers.push({ 'ns': timer.ns, 'res': getRes('ns'), 'unit': 'ns' });
|
|
|
|
|
}
|
|
|
|
|
} catch(e) { }
|
|
|
|
|
|
|
|
|
|
// detect Chrome's microsecond timer:
|
|
|
|
|
// enable benchmarking via the --enable-benchmarking command
|
|
|
|
|
// line switch in at least Chrome 7 to use chrome.Interval
|
|
|
|
|
try {
|
|
|
|
|
if ((timer.ns = new (window.chrome || window.chromium).Interval)) {
|
|
|
|
|
timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
|
|
|
|
|
}
|
|
|
|
|
} catch(e) { }
|
|
|
|
|
|
|
|
|
|
// detect `performance.now` microsecond resolution timer
|
|
|
|
|
if ((timer.ns = perfName && perfObject)) {
|
|
|
|
|
timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// detect Node's nanosecond resolution timer available in Node >= 0.8
|
|
|
|
|
if (processObject && typeof (timer.ns = processObject.hrtime) == 'function') {
|
|
|
|
|
timers.push({ 'ns': timer.ns, 'res': getRes('ns'), 'unit': 'ns' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// detect Wade Simmons' Node microtime module
|
|
|
|
|
if (microtimeObject && typeof (timer.ns = microtimeObject.now) == 'function') {
|
|
|
|
|
timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pick timer with highest resolution
|
|
|
|
|
timer = reduce(timers, function(timer, other) {
|
|
|
|
|
return other.res < timer.res ? other : timer;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// remove unused applet
|
|
|
|
|
if (timer.unit != 'ns' && applet) {
|
|
|
|
|
applet = destroyElement(applet);
|
|
|
|
|
}
|
|
|
|
|
// error if there are no working timers
|
|
|
|
|
if (timer.res == Infinity) {
|
|
|
|
|
throw new Error('Benchmark.js was unable to find a working timer.');
|
|
|
|
|
}
|
|
|
|
|
// use API of chosen timer
|
|
|
|
|
if (timer.unit == 'ns') {
|
|
|
|
|
if (timer.ns.nanoTime) {
|
|
|
|
|
extend(template, {
|
|
|
|
|
'begin': 's$=n$.nanoTime()',
|
|
|
|
|
'end': 'r$=(n$.nanoTime()-s$)/1e9'
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
extend(template, {
|
|
|
|
|
'begin': 's$=n$()',
|
|
|
|
|
'end': 'r$=n$(s$);r$=r$[0]+(r$[1]/1e9)'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (timer.unit == 'us') {
|
|
|
|
|
if (timer.ns.stop) {
|
|
|
|
|
extend(template, {
|
|
|
|
|
'begin': 's$=n$.start()',
|
|
|
|
|
'end': 'r$=n$.microseconds()/1e6'
|
|
|
|
|
});
|
|
|
|
|
} else if (perfName) {
|
|
|
|
|
extend(template, {
|
|
|
|
|
'begin': 's$=n$.' + perfName + '()',
|
|
|
|
|
'end': 'r$=(n$.' + perfName + '()-s$)/1e3'
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
extend(template, {
|
|
|
|
|
'begin': 's$=n$()',
|
|
|
|
|
'end': 'r$=(n$()-s$)/1e6'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// define `timer` methods
|
|
|
|
|
timer.start = createFunction(preprocess('o$'),
|
|
|
|
|
preprocess('var n$=this.ns,#{begin};o$.elapsed=0;o$.timeStamp=s$'));
|
|
|
|
|
|
|
|
|
|
timer.stop = createFunction(preprocess('o$'),
|
|
|
|
|
preprocess('var n$=this.ns,s$=o$.timeStamp,#{end};o$.elapsed=r$'));
|
|
|
|
|
|
|
|
|
|
// resolve time span required to achieve a percent uncertainty of at most 1%
|
|
|
|
|
// http://spiff.rit.edu/classes/phys273/uncert/uncert.html
|
|
|
|
|
options.minTime || (options.minTime = max(timer.res / 2 / 0.01, 0.05));
|
|
|
|
|
return clock.apply(null, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Computes stats on benchmark results.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Object} bench The benchmark instance.
|
|
|
|
|
* @param {Object} options The options object.
|
|
|
|
|
*/
|
|
|
|
|
function compute(bench, options) {
|
|
|
|
|
options || (options = {});
|
|
|
|
|
|
|
|
|
|
var async = options.async,
|
|
|
|
|
elapsed = 0,
|
|
|
|
|
initCount = bench.initCount,
|
|
|
|
|
minSamples = bench.minSamples,
|
|
|
|
|
queue = [],
|
|
|
|
|
sample = bench.stats.sample;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a clone to the queue.
|
|
|
|
|
*/
|
|
|
|
|
function enqueue() {
|
|
|
|
|
queue.push(bench.clone({
|
|
|
|
|
'_original': bench,
|
|
|
|
|
'events': {
|
|
|
|
|
'abort': [update],
|
|
|
|
|
'cycle': [update],
|
|
|
|
|
'error': [update],
|
|
|
|
|
'start': [update]
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the clone/original benchmarks to keep their data in sync.
|
|
|
|
|
*/
|
|
|
|
|
function update(event) {
|
|
|
|
|
var clone = this,
|
|
|
|
|
type = event.type;
|
|
|
|
|
|
|
|
|
|
if (bench.running) {
|
|
|
|
|
if (type == 'start') {
|
|
|
|
|
// Note: `clone.minTime` prop is inited in `clock()`
|
|
|
|
|
clone.count = bench.initCount;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (type == 'error') {
|
|
|
|
|
bench.error = clone.error;
|
|
|
|
|
}
|
|
|
|
|
if (type == 'abort') {
|
|
|
|
|
bench.abort();
|
|
|
|
|
bench.emit('cycle');
|
|
|
|
|
} else {
|
|
|
|
|
event.currentTarget = event.target = bench;
|
|
|
|
|
bench.emit(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (bench.aborted) {
|
|
|
|
|
// clear abort listeners to avoid triggering bench's abort/cycle again
|
|
|
|
|
clone.events.abort.length = 0;
|
|
|
|
|
clone.abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determines if more clones should be queued or if cycling should stop.
|
|
|
|
|
*/
|
|
|
|
|
function evaluate(event) {
|
|
|
|
|
var critical,
|
|
|
|
|
df,
|
|
|
|
|
mean,
|
|
|
|
|
moe,
|
|
|
|
|
rme,
|
|
|
|
|
sd,
|
|
|
|
|
sem,
|
|
|
|
|
variance,
|
|
|
|
|
clone = event.target,
|
|
|
|
|
done = bench.aborted,
|
|
|
|
|
now = +new Date,
|
|
|
|
|
size = sample.push(clone.times.period),
|
|
|
|
|
maxedOut = size >= minSamples && (elapsed += now - clone.times.timeStamp) / 1e3 > bench.maxTime,
|
|
|
|
|
times = bench.times,
|
|
|
|
|
varOf = function(sum, x) { return sum + pow(x - mean, 2); };
|
|
|
|
|
|
|
|
|
|
// exit early for aborted or unclockable tests
|
|
|
|
|
if (done || clone.hz == Infinity) {
|
|
|
|
|
maxedOut = !(size = sample.length = queue.length = 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
|
// sample mean (estimate of the population mean)
|
|
|
|
|
mean = getMean(sample);
|
|
|
|
|
// sample variance (estimate of the population variance)
|
|
|
|
|
variance = reduce(sample, varOf, 0) / (size - 1) || 0;
|
|
|
|
|
// sample standard deviation (estimate of the population standard deviation)
|
|
|
|
|
sd = sqrt(variance);
|
|
|
|
|
// standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
|
|
|
|
|
sem = sd / sqrt(size);
|
|
|
|
|
// degrees of freedom
|
|
|
|
|
df = size - 1;
|
|
|
|
|
// critical value
|
|
|
|
|
critical = tTable[Math.round(df) || 1] || tTable.infinity;
|
|
|
|
|
// margin of error
|
|
|
|
|
moe = sem * critical;
|
|
|
|
|
// relative margin of error
|
|
|
|
|
rme = (moe / mean) * 100 || 0;
|
|
|
|
|
|
|
|
|
|
extend(bench.stats, {
|
|
|
|
|
'deviation': sd,
|
|
|
|
|
'mean': mean,
|
|
|
|
|
'moe': moe,
|
|
|
|
|
'rme': rme,
|
|
|
|
|
'sem': sem,
|
|
|
|
|
'variance': variance
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Abort the cycle loop when the minimum sample size has been collected
|
|
|
|
|
// and the elapsed time exceeds the maximum time allowed per benchmark.
|
|
|
|
|
// We don't count cycle delays toward the max time because delays may be
|
|
|
|
|
// increased by browsers that clamp timeouts for inactive tabs.
|
|
|
|
|
// https://developer.mozilla.org/en/window.setTimeout#Inactive_tabs
|
|
|
|
|
if (maxedOut) {
|
|
|
|
|
// reset the `initCount` in case the benchmark is rerun
|
|
|
|
|
bench.initCount = initCount;
|
|
|
|
|
bench.running = false;
|
|
|
|
|
done = true;
|
|
|
|
|
times.elapsed = (now - times.timeStamp) / 1e3;
|
|
|
|
|
}
|
|
|
|
|
if (bench.hz != Infinity) {
|
|
|
|
|
bench.hz = 1 / mean;
|
|
|
|
|
times.cycle = mean * bench.count;
|
|
|
|
|
times.period = mean;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// if time permits, increase sample size to reduce the margin of error
|
|
|
|
|
if (queue.length < 2 && !maxedOut) {
|
|
|
|
|
enqueue();
|
|
|
|
|
}
|
|
|
|
|
// abort the invoke cycle when done
|
|
|
|
|
event.aborted = done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// init queue and begin
|
|
|
|
|
enqueue();
|
|
|
|
|
invoke(queue, {
|
|
|
|
|
'name': 'run',
|
|
|
|
|
'args': { 'async': async },
|
|
|
|
|
'queued': true,
|
|
|
|
|
'onCycle': evaluate,
|
|
|
|
|
'onComplete': function() { bench.emit('complete'); }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cycles a benchmark until a run `count` can be established.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Object} clone The cloned benchmark instance.
|
|
|
|
|
* @param {Object} options The options object.
|
|
|
|
|
*/
|
|
|
|
|
function cycle(clone, options) {
|
|
|
|
|
options || (options = {});
|
|
|
|
|
|
|
|
|
|
var deferred;
|
|
|
|
|
if (clone instanceof Deferred) {
|
|
|
|
|
deferred = clone;
|
|
|
|
|
clone = clone.benchmark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var clocked,
|
|
|
|
|
cycles,
|
|
|
|
|
divisor,
|
|
|
|
|
event,
|
|
|
|
|
minTime,
|
|
|
|
|
period,
|
|
|
|
|
async = options.async,
|
|
|
|
|
bench = clone._original,
|
|
|
|
|
count = clone.count,
|
|
|
|
|
times = clone.times;
|
|
|
|
|
|
|
|
|
|
// continue, if not aborted between cycles
|
|
|
|
|
if (clone.running) {
|
|
|
|
|
// `minTime` is set to `Benchmark.options.minTime` in `clock()`
|
|
|
|
|
cycles = ++clone.cycles;
|
|
|
|
|
clocked = deferred ? deferred.elapsed : clock(clone);
|
|
|
|
|
minTime = clone.minTime;
|
|
|
|
|
|
|
|
|
|
if (cycles > bench.cycles) {
|
|
|
|
|
bench.cycles = cycles;
|
|
|
|
|
}
|
|
|
|
|
if (clone.error) {
|
|
|
|
|
event = Event('error');
|
|
|
|
|
event.message = clone.error;
|
|
|
|
|
clone.emit(event);
|
|
|
|
|
if (!event.cancelled) {
|
|
|
|
|
clone.abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// continue, if not errored
|
|
|
|
|
if (clone.running) {
|
|
|
|
|
// time taken to complete last test cycle
|
|
|
|
|
bench.times.cycle = times.cycle = clocked;
|
|
|
|
|
// seconds per operation
|
|
|
|
|
period = bench.times.period = times.period = clocked / count;
|
|
|
|
|
// ops per second
|
|
|
|
|
bench.hz = clone.hz = 1 / period;
|
|
|
|
|
// avoid working our way up to this next time
|
|
|
|
|
bench.initCount = clone.initCount = count;
|
|
|
|
|
// do we need to do another cycle?
|
|
|
|
|
clone.running = clocked < minTime;
|
|
|
|
|
|
|
|
|
|
if (clone.running) {
|
|
|
|
|
// tests may clock at `0` when `initCount` is a small number,
|
|
|
|
|
// to avoid that we set its count to something a bit higher
|
|
|
|
|
if (!clocked && (divisor = divisors[clone.cycles]) != null) {
|
|
|
|
|
count = floor(4e6 / divisor);
|
|
|
|
|
}
|
|
|
|
|
// calculate how many more iterations it will take to achive the `minTime`
|
|
|
|
|
if (count <= clone.count) {
|
|
|
|
|
count += Math.ceil((minTime - clocked) / period);
|
|
|
|
|
}
|
|
|
|
|
clone.running = count != Infinity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// should we exit early?
|
|
|
|
|
event = Event('cycle');
|
|
|
|
|
clone.emit(event);
|
|
|
|
|
if (event.aborted) {
|
|
|
|
|
clone.abort();
|
|
|
|
|
}
|
|
|
|
|
// figure out what to do next
|
|
|
|
|
if (clone.running) {
|
|
|
|
|
// start a new cycle
|
|
|
|
|
clone.count = count;
|
|
|
|
|
if (deferred) {
|
|
|
|
|
clone.compiled.call(deferred, timer);
|
|
|
|
|
} else if (async) {
|
|
|
|
|
delay(clone, function() { cycle(clone, options); });
|
|
|
|
|
} else {
|
|
|
|
|
cycle(clone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// fix TraceMonkey bug associated with clock fallbacks
|
|
|
|
|
// http://bugzil.la/509069
|
|
|
|
|
if (support.browser) {
|
|
|
|
|
runScript(uid + '=1;delete ' + uid);
|
|
|
|
|
}
|
|
|
|
|
// done
|
|
|
|
|
clone.emit('complete');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Runs the benchmark.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @param {Object} [options={}] Options object.
|
|
|
|
|
* @returns {Object} The benchmark instance.
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // basic usage
|
|
|
|
|
* bench.run();
|
|
|
|
|
*
|
|
|
|
|
* // or with options
|
|
|
|
|
* bench.run({ 'async': true });
|
|
|
|
|
*/
|
|
|
|
|
function run(options) {
|
|
|
|
|
var me = this,
|
|
|
|
|
event = Event('start');
|
|
|
|
|
|
|
|
|
|
// set `running` to `false` so `reset()` won't call `abort()`
|
|
|
|
|
me.running = false;
|
|
|
|
|
me.reset();
|
|
|
|
|
me.running = true;
|
|
|
|
|
|
|
|
|
|
me.count = me.initCount;
|
|
|
|
|
me.times.timeStamp = +new Date;
|
|
|
|
|
me.emit(event);
|
|
|
|
|
|
|
|
|
|
if (!event.cancelled) {
|
|
|
|
|
options = { 'async': ((options = options && options.async) == null ? me.async : options) && support.timeout };
|
|
|
|
|
|
|
|
|
|
// for clones created within `compute()`
|
|
|
|
|
if (me._original) {
|
|
|
|
|
if (me.defer) {
|
|
|
|
|
Deferred(me);
|
|
|
|
|
} else {
|
|
|
|
|
cycle(me, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// for original benchmarks
|
|
|
|
|
else {
|
|
|
|
|
compute(me, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
// Firefox 1 erroneously defines variable and argument names of functions on
|
|
|
|
|
// the function itself as non-configurable properties with `undefined` values.
|
|
|
|
|
// The bugginess continues as the `Benchmark` constructor has an argument
|
|
|
|
|
// named `options` and Firefox 1 will not assign a value to `Benchmark.options`,
|
|
|
|
|
// making it non-writable in the process, unless it is the first property
|
|
|
|
|
// assigned by for-in loop of `extend()`.
|
|
|
|
|
extend(Benchmark, {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The default options copied by benchmark instances.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
'options': {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A flag to indicate that benchmark cycles will execute asynchronously
|
|
|
|
|
* by default.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
'async': false,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A flag to indicate that the benchmark clock is deferred.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
'defer': false,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The delay between test cycles (secs).
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'delay': 0.005,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Displayed by Benchmark#toString when a `name` is not available
|
|
|
|
|
* (auto-generated if absent).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type String
|
|
|
|
|
*/
|
|
|
|
|
'id': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The default number of times to execute a test on a benchmark's first cycle.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'initCount': 1,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The maximum time a benchmark is allowed to run before finishing (secs).
|
|
|
|
|
* Note: Cycle delays aren't counted toward the maximum time.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'maxTime': 5,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The minimum sample size required to perform statistical analysis.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'minSamples': 5,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The time needed to reduce the percent uncertainty of measurement to 1% (secs).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'minTime': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The name of the benchmark.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type String
|
|
|
|
|
*/
|
|
|
|
|
'name': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An event listener called when the benchmark is aborted.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Function
|
|
|
|
|
*/
|
|
|
|
|
'onAbort': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An event listener called when the benchmark completes running.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Function
|
|
|
|
|
*/
|
|
|
|
|
'onComplete': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An event listener called after each run cycle.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Function
|
|
|
|
|
*/
|
|
|
|
|
'onCycle': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An event listener called when a test errors.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Function
|
|
|
|
|
*/
|
|
|
|
|
'onError': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An event listener called when the benchmark is reset.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Function
|
|
|
|
|
*/
|
|
|
|
|
'onReset': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An event listener called when the benchmark starts running.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.options
|
|
|
|
|
* @type Function
|
|
|
|
|
*/
|
|
|
|
|
'onStart': undefined
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Platform object with properties describing things like browser name,
|
|
|
|
|
* version, and operating system.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
'platform': req('platform') || window.platform || {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The platform description.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.platform
|
|
|
|
|
* @type String
|
|
|
|
|
*/
|
|
|
|
|
'description': window.navigator && navigator.userAgent || null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The name of the browser layout engine.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.platform
|
|
|
|
|
* @type String|Null
|
|
|
|
|
*/
|
|
|
|
|
'layout': null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The name of the product hosting the browser.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.platform
|
|
|
|
|
* @type String|Null
|
|
|
|
|
*/
|
|
|
|
|
'product': null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The name of the browser/environment.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.platform
|
|
|
|
|
* @type String|Null
|
|
|
|
|
*/
|
|
|
|
|
'name': null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The name of the product's manufacturer.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.platform
|
|
|
|
|
* @type String|Null
|
|
|
|
|
*/
|
|
|
|
|
'manufacturer': null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The name of the operating system.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.platform
|
|
|
|
|
* @type String|Null
|
|
|
|
|
*/
|
|
|
|
|
'os': null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The alpha/beta release indicator.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.platform
|
|
|
|
|
* @type String|Null
|
|
|
|
|
*/
|
|
|
|
|
'prerelease': null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The browser/environment version.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.platform
|
|
|
|
|
* @type String|Null
|
|
|
|
|
*/
|
|
|
|
|
'version': null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return platform description when the platform object is coerced to a string.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.platform
|
|
|
|
|
* @type Function
|
|
|
|
|
* @returns {String} The platform description.
|
|
|
|
|
*/
|
|
|
|
|
'toString': function() {
|
|
|
|
|
return this.description || '';
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The semantic version number.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type String
|
|
|
|
|
*/
|
|
|
|
|
'version': '1.0.0',
|
|
|
|
|
|
|
|
|
|
// an object of environment/feature detection flags
|
|
|
|
|
'support': support,
|
|
|
|
|
|
|
|
|
|
// clone objects
|
|
|
|
|
'deepClone': deepClone,
|
|
|
|
|
|
|
|
|
|
// iteration utility
|
|
|
|
|
'each': each,
|
|
|
|
|
|
|
|
|
|
// augment objects
|
|
|
|
|
'extend': extend,
|
|
|
|
|
|
|
|
|
|
// generic Array#filter
|
|
|
|
|
'filter': filter,
|
|
|
|
|
|
|
|
|
|
// generic Array#forEach
|
|
|
|
|
'forEach': forEach,
|
|
|
|
|
|
|
|
|
|
// generic own property iteration utility
|
|
|
|
|
'forOwn': forOwn,
|
|
|
|
|
|
|
|
|
|
// converts a number to a comma-separated string
|
|
|
|
|
'formatNumber': formatNumber,
|
|
|
|
|
|
|
|
|
|
// generic Object#hasOwnProperty
|
|
|
|
|
// (trigger hasKey's lazy define before assigning it to Benchmark)
|
|
|
|
|
'hasKey': (hasKey(Benchmark, ''), hasKey),
|
|
|
|
|
|
|
|
|
|
// generic Array#indexOf
|
|
|
|
|
'indexOf': indexOf,
|
|
|
|
|
|
|
|
|
|
// template utility
|
|
|
|
|
'interpolate': interpolate,
|
|
|
|
|
|
|
|
|
|
// invokes a method on each item in an array
|
|
|
|
|
'invoke': invoke,
|
|
|
|
|
|
|
|
|
|
// generic Array#join for arrays and objects
|
|
|
|
|
'join': join,
|
|
|
|
|
|
|
|
|
|
// generic Array#map
|
|
|
|
|
'map': map,
|
|
|
|
|
|
|
|
|
|
// retrieves a property value from each item in an array
|
|
|
|
|
'pluck': pluck,
|
|
|
|
|
|
|
|
|
|
// generic Array#reduce
|
|
|
|
|
'reduce': reduce
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
extend(Benchmark.prototype, {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The number of times a test was executed.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'count': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The number of cycles performed while benchmarking.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'cycles': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The number of executions per second.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'hz': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The compiled test function.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Function|String
|
|
|
|
|
*/
|
|
|
|
|
'compiled': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The error object if the test failed.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
'error': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The test to benchmark.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Function|String
|
|
|
|
|
*/
|
|
|
|
|
'fn': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A flag to indicate if the benchmark is aborted.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
'aborted': false,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A flag to indicate if the benchmark is running.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
'running': false,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compiled into the test and executed immediately **before** the test loop.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Function|String
|
|
|
|
|
* @example
|
|
|
|
|
*
|
|
|
|
|
* // basic usage
|
|
|
|
|
* var bench = Benchmark({
|
|
|
|
|
* 'setup': function() {
|
|
|
|
|
* var c = this.count,
|
|
|
|
|
* element = document.getElementById('container');
|
|
|
|
|
* while (c--) {
|
|
|
|
|
* element.appendChild(document.createElement('div'));
|
|
|
|
|
* }
|
|
|
|
|
* },
|
|
|
|
|
* 'fn': function() {
|
|
|
|
|
* element.removeChild(element.lastChild);
|
|
|
|
|
* }
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // compiles to something like:
|
|
|
|
|
* var c = this.count,
|
|
|
|
|
* element = document.getElementById('container');
|
|
|
|
|
* while (c--) {
|
|
|
|
|
* element.appendChild(document.createElement('div'));
|
|
|
|
|
* }
|
|
|
|
|
* var start = new Date;
|
|
|
|
|
* while (count--) {
|
|
|
|
|
* element.removeChild(element.lastChild);
|
|
|
|
|
* }
|
|
|
|
|
* var end = new Date - start;
|
|
|
|
|
*
|
|
|
|
|
* // or using strings
|
|
|
|
|
* var bench = Benchmark({
|
|
|
|
|
* 'setup': '\
|
|
|
|
|
* var a = 0;\n\
|
|
|
|
|
* (function() {\n\
|
|
|
|
|
* (function() {\n\
|
|
|
|
|
* (function() {',
|
|
|
|
|
* 'fn': 'a += 1;',
|
|
|
|
|
* 'teardown': '\
|
|
|
|
|
* }())\n\
|
|
|
|
|
* }())\n\
|
|
|
|
|
* }())'
|
|
|
|
|
* });
|
|
|
|
|
*
|
|
|
|
|
* // compiles to something like:
|
|
|
|
|
* var a = 0;
|
|
|
|
|
* (function() {
|
|
|
|
|
* (function() {
|
|
|
|
|
* (function() {
|
|
|
|
|
* var start = new Date;
|
|
|
|
|
* while (count--) {
|
|
|
|
|
* a += 1;
|
|
|
|
|
* }
|
|
|
|
|
* var end = new Date - start;
|
|
|
|
|
* }())
|
|
|
|
|
* }())
|
|
|
|
|
* }())
|
|
|
|
|
*/
|
|
|
|
|
'setup': noop,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compiled into the test and executed immediately **after** the test loop.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Function|String
|
|
|
|
|
*/
|
|
|
|
|
'teardown': noop,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An object of stats including mean, margin or error, and standard deviation.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
'stats': {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The margin of error.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#stats
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'moe': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The relative margin of error (expressed as a percentage of the mean).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#stats
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'rme': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The standard error of the mean.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#stats
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'sem': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The sample standard deviation.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#stats
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'deviation': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The sample arithmetic mean.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#stats
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'mean': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The array of sampled periods.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#stats
|
|
|
|
|
* @type Array
|
|
|
|
|
*/
|
|
|
|
|
'sample': [],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The sample variance.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#stats
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'variance': 0
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An object of timing data including cycle, elapsed, period, start, and stop.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
'times': {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The time taken to complete the last cycle (secs).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#times
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'cycle': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The time taken to complete the benchmark (secs).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#times
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'elapsed': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The time taken to execute the test once (secs).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#times
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'period': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A timestamp of when the benchmark started (ms).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark#times
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'timeStamp': 0
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// aborts benchmark (does not record times)
|
|
|
|
|
'abort': abort,
|
|
|
|
|
|
|
|
|
|
// creates a new benchmark using the same test and options
|
|
|
|
|
'clone': clone,
|
|
|
|
|
|
|
|
|
|
// compares benchmark's hertz with another
|
|
|
|
|
'compare': compare,
|
|
|
|
|
|
|
|
|
|
// executes listeners
|
|
|
|
|
'emit': emit,
|
|
|
|
|
|
|
|
|
|
// get listeners
|
|
|
|
|
'listeners': listeners,
|
|
|
|
|
|
|
|
|
|
// unregister listeners
|
|
|
|
|
'off': off,
|
|
|
|
|
|
|
|
|
|
// register listeners
|
|
|
|
|
'on': on,
|
|
|
|
|
|
|
|
|
|
// reset benchmark properties
|
|
|
|
|
'reset': reset,
|
|
|
|
|
|
|
|
|
|
// runs the benchmark
|
|
|
|
|
'run': run,
|
|
|
|
|
|
|
|
|
|
// pretty print benchmark info
|
|
|
|
|
'toString': toStringBench
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
extend(Deferred.prototype, {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The deferred benchmark instance.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Deferred
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
'benchmark': null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The number of deferred cycles performed while benchmarking.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Deferred
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'cycles': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The time taken to complete the deferred benchmark (secs).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Deferred
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'elapsed': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A timestamp of when the deferred benchmark started (ms).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Deferred
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'timeStamp': 0,
|
|
|
|
|
|
|
|
|
|
// cycles/completes the deferred benchmark
|
|
|
|
|
'resolve': resolve
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
extend(Event.prototype, {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A flag to indicate if the emitters listener iteration is aborted.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Event
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
'aborted': false,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A flag to indicate if the default action is cancelled.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Event
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
'cancelled': false,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The object whose listeners are currently being processed.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Event
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
'currentTarget': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The return value of the last executed listener.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Event
|
|
|
|
|
* @type Mixed
|
|
|
|
|
*/
|
|
|
|
|
'result': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The object to which the event was originally emitted.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Event
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
'target': undefined,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A timestamp of when the event was created (ms).
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Event
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'timeStamp': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The event type.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Event
|
|
|
|
|
* @type String
|
|
|
|
|
*/
|
|
|
|
|
'type': ''
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The default options copied by suite instances.
|
|
|
|
|
*
|
|
|
|
|
* @static
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @type Object
|
|
|
|
|
*/
|
|
|
|
|
Suite.options = {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The name of the suite.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite.options
|
|
|
|
|
* @type String
|
|
|
|
|
*/
|
|
|
|
|
'name': undefined
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
extend(Suite.prototype, {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The number of benchmarks in the suite.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @type Number
|
|
|
|
|
*/
|
|
|
|
|
'length': 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A flag to indicate if the suite is aborted.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
'aborted': false,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A flag to indicate if the suite is running.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @type Boolean
|
|
|
|
|
*/
|
|
|
|
|
'running': false,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An `Array#forEach` like method.
|
|
|
|
|
* Callbacks may terminate the loop by explicitly returning `false`.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Function} callback The function called per iteration.
|
|
|
|
|
* @returns {Object} The suite iterated over.
|
|
|
|
|
*/
|
|
|
|
|
'forEach': methodize(forEach),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An `Array#indexOf` like method.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Mixed} value The value to search for.
|
|
|
|
|
* @returns {Number} The index of the matched value or `-1`.
|
|
|
|
|
*/
|
|
|
|
|
'indexOf': methodize(indexOf),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Invokes a method on all benchmarks in the suite.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {String|Object} name The name of the method to invoke OR options object.
|
|
|
|
|
* @param {Mixed} [arg1, arg2, ...] Arguments to invoke the method with.
|
|
|
|
|
* @returns {Array} A new array of values returned from each method invoked.
|
|
|
|
|
*/
|
|
|
|
|
'invoke': methodize(invoke),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts the suite of benchmarks to a string.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {String} [separator=','] A string to separate each element of the array.
|
|
|
|
|
* @returns {String} The string.
|
|
|
|
|
*/
|
|
|
|
|
'join': [].join,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An `Array#map` like method.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Function} callback The function called per iteration.
|
|
|
|
|
* @returns {Array} A new array of values returned by the callback.
|
|
|
|
|
*/
|
|
|
|
|
'map': methodize(map),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves the value of a specified property from all benchmarks in the suite.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {String} property The property to pluck.
|
|
|
|
|
* @returns {Array} A new array of property values.
|
|
|
|
|
*/
|
|
|
|
|
'pluck': methodize(pluck),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the last benchmark from the suite and returns it.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @returns {Mixed} The removed benchmark.
|
|
|
|
|
*/
|
|
|
|
|
'pop': [].pop,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Appends benchmarks to the suite.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @returns {Number} The suite's new length.
|
|
|
|
|
*/
|
|
|
|
|
'push': [].push,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sorts the benchmarks of the suite.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Function} [compareFn=null] A function that defines the sort order.
|
|
|
|
|
* @returns {Object} The sorted suite.
|
|
|
|
|
*/
|
|
|
|
|
'sort': [].sort,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An `Array#reduce` like method.
|
|
|
|
|
*
|
|
|
|
|
* @memberOf Benchmark.Suite
|
|
|
|
|
* @param {Function} callback The function called per iteration.
|
|
|
|
|
* @param {Mixed} accumulator Initial value of the accumulator.
|
|
|
|
|
* @returns {Mixed} The accumulator.
|
|
|
|
|
*/
|
|
|
|
|
'reduce': methodize(reduce),
|
|
|
|
|
|
|
|
|
|
// aborts all benchmarks in the suite
|
|
|
|
|
'abort': abortSuite,
|
|
|
|
|
|
|
|
|
|
// adds a benchmark to the suite
|
|
|
|
|
'add': add,
|
|
|
|
|
|
|
|
|
|
// creates a new suite with cloned benchmarks
|
|
|
|
|
'clone': cloneSuite,
|
|
|
|
|
|
|
|
|
|
// executes listeners of a specified type
|
|
|
|
|
'emit': emit,
|
|
|
|
|
|
|
|
|
|
// creates a new suite of filtered benchmarks
|
|
|
|
|
'filter': filterSuite,
|
|
|
|
|
|
|
|
|
|
// get listeners
|
|
|
|
|
'listeners': listeners,
|
|
|
|
|
|
|
|
|
|
// unregister listeners
|
|
|
|
|
'off': off,
|
|
|
|
|
|
|
|
|
|
// register listeners
|
|
|
|
|
'on': on,
|
|
|
|
|
|
|
|
|
|
// resets all benchmarks in the suite
|
|
|
|
|
'reset': resetSuite,
|
|
|
|
|
|
|
|
|
|
// runs all benchmarks in the suite
|
|
|
|
|
'run': runSuite,
|
|
|
|
|
|
|
|
|
|
// array methods
|
|
|
|
|
'concat': concat,
|
|
|
|
|
|
|
|
|
|
'reverse': reverse,
|
|
|
|
|
|
|
|
|
|
'shift': shift,
|
|
|
|
|
|
|
|
|
|
'slice': slice,
|
|
|
|
|
|
|
|
|
|
'splice': splice,
|
|
|
|
|
|
|
|
|
|
'unshift': unshift
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
// expose Deferred, Event and Suite
|
|
|
|
|
extend(Benchmark, {
|
|
|
|
|
'Deferred': Deferred,
|
|
|
|
|
'Event': Event,
|
|
|
|
|
'Suite': Suite
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// expose Benchmark
|
|
|
|
|
// some AMD build optimizers, like r.js, check for specific condition patterns like the following:
|
|
|
|
|
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
|
|
|
|
// define as an anonymous module so, through path mapping, it can be aliased
|
|
|
|
|
define(function() {
|
|
|
|
|
return Benchmark;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// check for `exports` after `define` in case a build optimizer adds an `exports` object
|
|
|
|
|
else if (freeExports) {
|
|
|
|
|
// in Node.js or RingoJS v0.8.0+
|
|
|
|
|
if (typeof module == 'object' && module && module.exports == freeExports) {
|
|
|
|
|
(module.exports = Benchmark).Benchmark = Benchmark;
|
|
|
|
|
}
|
|
|
|
|
// in Narwhal or RingoJS v0.7.0-
|
|
|
|
|
else {
|
|
|
|
|
freeExports.Benchmark = Benchmark;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// in a browser or Rhino
|
|
|
|
|
else {
|
|
|
|
|
// use square bracket notation so Closure Compiler won't munge `Benchmark`
|
|
|
|
|
// http://code.google.com/closure/compiler/docs/api-tutorial3.html#export
|
|
|
|
|
window['Benchmark'] = Benchmark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// trigger clock's lazy define early to avoid a security error
|
|
|
|
|
if (support.air) {
|
|
|
|
|
clock({ '_original': { 'fn': noop, 'count': 1, 'options': {} } });
|
|
|
|
|
}
|
|
|
|
|
}(this));
|
|
|
|
|
|
|
|
|
|
},{"__browserify_process":2}],6:[function(require,module,exports){
|
|
|
|
|
exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
|
|
|
|
|
var e, m,
|
|
|
|
|
eLen = nBytes * 8 - mLen - 1,
|
|
|
|
|
eMax = (1 << eLen) - 1,
|
|
|
|
|
eBias = eMax >> 1,
|
|
|
|
|
nBits = -7,
|
|
|
|
|
i = isBE ? 0 : (nBytes - 1),
|
|
|
|
|
d = isBE ? 1 : -1,
|
|
|
|
|
s = buffer[offset + i];
|
|
|
|
|
|
|
|
|
|
i += d;
|
|
|
|
|
|
|
|
|
|
e = s & ((1 << (-nBits)) - 1);
|
|
|
|
|
s >>= (-nBits);
|
|
|
|
|
nBits += eLen;
|
|
|
|
|
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
|
|
|
|
|
|
|
|
|
|
m = e & ((1 << (-nBits)) - 1);
|
|
|
|
|
e >>= (-nBits);
|
|
|
|
|
nBits += mLen;
|
|
|
|
|
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
|
|
|
|
|
|
|
|
|
|
if (e === 0) {
|
|
|
|
|
e = 1 - eBias;
|
|
|
|
|
} else if (e === eMax) {
|
|
|
|
|
return m ? NaN : ((s ? -1 : 1) * Infinity);
|
|
|
|
|
} else {
|
|
|
|
|
m = m + Math.pow(2, mLen);
|
|
|
|
|
e = e - eBias;
|
|
|
|
|
}
|
|
|
|
|
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
|
|
|
|
|
var e, m, c,
|
|
|
|
|
eLen = nBytes * 8 - mLen - 1,
|
|
|
|
|
eMax = (1 << eLen) - 1,
|
|
|
|
|
eBias = eMax >> 1,
|
|
|
|
|
rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
|
|
|
|
|
i = isBE ? (nBytes - 1) : 0,
|
|
|
|
|
d = isBE ? -1 : 1,
|
|
|
|
|
s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
value = Math.abs(value);
|
|
|
|
|
|
|
|
|
|
if (isNaN(value) || value === Infinity) {
|
|
|
|
|
m = isNaN(value) ? 1 : 0;
|
|
|
|
|
e = eMax;
|
|
|
|
|
} else {
|
|
|
|
|
e = Math.floor(Math.log(value) / Math.LN2);
|
|
|
|
|
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
|
|
|
e--;
|
|
|
|
|
c *= 2;
|
|
|
|
|
}
|
|
|
|
|
if (e + eBias >= 1) {
|
|
|
|
|
value += rt / c;
|
|
|
|
|
} else {
|
|
|
|
|
value += rt * Math.pow(2, 1 - eBias);
|
|
|
|
|
}
|
|
|
|
|
if (value * c >= 2) {
|
|
|
|
|
e++;
|
|
|
|
|
c /= 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e + eBias >= eMax) {
|
|
|
|
|
m = 0;
|
|
|
|
|
e = eMax;
|
|
|
|
|
} else if (e + eBias >= 1) {
|
|
|
|
|
m = (value * c - 1) * Math.pow(2, mLen);
|
|
|
|
|
e = e + eBias;
|
|
|
|
|
} else {
|
|
|
|
|
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
|
|
|
e = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
|
|
|
|
|
|
|
|
|
|
e = (e << mLen) | m;
|
|
|
|
|
eLen += mLen;
|
|
|
|
|
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
|
|
|
|
|
|
|
|
|
|
buffer[offset + i - d] |= s * 128;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
},{}],7:[function(require,module,exports){
|
|
|
|
|
var assert;
|
|
|
|
|
exports.Buffer = Buffer;
|
|
|
|
|
exports.SlowBuffer = Buffer;
|
|
|
|
|
Buffer.poolSize = 8192;
|
|
|
|
|
exports.INSPECT_MAX_BYTES = 50;
|
|
|
|
|
|
|
|
|
|
function stringtrim(str) {
|
|
|
|
|
if (str.trim) return str.trim();
|
|
|
|
|
return str.replace(/^\s+|\s+$/g, '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Buffer(subject, encoding, offset) {
|
|
|
|
|
if(!assert) assert= require('assert');
|
|
|
|
|
if (!(this instanceof Buffer)) {
|
|
|
|
|
return new Buffer(subject, encoding, offset);
|
|
|
|
|
}
|
|
|
|
|
this.parent = this;
|
|
|
|
|
this.offset = 0;
|
|
|
|
|
|
|
|
|
|
// Work-around: node's base64 implementation
|
|
|
|
|
// allows for non-padded strings while base64-js
|
|
|
|
|
// does not..
|
|
|
|
|
if (encoding == "base64" && typeof subject == "string") {
|
|
|
|
|
subject = stringtrim(subject);
|
|
|
|
|
while (subject.length % 4 != 0) {
|
|
|
|
|
subject = subject + "=";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var type;
|
|
|
|
|
|
|
|
|
|
// Are we slicing?
|
|
|
|
|
if (typeof offset === 'number') {
|
|
|
|
|
this.length = coerce(encoding);
|
|
|
|
|
// slicing works, with limitations (no parent tracking/update)
|
|
|
|
|
// check https://github.com/toots/buffer-browserify/issues/19
|
|
|
|
|
for (var i = 0; i < this.length; i++) {
|
|
|
|
|
this[i] = subject.get(i+offset);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Find the length
|
|
|
|
|
switch (type = typeof subject) {
|
|
|
|
|
case 'number':
|
|
|
|
|
this.length = coerce(subject);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'string':
|
|
|
|
|
this.length = Buffer.byteLength(subject, encoding);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'object': // Assume object is an array
|
|
|
|
|
this.length = coerce(subject.length);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('First argument needs to be a number, ' +
|
|
|
|
|
'array or string.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Treat array-ish objects as a byte array.
|
|
|
|
|
if (isArrayIsh(subject)) {
|
|
|
|
|
for (var i = 0; i < this.length; i++) {
|
|
|
|
|
if (subject instanceof Buffer) {
|
|
|
|
|
this[i] = subject.readUInt8(i);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this[i] = subject[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (type == 'string') {
|
|
|
|
|
// We are a string
|
|
|
|
|
this.length = this.write(subject, 0, encoding);
|
|
|
|
|
} else if (type === 'number') {
|
|
|
|
|
for (var i = 0; i < this.length; i++) {
|
|
|
|
|
this[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.get = function get(i) {
|
|
|
|
|
if (i < 0 || i >= this.length) throw new Error('oob');
|
|
|
|
|
return this[i];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.set = function set(i, v) {
|
|
|
|
|
if (i < 0 || i >= this.length) throw new Error('oob');
|
|
|
|
|
return this[i] = v;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.byteLength = function (str, encoding) {
|
|
|
|
|
switch (encoding || "utf8") {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return str.length / 2;
|
|
|
|
|
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
return utf8ToBytes(str).length;
|
|
|
|
|
|
|
|
|
|
case 'ascii':
|
|
|
|
|
case 'binary':
|
|
|
|
|
return str.length;
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return base64ToBytes(str).length;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown encoding');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.utf8Write = function (string, offset, length) {
|
|
|
|
|
var bytes, pos;
|
|
|
|
|
return Buffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.asciiWrite = function (string, offset, length) {
|
|
|
|
|
var bytes, pos;
|
|
|
|
|
return Buffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.binaryWrite = Buffer.prototype.asciiWrite;
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.base64Write = function (string, offset, length) {
|
|
|
|
|
var bytes, pos;
|
|
|
|
|
return Buffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.base64Slice = function (start, end) {
|
|
|
|
|
var bytes = Array.prototype.slice.apply(this, arguments)
|
|
|
|
|
return require("base64-js").fromByteArray(bytes);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.utf8Slice = function () {
|
|
|
|
|
var bytes = Array.prototype.slice.apply(this, arguments);
|
|
|
|
|
var res = "";
|
|
|
|
|
var tmp = "";
|
|
|
|
|
var i = 0;
|
|
|
|
|
while (i < bytes.length) {
|
|
|
|
|
if (bytes[i] <= 0x7F) {
|
|
|
|
|
res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]);
|
|
|
|
|
tmp = "";
|
|
|
|
|
} else
|
|
|
|
|
tmp += "%" + bytes[i].toString(16);
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res + decodeUtf8Char(tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.asciiSlice = function () {
|
|
|
|
|
var bytes = Array.prototype.slice.apply(this, arguments);
|
|
|
|
|
var ret = "";
|
|
|
|
|
for (var i = 0; i < bytes.length; i++)
|
|
|
|
|
ret += String.fromCharCode(bytes[i]);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.binarySlice = Buffer.prototype.asciiSlice;
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.inspect = function() {
|
|
|
|
|
var out = [],
|
|
|
|
|
len = this.length;
|
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
|
|
|
out[i] = toHex(this[i]);
|
|
|
|
|
if (i == exports.INSPECT_MAX_BYTES) {
|
|
|
|
|
out[i + 1] = '...';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return '<Buffer ' + out.join(' ') + '>';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.hexSlice = function(start, end) {
|
|
|
|
|
var len = this.length;
|
|
|
|
|
|
|
|
|
|
if (!start || start < 0) start = 0;
|
|
|
|
|
if (!end || end < 0 || end > len) end = len;
|
|
|
|
|
|
|
|
|
|
var out = '';
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
out += toHex(this[i]);
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.toString = function(encoding, start, end) {
|
|
|
|
|
encoding = String(encoding || 'utf8').toLowerCase();
|
|
|
|
|
start = +start || 0;
|
|
|
|
|
if (typeof end == 'undefined') end = this.length;
|
|
|
|
|
|
|
|
|
|
// Fastpath empty strings
|
|
|
|
|
if (+end == start) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (encoding) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return this.hexSlice(start, end);
|
|
|
|
|
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
return this.utf8Slice(start, end);
|
|
|
|
|
|
|
|
|
|
case 'ascii':
|
|
|
|
|
return this.asciiSlice(start, end);
|
|
|
|
|
|
|
|
|
|
case 'binary':
|
|
|
|
|
return this.binarySlice(start, end);
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return this.base64Slice(start, end);
|
|
|
|
|
|
|
|
|
|
case 'ucs2':
|
|
|
|
|
case 'ucs-2':
|
|
|
|
|
return this.ucs2Slice(start, end);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown encoding');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.hexWrite = function(string, offset, length) {
|
|
|
|
|
offset = +offset || 0;
|
|
|
|
|
var remaining = this.length - offset;
|
|
|
|
|
if (!length) {
|
|
|
|
|
length = remaining;
|
|
|
|
|
} else {
|
|
|
|
|
length = +length;
|
|
|
|
|
if (length > remaining) {
|
|
|
|
|
length = remaining;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// must be an even number of digits
|
|
|
|
|
var strLen = string.length;
|
|
|
|
|
if (strLen % 2) {
|
|
|
|
|
throw new Error('Invalid hex string');
|
|
|
|
|
}
|
|
|
|
|
if (length > strLen / 2) {
|
|
|
|
|
length = strLen / 2;
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
var byte = parseInt(string.substr(i * 2, 2), 16);
|
|
|
|
|
if (isNaN(byte)) throw new Error('Invalid hex string');
|
|
|
|
|
this[offset + i] = byte;
|
|
|
|
|
}
|
|
|
|
|
Buffer._charsWritten = i * 2;
|
|
|
|
|
return i;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.write = function(string, offset, length, encoding) {
|
|
|
|
|
// Support both (string, offset, length, encoding)
|
|
|
|
|
// and the legacy (string, encoding, offset, length)
|
|
|
|
|
if (isFinite(offset)) {
|
|
|
|
|
if (!isFinite(length)) {
|
|
|
|
|
encoding = length;
|
|
|
|
|
length = undefined;
|
|
|
|
|
}
|
|
|
|
|
} else { // legacy
|
|
|
|
|
var swap = encoding;
|
|
|
|
|
encoding = offset;
|
|
|
|
|
offset = length;
|
|
|
|
|
length = swap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset = +offset || 0;
|
|
|
|
|
var remaining = this.length - offset;
|
|
|
|
|
if (!length) {
|
|
|
|
|
length = remaining;
|
|
|
|
|
} else {
|
|
|
|
|
length = +length;
|
|
|
|
|
if (length > remaining) {
|
|
|
|
|
length = remaining;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
encoding = String(encoding || 'utf8').toLowerCase();
|
|
|
|
|
|
|
|
|
|
switch (encoding) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return this.hexWrite(string, offset, length);
|
|
|
|
|
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
return this.utf8Write(string, offset, length);
|
|
|
|
|
|
|
|
|
|
case 'ascii':
|
|
|
|
|
return this.asciiWrite(string, offset, length);
|
|
|
|
|
|
|
|
|
|
case 'binary':
|
|
|
|
|
return this.binaryWrite(string, offset, length);
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return this.base64Write(string, offset, length);
|
|
|
|
|
|
|
|
|
|
case 'ucs2':
|
|
|
|
|
case 'ucs-2':
|
|
|
|
|
return this.ucs2Write(string, offset, length);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Unknown encoding');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// slice(start, end)
|
|
|
|
|
function clamp(index, len, defaultValue) {
|
|
|
|
|
if (typeof index !== 'number') return defaultValue;
|
|
|
|
|
index = ~~index; // Coerce to integer.
|
|
|
|
|
if (index >= len) return len;
|
|
|
|
|
if (index >= 0) return index;
|
|
|
|
|
index += len;
|
|
|
|
|
if (index >= 0) return index;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.slice = function(start, end) {
|
|
|
|
|
var len = this.length;
|
|
|
|
|
start = clamp(start, len, 0);
|
|
|
|
|
end = clamp(end, len, len);
|
|
|
|
|
return new Buffer(this, end - start, +start);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
|
|
|
Buffer.prototype.copy = function(target, target_start, start, end) {
|
|
|
|
|
var source = this;
|
|
|
|
|
start || (start = 0);
|
|
|
|
|
if (end === undefined || isNaN(end)) {
|
|
|
|
|
end = this.length;
|
|
|
|
|
}
|
|
|
|
|
target_start || (target_start = 0);
|
|
|
|
|
|
|
|
|
|
if (end < start) throw new Error('sourceEnd < sourceStart');
|
|
|
|
|
|
|
|
|
|
// Copy 0 bytes; we're done
|
|
|
|
|
if (end === start) return 0;
|
|
|
|
|
if (target.length == 0 || source.length == 0) return 0;
|
|
|
|
|
|
|
|
|
|
if (target_start < 0 || target_start >= target.length) {
|
|
|
|
|
throw new Error('targetStart out of bounds');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (start < 0 || start >= source.length) {
|
|
|
|
|
throw new Error('sourceStart out of bounds');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end < 0 || end > source.length) {
|
|
|
|
|
throw new Error('sourceEnd out of bounds');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Are we oob?
|
|
|
|
|
if (end > this.length) {
|
|
|
|
|
end = this.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (target.length - target_start < end - start) {
|
|
|
|
|
end = target.length - target_start + start;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var temp = [];
|
|
|
|
|
for (var i=start; i<end; i++) {
|
|
|
|
|
assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!");
|
|
|
|
|
temp.push(this[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i=target_start; i<target_start+temp.length; i++) {
|
|
|
|
|
target[i] = temp[i-target_start];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// fill(value, start=0, end=buffer.length)
|
|
|
|
|
Buffer.prototype.fill = function fill(value, start, end) {
|
|
|
|
|
value || (value = 0);
|
|
|
|
|
start || (start = 0);
|
|
|
|
|
end || (end = this.length);
|
|
|
|
|
|
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
|
value = value.charCodeAt(0);
|
|
|
|
|
}
|
|
|
|
|
if (!(typeof value === 'number') || isNaN(value)) {
|
|
|
|
|
throw new Error('value is not a number');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end < start) throw new Error('end < start');
|
|
|
|
|
|
|
|
|
|
// Fill 0 bytes; we're done
|
|
|
|
|
if (end === start) return 0;
|
|
|
|
|
if (this.length == 0) return 0;
|
|
|
|
|
|
|
|
|
|
if (start < 0 || start >= this.length) {
|
|
|
|
|
throw new Error('start out of bounds');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end < 0 || end > this.length) {
|
|
|
|
|
throw new Error('end out of bounds');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
this[i] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Static methods
|
|
|
|
|
Buffer.isBuffer = function isBuffer(b) {
|
|
|
|
|
return b instanceof Buffer || b instanceof Buffer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.concat = function (list, totalLength) {
|
|
|
|
|
if (!isArray(list)) {
|
|
|
|
|
throw new Error("Usage: Buffer.concat(list, [totalLength])\n \
|
|
|
|
|
list should be an Array.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.length === 0) {
|
|
|
|
|
return new Buffer(0);
|
|
|
|
|
} else if (list.length === 1) {
|
|
|
|
|
return list[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof totalLength !== 'number') {
|
|
|
|
|
totalLength = 0;
|
|
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
|
|
var buf = list[i];
|
|
|
|
|
totalLength += buf.length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var buffer = new Buffer(totalLength);
|
|
|
|
|
var pos = 0;
|
|
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
|
|
var buf = list[i];
|
|
|
|
|
buf.copy(buffer, pos);
|
|
|
|
|
pos += buf.length;
|
|
|
|
|
}
|
|
|
|
|
return buffer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.isEncoding = function(encoding) {
|
|
|
|
|
switch ((encoding + '').toLowerCase()) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
case 'ascii':
|
|
|
|
|
case 'binary':
|
|
|
|
|
case 'base64':
|
|
|
|
|
case 'ucs2':
|
|
|
|
|
case 'ucs-2':
|
|
|
|
|
case 'utf16le':
|
|
|
|
|
case 'utf-16le':
|
|
|
|
|
case 'raw':
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// helpers
|
|
|
|
|
|
|
|
|
|
function coerce(length) {
|
|
|
|
|
// Coerce length to a number (possibly NaN), round up
|
|
|
|
|
// in case it's fractional (e.g. 123.456) then do a
|
|
|
|
|
// double negate to coerce a NaN to 0. Easy, right?
|
|
|
|
|
length = ~~Math.ceil(+length);
|
|
|
|
|
return length < 0 ? 0 : length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isArray(subject) {
|
|
|
|
|
return (Array.isArray ||
|
|
|
|
|
function(subject){
|
|
|
|
|
return {}.toString.apply(subject) == '[object Array]'
|
|
|
|
|
})
|
|
|
|
|
(subject)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isArrayIsh(subject) {
|
|
|
|
|
return isArray(subject) || Buffer.isBuffer(subject) ||
|
|
|
|
|
subject && typeof subject === 'object' &&
|
|
|
|
|
typeof subject.length === 'number';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toHex(n) {
|
|
|
|
|
if (n < 16) return '0' + n.toString(16);
|
|
|
|
|
return n.toString(16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function utf8ToBytes(str) {
|
|
|
|
|
var byteArray = [];
|
|
|
|
|
for (var i = 0; i < str.length; i++)
|
|
|
|
|
if (str.charCodeAt(i) <= 0x7F)
|
|
|
|
|
byteArray.push(str.charCodeAt(i));
|
|
|
|
|
else {
|
|
|
|
|
var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
|
|
|
|
|
for (var j = 0; j < h.length; j++)
|
|
|
|
|
byteArray.push(parseInt(h[j], 16));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return byteArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function asciiToBytes(str) {
|
|
|
|
|
var byteArray = []
|
|
|
|
|
for (var i = 0; i < str.length; i++ )
|
|
|
|
|
// Node's code seems to be doing this and not & 0x7F..
|
|
|
|
|
byteArray.push( str.charCodeAt(i) & 0xFF );
|
|
|
|
|
|
|
|
|
|
return byteArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function base64ToBytes(str) {
|
|
|
|
|
return require("base64-js").toByteArray(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function blitBuffer(src, dst, offset, length) {
|
|
|
|
|
var pos, i = 0;
|
|
|
|
|
while (i < length) {
|
|
|
|
|
if ((i+offset >= dst.length) || (i >= src.length))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
dst[i + offset] = src[i];
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function decodeUtf8Char(str) {
|
|
|
|
|
try {
|
|
|
|
|
return decodeURIComponent(str);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return String.fromCharCode(0xFFFD); // UTF 8 invalid char
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// read/write bit-twiddling
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readUInt8 = function(offset, noAssert) {
|
|
|
|
|
var buffer = this;
|
|
|
|
|
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset < buffer.length,
|
|
|
|
|
'Trying to read beyond buffer length');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buffer.length) return;
|
|
|
|
|
|
|
|
|
|
return buffer[offset];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function readUInt16(buffer, offset, isBigEndian, noAssert) {
|
|
|
|
|
var val = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 1 < buffer.length,
|
|
|
|
|
'Trying to read beyond buffer length');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buffer.length) return 0;
|
|
|
|
|
|
|
|
|
|
if (isBigEndian) {
|
|
|
|
|
val = buffer[offset] << 8;
|
|
|
|
|
if (offset + 1 < buffer.length) {
|
|
|
|
|
val |= buffer[offset + 1];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
val = buffer[offset];
|
|
|
|
|
if (offset + 1 < buffer.length) {
|
|
|
|
|
val |= buffer[offset + 1] << 8;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readUInt16LE = function(offset, noAssert) {
|
|
|
|
|
return readUInt16(this, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readUInt16BE = function(offset, noAssert) {
|
|
|
|
|
return readUInt16(this, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function readUInt32(buffer, offset, isBigEndian, noAssert) {
|
|
|
|
|
var val = 0;
|
|
|
|
|
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 3 < buffer.length,
|
|
|
|
|
'Trying to read beyond buffer length');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buffer.length) return 0;
|
|
|
|
|
|
|
|
|
|
if (isBigEndian) {
|
|
|
|
|
if (offset + 1 < buffer.length)
|
|
|
|
|
val = buffer[offset + 1] << 16;
|
|
|
|
|
if (offset + 2 < buffer.length)
|
|
|
|
|
val |= buffer[offset + 2] << 8;
|
|
|
|
|
if (offset + 3 < buffer.length)
|
|
|
|
|
val |= buffer[offset + 3];
|
|
|
|
|
val = val + (buffer[offset] << 24 >>> 0);
|
|
|
|
|
} else {
|
|
|
|
|
if (offset + 2 < buffer.length)
|
|
|
|
|
val = buffer[offset + 2] << 16;
|
|
|
|
|
if (offset + 1 < buffer.length)
|
|
|
|
|
val |= buffer[offset + 1] << 8;
|
|
|
|
|
val |= buffer[offset];
|
|
|
|
|
if (offset + 3 < buffer.length)
|
|
|
|
|
val = val + (buffer[offset + 3] << 24 >>> 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readUInt32LE = function(offset, noAssert) {
|
|
|
|
|
return readUInt32(this, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readUInt32BE = function(offset, noAssert) {
|
|
|
|
|
return readUInt32(this, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Signed integer types, yay team! A reminder on how two's complement actually
|
|
|
|
|
* works. The first bit is the signed bit, i.e. tells us whether or not the
|
|
|
|
|
* number should be positive or negative. If the two's complement value is
|
|
|
|
|
* positive, then we're done, as it's equivalent to the unsigned representation.
|
|
|
|
|
*
|
|
|
|
|
* Now if the number is positive, you're pretty much done, you can just leverage
|
|
|
|
|
* the unsigned translations and return those. Unfortunately, negative numbers
|
|
|
|
|
* aren't quite that straightforward.
|
|
|
|
|
*
|
|
|
|
|
* At first glance, one might be inclined to use the traditional formula to
|
|
|
|
|
* translate binary numbers between the positive and negative values in two's
|
|
|
|
|
* complement. (Though it doesn't quite work for the most negative value)
|
|
|
|
|
* Mainly:
|
|
|
|
|
* - invert all the bits
|
|
|
|
|
* - add one to the result
|
|
|
|
|
*
|
|
|
|
|
* Of course, this doesn't quite work in Javascript. Take for example the value
|
|
|
|
|
* of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
|
|
|
|
|
* course, Javascript will do the following:
|
|
|
|
|
*
|
|
|
|
|
* > ~0xff80
|
|
|
|
|
* -65409
|
|
|
|
|
*
|
|
|
|
|
* Whoh there, Javascript, that's not quite right. But wait, according to
|
|
|
|
|
* Javascript that's perfectly correct. When Javascript ends up seeing the
|
|
|
|
|
* constant 0xff80, it has no notion that it is actually a signed number. It
|
|
|
|
|
* assumes that we've input the unsigned value 0xff80. Thus, when it does the
|
|
|
|
|
* binary negation, it casts it into a signed value, (positive 0xff80). Then
|
|
|
|
|
* when you perform binary negation on that, it turns it into a negative number.
|
|
|
|
|
*
|
|
|
|
|
* Instead, we're going to have to use the following general formula, that works
|
|
|
|
|
* in a rather Javascript friendly way. I'm glad we don't support this kind of
|
|
|
|
|
* weird numbering scheme in the kernel.
|
|
|
|
|
*
|
|
|
|
|
* (BIT-MAX - (unsigned)val + 1) * -1
|
|
|
|
|
*
|
|
|
|
|
* The astute observer, may think that this doesn't make sense for 8-bit numbers
|
|
|
|
|
* (really it isn't necessary for them). However, when you get 16-bit numbers,
|
|
|
|
|
* you do. Let's go back to our prior example and see how this will look:
|
|
|
|
|
*
|
|
|
|
|
* (0xffff - 0xff80 + 1) * -1
|
|
|
|
|
* (0x007f + 1) * -1
|
|
|
|
|
* (0x0080) * -1
|
|
|
|
|
*/
|
|
|
|
|
Buffer.prototype.readInt8 = function(offset, noAssert) {
|
|
|
|
|
var buffer = this;
|
|
|
|
|
var neg;
|
|
|
|
|
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset < buffer.length,
|
|
|
|
|
'Trying to read beyond buffer length');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset >= buffer.length) return;
|
|
|
|
|
|
|
|
|
|
neg = buffer[offset] & 0x80;
|
|
|
|
|
if (!neg) {
|
|
|
|
|
return (buffer[offset]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ((0xff - buffer[offset] + 1) * -1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function readInt16(buffer, offset, isBigEndian, noAssert) {
|
|
|
|
|
var neg, val;
|
|
|
|
|
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 1 < buffer.length,
|
|
|
|
|
'Trying to read beyond buffer length');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val = readUInt16(buffer, offset, isBigEndian, noAssert);
|
|
|
|
|
neg = val & 0x8000;
|
|
|
|
|
if (!neg) {
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (0xffff - val + 1) * -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readInt16LE = function(offset, noAssert) {
|
|
|
|
|
return readInt16(this, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readInt16BE = function(offset, noAssert) {
|
|
|
|
|
return readInt16(this, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function readInt32(buffer, offset, isBigEndian, noAssert) {
|
|
|
|
|
var neg, val;
|
|
|
|
|
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 3 < buffer.length,
|
|
|
|
|
'Trying to read beyond buffer length');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val = readUInt32(buffer, offset, isBigEndian, noAssert);
|
|
|
|
|
neg = val & 0x80000000;
|
|
|
|
|
if (!neg) {
|
|
|
|
|
return (val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (0xffffffff - val + 1) * -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readInt32LE = function(offset, noAssert) {
|
|
|
|
|
return readInt32(this, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readInt32BE = function(offset, noAssert) {
|
|
|
|
|
return readInt32(this, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function readFloat(buffer, offset, isBigEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 3 < buffer.length,
|
|
|
|
|
'Trying to read beyond buffer length');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
|
|
|
|
|
23, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readFloatLE = function(offset, noAssert) {
|
|
|
|
|
return readFloat(this, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readFloatBE = function(offset, noAssert) {
|
|
|
|
|
return readFloat(this, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function readDouble(buffer, offset, isBigEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 7 < buffer.length,
|
|
|
|
|
'Trying to read beyond buffer length');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
|
|
|
|
|
52, 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readDoubleLE = function(offset, noAssert) {
|
|
|
|
|
return readDouble(this, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.readDoubleBE = function(offset, noAssert) {
|
|
|
|
|
return readDouble(this, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We have to make sure that the value is a valid integer. This means that it is
|
|
|
|
|
* non-negative. It has no fractional component and that it does not exceed the
|
|
|
|
|
* maximum allowed value.
|
|
|
|
|
*
|
|
|
|
|
* value The number to check for validity
|
|
|
|
|
*
|
|
|
|
|
* max The maximum value
|
|
|
|
|
*/
|
|
|
|
|
function verifuint(value, max) {
|
|
|
|
|
assert.ok(typeof (value) == 'number',
|
|
|
|
|
'cannot write a non-number as a number');
|
|
|
|
|
|
|
|
|
|
assert.ok(value >= 0,
|
|
|
|
|
'specified a negative value for writing an unsigned value');
|
|
|
|
|
|
|
|
|
|
assert.ok(value <= max, 'value is larger than maximum value for type');
|
|
|
|
|
|
|
|
|
|
assert.ok(Math.floor(value) === value, 'value has a fractional component');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
|
|
|
|
|
var buffer = this;
|
|
|
|
|
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(value !== undefined && value !== null,
|
|
|
|
|
'missing value');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset < buffer.length,
|
|
|
|
|
'trying to write beyond buffer length');
|
|
|
|
|
|
|
|
|
|
verifuint(value, 0xff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset < buffer.length) {
|
|
|
|
|
buffer[offset] = value;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(value !== undefined && value !== null,
|
|
|
|
|
'missing value');
|
|
|
|
|
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 1 < buffer.length,
|
|
|
|
|
'trying to write beyond buffer length');
|
|
|
|
|
|
|
|
|
|
verifuint(value, 0xffff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < Math.min(buffer.length - offset, 2); i++) {
|
|
|
|
|
buffer[offset + i] =
|
|
|
|
|
(value & (0xff << (8 * (isBigEndian ? 1 - i : i)))) >>>
|
|
|
|
|
(isBigEndian ? 1 - i : i) * 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
|
|
|
|
|
writeUInt16(this, value, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
|
|
|
|
|
writeUInt16(this, value, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(value !== undefined && value !== null,
|
|
|
|
|
'missing value');
|
|
|
|
|
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 3 < buffer.length,
|
|
|
|
|
'trying to write beyond buffer length');
|
|
|
|
|
|
|
|
|
|
verifuint(value, 0xffffffff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < Math.min(buffer.length - offset, 4); i++) {
|
|
|
|
|
buffer[offset + i] =
|
|
|
|
|
(value >>> (isBigEndian ? 3 - i : i) * 8) & 0xff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
|
|
|
|
|
writeUInt32(this, value, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
|
|
|
|
|
writeUInt32(this, value, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We now move onto our friends in the signed number category. Unlike unsigned
|
|
|
|
|
* numbers, we're going to have to worry a bit more about how we put values into
|
|
|
|
|
* arrays. Since we are only worrying about signed 32-bit values, we're in
|
|
|
|
|
* slightly better shape. Unfortunately, we really can't do our favorite binary
|
|
|
|
|
* & in this system. It really seems to do the wrong thing. For example:
|
|
|
|
|
*
|
|
|
|
|
* > -32 & 0xff
|
|
|
|
|
* 224
|
|
|
|
|
*
|
|
|
|
|
* What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
|
|
|
|
|
* this aren't treated as a signed number. Ultimately a bad thing.
|
|
|
|
|
*
|
|
|
|
|
* What we're going to want to do is basically create the unsigned equivalent of
|
|
|
|
|
* our representation and pass that off to the wuint* functions. To do that
|
|
|
|
|
* we're going to do the following:
|
|
|
|
|
*
|
|
|
|
|
* - if the value is positive
|
|
|
|
|
* we can pass it directly off to the equivalent wuint
|
|
|
|
|
* - if the value is negative
|
|
|
|
|
* we do the following computation:
|
|
|
|
|
* mb + val + 1, where
|
|
|
|
|
* mb is the maximum unsigned value in that byte size
|
|
|
|
|
* val is the Javascript negative integer
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
|
|
|
|
|
* you do out the computations:
|
|
|
|
|
*
|
|
|
|
|
* 0xffff - 128 + 1
|
|
|
|
|
* 0xffff - 127
|
|
|
|
|
* 0xff80
|
|
|
|
|
*
|
|
|
|
|
* You can then encode this value as the signed version. This is really rather
|
|
|
|
|
* hacky, but it should work and get the job done which is our goal here.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A series of checks to make sure we actually have a signed 32-bit number
|
|
|
|
|
*/
|
|
|
|
|
function verifsint(value, max, min) {
|
|
|
|
|
assert.ok(typeof (value) == 'number',
|
|
|
|
|
'cannot write a non-number as a number');
|
|
|
|
|
|
|
|
|
|
assert.ok(value <= max, 'value larger than maximum allowed value');
|
|
|
|
|
|
|
|
|
|
assert.ok(value >= min, 'value smaller than minimum allowed value');
|
|
|
|
|
|
|
|
|
|
assert.ok(Math.floor(value) === value, 'value has a fractional component');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function verifIEEE754(value, max, min) {
|
|
|
|
|
assert.ok(typeof (value) == 'number',
|
|
|
|
|
'cannot write a non-number as a number');
|
|
|
|
|
|
|
|
|
|
assert.ok(value <= max, 'value larger than maximum allowed value');
|
|
|
|
|
|
|
|
|
|
assert.ok(value >= min, 'value smaller than minimum allowed value');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
|
|
|
|
|
var buffer = this;
|
|
|
|
|
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(value !== undefined && value !== null,
|
|
|
|
|
'missing value');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset < buffer.length,
|
|
|
|
|
'Trying to write beyond buffer length');
|
|
|
|
|
|
|
|
|
|
verifsint(value, 0x7f, -0x80);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value >= 0) {
|
|
|
|
|
buffer.writeUInt8(value, offset, noAssert);
|
|
|
|
|
} else {
|
|
|
|
|
buffer.writeUInt8(0xff + value + 1, offset, noAssert);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(value !== undefined && value !== null,
|
|
|
|
|
'missing value');
|
|
|
|
|
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 1 < buffer.length,
|
|
|
|
|
'Trying to write beyond buffer length');
|
|
|
|
|
|
|
|
|
|
verifsint(value, 0x7fff, -0x8000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value >= 0) {
|
|
|
|
|
writeUInt16(buffer, value, offset, isBigEndian, noAssert);
|
|
|
|
|
} else {
|
|
|
|
|
writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
|
|
|
|
|
writeInt16(this, value, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
|
|
|
|
|
writeInt16(this, value, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(value !== undefined && value !== null,
|
|
|
|
|
'missing value');
|
|
|
|
|
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 3 < buffer.length,
|
|
|
|
|
'Trying to write beyond buffer length');
|
|
|
|
|
|
|
|
|
|
verifsint(value, 0x7fffffff, -0x80000000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value >= 0) {
|
|
|
|
|
writeUInt32(buffer, value, offset, isBigEndian, noAssert);
|
|
|
|
|
} else {
|
|
|
|
|
writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
|
|
|
|
|
writeInt32(this, value, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
|
|
|
|
|
writeInt32(this, value, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(value !== undefined && value !== null,
|
|
|
|
|
'missing value');
|
|
|
|
|
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 3 < buffer.length,
|
|
|
|
|
'Trying to write beyond buffer length');
|
|
|
|
|
|
|
|
|
|
verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
|
|
|
|
|
23, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
|
|
|
|
|
writeFloat(this, value, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
|
|
|
|
|
writeFloat(this, value, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
|
|
|
|
|
if (!noAssert) {
|
|
|
|
|
assert.ok(value !== undefined && value !== null,
|
|
|
|
|
'missing value');
|
|
|
|
|
|
|
|
|
|
assert.ok(typeof (isBigEndian) === 'boolean',
|
|
|
|
|
'missing or invalid endian');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset !== undefined && offset !== null,
|
|
|
|
|
'missing offset');
|
|
|
|
|
|
|
|
|
|
assert.ok(offset + 7 < buffer.length,
|
|
|
|
|
'Trying to write beyond buffer length');
|
|
|
|
|
|
|
|
|
|
verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
|
|
|
|
|
52, 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
|
|
|
|
|
writeDouble(this, value, offset, false, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
|
|
|
|
|
writeDouble(this, value, offset, true, noAssert);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
},{"./buffer_ieee754":6,"assert":11,"base64-js":8}],8:[function(require,module,exports){
|
|
|
|
|
(function (exports) {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
|
|
|
|
|
|
|
|
function b64ToByteArray(b64) {
|
|
|
|
|
var i, j, l, tmp, placeHolders, arr;
|
|
|
|
|
|
|
|
|
|
if (b64.length % 4 > 0) {
|
|
|
|
|
throw 'Invalid string. Length must be a multiple of 4';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the number of equal signs (place holders)
|
|
|
|
|
// if there are two placeholders, than the two characters before it
|
|
|
|
|
// represent one byte
|
|
|
|
|
// if there is only one, then the three characters before it represent 2 bytes
|
|
|
|
|
// this is just a cheap hack to not do indexOf twice
|
|
|
|
|
placeHolders = b64.indexOf('=');
|
|
|
|
|
placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
|
|
|
|
|
|
|
|
|
|
// base64 is 4/3 + up to two characters of the original data
|
|
|
|
|
arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
|
|
|
|
|
|
|
|
|
|
// if there are placeholders, only get up to the last complete 4 chars
|
|
|
|
|
l = placeHolders > 0 ? b64.length - 4 : b64.length;
|
|
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
|
|
|
|
tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);
|
|
|
|
|
arr.push((tmp & 0xFF0000) >> 16);
|
|
|
|
|
arr.push((tmp & 0xFF00) >> 8);
|
|
|
|
|
arr.push(tmp & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (placeHolders === 2) {
|
|
|
|
|
tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
|
|
|
|
|
arr.push(tmp & 0xFF);
|
|
|
|
|
} else if (placeHolders === 1) {
|
|
|
|
|
tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
|
|
|
|
|
arr.push((tmp >> 8) & 0xFF);
|
|
|
|
|
arr.push(tmp & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function uint8ToBase64(uint8) {
|
|
|
|
|
var i,
|
|
|
|
|
extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
|
|
|
|
|
output = "",
|
|
|
|
|
temp, length;
|
|
|
|
|
|
|
|
|
|
function tripletToBase64 (num) {
|
|
|
|
|
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
|
|
|
for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
|
|
|
|
|
temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
|
|
|
|
|
output += tripletToBase64(temp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
|
|
|
switch (extraBytes) {
|
|
|
|
|
case 1:
|
|
|
|
|
temp = uint8[uint8.length - 1];
|
|
|
|
|
output += lookup[temp >> 2];
|
|
|
|
|
output += lookup[(temp << 4) & 0x3F];
|
|
|
|
|
output += '==';
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
|
|
|
|
|
output += lookup[temp >> 10];
|
|
|
|
|
output += lookup[(temp >> 4) & 0x3F];
|
|
|
|
|
output += lookup[(temp << 2) & 0x3F];
|
|
|
|
|
output += '=';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports.toByteArray = b64ToByteArray;
|
|
|
|
|
module.exports.fromByteArray = uint8ToBase64;
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
},{}],9:[function(require,module,exports){
|
|
|
|
|
var undefined = (void 0); // Paranoia
|
|
|
|
|
|
|
|
|
|
// Beyond this value, index getters/setters (i.e. array[0], array[1]) are so slow to
|
|
|
|
|
// create, and consume so much memory, that the browser appears frozen.
|
|
|
|
|
var MAX_ARRAY_LENGTH = 1e5;
|
|
|
|
|
|
|
|
|
|
// Approximations of internal ECMAScript conversion functions
|
|
|
|
|
var ECMAScript = (function() {
|
|
|
|
|
// Stash a copy in case other scripts modify these
|
|
|
|
|
var opts = Object.prototype.toString,
|
|
|
|
|
ophop = Object.prototype.hasOwnProperty;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
// Class returns internal [[Class]] property, used to avoid cross-frame instanceof issues:
|
|
|
|
|
Class: function(v) { return opts.call(v).replace(/^\[object *|\]$/g, ''); },
|
|
|
|
|
HasProperty: function(o, p) { return p in o; },
|
|
|
|
|
HasOwnProperty: function(o, p) { return ophop.call(o, p); },
|
|
|
|
|
IsCallable: function(o) { return typeof o === 'function'; },
|
|
|
|
|
ToInt32: function(v) { return v >> 0; },
|
|
|
|
|
ToUint32: function(v) { return v >>> 0; }
|
|
|
|
|
};
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
// Snapshot intrinsics
|
|
|
|
|
var LN2 = Math.LN2,
|
|
|
|
|
abs = Math.abs,
|
|
|
|
|
floor = Math.floor,
|
|
|
|
|
log = Math.log,
|
|
|
|
|
min = Math.min,
|
|
|
|
|
pow = Math.pow,
|
|
|
|
|
round = Math.round;
|
|
|
|
|
|
|
|
|
|
// ES5: lock down object properties
|
|
|
|
|
function configureProperties(obj) {
|
|
|
|
|
if (getOwnPropNames && defineProp) {
|
|
|
|
|
var props = getOwnPropNames(obj), i;
|
|
|
|
|
for (i = 0; i < props.length; i += 1) {
|
|
|
|
|
defineProp(obj, props[i], {
|
|
|
|
|
value: obj[props[i]],
|
|
|
|
|
writable: false,
|
|
|
|
|
enumerable: false,
|
|
|
|
|
configurable: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// emulate ES5 getter/setter API using legacy APIs
|
|
|
|
|
// http://blogs.msdn.com/b/ie/archive/2010/09/07/transitioning-existing-code-to-the-es5-getter-setter-apis.aspx
|
|
|
|
|
// (second clause tests for Object.defineProperty() in IE<9 that only supports extending DOM prototypes, but
|
|
|
|
|
// note that IE<9 does not support __defineGetter__ or __defineSetter__ so it just renders the method harmless)
|
|
|
|
|
var defineProp
|
|
|
|
|
if (Object.defineProperty && (function() {
|
|
|
|
|
try {
|
|
|
|
|
Object.defineProperty({}, 'x', {});
|
|
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
})()) {
|
|
|
|
|
defineProp = Object.defineProperty;
|
|
|
|
|
} else {
|
|
|
|
|
defineProp = function(o, p, desc) {
|
|
|
|
|
if (!o === Object(o)) throw new TypeError("Object.defineProperty called on non-object");
|
|
|
|
|
if (ECMAScript.HasProperty(desc, 'get') && Object.prototype.__defineGetter__) { Object.prototype.__defineGetter__.call(o, p, desc.get); }
|
|
|
|
|
if (ECMAScript.HasProperty(desc, 'set') && Object.prototype.__defineSetter__) { Object.prototype.__defineSetter__.call(o, p, desc.set); }
|
|
|
|
|
if (ECMAScript.HasProperty(desc, 'value')) { o[p] = desc.value; }
|
|
|
|
|
return o;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var getOwnPropNames = Object.getOwnPropertyNames || function (o) {
|
|
|
|
|
if (o !== Object(o)) throw new TypeError("Object.getOwnPropertyNames called on non-object");
|
|
|
|
|
var props = [], p;
|
|
|
|
|
for (p in o) {
|
|
|
|
|
if (ECMAScript.HasOwnProperty(o, p)) {
|
|
|
|
|
props.push(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return props;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ES5: Make obj[index] an alias for obj._getter(index)/obj._setter(index, value)
|
|
|
|
|
// for index in 0 ... obj.length
|
|
|
|
|
function makeArrayAccessors(obj) {
|
|
|
|
|
if (!defineProp) { return; }
|
|
|
|
|
|
|
|
|
|
if (obj.length > MAX_ARRAY_LENGTH) throw new RangeError("Array too large for polyfill");
|
|
|
|
|
|
|
|
|
|
function makeArrayAccessor(index) {
|
|
|
|
|
defineProp(obj, index, {
|
|
|
|
|
'get': function() { return obj._getter(index); },
|
|
|
|
|
'set': function(v) { obj._setter(index, v); },
|
|
|
|
|
enumerable: true,
|
|
|
|
|
configurable: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var i;
|
|
|
|
|
for (i = 0; i < obj.length; i += 1) {
|
|
|
|
|
makeArrayAccessor(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Internal conversion functions:
|
|
|
|
|
// pack<Type>() - take a number (interpreted as Type), output a byte array
|
|
|
|
|
// unpack<Type>() - take a byte array, output a Type-like number
|
|
|
|
|
|
|
|
|
|
function as_signed(value, bits) { var s = 32 - bits; return (value << s) >> s; }
|
|
|
|
|
function as_unsigned(value, bits) { var s = 32 - bits; return (value << s) >>> s; }
|
|
|
|
|
|
|
|
|
|
function packI8(n) { return [n & 0xff]; }
|
|
|
|
|
function unpackI8(bytes) { return as_signed(bytes[0], 8); }
|
|
|
|
|
|
|
|
|
|
function packU8(n) { return [n & 0xff]; }
|
|
|
|
|
function unpackU8(bytes) { return as_unsigned(bytes[0], 8); }
|
|
|
|
|
|
|
|
|
|
function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; }
|
|
|
|
|
|
|
|
|
|
function packI16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
|
|
|
|
|
function unpackI16(bytes) { return as_signed(bytes[0] << 8 | bytes[1], 16); }
|
|
|
|
|
|
|
|
|
|
function packU16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
|
|
|
|
|
function unpackU16(bytes) { return as_unsigned(bytes[0] << 8 | bytes[1], 16); }
|
|
|
|
|
|
|
|
|
|
function packI32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
|
|
|
|
|
function unpackI32(bytes) { return as_signed(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
|
|
|
|
|
|
|
|
|
|
function packU32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
|
|
|
|
|
function unpackU32(bytes) { return as_unsigned(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
|
|
|
|
|
|
|
|
|
|
function packIEEE754(v, ebits, fbits) {
|
|
|
|
|
|
|
|
|
|
var bias = (1 << (ebits - 1)) - 1,
|
|
|
|
|
s, e, f, ln,
|
|
|
|
|
i, bits, str, bytes;
|
|
|
|
|
|
|
|
|
|
function roundToEven(n) {
|
|
|
|
|
var w = floor(n), f = n - w;
|
|
|
|
|
if (f < 0.5)
|
|
|
|
|
return w;
|
|
|
|
|
if (f > 0.5)
|
|
|
|
|
return w + 1;
|
|
|
|
|
return w % 2 ? w + 1 : w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compute sign, exponent, fraction
|
|
|
|
|
if (v !== v) {
|
|
|
|
|
// NaN
|
|
|
|
|
// http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping
|
|
|
|
|
e = (1 << ebits) - 1; f = pow(2, fbits - 1); s = 0;
|
|
|
|
|
} else if (v === Infinity || v === -Infinity) {
|
|
|
|
|
e = (1 << ebits) - 1; f = 0; s = (v < 0) ? 1 : 0;
|
|
|
|
|
} else if (v === 0) {
|
|
|
|
|
e = 0; f = 0; s = (1 / v === -Infinity) ? 1 : 0;
|
|
|
|
|
} else {
|
|
|
|
|
s = v < 0;
|
|
|
|
|
v = abs(v);
|
|
|
|
|
|
|
|
|
|
if (v >= pow(2, 1 - bias)) {
|
|
|
|
|
e = min(floor(log(v) / LN2), 1023);
|
|
|
|
|
f = roundToEven(v / pow(2, e) * pow(2, fbits));
|
|
|
|
|
if (f / pow(2, fbits) >= 2) {
|
|
|
|
|
e = e + 1;
|
|
|
|
|
f = 1;
|
|
|
|
|
}
|
|
|
|
|
if (e > bias) {
|
|
|
|
|
// Overflow
|
|
|
|
|
e = (1 << ebits) - 1;
|
|
|
|
|
f = 0;
|
|
|
|
|
} else {
|
|
|
|
|
// Normalized
|
|
|
|
|
e = e + bias;
|
|
|
|
|
f = f - pow(2, fbits);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Denormalized
|
|
|
|
|
e = 0;
|
|
|
|
|
f = roundToEven(v / pow(2, 1 - bias - fbits));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pack sign, exponent, fraction
|
|
|
|
|
bits = [];
|
|
|
|
|
for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = floor(f / 2); }
|
|
|
|
|
for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = floor(e / 2); }
|
|
|
|
|
bits.push(s ? 1 : 0);
|
|
|
|
|
bits.reverse();
|
|
|
|
|
str = bits.join('');
|
|
|
|
|
|
|
|
|
|
// Bits to bytes
|
|
|
|
|
bytes = [];
|
|
|
|
|
while (str.length) {
|
|
|
|
|
bytes.push(parseInt(str.substring(0, 8), 2));
|
|
|
|
|
str = str.substring(8);
|
|
|
|
|
}
|
|
|
|
|
return bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unpackIEEE754(bytes, ebits, fbits) {
|
|
|
|
|
|
|
|
|
|
// Bytes to bits
|
|
|
|
|
var bits = [], i, j, b, str,
|
|
|
|
|
bias, s, e, f;
|
|
|
|
|
|
|
|
|
|
for (i = bytes.length; i; i -= 1) {
|
|
|
|
|
b = bytes[i - 1];
|
|
|
|
|
for (j = 8; j; j -= 1) {
|
|
|
|
|
bits.push(b % 2 ? 1 : 0); b = b >> 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bits.reverse();
|
|
|
|
|
str = bits.join('');
|
|
|
|
|
|
|
|
|
|
// Unpack sign, exponent, fraction
|
|
|
|
|
bias = (1 << (ebits - 1)) - 1;
|
|
|
|
|
s = parseInt(str.substring(0, 1), 2) ? -1 : 1;
|
|
|
|
|
e = parseInt(str.substring(1, 1 + ebits), 2);
|
|
|
|
|
f = parseInt(str.substring(1 + ebits), 2);
|
|
|
|
|
|
|
|
|
|
// Produce number
|
|
|
|
|
if (e === (1 << ebits) - 1) {
|
|
|
|
|
return f !== 0 ? NaN : s * Infinity;
|
|
|
|
|
} else if (e > 0) {
|
|
|
|
|
// Normalized
|
|
|
|
|
return s * pow(2, e - bias) * (1 + f / pow(2, fbits));
|
|
|
|
|
} else if (f !== 0) {
|
|
|
|
|
// Denormalized
|
|
|
|
|
return s * pow(2, -(bias - 1)) * (f / pow(2, fbits));
|
|
|
|
|
} else {
|
|
|
|
|
return s < 0 ? -0 : 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unpackF64(b) { return unpackIEEE754(b, 11, 52); }
|
|
|
|
|
function packF64(v) { return packIEEE754(v, 11, 52); }
|
|
|
|
|
function unpackF32(b) { return unpackIEEE754(b, 8, 23); }
|
|
|
|
|
function packF32(v) { return packIEEE754(v, 8, 23); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 3 The ArrayBuffer Type
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
|
|
/** @constructor */
|
|
|
|
|
var ArrayBuffer = function ArrayBuffer(length) {
|
|
|
|
|
length = ECMAScript.ToInt32(length);
|
|
|
|
|
if (length < 0) throw new RangeError('ArrayBuffer size is not a small enough positive integer');
|
|
|
|
|
|
|
|
|
|
this.byteLength = length;
|
|
|
|
|
this._bytes = [];
|
|
|
|
|
this._bytes.length = length;
|
|
|
|
|
|
|
|
|
|
var i;
|
|
|
|
|
for (i = 0; i < this.byteLength; i += 1) {
|
|
|
|
|
this._bytes[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureProperties(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.ArrayBuffer = exports.ArrayBuffer || ArrayBuffer;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 4 The ArrayBufferView Type
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// NOTE: this constructor is not exported
|
|
|
|
|
/** @constructor */
|
|
|
|
|
var ArrayBufferView = function ArrayBufferView() {
|
|
|
|
|
//this.buffer = null;
|
|
|
|
|
//this.byteOffset = 0;
|
|
|
|
|
//this.byteLength = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 5 The Typed Array View Types
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
function makeConstructor(bytesPerElement, pack, unpack) {
|
|
|
|
|
// Each TypedArray type requires a distinct constructor instance with
|
|
|
|
|
// identical logic, which this produces.
|
|
|
|
|
|
|
|
|
|
var ctor;
|
|
|
|
|
ctor = function(buffer, byteOffset, length) {
|
|
|
|
|
var array, sequence, i, s;
|
|
|
|
|
|
|
|
|
|
if (!arguments.length || typeof arguments[0] === 'number') {
|
|
|
|
|
// Constructor(unsigned long length)
|
|
|
|
|
this.length = ECMAScript.ToInt32(arguments[0]);
|
|
|
|
|
if (length < 0) throw new RangeError('ArrayBufferView size is not a small enough positive integer');
|
|
|
|
|
|
|
|
|
|
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
this.buffer = new ArrayBuffer(this.byteLength);
|
|
|
|
|
this.byteOffset = 0;
|
|
|
|
|
} else if (typeof arguments[0] === 'object' && arguments[0].constructor === ctor) {
|
|
|
|
|
// Constructor(TypedArray array)
|
|
|
|
|
array = arguments[0];
|
|
|
|
|
|
|
|
|
|
this.length = array.length;
|
|
|
|
|
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
this.buffer = new ArrayBuffer(this.byteLength);
|
|
|
|
|
this.byteOffset = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < this.length; i += 1) {
|
|
|
|
|
this._setter(i, array._getter(i));
|
|
|
|
|
}
|
|
|
|
|
} else if (typeof arguments[0] === 'object' &&
|
|
|
|
|
!(arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
|
|
|
|
|
// Constructor(sequence<type> array)
|
|
|
|
|
sequence = arguments[0];
|
|
|
|
|
|
|
|
|
|
this.length = ECMAScript.ToUint32(sequence.length);
|
|
|
|
|
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
this.buffer = new ArrayBuffer(this.byteLength);
|
|
|
|
|
this.byteOffset = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < this.length; i += 1) {
|
|
|
|
|
s = sequence[i];
|
|
|
|
|
this._setter(i, Number(s));
|
|
|
|
|
}
|
|
|
|
|
} else if (typeof arguments[0] === 'object' &&
|
|
|
|
|
(arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
|
|
|
|
|
// Constructor(ArrayBuffer buffer,
|
|
|
|
|
// optional unsigned long byteOffset, optional unsigned long length)
|
|
|
|
|
this.buffer = buffer;
|
|
|
|
|
|
|
|
|
|
this.byteOffset = ECMAScript.ToUint32(byteOffset);
|
|
|
|
|
if (this.byteOffset > this.buffer.byteLength) {
|
|
|
|
|
throw new RangeError("byteOffset out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.byteOffset % this.BYTES_PER_ELEMENT) {
|
|
|
|
|
// The given byteOffset must be a multiple of the element
|
|
|
|
|
// size of the specific type, otherwise an exception is raised.
|
|
|
|
|
throw new RangeError("ArrayBuffer length minus the byteOffset is not a multiple of the element size.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (arguments.length < 3) {
|
|
|
|
|
this.byteLength = this.buffer.byteLength - this.byteOffset;
|
|
|
|
|
|
|
|
|
|
if (this.byteLength % this.BYTES_PER_ELEMENT) {
|
|
|
|
|
throw new RangeError("length of buffer minus byteOffset not a multiple of the element size");
|
|
|
|
|
}
|
|
|
|
|
this.length = this.byteLength / this.BYTES_PER_ELEMENT;
|
|
|
|
|
} else {
|
|
|
|
|
this.length = ECMAScript.ToUint32(length);
|
|
|
|
|
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
|
|
|
|
|
throw new RangeError("byteOffset and length reference an area beyond the end of the buffer");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new TypeError("Unexpected argument type(s)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.constructor = ctor;
|
|
|
|
|
|
|
|
|
|
configureProperties(this);
|
|
|
|
|
makeArrayAccessors(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ctor.prototype = new ArrayBufferView();
|
|
|
|
|
ctor.prototype.BYTES_PER_ELEMENT = bytesPerElement;
|
|
|
|
|
ctor.prototype._pack = pack;
|
|
|
|
|
ctor.prototype._unpack = unpack;
|
|
|
|
|
ctor.BYTES_PER_ELEMENT = bytesPerElement;
|
|
|
|
|
|
|
|
|
|
// getter type (unsigned long index);
|
|
|
|
|
ctor.prototype._getter = function(index) {
|
|
|
|
|
if (arguments.length < 1) throw new SyntaxError("Not enough arguments");
|
|
|
|
|
|
|
|
|
|
index = ECMAScript.ToUint32(index);
|
|
|
|
|
if (index >= this.length) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bytes = [], i, o;
|
|
|
|
|
for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT;
|
|
|
|
|
i < this.BYTES_PER_ELEMENT;
|
|
|
|
|
i += 1, o += 1) {
|
|
|
|
|
bytes.push(this.buffer._bytes[o]);
|
|
|
|
|
}
|
|
|
|
|
return this._unpack(bytes);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// NONSTANDARD: convenience alias for getter: type get(unsigned long index);
|
|
|
|
|
ctor.prototype.get = ctor.prototype._getter;
|
|
|
|
|
|
|
|
|
|
// setter void (unsigned long index, type value);
|
|
|
|
|
ctor.prototype._setter = function(index, value) {
|
|
|
|
|
if (arguments.length < 2) throw new SyntaxError("Not enough arguments");
|
|
|
|
|
|
|
|
|
|
index = ECMAScript.ToUint32(index);
|
|
|
|
|
if (index >= this.length) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bytes = this._pack(value), i, o;
|
|
|
|
|
for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT;
|
|
|
|
|
i < this.BYTES_PER_ELEMENT;
|
|
|
|
|
i += 1, o += 1) {
|
|
|
|
|
this.buffer._bytes[o] = bytes[i];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// void set(TypedArray array, optional unsigned long offset);
|
|
|
|
|
// void set(sequence<type> array, optional unsigned long offset);
|
|
|
|
|
ctor.prototype.set = function(index, value) {
|
|
|
|
|
if (arguments.length < 1) throw new SyntaxError("Not enough arguments");
|
|
|
|
|
var array, sequence, offset, len,
|
|
|
|
|
i, s, d,
|
|
|
|
|
byteOffset, byteLength, tmp;
|
|
|
|
|
|
|
|
|
|
if (typeof arguments[0] === 'object' && arguments[0].constructor === this.constructor) {
|
|
|
|
|
// void set(TypedArray array, optional unsigned long offset);
|
|
|
|
|
array = arguments[0];
|
|
|
|
|
offset = ECMAScript.ToUint32(arguments[1]);
|
|
|
|
|
|
|
|
|
|
if (offset + array.length > this.length) {
|
|
|
|
|
throw new RangeError("Offset plus length of array is out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byteOffset = this.byteOffset + offset * this.BYTES_PER_ELEMENT;
|
|
|
|
|
byteLength = array.length * this.BYTES_PER_ELEMENT;
|
|
|
|
|
|
|
|
|
|
if (array.buffer === this.buffer) {
|
|
|
|
|
tmp = [];
|
|
|
|
|
for (i = 0, s = array.byteOffset; i < byteLength; i += 1, s += 1) {
|
|
|
|
|
tmp[i] = array.buffer._bytes[s];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0, d = byteOffset; i < byteLength; i += 1, d += 1) {
|
|
|
|
|
this.buffer._bytes[d] = tmp[i];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (i = 0, s = array.byteOffset, d = byteOffset;
|
|
|
|
|
i < byteLength; i += 1, s += 1, d += 1) {
|
|
|
|
|
this.buffer._bytes[d] = array.buffer._bytes[s];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (typeof arguments[0] === 'object' && typeof arguments[0].length !== 'undefined') {
|
|
|
|
|
// void set(sequence<type> array, optional unsigned long offset);
|
|
|
|
|
sequence = arguments[0];
|
|
|
|
|
len = ECMAScript.ToUint32(sequence.length);
|
|
|
|
|
offset = ECMAScript.ToUint32(arguments[1]);
|
|
|
|
|
|
|
|
|
|
if (offset + len > this.length) {
|
|
|
|
|
throw new RangeError("Offset plus length of array is out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i += 1) {
|
|
|
|
|
s = sequence[i];
|
|
|
|
|
this._setter(offset + i, Number(s));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new TypeError("Unexpected argument type(s)");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TypedArray subarray(long begin, optional long end);
|
|
|
|
|
ctor.prototype.subarray = function(start, end) {
|
|
|
|
|
function clamp(v, min, max) { return v < min ? min : v > max ? max : v; }
|
|
|
|
|
|
|
|
|
|
start = ECMAScript.ToInt32(start);
|
|
|
|
|
end = ECMAScript.ToInt32(end);
|
|
|
|
|
|
|
|
|
|
if (arguments.length < 1) { start = 0; }
|
|
|
|
|
if (arguments.length < 2) { end = this.length; }
|
|
|
|
|
|
|
|
|
|
if (start < 0) { start = this.length + start; }
|
|
|
|
|
if (end < 0) { end = this.length + end; }
|
|
|
|
|
|
|
|
|
|
start = clamp(start, 0, this.length);
|
|
|
|
|
end = clamp(end, 0, this.length);
|
|
|
|
|
|
|
|
|
|
var len = end - start;
|
|
|
|
|
if (len < 0) {
|
|
|
|
|
len = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new this.constructor(
|
|
|
|
|
this.buffer, this.byteOffset + start * this.BYTES_PER_ELEMENT, len);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ctor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Int8Array = makeConstructor(1, packI8, unpackI8);
|
|
|
|
|
var Uint8Array = makeConstructor(1, packU8, unpackU8);
|
|
|
|
|
var Uint8ClampedArray = makeConstructor(1, packU8Clamped, unpackU8);
|
|
|
|
|
var Int16Array = makeConstructor(2, packI16, unpackI16);
|
|
|
|
|
var Uint16Array = makeConstructor(2, packU16, unpackU16);
|
|
|
|
|
var Int32Array = makeConstructor(4, packI32, unpackI32);
|
|
|
|
|
var Uint32Array = makeConstructor(4, packU32, unpackU32);
|
|
|
|
|
var Float32Array = makeConstructor(4, packF32, unpackF32);
|
|
|
|
|
var Float64Array = makeConstructor(8, packF64, unpackF64);
|
|
|
|
|
|
|
|
|
|
exports.Int8Array = exports.Int8Array || Int8Array;
|
|
|
|
|
exports.Uint8Array = exports.Uint8Array || Uint8Array;
|
|
|
|
|
exports.Uint8ClampedArray = exports.Uint8ClampedArray || Uint8ClampedArray;
|
|
|
|
|
exports.Int16Array = exports.Int16Array || Int16Array;
|
|
|
|
|
exports.Uint16Array = exports.Uint16Array || Uint16Array;
|
|
|
|
|
exports.Int32Array = exports.Int32Array || Int32Array;
|
|
|
|
|
exports.Uint32Array = exports.Uint32Array || Uint32Array;
|
|
|
|
|
exports.Float32Array = exports.Float32Array || Float32Array;
|
|
|
|
|
exports.Float64Array = exports.Float64Array || Float64Array;
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 6 The DataView View Type
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
function r(array, index) {
|
|
|
|
|
return ECMAScript.IsCallable(array.get) ? array.get(index) : array[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var IS_BIG_ENDIAN = (function() {
|
|
|
|
|
var u16array = new(exports.Uint16Array)([0x1234]),
|
|
|
|
|
u8array = new(exports.Uint8Array)(u16array.buffer);
|
|
|
|
|
return r(u8array, 0) === 0x12;
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
// Constructor(ArrayBuffer buffer,
|
|
|
|
|
// optional unsigned long byteOffset,
|
|
|
|
|
// optional unsigned long byteLength)
|
|
|
|
|
/** @constructor */
|
|
|
|
|
var DataView = function DataView(buffer, byteOffset, byteLength) {
|
|
|
|
|
if (arguments.length === 0) {
|
|
|
|
|
buffer = new exports.ArrayBuffer(0);
|
|
|
|
|
} else if (!(buffer instanceof exports.ArrayBuffer || ECMAScript.Class(buffer) === 'ArrayBuffer')) {
|
|
|
|
|
throw new TypeError("TypeError");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.buffer = buffer || new exports.ArrayBuffer(0);
|
|
|
|
|
|
|
|
|
|
this.byteOffset = ECMAScript.ToUint32(byteOffset);
|
|
|
|
|
if (this.byteOffset > this.buffer.byteLength) {
|
|
|
|
|
throw new RangeError("byteOffset out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (arguments.length < 3) {
|
|
|
|
|
this.byteLength = this.buffer.byteLength - this.byteOffset;
|
|
|
|
|
} else {
|
|
|
|
|
this.byteLength = ECMAScript.ToUint32(byteLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
|
|
|
|
|
throw new RangeError("byteOffset and length reference an area beyond the end of the buffer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configureProperties(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function makeGetter(arrayType) {
|
|
|
|
|
return function(byteOffset, littleEndian) {
|
|
|
|
|
|
|
|
|
|
byteOffset = ECMAScript.ToUint32(byteOffset);
|
|
|
|
|
|
|
|
|
|
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
|
|
|
|
|
throw new RangeError("Array index out of range");
|
|
|
|
|
}
|
|
|
|
|
byteOffset += this.byteOffset;
|
|
|
|
|
|
|
|
|
|
var uint8Array = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT),
|
|
|
|
|
bytes = [], i;
|
|
|
|
|
for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
|
|
|
|
|
bytes.push(r(uint8Array, i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
|
|
|
|
|
bytes.reverse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r(new arrayType(new exports.Uint8Array(bytes).buffer), 0);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataView.prototype.getUint8 = makeGetter(exports.Uint8Array);
|
|
|
|
|
DataView.prototype.getInt8 = makeGetter(exports.Int8Array);
|
|
|
|
|
DataView.prototype.getUint16 = makeGetter(exports.Uint16Array);
|
|
|
|
|
DataView.prototype.getInt16 = makeGetter(exports.Int16Array);
|
|
|
|
|
DataView.prototype.getUint32 = makeGetter(exports.Uint32Array);
|
|
|
|
|
DataView.prototype.getInt32 = makeGetter(exports.Int32Array);
|
|
|
|
|
DataView.prototype.getFloat32 = makeGetter(exports.Float32Array);
|
|
|
|
|
DataView.prototype.getFloat64 = makeGetter(exports.Float64Array);
|
|
|
|
|
|
|
|
|
|
function makeSetter(arrayType) {
|
|
|
|
|
return function(byteOffset, value, littleEndian) {
|
|
|
|
|
|
|
|
|
|
byteOffset = ECMAScript.ToUint32(byteOffset);
|
|
|
|
|
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
|
|
|
|
|
throw new RangeError("Array index out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get bytes
|
|
|
|
|
var typeArray = new arrayType([value]),
|
|
|
|
|
byteArray = new exports.Uint8Array(typeArray.buffer),
|
|
|
|
|
bytes = [], i, byteView;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
|
|
|
|
|
bytes.push(r(byteArray, i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Flip if necessary
|
|
|
|
|
if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
|
|
|
|
|
bytes.reverse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write them
|
|
|
|
|
byteView = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT);
|
|
|
|
|
byteView.set(bytes);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataView.prototype.setUint8 = makeSetter(exports.Uint8Array);
|
|
|
|
|
DataView.prototype.setInt8 = makeSetter(exports.Int8Array);
|
|
|
|
|
DataView.prototype.setUint16 = makeSetter(exports.Uint16Array);
|
|
|
|
|
DataView.prototype.setInt16 = makeSetter(exports.Int16Array);
|
|
|
|
|
DataView.prototype.setUint32 = makeSetter(exports.Uint32Array);
|
|
|
|
|
DataView.prototype.setInt32 = makeSetter(exports.Int32Array);
|
|
|
|
|
DataView.prototype.setFloat32 = makeSetter(exports.Float32Array);
|
|
|
|
|
DataView.prototype.setFloat64 = makeSetter(exports.Float64Array);
|
|
|
|
|
|
|
|
|
|
exports.DataView = exports.DataView || DataView;
|
|
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
},{}],10:[function(require,module,exports){
|
|
|
|
|
var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},Buffer=require("__browserify_Buffer");var benchmark = require('benchmark')
|
|
|
|
|
var suite = new benchmark.Suite()
|
|
|
|
|
|
|
|
|
|
global.NewBuffer = require('../../').Buffer // native-buffer-browserify
|
|
|
|
|
global.OldBuffer = require('buffer-browserify').Buffer // buffer-browserify
|
|
|
|
|
|
|
|
|
|
var LENGTH = 50
|
|
|
|
|
|
|
|
|
|
var newTarget = NewBuffer(LENGTH)
|
|
|
|
|
var oldTarget = OldBuffer(LENGTH)
|
|
|
|
|
var nodeTarget = Buffer(LENGTH)
|
|
|
|
|
|
|
|
|
|
suite.add('NewBuffer#bracket-notation', function () {
|
|
|
|
|
for (var i = 0; i < LENGTH; i++) {
|
|
|
|
|
newTarget[i] = i + 97
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.add('OldBuffer#bracket-notation', function () {
|
|
|
|
|
for (var i = 0; i < LENGTH; i++) {
|
|
|
|
|
oldTarget[i] = i + 97
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.add('Buffer#bracket-notation', function () {
|
|
|
|
|
for (var i = 0; i < LENGTH; i++) {
|
|
|
|
|
nodeTarget[i] = i + 97
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.on('error', function (event) {
|
|
|
|
|
console.error(event.target.error.stack)
|
|
|
|
|
})
|
|
|
|
|
.on('cycle', function (event) {
|
|
|
|
|
console.log(String(event.target))
|
|
|
|
|
})
|
|
|
|
|
.on('complete', function () {
|
|
|
|
|
console.log('Fastest is ' + this.filter('fastest').pluck('name'))
|
|
|
|
|
})
|
|
|
|
|
.run({ 'async': true })
|
|
|
|
|
|
|
|
|
|
},{"../../":3,"__browserify_Buffer":1,"benchmark":5,"buffer-browserify":7}],11:[function(require,module,exports){
|
|
|
|
|
// http://wiki.commonjs.org/wiki/Unit_Testing/1.0
|
|
|
|
|
//
|
|
|
|
|
// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
|
|
|
|
|
//
|
|
|
|
|
// Originally from narwhal.js (http://narwhaljs.org)
|
|
|
|
|
// Copyright (c) 2009 Thomas Robinson <280north.com>
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the 'Software'), to
|
|
|
|
|
// deal in the Software without restriction, including without limitation the
|
|
|
|
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
|
// sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
// when used in node, this will actually load the util module we depend on
|
|
|
|
|
// versus loading the builtin util module as happens otherwise
|
|
|
|
|
// this is a bug in node module loading as far as I am concerned
|
|
|
|
|
var util = require('util/');
|
|
|
|
|
|
|
|
|
|
var pSlice = Array.prototype.slice;
|
|
|
|
|
var hasOwn = Object.prototype.hasOwnProperty;
|
|
|
|
|
|
|
|
|
|
// 1. The assert module provides functions that throw
|
|
|
|
|
// AssertionError's when particular conditions are not met. The
|
|
|
|
|
// assert module must conform to the following interface.
|
|
|
|
|
|
|
|
|
|
var assert = module.exports = ok;
|
|
|
|
|
|
|
|
|
|
// 2. The AssertionError is defined in assert.
|
|
|
|
|
// new assert.AssertionError({ message: message,
|
|
|
|
|
// actual: actual,
|
|
|
|
|
// expected: expected })
|
|
|
|
|
|
|
|
|
|
assert.AssertionError = function AssertionError(options) {
|
|
|
|
|
this.name = 'AssertionError';
|
|
|
|
|
this.actual = options.actual;
|
|
|
|
|
this.expected = options.expected;
|
|
|
|
|
this.operator = options.operator;
|
|
|
|
|
if (options.message) {
|
|
|
|
|
this.message = options.message;
|
|
|
|
|
this.generatedMessage = false;
|
|
|
|
|
} else {
|
|
|
|
|
this.message = getMessage(this);
|
|
|
|
|
this.generatedMessage = true;
|
|
|
|
|
}
|
|
|
|
|
var stackStartFunction = options.stackStartFunction || fail;
|
|
|
|
|
|
|
|
|
|
if (Error.captureStackTrace) {
|
|
|
|
|
Error.captureStackTrace(this, stackStartFunction);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// assert.AssertionError instanceof Error
|
|
|
|
|
util.inherits(assert.AssertionError, Error);
|
|
|
|
|
|
|
|
|
|
function replacer(key, value) {
|
|
|
|
|
if (util.isUndefined(value)) {
|
|
|
|
|
return '' + value;
|
|
|
|
|
}
|
|
|
|
|
if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
|
|
|
|
|
return value.toString();
|
|
|
|
|
}
|
|
|
|
|
if (util.isFunction(value) || util.isRegExp(value)) {
|
|
|
|
|
return value.toString();
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function truncate(s, n) {
|
|
|
|
|
if (util.isString(s)) {
|
|
|
|
|
return s.length < n ? s : s.slice(0, n);
|
|
|
|
|
} else {
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getMessage(self) {
|
|
|
|
|
return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
|
|
|
|
|
self.operator + ' ' +
|
|
|
|
|
truncate(JSON.stringify(self.expected, replacer), 128);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// At present only the three keys mentioned above are used and
|
|
|
|
|
// understood by the spec. Implementations or sub modules can pass
|
|
|
|
|
// other keys to the AssertionError's constructor - they will be
|
|
|
|
|
// ignored.
|
|
|
|
|
|
|
|
|
|
// 3. All of the following functions must throw an AssertionError
|
|
|
|
|
// when a corresponding condition is not met, with a message that
|
|
|
|
|
// may be undefined if not provided. All assertion methods provide
|
|
|
|
|
// both the actual and expected values to the assertion error for
|
|
|
|
|
// display purposes.
|
|
|
|
|
|
|
|
|
|
function fail(actual, expected, message, operator, stackStartFunction) {
|
|
|
|
|
throw new assert.AssertionError({
|
|
|
|
|
message: message,
|
|
|
|
|
actual: actual,
|
|
|
|
|
expected: expected,
|
|
|
|
|
operator: operator,
|
|
|
|
|
stackStartFunction: stackStartFunction
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EXTENSION! allows for well behaved errors defined elsewhere.
|
|
|
|
|
assert.fail = fail;
|
|
|
|
|
|
|
|
|
|
// 4. Pure assertion tests whether a value is truthy, as determined
|
|
|
|
|
// by !!guard.
|
|
|
|
|
// assert.ok(guard, message_opt);
|
|
|
|
|
// This statement is equivalent to assert.equal(true, !!guard,
|
|
|
|
|
// message_opt);. To test strictly for the value true, use
|
|
|
|
|
// assert.strictEqual(true, guard, message_opt);.
|
|
|
|
|
|
|
|
|
|
function ok(value, message) {
|
|
|
|
|
if (!value) fail(value, true, message, '==', assert.ok);
|
|
|
|
|
}
|
|
|
|
|
assert.ok = ok;
|
|
|
|
|
|
|
|
|
|
// 5. The equality assertion tests shallow, coercive equality with
|
|
|
|
|
// ==.
|
|
|
|
|
// assert.equal(actual, expected, message_opt);
|
|
|
|
|
|
|
|
|
|
assert.equal = function equal(actual, expected, message) {
|
|
|
|
|
if (actual != expected) fail(actual, expected, message, '==', assert.equal);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 6. The non-equality assertion tests for whether two objects are not equal
|
|
|
|
|
// with != assert.notEqual(actual, expected, message_opt);
|
|
|
|
|
|
|
|
|
|
assert.notEqual = function notEqual(actual, expected, message) {
|
|
|
|
|
if (actual == expected) {
|
|
|
|
|
fail(actual, expected, message, '!=', assert.notEqual);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 7. The equivalence assertion tests a deep equality relation.
|
|
|
|
|
// assert.deepEqual(actual, expected, message_opt);
|
|
|
|
|
|
|
|
|
|
assert.deepEqual = function deepEqual(actual, expected, message) {
|
|
|
|
|
if (!_deepEqual(actual, expected)) {
|
|
|
|
|
fail(actual, expected, message, 'deepEqual', assert.deepEqual);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function _deepEqual(actual, expected) {
|
|
|
|
|
// 7.1. All identical values are equivalent, as determined by ===.
|
|
|
|
|
if (actual === expected) {
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
} else if (util.isBuffer(actual) && util.isBuffer(expected)) {
|
|
|
|
|
if (actual.length != expected.length) return false;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < actual.length; i++) {
|
|
|
|
|
if (actual[i] !== expected[i]) return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// 7.2. If the expected value is a Date object, the actual value is
|
|
|
|
|
// equivalent if it is also a Date object that refers to the same time.
|
|
|
|
|
} else if (util.isDate(actual) && util.isDate(expected)) {
|
|
|
|
|
return actual.getTime() === expected.getTime();
|
|
|
|
|
|
|
|
|
|
// 7.3 If the expected value is a RegExp object, the actual value is
|
|
|
|
|
// equivalent if it is also a RegExp object with the same source and
|
|
|
|
|
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
|
|
|
|
|
} else if (util.isRegExp(actual) && util.isRegExp(expected)) {
|
|
|
|
|
return actual.source === expected.source &&
|
|
|
|
|
actual.global === expected.global &&
|
|
|
|
|
actual.multiline === expected.multiline &&
|
|
|
|
|
actual.lastIndex === expected.lastIndex &&
|
|
|
|
|
actual.ignoreCase === expected.ignoreCase;
|
|
|
|
|
|
|
|
|
|
// 7.4. Other pairs that do not both pass typeof value == 'object',
|
|
|
|
|
// equivalence is determined by ==.
|
|
|
|
|
} else if (!util.isObject(actual) && !util.isObject(expected)) {
|
|
|
|
|
return actual == expected;
|
|
|
|
|
|
|
|
|
|
// 7.5 For all other Object pairs, including Array objects, equivalence is
|
|
|
|
|
// determined by having the same number of owned properties (as verified
|
|
|
|
|
// with Object.prototype.hasOwnProperty.call), the same set of keys
|
|
|
|
|
// (although not necessarily the same order), equivalent values for every
|
|
|
|
|
// corresponding key, and an identical 'prototype' property. Note: this
|
|
|
|
|
// accounts for both named and indexed properties on Arrays.
|
|
|
|
|
} else {
|
|
|
|
|
return objEquiv(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isArguments(object) {
|
|
|
|
|
return Object.prototype.toString.call(object) == '[object Arguments]';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function objEquiv(a, b) {
|
|
|
|
|
if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
|
|
|
|
|
return false;
|
|
|
|
|
// an identical 'prototype' property.
|
|
|
|
|
if (a.prototype !== b.prototype) return false;
|
|
|
|
|
//~~~I've managed to break Object.keys through screwy arguments passing.
|
|
|
|
|
// Converting to array solves the problem.
|
|
|
|
|
if (isArguments(a)) {
|
|
|
|
|
if (!isArguments(b)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
a = pSlice.call(a);
|
|
|
|
|
b = pSlice.call(b);
|
|
|
|
|
return _deepEqual(a, b);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
var ka = objectKeys(a),
|
|
|
|
|
kb = objectKeys(b),
|
|
|
|
|
key, i;
|
|
|
|
|
} catch (e) {//happens when one is a string literal and the other isn't
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// having the same number of owned properties (keys incorporates
|
|
|
|
|
// hasOwnProperty)
|
|
|
|
|
if (ka.length != kb.length)
|
|
|
|
|
return false;
|
|
|
|
|
//the same set of keys (although not necessarily the same order),
|
|
|
|
|
ka.sort();
|
|
|
|
|
kb.sort();
|
|
|
|
|
//~~~cheap key test
|
|
|
|
|
for (i = ka.length - 1; i >= 0; i--) {
|
|
|
|
|
if (ka[i] != kb[i])
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
//equivalent values for every corresponding key, and
|
|
|
|
|
//~~~possibly expensive deep test
|
|
|
|
|
for (i = ka.length - 1; i >= 0; i--) {
|
|
|
|
|
key = ka[i];
|
|
|
|
|
if (!_deepEqual(a[key], b[key])) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 8. The non-equivalence assertion tests for any deep inequality.
|
|
|
|
|
// assert.notDeepEqual(actual, expected, message_opt);
|
|
|
|
|
|
|
|
|
|
assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
|
|
|
|
|
if (_deepEqual(actual, expected)) {
|
|
|
|
|
fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 9. The strict equality assertion tests strict equality, as determined by ===.
|
|
|
|
|
// assert.strictEqual(actual, expected, message_opt);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual = function strictEqual(actual, expected, message) {
|
|
|
|
|
if (actual !== expected) {
|
|
|
|
|
fail(actual, expected, message, '===', assert.strictEqual);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 10. The strict non-equality assertion tests for strict inequality, as
|
|
|
|
|
// determined by !==. assert.notStrictEqual(actual, expected, message_opt);
|
|
|
|
|
|
|
|
|
|
assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
|
|
|
|
if (actual === expected) {
|
|
|
|
|
fail(actual, expected, message, '!==', assert.notStrictEqual);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function expectedException(actual, expected) {
|
|
|
|
|
if (!actual || !expected) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Object.prototype.toString.call(expected) == '[object RegExp]') {
|
|
|
|
|
return expected.test(actual);
|
|
|
|
|
} else if (actual instanceof expected) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (expected.call({}, actual) === true) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _throws(shouldThrow, block, expected, message) {
|
|
|
|
|
var actual;
|
|
|
|
|
|
|
|
|
|
if (util.isString(expected)) {
|
|
|
|
|
message = expected;
|
|
|
|
|
expected = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
block();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
actual = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
|
|
|
|
|
(message ? ' ' + message : '.');
|
|
|
|
|
|
|
|
|
|
if (shouldThrow && !actual) {
|
|
|
|
|
fail(actual, expected, 'Missing expected exception' + message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!shouldThrow && expectedException(actual, expected)) {
|
|
|
|
|
fail(actual, expected, 'Got unwanted exception' + message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((shouldThrow && actual && expected &&
|
|
|
|
|
!expectedException(actual, expected)) || (!shouldThrow && actual)) {
|
|
|
|
|
throw actual;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 11. Expected to throw an error:
|
|
|
|
|
// assert.throws(block, Error_opt, message_opt);
|
|
|
|
|
|
|
|
|
|
assert.throws = function(block, /*optional*/error, /*optional*/message) {
|
|
|
|
|
_throws.apply(this, [true].concat(pSlice.call(arguments)));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// EXTENSION! This is annoying to write outside this module.
|
|
|
|
|
assert.doesNotThrow = function(block, /*optional*/message) {
|
|
|
|
|
_throws.apply(this, [false].concat(pSlice.call(arguments)));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
assert.ifError = function(err) { if (err) {throw err;}};
|
|
|
|
|
|
|
|
|
|
var objectKeys = Object.keys || function (obj) {
|
|
|
|
|
var keys = [];
|
|
|
|
|
for (var key in obj) {
|
|
|
|
|
if (hasOwn.call(obj, key)) keys.push(key);
|
|
|
|
|
}
|
|
|
|
|
return keys;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
},{"util/":14}],12:[function(require,module,exports){
|
|
|
|
|
if (typeof Object.create === 'function') {
|
|
|
|
|
// implementation from standard node.js 'util' module
|
|
|
|
|
module.exports = function inherits(ctor, superCtor) {
|
|
|
|
|
ctor.super_ = superCtor
|
|
|
|
|
ctor.prototype = Object.create(superCtor.prototype, {
|
|
|
|
|
constructor: {
|
|
|
|
|
value: ctor,
|
|
|
|
|
enumerable: false,
|
|
|
|
|
writable: true,
|
|
|
|
|
configurable: true
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
// old school shim for old browsers
|
|
|
|
|
module.exports = function inherits(ctor, superCtor) {
|
|
|
|
|
ctor.super_ = superCtor
|
|
|
|
|
var TempCtor = function () {}
|
|
|
|
|
TempCtor.prototype = superCtor.prototype
|
|
|
|
|
ctor.prototype = new TempCtor()
|
|
|
|
|
ctor.prototype.constructor = ctor
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},{}],13:[function(require,module,exports){
|
|
|
|
|
module.exports = function isBuffer(arg) {
|
|
|
|
|
return arg && typeof arg === 'object'
|
|
|
|
|
&& typeof arg.copy === 'function'
|
|
|
|
|
&& typeof arg.fill === 'function'
|
|
|
|
|
&& typeof arg.readUInt8 === 'function';
|
|
|
|
|
}
|
|
|
|
|
},{}],14:[function(require,module,exports){
|
|
|
|
|
var process=require("__browserify_process"),global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
|
// following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
var formatRegExp = /%[sdj%]/g;
|
|
|
|
|
exports.format = function(f) {
|
|
|
|
|
if (!isString(f)) {
|
|
|
|
|
var objects = [];
|
|
|
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
|
|
|
objects.push(inspect(arguments[i]));
|
|
|
|
|
}
|
|
|
|
|
return objects.join(' ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var i = 1;
|
|
|
|
|
var args = arguments;
|
|
|
|
|
var len = args.length;
|
|
|
|
|
var str = String(f).replace(formatRegExp, function(x) {
|
|
|
|
|
if (x === '%%') return '%';
|
|
|
|
|
if (i >= len) return x;
|
|
|
|
|
switch (x) {
|
|
|
|
|
case '%s': return String(args[i++]);
|
|
|
|
|
case '%d': return Number(args[i++]);
|
|
|
|
|
case '%j':
|
|
|
|
|
try {
|
|
|
|
|
return JSON.stringify(args[i++]);
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return '[Circular]';
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
for (var x = args[i]; i < len; x = args[++i]) {
|
|
|
|
|
if (isNull(x) || !isObject(x)) {
|
|
|
|
|
str += ' ' + x;
|
|
|
|
|
} else {
|
|
|
|
|
str += ' ' + inspect(x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mark that a method should not be used.
|
|
|
|
|
// Returns a modified function which warns once by default.
|
|
|
|
|
// If --no-deprecation is set, then it is a no-op.
|
|
|
|
|
exports.deprecate = function(fn, msg) {
|
|
|
|
|
// Allow for deprecating things in the process of starting up.
|
|
|
|
|
if (isUndefined(global.process)) {
|
|
|
|
|
return function() {
|
|
|
|
|
return exports.deprecate(fn, msg).apply(this, arguments);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (process.noDeprecation === true) {
|
|
|
|
|
return fn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var warned = false;
|
|
|
|
|
function deprecated() {
|
|
|
|
|
if (!warned) {
|
|
|
|
|
if (process.throwDeprecation) {
|
|
|
|
|
throw new Error(msg);
|
|
|
|
|
} else if (process.traceDeprecation) {
|
|
|
|
|
console.trace(msg);
|
|
|
|
|
} else {
|
|
|
|
|
console.error(msg);
|
|
|
|
|
}
|
|
|
|
|
warned = true;
|
|
|
|
|
}
|
|
|
|
|
return fn.apply(this, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return deprecated;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var debugs = {};
|
|
|
|
|
var debugEnviron;
|
|
|
|
|
exports.debuglog = function(set) {
|
|
|
|
|
if (isUndefined(debugEnviron))
|
|
|
|
|
debugEnviron = process.env.NODE_DEBUG || '';
|
|
|
|
|
set = set.toUpperCase();
|
|
|
|
|
if (!debugs[set]) {
|
|
|
|
|
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
|
|
|
|
var pid = process.pid;
|
|
|
|
|
debugs[set] = function() {
|
|
|
|
|
var msg = exports.format.apply(exports, arguments);
|
|
|
|
|
console.error('%s %d: %s', set, pid, msg);
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
debugs[set] = function() {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return debugs[set];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Echos the value of a value. Trys to print the value out
|
|
|
|
|
* in the best way possible given the different types.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} obj The object to print out.
|
|
|
|
|
* @param {Object} opts Optional options object that alters the output.
|
|
|
|
|
*/
|
|
|
|
|
/* legacy: obj, showHidden, depth, colors*/
|
|
|
|
|
function inspect(obj, opts) {
|
|
|
|
|
// default options
|
|
|
|
|
var ctx = {
|
|
|
|
|
seen: [],
|
|
|
|
|
stylize: stylizeNoColor
|
|
|
|
|
};
|
|
|
|
|
// legacy...
|
|
|
|
|
if (arguments.length >= 3) ctx.depth = arguments[2];
|
|
|
|
|
if (arguments.length >= 4) ctx.colors = arguments[3];
|
|
|
|
|
if (isBoolean(opts)) {
|
|
|
|
|
// legacy...
|
|
|
|
|
ctx.showHidden = opts;
|
|
|
|
|
} else if (opts) {
|
|
|
|
|
// got an "options" object
|
|
|
|
|
exports._extend(ctx, opts);
|
|
|
|
|
}
|
|
|
|
|
// set default options
|
|
|
|
|
if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
|
|
|
|
if (isUndefined(ctx.depth)) ctx.depth = 2;
|
|
|
|
|
if (isUndefined(ctx.colors)) ctx.colors = false;
|
|
|
|
|
if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
|
|
|
|
if (ctx.colors) ctx.stylize = stylizeWithColor;
|
|
|
|
|
return formatValue(ctx, obj, ctx.depth);
|
|
|
|
|
}
|
|
|
|
|
exports.inspect = inspect;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
|
|
|
|
inspect.colors = {
|
|
|
|
|
'bold' : [1, 22],
|
|
|
|
|
'italic' : [3, 23],
|
|
|
|
|
'underline' : [4, 24],
|
|
|
|
|
'inverse' : [7, 27],
|
|
|
|
|
'white' : [37, 39],
|
|
|
|
|
'grey' : [90, 39],
|
|
|
|
|
'black' : [30, 39],
|
|
|
|
|
'blue' : [34, 39],
|
|
|
|
|
'cyan' : [36, 39],
|
|
|
|
|
'green' : [32, 39],
|
|
|
|
|
'magenta' : [35, 39],
|
|
|
|
|
'red' : [31, 39],
|
|
|
|
|
'yellow' : [33, 39]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Don't use 'blue' not visible on cmd.exe
|
|
|
|
|
inspect.styles = {
|
|
|
|
|
'special': 'cyan',
|
|
|
|
|
'number': 'yellow',
|
|
|
|
|
'boolean': 'yellow',
|
|
|
|
|
'undefined': 'grey',
|
|
|
|
|
'null': 'bold',
|
|
|
|
|
'string': 'green',
|
|
|
|
|
'date': 'magenta',
|
|
|
|
|
// "name": intentionally not styling
|
|
|
|
|
'regexp': 'red'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function stylizeWithColor(str, styleType) {
|
|
|
|
|
var style = inspect.styles[styleType];
|
|
|
|
|
|
|
|
|
|
if (style) {
|
|
|
|
|
return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
|
|
|
|
'\u001b[' + inspect.colors[style][1] + 'm';
|
|
|
|
|
} else {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function stylizeNoColor(str, styleType) {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function arrayToHash(array) {
|
|
|
|
|
var hash = {};
|
|
|
|
|
|
|
|
|
|
array.forEach(function(val, idx) {
|
|
|
|
|
hash[val] = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatValue(ctx, value, recurseTimes) {
|
|
|
|
|
// Provide a hook for user-specified inspect functions.
|
|
|
|
|
// Check that value is an object with an inspect function on it
|
|
|
|
|
if (ctx.customInspect &&
|
|
|
|
|
value &&
|
|
|
|
|
isFunction(value.inspect) &&
|
|
|
|
|
// Filter out the util module, it's inspect function is special
|
|
|
|
|
value.inspect !== exports.inspect &&
|
|
|
|
|
// Also filter out any prototype objects using the circular check.
|
|
|
|
|
!(value.constructor && value.constructor.prototype === value)) {
|
|
|
|
|
var ret = value.inspect(recurseTimes, ctx);
|
|
|
|
|
if (!isString(ret)) {
|
|
|
|
|
ret = formatValue(ctx, ret, recurseTimes);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Primitive types cannot have properties
|
|
|
|
|
var primitive = formatPrimitive(ctx, value);
|
|
|
|
|
if (primitive) {
|
|
|
|
|
return primitive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Look up the keys of the object.
|
|
|
|
|
var keys = Object.keys(value);
|
|
|
|
|
var visibleKeys = arrayToHash(keys);
|
|
|
|
|
|
|
|
|
|
if (ctx.showHidden) {
|
|
|
|
|
keys = Object.getOwnPropertyNames(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IE doesn't make error fields non-enumerable
|
|
|
|
|
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
|
|
|
|
|
if (isError(value)
|
|
|
|
|
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
|
|
|
|
|
return formatError(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Some type of object without properties can be shortcutted.
|
|
|
|
|
if (keys.length === 0) {
|
|
|
|
|
if (isFunction(value)) {
|
|
|
|
|
var name = value.name ? ': ' + value.name : '';
|
|
|
|
|
return ctx.stylize('[Function' + name + ']', 'special');
|
|
|
|
|
}
|
|
|
|
|
if (isRegExp(value)) {
|
|
|
|
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
|
|
|
}
|
|
|
|
|
if (isDate(value)) {
|
|
|
|
|
return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
|
|
|
|
}
|
|
|
|
|
if (isError(value)) {
|
|
|
|
|
return formatError(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var base = '', array = false, braces = ['{', '}'];
|
|
|
|
|
|
|
|
|
|
// Make Array say that they are Array
|
|
|
|
|
if (isArray(value)) {
|
|
|
|
|
array = true;
|
|
|
|
|
braces = ['[', ']'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make functions say that they are functions
|
|
|
|
|
if (isFunction(value)) {
|
|
|
|
|
var n = value.name ? ': ' + value.name : '';
|
|
|
|
|
base = ' [Function' + n + ']';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make RegExps say that they are RegExps
|
|
|
|
|
if (isRegExp(value)) {
|
|
|
|
|
base = ' ' + RegExp.prototype.toString.call(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make dates with properties first say the date
|
|
|
|
|
if (isDate(value)) {
|
|
|
|
|
base = ' ' + Date.prototype.toUTCString.call(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make error with message first say the error
|
|
|
|
|
if (isError(value)) {
|
|
|
|
|
base = ' ' + formatError(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (keys.length === 0 && (!array || value.length == 0)) {
|
|
|
|
|
return braces[0] + base + braces[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (recurseTimes < 0) {
|
|
|
|
|
if (isRegExp(value)) {
|
|
|
|
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
|
|
|
} else {
|
|
|
|
|
return ctx.stylize('[Object]', 'special');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.seen.push(value);
|
|
|
|
|
|
|
|
|
|
var output;
|
|
|
|
|
if (array) {
|
|
|
|
|
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
|
|
|
|
} else {
|
|
|
|
|
output = keys.map(function(key) {
|
|
|
|
|
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.seen.pop();
|
|
|
|
|
|
|
|
|
|
return reduceToSingleString(output, base, braces);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatPrimitive(ctx, value) {
|
|
|
|
|
if (isUndefined(value))
|
|
|
|
|
return ctx.stylize('undefined', 'undefined');
|
|
|
|
|
if (isString(value)) {
|
|
|
|
|
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
|
|
|
|
.replace(/'/g, "\\'")
|
|
|
|
|
.replace(/\\"/g, '"') + '\'';
|
|
|
|
|
return ctx.stylize(simple, 'string');
|
|
|
|
|
}
|
|
|
|
|
if (isNumber(value))
|
|
|
|
|
return ctx.stylize('' + value, 'number');
|
|
|
|
|
if (isBoolean(value))
|
|
|
|
|
return ctx.stylize('' + value, 'boolean');
|
|
|
|
|
// For some reason typeof null is "object", so special case here.
|
|
|
|
|
if (isNull(value))
|
|
|
|
|
return ctx.stylize('null', 'null');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatError(value) {
|
|
|
|
|
return '[' + Error.prototype.toString.call(value) + ']';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
|
|
|
var output = [];
|
|
|
|
|
for (var i = 0, l = value.length; i < l; ++i) {
|
|
|
|
|
if (hasOwnProperty(value, String(i))) {
|
|
|
|
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
|
|
|
String(i), true));
|
|
|
|
|
} else {
|
|
|
|
|
output.push('');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
keys.forEach(function(key) {
|
|
|
|
|
if (!key.match(/^\d+$/)) {
|
|
|
|
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
|
|
|
key, true));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
|
|
|
|
var name, str, desc;
|
|
|
|
|
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
|
|
|
|
if (desc.get) {
|
|
|
|
|
if (desc.set) {
|
|
|
|
|
str = ctx.stylize('[Getter/Setter]', 'special');
|
|
|
|
|
} else {
|
|
|
|
|
str = ctx.stylize('[Getter]', 'special');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (desc.set) {
|
|
|
|
|
str = ctx.stylize('[Setter]', 'special');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!hasOwnProperty(visibleKeys, key)) {
|
|
|
|
|
name = '[' + key + ']';
|
|
|
|
|
}
|
|
|
|
|
if (!str) {
|
|
|
|
|
if (ctx.seen.indexOf(desc.value) < 0) {
|
|
|
|
|
if (isNull(recurseTimes)) {
|
|
|
|
|
str = formatValue(ctx, desc.value, null);
|
|
|
|
|
} else {
|
|
|
|
|
str = formatValue(ctx, desc.value, recurseTimes - 1);
|
|
|
|
|
}
|
|
|
|
|
if (str.indexOf('\n') > -1) {
|
|
|
|
|
if (array) {
|
|
|
|
|
str = str.split('\n').map(function(line) {
|
|
|
|
|
return ' ' + line;
|
|
|
|
|
}).join('\n').substr(2);
|
|
|
|
|
} else {
|
|
|
|
|
str = '\n' + str.split('\n').map(function(line) {
|
|
|
|
|
return ' ' + line;
|
|
|
|
|
}).join('\n');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
str = ctx.stylize('[Circular]', 'special');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isUndefined(name)) {
|
|
|
|
|
if (array && key.match(/^\d+$/)) {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
name = JSON.stringify('' + key);
|
|
|
|
|
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
|
|
|
|
name = name.substr(1, name.length - 2);
|
|
|
|
|
name = ctx.stylize(name, 'name');
|
|
|
|
|
} else {
|
|
|
|
|
name = name.replace(/'/g, "\\'")
|
|
|
|
|
.replace(/\\"/g, '"')
|
|
|
|
|
.replace(/(^"|"$)/g, "'");
|
|
|
|
|
name = ctx.stylize(name, 'string');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return name + ': ' + str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function reduceToSingleString(output, base, braces) {
|
|
|
|
|
var numLinesEst = 0;
|
|
|
|
|
var length = output.reduce(function(prev, cur) {
|
|
|
|
|
numLinesEst++;
|
|
|
|
|
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
|
|
|
|
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
|
|
if (length > 60) {
|
|
|
|
|
return braces[0] +
|
|
|
|
|
(base === '' ? '' : base + '\n ') +
|
|
|
|
|
' ' +
|
|
|
|
|
output.join(',\n ') +
|
|
|
|
|
' ' +
|
|
|
|
|
braces[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: These type checking functions intentionally don't use `instanceof`
|
|
|
|
|
// because it is fragile and can be easily faked with `Object.create()`.
|
|
|
|
|
function isArray(ar) {
|
|
|
|
|
return Array.isArray(ar);
|
|
|
|
|
}
|
|
|
|
|
exports.isArray = isArray;
|
|
|
|
|
|
|
|
|
|
function isBoolean(arg) {
|
|
|
|
|
return typeof arg === 'boolean';
|
|
|
|
|
}
|
|
|
|
|
exports.isBoolean = isBoolean;
|
|
|
|
|
|
|
|
|
|
function isNull(arg) {
|
|
|
|
|
return arg === null;
|
|
|
|
|
}
|
|
|
|
|
exports.isNull = isNull;
|
|
|
|
|
|
|
|
|
|
function isNullOrUndefined(arg) {
|
|
|
|
|
return arg == null;
|
|
|
|
|
}
|
|
|
|
|
exports.isNullOrUndefined = isNullOrUndefined;
|
|
|
|
|
|
|
|
|
|
function isNumber(arg) {
|
|
|
|
|
return typeof arg === 'number';
|
|
|
|
|
}
|
|
|
|
|
exports.isNumber = isNumber;
|
|
|
|
|
|
|
|
|
|
function isString(arg) {
|
|
|
|
|
return typeof arg === 'string';
|
|
|
|
|
}
|
|
|
|
|
exports.isString = isString;
|
|
|
|
|
|
|
|
|
|
function isSymbol(arg) {
|
|
|
|
|
return typeof arg === 'symbol';
|
|
|
|
|
}
|
|
|
|
|
exports.isSymbol = isSymbol;
|
|
|
|
|
|
|
|
|
|
function isUndefined(arg) {
|
|
|
|
|
return arg === void 0;
|
|
|
|
|
}
|
|
|
|
|
exports.isUndefined = isUndefined;
|
|
|
|
|
|
|
|
|
|
function isRegExp(re) {
|
|
|
|
|
return isObject(re) && objectToString(re) === '[object RegExp]';
|
|
|
|
|
}
|
|
|
|
|
exports.isRegExp = isRegExp;
|
|
|
|
|
|
|
|
|
|
function isObject(arg) {
|
|
|
|
|
return typeof arg === 'object' && arg !== null;
|
|
|
|
|
}
|
|
|
|
|
exports.isObject = isObject;
|
|
|
|
|
|
|
|
|
|
function isDate(d) {
|
|
|
|
|
return isObject(d) && objectToString(d) === '[object Date]';
|
|
|
|
|
}
|
|
|
|
|
exports.isDate = isDate;
|
|
|
|
|
|
|
|
|
|
function isError(e) {
|
|
|
|
|
return isObject(e) &&
|
|
|
|
|
(objectToString(e) === '[object Error]' || e instanceof Error);
|
|
|
|
|
}
|
|
|
|
|
exports.isError = isError;
|
|
|
|
|
|
|
|
|
|
function isFunction(arg) {
|
|
|
|
|
return typeof arg === 'function';
|
|
|
|
|
}
|
|
|
|
|
exports.isFunction = isFunction;
|
|
|
|
|
|
|
|
|
|
function isPrimitive(arg) {
|
|
|
|
|
return arg === null ||
|
|
|
|
|
typeof arg === 'boolean' ||
|
|
|
|
|
typeof arg === 'number' ||
|
|
|
|
|
typeof arg === 'string' ||
|
|
|
|
|
typeof arg === 'symbol' || // ES6 symbol
|
|
|
|
|
typeof arg === 'undefined';
|
|
|
|
|
}
|
|
|
|
|
exports.isPrimitive = isPrimitive;
|
|
|
|
|
|
|
|
|
|
exports.isBuffer = require('./support/isBuffer');
|
|
|
|
|
|
|
|
|
|
function objectToString(o) {
|
|
|
|
|
return Object.prototype.toString.call(o);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function pad(n) {
|
|
|
|
|
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
|
|
|
|
'Oct', 'Nov', 'Dec'];
|
|
|
|
|
|
|
|
|
|
// 26 Feb 16:19:34
|
|
|
|
|
function timestamp() {
|
|
|
|
|
var d = new Date();
|
|
|
|
|
var time = [pad(d.getHours()),
|
|
|
|
|
pad(d.getMinutes()),
|
|
|
|
|
pad(d.getSeconds())].join(':');
|
|
|
|
|
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// log is just a thin wrapper to console.log that prepends a timestamp
|
|
|
|
|
exports.log = function() {
|
|
|
|
|
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Inherit the prototype methods from one constructor into another.
|
|
|
|
|
*
|
|
|
|
|
* The Function.prototype.inherits from lang.js rewritten as a standalone
|
|
|
|
|
* function (not on Function.prototype). NOTE: If this file is to be loaded
|
|
|
|
|
* during bootstrapping this function needs to be rewritten using some native
|
|
|
|
|
* functions as prototype setup using normal JavaScript does not work as
|
|
|
|
|
* expected during bootstrapping (see mirror.js in r114903).
|
|
|
|
|
*
|
|
|
|
|
* @param {function} ctor Constructor function which needs to inherit the
|
|
|
|
|
* prototype.
|
|
|
|
|
* @param {function} superCtor Constructor function to inherit prototype from.
|
|
|
|
|
*/
|
|
|
|
|
exports.inherits = require('inherits');
|
|
|
|
|
|
|
|
|
|
exports._extend = function(origin, add) {
|
|
|
|
|
// Don't do anything if add isn't an object
|
|
|
|
|
if (!add || !isObject(add)) return origin;
|
|
|
|
|
|
|
|
|
|
var keys = Object.keys(add);
|
|
|
|
|
var i = keys.length;
|
|
|
|
|
while (i--) {
|
|
|
|
|
origin[keys[i]] = add[keys[i]];
|
|
|
|
|
}
|
|
|
|
|
return origin;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function hasOwnProperty(obj, prop) {
|
|
|
|
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},{"./support/isBuffer":13,"__browserify_process":2,"inherits":12}]},{},[10])
|
|
|
|
|
//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlcyI6WyIvVXNlcnMvZmVyb3NzL2NvZGUvaW5zZXJ0LW1vZHVsZS1nbG9iYWxzL2J1ZmZlci5qcyIsIi9Vc2Vycy9mZXJvc3MvY29kZS9pbnNlcnQtbW9kdWxlLWdsb2JhbHMvbm9kZV9tb2R1bGVzL3Byb2Nlc3MvYnJvd3Nlci5qcyIsIi9Vc2Vycy9mZXJvc3MvY29kZS9uYXRpdmUtYnVmZmVyLWJyb3dzZXJpZnkvaW5kZXguanMiLCIvVXNlcnMvZmVyb3NzL2NvZGUvbmF0aXZlLWJ1ZmZlci1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9iYXNlNjQtanMvbGliL2I2NC5qcyIsIi9Vc2Vycy9mZXJvc3MvY29kZS9uYXRpdmUtYnVmZmVyLWJyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2JlbmNobWFyay9iZW5jaG1hcmsuanMiLCIvVXNlcnMvZmVyb3NzL2NvZGUvbmF0aXZlLWJ1ZmZlci1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9idWZmZXItYnJvd3NlcmlmeS9idWZmZXJfaWVlZTc1NC5qcyIsIi9Vc2Vycy9mZXJvc3MvY29kZS9uYXRpdmUtYnVmZmVyLWJyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2J1ZmZlci1icm93c2VyaWZ5L2luZGV4LmpzIiwiL1VzZXJzL2Zlcm9zcy9jb2RlL25hdGl2ZS1idWZmZXItYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvYnVmZmVyLWJyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2Jhc2U2NC1qcy9saWIvYjY0LmpzIiwiL1VzZXJzL2Zlcm9zcy9jb2RlL25hdGl2ZS1idWZmZXItYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvdHlwZWRhcnJheS9pbmRleC5qcyIsIi9Vc2Vycy9mZXJvc3MvY29kZS9uYXRpdmUtYnVmZmVyLWJyb3dzZXJpZnkvcGVyZi9jb21wYXJpc29uL2JyYWNrZXQtbm90YXRpb24uanMiLCIvVXNlcnMvZmVyb3NzL2NvZGUvbm9kZS1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9hc3NlcnQvYXNzZXJ0LmpzIiwiL1VzZXJzL2Zlcm9zcy9jb2RlL25vZGUtYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvaW5oZXJpdHMvaW5oZXJpdHNfYnJvd3Nlci5qcyIsIi9Vc2Vycy9mZXJvc3MvY29kZS9ub2RlLWJyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL3V0aWwvc3VwcG9ydC9pc0J1ZmZlckJyb3dzZXIuanMiLCIvVXNlcnMvZmVyb3NzL2NvZGUvbm9kZS1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy91dGlsL3V0aWwuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQ
|