This change is to prepare for proper `instanceof Buffer` support.
When testing the Object implementation, we’ll want to exclude the code
that changes the Buffer’s __proto__ values and it won’t be enough to
just set `Buffer.TYPED_ARRAY_SUPPORT = false` like we were doing before.
if (firstline) {
// require buffer explicitly
- var preamble = 'var Buffer = require(\'../../\').Buffer;\n' +
- 'if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;'
+ var preamble = 'if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;\n' +
+ 'var Buffer = require(\'../../\').Buffer;'
if (/use strict/.test(line)) line += '\n' + preamble
else line + preamble + '\n' + line
firstline = false
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
* get the Object implementation, which is slower but behaves correctly.
*/
-Buffer.TYPED_ARRAY_SUPPORT = (function () {
- function Bar () {}
- try {
- var arr = new Uint8Array(1)
- arr.foo = function () { return 42 }
- arr.constructor = Bar
- return arr.foo() === 42 && // typed array instances can be augmented
- arr.constructor === Bar && // constructor can be set
- typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
- arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
- } catch (e) {
- return false
- }
-})()
+Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
+ ? global.TYPED_ARRAY_SUPPORT
+ : (function () {
+ function Bar () {}
+ try {
+ var arr = new Uint8Array(1)
+ arr.foo = function () { return 42 }
+ arr.constructor = Bar
+ return arr.foo() === 42 && // typed array instances can be augmented
+ arr.constructor === Bar && // constructor can be set
+ typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
+ arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
+ } catch (e) {
+ return false
+ }
+ })()
function kMaxLength () {
return Buffer.TYPED_ARRAY_SUPPORT
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('base64: ignore whitespace', function (t) {
var text = '\n YW9ldQ== '
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('buf.constructor is Buffer', function (t) {
var buf = new B([1, 2])
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('buffer.compare', function (t) {
var b = new B(1).fill('a')
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('new buffer from array', function (t) {
t.equal(
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('.get (deprecated)', function (t) {
var b = new B([7, 42])
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('detect utf16 surrogate pairs', function (t) {
var text = '\uD83D\uDE38' + '\uD83D\uDCAD' + '\uD83D\uDC4D'
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('buffer.toJSON', function (t) {
var data = [1, 2, 3, 4]
'use strict';
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
var Buffer = require('../../').Buffer;
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
'use strict';
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
var Buffer = require('../../').Buffer;
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
'use strict';
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
var Buffer = require('../../').Buffer;
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
'use strict';
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
var Buffer = require('../../').Buffer;
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
'use strict';
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
var Buffer = require('../../').Buffer;
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
'use strict';
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
var Buffer = require('../../').Buffer;
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
'use strict';
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
var Buffer = require('../../').Buffer;
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
'use strict';
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false;
var Buffer = require('../../').Buffer;
-if (process.env.OBJECT_IMPL) Buffer.TYPED_ARRAY_SUPPORT = false;
var common = {};
var assert = require('assert');
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('modifying buffer created by .slice() modifies original memory', function (t) {
if (!B.TYPED_ARRAY_SUPPORT) return t.end()
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('Buffer.isEncoding', function (t) {
t.equal(B.isEncoding('HEX'), true)
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('utf8 buffer to base64', function (t) {
t.equal(
+if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
var B = require('../').Buffer
var test = require('tape')
var isnan = require('is-nan')
-if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
test('buffer.write string should get parsed as number', function (t) {
var b = new B(64)