From 2e5935b91cff462165a054b33c8b8413f51e3f39 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 15 May 2023 17:18:46 -0400 Subject: [PATCH] Fix Result.map when Array contains zero elements (#4036, #4048). --- src.ts/abi/coders/abstract-coder.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src.ts/abi/coders/abstract-coder.ts b/src.ts/abi/coders/abstract-coder.ts index bc28e8841c..8a4521a69d 100644 --- a/src.ts/abi/coders/abstract-coder.ts +++ b/src.ts/abi/coders/abstract-coder.ts @@ -211,6 +211,23 @@ export class Result extends Array { return new Result(_guard, result, names); } + /** + * @_ignore + */ + map(callback: (el: any, index: number, array: Result) => T, thisArg?: any): Array { + const result: Array = [ ]; + for (let i = 0; i < this.length; i++) { + const item = this[i]; + if (item instanceof Error) { + throwError(`index ${ i }`, item); + } + + result.push(callback.call(thisArg, item, i, this)); + } + + return result; + } + /** * Returns the value for %%name%%.