@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,477 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides the mechanism to create a Compartment constructor that
|
|
3
|
+
* can provide either shim-specific or native XS features depending on
|
|
4
|
+
* the __native__ constructor option.
|
|
5
|
+
* This is necessary because a native Compartment can handle native ModuleSource
|
|
6
|
+
* but cannot handle shim-specific pre-compiled ModuleSources like the JSON
|
|
7
|
+
* representation of a module that Compartment Mapper can put in bundles.
|
|
8
|
+
* Pre-compiling ModuleSource during bundling helps avoid paying the cost
|
|
9
|
+
* of importing Babel and transforming ESM syntax to a form that can be
|
|
10
|
+
* confined by the shim, which is prohibitively expensive for a web runtime
|
|
11
|
+
* and for XS _without this adapter_.
|
|
12
|
+
*
|
|
13
|
+
* Since any invocation of the Compartment constructor may occur standing
|
|
14
|
+
* on a native-flavor or shim-flavor compartment, we create parallel compartment
|
|
15
|
+
* constructor trees for compartments created with the Compartment constructor
|
|
16
|
+
* of a specific compartment.
|
|
17
|
+
*
|
|
18
|
+
* A compartment's importHook, importNowHook, moduleMapHook, and the modules
|
|
19
|
+
* map itself may provide module descriptors that address another compartment,
|
|
20
|
+
* using a compartment instance as a token indicating the compartment the
|
|
21
|
+
* module should be loaded or initialized in.
|
|
22
|
+
* Consequently, the compartment instance must be a suitable token for the
|
|
23
|
+
* underlying native-flavor or shim-flavor compartment.
|
|
24
|
+
* We are not in a position to fidddle with the native compartments behavior,
|
|
25
|
+
* so adapted compartments use the identity of the native compartment.
|
|
26
|
+
* We replace all of the methods of the native compartment prototype with
|
|
27
|
+
* thunks that choose behavior based on whether the compartment was
|
|
28
|
+
* constructed with the __native__ option.
|
|
29
|
+
* The SES shim associates a compartment with its private fields using a weak
|
|
30
|
+
* map exported by ../src/compartment.js and held closely by ses by the
|
|
31
|
+
* enforcement of explicit exports in package.json, since Node.js 12.11.0.
|
|
32
|
+
*
|
|
33
|
+
* Evaluating ./compartment.js does not have global side-effects.
|
|
34
|
+
* We defer modification of the global environment until the evaluation
|
|
35
|
+
* of ./compartment-shim.js.
|
|
36
|
+
*
|
|
37
|
+
* @module
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
// @ts-check
|
|
41
|
+
/* eslint-disable no-underscore-dangle */
|
|
42
|
+
|
|
43
|
+
import {
|
|
44
|
+
Map,
|
|
45
|
+
TypeError,
|
|
46
|
+
WeakMap,
|
|
47
|
+
arrayFlatMap,
|
|
48
|
+
assign,
|
|
49
|
+
defineProperties,
|
|
50
|
+
identity,
|
|
51
|
+
promiseThen,
|
|
52
|
+
toStringTagSymbol,
|
|
53
|
+
weakmapGet,
|
|
54
|
+
weakmapSet,
|
|
55
|
+
} from './commons.js';
|
|
56
|
+
import {
|
|
57
|
+
setGlobalObjectSymbolUnscopables,
|
|
58
|
+
setGlobalObjectConstantProperties,
|
|
59
|
+
setGlobalObjectMutableProperties,
|
|
60
|
+
setGlobalObjectEvaluators,
|
|
61
|
+
} from './global-object.js';
|
|
62
|
+
import { assert, assertEqual, q } from './error/assert.js';
|
|
63
|
+
import { sharedGlobalPropertyNames } from './permits.js';
|
|
64
|
+
import { load, loadNow } from './module-load.js';
|
|
65
|
+
import { link } from './module-link.js';
|
|
66
|
+
import { getDeferredExports } from './module-proxy.js';
|
|
67
|
+
import { compartmentEvaluate } from './compartment-evaluate.js';
|
|
68
|
+
import { makeSafeEvaluator } from './make-safe-evaluator.js';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @import {ImportHook, ImportMetaHook, ImportNowHook, ModuleDescriptor, ModuleExportsNamespace, ModuleMap, ModuleMapHook, ResolveHook, ModuleSource, CompartmentOptions} from '../types.js'
|
|
72
|
+
* @import {Transform} from './lockdown.js'
|
|
73
|
+
* @import {DeferredExports} from './module-proxy.js'
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Associates every public module exports namespace with its corresponding
|
|
78
|
+
* compartment and specifier so they can be used to link modules across
|
|
79
|
+
* compartments. The mechanism to thread an alias is to use the
|
|
80
|
+
* {@link Compartment.module} function to obtain the exports namespace of a foreign
|
|
81
|
+
* module and pass it into another compartment's `moduleMap` constructor option
|
|
82
|
+
* @type {WeakMap<ModuleExportsNamespace, Compartment>}
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
const moduleAliases = new WeakMap();
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Private fields for `Compartment` instances
|
|
89
|
+
* @typedef {object} CompartmentFields
|
|
90
|
+
* @property {string} name
|
|
91
|
+
* @property {object} globalObject
|
|
92
|
+
* @property {Array<Transform>} globalTransforms
|
|
93
|
+
* @property {(source: string, options?: {localTransforms?: Array<Transform>}) => void} safeEvaluate
|
|
94
|
+
* @property {ResolveHook} resolveHook
|
|
95
|
+
* @property {ImportHook} importHook
|
|
96
|
+
* @property {ImportNowHook} importNowHook
|
|
97
|
+
* @property {ModuleMap} moduleMap
|
|
98
|
+
* @property {ModuleMapHook} moduleMapHook
|
|
99
|
+
* @property {ImportMetaHook} importMetaHook
|
|
100
|
+
* @property {Map<string, ModuleSource>} moduleRecords
|
|
101
|
+
* @property {Array<Transform>} __shimTransforms__
|
|
102
|
+
* @property {DeferredExports} deferredExports
|
|
103
|
+
* @property {Map<string, ModuleDescriptor>} instances
|
|
104
|
+
* @property {Compartment} [parentCompartment]
|
|
105
|
+
* @property {boolean} noNamespaceBox
|
|
106
|
+
* @property {(fullSpecifier: string) => Promise<ModuleExportsNamespace>} compartmentImport
|
|
107
|
+
* @property {boolean} [noAggregateLoadErrors]
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Captures the private state for each {@link Compartment}
|
|
112
|
+
* @type {WeakMap<Compartment, CompartmentFields>}
|
|
113
|
+
*/
|
|
114
|
+
const privateFields = new WeakMap();
|
|
115
|
+
|
|
116
|
+
export const InertCompartment = function Compartment(
|
|
117
|
+
_endowments = {},
|
|
118
|
+
_modules = {},
|
|
119
|
+
_options = {},
|
|
120
|
+
) {
|
|
121
|
+
throw TypeError(
|
|
122
|
+
'Compartment.prototype.constructor is not a valid constructor.',
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @param {Compartment} compartment
|
|
128
|
+
* @param {string} specifier
|
|
129
|
+
* @returns {{namespace: ModuleExportsNamespace}}
|
|
130
|
+
*/
|
|
131
|
+
const compartmentImportNow = (compartment, specifier) => {
|
|
132
|
+
const { execute, exportsProxy } = link(
|
|
133
|
+
privateFields,
|
|
134
|
+
moduleAliases,
|
|
135
|
+
compartment,
|
|
136
|
+
specifier,
|
|
137
|
+
);
|
|
138
|
+
execute();
|
|
139
|
+
return exportsProxy;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** @type {Compartment & {constructor: typeof InertCompartment}} */
|
|
143
|
+
export const CompartmentPrototype = {
|
|
144
|
+
constructor: InertCompartment,
|
|
145
|
+
|
|
146
|
+
get globalThis() {
|
|
147
|
+
return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
|
|
148
|
+
.globalObject;
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
get name() {
|
|
152
|
+
return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
|
|
153
|
+
.name;
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
evaluate(source, options = {}) {
|
|
157
|
+
const compartmentFields = weakmapGet(privateFields, this);
|
|
158
|
+
return compartmentEvaluate(compartmentFields, source, options);
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
module(specifier) {
|
|
162
|
+
if (typeof specifier !== 'string') {
|
|
163
|
+
throw TypeError('first argument of module() must be a string');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const { exportsProxy } = getDeferredExports(
|
|
167
|
+
this,
|
|
168
|
+
weakmapGet(privateFields, this),
|
|
169
|
+
moduleAliases,
|
|
170
|
+
specifier,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
return exportsProxy;
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
async import(specifier) {
|
|
177
|
+
const { noNamespaceBox, noAggregateLoadErrors } =
|
|
178
|
+
/** @type {CompartmentFields} */ (weakmapGet(privateFields, this));
|
|
179
|
+
|
|
180
|
+
if (typeof specifier !== 'string') {
|
|
181
|
+
throw TypeError('first argument of import() must be a string');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return promiseThen(
|
|
185
|
+
load(privateFields, moduleAliases, this, specifier, {
|
|
186
|
+
noAggregateErrors: noAggregateLoadErrors,
|
|
187
|
+
}),
|
|
188
|
+
() => {
|
|
189
|
+
// The namespace box is a contentious design and likely to be a breaking
|
|
190
|
+
// change in an appropriately numbered future version.
|
|
191
|
+
const namespace = compartmentImportNow(
|
|
192
|
+
/** @type {Compartment} */ (this),
|
|
193
|
+
specifier,
|
|
194
|
+
);
|
|
195
|
+
if (noNamespaceBox) {
|
|
196
|
+
return namespace;
|
|
197
|
+
}
|
|
198
|
+
// Legacy behavior: box the namespace object so that thenable modules
|
|
199
|
+
// do not get coerced into a promise accidentally.
|
|
200
|
+
return { namespace };
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
async load(specifier) {
|
|
206
|
+
if (typeof specifier !== 'string') {
|
|
207
|
+
throw TypeError('first argument of load() must be a string');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const { noAggregateLoadErrors } = /** @type {CompartmentFields} */ (
|
|
211
|
+
weakmapGet(privateFields, this)
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
return load(privateFields, moduleAliases, this, specifier, {
|
|
215
|
+
noAggregateErrors: noAggregateLoadErrors,
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
importNow(specifier) {
|
|
220
|
+
if (typeof specifier !== 'string') {
|
|
221
|
+
throw TypeError('first argument of importNow() must be a string');
|
|
222
|
+
}
|
|
223
|
+
const { noAggregateLoadErrors } = /** @type {CompartmentFields} */ (
|
|
224
|
+
weakmapGet(privateFields, this)
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
loadNow(privateFields, moduleAliases, this, specifier, {
|
|
228
|
+
noAggregateErrors: noAggregateLoadErrors,
|
|
229
|
+
});
|
|
230
|
+
return compartmentImportNow(/** @type {Compartment} */ (this), specifier);
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// This causes `String(new Compartment())` to evaluate to `[object Compartment]`.
|
|
235
|
+
// The descriptor follows the conventions of other globals with @@toStringTag
|
|
236
|
+
// properties, e.g. Math.
|
|
237
|
+
defineProperties(CompartmentPrototype, {
|
|
238
|
+
[toStringTagSymbol]: {
|
|
239
|
+
value: 'Compartment',
|
|
240
|
+
writable: false,
|
|
241
|
+
enumerable: false,
|
|
242
|
+
configurable: true,
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
defineProperties(InertCompartment, {
|
|
247
|
+
prototype: { value: CompartmentPrototype },
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @callback MakeCompartmentConstructor
|
|
252
|
+
* @param {MakeCompartmentConstructor} targetMakeCompartmentConstructor
|
|
253
|
+
* @param {Record<string, any>} intrinsics
|
|
254
|
+
* @param {(object: object) => void} markVirtualizedNativeFunction
|
|
255
|
+
* @param {object} [options]
|
|
256
|
+
* @param {Compartment} [options.parentCompartment]
|
|
257
|
+
* @param {boolean} [options.enforceNew]
|
|
258
|
+
* @returns {Compartment['constructor']}
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* "Options bag"-style `Compartment` constructor arguments.
|
|
263
|
+
* @typedef {[options?: CompartmentOptions & { __options__: true }]} CompartmentOptionsArgs
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Legacy `Compartment` constructor arguments.
|
|
268
|
+
*
|
|
269
|
+
* @deprecated
|
|
270
|
+
* @typedef {[globals?: Map<string, any>, modules?: Map<string, ModuleDescriptor>, options?: CompartmentOptions]} LegacyCompartmentOptionsArgs
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* In order to facilitate migration from the deprecated signature of the
|
|
275
|
+
* compartment constructor,
|
|
276
|
+
*
|
|
277
|
+
* `new Compartent(globals?, modules?, options?)`
|
|
278
|
+
*
|
|
279
|
+
* to the new signature:
|
|
280
|
+
*
|
|
281
|
+
* `new Compartment(options?)`
|
|
282
|
+
*
|
|
283
|
+
* ...where globals and modules are expressed in the options bag instead of
|
|
284
|
+
* positional arguments, this function detects the temporary sigil __options__
|
|
285
|
+
* on the first argument and coerces compartments arguments into a single
|
|
286
|
+
* compartments object.
|
|
287
|
+
* @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
|
|
288
|
+
* @returns {CompartmentOptions}
|
|
289
|
+
*/
|
|
290
|
+
export const compartmentOptions = (...args) => {
|
|
291
|
+
if (args.length === 0) {
|
|
292
|
+
return {};
|
|
293
|
+
}
|
|
294
|
+
if (
|
|
295
|
+
args.length === 1 &&
|
|
296
|
+
typeof args[0] === 'object' &&
|
|
297
|
+
args[0] !== null &&
|
|
298
|
+
'__options__' in args[0]
|
|
299
|
+
) {
|
|
300
|
+
const { __options__, ...options } = args[0];
|
|
301
|
+
assert(
|
|
302
|
+
__options__ === true,
|
|
303
|
+
`Compartment constructor only supports true __options__ sigil, got ${__options__}`,
|
|
304
|
+
);
|
|
305
|
+
return options;
|
|
306
|
+
} else {
|
|
307
|
+
const [
|
|
308
|
+
globals = /** @type {Map<string, any>} */ ({}),
|
|
309
|
+
modules = /** @type {Map<string, ModuleDescriptor>} */ ({}),
|
|
310
|
+
options = {},
|
|
311
|
+
] = /** @type {LegacyCompartmentOptionsArgs} */ (args);
|
|
312
|
+
assertEqual(
|
|
313
|
+
options.modules,
|
|
314
|
+
undefined,
|
|
315
|
+
`Compartment constructor must receive either a module map argument or modules option, not both`,
|
|
316
|
+
);
|
|
317
|
+
assertEqual(
|
|
318
|
+
options.globals,
|
|
319
|
+
undefined,
|
|
320
|
+
`Compartment constructor must receive either globals argument or option, not both`,
|
|
321
|
+
);
|
|
322
|
+
return {
|
|
323
|
+
...options,
|
|
324
|
+
globals,
|
|
325
|
+
modules,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
/** @type {MakeCompartmentConstructor} */
|
|
331
|
+
export const makeCompartmentConstructor = (
|
|
332
|
+
targetMakeCompartmentConstructor,
|
|
333
|
+
intrinsics,
|
|
334
|
+
markVirtualizedNativeFunction,
|
|
335
|
+
{ parentCompartment = undefined, enforceNew = false } = {},
|
|
336
|
+
) => {
|
|
337
|
+
/**
|
|
338
|
+
*
|
|
339
|
+
* @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
|
|
340
|
+
*/
|
|
341
|
+
function Compartment(...args) {
|
|
342
|
+
if (enforceNew && new.target === undefined) {
|
|
343
|
+
throw TypeError(
|
|
344
|
+
"Class constructor Compartment cannot be invoked without 'new'",
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Extract options, and shallow-clone transforms.
|
|
349
|
+
const {
|
|
350
|
+
name = '<unknown>',
|
|
351
|
+
transforms = [],
|
|
352
|
+
__shimTransforms__ = [],
|
|
353
|
+
globals: endowmentsOption = {},
|
|
354
|
+
modules: moduleMapOption = {},
|
|
355
|
+
resolveHook,
|
|
356
|
+
importHook,
|
|
357
|
+
importNowHook,
|
|
358
|
+
moduleMapHook,
|
|
359
|
+
importMetaHook,
|
|
360
|
+
__noNamespaceBox__: noNamespaceBox = false,
|
|
361
|
+
noAggregateLoadErrors = false,
|
|
362
|
+
} = compartmentOptions(...args);
|
|
363
|
+
const globalTransforms = arrayFlatMap(
|
|
364
|
+
[transforms, __shimTransforms__],
|
|
365
|
+
identity,
|
|
366
|
+
);
|
|
367
|
+
const endowments = { __proto__: null, ...endowmentsOption };
|
|
368
|
+
const moduleMap = { __proto__: null, ...moduleMapOption };
|
|
369
|
+
|
|
370
|
+
// Map<FullSpecifier, ModuleCompartmentRecord>
|
|
371
|
+
const moduleRecords = new Map();
|
|
372
|
+
// Map<FullSpecifier, ModuleInstance>
|
|
373
|
+
const instances = new Map();
|
|
374
|
+
// Map<FullSpecifier, {ExportsProxy, ProxiedExports, activate()}>
|
|
375
|
+
const deferredExports = new Map();
|
|
376
|
+
|
|
377
|
+
const globalObject = {};
|
|
378
|
+
|
|
379
|
+
const compartment = this;
|
|
380
|
+
|
|
381
|
+
setGlobalObjectSymbolUnscopables(globalObject);
|
|
382
|
+
|
|
383
|
+
// We must initialize all constant properties first because
|
|
384
|
+
// `makeSafeEvaluator` may use them to create optimized bindings
|
|
385
|
+
// in the evaluator.
|
|
386
|
+
// TODO: consider merging into a single initialization if internal
|
|
387
|
+
// evaluator is no longer eagerly created
|
|
388
|
+
setGlobalObjectConstantProperties(globalObject);
|
|
389
|
+
|
|
390
|
+
const { safeEvaluate } = makeSafeEvaluator({
|
|
391
|
+
globalObject,
|
|
392
|
+
globalTransforms,
|
|
393
|
+
sloppyGlobalsMode: false,
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
setGlobalObjectMutableProperties(globalObject, {
|
|
397
|
+
intrinsics,
|
|
398
|
+
newGlobalPropertyNames: sharedGlobalPropertyNames,
|
|
399
|
+
makeCompartmentConstructor: targetMakeCompartmentConstructor,
|
|
400
|
+
parentCompartment: this,
|
|
401
|
+
markVirtualizedNativeFunction,
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// TODO: maybe add evalTaming to the Compartment constructor 3rd options?
|
|
405
|
+
setGlobalObjectEvaluators(
|
|
406
|
+
globalObject,
|
|
407
|
+
safeEvaluate,
|
|
408
|
+
markVirtualizedNativeFunction,
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
assign(globalObject, endowments);
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* In support dynamic import in a module source loaded by this compartment,
|
|
415
|
+
* like `await import(importSpecifier)`, induces this compartment to import
|
|
416
|
+
* a module, returning a promise for the resulting module exports
|
|
417
|
+
* namespace.
|
|
418
|
+
* Unlike `compartment.import`, never creates a box object for the
|
|
419
|
+
* namespace as that behavior is deprecated and inconsistent with the
|
|
420
|
+
* standard behavior of dynamic import.
|
|
421
|
+
* Obliges the caller to resolve import specifiers to their corresponding
|
|
422
|
+
* full specifier.
|
|
423
|
+
* That is, every module must have its own dynamic import function that
|
|
424
|
+
* closes over the surrounding module's full module specifier and calls
|
|
425
|
+
* through to this function.
|
|
426
|
+
* @param {string} fullSpecifier - A full specifier is a key in the
|
|
427
|
+
* compartment's module memo.
|
|
428
|
+
* The method `compartment.import` accepts a full specifier, but dynamic
|
|
429
|
+
* import accepts an import specifier and resolves it to a full specifier
|
|
430
|
+
* relative to the calling module's full specifier.
|
|
431
|
+
* @returns {Promise<ModuleExportsNamespace>}
|
|
432
|
+
*/
|
|
433
|
+
const compartmentImport = async fullSpecifier => {
|
|
434
|
+
if (typeof resolveHook !== 'function') {
|
|
435
|
+
throw TypeError(
|
|
436
|
+
`Compartment does not support dynamic import: no configured resolveHook for compartment ${q(name)}`,
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
await load(privateFields, moduleAliases, compartment, fullSpecifier, {
|
|
440
|
+
noAggregateErrors: noAggregateLoadErrors,
|
|
441
|
+
});
|
|
442
|
+
const { execute, exportsProxy } = link(
|
|
443
|
+
privateFields,
|
|
444
|
+
moduleAliases,
|
|
445
|
+
compartment,
|
|
446
|
+
fullSpecifier,
|
|
447
|
+
);
|
|
448
|
+
execute();
|
|
449
|
+
return exportsProxy;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
weakmapSet(privateFields, this, {
|
|
453
|
+
name: `${name}`,
|
|
454
|
+
globalTransforms,
|
|
455
|
+
globalObject,
|
|
456
|
+
safeEvaluate,
|
|
457
|
+
resolveHook,
|
|
458
|
+
importHook,
|
|
459
|
+
importNowHook,
|
|
460
|
+
moduleMap,
|
|
461
|
+
moduleMapHook,
|
|
462
|
+
importMetaHook,
|
|
463
|
+
moduleRecords,
|
|
464
|
+
__shimTransforms__,
|
|
465
|
+
deferredExports,
|
|
466
|
+
instances,
|
|
467
|
+
parentCompartment,
|
|
468
|
+
noNamespaceBox,
|
|
469
|
+
compartmentImport,
|
|
470
|
+
noAggregateLoadErrors,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
Compartment.prototype = CompartmentPrototype;
|
|
475
|
+
|
|
476
|
+
return Compartment;
|
|
477
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { symbolFor, globalThis } from './commons.js';
|
|
2
|
+
import { defineCausalConsoleFromLogger } from './error/console.js';
|
|
3
|
+
import { loggedErrorHandler } from './error/assert.js';
|
|
4
|
+
|
|
5
|
+
// TODO possible additional exports. Some are privileged.
|
|
6
|
+
// export { loggedErrorHandler };
|
|
7
|
+
// export {
|
|
8
|
+
// makeCausalConsole,
|
|
9
|
+
// consoleLevelMethods,
|
|
10
|
+
// consoleOtherMethods,
|
|
11
|
+
// makeLoggingConsoleKit,
|
|
12
|
+
// filterConsole,
|
|
13
|
+
// pumpLogToConsole,
|
|
14
|
+
// } from './src/error/console.js';
|
|
15
|
+
// export { assertLogs, throwsAndLogs } from './src/error/throws-and-logs.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Makes a Console like the
|
|
19
|
+
* [SES causal `console`](https://github.com/endojs/endo/blob/master/packages/ses/src/error/README.md)
|
|
20
|
+
* but whose output is redirected to the supplied `logger` function.
|
|
21
|
+
*/
|
|
22
|
+
const makeCausalConsoleFromLoggerForSesAva =
|
|
23
|
+
defineCausalConsoleFromLogger(loggedErrorHandler);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*`makeCausalConsoleFromLoggerForSesAva` is privileged because it exposes
|
|
27
|
+
* unredacted error info onto the `Logger` provided by the caller. It
|
|
28
|
+
* should not be made available to non-privileged code.
|
|
29
|
+
*
|
|
30
|
+
* Further, we consider this particular API choice to be experimental
|
|
31
|
+
* and may change in the future. It is currently only intended for use by
|
|
32
|
+
* `@endo/ses-ava`, with which it will be co-maintained.
|
|
33
|
+
*
|
|
34
|
+
* Thus, this `console-shim.js` makes `makeCausalConsoleFromLoggerForSesAva`
|
|
35
|
+
* available on `globalThis` which it *assumes* is the global of the start
|
|
36
|
+
* compartment and is therefore allowed to hold powers that should not be
|
|
37
|
+
* available in constructed compartments. It makes it available as the value of
|
|
38
|
+
* a global property named by a registered symbol named
|
|
39
|
+
* `MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA`.
|
|
40
|
+
*
|
|
41
|
+
* Anyone accessing this, including `@endo/ses-ava`, should feature test for
|
|
42
|
+
* this and be tolerant of its absence. It may indeed disappear from later
|
|
43
|
+
* versions of the ses-shim.
|
|
44
|
+
*/
|
|
45
|
+
const MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA = symbolFor(
|
|
46
|
+
'MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA',
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
globalThis[MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA] =
|
|
50
|
+
makeCausalConsoleFromLoggerForSesAva;
|