diff options
author | Trevor Norris <trev.norris@gmail.com> | 2013-07-12 15:18:21 -0700 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2013-07-19 13:36:13 -0700 |
commit | d817843d2e0d8f9708620c76c471fc5e94f84264 (patch) | |
tree | 851c3b27a7c449af850f303969df9218ec71fa71 /lib/buffer.js | |
parent | 46d11510ad6ea9a1fd9ffeafbe9e2345fabc8e93 (diff) | |
download | node-new-d817843d2e0d8f9708620c76c471fc5e94f84264.tar.gz |
smalloc: create separate module
It will be confusing if later on we add Buffer#dispose(), and smalloc is
its own cpp api anyways. So instead create a new require('smalloc') to
expose the previous Buffer.alloc/dispose methods, and expose copyOnto
and kMaxLength as well.
Other changes:
* Added documentation and additional tests.
* smalloc::CopyOnto has changed from using assert() to throwing errors
on bad argument values because it is not exposed to the user.
* Minor style fixes.
Diffstat (limited to 'lib/buffer.js')
-rw-r--r-- | lib/buffer.js | 22 |
1 files changed, 1 insertions, 21 deletions
diff --git a/lib/buffer.js b/lib/buffer.js index a34d319971..5592e31691 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -19,8 +19,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -var smalloc = process.binding('smalloc'); var buffer = process.binding('buffer'); +var smalloc = process.binding('smalloc'); var assert = require('assert'); var util = require('util'); var alloc = smalloc.alloc; @@ -177,26 +177,6 @@ Buffer.concat = function(list, length) { }; -Buffer.alloc = function(n, obj) { - n = ~~n; - if (n < 0) n = 0; - - if (n > kMaxLength) - throw new RangeError('n > kMaxLength'); - if (Array.isArray(obj)) - throw new TypeError('Arrays are not supported'); - - return alloc(obj != null ? obj : {}, n); -}; - - -Buffer.dispose = function(obj) { - if (obj instanceof Buffer) - throw new TypeError('obj cannot be a Buffer'); - smalloc.dispose(obj); -}; - - // pre-set for values that may exist in the future Buffer.prototype.length = undefined; Buffer.prototype.parent = undefined; |