Socket
Socket
Sign inDemoInstall

ses

Package Overview
Dependencies
Maintainers
6
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ses - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

20

NEWS.md
User-visible changes in SES:
# v1.3.0 (2024-02-22)
- Now supports `Promise.any`, `AggegateError`, `error.errors`,
and `error.cause`.
- Assertion functions/methods that were parameterized by an error constructor
(`makeError`, `assert`, `assert.fail`, `assert.equal`) now also accept named
options `cause` and `errors` in their immediately succeeding
`options` argument.
- For all those, the error constructor can now be an `AggregateError`.
If they do make an error instance, they encapsulate the
non-uniformity of the `AggregateError` construction arguments, allowing
all the error constructors to be used polymorphically
(generic / interchangeable).
- Adds a `GenericErrorConstructor` type to be effectively the common supertype
of `ErrorConstructor` and `AggregateErrorConstructor`, for typing these
error constructor parameters that handle the error constructor
polymorphically.
- The SES `console` now includes `error.cause` and `error.errors` in
its diagnostic output for errors.
# v1.2.0 (2024-02-14)

@@ -4,0 +24,0 @@

13

package.json
{
"name": "ses",
"version": "1.2.0",
"version": "1.3.0",
"description": "Hardened JavaScript for Fearless Cooperation",

@@ -72,5 +72,5 @@ "keywords": [

"devDependencies": {
"@endo/compartment-mapper": "^1.1.1",
"@endo/static-module-record": "^1.0.3",
"@endo/test262-runner": "^0.1.33",
"@endo/compartment-mapper": "^1.1.2",
"@endo/static-module-record": "^1.0.4",
"@endo/test262-runner": "^0.1.34",
"ava": "^5.3.0",

@@ -165,3 +165,4 @@ "babel-eslint": "^10.0.3",

"parseInt",
"unescape"
"unescape",
"AggregateError"
],

@@ -193,3 +194,3 @@ "@endo/no-polymorphic-call": "error"

},
"gitHead": "f731c5c12f8d185dbf2daf53ec6a57e5ac56e4e9"
"gitHead": "297fed572fedec0e1ae3ce34cf409f9d45233d43"
}

@@ -50,2 +50,3 @@ /* global globalThis */

TypeError,
AggregateError,
} = globalThis;

@@ -52,0 +53,0 @@

@@ -152,2 +152,8 @@ import { toStringTagSymbol, iteratorSymbol } from './commons.js';

// https://github.com/endojs/endo/issues/550
'%AggregateErrorPrototype%': {
message: true, // to match TypeErrorPrototype.message
name: true, // set by "node 14"?
},
'%PromisePrototype%': {

@@ -154,0 +160,0 @@ constructor: true, // set by "core-js"

@@ -24,2 +24,3 @@ // Copyright (C) 2019 Agoric, under Apache License 2.0

freeze,
defineProperty,
globalThis,

@@ -37,2 +38,3 @@ is,

weakmapSet,
AggregateError,
} from '../commons.js';

@@ -262,4 +264,4 @@ import { an, bestEffortStringify } from './stringify-utils.js';

