Skip to content

Commit

Permalink
Merge pull request #47 from atlassian-forks/wbinnssmith/corejs
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop authored Apr 30, 2020
2 parents 9364e7d + 4068972 commit cb72df7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 107 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ script:
- 'npm test'
# Run browser tests on one node version.
- 'if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_NODE_VERSION}" = "stable" ]; then npm run test:browsers; fi'
- 'if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_NODE_VERSION}" = "stable" ]; then npm run test:browsers:with-polyfills; fi'
addons:
sauce_connect: true
hosts:
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
"inherits": "^2.0.3",
"is-arguments": "^1.0.4",
"is-generator-function": "^1.0.7",
"safe-buffer": "^5.1.2"
"is-typed-array": "^1.1.3",
"safe-buffer": "^5.1.2",
"which-typed-array": "^1.1.2"
},
"devDependencies": {
"airtap": "~1.0.0",
"core-js": "^3.6.5",
"is-async-supported": "~1.2.0",
"object.assign": "~4.1.0",
"object.entries": "^1.1.0",
Expand All @@ -40,6 +43,8 @@
"scripts": {
"test": "node test/node/index.js",
"test:browsers": "airtap test/browser/index.js",
"test:browsers:with-polyfills": "airtap test/browser/with-polyfills.js",
"test:browsers:with-polyfills:local": "npm run test:browsers:with-polyfills -- --local",
"test:browsers:local": "npm run test:browsers -- --local"
}
}
122 changes: 16 additions & 106 deletions support/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,17 @@

'use strict';

var isBuffer = require('./isBuffer');

var isArgumentsObject = require('is-arguments');
var isGeneratorFunction = require('is-generator-function');
var whichTypedArray = require('which-typed-array');
var isTypedArray = require('is-typed-array');

function uncurryThis(f) {
return f.call.bind(f);
}

var BigIntSupported = typeof BigInt !== 'undefined';
var SymbolSupported = typeof Symbol !== 'undefined';
var SymbolToStringTagSupported = SymbolSupported && typeof Symbol.toStringTag !== 'undefined';
var Uint8ArraySupported = typeof Uint8Array !== 'undefined';
var ArrayBufferSupported = typeof ArrayBuffer !== 'undefined';

if (Uint8ArraySupported && SymbolToStringTagSupported) {
var TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);

var TypedArrayProto_toStringTag =
uncurryThis(
Object.getOwnPropertyDescriptor(TypedArrayPrototype,
Symbol.toStringTag).get);

}

var ObjectToString = uncurryThis(Object.prototype.toString);

Expand Down Expand Up @@ -55,8 +42,8 @@ function checkBoxedPrimitive(value, prototypeValueOf) {
}

exports.isArgumentsObject = isArgumentsObject;

exports.isGeneratorFunction = isGeneratorFunction;
exports.isTypedArray = isTypedArray;

// Taken from here and modified for better browser support
// https://github.com/sindresorhus/p-is-promise/blob/cda35a513bda03f977ad5cde3a079d237e82d7ef/index.js
Expand All @@ -77,7 +64,7 @@ function isPromise(input) {
exports.isPromise = isPromise;

function isArrayBufferView(value) {
if (ArrayBufferSupported && ArrayBuffer.isView) {
if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView) {
return ArrayBuffer.isView(value);
}

Expand All @@ -88,129 +75,59 @@ function isArrayBufferView(value) {
}
exports.isArrayBufferView = isArrayBufferView;

function isTypedArray(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) !== undefined;
} else {
return (
isUint8Array(value) ||
isUint8ClampedArray(value) ||
isUint16Array(value) ||
isUint32Array(value) ||
isInt8Array(value) ||
isInt16Array(value) ||
isInt32Array(value) ||
isFloat32Array(value) ||
isFloat64Array(value) ||
isBigInt64Array(value) ||
isBigUint64Array(value)
);
}
}
exports.isTypedArray = isTypedArray;

