@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.
- package/LICENSE +661 -0
- package/README.md +29 -0
- package/build.config.ts +22 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/index.d.ts +15 -0
- package/dist/client/index.js +10 -0
- package/dist/externalVersion.js +21 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +61 -0
- package/dist/locale/index.d.ts +141 -0
- package/dist/locale/index.js +79 -0
- package/dist/locale/zh-CN.json +61 -0
- package/dist/node_modules/ses/LICENSE +201 -0
- package/dist/node_modules/ses/LICENSE-aura +16 -0
- package/dist/node_modules/ses/LICENSE-caja +13 -0
- package/dist/node_modules/ses/LICENSE-corejs +19 -0
- package/dist/node_modules/ses/LICENSE-v8 +9 -0
- package/dist/node_modules/ses/assert-shim.js +1 -0
- package/dist/node_modules/ses/compartment-shim.js +1 -0
- package/dist/node_modules/ses/console-shim.js +1 -0
- package/dist/node_modules/ses/dist/lockdown.cjs +13912 -0
- package/dist/node_modules/ses/dist/lockdown.umd.js +13912 -0
- package/dist/node_modules/ses/dist/lockdown.umd.min.js +1 -0
- package/dist/node_modules/ses/dist/ses-hermes.cjs +13912 -0
- package/dist/node_modules/ses/dist/ses.cjs +1 -0
- package/dist/node_modules/ses/dist/ses.umd.js +13912 -0
- package/dist/node_modules/ses/dist/ses.umd.min.js +1 -0
- package/dist/node_modules/ses/dist/types.d.cts +606 -0
- package/dist/node_modules/ses/index.js +18 -0
- package/dist/node_modules/ses/lockdown-shim.js +1 -0
- package/dist/node_modules/ses/lockdown.js +1 -0
- package/dist/node_modules/ses/package.json +1 -0
- package/dist/node_modules/ses/src/assert-shim.js +4 -0
- package/dist/node_modules/ses/src/assert-sloppy-mode.js +11 -0
- package/dist/node_modules/ses/src/cauterize-property.js +69 -0
- package/dist/node_modules/ses/src/commons.js +425 -0
- package/dist/node_modules/ses/src/compartment-evaluate.js +93 -0
- package/dist/node_modules/ses/src/compartment-shim.js +22 -0
- package/dist/node_modules/ses/src/compartment.js +477 -0
- package/dist/node_modules/ses/src/console-shim.js +50 -0
- package/dist/node_modules/ses/src/enable-property-overrides.js +211 -0
- package/dist/node_modules/ses/src/enablements.js +244 -0
- package/dist/node_modules/ses/src/error/assert.js +584 -0
- package/dist/node_modules/ses/src/error/console.js +541 -0
- package/dist/node_modules/ses/src/error/fatal-assert.js +54 -0
- package/dist/node_modules/ses/src/error/internal-types.js +98 -0
- package/dist/node_modules/ses/src/error/note-log-args.js +77 -0
- package/dist/node_modules/ses/src/error/stringify-utils.js +195 -0
- package/dist/node_modules/ses/src/error/tame-console.js +197 -0
- package/dist/node_modules/ses/src/error/tame-error-constructor.js +284 -0
- package/dist/node_modules/ses/src/error/tame-v8-error-constructor.js +386 -0
- package/dist/node_modules/ses/src/error/types.js +59 -0
- package/dist/node_modules/ses/src/error/unhandled-rejection.js +122 -0
- package/dist/node_modules/ses/src/eval-scope.js +89 -0
- package/dist/node_modules/ses/src/get-anonymous-intrinsics.js +181 -0
- package/dist/node_modules/ses/src/get-source-url.js +50 -0
- package/dist/node_modules/ses/src/global-object.js +175 -0
- package/dist/node_modules/ses/src/intrinsics.js +192 -0
- package/dist/node_modules/ses/src/lockdown-shim.js +37 -0
- package/dist/node_modules/ses/src/lockdown.js +558 -0
- package/dist/node_modules/ses/src/make-eval-function.js +28 -0
- package/dist/node_modules/ses/src/make-evaluate.js +110 -0
- package/dist/node_modules/ses/src/make-function-constructor.js +79 -0
- package/dist/node_modules/ses/src/make-hardener.js +275 -0
- package/dist/node_modules/ses/src/make-safe-evaluator.js +112 -0
- package/dist/node_modules/ses/src/module-instance.js +497 -0
- package/dist/node_modules/ses/src/module-link.js +159 -0
- package/dist/node_modules/ses/src/module-load.js +719 -0
- package/dist/node_modules/ses/src/module-proxy.js +200 -0
- package/dist/node_modules/ses/src/permits-intrinsics.js +291 -0
- package/dist/node_modules/ses/src/permits.js +1761 -0
- package/dist/node_modules/ses/src/reporting-types.d.ts +13 -0
- package/dist/node_modules/ses/src/reporting.js +105 -0
- package/dist/node_modules/ses/src/scope-constants.js +180 -0
- package/dist/node_modules/ses/src/shim-arraybuffer-transfer.js +85 -0
- package/dist/node_modules/ses/src/sloppy-globals-scope-terminator.js +61 -0
- package/dist/node_modules/ses/src/strict-scope-terminator.js +99 -0
- package/dist/node_modules/ses/src/tame-date-constructor.js +127 -0
- package/dist/node_modules/ses/src/tame-domains.js +41 -0
- package/dist/node_modules/ses/src/tame-faux-data-properties.js +210 -0
- package/dist/node_modules/ses/src/tame-function-constructors.js +140 -0
- package/dist/node_modules/ses/src/tame-function-tostring.js +50 -0
- package/dist/node_modules/ses/src/tame-harden.js +29 -0
- package/dist/node_modules/ses/src/tame-locale-methods.js +78 -0
- package/dist/node_modules/ses/src/tame-math-object.js +41 -0
- package/dist/node_modules/ses/src/tame-module-source.js +51 -0
- package/dist/node_modules/ses/src/tame-regenerator-runtime.js +29 -0
- package/dist/node_modules/ses/src/tame-regexp-constructor.js +65 -0
- package/dist/node_modules/ses/src/tame-symbol-constructor.js +64 -0
- package/dist/node_modules/ses/src/transforms.js +267 -0
- package/dist/node_modules/ses/tools.js +25 -0
- package/dist/node_modules/ses/types.d.ts +606 -0
- package/dist/server/actions/ui-schema-action.d.ts +27 -0
- package/dist/server/actions/ui-schema-action.js +118 -0
- package/dist/server/collections/flowModelTreePath.d.ts +11 -0
- package/dist/server/collections/flowModelTreePath.js +74 -0
- package/dist/server/collections/flowModels.d.ts +11 -0
- package/dist/server/collections/flowModels.js +57 -0
- package/dist/server/collections/flowsql.d.ts +10 -0
- package/dist/server/collections/flowsql.js +51 -0
- package/dist/server/dao/ui_schema_node_dao.d.ts +26 -0
- package/dist/server/dao/ui_schema_node_dao.js +24 -0
- package/dist/server/helper.d.ts +8 -0
- package/dist/server/helper.js +9 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.js +42 -0
- package/dist/server/model.d.ts +12 -0
- package/dist/server/model.js +38 -0
- package/dist/server/plugin.d.ts +26 -0
- package/dist/server/plugin.js +270 -0
- package/dist/server/repository.d.ts +116 -0
- package/dist/server/repository.js +1209 -0
- package/dist/server/server.d.ts +16 -0
- package/dist/server/server.js +198 -0
- package/dist/server/template/contexts.d.ts +73 -0
- package/dist/server/template/contexts.js +233 -0
- package/dist/server/template/resolver.d.ts +30 -0
- package/dist/server/template/resolver.js +225 -0
- package/dist/server/variables/registry.d.ts +42 -0
- package/dist/server/variables/registry.js +299 -0
- package/package.json +28 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { hasOwn } from './commons.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @import {Reporter} from './reporting-types.js'
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Delete `obj[prop]` or at least make it harmless.
|
|
9
|
+
*
|
|
10
|
+
* If the property was not expected, then emit a reporter-dependent warning
|
|
11
|
+
* to bring attention to this case, so someone can determine what to do with it.
|
|
12
|
+
*
|
|
13
|
+
* If the property to be deleted is a function's `.prototype` property, this
|
|
14
|
+
* will normally be because the function was supposed to be a
|
|
15
|
+
* - builtin method or non-constructor function
|
|
16
|
+
* - arrow function
|
|
17
|
+
* - concise method
|
|
18
|
+
*
|
|
19
|
+
* all of whom are not supposed to have a `.prototype` property. Nevertheless,
|
|
20
|
+
* on some platforms (like older versions of Hermes), or as a result of
|
|
21
|
+
* some shim-based mods to the primordials (like core-js?), some of these
|
|
22
|
+
* functions may accidentally be more like `function` functions with
|
|
23
|
+
* an undeletable `.prototype` property. In these cases, if we can
|
|
24
|
+
* set the value of that bogus `.prototype` property to `undefined`,
|
|
25
|
+
* we do so, issuing a warning, rather than failing to initialize ses.
|
|
26
|
+
*
|
|
27
|
+
* @param {object} obj
|
|
28
|
+
* @param {PropertyKey} prop
|
|
29
|
+
* @param {boolean} known If deletion is expected, don't warn
|
|
30
|
+
* @param {string} subPath Used for warning messages
|
|
31
|
+
* @param {Reporter} reporter Where to issue warning or error.
|
|
32
|
+
* @returns {void}
|
|
33
|
+
*/
|
|
34
|
+
export const cauterizeProperty = (
|
|
35
|
+
obj,
|
|
36
|
+
prop,
|
|
37
|
+
known,
|
|
38
|
+
subPath,
|
|
39
|
+
{ warn, error },
|
|
40
|
+
) => {
|
|
41
|
+
// Either the object lacks a permit or the object doesn't match the
|
|
42
|
+
// permit.
|
|
43
|
+
// If the permit is specifically false, not merely undefined,
|
|
44
|
+
// this is a property we expect to see because we know it exists in
|
|
45
|
+
// some environments and we have expressly decided to exclude it.
|
|
46
|
+
// Any other disallowed property is one we have not audited and we log
|
|
47
|
+
// that we are removing it so we know to look into it, as happens when
|
|
48
|
+
// the language evolves new features to existing intrinsics.
|
|
49
|
+
if (!known) {
|
|
50
|
+
warn(`Removing ${subPath}`);
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
delete obj[prop];
|
|
54
|
+
} catch (err) {
|
|
55
|
+
if (hasOwn(obj, prop)) {
|
|
56
|
+
if (typeof obj === 'function' && prop === 'prototype') {
|
|
57
|
+
obj.prototype = undefined;
|
|
58
|
+
if (obj.prototype === undefined) {
|
|
59
|
+
warn(`Tolerating undeletable ${subPath} === undefined`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
error(`failed to delete ${subPath}`, err);
|
|
64
|
+
} else {
|
|
65
|
+
error(`deleting ${subPath} threw`, err);
|
|
66
|
+
}
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Captures native intrinsics during initialization, so vetted shims
|
|
3
|
+
* (running between initialization of SES and calling lockdown) are free to
|
|
4
|
+
* modify the environment without compromising the integrity of SES. For
|
|
5
|
+
* example, a vetted shim can modify Object.assign because we capture and
|
|
6
|
+
* export Object and assign here, then never again consult Object to get its
|
|
7
|
+
* assign property.
|
|
8
|
+
*
|
|
9
|
+
* This pattern of use is enforced by eslint rules no-restricted-globals and
|
|
10
|
+
* no-polymorphic-call.
|
|
11
|
+
* We maintain the list of restricted globals in ../package.json.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/* global globalThis */
|
|
17
|
+
/* eslint-disable no-restricted-globals */
|
|
18
|
+
|
|
19
|
+
// We cannot use globalThis as the local name since it would capture the
|
|
20
|
+
// lexical name.
|
|
21
|
+
const universalThis = globalThis;
|
|
22
|
+
export { universalThis as globalThis };
|
|
23
|
+
|
|
24
|
+
export const {
|
|
25
|
+
Array,
|
|
26
|
+
ArrayBuffer,
|
|
27
|
+
Date,
|
|
28
|
+
FinalizationRegistry,
|
|
29
|
+
Float32Array,
|
|
30
|
+
JSON,
|
|
31
|
+
Map,
|
|
32
|
+
Math,
|
|
33
|
+
Number,
|
|
34
|
+
Object,
|
|
35
|
+
Promise,
|
|
36
|
+
Proxy,
|
|
37
|
+
Reflect,
|
|
38
|
+
RegExp: FERAL_REG_EXP,
|
|
39
|
+
Set,
|
|
40
|
+
String,
|
|
41
|
+
Symbol,
|
|
42
|
+
Uint8Array,
|
|
43
|
+
WeakMap,
|
|
44
|
+
WeakSet,
|
|
45
|
+
} = globalThis;
|
|
46
|
+
|
|
47
|
+
export const {
|
|
48
|
+
// The feral Error constructor is safe for internal use, but must not be
|
|
49
|
+
// revealed to post-lockdown code in any compartment including the start
|
|
50
|
+
// compartment since in V8 at least it bears stack inspection capabilities.
|
|
51
|
+
Error: FERAL_ERROR,
|
|
52
|
+
RangeError,
|
|
53
|
+
ReferenceError,
|
|
54
|
+
SyntaxError,
|
|
55
|
+
TypeError,
|
|
56
|
+
AggregateError,
|
|
57
|
+
} = globalThis;
|
|
58
|
+
|
|
59
|
+
export const {
|
|
60
|
+
assign,
|
|
61
|
+
create,
|
|
62
|
+
defineProperties,
|
|
63
|
+
entries,
|
|
64
|
+
freeze,
|
|
65
|
+
getOwnPropertyDescriptor,
|
|
66
|
+
getOwnPropertyDescriptors,
|
|
67
|
+
getOwnPropertyNames,
|
|
68
|
+
getPrototypeOf,
|
|
69
|
+
is,
|
|
70
|
+
isFrozen,
|
|
71
|
+
isSealed,
|
|
72
|
+
isExtensible,
|
|
73
|
+
keys,
|
|
74
|
+
prototype: objectPrototype,
|
|
75
|
+
seal,
|
|
76
|
+
preventExtensions,
|
|
77
|
+
setPrototypeOf,
|
|
78
|
+
values,
|
|
79
|
+
fromEntries,
|
|
80
|
+
hasOwn,
|
|
81
|
+
} = Object;
|
|
82
|
+
|
|
83
|
+
export const {
|
|
84
|
+
species: speciesSymbol,
|
|
85
|
+
toStringTag: toStringTagSymbol,
|
|
86
|
+
iterator: iteratorSymbol,
|
|
87
|
+
matchAll: matchAllSymbol,
|
|
88
|
+
unscopables: unscopablesSymbol,
|
|
89
|
+
keyFor: symbolKeyFor,
|
|
90
|
+
for: symbolFor,
|
|
91
|
+
} = Symbol;
|
|
92
|
+
|
|
93
|
+
export const { isInteger } = Number;
|
|
94
|
+
|
|
95
|
+
export const { stringify: stringifyJson } = JSON;
|
|
96
|
+
|
|
97
|
+
// Needed only for the Safari bug workaround below
|
|
98
|
+
const { defineProperty: originalDefineProperty } = Object;
|
|
99
|
+
|
|
100
|
+
export const defineProperty = (object, prop, descriptor) => {
|
|
101
|
+
// We used to do the following, until we had to reopen Safari bug
|
|
102
|
+
// https://bugs.webkit.org/show_bug.cgi?id=222538#c17
|
|
103
|
+
// Once this is fixed, we may restore it.
|
|
104
|
+
// // Object.defineProperty is allowed to fail silently so we use
|
|
105
|
+
// // Object.defineProperties instead.
|
|
106
|
+
// return defineProperties(object, { [prop]: descriptor });
|
|
107
|
+
|
|
108
|
+
// Instead, to workaround the Safari bug
|
|
109
|
+
const result = originalDefineProperty(object, prop, descriptor);
|
|
110
|
+
if (result !== object) {
|
|
111
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DEFINE_PROPERTY_FAILED_SILENTLY.md
|
|
112
|
+
throw TypeError(
|
|
113
|
+
`Please report that the original defineProperty silently failed to set ${stringifyJson(
|
|
114
|
+
String(prop),
|
|
115
|
+
)}. (SES_DEFINE_PROPERTY_FAILED_SILENTLY)`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const {
|
|
122
|
+
apply,
|
|
123
|
+
construct,
|
|
124
|
+
get: reflectGet,
|
|
125
|
+
getOwnPropertyDescriptor: reflectGetOwnPropertyDescriptor,
|
|
126
|
+
has: reflectHas,
|
|
127
|
+
isExtensible: reflectIsExtensible,
|
|
128
|
+
ownKeys,
|
|
129
|
+
preventExtensions: reflectPreventExtensions,
|
|
130
|
+
set: reflectSet,
|
|
131
|
+
} = Reflect;
|
|
132
|
+
|
|
133
|
+
export const { isArray, prototype: arrayPrototype } = Array;
|
|
134
|
+
export const { prototype: arrayBufferPrototype } = ArrayBuffer;
|
|
135
|
+
export const { prototype: mapPrototype } = Map;
|
|
136
|
+
export const { revocable: proxyRevocable } = Proxy;
|
|
137
|
+
export const { prototype: regexpPrototype } = RegExp;
|
|
138
|
+
export const { prototype: setPrototype } = Set;
|
|
139
|
+
export const { prototype: stringPrototype } = String;
|
|
140
|
+
export const { prototype: weakmapPrototype } = WeakMap;
|
|
141
|
+
export const { prototype: weaksetPrototype } = WeakSet;
|
|
142
|
+
export const { prototype: functionPrototype } = Function;
|
|
143
|
+
export const { prototype: promisePrototype } = Promise;
|
|
144
|
+
export const { prototype: generatorPrototype } = getPrototypeOf(
|
|
145
|
+
// eslint-disable-next-line no-empty-function, func-names
|
|
146
|
+
function* () {},
|
|
147
|
+
);
|
|
148
|
+
export const iteratorPrototype = getPrototypeOf(
|
|
149
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
150
|
+
getPrototypeOf(arrayPrototype.values()),
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
export const typedArrayPrototype = getPrototypeOf(Uint8Array.prototype);
|
|
154
|
+
|
|
155
|
+
const { bind } = functionPrototype;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* uncurryThis()
|
|
159
|
+
* Equivalent of: fn => (thisArg, ...args) => apply(fn, thisArg, args)
|
|
160
|
+
*
|
|
161
|
+
* See those reference for a complete explanation:
|
|
162
|
+
* http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programming
|
|
163
|
+
* which only lives at
|
|
164
|
+
* http://web.archive.org/web/20160805225710/http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programming
|
|
165
|
+
*
|
|
166
|
+
* @type {<F extends (this: any, ...args: any[]) => any>(fn: F) => ((thisArg: ThisParameterType<F>, ...args: Parameters<F>) => ReturnType<F>)}
|
|
167
|
+
*/
|
|
168
|
+
export const uncurryThis = bind.bind(bind.call); // eslint-disable-line @endo/no-polymorphic-call
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @deprecated Use `hasOwn` instead
|
|
172
|
+
*/
|
|
173
|
+
export const objectHasOwnProperty = hasOwn;
|
|
174
|
+
//
|
|
175
|
+
export const arrayFilter = uncurryThis(arrayPrototype.filter);
|
|
176
|
+
export const arrayForEach = uncurryThis(arrayPrototype.forEach);
|
|
177
|
+
export const arrayIncludes = uncurryThis(arrayPrototype.includes);
|
|
178
|
+
export const arrayJoin = uncurryThis(arrayPrototype.join);
|
|
179
|
+
/** @type {<T, U>(thisArg: readonly T[], callbackfn: (value: T, index: number, array: T[]) => U, cbThisArg?: any) => U[]} */
|
|
180
|
+
export const arrayMap = /** @type {any} */ (uncurryThis(arrayPrototype.map));
|
|
181
|
+
export const arrayFlatMap = /** @type {any} */ (
|
|
182
|
+
uncurryThis(arrayPrototype.flatMap)
|
|
183
|
+
);
|
|
184
|
+
export const arrayPop = uncurryThis(arrayPrototype.pop);
|
|
185
|
+
/** @type {<T>(thisArg: T[], ...items: T[]) => number} */
|
|
186
|
+
export const arrayPush = uncurryThis(arrayPrototype.push);
|
|
187
|
+
export const arraySlice = uncurryThis(arrayPrototype.slice);
|
|
188
|
+
export const arraySome = uncurryThis(arrayPrototype.some);
|
|
189
|
+
export const arraySort = uncurryThis(arrayPrototype.sort);
|
|
190
|
+
export const iterateArray = uncurryThis(arrayPrototype[iteratorSymbol]);
|
|
191
|
+
//
|
|
192
|
+
export const arrayBufferSlice = uncurryThis(arrayBufferPrototype.slice);
|
|
193
|
+
/** @type {(b: ArrayBuffer) => number} */
|
|
194
|
+
export const arrayBufferGetByteLength = uncurryThis(
|
|
195
|
+
// @ts-expect-error we know it is there on all conforming platforms
|
|
196
|
+
getOwnPropertyDescriptor(arrayBufferPrototype, 'byteLength').get,
|
|
197
|
+
);
|
|
198
|
+
//
|
|
199
|
+
export const typedArraySet = uncurryThis(typedArrayPrototype.set);
|
|
200
|
+
//
|
|
201
|
+
export const mapSet = uncurryThis(mapPrototype.set);
|
|
202
|
+
export const mapGet = uncurryThis(mapPrototype.get);
|
|
203
|
+
export const mapHas = uncurryThis(mapPrototype.has);
|
|
204
|
+
export const mapDelete = uncurryThis(mapPrototype.delete);
|
|
205
|
+
export const mapEntries = uncurryThis(mapPrototype.entries);
|
|
206
|
+
export const iterateMap = uncurryThis(mapPrototype[iteratorSymbol]);
|
|
207
|
+
//
|
|
208
|
+
export const setAdd = uncurryThis(setPrototype.add);
|
|
209
|
+
export const setDelete = uncurryThis(setPrototype.delete);
|
|
210
|
+
export const setForEach = uncurryThis(setPrototype.forEach);
|
|
211
|
+
export const setHas = uncurryThis(setPrototype.has);
|
|
212
|
+
export const iterateSet = uncurryThis(setPrototype[iteratorSymbol]);
|
|
213
|
+
//
|
|
214
|
+
export const regexpTest = uncurryThis(regexpPrototype.test);
|
|
215
|
+
export const regexpExec = uncurryThis(regexpPrototype.exec);
|
|
216
|
+
export const matchAllRegExp = uncurryThis(regexpPrototype[matchAllSymbol]);
|
|
217
|
+
//
|
|
218
|
+
export const stringEndsWith = uncurryThis(stringPrototype.endsWith);
|
|
219
|
+
export const stringIncludes = uncurryThis(stringPrototype.includes);
|
|
220
|
+
export const stringIndexOf = uncurryThis(stringPrototype.indexOf);
|
|
221
|
+
export const stringMatch = uncurryThis(stringPrototype.match);
|
|
222
|
+
export const generatorNext = uncurryThis(generatorPrototype.next);
|
|
223
|
+
export const generatorThrow = uncurryThis(generatorPrototype.throw);
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @type { &
|
|
227
|
+
* ((thisArg: string, searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string) => string) &
|
|
228
|
+
* ((thisArg: string, searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string) => string)
|
|
229
|
+
* }
|
|
230
|
+
*/
|
|
231
|
+
export const stringReplace = /** @type {any} */ (
|
|
232
|
+
uncurryThis(stringPrototype.replace)
|
|
233
|
+
);
|
|
234
|
+
export const stringSearch = uncurryThis(stringPrototype.search);
|
|
235
|
+
export const stringSlice = uncurryThis(stringPrototype.slice);
|
|
236
|
+
export const stringSplit =
|
|
237
|
+
/** @type {(thisArg: string, splitter: string | RegExp | { [Symbol.split](string: string, limit?: number): string[]; }, limit?: number) => string[]} */ (
|
|
238
|
+
uncurryThis(stringPrototype.split)
|
|
239
|
+
);
|
|
240
|
+
export const stringStartsWith = uncurryThis(stringPrototype.startsWith);
|
|
241
|
+
export const iterateString = uncurryThis(stringPrototype[iteratorSymbol]);
|
|
242
|
+
//
|
|
243
|
+
export const weakmapDelete = uncurryThis(weakmapPrototype.delete);
|
|
244
|
+
/** @type {<K extends {}, V>(thisArg: WeakMap<K, V>, ...args: Parameters<WeakMap<K,V>['get']>) => ReturnType<WeakMap<K,V>['get']>} */
|
|
245
|
+
export const weakmapGet = uncurryThis(weakmapPrototype.get);
|
|
246
|
+
export const weakmapHas = uncurryThis(weakmapPrototype.has);
|
|
247
|
+
export const weakmapSet = uncurryThis(weakmapPrototype.set);
|
|
248
|
+
//
|
|
249
|
+
export const weaksetAdd = uncurryThis(weaksetPrototype.add);
|
|
250
|
+
export const weaksetHas = uncurryThis(weaksetPrototype.has);
|
|
251
|
+
//
|
|
252
|
+
export const functionToString = uncurryThis(functionPrototype.toString);
|
|
253
|
+
export const functionBind = uncurryThis(bind);
|
|
254
|
+
//
|
|
255
|
+
const { all } = Promise;
|
|
256
|
+
export const promiseAll = promises => apply(all, Promise, [promises]);
|
|
257
|
+
export const promiseCatch = uncurryThis(promisePrototype.catch);
|
|
258
|
+
/** @type {<T, TResult1 = T, TResult2 = never>(thisArg: T, onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null) => Promise<TResult1 | TResult2>} */
|
|
259
|
+
export const promiseThen = /** @type {any} */ (
|
|
260
|
+
uncurryThis(promisePrototype.then)
|
|
261
|
+
);
|
|
262
|
+
//
|
|
263
|
+
export const finalizationRegistryRegister =
|
|
264
|
+
FinalizationRegistry && uncurryThis(FinalizationRegistry.prototype.register);
|
|
265
|
+
export const finalizationRegistryUnregister =
|
|
266
|
+
FinalizationRegistry &&
|
|
267
|
+
uncurryThis(FinalizationRegistry.prototype.unregister);
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* getConstructorOf()
|
|
271
|
+
* Return the constructor from an instance.
|
|
272
|
+
*
|
|
273
|
+
* @param {Function} fn
|
|
274
|
+
*/
|
|
275
|
+
export const getConstructorOf = fn =>
|
|
276
|
+
reflectGet(getPrototypeOf(fn), 'constructor');
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* TODO Consolidate with `isPrimitive` that's currently in `@endo/pass-style`.
|
|
280
|
+
* Layering constraints make this tricky, which is why we haven't yet figured
|
|
281
|
+
* out how to do this.
|
|
282
|
+
*
|
|
283
|
+
* @type {(val: unknown) => val is (undefined
|
|
284
|
+
* | null
|
|
285
|
+
* | boolean
|
|
286
|
+
* | number
|
|
287
|
+
* | bigint
|
|
288
|
+
* | string
|
|
289
|
+
* | symbol)}
|
|
290
|
+
*/
|
|
291
|
+
export const isPrimitive = val =>
|
|
292
|
+
!val || (typeof val !== 'object' && typeof val !== 'function');
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* isError tests whether an object inherits from the intrinsic
|
|
296
|
+
* `Error.prototype`.
|
|
297
|
+
* We capture the original error constructor as FERAL_ERROR to provide a clear
|
|
298
|
+
* signal for reviewers that we are handling an object with excess authority,
|
|
299
|
+
* like stack trace inspection, that we are carefully hiding from client code.
|
|
300
|
+
* Checking instanceof happens to be safe, but to avoid uttering FERAL_ERROR
|
|
301
|
+
* for such a trivial case outside commons.js, we provide a utility function.
|
|
302
|
+
*
|
|
303
|
+
* @param {any} value
|
|
304
|
+
*/
|
|
305
|
+
export const isError = value => value instanceof FERAL_ERROR;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* @template T
|
|
309
|
+
* @param {T} x
|
|
310
|
+
*/
|
|
311
|
+
export const identity = x => x;
|
|
312
|
+
|
|
313
|
+
// The original unsafe untamed eval function, which must not escape.
|
|
314
|
+
// Sample at module initialization time, which is before lockdown can
|
|
315
|
+
// repair it. Use it only to build powerless abstractions.
|
|
316
|
+
// eslint-disable-next-line no-eval
|
|
317
|
+
export const FERAL_EVAL = eval;
|
|
318
|
+
|
|
319
|
+
// The original unsafe untamed Function constructor, which must not escape.
|
|
320
|
+
// Sample at module initialization time, which is before lockdown can
|
|
321
|
+
// repair it. Use it only to build powerless abstractions.
|
|
322
|
+
export const FERAL_FUNCTION = Function;
|
|
323
|
+
|
|
324
|
+
export const noEvalEvaluate = () => {
|
|
325
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
|
|
326
|
+
throw TypeError('Cannot eval with evalTaming set to "no-eval" (SES_NO_EVAL)');
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// ////////////////// FERAL_STACK_GETTER FERAL_STACK_SETTER ////////////////////
|
|
330
|
+
|
|
331
|
+
const er1StackDesc = getOwnPropertyDescriptor(Error('er1'), 'stack');
|
|
332
|
+
const er2StackDesc = getOwnPropertyDescriptor(TypeError('er2'), 'stack');
|
|
333
|
+
|
|
334
|
+
let feralStackGetter;
|
|
335
|
+
let feralStackSetter;
|
|
336
|
+
if (er1StackDesc && er2StackDesc && er1StackDesc.get) {
|
|
337
|
+
// We should only encounter this case on v8 because of its problematic
|
|
338
|
+
// error own stack accessor behavior.
|
|
339
|
+
// Note that FF/SpiderMonkey, Moddable/XS, and the error stack proposal
|
|
340
|
+
// all inherit a stack accessor property from Error.prototype, which is
|
|
341
|
+
// great. That case needs no heroics to secure.
|
|
342
|
+
if (
|
|
343
|
+
// In the v8 case as we understand it, all errors have an own stack
|
|
344
|
+
// accessor property, but within the same realm, all these accessor
|
|
345
|
+
// properties have the same getter and have the same setter.
|
|
346
|
+
// This is therefore the case that we repair.
|
|
347
|
+
typeof er1StackDesc.get === 'function' &&
|
|
348
|
+
er1StackDesc.get === er2StackDesc.get &&
|
|
349
|
+
typeof er1StackDesc.set === 'function' &&
|
|
350
|
+
er1StackDesc.set === er2StackDesc.set
|
|
351
|
+
) {
|
|
352
|
+
// Otherwise, we have own stack accessor properties that are outside
|
|
353
|
+
// our expectations, that therefore need to be understood better
|
|
354
|
+
// before we know how to repair them.
|
|
355
|
+
feralStackGetter = freeze(er1StackDesc.get);
|
|
356
|
+
feralStackSetter = freeze(er1StackDesc.set);
|
|
357
|
+
} else {
|
|
358
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNEXPECTED_ERROR_OWN_STACK_ACCESSOR.md
|
|
359
|
+
throw TypeError(
|
|
360
|
+
'Unexpected Error own stack accessor functions (SES_UNEXPECTED_ERROR_OWN_STACK_ACCESSOR)',
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* If on a v8 with the problematic error own stack accessor behavior,
|
|
367
|
+
* `FERAL_STACK_GETTER` will be the shared getter of all those accessors
|
|
368
|
+
* and `FERAL_STACK_SETTER` will be the shared setter. On any platform
|
|
369
|
+
* without this problem, `FERAL_STACK_GETTER` and `FERAL_STACK_SETTER` are
|
|
370
|
+
* both `undefined`.
|
|
371
|
+
*
|
|
372
|
+
* @type {(() => any) | undefined}
|
|
373
|
+
*/
|
|
374
|
+
export const FERAL_STACK_GETTER = feralStackGetter;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* If on a v8 with the problematic error own stack accessor behavior,
|
|
378
|
+
* `FERAL_STACK_GETTER` will be the shared getter of all those accessors
|
|
379
|
+
* and `FERAL_STACK_SETTER` will be the shared setter. On any platform
|
|
380
|
+
* without this problem, `FERAL_STACK_GETTER` and `FERAL_STACK_SETTER` are
|
|
381
|
+
* both `undefined`.
|
|
382
|
+
*
|
|
383
|
+
* @type {((newValue: any) => void) | undefined}
|
|
384
|
+
*/
|
|
385
|
+
export const FERAL_STACK_SETTER = feralStackSetter;
|
|
386
|
+
|
|
387
|
+
const getAsyncGeneratorFunctionInstance = () => {
|
|
388
|
+
// Test for async generator function syntax support.
|
|
389
|
+
try {
|
|
390
|
+
// Wrapping one in an new Function lets the `hermesc` binary file
|
|
391
|
+
// parse the Metro js bundle without SyntaxError, to generate the
|
|
392
|
+
// optimised Hermes bytecode bundle, when `gradlew` is called to
|
|
393
|
+
// assemble the release build APK for React Native prod Android apps.
|
|
394
|
+
// Delaying the error until runtime lets us customise lockdown behaviour.
|
|
395
|
+
return new FERAL_FUNCTION(
|
|
396
|
+
'return (async function* AsyncGeneratorFunctionInstance() {})',
|
|
397
|
+
)();
|
|
398
|
+
} catch (error) {
|
|
399
|
+
// Note: `Error.prototype.jsEngine` is only set by React Native runtime, not Hermes:
|
|
400
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp#L224-L230
|
|
401
|
+
if (error.name === 'SyntaxError') {
|
|
402
|
+
// Swallows Hermes error `async generators are unsupported` at runtime.
|
|
403
|
+
// Note: `console` is not a JS built-in, so Hermes engine throws:
|
|
404
|
+
// Uncaught ReferenceError: Property 'console' doesn't exist
|
|
405
|
+
// See: https://github.com/facebook/hermes/issues/675
|
|
406
|
+
// However React Native provides a `console` implementation when setting up error handling:
|
|
407
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/InitializeCore.js
|
|
408
|
+
return undefined;
|
|
409
|
+
} else if (error.name === 'EvalError') {
|
|
410
|
+
// eslint-disable-next-line no-empty-function
|
|
411
|
+
return async function* AsyncGeneratorFunctionInstance() {};
|
|
412
|
+
} else {
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* If the platform supports async generator functions, this will be an
|
|
420
|
+
* async generator function instance. Otherwise, it will be `undefined`.
|
|
421
|
+
*
|
|
422
|
+
* @type {AsyncGeneratorFunction | undefined}
|
|
423
|
+
*/
|
|
424
|
+
export const AsyncGeneratorFunctionInstance =
|
|
425
|
+
getAsyncGeneratorFunctionInstance();
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/// <reference types="ses">
|
|
2
|
+
import {
|
|
3
|
+
TypeError,
|
|
4
|
+
arrayPush,
|
|
5
|
+
create,
|
|
6
|
+
getOwnPropertyDescriptors,
|
|
7
|
+
} from './commons.js';
|
|
8
|
+
import {
|
|
9
|
+
evadeHtmlCommentTest,
|
|
10
|
+
evadeImportExpressionTest,
|
|
11
|
+
rejectSomeDirectEvalExpressions,
|
|
12
|
+
} from './transforms.js';
|
|
13
|
+
import { makeSafeEvaluator } from './make-safe-evaluator.js';
|
|
14
|
+
|
|
15
|
+
export const provideCompartmentEvaluator = (compartmentFields, options) => {
|
|
16
|
+
const { sloppyGlobalsMode = false, __moduleShimLexicals__ = undefined } =
|
|
17
|
+
options;
|
|
18
|
+
|
|
19
|
+
let safeEvaluate;
|
|
20
|
+
|
|
21
|
+
if (__moduleShimLexicals__ === undefined && !sloppyGlobalsMode) {
|
|
22
|
+
({ safeEvaluate } = compartmentFields);
|
|
23
|
+
} else {
|
|
24
|
+
// The scope proxy or global lexicals are different from the
|
|
25
|
+
// shared evaluator so we need to build a new one
|
|
26
|
+
|
|
27
|
+
let { globalTransforms } = compartmentFields;
|
|
28
|
+
const { globalObject } = compartmentFields;
|
|
29
|
+
|
|
30
|
+
let moduleLexicals;
|
|
31
|
+
if (__moduleShimLexicals__ !== undefined) {
|
|
32
|
+
// When using `evaluate` for ESM modules, as should only occur from the
|
|
33
|
+
// module-shim's module-instance.js, we do not reveal the SES-shim's
|
|
34
|
+
// module-to-program translation, as this is not standardizable behavior.
|
|
35
|
+
// However, the `localTransforms` will come from the `__shimTransforms__`
|
|
36
|
+
// Compartment option in this case, which is a non-standardizable escape
|
|
37
|
+
// hatch so programs designed specifically for the SES-shim
|
|
38
|
+
// implementation may opt-in to use the same transforms for `evaluate`
|
|
39
|
+
// and `import`, at the expense of being tightly coupled to SES-shim.
|
|
40
|
+
globalTransforms = undefined;
|
|
41
|
+
|
|
42
|
+
moduleLexicals = create(
|
|
43
|
+
null,
|
|
44
|
+
getOwnPropertyDescriptors(__moduleShimLexicals__),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
({ safeEvaluate } = makeSafeEvaluator({
|
|
49
|
+
globalObject,
|
|
50
|
+
moduleLexicals,
|
|
51
|
+
globalTransforms,
|
|
52
|
+
sloppyGlobalsMode,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { safeEvaluate };
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const compartmentEvaluate = (compartmentFields, source, options) => {
|
|
60
|
+
// Perform this check first to avoid unnecessary sanitizing.
|
|
61
|
+
// TODO Maybe relax string check and coerce instead:
|
|
62
|
+
// https://github.com/tc39/proposal-dynamic-code-brand-checks
|
|
63
|
+
if (typeof source !== 'string') {
|
|
64
|
+
throw TypeError('first argument of evaluate() must be a string');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Extract options, and shallow-clone transforms.
|
|
68
|
+
const {
|
|
69
|
+
transforms = [],
|
|
70
|
+
__evadeHtmlCommentTest__ = false,
|
|
71
|
+
__evadeImportExpressionTest__ = false,
|
|
72
|
+
__rejectSomeDirectEvalExpressions__ = true, // Note default on
|
|
73
|
+
} = options;
|
|
74
|
+
const localTransforms = [...transforms];
|
|
75
|
+
if (__evadeHtmlCommentTest__ === true) {
|
|
76
|
+
arrayPush(localTransforms, evadeHtmlCommentTest);
|
|
77
|
+
}
|
|
78
|
+
if (__evadeImportExpressionTest__ === true) {
|
|
79
|
+
arrayPush(localTransforms, evadeImportExpressionTest);
|
|
80
|
+
}
|
|
81
|
+
if (__rejectSomeDirectEvalExpressions__ === true) {
|
|
82
|
+
arrayPush(localTransforms, rejectSomeDirectEvalExpressions);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const { safeEvaluate } = provideCompartmentEvaluator(
|
|
86
|
+
compartmentFields,
|
|
87
|
+
options,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return safeEvaluate(source, {
|
|
91
|
+
localTransforms,
|
|
92
|
+
});
|
|
93
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { globalThis } from './commons.js';
|
|
2
|
+
import { makeCompartmentConstructor } from './compartment.js';
|
|
3
|
+
import { tameFunctionToString } from './tame-function-tostring.js';
|
|
4
|
+
import { getGlobalIntrinsics } from './intrinsics.js';
|
|
5
|
+
import { chooseReporter } from './reporting.js';
|
|
6
|
+
|
|
7
|
+
const markVirtualizedNativeFunction = tameFunctionToString();
|
|
8
|
+
|
|
9
|
+
const muteReporter = chooseReporter('none');
|
|
10
|
+
|
|
11
|
+
// @ts-ignore Compartment is definitely on globalThis.
|
|
12
|
+
globalThis.Compartment = makeCompartmentConstructor(
|
|
13
|
+
makeCompartmentConstructor,
|
|
14
|
+
// Any reporting that would need to be done should have already been done
|
|
15
|
+
// during `lockdown()`.
|
|
16
|
+
// See https://github.com/endojs/endo/pull/2624#discussion_r1840979770
|
|
17
|
+
getGlobalIntrinsics(globalThis, muteReporter),
|
|
18
|
+
markVirtualizedNativeFunction,
|
|
19
|
+
{
|
|
20
|
+
enforceNew: true,
|
|
21
|
+
},
|
|
22
|
+
);
|