optDetails = redactedDetails`Assert failed`,
ErrorConstructor = globalThis.Error,
{ errorName = undefined } = {},
errConstructor = globalThis.Error,
{ errorName = undefined, cause = undefined, errors = undefined } = {},
) => {

@@ -276,3 +278,25 @@ if (typeof optDetails === 'string') {

const messageString = getMessageString(hiddenDetails);
const error = new ErrorConstructor(messageString);
const opts = cause && { cause };
let error;
if (
typeof AggregateError !== 'undefined' &&
errConstructor === AggregateError
) {
error = AggregateError(errors || [], messageString, opts);
} else {
error = /** @type {ErrorConstructor} */ (errConstructor)(
messageString,
opts,
);
if (errors !== undefined) {
// Since we need to tolerate `errors` on an AggregateError, may as
// well tolerate it on all errors.
defineProperty(error, 'errors', {
value: errors,
writable: true,
enumerable: false,
configurable: true,
});
}
}
weakmapSet(hiddenMessageLogArgs, error, getLogArgs(hiddenDetails));

@@ -389,5 +413,6 @@ if (errorName !== undefined) {

optDetails = assertFailedDetails,
ErrorConstructor = globalThis.Error,
errConstructor = undefined,
options = undefined,
) => {
const reason = makeError(optDetails, ErrorConstructor);
const reason = makeError(optDetails, errConstructor, options);
if (optRaise !== undefined) {

@@ -410,5 +435,6 @@ optRaise(reason);

optDetails = undefined,
ErrorConstructor = undefined,
errConstructor = undefined,
options = undefined,
) {
flag || fail(optDetails, ErrorConstructor);
flag || fail(optDetails, errConstructor, options);
}

@@ -421,3 +447,4 @@

optDetails = undefined,
ErrorConstructor = undefined,
errConstructor = undefined,
options = undefined,
) => {

@@ -427,3 +454,4 @@ is(actual, expected) ||

optDetails || details`Expected ${actual} is same as ${expected}`,
ErrorConstructor || RangeError,
errConstructor || RangeError,
options,
);

@@ -430,0 +458,0 @@ };

@@ -172,2 +172,4 @@ // @ts-check

MESSAGE: 'ERROR_MESSAGE:',
CAUSE: 'cause:',
ERRORS: 'errors:',
};

@@ -312,2 +314,10 @@ freeze(ErrorInfo);

// Show the other annotations on error
if (error.cause) {
logErrorInfo(severity, error, ErrorInfo.CAUSE, [error.cause], subErrors);
}
// @ts-expect-error AggregateError has an `errors` property.
if (error.errors) {
// @ts-expect-error AggregateError has an `errors` property.
logErrorInfo(severity, error, ErrorInfo.ERRORS, error.errors, subErrors);
}
for (const noteLogArgs of noteLogArgsArray) {

@@ -314,0 +324,0 @@ logErrorInfo(severity, error, ErrorInfo.NOTE, noteLogArgs, subErrors);

@@ -72,3 +72,8 @@ // @ts-check

/**
* @typedef {{ NOTE: 'ERROR_NOTE:', MESSAGE: 'ERROR_MESSAGE:' }} ErrorInfo
* @typedef {{
* NOTE: 'ERROR_NOTE:',
* MESSAGE: 'ERROR_MESSAGE:',
* CAUSE: 'cause:',
* ERRORS: 'errors:',
* }} ErrorInfo
*/

@@ -75,0 +80,0 @@

@@ -61,10 +61,10 @@ // @ts-check

: typeof globalThis.print === 'function'
? // Make a good-enough console for eshost (including only functions that
// log at a specific level with no special argument interpretation).
// https://console.spec.whatwg.org/#logging
(p => freeze({ debug: p, log: p, info: p, warn: p, error: p }))(
// eslint-disable-next-line no-undef
wrapLogger(globalThis.print),
)
: undefined
? // Make a good-enough console for eshost (including only functions that
// log at a specific level with no special argument interpretation).
// https://console.spec.whatwg.org/#logging
(p => freeze({ debug: p, log: p, info: p, warn: p, error: p }))(
// eslint-disable-next-line no-undef
wrapLogger(globalThis.print),
)
: undefined
);

@@ -71,0 +71,0 @@

