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.3.0 to 1.4.0

src/console-shim.js

1

index.js

@@ -18,1 +18,2 @@ // Copyright (C) 2018 Agoric

import './src/assert-shim.js';
import './src/console-shim.js';

16

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

@@ -69,9 +69,9 @@ "keywords": [

"dependencies": {
"@endo/env-options": "^1.1.1"
"@endo/env-options": "^1.1.2"
},
"devDependencies": {
"@endo/compartment-mapper": "^1.1.2",
"@endo/static-module-record": "^1.0.4",
"@endo/test262-runner": "^0.1.34",
"ava": "^5.3.0",
"@endo/compartment-mapper": "^1.1.3",
"@endo/static-module-record": "^1.1.0",
"@endo/test262-runner": "^0.1.35",
"ava": "^6.1.2",
"babel-eslint": "^10.0.3",

@@ -89,3 +89,3 @@ "c8": "^7.14.0",

"tsd": "^0.28.1",
"typescript": "~5.3.3"
"typescript": "~5.4.2"
},

@@ -194,3 +194,3 @@ "files": [

},
"gitHead": "297fed572fedec0e1ae3ce34cf409f9d45233d43"
"gitHead": "36384eb5a4bbd11dd3d06a8045d620f8d6569590"
}

@@ -162,2 +162,5 @@ /* global globalThis */

export const arrayMap = /** @type {any} */ (uncurryThis(arrayPrototype.map));
export const arrayFlatMap = /** @type {any} */ (
uncurryThis(arrayPrototype.flatMap)
);
export const arrayPop = uncurryThis(arrayPrototype.pop);

@@ -164,0 +167,0 @@ /** @type {<T>(thisArg: T[], ...items: T[]) => number} */

@@ -11,3 +11,5 @@ // @ts-check

arrayFilter,
arrayFlatMap,
arrayMap,
arrayPop,
arrayPush,

@@ -19,2 +21,4 @@ defineProperty,

stringEndsWith,
stringIncludes,
stringSplit,
weaksetAdd,

@@ -51,4 +55,13 @@ weaksetHas,

