From 840160f352ff0d8e88d4ac308a1640fd278f50fc Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Tue, 3 Nov 2020 14:21:35 -1000 Subject: [PATCH] BREAKING: Drop IE11, Safari 9-10 support MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Since Buffer now supports the BigInt methods and the code for that uses the exponentiation operator, I'm going to drop support for IE11 and Safari 9-10. Further changes I needed to make: - Use consistent shifting to floor the offset numbers, like we do for other methods - Remove all BigInt literals in favor of using a BigInt constructor – this fixes parse errors in older browsers like Safari 11 - Disable Node tests in Safari 11 and 12 since they use BigInt literal syntax This commit contains fixes for PR #267 --- README.md | 2 +- bin/{airtap-es6.yml => airtap-new.yml} | 6 ++---- bin/{airtap-es5.yml => airtap-old.yml} | 9 +++++---- bin/test.js | 8 ++++---- index.js | 28 +++++++++++++------------- package.json | 20 +++++++----------- 6 files changed, 33 insertions(+), 40 deletions(-) rename bin/{airtap-es6.yml => airtap-new.yml} (77%) rename bin/{airtap-es5.yml => airtap-old.yml} (56%) diff --git a/README.md b/README.md index 9a23d7c..451e235 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ instance methods, and class methods that are supported. - Manipulate binary data like a boss, in all browsers! - Super fast. Backed by Typed Arrays (`Uint8Array`/`ArrayBuffer`, not `Object`) - Extremely small bundle size (**6.75KB minified + gzipped**, 51.9KB with comments) -- Excellent browser support (Chrome, Firefox, Edge, Safari 9+, IE 11, iOS 9+, Android, etc.) +- Excellent browser support (Chrome, Firefox, Edge, Safari 11+, iOS 11+, Android, etc.) - Preserves Node API exactly, with one minor difference (see below) - Square-bracket `buf[4]` notation works! - Does not modify any browser prototypes or put anything on `window` diff --git a/bin/airtap-es6.yml b/bin/airtap-new.yml similarity index 77% rename from bin/airtap-es6.yml rename to bin/airtap-new.yml index f24be1a..8401f08 100644 --- a/bin/airtap-es6.yml +++ b/bin/airtap-new.yml @@ -6,10 +6,8 @@ browsers: - name: firefox version: -1..latest - name: safari - version: 10..latest + version: 14..latest - name: microsoftedge version: -1..latest - name: iphone - version: - - 10.3 - - latest + version: 14..latest diff --git a/bin/airtap-es5.yml b/bin/airtap-old.yml similarity index 56% rename from bin/airtap-es5.yml rename to bin/airtap-old.yml index aabfd65..73d87cd 100644 --- a/bin/airtap-es5.yml +++ b/bin/airtap-old.yml @@ -1,9 +1,10 @@ sauce_connect: true loopback: airtap.local browsers: - - name: ie - version: latest - name: safari - version: 9 + version: 11..13 - name: iphone - version: 9.3 + version: + - 11 + - 12 + - 13 diff --git a/bin/test.js b/bin/test.js index 35c8aac..ec557b2 100644 --- a/bin/test.js +++ b/bin/test.js @@ -14,21 +14,21 @@ function runBrowserTests () { const airtapYmlPath = path.join(__dirname, '..', '.airtap.yml') writeES5AirtapYml() - cp.spawn('npm', ['run', 'test-browser-es5'], { stdio: 'inherit' }) + cp.spawn('npm', ['run', 'test-browser-old'], { stdio: 'inherit' }) .on('close', function (code) { if (code !== 0) process.exit(code) writeES6AirtapYml() - cp.spawn('npm', ['run', 'test-browser-es6'], { stdio: 'inherit' }) + cp.spawn('npm', ['run', 'test-browser-new'], { stdio: 'inherit' }) .on('close', function (code) { process.exit(code) }) }) function writeES5AirtapYml () { - fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-es5.yml'))) + fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-old.yml'))) } function writeES6AirtapYml () { - fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-es6.yml'))) + fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-new.yml'))) } } diff --git a/index.js b/index.js index b14acc3..ba68f7b 100644 --- a/index.js +++ b/index.js @@ -1217,7 +1217,7 @@ Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE ( this[++offset] * 2 ** 16 + last * 2 ** 24 - return BigInt(lo) + (BigInt(hi) << 32n) + return BigInt(lo) + (BigInt(hi) << BigInt(32)) }) Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) { @@ -1239,7 +1239,7 @@ Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE ( this[++offset] * 2 ** 8 + last - return (BigInt(hi) << 32n) + BigInt(lo) + return (BigInt(hi) << BigInt(32)) + BigInt(lo) }) Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { @@ -1333,7 +1333,7 @@ Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (of this[offset + 6] * 2 ** 16 + (last << 24) // Overflow - return (BigInt(val) << 32n) + + return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + @@ -1354,7 +1354,7 @@ Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (of this[++offset] * 2 ** 8 + this[++offset] - return (BigInt(val) << 32n) + + return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + @@ -1487,7 +1487,7 @@ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert function wrtBigUInt64LE (buf, value, offset, min, max) { checkIntBI(value, min, max, buf, offset, 7) - let lo = Number(value & 0xffffffffn) + let lo = Number(value & BigInt(0xffffffff)) buf[offset++] = lo lo = lo >> 8 buf[offset++] = lo @@ -1495,7 +1495,7 @@ function wrtBigUInt64LE (buf, value, offset, min, max) { buf[offset++] = lo lo = lo >> 8 buf[offset++] = lo - let hi = Number(value >> 32n & 0xffffffffn) + let hi = Number(value >> BigInt(32) & BigInt(0xffffffff)) buf[offset++] = hi hi = hi >> 8 buf[offset++] = hi @@ -1509,7 +1509,7 @@ function wrtBigUInt64LE (buf, value, offset, min, max) { function wrtBigUInt64BE (buf, value, offset, min, max) { checkIntBI(value, min, max, buf, offset, 7) - let lo = Number(value & 0xffffffffn) + let lo = Number(value & BigInt(0xffffffff)) buf[offset + 7] = lo lo = lo >> 8 buf[offset + 6] = lo @@ -1517,7 +1517,7 @@ function wrtBigUInt64BE (buf, value, offset, min, max) { buf[offset + 5] = lo lo = lo >> 8 buf[offset + 4] = lo - let hi = Number(value >> 32n & 0xffffffffn) + let hi = Number(value >> BigInt(32) & BigInt(0xffffffff)) buf[offset + 3] = hi hi = hi >> 8 buf[offset + 2] = hi @@ -1529,11 +1529,11 @@ function wrtBigUInt64BE (buf, value, offset, min, max) { } Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) { - return wrtBigUInt64LE(this, value, offset, 0n, 0xffffffffffffffffn) + return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff')) }) Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) { - return wrtBigUInt64BE(this, value, offset, 0n, 0xffffffffffffffffn) + return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff')) }) Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { @@ -1633,11 +1633,11 @@ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) } Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) { - return wrtBigUInt64LE(this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn) + return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff')) }) Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) { - return wrtBigUInt64BE(this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn) + return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff')) }) function checkIEEE754 (buf, value, offset, ext, max, min) { @@ -1858,7 +1858,7 @@ E('ERR_OUT_OF_RANGE', received = addNumericalSeparator(String(input)) } else if (typeof input === 'bigint') { received = String(input) - if (input > 2n ** 32n || input < -(2n ** 32n)) { + if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) { received = addNumericalSeparator(received) } received += 'n' @@ -1892,7 +1892,7 @@ function checkIntBI (value, min, max, buf, offset, byteLength) { const n = typeof min === 'bigint' ? 'n' : '' let range if (byteLength > 3) { - if (min === 0 || min === 0n) { + if (min === 0 || min === BigInt(0)) { range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}` } else { range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` + diff --git a/package.json b/package.json index 97f6d82..5b3b02c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ ], "dependencies": { "base64-js": "^1.3.1", - "ieee754": "^1.1.13" + "ieee754": "^1.2.1" }, "devDependencies": { "airtap": "^3.0.0", @@ -24,13 +24,13 @@ "browserify": "^17.0.0", "concat-stream": "^2.0.0", "hyperquest": "^2.1.3", - "is-buffer": "^2.0.4", + "is-buffer": "^2.0.5", "is-nan": "^1.3.0", "split": "^1.0.1", "standard": "*", "tape": "^5.0.1", "through2": "^4.0.2", - "uglify-js": "^3.11.3" + "uglify-js": "^3.11.5" }, "homepage": "https://github.com/feross/buffer", "jspm": { @@ -61,25 +61,19 @@ "perf-node": "node perf/bracket-notation.js && node perf/concat.js && node perf/copy-big.js && node perf/copy.js && node perf/new-big.js && node perf/new.js && node perf/readDoubleBE.js && node perf/readFloatBE.js && node perf/readUInt32LE.js && node perf/slice.js && node perf/writeFloatBE.js", "size": "browserify -r ./ | uglifyjs -c -m | gzip | wc -c", "test": "standard && node ./bin/test.js", - "test-browser-es5": "airtap -- test/*.js", - "test-browser-es5-local": "airtap --local -- test/*.js", - "test-browser-es6": "airtap -- test/*.js test/node/*.js", - "test-browser-es6-local": "airtap --local -- test/*.js test/node/*.js", + "test-browser-old": "airtap -- test/*.js", + "test-browser-old-local": "airtap --local -- test/*.js", + "test-browser-new": "airtap -- test/*.js test/node/*.js", + "test-browser-new-local": "airtap --local -- test/*.js test/node/*.js", "test-node": "tape test/*.js test/node/*.js", "update-authors": "./bin/update-authors.sh" }, "standard": { - "globals": [ - "BigInt" - ], "ignore": [ "test/node/**/*.js", "test/common.js", "test/_polyfill.js", "perf/**/*.js" - ], - "globals": [ - "SharedArrayBuffer" ] }, "funding": [ -- 2.34.1