Skip to content

Commit

Permalink
Merge pull request #150 from feross/feross/cleanup
Browse files Browse the repository at this point in the history
Lots of little cleanup
  • Loading branch information
feross committed Dec 2, 2016
2 parents ed9d8ce + 71b0c75 commit 0f45583
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 221 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

1 change: 1 addition & 0 deletions .npmignore
@@ -1,2 +1,3 @@
.zuul.yml
bin/
perf/
10 changes: 1 addition & 9 deletions bin/zuul-es5.yml
@@ -1,14 +1,6 @@
ui: tape
scripts:
- ./test/_polyfill.js
browsers:
- name: safari
version: latest
- name: ie
version: 11..latest
- name: microsoftedge
version: 13..latest
version: latest
- name: android
version: 4.4..latest
- name: iphone
version: latest
6 changes: 6 additions & 0 deletions bin/zuul-es6.yml
Expand Up @@ -4,3 +4,9 @@ browsers:
version: '-1..latest'
- name: firefox
version: '-1..latest'
- name: safari
version: latest
- name: microsoftedge
version: latest
- name: iphone
version: latest
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -19,7 +19,7 @@ var K_MAX_LENGTH = 0x7fffffff
exports.kMaxLength = K_MAX_LENGTH

/**
* If `TYPED_ARRAY_SUPPORT`:
* If `Buffer.TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
* === false Print warning and recommend using `buffer` v4.x which has an Object
* implementation (most compatible, even IE6)
Expand All @@ -37,7 +37,7 @@ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
if (!Buffer.TYPED_ARRAY_SUPPORT) {
console.error(
'This browser lacks typed array (Uint8Array) support which is required by ' +
'`buffer` v5.x. Use v4.x if you require old browser support.')
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.')
}

function typedArraySupport () {
Expand Down
150 changes: 0 additions & 150 deletions test/_polyfill.js

This file was deleted.

45 changes: 17 additions & 28 deletions test/basic.js
Expand Up @@ -8,15 +8,11 @@ test('instanceof Buffer', function (t) {
})

test('convert to Uint8Array in modern browsers', function (t) {
if (B.TYPED_ARRAY_SUPPORT) {
var buf = new B([1, 2])
var uint8array = new Uint8Array(buf.buffer)
t.ok(uint8array instanceof Uint8Array)
t.equal(uint8array[0], 1)
t.equal(uint8array[1], 2)
} else {
t.pass('object impl: skipping test')
}
var buf = new B([1, 2])
var uint8array = new Uint8Array(buf.buffer)
t.ok(uint8array instanceof Uint8Array)
t.equal(uint8array[0], 1)
t.equal(uint8array[1], 2)
t.end()
})

Expand Down Expand Up @@ -50,11 +46,8 @@ test('setting index value should modify buffer contents', function (t) {
test('storing negative number should cast to unsigned', function (t) {
var buf = new B(1)

if (B.TYPED_ARRAY_SUPPORT) {
// This does not work with the object implementation -- nothing we can do!
buf[0] = -3
t.equal(buf[0], 253)
}
buf[0] = -3
t.equal(buf[0], 253)

buf = new B(1)
buf.writeInt8(-3, 0)
Expand All @@ -64,21 +57,17 @@ test('storing negative number should cast to unsigned', function (t) {
})

test('test that memory is copied from array-like', function (t) {
if (B.TYPED_ARRAY_SUPPORT) {
var u = new Uint8Array(4)
var b = new B(u)
b[0] = 1
b[1] = 2
b[2] = 3
b[3] = 4
var u = new Uint8Array(4)
var b = new B(u)
b[0] = 1
b[1] = 2
b[2] = 3
b[3] = 4

t.equal(u[0], 0)
t.equal(u[1], 0)
t.equal(u[2], 0)
t.equal(u[3], 0)
} else {
t.pass('object impl: skipping test')
}
t.equal(u[0], 0)
t.equal(u[1], 0)
t.equal(u[2], 0)
t.equal(u[3], 0)

t.end()
})
40 changes: 19 additions & 21 deletions test/constructor.js
Expand Up @@ -55,27 +55,25 @@ test('new buffer from ArrayBuffer', function (t) {
})

test('new buffer from ArrayBuffer, shares memory', function (t) {
if (Buffer.TYPED_ARRAY_SUPPORT) {
var u = new Uint8Array([0, 1, 2, 3])
var arraybuffer = u.buffer
var b = new B(arraybuffer)
t.equal(b.length, 4)
t.equal(b[0], 0)
t.equal(b[1], 1)
t.equal(b[2], 2)
t.equal(b[3], 3)
t.equal(b[4], undefined)

// changing the Uint8Array (and thus the ArrayBuffer), changes the Buffer
u[0] = 10
t.equal(b[0], 10)
u[1] = 11
t.equal(b[1], 11)
u[2] = 12
t.equal(b[2], 12)
u[3] = 13
t.equal(b[3], 13)
}
var u = new Uint8Array([0, 1, 2, 3])
var arraybuffer = u.buffer
var b = new B(arraybuffer)
t.equal(b.length, 4)
t.equal(b[0], 0)
t.equal(b[1], 1)
t.equal(b[2], 2)
t.equal(b[3], 3)
t.equal(b[4], undefined)

// changing the Uint8Array (and thus the ArrayBuffer), changes the Buffer
u[0] = 10
t.equal(b[0], 10)
u[1] = 11
t.equal(b[1], 11)
u[2] = 12
t.equal(b[2], 12)
u[3] = 13
t.equal(b[3], 13)
t.end()
})

Expand Down
4 changes: 0 additions & 4 deletions test/slice.js
Expand Up @@ -2,8 +2,6 @@ var B = require('../').Buffer
var test = require('tape')

test('modifying buffer created by .slice() modifies original memory', function (t) {
if (!B.TYPED_ARRAY_SUPPORT) return t.end()

var buf1 = new B(26)
for (var i = 0; i < 26; i++) {
buf1[i] = i + 97 // 97 is ASCII a
Expand All @@ -19,8 +17,6 @@ test('modifying buffer created by .slice() modifies original memory', function (
})

test('modifying parent buffer modifies .slice() buffer\'s memory', function (t) {
if (!B.TYPED_ARRAY_SUPPORT) return t.end()

var buf1 = new B(26)
for (var i = 0; i < 26; i++) {
buf1[i] = i + 97 // 97 is ASCII a
Expand Down
6 changes: 0 additions & 6 deletions test/write.js
Expand Up @@ -65,12 +65,6 @@ test('hex of write{Uint,Int}{8,16,32}{LE,BE}', function (t) {
})

test('hex of write{Uint,Int}{8,16,32}{LE,BE} with overflow', function (t) {
if (!B.TYPED_ARRAY_SUPPORT) {
t.pass('object impl: skipping overflow test')
t.end()
return
}

t.plan(3 * (2 * 2 * 2 + 2))
var hex = [
'', '03', '00', '030000', '000000',
Expand Down

2 comments on commit 0f45583

@aiingstan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that uppy is not aiming to support IE 10, but I see the comment you leave here about using buffer v4.0 to support old browsers, can you explain me how?

@feross
Copy link
Owner Author

@feross feross commented on 0f45583 Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should ask the maintainers of uppy

Please sign in to comment.