// @ts-check
/**
* TypeScript does not treat `AggregateErrorConstructor` as a subtype of
* `ErrorConstructor`, which makes sense because their constructors
* have incompatible signatures. However, we want to parameterize some
* operations by any error constructor, including possible `AggregateError`.
* So we introduce `GenericErrorConstructor` as a common supertype. Any call
* to it to make an instance must therefore first case split on whether the
* constructor is an AggregateErrorConstructor or a normal ErrorConstructor.
*
* @typedef {ErrorConstructor | AggregateErrorConstructor} GenericErrorConstructor
*/
/**
* @callback BaseAssert

@@ -8,5 +20,6 @@ * The `assert` function itself.

* @param {any} flag The truthy/falsy value
* @param {Details=} optDetails The details to throw
* @param {ErrorConstructor=} ErrorConstructor An optional alternate error
* constructor to use.
* @param {Details} [optDetails] The details to throw
* @param {GenericErrorConstructor} [errConstructor]
* An optional alternate error constructor to use.
* @param {AssertMakeErrorOptions} [options]
* @returns {asserts flag}

@@ -17,3 +30,6 @@ */

* @typedef {object} AssertMakeErrorOptions
* @property {string=} errorName
* @property {string} [errorName]
* @property {Error} [cause]
* @property {Error[]} [errors]
* Normally only used when the ErrorConstuctor is `AggregateError`
*/

@@ -27,6 +43,6 @@

* The optional `optDetails` can be a string.
* @param {Details=} optDetails The details of what was asserted
* @param {ErrorConstructor=} ErrorConstructor An optional alternate error
* constructor to use.
* @param {AssertMakeErrorOptions=} options
* @param {Details} [optDetails] The details of what was asserted
* @param {GenericErrorConstructor} [errConstructor]
* An optional alternate error constructor to use.
* @param {AssertMakeErrorOptions} [options]
* @returns {Error}

@@ -46,5 +62,6 @@ */

* with the nodejs assertion library.
* @param {Details=} optDetails The details of what was asserted
* @param {ErrorConstructor=} ErrorConstructor An optional alternate error
* constructor to use.
* @param {Details} [optDetails] The details of what was asserted
* @param {GenericErrorConstructor} [errConstructor]
* An optional alternate error constructor to use.
* @param {AssertMakeErrorOptions} [options]
* @returns {never}

@@ -60,5 +77,6 @@ */

* @param {any} expected What we wanted
* @param {Details=} optDetails The details to throw
* @param {ErrorConstructor=} ErrorConstructor An optional alternate error
* constructor to use.
* @param {Details} [optDetails] The details to throw
* @param {GenericErrorConstructor} [errConstructor]
* An optional alternate error constructor to use.
* @param {AssertMakeErrorOptions} [options]
* @returns {void}

@@ -74,3 +92,3 @@ */

* @param {'bigint'} typename
* @param {Details=} optDetails
* @param {Details} [optDetails]
* @returns {asserts specimen is bigint}

@@ -83,3 +101,3 @@ */

* @param {'boolean'} typename
* @param {Details=} optDetails
* @param {Details} [optDetails]
* @returns {asserts specimen is boolean}

@@ -92,3 +110,3 @@ */

* @param {'function'} typename
* @param {Details=} optDetails
* @param {Details} [optDetails]
* @returns {asserts specimen is Function}

@@ -101,3 +119,3 @@ */

* @param {'number'} typename
* @param {Details=} optDetails
* @param {Details} [optDetails]
* @returns {asserts specimen is number}

@@ -110,3 +128,3 @@ */

* @param {'object'} typename
* @param {Details=} optDetails
* @param {Details} [optDetails]
* @returns {asserts specimen is Record<any, any> | null}

@@ -119,3 +137,3 @@ */

* @param {'string'} typename
* @param {Details=} optDetails
* @param {Details} [optDetails]
* @returns {asserts specimen is string}

@@ -128,3 +146,3 @@ */

* @param {'symbol'} typename
* @param {Details=} optDetails
* @param {Details} [optDetails]
* @returns {asserts specimen is symbol}

@@ -137,3 +155,3 @@ */

* @param {'undefined'} typename
* @param {Details=} optDetails
* @param {Details} [optDetails]
* @returns {asserts specimen is undefined}

@@ -157,3 +175,3 @@ */

* @param {any} specimen The value to get the typeof
* @param {Details=} optDetails The details to throw
* @param {Details} [optDetails] The details to throw
* @returns {asserts specimen is string}

