From a662490e82a9b71b5f6dee0a8242e6fa78409d79 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Tue, 24 Aug 2021 16:03:12 -0300 Subject: [PATCH] Added Deferred Error support to Description objects to extent Interface parse methods (#1894). --- packages/abi/src.ts/coders/array.ts | 2 ++ packages/abi/src.ts/interface.ts | 2 ++ packages/properties/src.ts/index.ts | 11 ++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/abi/src.ts/coders/array.ts b/packages/abi/src.ts/coders/array.ts index 449b23e99..a9310370b 100644 --- a/packages/abi/src.ts/coders/array.ts +++ b/packages/abi/src.ts/coders/array.ts @@ -144,6 +144,7 @@ export function unpack(reader: Reader, coders: Array): Result { if (value instanceof Error) { Object.defineProperty(values, name, { + enumerable: true, get: () => { throw value; } }); } else { @@ -155,6 +156,7 @@ export function unpack(reader: Reader, coders: Array): Result { const value = values[i]; if (value instanceof Error) { Object.defineProperty(values, i, { + enumerable: true, get: () => { throw value; } }); } diff --git a/packages/abi/src.ts/interface.ts b/packages/abi/src.ts/interface.ts index fa79fdbf0..664838845 100644 --- a/packages/abi/src.ts/interface.ts +++ b/packages/abi/src.ts/interface.ts @@ -606,6 +606,7 @@ export class Interface { // Make error named values throw on access if (value instanceof Error) { Object.defineProperty(result, param.name, { + enumerable: true, get: () => { throw wrapAccessError(`property ${ JSON.stringify(param.name) }`, value); } }); } else { @@ -619,6 +620,7 @@ export class Interface { const value = result[i]; if (value instanceof Error) { Object.defineProperty(result, i, { + enumerable: true, get: () => { throw wrapAccessError(`index ${ i }`, value); } }); } diff --git a/packages/properties/src.ts/index.ts b/packages/properties/src.ts/index.ts index e6c4c4008..6dc7eadd1 100644 --- a/packages/properties/src.ts/index.ts +++ b/packages/properties/src.ts/index.ts @@ -73,7 +73,16 @@ function _isFrozen(object: any): boolean { const keys = Object.keys(object); for (let i = 0; i < keys.length; i++) { - if (!_isFrozen(object[keys[i]])) { return false; } + let value: any = null; + try { + value = object[keys[i]]; + } catch (error) { + // If accessing a value triggers an error, it is a getter + // designed to do so (e.g. Result) and is therefore "frozen" + continue; + } + + if (!_isFrozen(value)) { return false; } } return true;