From e226f001e4e4633d64c52be4abc1915d7b7bd515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E9=93=84=E8=BF=90?= Date: Sun, 18 Dec 2016 21:48:02 +0800 Subject: [PATCH] Support usage when size = 0 I got an error when encoding an empty message (`{}`). When the message is empty, the size is 0 and `slab` is null, so`slice.call(slab, offset, offset += size);` gave me ``` Uncaught TypeError: Method get TypedArray.prototype.subarray called on incompatible receiver null ``` Adding this solved the issue for me. Please correct me if I was using it all wrong. :joy: --- src/util/pool/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/pool/index.js b/src/util/pool/index.js index ea4feaddc..3f2337b7e 100644 --- a/src/util/pool/index.js +++ b/src/util/pool/index.js @@ -34,7 +34,7 @@ function pool(alloc, slice, size) { var slab = null; var offset = SIZE; return function pool_alloc(size) { - if (size > MAX) + if (size > MAX || size === 0) return alloc(size); if (offset + size > SIZE) { slab = alloc(SIZE);