@@ -219,3 +237,3 @@ */

* @param {any} payload What to declassify
* @param {(string|number)=} spaces
* @param {(string|number)} [spaces]
* @returns {StringablePayload} The declassified payload

@@ -253,4 +271,4 @@ */

*
* @param {Raise=} optRaise
* @param {boolean=} unredacted
* @param {Raise} [optRaise]
* @param {boolean} [unredacted]
* @returns {Assert}

@@ -419,4 +437,4 @@ */

* @param {ConsoleFilter} filter
* @param {string=} topic
* @param {string} [topic]
* @returns {VirtualConsole}
*/
/* eslint-disable no-restricted-globals */
/* eslint max-lines: 0 */
import { arrayPush } from './commons.js';
/**

@@ -11,4 +15,2 @@ * @file Exports {@code whitelist}, a recursively defined

/* eslint max-lines: 0 */
/**

@@ -86,2 +88,4 @@ * constantProperties

AsyncIterator: 'AsyncIterator',
// https://github.com/endojs/endo/issues/550
AggregateError: 'AggregateError',

@@ -190,4 +194,4 @@ // *** Other Properties of the Global Object

// ECMAScript spec by the meta variable NativeError.
// TODO Add AggregateError https://github.com/Agoric/SES-shim/issues/550
export const NativeErrors = [
/** @type {GenericErrorConstructor[]} */
const NativeErrors = [
EvalError,

@@ -199,4 +203,15 @@ RangeError,

URIError,
// https://github.com/endojs/endo/issues/550
// 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 };
/**

@@ -606,2 +621,4 @@ * <p>Each JSON record enumerates the disposition of the properties on

URIError: NativeError('%URIErrorPrototype%'),
// https://github.com/endojs/endo/issues/550
AggregateError: NativeError('%AggregateErrorPrototype%'),

@@ -614,2 +631,4 @@ '%EvalErrorPrototype%': NativeErrorPrototype('EvalError'),

'%URIErrorPrototype%': NativeErrorPrototype('URIError'),
// https://github.com/endojs/endo/issues/550
'%AggregateErrorPrototype%': NativeErrorPrototype('AggregateError'),

@@ -1482,5 +1501,4 @@ // *** Numbers and Dates

allSettled: fn,
// To transition from `false` to `fn` once we also have `AggregateError`
// TODO https://github.com/Agoric/SES-shim/issues/550
any: false, // ES2021
// https://github.com/Agoric/SES-shim/issues/550
any: fn,
prototype: '%PromisePrototype%',

@@ -1487,0 +1505,0 @@ race: fn,

@@ -122,2 +122,4 @@ /**

errorName?: string;
cause?: Error;
errors?: Error[];
}

@@ -179,2 +181,6 @@

export type GenericErrorConstructor =
| ErrorConstructor
| AggregateErrorConstructor;
export type Raise = (reason: Error) => void;

@@ -189,3 +195,4 @@ // Behold: recursion.

details?: Details,
errorConstructor?: ErrorConstructor,
errConstructor?: GenericErrorConstructor,
options?: AssertMakeErrorOptions,
): asserts value;

@@ -197,6 +204,11 @@ typeof: AssertTypeof;

details?: Details,
errorConstructor?: ErrorConstructor,
errConstructor?: GenericErrorConstructor,
options?: AssertMakeErrorOptions,
): void;
string(specimen: any, details?: Details): asserts specimen is string;
fail(details?: Details, errorConstructor?: ErrorConstructor): never;
fail(
details?: Details,
errConstructor?: GenericErrorConstructor,
options?: AssertMakeErrorOptions,
): never;
}

@@ -207,3 +219,3 @@

details?: Details,
errorConstructor?: ErrorConstructor,
errConstructor?: GenericErrorConstructor,
options?: AssertMakeErrorOptions,

@@ -210,0 +222,0 @@ ): Error;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc