@nocobase/plugin-flow-engine 2.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +29 -0
  3. package/build.config.ts +22 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/index.d.ts +15 -0
  7. package/dist/client/index.js +10 -0
  8. package/dist/externalVersion.js +21 -0
  9. package/dist/index.d.ts +10 -0
  10. package/dist/index.js +48 -0
  11. package/dist/locale/en-US.json +61 -0
  12. package/dist/locale/index.d.ts +141 -0
  13. package/dist/locale/index.js +79 -0
  14. package/dist/locale/zh-CN.json +61 -0
  15. package/dist/node_modules/ses/LICENSE +201 -0
  16. package/dist/node_modules/ses/LICENSE-aura +16 -0
  17. package/dist/node_modules/ses/LICENSE-caja +13 -0
  18. package/dist/node_modules/ses/LICENSE-corejs +19 -0
  19. package/dist/node_modules/ses/LICENSE-v8 +9 -0
  20. package/dist/node_modules/ses/assert-shim.js +1 -0
  21. package/dist/node_modules/ses/compartment-shim.js +1 -0
  22. package/dist/node_modules/ses/console-shim.js +1 -0
  23. package/dist/node_modules/ses/dist/lockdown.cjs +13912 -0
  24. package/dist/node_modules/ses/dist/lockdown.umd.js +13912 -0
  25. package/dist/node_modules/ses/dist/lockdown.umd.min.js +1 -0
  26. package/dist/node_modules/ses/dist/ses-hermes.cjs +13912 -0
  27. package/dist/node_modules/ses/dist/ses.cjs +1 -0
  28. package/dist/node_modules/ses/dist/ses.umd.js +13912 -0
  29. package/dist/node_modules/ses/dist/ses.umd.min.js +1 -0
  30. package/dist/node_modules/ses/dist/types.d.cts +606 -0
  31. package/dist/node_modules/ses/index.js +18 -0
  32. package/dist/node_modules/ses/lockdown-shim.js +1 -0
  33. package/dist/node_modules/ses/lockdown.js +1 -0
  34. package/dist/node_modules/ses/package.json +1 -0
  35. package/dist/node_modules/ses/src/assert-shim.js +4 -0
  36. package/dist/node_modules/ses/src/assert-sloppy-mode.js +11 -0
  37. package/dist/node_modules/ses/src/cauterize-property.js +69 -0
  38. package/dist/node_modules/ses/src/commons.js +425 -0
  39. package/dist/node_modules/ses/src/compartment-evaluate.js +93 -0
  40. package/dist/node_modules/ses/src/compartment-shim.js +22 -0
  41. package/dist/node_modules/ses/src/compartment.js +477 -0
  42. package/dist/node_modules/ses/src/console-shim.js +50 -0
  43. package/dist/node_modules/ses/src/enable-property-overrides.js +211 -0
  44. package/dist/node_modules/ses/src/enablements.js +244 -0
  45. package/dist/node_modules/ses/src/error/assert.js +584 -0
  46. package/dist/node_modules/ses/src/error/console.js +541 -0
  47. package/dist/node_modules/ses/src/error/fatal-assert.js +54 -0
  48. package/dist/node_modules/ses/src/error/internal-types.js +98 -0
  49. package/dist/node_modules/ses/src/error/note-log-args.js +77 -0
  50. package/dist/node_modules/ses/src/error/stringify-utils.js +195 -0
  51. package/dist/node_modules/ses/src/error/tame-console.js +197 -0
  52. package/dist/node_modules/ses/src/error/tame-error-constructor.js +284 -0
  53. package/dist/node_modules/ses/src/error/tame-v8-error-constructor.js +386 -0
  54. package/dist/node_modules/ses/src/error/types.js +59 -0
  55. package/dist/node_modules/ses/src/error/unhandled-rejection.js +122 -0
  56. package/dist/node_modules/ses/src/eval-scope.js +89 -0
  57. package/dist/node_modules/ses/src/get-anonymous-intrinsics.js +181 -0
  58. package/dist/node_modules/ses/src/get-source-url.js +50 -0
  59. package/dist/node_modules/ses/src/global-object.js +175 -0
  60. package/dist/node_modules/ses/src/intrinsics.js +192 -0
  61. package/dist/node_modules/ses/src/lockdown-shim.js +37 -0
  62. package/dist/node_modules/ses/src/lockdown.js +558 -0
  63. package/dist/node_modules/ses/src/make-eval-function.js +28 -0
  64. package/dist/node_modules/ses/src/make-evaluate.js +110 -0
  65. package/dist/node_modules/ses/src/make-function-constructor.js +79 -0
  66. package/dist/node_modules/ses/src/make-hardener.js +275 -0
  67. package/dist/node_modules/ses/src/make-safe-evaluator.js +112 -0
  68. package/dist/node_modules/ses/src/module-instance.js +497 -0
  69. package/dist/node_modules/ses/src/module-link.js +159 -0
  70. package/dist/node_modules/ses/src/module-load.js +719 -0
  71. package/dist/node_modules/ses/src/module-proxy.js +200 -0
  72. package/dist/node_modules/ses/src/permits-intrinsics.js +291 -0
  73. package/dist/node_modules/ses/src/permits.js +1761 -0
  74. package/dist/node_modules/ses/src/reporting-types.d.ts +13 -0
  75. package/dist/node_modules/ses/src/reporting.js +105 -0
  76. package/dist/node_modules/ses/src/scope-constants.js +180 -0
  77. package/dist/node_modules/ses/src/shim-arraybuffer-transfer.js +85 -0
  78. package/dist/node_modules/ses/src/sloppy-globals-scope-terminator.js +61 -0
  79. package/dist/node_modules/ses/src/strict-scope-terminator.js +99 -0
  80. package/dist/node_modules/ses/src/tame-date-constructor.js +127 -0
  81. package/dist/node_modules/ses/src/tame-domains.js +41 -0
  82. package/dist/node_modules/ses/src/tame-faux-data-properties.js +210 -0
  83. package/dist/node_modules/ses/src/tame-function-constructors.js +140 -0
  84. package/dist/node_modules/ses/src/tame-function-tostring.js +50 -0
  85. package/dist/node_modules/ses/src/tame-harden.js +29 -0
  86. package/dist/node_modules/ses/src/tame-locale-methods.js +78 -0
  87. package/dist/node_modules/ses/src/tame-math-object.js +41 -0
  88. package/dist/node_modules/ses/src/tame-module-source.js +51 -0
  89. package/dist/node_modules/ses/src/tame-regenerator-runtime.js +29 -0
  90. package/dist/node_modules/ses/src/tame-regexp-constructor.js +65 -0
  91. package/dist/node_modules/ses/src/tame-symbol-constructor.js +64 -0
  92. package/dist/node_modules/ses/src/transforms.js +267 -0
  93. package/dist/node_modules/ses/tools.js +25 -0
  94. package/dist/node_modules/ses/types.d.ts +606 -0
  95. package/dist/server/actions/ui-schema-action.d.ts +27 -0
  96. package/dist/server/actions/ui-schema-action.js +118 -0
  97. package/dist/server/collections/flowModelTreePath.d.ts +11 -0
  98. package/dist/server/collections/flowModelTreePath.js +74 -0
  99. package/dist/server/collections/flowModels.d.ts +11 -0
  100. package/dist/server/collections/flowModels.js +57 -0
  101. package/dist/server/collections/flowsql.d.ts +10 -0
  102. package/dist/server/collections/flowsql.js +51 -0
  103. package/dist/server/dao/ui_schema_node_dao.d.ts +26 -0
  104. package/dist/server/dao/ui_schema_node_dao.js +24 -0
  105. package/dist/server/helper.d.ts +8 -0
  106. package/dist/server/helper.js +9 -0
  107. package/dist/server/index.d.ts +9 -0
  108. package/dist/server/index.js +42 -0
  109. package/dist/server/model.d.ts +12 -0
  110. package/dist/server/model.js +38 -0
  111. package/dist/server/plugin.d.ts +26 -0
  112. package/dist/server/plugin.js +270 -0
  113. package/dist/server/repository.d.ts +116 -0
  114. package/dist/server/repository.js +1209 -0
  115. package/dist/server/server.d.ts +16 -0
  116. package/dist/server/server.js +198 -0
  117. package/dist/server/template/contexts.d.ts +73 -0
  118. package/dist/server/template/contexts.js +233 -0
  119. package/dist/server/template/resolver.d.ts +30 -0
  120. package/dist/server/template/resolver.js +225 -0
  121. package/dist/server/variables/registry.d.ts +42 -0
  122. package/dist/server/variables/registry.js +299 -0
  123. package/package.json +28 -0
  124. package/server.d.ts +2 -0
  125. package/server.js +1 -0
