Added Deferred Error support to Description objects to extent Interface parse methods (#1894).

This commit is contained in:
Richard Moore 2021-08-24 16:03:12 -03:00
parent bdb54ac52b
commit a662490e82
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
3 changed files with 14 additions and 1 deletions

@ -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 {
@ -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; }
});
}

@ -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); }
});
}

@ -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;