/** @type {readonly [ConsoleProps, LogSeverity | undefined][]} */
const consoleLevelMethods = freeze([
/**
* Those console methods whose actual parameters are `(fmt?, ...args)`
* even if their TypeScript types claim otherwise.
*
* Each is paired with what we consider to be their log severity level.
* This is the same as the log severity of these on other
* platform console implementations when they all agree.
*
* @type {readonly [ConsoleProps, LogSeverity | undefined][]}
*/
export const consoleLevelMethods = freeze([
['debug', 'debug'], // (fmt?, ...args) verbose level on Chrome

@@ -61,9 +74,18 @@ ['log', 'log'], // (fmt?, ...args) info level on Chrome

['trace', 'log'], // (fmt?, ...args)
['dirxml', 'log'], // (fmt?, ...args)
['group', 'log'], // (fmt?, ...args)
['groupCollapsed', 'log'], // (fmt?, ...args)
['dirxml', 'log'], // (fmt?, ...args) but TS typed (...data)
['group', 'log'], // (fmt?, ...args) but TS typed (...label)
['groupCollapsed', 'log'], // (fmt?, ...args) but TS typed (...label)
]);
/** @type {readonly [ConsoleProps, LogSeverity | undefined][]} */
const consoleOtherMethods = freeze([
/**
* Those console methods other than those already enumerated by
* `consoleLevelMethods`.
*
* Each is paired with what we consider to be their log severity level.
* This is the same as the log severity of these on other
* platform console implementations when they all agree.
*
* @type {readonly [ConsoleProps, LogSeverity | undefined][]}
*/
export const consoleOtherMethods = freeze([
['assert', 'error'], // (value, fmt?, ...args)

@@ -92,3 +114,3 @@ ['timeLog', 'log'], // (label?, ...args) no fmt string

/** @type {readonly [ConsoleProps, LogSeverity | undefined][]} */
export const consoleWhitelist = freeze([
const consoleWhitelist = freeze([
...consoleLevelMethods,

@@ -125,6 +147,6 @@ ...consoleOtherMethods,

// /////////////////////////////////////////////////////////////////////////////
// //////////////////////////// Logging Console ////////////////////////////////
/** @type {MakeLoggingConsoleKit} */
const makeLoggingConsoleKit = (
export const makeLoggingConsoleKit = (
loggedErrorHandler,

@@ -170,5 +192,19 @@ { shouldResetForDebugging = false } = {},

freeze(makeLoggingConsoleKit);
export { makeLoggingConsoleKit };
// /////////////////////////////////////////////////////////////////////////////
/**
* Makes the same calls on a `baseConsole` that were made on a
* `loggingConsole` to produce this `log`. In this way, a logging console
* can be used as a buffer to delay the application of these calls to a
* `baseConsole`.
*
* @param {LogRecord[]} log
* @param {VirtualConsole} baseConsole
*/
export const pumpLogToConsole = (log, baseConsole) => {
for (const [name, ...args] of log) {
// eslint-disable-next-line @endo/no-polymorphic-call
baseConsole[name](...args);
}
};
// //////////////////////////// Causal Console /////////////////////////////////

@@ -185,3 +221,3 @@ /** @type {ErrorInfo} */

/** @type {MakeCausalConsole} */
const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
export const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
if (!baseConsole) {

@@ -373,8 +409,102 @@ return undefined;

freeze(makeCausalConsole);
export { makeCausalConsole };
// /////////////////////////////////////////////////////////////////////////////
/**
* @typedef {(...args: unknown[]) => void} Logger
*/
/**
* This is a rather horrible kludge to indent the output to a logger in
* the case where some arguments are strings containing newlines. Part of
* the problem is that console-like loggers, including the one in ava,
* join the string arguments of the log message with a space.
* Because of this, there's an extra space at the beginning of each of
* the split lines. So this kludge compensated by putting an extra empty
* string at the beginning, so that the logger will add the same extra
* joiner.
* TODO: Fix this horrible kludge, and indent in a sane manner.
*
* @param {string} str
* @param {string} sep
* @param {string[]} indents
* @returns {string[]}
*/
const indentAfterAllSeps = (str, sep, indents) => {
const [firstLine, ...restLines] = stringSplit(str, sep);
const indentedRest = arrayFlatMap(restLines, line => [sep, ...indents, line]);
return ['', firstLine, ...indentedRest];
};
/**
* @param {LoggedErrorHandler} loggedErrorHandler
*/
export const defineCausalConsoleFromLogger = loggedErrorHandler => {
/**
* Implement the `VirtualConsole` API badly by turning all calls into
* calls on `tlogger`. We need to do this to have `console` logging
* turn into calls to Ava's `t.log`, so these console log messages
* are output in the right place.
*
* @param {Logger} tlogger
* @returns {VirtualConsole}
*/
const makeCausalConsoleFromLogger = tlogger => {
const indents = [];
const logWithIndent = (...args) => {
if (indents.length > 0) {
args = arrayFlatMap(args, arg =>
typeof arg === 'string' && stringIncludes(arg, '\n')
? indentAfterAllSeps(arg, '\n', indents)
: [arg],
);
args = [...indents, ...args];
}
return tlogger(...args);
};
const makeNamed = (name, fn) =>
({ [name]: (...args) => fn(...args) })[name];
const baseConsole = fromEntries([
...arrayMap(consoleLevelMethods, ([name]) => [
name,
makeNamed(name, logWithIndent),
]),
...arrayMap(consoleOtherMethods, ([name]) => [
name,
makeNamed(name, (...args) => logWithIndent(name, ...args)),
]),
]);
// https://console.spec.whatwg.org/#grouping
for (const name of ['group', 'groupCollapsed']) {
if (baseConsole[name]) {
baseConsole[name] = makeNamed(name, (...args) => {
if (args.length >= 1) {
// Prefix the logged data with "group" or "groupCollapsed".
logWithIndent(...args);
}
// A single space is enough;
// the host console will separate them with additional spaces.
arrayPush(indents, ' ');
});
}
}
if (baseConsole.groupEnd) {
baseConsole.groupEnd = makeNamed('groupEnd', (...args) => {
arrayPop(indents);
});
}
harden(baseConsole);
const causalConsole = makeCausalConsole(
/** @type {VirtualConsole} */ (baseConsole),
loggedErrorHandler,
);
return /** @type {VirtualConsole} */ (causalConsole);
};
return freeze(makeCausalConsoleFromLogger);
};
freeze(defineCausalConsoleFromLogger);
// ///////////////////////// Filter Console ////////////////////////////////////
/** @type {FilterConsole} */
const filterConsole = (baseConsole, filter, _topic = undefined) => {
export const filterConsole = (baseConsole, filter, _topic = undefined) => {
// TODO do something with optional topic string

@@ -403,2 +533,1 @@ const whitelist = arrayFilter(

freeze(filterConsole);
export { filterConsole };

@@ -9,5 +9,13 @@ # Logging Errors

* SES hides annotations and stack traces by default. To reveal them, SES uses mechanisms like `process.on("uncaughtException")` in Node.js to catch the error and log it back to the `console` tamed by `lockdown`.
* In the scope of the Agoric software ecosystem, this architecture will allow us to eventually introduce a more powerful distributed `console` that can meaningfully capture stack traces for a distributed debugger, based on the design of [Causeway](https://github.com/Agoric/agoric-sdk/issues/1318#issuecomment-662127549).
We refer to the enhanced `console`, installed by default by the ses shim, as the *causal console*, because the annotations it reveals are often used to show causality information. For example, with the [`TRACK_TURNS=enabled`](https://github.com/Agoric/agoric-sdk/blob/master/docs/env.md#track_turns) and [`DEBUG=track-turns`](https://github.com/Agoric/agoric-sdk/blob/master/docs/env.md#debug) environment options set
```sh
# in bash syntax
export DEBUG=track-turns
export TRACK_TURNS=enabled
```
the @endo/eventual-send package will use annotations to show where previous `E` operations (either eventual sends or `E.when`) in previous turns *locally in the same vat* caused the turn with the current error. This is sometimes called "deep asynchronous stacks".
* In the scope of the Agoric software ecosystem, this architecture will allow us to eventually introduce a more powerful distributed causal `console` that can meaningfully capture stack traces for a distributed debugger, based on the design of [Causeway](https://github.com/Agoric/agoric-sdk/issues/1318#issuecomment-662127549).
## Goals, non-goals, and partial goals

@@ -14,0 +22,0 @@

@@ -9,3 +9,3 @@ /**

export const makeEvalFunction = safeEvaluate => {
// We use the the concise method syntax to create an eval without a
// We use the concise method syntax to create an eval without a
// [[Construct]] behavior (such that the invocation "new eval()" throws

@@ -12,0 +12,0 @@ // TypeError: eval is not a constructor"), but which still accepts a

@@ -28,7 +28,2 @@ import {

const speciesDesc = getOwnPropertyDescriptor(FERAL_REG_EXP, speciesSymbol);
if (!speciesDesc) {
throw TypeError('no RegExp[Symbol.species] descriptor');
}
defineProperties(ResultRegExp, {

@@ -42,4 +37,16 @@ length: { value: 2 },

},
[speciesSymbol]: speciesDesc,
});
// Hermes does not have `Symbol.species`. We should support such platforms.
if (speciesSymbol) {
const speciesDesc = getOwnPropertyDescriptor(
FERAL_REG_EXP,
speciesSymbol,
);
if (!speciesDesc) {
throw TypeError('no RegExp[Symbol.species] descriptor');
}
defineProperties(ResultRegExp, {
[speciesSymbol]: speciesDesc,
});
}
return ResultRegExp;

@@ -46,0 +53,0 @@ };

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