@@ -0,0 +1,77 @@
1
+ // @ts-check
2
+ /* eslint-disable @endo/no-polymorphic-call */
3
+ /* eslint-disable no-restricted-globals */
4
+
5
+ import { makeCacheMapKit } from '@endo/cache-map';
6
+
7
+ /**
8
+ * @import {CacheMapKit} from '@endo/cache-map';
9
+ * @import {LogArgs} from './internal-types.js';
10
+ */
11
+
12
+ const { freeze } = Object;
13
+ const { isSafeInteger } = Number;
14
+
15
+ const defaultLoggedErrorsBudget = 1000;
16
+ const defaultArgsPerErrorBudget = 100;
17
+
18
+ /**
19
+ * @param {number} [errorsBudget]
20
+ * @param {number} [argsPerErrorBudget]
21
+ */
22
+ export const makeNoteLogArgsArrayKit = (
23
+ errorsBudget = defaultLoggedErrorsBudget,
24
+ argsPerErrorBudget = defaultArgsPerErrorBudget,
25
+ ) => {
26
+ if (!isSafeInteger(argsPerErrorBudget) || argsPerErrorBudget < 1) {
27
+ throw TypeError(
28
+ 'argsPerErrorBudget must be a safe positive integer number',
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Maps from an error to an array of log args, where each log args is
34
+ * remembered as an annotation on that error. This can be used, for example,
35
+ * to keep track of additional causes of the error. The elements of any
36
+ * log args may include errors which are associated with further annotations.
37
+ * An augmented console, like the causal console of `console.js`, could
38
+ * then retrieve the graph of such annotations.
39
+ *
40
+ * @type {CacheMapKit<WeakMapConstructor, Error, LogArgs[]>}
41
+ */
42
+ const { cache: noteLogArgsArrayMap } = makeCacheMapKit(errorsBudget);
43
+
44
+ /**
45
+ * @param {Error} error
46
+ * @param {LogArgs} logArgs
47
+ */
48
+ const addLogArgs = (error, logArgs) => {
49
+ const logArgsArray = noteLogArgsArrayMap.get(error);
50
+ if (logArgsArray !== undefined) {
51
+ if (logArgsArray.length >= argsPerErrorBudget) {
52
+ logArgsArray.shift();
53
+ }
54
+ logArgsArray.push(logArgs);
55
+ } else {
56
+ noteLogArgsArrayMap.set(error, [logArgs]);
57
+ }
58
+ };
59
+ freeze(addLogArgs);
60
+
61
+ /**
62
+ * @param {Error} error
63
+ * @returns {LogArgs[] | undefined}
64
+ */
65
+ const takeLogArgsArray = error => {
66
+ const result = noteLogArgsArrayMap.get(error);
67
+ noteLogArgsArrayMap.delete(error);
68
+ return result;
69
+ };
70
+ freeze(takeLogArgsArray);
71
+
72
+ return freeze({
73
+ addLogArgs,
74
+ takeLogArgsArray,
75
+ });
76
+ };
77
+ freeze(makeNoteLogArgsArrayKit);
@@ -0,0 +1,195 @@
1
+ // @ts-check
2
+
3
+ import {
4
+ Set,
5
+ String,
6
+ isArray,
7
+ arrayJoin,
8
+ arraySlice,
9
+ arraySort,
10
+ arrayMap,
11
+ keys,
12
+ fromEntries,
13
+ freeze,
14
+ is,
15
+ isError,
16
+ setAdd,
17
+ setHas,
18
+ stringIncludes,
19
+ stringStartsWith,
20
+ stringifyJson,
21
+ toStringTagSymbol,
22
+ } from '../commons.js';
23
+
24
+ /** @import {StringablePayload} from '../../types.js' */
25
+
26
+ /**
27
+ * Joins English terms with commas and an optional conjunction.
28
+ *
29
+ * @param {(string | StringablePayload)[]} terms
30
+ * @param {"and" | "or"} conjunction
31
+ */
32
+ export const enJoin = (terms, conjunction) => {
33
+ if (terms.length === 0) {
34
+ return '(none)';
35
+ } else if (terms.length === 1) {
36
+ return terms[0];
37
+ } else if (terms.length === 2) {
38
+ const [first, second] = terms;
39
+ return `${first} ${conjunction} ${second}`;
40
+ } else {
41
+ return `${arrayJoin(arraySlice(terms, 0, -1), ', ')}, ${conjunction} ${
42
+ terms[terms.length - 1]
43
+ }`;
44
+ }
45
+ };
46
+
47
+ /**
48
+ * Prepend the correct indefinite article onto a noun, typically a typeof
49
+ * result, e.g., "an object" vs. "a number"
50
+ *
51
+ * @param {string} str The noun to prepend
52
+ * @returns {string} The noun prepended with a/an
53
+ */
54
+ const an = str => {
55
+ str = `${str}`;
56
+ if (str.length >= 1 && stringIncludes('aeiouAEIOU', str[0])) {
57
+ return `an ${str}`;
58
+ }
59
+ return `a ${str}`;
60
+ };
61
+ freeze(an);
62
+ export { an };
63
+
64
+ /**
65
+ * Like `JSON.stringify` but does not blow up if given a cycle or a bigint.
66
+ * This is not
67
+ * intended to be a serialization to support any useful unserialization,
68
+ * or any programmatic use of the resulting string. The string is intended
69
+ * *only* for showing a human under benign conditions, in order to be
70
+ * informative enough for some
71
+ * logging purposes. As such, this `bestEffortStringify` has an
72
+ * imprecise specification and may change over time.
73
+ *
74
+ * The current `bestEffortStringify` possibly emits too many "seen"
75
+ * markings: Not only for cycles, but also for repeated subtrees by
76
+ * object identity.
77
+ *
78
+ * As a best effort only for diagnostic interpretation by humans,
79
+ * `bestEffortStringify` also turns various cases that normal
80
+ * `JSON.stringify` skips or errors on, like `undefined` or bigints,
81
+ * into strings that convey their meaning. To distinguish this from
82
+ * strings in the input, these synthesized strings always begin and
83
+ * end with square brackets. To distinguish those strings from an
84
+ * input string with square brackets, and input string that starts
85
+ * with an open square bracket `[` is itself placed in square brackets.
86
+ *
87
+ * @param {any} payload
88
+ * @param {(string|number)=} spaces
89
+ * @returns {string}
90
+ */
91
+ const bestEffortStringify = (payload, spaces = undefined) => {
92
+ const seenSet = new Set();
93
+ const replacer = (_, val) => {
94
+ switch (typeof val) {
95
+ case 'object': {
96
+ if (val === null) {
97
+ return null;
98
+ }
99
+ if (setHas(seenSet, val)) {
100
+ return '[Seen]';
101
+ }
102
+ setAdd(seenSet, val);
103
+ if (isError(val)) {
104
+ return `[${val.name}: ${val.message}]`;
105
+ }
106
+ if (toStringTagSymbol in val) {
107
+ // For the built-ins that have or inherit a `Symbol.toStringTag`-named
108
+ // property, most of them inherit the default `toString` method,
109
+ // which will print in a similar manner: `"[object Foo]"` vs
110
+ // `"[Foo]"`. The exceptions are
111
+ // * `Symbol.prototype`, `BigInt.prototype`, `String.prototype`
112
+ // which don't matter to us since we handle primitives
113
+ // separately and we don't care about primitive wrapper objects.
114
+ // * TODO
115
+ // `Date.prototype`, `TypedArray.prototype`.
116
+ // Hmmm, we probably should make special cases for these. We're
117
+ // not using these yet, so it's not urgent. But others will run
118
+ // into these.
119
+ //
120
+ // Once #2018 is closed, the only objects in our code that have or
121
+ // inherit a `Symbol.toStringTag`-named property are remotables
122
+ // or their remote presences.
123
+ // This printing will do a good job for these without
124
+ // violating abstraction layering. This behavior makes sense
125
+ // purely in terms of JavaScript concepts. That's some of the
126
+ // motivation for choosing that representation of remotables
127
+ // and their remote presences in the first place.
128
+ return `[${val[toStringTagSymbol]}]`;
129
+ }
130
+ if (isArray(val)) {
131
+ return val;
132
+ }
133
+ const names = keys(val);
134
+ if (names.length < 2) {
135
+ return val;
136
+ }
137
+ let sorted = true;
138
+ for (let i = 1; i < names.length; i += 1) {
139
+ if (names[i - 1] >= names[i]) {
140
+ sorted = false;
141
+ break;
142
+ }
143
+ }
144
+ if (sorted) {
145
+ return val;
146
+ }
147
+ arraySort(names);
148
+ const entries = arrayMap(names, name => [name, val[name]]);
149
+ return fromEntries(entries);
150
+ }
151
+ case 'function': {
152
+ return `[Function ${val.name || '<anon>'}]`;
153
+ }
154
+ case 'string': {
155
+ if (stringStartsWith(val, '[')) {
156
+ return `[${val}]`;
157
+ }
158
+ return val;
159
+ }
160
+ case 'undefined':
161
+ case 'symbol': {
162
+ return `[${String(val)}]`;
163
+ }
164
+ case 'bigint': {
165
+ return `[${val}n]`;
166
+ }
167
+ case 'number': {
168
+ if (is(val, NaN)) {
169
+ return '[NaN]';
170
+ } else if (val === Infinity) {
171
+ return '[Infinity]';
172
+ } else if (val === -Infinity) {
173
+ return '[-Infinity]';
174
+ }
175
+ return val;
176
+ }
177
+ default: {
178
+ return val;
179
+ }
180
+ }
181
+ };
182
+ try {
183
+ return stringifyJson(payload, replacer, spaces);
184
+ } catch (_err) {
185
+ // Don't do anything more fancy here if there is any
186
+ // chance that might throw, unless you surround that
187
+ // with another try-catch-recovery. For example,
188
+ // the caught thing might be a proxy or other exotic
189
+ // object rather than an error. The proxy might throw
190
+ // whenever it is possible for it to.
191
+ return '[Something that failed to stringify]';
192
+ }
193
+ };
194
+ freeze(bestEffortStringify);
195
+ export { bestEffortStringify };
@@ -0,0 +1,197 @@
1
+ // @ts-check
2
+
3
+ import {
4
+ // Using TypeError minimizes risk of exposing the feral Error constructor
5
+ TypeError,
6
+ apply,
7
+ defineProperty,
8
+ freeze,
9
+ globalThis,
10
+ } from '../commons.js';
11
+ import { loggedErrorHandler as defaultHandler } from './assert.js';
12
+ import { makeCausalConsole } from './console.js';
13
+ import { makeRejectionHandlers } from './unhandled-rejection.js';
14
+
15
+ /**
16
+ * @import {VirtualConsole} from './types.js'
17
+ * @import {GetStackString} from './internal-types.js';
18
+ */
19
+
20
+ const failFast = message => {
21
+ throw TypeError(message);
22
+ };
23
+
24
+ const wrapLogger = (logger, thisArg) =>
25
+ freeze((...args) => apply(logger, thisArg, args));
26
+
27
+ /**
28
+ * Wrap console unless suppressed.
29
+ * At the moment, the console is considered a host power in the start
30
+ * compartment, and not a primordial. Hence it is absent from the whilelist
31
+ * and bypasses the intrinsicsCollector.
32
+ *
33
+ * @param {"safe" | "unsafe"} consoleTaming
34
+ * @param {"platform" | "exit" | "abort" | "report" | "none"} [errorTrapping]
35
+ * @param {"report" | "none"} [unhandledRejectionTrapping]
36
+ * @param {GetStackString=} optGetStackString
37
+ */
38
+ export const tameConsole = (
39
+ consoleTaming = 'safe',
40
+ errorTrapping = 'platform',
41
+ unhandledRejectionTrapping = 'report',
42
+ optGetStackString = undefined,
43
+ ) => {
44
+ let loggedErrorHandler;
45
+ if (optGetStackString === undefined) {
46
+ loggedErrorHandler = defaultHandler;
47
+ } else {
48
+ loggedErrorHandler = {
49
+ ...defaultHandler,
50
+ getStackString: optGetStackString,
51
+ };
52
+ }
53
+
54
+ // eslint-disable-next-line no-restricted-globals
55
+ const originalConsole = /** @type {VirtualConsole} */ (
56
+ // eslint-disable-next-line no-nested-ternary
57
+ typeof globalThis.console !== 'undefined'
58
+ ? globalThis.console
59
+ : typeof globalThis.print === 'function'
60
+ ? // Make a good-enough console for eshost (including only functions that
61
+ // log at a specific level with no special argument interpretation).
62
+ // https://console.spec.whatwg.org/#logging
63
+ (p => freeze({ debug: p, log: p, info: p, warn: p, error: p }))(
64
+ // eslint-disable-next-line no-undef
65
+ wrapLogger(globalThis.print),
66
+ )
67
+ : undefined
68
+ );
69
+
70
+ // Upgrade a log-only console (as in `eshost -h SpiderMonkey`).
71
+ if (originalConsole && originalConsole.log) {
72
+ for (const methodName of ['warn', 'error']) {
73
+ if (!originalConsole[methodName]) {
74
+ defineProperty(originalConsole, methodName, {
75
+ value: wrapLogger(originalConsole.log, originalConsole),
76
+ });
77
+ }
78
+ }
79
+ }
80
+
81
+ const ourConsole = /** @type {VirtualConsole} */ (
82
+ consoleTaming === 'unsafe'
83
+ ? originalConsole
84
+ : makeCausalConsole(originalConsole, loggedErrorHandler)
85
+ );
86
+
87
+ // Attach platform-specific error traps such that any error that gets thrown
88
+ // at top-of-turn (the bottom of stack) will get logged by our causal
89
+ // console, revealing the diagnostic information associated with the error,
90
+ // including the stack from when the error was created.
91
+
92
+ // In the following Node.js and web browser cases, `process` and `window` are
93
+ // spelled as `globalThis` properties to avoid the overweaning gaze of
94
+ // Parcel, which dutifully installs an unnecessary `process` shim if we ever
95
+ // utter that. That unnecessary shim forces the whole bundle into sloppy mode,
96
+ // which in turn breaks SES's strict mode invariant.
97
+
98
+ // Disable the polymorphic check for the rest of this file. It's too noisy
99
+ // when dealing with platform APIs.
100
+ /* eslint-disable @endo/no-polymorphic-call */
101
+
102
+ // Node.js
103
+ const globalProcess = globalThis.process || undefined;
104
+ if (
105
+ errorTrapping !== 'none' &&
106
+ typeof globalProcess === 'object' &&
107
+ typeof globalProcess.on === 'function'
108
+ ) {
109
+ let terminate;
110
+ if (errorTrapping === 'platform' || errorTrapping === 'exit') {
111
+ const { exit } = globalProcess;
112
+ // If there is a function-valued process.on but no function-valued process.exit,
113
+ // fail early without caring whether errorTrapping is "platform" only by default.
114
+ typeof exit === 'function' || failFast('missing process.exit');
115
+ terminate = () => exit(globalProcess.exitCode || -1);
116
+ } else if (errorTrapping === 'abort') {
117
+ terminate = globalProcess.abort;
118
+ typeof terminate === 'function' || failFast('missing process.abort');
119
+ }
120
+
121
+ globalProcess.on('uncaughtException', error => {
122
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNCAUGHT_EXCEPTION.md
123
+ ourConsole.error('SES_UNCAUGHT_EXCEPTION:', error);
124
+ if (terminate) {
125
+ terminate();
126
+ }
127
+ });
128
+ }
129
+ if (
130
+ unhandledRejectionTrapping !== 'none' &&
131
+ typeof globalProcess === 'object' &&
132
+ typeof globalProcess.on === 'function'
133
+ ) {
134
+ const handleRejection = reason => {
135
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNHANDLED_REJECTION.md
136
+ ourConsole.error('SES_UNHANDLED_REJECTION:', reason);
137
+ // 'platform' and 'report' just log the reason.
138
+ };
139
+ // Maybe track unhandled promise rejections.
140
+ const h = makeRejectionHandlers(handleRejection);
141
+ if (h) {
142
+ // Rejection handlers are supported.
143
+ globalProcess.on('unhandledRejection', h.unhandledRejectionHandler);
144
+ globalProcess.on('rejectionHandled', h.rejectionHandledHandler);
145
+ globalProcess.on('exit', h.processTerminationHandler);
146
+ }
147
+ }
148
+
149
+ // Browser
150
+ const globalWindow = globalThis.window || undefined;
151
+ if (
152
+ errorTrapping !== 'none' &&
153
+ typeof globalWindow === 'object' &&
154
+ typeof globalWindow.addEventListener === 'function'
155
+ ) {
156
+ globalWindow.addEventListener('error', event => {
157
+ event.preventDefault();
158
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNCAUGHT_EXCEPTION.md
159
+ ourConsole.error('SES_UNCAUGHT_EXCEPTION:', event.error);
160
+ // 'platform' and 'report' just log the reason.
161
+ if (errorTrapping === 'exit' || errorTrapping === 'abort') {
162
+ globalWindow.location.href = `about:blank`;
163
+ }
164
+ });
165
+ }
166
+ if (
167
+ unhandledRejectionTrapping !== 'none' &&
168
+ typeof globalWindow === 'object' &&
169
+ typeof globalWindow.addEventListener === 'function'
170
+ ) {
171
+ const handleRejection = reason => {
172
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNHANDLED_REJECTION.md
173
+ ourConsole.error('SES_UNHANDLED_REJECTION:', reason);
174
+ };
175
+
176
+ const h = makeRejectionHandlers(handleRejection);
177
+ if (h) {
178
+ // Rejection handlers are supported.
179
+ globalWindow.addEventListener('unhandledrejection', event => {
180
+ event.preventDefault();
181
+ h.unhandledRejectionHandler(event.reason, event.promise);
182
+ });
183
+
184
+ globalWindow.addEventListener('rejectionhandled', event => {
185
+ event.preventDefault();
186
+ h.rejectionHandledHandler(event.promise);
187
+ });
188
+
189
+ globalWindow.addEventListener('beforeunload', _event => {
190
+ h.processTerminationHandler();
191
+ });
192
+ }
193
+ }
194
+ /* eslint-enable @endo/no-polymorphic-call */
195
+
196
+ return { console: ourConsole };
197
+ };