Skip to content

Commit

Permalink
[fix] Remove any reference to the global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Nov 7, 2018
1 parent d95e38f commit b47efb2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
var isArray = require('isarray');
var isBuf = require('./is-buffer');
var toString = Object.prototype.toString;
var withNativeBlob = typeof global.Blob === 'function' || toString.call(global.Blob) === '[object BlobConstructor]';
var withNativeFile = typeof global.File === 'function' || toString.call(global.File) === '[object FileConstructor]';
var withNativeBlob = typeof Blob === 'function' || (typeof Blob !== 'undefined' && toString.call(Blob) === '[object BlobConstructor]');
var withNativeFile = typeof File === 'function' || (typeof File !== 'undefined' && toString.call(File) === '[object FileConstructor]');

/**
* Replaces every Buffer | ArrayBuffer in packet with a numbered placeholder.
Expand Down
18 changes: 7 additions & 11 deletions is-buffer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@

module.exports = isBuf;

var withNativeBuffer = typeof global.Buffer === 'function' && typeof global.Buffer.isBuffer === 'function';
var withNativeArrayBuffer = typeof global.ArrayBuffer === 'function';
var withNativeBuffer = typeof Buffer === 'function' && typeof Buffer.isBuffer === 'function';
var withNativeArrayBuffer = typeof ArrayBuffer === 'function';

var isView = (function () {
if (withNativeArrayBuffer && typeof global.ArrayBuffer.isView === 'function') {
return global.ArrayBuffer.isView;
} else {
return function (obj) { return obj.buffer instanceof global.ArrayBuffer; };
}
})();
var isView = function (obj) {
return typeof ArrayBuffer.isView === 'function' ? ArrayBuffer.isView(obj) : (obj.buffer instanceof ArrayBuffer);
};

/**
* Returns true if obj is a buffer or an arraybuffer.
Expand All @@ -19,6 +15,6 @@ var isView = (function () {
*/

function isBuf(obj) {
return (withNativeBuffer && global.Buffer.isBuffer(obj)) ||
(withNativeArrayBuffer && (obj instanceof global.ArrayBuffer || isView(obj)));
return (withNativeBuffer && Buffer.isBuffer(obj)) ||
(withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj)));
}
8 changes: 4 additions & 4 deletions test/blob.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var parser = require('../index.js');
var expect = require('expect.js');
var helpers = require('./helpers.js');
var encode = parser.encode;
var decode = parser.decode;

var BlobBuilder = global.BlobBuilder || global.WebKitBlobBuilder || global.MSBlobBuilder || global.MozBlobBuilder;
var BlobBuilder = typeof BlobBuilder !== 'undefined' ? BlobBuilder :
typeof WebKitBlobBuilder !== 'undefined' ? WebKitBlobBuilder :
typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder :
typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : false;

describe('parser', function() {
it('encodes a Blob', function() {
Expand Down
7 changes: 5 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ var blobSupported = (function() {
* Create a blob builder even when vendor prefixes exist
*/

var BlobBuilder = global.BlobBuilder || global.WebKitBlobBuilder || global.MSBlobBuilder || global.MozBlobBuilder;
var BlobBuilder = typeof BlobBuilder !== 'undefined' ? BlobBuilder :
typeof WebKitBlobBuilder !== 'undefined' ? WebKitBlobBuilder :
typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder :
typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : false;
var blobBuilderSupported = !!BlobBuilder && !!BlobBuilder.prototype.append && !!BlobBuilder.prototype.getBlob;

require('./parser.js');
Expand All @@ -21,7 +24,7 @@ if (!env.browser) {
require('./buffer.js');
}

if (global.ArrayBuffer) {
if (typeof ArrayBuffer !== 'undefined') {
require('./arraybuffer.js');
}

Expand Down
2 changes: 1 addition & 1 deletion test/support/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// we only do this in our tests because we need to test engine.io-client
// support in browsers and in node.js
// some tests do not yet work in both
module.exports.browser = !!global.window;
module.exports.browser = typeof window !== 'undefined';

0 comments on commit b47efb2

Please sign in to comment.