From 523929c9272a53c9429616564a45f2af59670e47 Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Wed, 22 Oct 2014 16:57:51 -0600 Subject: [PATCH] repl: Private Buffer object in lib/* files Fixes usage of global object 'Buffer' in lib/* files by ensuring that each file does an explicit require('buffer').Buffer. Previously, when running a repl, due to usage of global 'Buffer', any redefinition of Buffer would cause a crash eg var Buffer = {}. Fixes: https://github.com/joyent/node/issues/8588 PR-URL: https://github.com/joyent/node/pull/8603 Reviewed-by: Trevor Norris --- lib/_stream_readable.js | 1 + lib/_stream_writable.js | 1 + lib/assert.js | 3 ++- lib/dgram.js | 1 + lib/fs.js | 1 + lib/http.js | 1 + lib/net.js | 1 + lib/readline.js | 1 + lib/tls.js | 1 + lib/zlib.js | 1 + 10 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 1b29676e00d7..52fe3136af5d 100755 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -24,6 +24,7 @@ Readable.ReadableState = ReadableState; var EE = require('events').EventEmitter; var Stream = require('stream'); +var Buffer = require('buffer').Buffer; var util = require('util'); var StringDecoder; diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index f02eb4edc1ee..f5efe723b42d 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -28,6 +28,7 @@ Writable.WritableState = WritableState; var util = require('util'); var Stream = require('stream'); +var Buffer = require('buffer').Buffer; util.inherits(Writable, Stream); diff --git a/lib/assert.js b/lib/assert.js index c9b71d44999c..5bd30ea952ea 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -24,6 +24,7 @@ // UTILITY var util = require('util'); +var b = require('buffer'); var pSlice = Array.prototype.slice; // 1. The assert module provides functions that throw @@ -144,7 +145,7 @@ function _deepEqual(actual, expected) { if (actual === expected) { return true; - } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) { + } else if (b.Buffer.isBuffer(actual) && b.Buffer.isBuffer(expected)) { if (actual.length != expected.length) return false; for (var i = 0; i < actual.length; i++) { diff --git a/lib/dgram.js b/lib/dgram.js index e724a619d8ca..ea14214535a7 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -22,6 +22,7 @@ var assert = require('assert'); var util = require('util'); var events = require('events'); +var Buffer = require('buffer').Buffer; var UDP = process.binding('udp_wrap').UDP; diff --git a/lib/fs.js b/lib/fs.js index 1e3dc6415a62..626f38c1dd14 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -31,6 +31,7 @@ var pathModule = require('path'); var binding = process.binding('fs'); var constants = process.binding('constants'); var fs = exports; +var Buffer = require('buffer').Buffer; var Stream = require('stream').Stream; var EventEmitter = require('events').EventEmitter; diff --git a/lib/http.js b/lib/http.js index f87df173b31d..6f640d1af37b 100644 --- a/lib/http.js +++ b/lib/http.js @@ -24,6 +24,7 @@ var net = require('net'); var Stream = require('stream'); var timers = require('timers'); var url = require('url'); +var Buffer = require('buffer').Buffer; var EventEmitter = require('events').EventEmitter; var FreeList = require('freelist').FreeList; var HTTPParser = process.binding('http_parser').HTTPParser; diff --git a/lib/net.js b/lib/net.js index bc336934b1d8..402e0909bc65 100644 --- a/lib/net.js +++ b/lib/net.js @@ -25,6 +25,7 @@ var timers = require('timers'); var util = require('util'); var assert = require('assert'); var cares = process.binding('cares_wrap'); +var Buffer = require('buffer').Buffer; var cluster; function noop() {} diff --git a/lib/readline.js b/lib/readline.js index c52f3e88b215..d64661622e14 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -29,6 +29,7 @@ var kHistorySize = 30; var kBufSize = 10 * 1024; var util = require('util'); +var Buffer = require('buffer').Buffer; var inherits = require('util').inherits; var EventEmitter = require('events').EventEmitter; diff --git a/lib/tls.js b/lib/tls.js index 77a7089218b7..e3b90832236f 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -26,6 +26,7 @@ var url = require('url'); var events = require('events'); var stream = require('stream'); var assert = require('assert').ok; +var Buffer = require('buffer').Buffer; var constants = require('constants'); var Timer = process.binding('timer_wrap').Timer; diff --git a/lib/zlib.js b/lib/zlib.js index c72ab92dcda1..0004f9da4ba3 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -23,6 +23,7 @@ var Transform = require('_stream_transform'); var binding = process.binding('zlib'); var util = require('util'); +var Buffer = require('buffer').Buffer; var assert = require('assert').ok; // zlib doesn't provide these, so kludge them in following the same