Skip to content

Commit

Permalink
Fixed Result to behave correctly like an array using slice and toArray (
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Feb 19, 2023
1 parent 4512e97 commit 399356b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src.ts/abi/coders/abstract-coder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ export class Result extends Array<any> {
* errors.
*/
toArray(): Array<any> {
const result: Array<any> = [ ];
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;
}

/**
Expand Down Expand Up @@ -170,7 +170,17 @@ export class Result extends Array<any> {
*/
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++) {
Expand Down

0 comments on commit 399356b

Please sign in to comment.