Skip to content

Commit 840160f

Browse files
committed
BREAKING: Drop IE11, Safari 9-10 support
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
1 parent 1704792 commit 840160f

6 files changed

Lines changed: 33 additions & 40 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ instance methods, and class methods that are supported.
2828
- Manipulate binary data like a boss, in all browsers!
2929
- Super fast. Backed by Typed Arrays (`Uint8Array`/`ArrayBuffer`, not `Object`)
3030
- Extremely small bundle size (**6.75KB minified + gzipped**, 51.9KB with comments)
31-
- Excellent browser support (Chrome, Firefox, Edge, Safari 9+, IE 11, iOS 9+, Android, etc.)
31+
- Excellent browser support (Chrome, Firefox, Edge, Safari 11+, iOS 11+, Android, etc.)
3232
- Preserves Node API exactly, with one minor difference (see below)
3333
- Square-bracket `buf[4]` notation works!
3434
- Does not modify any browser prototypes or put anything on `window`
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ browsers:
66
- name: firefox
77
version: -1..latest
88
- name: safari
9-
version: 10..latest
9+
version: 14..latest
1010
- name: microsoftedge
1111
version: -1..latest
1212
- name: iphone
13-
version:
14-
- 10.3
15-
- latest
13+
version: 14..latest
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
sauce_connect: true
22
loopback: airtap.local
33
browsers:
4-
- name: ie
5-
version: latest
64
- name: safari
7-
version: 9
5+
version: 11..13
86
- name: iphone
9-
version: 9.3
7+
version:
8+
- 11
9+
- 12
10+
- 13

bin/test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ function runBrowserTests () {
1414
const airtapYmlPath = path.join(__dirname, '..', '.airtap.yml')
1515

1616
writeES5AirtapYml()
17-
cp.spawn('npm', ['run', 'test-browser-es5'], { stdio: 'inherit' })
17+
cp.spawn('npm', ['run', 'test-browser-old'], { stdio: 'inherit' })
1818
.on('close', function (code) {
1919
if (code !== 0) process.exit(code)
2020
writeES6AirtapYml()
21-
cp.spawn('npm', ['run', 'test-browser-es6'], { stdio: 'inherit' })
21+
cp.spawn('npm', ['run', 'test-browser-new'], { stdio: 'inherit' })
2222
.on('close', function (code) {
2323
process.exit(code)
2424
})
2525
})
2626

2727
function writeES5AirtapYml () {
28-
fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-es5.yml')))
28+
fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-old.yml')))
2929
}
3030

3131
function writeES6AirtapYml () {
32-
fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-es6.yml')))
32+
fs.writeFileSync(airtapYmlPath, fs.readFileSync(path.join(__dirname, 'airtap-new.yml')))
3333
}
3434
}

index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (
12171217
this[++offset] * 2 ** 16 +
12181218
last * 2 ** 24
12191219

1220-
return BigInt(lo) + (BigInt(hi) << 32n)
1220+
return BigInt(lo) + (BigInt(hi) << BigInt(32))
12211221
})
12221222

12231223
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
@@ -1239,7 +1239,7 @@ Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (
12391239
this[++offset] * 2 ** 8 +
12401240
last
12411241

1242-
return (BigInt(hi) << 32n) + BigInt(lo)
1242+
return (BigInt(hi) << BigInt(32)) + BigInt(lo)
12431243
})
12441244

