From c427c2df427f477eb1214d8ff3fdfad36e191a6c Mon Sep 17 00:00:00 2001 From: binaryta Date: Mon, 10 Dec 2018 05:38:30 +0900 Subject: Add TooLarge error code for buffers (#1298) In collaboration with @yushimatenjin --- js/buffer.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'js/buffer.ts') diff --git a/js/buffer.ts b/js/buffer.ts index 4e9cd6eb2..9e06eecd4 100644 --- a/js/buffer.ts +++ b/js/buffer.ts @@ -6,6 +6,7 @@ import { Reader, Writer, ReadResult } from "./io"; import { assert } from "./util"; import { TextDecoder } from "./text_encoding"; +import { DenoError, ErrorKind } from "./errors"; // MIN_READ is the minimum ArrayBuffer size passed to a read call by // buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond @@ -170,7 +171,10 @@ export class Buffer implements Reader, Writer { // don't spend all our time copying. copyBytes(this.buf, this.buf.subarray(this.off)); } else if (c > MAX_SIZE - c - n) { - throw Error("ErrTooLarge"); // TODO DenoError(TooLarge) + throw new DenoError( + ErrorKind.TooLarge, + "The buffer cannot be grown beyond the maximum size." + ); } else { // Not enough space anywhere, we need to allocate. const buf = new Uint8Array(2 * c + n); -- cgit v1.2.3