Skip to content

Commit

Permalink
Added Deferred Error support to Description objects to extent Interfa…
Browse files Browse the repository at this point in the history
…ce parse methods (#1894).
  • Loading branch information
ricmoo committed Aug 24, 2021
1 parent bdb54ac commit a662490
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/abi/src.ts/coders/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export function unpack(reader: Reader, coders: Array<Coder>): Result {

if (value instanceof Error) {
Object.defineProperty(values, name, {
enumerable: true,
get: () => { throw value; }
});
} else {
Expand All @@ -155,6 +156,7 @@ export function unpack(reader: Reader, coders: Array<Coder>): Result {
const value = values[i];
if (value instanceof Error) {
Object.defineProperty(values, i, {
enumerable: true,
get: () => { throw value; }
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/abi/src.ts/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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); }
});
}
Expand Down
11 changes: 10 additions & 1 deletion packages/properties/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a662490

Please sign in to comment.