diff options
Diffstat (limited to 'ext/node/polyfills/internal/buffer.mjs')
-rw-r--r-- | ext/node/polyfills/internal/buffer.mjs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/ext/node/polyfills/internal/buffer.mjs b/ext/node/polyfills/internal/buffer.mjs index a051965a3..c32494555 100644 --- a/ext/node/polyfills/internal/buffer.mjs +++ b/ext/node/polyfills/internal/buffer.mjs @@ -220,12 +220,9 @@ function fromString(string, encoding) { return buf; } -function fromArrayLike(array) { - const length = array.length < 0 ? 0 : checked(array.length) | 0; - const buf = createBuffer(length); - for (let i = 0; i < length; i += 1) { - buf[i] = array[i] & 255; - } +function fromArrayLike(obj) { + const buf = new Uint8Array(obj); + Object.setPrototypeOf(buf, Buffer.prototype); return buf; } @@ -234,6 +231,7 @@ function fromObject(obj) { if (typeof obj.length !== "number") { return createBuffer(0); } + return fromArrayLike(obj); } |