diff --git a/packages/marshal/test/test-marshal-capdata.js b/packages/marshal/test/test-marshal-capdata.js index e0251a97e8..f4854083d7 100644 --- a/packages/marshal/test/test-marshal-capdata.js +++ b/packages/marshal/test/test-marshal-capdata.js @@ -154,12 +154,13 @@ test('unserialize errors', t => { }); test('unserialize extended errors', t => { + if (typeof AggregateError === 'undefined') { + t.pass('skip test on platforms prior to AggregateError'); + return; + } const { unserialize } = makeTestMarshal(); const uns = body => unserialize({ body, slots: [] }); - // TODO cause, errors, and AggregateError will eventually be recognized. - // See https://github.com/endojs/endo/pull/2042 - const refErr = uns( '{"@qclass":"error","message":"msg","name":"ReferenceError","extraProp":"foo","cause":"bar","errors":["zip","zap"]}', ); @@ -189,6 +190,10 @@ test('unserialize extended errors', t => { }); test('unserialize errors w recognized extensions', t => { + if (typeof AggregateError === 'undefined') { + t.pass('skip test on platforms prior to AggregateError'); + return; + } const { unserialize } = makeTestMarshal(); const uns = body => unserialize({ body, slots: [] }); diff --git a/packages/marshal/test/test-marshal-smallcaps.js b/packages/marshal/test/test-marshal-smallcaps.js index 9b285dbe02..86e75bdeca 100644 --- a/packages/marshal/test/test-marshal-smallcaps.js +++ b/packages/marshal/test/test-marshal-smallcaps.js @@ -160,6 +160,10 @@ test('smallcaps unserialize errors', t => { }); test('smallcaps unserialize extended errors', t => { + if (typeof AggregateError === 'undefined') { + t.pass('skip test on platforms prior to AggregateError'); + return; + } const { unserialize } = makeTestMarshal(); const uns = body => unserialize({ body, slots: [] }); @@ -192,6 +196,10 @@ test('smallcaps unserialize extended errors', t => { }); test('smallcaps unserialize errors w recognized extensions', t => { + if (typeof AggregateError === 'undefined') { + t.pass('skip test on platforms prior to AggregateError'); + return; + } const { unserialize } = makeTestMarshal(); const uns = body => unserialize({ body, slots: [] }); diff --git a/packages/pass-style/src/error.js b/packages/pass-style/src/error.js index dc9d4afae5..5e70ec8baf 100644 --- a/packages/pass-style/src/error.js +++ b/packages/pass-style/src/error.js @@ -24,10 +24,17 @@ const errorConstructors = new Map( ['URIError', URIError], // https://github.com/endojs/endo/issues/550 - ['AggregateError', AggregateError], + // To accommodate platforms prior to AggregateError, we comment out the + // following line and instead conditionally add it to the map below. + // ['AggregateError', AggregateError], ]), ); +if (typeof AggregateError !== 'undefined') { + // Conditional, to accommodate platforms prior to AggregateError + errorConstructors.set('AggregateError', AggregateError); +} + /** * Because the error constructor returned by this function might be * `AggregateError`, which has different construction parameters diff --git a/packages/pass-style/src/passStyleOf.js b/packages/pass-style/src/passStyleOf.js index 1f2ddb05a8..32b43db37b 100644 --- a/packages/pass-style/src/passStyleOf.js +++ b/packages/pass-style/src/passStyleOf.js @@ -299,7 +299,7 @@ export const assertPassableError = err => { * Return a new passable error that propagates the diagnostic info of the * original, and is linked to the original as a note. * - * @param {Error | AggregateError} err + * @param {Error} err * @returns {Error} */ export const toPassableError = err => { diff --git a/packages/pass-style/test/test-extended-errors.js b/packages/pass-style/test/test-extended-errors.js index 0f653bf39a..1f24f4b5e5 100644 --- a/packages/pass-style/test/test-extended-errors.js +++ b/packages/pass-style/test/test-extended-errors.js @@ -18,6 +18,9 @@ test('style of extended errors', t => { const u3 = harden(URIError('u3', { cause: e1 })); t.is(passStyleOf(u3), 'error'); - const a4 = harden(AggregateError([e2, u3], 'a4', { cause: e1 })); - t.is(passStyleOf(a4), 'error'); + if (typeof AggregateError !== 'undefined') { + // Conditional, to accommodate platforms prior to AggregateError + const a4 = harden(AggregateError([e2, u3], 'a4', { cause: e1 })); + t.is(passStyleOf(a4), 'error'); + } }); diff --git a/packages/ses/src/error/assert.js b/packages/ses/src/error/assert.js index 6dae9e3ae4..bacf5124c9 100644 --- a/packages/ses/src/error/assert.js +++ b/packages/ses/src/error/assert.js @@ -274,7 +274,10 @@ const makeError = ( const messageString = getMessageString(hiddenDetails); const opts = cause && { cause }; let error; - if (errConstructor === AggregateError) { + if ( + typeof AggregateError !== 'undefined' && + errConstructor === AggregateError + ) { error = AggregateError(errors || [], messageString, opts); } else { error = /** @type {ErrorConstructor} */ (errConstructor)( diff --git a/packages/ses/src/permits.js b/packages/ses/src/permits.js index bf3d33f4d2..611671dd6e 100644 --- a/packages/ses/src/permits.js +++ b/packages/ses/src/permits.js @@ -1,4 +1,8 @@ /* eslint-disable no-restricted-globals */ +/* eslint max-lines: 0 */ + +import { arrayPush } from './commons.js'; + /** * @file Exports {@code whitelist}, a recursively defined * JSON record enumerating all intrinsics and their properties @@ -8,8 +12,6 @@ * @author Mark S. Miller */ -/* eslint max-lines: 0 */ - /** * constantProperties * non-configurable, non-writable data properties of all global objects. @@ -187,7 +189,8 @@ export const uniqueGlobalPropertyNames = { // All the "subclasses" of Error. These are collectively represented in the // ECMAScript spec by the meta variable NativeError. -export const NativeErrors = [ +/** @type {GenericErrorConstructor[]} */ +const NativeErrors = [ EvalError, RangeError, ReferenceError, @@ -195,9 +198,18 @@ export const NativeErrors = [ TypeError, URIError, // https://github.com/endojs/endo/issues/550 - AggregateError, + // Commented out to accommodate platforms prior to AggregateError. + // Instead, conditional push below. + // AggregateError, ]; +if (typeof AggregateError !== 'undefined') { + // Conditional, to accommodate platforms prior to AggregateError + arrayPush(NativeErrors, AggregateError); +} + +export { NativeErrors }; + /** *

Each JSON record enumerates the disposition of the properties on * some corresponding intrinsic object. diff --git a/packages/ses/test/error/test-aggregate-error-console-demo.js b/packages/ses/test/error/test-aggregate-error-console-demo.js index 8472d7ce91..ba2da6ae16 100644 --- a/packages/ses/test/error/test-aggregate-error-console-demo.js +++ b/packages/ses/test/error/test-aggregate-error-console-demo.js @@ -10,6 +10,10 @@ import '../../index.js'; lockdown(); test('aggregate error console demo', t => { + if (typeof AggregateError === 'undefined') { + t.pass('skip test on platforms prior to AggregateError'); + return; + } const e3 = Error('e3'); const e2 = Error('e2', { cause: e3 }); const u4 = URIError('u4', { cause: e2 }); diff --git a/packages/ses/test/error/test-aggregate-error-console.js b/packages/ses/test/error/test-aggregate-error-console.js index 417fcc85c8..ba192546be 100644 --- a/packages/ses/test/error/test-aggregate-error-console.js +++ b/packages/ses/test/error/test-aggregate-error-console.js @@ -5,6 +5,10 @@ import { throwsAndLogs } from './throws-and-logs.js'; lockdown(); test('aggregate error console', t => { + if (typeof AggregateError === 'undefined') { + t.pass('skip test on platforms prior to AggregateError'); + return; + } const e3 = Error('e3'); const e2 = Error('e2', { cause: e3 }); const u4 = URIError('u4', { cause: e2 }); diff --git a/packages/ses/test/error/test-aggregate-error.js b/packages/ses/test/error/test-aggregate-error.js index a95fbd114c..5c0b0b2466 100644 --- a/packages/ses/test/error/test-aggregate-error.js +++ b/packages/ses/test/error/test-aggregate-error.js @@ -6,6 +6,10 @@ const { getOwnPropertyDescriptor } = Object; lockdown(); test('aggregate error', t => { + if (typeof AggregateError === 'undefined') { + t.pass('skip test on platforms prior to AggregateError'); + return; + } const e1 = Error('e1'); const e2 = Error('e2', { cause: e1 }); const u3 = URIError('u3', { cause: e1 }); @@ -28,6 +32,10 @@ test('aggregate error', t => { }); test('Promise.any aggregate error', async t => { + if (typeof AggregateError === 'undefined') { + t.pass('skip test on platforms prior to AggregateError'); + return; + } const e1 = Error('e1'); const e2 = Error('e2', { cause: e1 }); const u3 = URIError('u3', { cause: e1 }); diff --git a/packages/ses/test/error/test-error-cause.js b/packages/ses/test/error/test-error-cause.js index 0416285afd..5cd32091f5 100644 --- a/packages/ses/test/error/test-error-cause.js +++ b/packages/ses/test/error/test-error-cause.js @@ -27,6 +27,10 @@ test('error cause', t => { enumerable: false, configurable: true, }); + if (typeof AggregateError === 'undefined') { + t.pass('skip rest of test on platforms prior to AggregateError'); + return; + } const a4 = AggregateError([e2, u3], 'a4', { cause: e1 }); t.is(a4.message, 'a4'); t.is(a4.cause, e1);