From 484a9f6470193980f44c496028a3cd219b6c4d51 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sat, 18 Feb 2023 21:42:01 -0500 Subject: [PATCH] Fixed Result to behave correctly like an array using slice and toArray (#3787). --- src.ts/abi/coders/abstract-coder.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src.ts/abi/coders/abstract-coder.ts b/src.ts/abi/coders/abstract-coder.ts index c7c9f8e524..bc28e8841c 100644 --- a/src.ts/abi/coders/abstract-coder.ts +++ b/src.ts/abi/coders/abstract-coder.ts @@ -136,12 +136,12 @@ export class Result extends Array { * errors. */ toArray(): Array { + const result: Array = [ ]; this.forEach((item, index) => { - if (item instanceof Error) { - throwError(`index ${ index }`, item); - } + if (item instanceof Error) { throwError(`index ${ index }`, item); } + result.push(item); }); - return Array.of(this); + return result; } /** @@ -170,7 +170,17 @@ export class Result extends Array { */ slice(start?: number | undefined, end?: number | undefined): Result { if (start == null) { start = 0; } + if (start < 0) { + start += this.length; + if (start < 0) { start = 0; } + } + if (end == null) { end = this.length; } + if (end < 0) { + end += this.length; + if (end < 0) { end = 0; } + } + if (end > this.length) { end = this.length; } const result = [ ], names = [ ]; for (let i = start; i < end; i++) {