All files / node_modules/upng-js/node_modules/pako/lib/utils common.js

40.74% Statements 22/54
38.46% Branches 5/13
37.5% Functions 3/8
44.89% Lines 22/49

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106      18x         666x     18x 36x 36x 72x 72x   72x       72x 666x 666x         36x         18x               18x                                                                   18x                             18x 18x 18x 18x 18x 18x                 18x  
'use strict';
 
 
var TYPED_OK =  (typeof Uint8Array !== 'undefined') &&
                (typeof Uint16Array !== 'undefined') &&
                (typeof Int32Array !== 'undefined');
 
function _has(obj, key) {
  return Object.prototype.hasOwnProperty.call(obj, key);
}
 
exports.assign = function (obj /*from1, from2, from3, ...*/) {
  var sources = Array.prototype.slice.call(arguments, 1);
  while (sources.length) {
    var source = sources.shift();
I    if (!source) { continue; }
 
I    if (typeof source !== 'object') {
      throw new TypeError(source + 'must be non-object');
    }
 
    for (var p in source) {
      if (_has(source, p)) {
        obj[p] = source[p];
      }
    }
  }
 
  return obj;
};
 
 
// reduce buffer size, avoiding mem copy
exports.shrinkBuf = function (buf, size) {
I  if (buf.length === size) { return buf; }
I  if (buf.subarray) { return buf.subarray(0, size); }
  buf.length = size;
  return buf;
};
 
 
var fnTyped = {
  arraySet: function (dest, src, src_offs, len, dest_offs) {
I    if (src.subarray && dest.subarray) {
      dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
      return;
    }
    // Fallback to ordinary array
    for (var i = 0; i < len; i++) {
      dest[dest_offs + i] = src[src_offs + i];
    }
  },
  // Join array of chunks to single array.
  flattenChunks: function (chunks) {
    var i, l, len, pos, chunk, result;
 
    // calculate data length
    len = 0;
    for (i = 0, l = chunks.length; i < l; i++) {
      len += chunks[i].length;
    }
 
    // join chunks
    result = new Uint8Array(len);
    pos = 0;
    for (i = 0, l = chunks.length; i < l; i++) {
      chunk = chunks[i];
      result.set(chunk, pos);
      pos += chunk.length;
    }
 
    return result;
  }
};
 
var fnUntyped = {
  arraySet: function (dest, src, src_offs, len, dest_offs) {
    for (var i = 0; i < len; i++) {
      dest[dest_offs + i] = src[src_offs + i];
    }
  },
  // Join array of chunks to single array.
  flattenChunks: function (chunks) {
    return [].concat.apply([], chunks);
  }
};
 
 
// Enable/Disable typed arrays use, for testing
//
exports.setTyped = function (on) {
  if (on) {
    exports.Buf8  = Uint8Array;
    exports.Buf16 = Uint16Array;
    exports.Buf32 = Int32Array;
    exports.assign(exports, fnTyped);
  } Eelse {
    exports.Buf8  = Array;
    exports.Buf16 = Array;
    exports.Buf32 = Array;
    exports.assign(exports, fnUntyped);
  }
};
 
exports.setTyped(TYPED_OK);