From 2ad4e93a2e0899f93e4072a4c33468b0dca91461 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 23 Dec 2015 21:37:44 -0800 Subject: [PATCH] Proper strict mode support. Fixes #79 --- index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1abc8df..0dc9007 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,8 @@ */ /* eslint-disable no-proto */ +'use strict' + var base64 = require('base64-js') var ieee754 = require('ieee754') var isArray = require('isarray') @@ -88,8 +90,10 @@ function Buffer (arg) { return new Buffer(arg) } - this.length = 0 - this.parent = undefined + if (!Buffer.TYPED_ARRAY_SUPPORT) { + this.length = 0 + this.parent = undefined + } // Common case. if (typeof arg === 'number') { @@ -220,6 +224,10 @@ function fromJsonObject (that, object) { if (Buffer.TYPED_ARRAY_SUPPORT) { Buffer.prototype.__proto__ = Uint8Array.prototype Buffer.__proto__ = Uint8Array +} else { + // pre-set for values that may exist in the future + Buffer.prototype.length = undefined + Buffer.prototype.parent = undefined } function allocate (that, length) { @@ -370,10 +378,6 @@ function byteLength (string, encoding) { } Buffer.byteLength = byteLength -// pre-set for values that may exist in the future -Buffer.prototype.length = undefined -Buffer.prototype.parent = undefined - function slowToString (encoding, start, end) { var loweredCase = false -- 2.34.1