12451245
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
@@ -1333,7 +1333,7 @@ Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (of
13331333
this[offset + 6] * 2 ** 16 +
13341334
(last << 24) // Overflow
13351335

1336-
return (BigInt(val) << 32n) +
1336+
return (BigInt(val) << BigInt(32)) +
13371337
BigInt(first +
13381338
this[++offset] * 2 ** 8 +
13391339
this[++offset] * 2 ** 16 +
@@ -1354,7 +1354,7 @@ Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (of
13541354
this[++offset] * 2 ** 8 +
13551355
this[++offset]
13561356

1357-
return (BigInt(val) << 32n) +
1357+
return (BigInt(val) << BigInt(32)) +
13581358
BigInt(this[++offset] * 2 ** 24 +
13591359
this[++offset] * 2 ** 16 +
13601360
this[++offset] * 2 ** 8 +
@@ -1487,15 +1487,15 @@ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert
14871487
function wrtBigUInt64LE (buf, value, offset, min, max) {
14881488
checkIntBI(value, min, max, buf, offset, 7)
14891489

1490-
let lo = Number(value & 0xffffffffn)
1490+
let lo = Number(value & BigInt(0xffffffff))
14911491
buf[offset++] = lo
14921492
lo = lo >> 8
14931493
buf[offset++] = lo
14941494
lo = lo >> 8
14951495
buf[offset++] = lo
14961496
lo = lo >> 8
14971497
buf[offset++] = lo
1498-
let hi = Number(value >> 32n & 0xffffffffn)
1498+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
14991499
buf[offset++] = hi
15001500
hi = hi >> 8
15011501
buf[offset++] = hi
@@ -1509,15 +1509,15 @@ function wrtBigUInt64LE (buf, value, offset, min, max) {
15091509
function wrtBigUInt64BE (buf, value, offset, min, max) {
15101510
checkIntBI(value, min, max, buf, offset, 7)
15111511

1512-
let lo = Number(value & 0xffffffffn)
1512+
let lo = Number(value & BigInt(0xffffffff))
15131513
buf[offset + 7] = lo
15141514
lo = lo >> 8
15151515
buf[offset + 6] = lo
15161516
lo = lo >> 8
15171517
buf[offset + 5] = lo
15181518
lo = lo >> 8
15191519
buf[offset + 4] = lo
1520-
let hi = Number(value >> 32n & 0xffffffffn)
1520+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
15211521
buf[offset + 3] = hi
15221522
hi = hi >> 8
15231523
buf[offset + 2] = hi
@@ -1529,11 +1529,11 @@ function wrtBigUInt64BE (buf, value, offset, min, max) {
15291529
}
15301530

15311531
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
1532-
return wrtBigUInt64LE(this, value, offset, 0n, 0xffffffffffffffffn)
1532+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
15331533
})
15341534

15351535
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
1536-
return wrtBigUInt64BE(this, value, offset, 0n, 0xffffffffffffffffn)
1536+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
15371537
})
15381538

15391539
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
@@ -1633,11 +1633,11 @@ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert)
16331633
}
16341634

16351635
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
1636-
return wrtBigUInt64LE(this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn)
1636+
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
16371637
})
16381638

16391639
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
1640-
return wrtBigUInt64BE(this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn)
1640+
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
16411641
})
16421642

16431643
function checkIEEE754 (buf, value, offset, ext, max, min) {
@@ -1858,7 +1858,7 @@ E('ERR_OUT_OF_RANGE',
18581858
received = addNumericalSeparator(String(input))
18591859
} else if (typeof input === 'bigint') {
18601860
received = String(input)
1861-
if (input > 2n ** 32n || input < -(2n ** 32n)) {
1861+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
18621862
received = addNumericalSeparator(received)
18631863
}
18641864
received += 'n'
@@ -1892,7 +1892,7 @@ function checkIntBI (value, min, max, buf, offset, byteLength) {
18921892
const n = typeof min === 'bigint' ? 'n' : ''
18931893
let range
18941894
if (byteLength > 3) {
1895-
if (min === 0 || min === 0n) {
1895+
if (min === 0 || min === BigInt(0)) {
18961896
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`
18971897
} else {
18981898
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +

package.json

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
],
1717
"dependencies": {
1818
"base64-js": "^1.3.1",
19-
"ieee754": "^1.1.13"
19+
"ieee754": "^1.2.1"
2020
},
2121
"devDependencies": {
2222
"airtap": "^3.0.0",
2323
"benchmark": "^2.1.4",
2424
"browserify": "^17.0.0",
2525
"concat-stream": "^2.0.0",
2626
"hyperquest": "^2.1.3",
27-
"is-buffer": "^2.0.4",
27+
"is-buffer": "^2.0.5",
2828
"is-nan": "^1.3.0",
2929
"split": "^1.0.1",
3030
"standard": "*",
3131
"tape": "^5.0.1",
3232
"through2": "^4.0.2",
33-
"uglify-js": "^3.11.3"
33+
"uglify-js": "^3.11.5"
3434
},
3535
"homepage": "https://github.com/feross/buffer",
3636
"jspm": {
@@ -61,25 +61,19 @@
6161
"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",
6262
"size": "browserify -r ./ | uglifyjs -c -m | gzip | wc -c",
6363
"test": "standard && node ./bin/test.js",
64-
"test-browser-es5": "airtap -- test/*.js",
65-
"test-browser-es5-local": "airtap --local -- test/*.js",
66-
"test-browser-es6": "airtap -- test/*.js test/node/*.js",
67-
"test-browser-es6-local": "airtap --local -- test/*.js test/node/*.js",
64+
"test-browser-old": "airtap -- test/*.js",
65+
"test-browser-old-local": "airtap --local -- test/*.js",
66+
"test-browser-new": "airtap -- test/*.js test/node/*.js",
67+
"test-browser-new-local": "airtap --local -- test/*.js test/node/*.js",
6868
"test-node": "tape test/*.js test/node/*.js",
6969
"update-authors": "./bin/update-authors.sh"
7070
},
7171
"standard": {
72-
"globals": [
73-
"BigInt"
74-
],
7572
"ignore": [
7673
"test/node/**/*.js",
7774
"test/common.js",
7875
"test/_polyfill.js",
7976
"perf/**/*.js"
80-
],
81-
"globals": [
82-
"SharedArrayBuffer"
8377
]
8478
},
8579
"funding": [

0 commit comments

Comments
 (0)