function isUint8Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'Uint8Array';
} else {
return (
ObjectToString(value) === '[object Uint8Array]' ||
// If it's a Buffer instance _and_ has a `.buffer` property,
// this is an ArrayBuffer based buffer; thus it's an Uint8Array
// (Old Node.js had a custom non-Uint8Array implementation)
isBuffer(value) && value.buffer !== undefined
);
}
return whichTypedArray(value) === 'Uint8Array';
}
exports.isUint8Array = isUint8Array;

function isUint8ClampedArray(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'Uint8ClampedArray';
} else {
return ObjectToString(value) === '[object Uint8ClampedArray]';
}
return whichTypedArray(value) === 'Uint8ClampedArray';
}
exports.isUint8ClampedArray = isUint8ClampedArray;

function isUint16Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'Uint16Array';
} else {
return ObjectToString(value) === '[object Uint16Array]';
}
return whichTypedArray(value) === 'Uint16Array';
}
exports.isUint16Array = isUint16Array;

function isUint32Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'Uint32Array';
} else {
return ObjectToString(value) === '[object Uint32Array]';
}
return whichTypedArray(value) === 'Uint32Array';
}
exports.isUint32Array = isUint32Array;

function isInt8Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'Int8Array';
} else {
return ObjectToString(value) === '[object Int8Array]';
}
return whichTypedArray(value) === 'Int8Array';
}
exports.isInt8Array = isInt8Array;

function isInt16Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'Int16Array';
} else {
return ObjectToString(value) === '[object Int16Array]';
}
return whichTypedArray(value) === 'Int16Array';
}
exports.isInt16Array = isInt16Array;

function isInt32Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'Int32Array';
} else {
return ObjectToString(value) === '[object Int32Array]';
}
return whichTypedArray(value) === 'Int32Array';
}
exports.isInt32Array = isInt32Array;

function isFloat32Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'Float32Array';
} else {
return ObjectToString(value) === '[object Float32Array]';
}
return whichTypedArray(value) === 'Float32Array';
}
exports.isFloat32Array = isFloat32Array;

function isFloat64Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'Float64Array';
} else {
return ObjectToString(value) === '[object Float64Array]';
}
return whichTypedArray(value) === 'Float64Array';
}
exports.isFloat64Array = isFloat64Array;

function isBigInt64Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'BigInt64Array';
} else {
return ObjectToString(value) === '[object BigInt64Array]';
}
return whichTypedArray(value) === 'BigInt64Array';
}
exports.isBigInt64Array = isBigInt64Array;

function isBigUint64Array(value) {
if (Uint8ArraySupported && SymbolToStringTagSupported) {
return TypedArrayProto_toStringTag(value) === 'BigUint64Array';
} else {
return ObjectToString(value) === '[object BigUint64Array]';
}
return whichTypedArray(value) === 'BigUint64Array';
}
exports.isBigUint64Array = isBigUint64Array;

Expand Down Expand Up @@ -278,13 +195,6 @@ isWeakSetToString.working = (
);
function isWeakSet(value) {
return isWeakSetToString(value);
if (typeof WeakSet === 'undefined') {
return false;
}

return isWeakSetToString.working
? isWeakSetToString(value)
: value instanceof WeakSet;
}
exports.isWeakSet = isWeakSet;

Expand Down Expand Up @@ -405,7 +315,7 @@ function isBoxedPrimitive(value) {
exports.isBoxedPrimitive = isBoxedPrimitive;

function isAnyArrayBuffer(value) {
return Uint8ArraySupported && (
return typeof Uint8Array !== 'undefined' && (
isArrayBuffer(value) ||
isSharedArrayBuffer(value)
);
Expand Down
2 changes: 2 additions & 0 deletions test/browser/with-polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('core-js');
require('./index.js');

0 comments on commit cb72df7

Please sign in to comment.