diff options
author | binaryta <naritatakuya0000@gmail.com> | 2018-12-10 05:38:30 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-09 15:38:30 -0500 |
commit | c427c2df427f477eb1214d8ff3fdfad36e191a6c (patch) | |
tree | f14068269fba8e495b5d5f5bb289257792a04255 /js/buffer.ts | |
parent | f2447f6a2307369c16322861735a87fdd30f7233 (diff) |
Add TooLarge error code for buffers (#1298)
In collaboration with @yushimatenjin
Diffstat (limited to 'js/buffer.ts')
-rw-r--r-- | js/buffer.ts | 6 |
1 files changed, 5 insertions, 1 deletions
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); |