1
|
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
2
|
var B = require('../').Buffer
|
3
|
var test = require('tape')
|
4
|
|
5
|
test('modifying buffer created by .slice() modifies original memory', function (t) {
|
6
|
if (!B.TYPED_ARRAY_SUPPORT) return t.end()
|
7
|
|
8
|
var buf1 = new B(26)
|
9
|
for (var i = 0; i < 26; i++) {
|
10
|
buf1[i] = i + 97 // 97 is ASCII a
|
11
|
}
|
12
|
|
13
|
var buf2 = buf1.slice(0, 3)
|
14
|
t.equal(buf2.toString('ascii', 0, buf2.length), 'abc')
|
15
|
|
16
|
buf2[0] = '!'.charCodeAt(0)
|
17
|
t.equal(buf1.toString('ascii', 0, buf2.length), '!bc')
|
18
|
|
19
|
t.end()
|
20
|
})
|
21
|
|
22
|
test('modifying parent buffer modifies .slice() buffer\'s memory', function (t) {
|
23
|
if (!B.TYPED_ARRAY_SUPPORT) return t.end()
|
24
|
|
25
|
var buf1 = new B(26)
|
26
|
for (var i = 0; i < 26; i++) {
|
27
|
buf1[i] = i + 97 // 97 is ASCII a
|
28
|
}
|
29
|
|
30
|
var buf2 = buf1.slice(0, 3)
|
31
|
t.equal(buf2.toString('ascii', 0, buf2.length), 'abc')
|
32
|
|
33
|
buf1[0] = '!'.charCodeAt(0)
|
34
|
t.equal(buf2.toString('ascii', 0, buf2.length), '!bc')
|
35
|
|
36
|
t.end()
|
37
|
})
|