@nocobase/plugin-workflow-javascript 2.1.0-beta.10 → 2.1.0-beta.12
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/dist/externalVersion.js +4 -4
- package/dist/node_modules/isolated-vm/.clang-tidy +13 -0
- package/dist/node_modules/isolated-vm/.dockerignore +9 -0
- package/dist/node_modules/isolated-vm/Dockerfile.alpine +9 -0
- package/dist/node_modules/isolated-vm/Dockerfile.debian +12 -0
- package/dist/node_modules/isolated-vm/LICENSE +13 -0
- package/dist/node_modules/isolated-vm/binding.gyp +120 -0
- package/dist/node_modules/isolated-vm/include.js +3 -0
- package/dist/node_modules/isolated-vm/inspector-example.js +59 -0
- package/dist/node_modules/isolated-vm/isolated-vm.d.ts +820 -0
- package/dist/node_modules/isolated-vm/isolated-vm.js +1 -0
- package/dist/node_modules/isolated-vm/native-example/binding.gyp +23 -0
- package/dist/node_modules/isolated-vm/native-example/example.cc +61 -0
- package/dist/node_modules/isolated-vm/native-example/package.json +13 -0
- package/dist/node_modules/isolated-vm/native-example/usage.js +35 -0
- package/dist/node_modules/isolated-vm/out/isolated_vm.node +0 -0
- package/dist/node_modules/isolated-vm/package.json +1 -0
- package/dist/node_modules/isolated-vm/src/external_copy/error.h +33 -0
- package/dist/node_modules/isolated-vm/src/external_copy/external_copy.cc +509 -0
- package/dist/node_modules/isolated-vm/src/external_copy/external_copy.h +117 -0
- package/dist/node_modules/isolated-vm/src/external_copy/serializer.cc +85 -0
- package/dist/node_modules/isolated-vm/src/external_copy/serializer.h +136 -0
- package/dist/node_modules/isolated-vm/src/external_copy/serializer_nortti.cc +73 -0
- package/dist/node_modules/isolated-vm/src/external_copy/string.cc +124 -0
- package/dist/node_modules/isolated-vm/src/external_copy/string.h +28 -0
- package/dist/node_modules/isolated-vm/src/isolate/allocator.h +32 -0
- package/dist/node_modules/isolated-vm/src/isolate/allocator_nortti.cc +142 -0
- package/dist/node_modules/isolated-vm/src/isolate/class_handle.h +334 -0
- package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.cc +220 -0
- package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.h +100 -0
- package/dist/node_modules/isolated-vm/src/isolate/environment.cc +626 -0
- package/dist/node_modules/isolated-vm/src/isolate/environment.h +381 -0
- package/dist/node_modules/isolated-vm/src/isolate/executor.cc +198 -0
- package/dist/node_modules/isolated-vm/src/isolate/executor.h +183 -0
- package/dist/node_modules/isolated-vm/src/isolate/external.h +64 -0
- package/dist/node_modules/isolated-vm/src/isolate/functor_runners.h +97 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/array.h +145 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/callbacks.h +272 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/error.h +140 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/extract_params.h +145 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/handle_cast.h +257 -0
- package/dist/node_modules/isolated-vm/src/isolate/generic/read_option.h +47 -0
- package/dist/node_modules/isolated-vm/src/isolate/holder.cc +88 -0
- package/dist/node_modules/isolated-vm/src/isolate/holder.h +63 -0
- package/dist/node_modules/isolated-vm/src/isolate/inspector.cc +200 -0
- package/dist/node_modules/isolated-vm/src/isolate/inspector.h +70 -0
- package/dist/node_modules/isolated-vm/src/isolate/node_wrapper.h +15 -0
- package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.cc +22 -0
- package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.h +46 -0
- package/dist/node_modules/isolated-vm/src/isolate/remote_handle.h +164 -0
- package/dist/node_modules/isolated-vm/src/isolate/run_with_timeout.h +171 -0
- package/dist/node_modules/isolated-vm/src/isolate/runnable.h +29 -0
- package/dist/node_modules/isolated-vm/src/isolate/scheduler.cc +191 -0
- package/dist/node_modules/isolated-vm/src/isolate/scheduler.h +165 -0
- package/dist/node_modules/isolated-vm/src/isolate/specific.h +35 -0
- package/dist/node_modules/isolated-vm/src/isolate/stack_trace.cc +219 -0
- package/dist/node_modules/isolated-vm/src/isolate/stack_trace.h +24 -0
- package/dist/node_modules/isolated-vm/src/isolate/strings.h +127 -0
- package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.cc +385 -0
- package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.h +136 -0
- package/dist/node_modules/isolated-vm/src/isolate/transferable.h +15 -0
- package/dist/node_modules/isolated-vm/src/isolate/util.h +45 -0
- package/dist/node_modules/isolated-vm/src/isolate/v8_inspector_wrapper.h +12 -0
- package/dist/node_modules/isolated-vm/src/isolate/v8_version.h +12 -0
- package/dist/node_modules/isolated-vm/src/isolated_vm.h +71 -0
- package/dist/node_modules/isolated-vm/src/lib/covariant.h +50 -0
- package/dist/node_modules/isolated-vm/src/lib/lockable.h +178 -0
- package/dist/node_modules/isolated-vm/src/lib/suspend.h +106 -0
- package/dist/node_modules/isolated-vm/src/lib/thread_pool.cc +98 -0
- package/dist/node_modules/isolated-vm/src/lib/thread_pool.h +45 -0
- package/dist/node_modules/isolated-vm/src/lib/timer.cc +233 -0
- package/dist/node_modules/isolated-vm/src/lib/timer.h +36 -0
- package/dist/node_modules/isolated-vm/src/module/callback.cc +151 -0
- package/dist/node_modules/isolated-vm/src/module/callback.h +64 -0
- package/dist/node_modules/isolated-vm/src/module/context_handle.cc +241 -0
- package/dist/node_modules/isolated-vm/src/module/context_handle.h +35 -0
- package/dist/node_modules/isolated-vm/src/module/evaluation.cc +109 -0
- package/dist/node_modules/isolated-vm/src/module/evaluation.h +99 -0
- package/dist/node_modules/isolated-vm/src/module/external_copy_handle.cc +119 -0
- package/dist/node_modules/isolated-vm/src/module/external_copy_handle.h +64 -0
- package/dist/node_modules/isolated-vm/src/module/isolate.cc +136 -0
- package/dist/node_modules/isolated-vm/src/module/isolate_handle.cc +611 -0
- package/dist/node_modules/isolated-vm/src/module/isolate_handle.h +47 -0
- package/dist/node_modules/isolated-vm/src/module/lib_handle.cc +77 -0
- package/dist/node_modules/isolated-vm/src/module/lib_handle.h +28 -0
- package/dist/node_modules/isolated-vm/src/module/module_handle.cc +475 -0
- package/dist/node_modules/isolated-vm/src/module/module_handle.h +68 -0
- package/dist/node_modules/isolated-vm/src/module/native_module_handle.cc +104 -0
- package/dist/node_modules/isolated-vm/src/module/native_module_handle.h +49 -0
- package/dist/node_modules/isolated-vm/src/module/reference_handle.cc +636 -0
- package/dist/node_modules/isolated-vm/src/module/reference_handle.h +106 -0
- package/dist/node_modules/isolated-vm/src/module/script_handle.cc +107 -0
- package/dist/node_modules/isolated-vm/src/module/script_handle.h +37 -0
- package/dist/node_modules/isolated-vm/src/module/session_handle.cc +173 -0
- package/dist/node_modules/isolated-vm/src/module/session_handle.h +31 -0
- package/dist/node_modules/isolated-vm/src/module/transferable.cc +268 -0
- package/dist/node_modules/isolated-vm/src/module/transferable.h +42 -0
- package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.0.0.h +360 -0
- package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.3.0.h +376 -0
- package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v20.0.0.h +397 -0
- package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v22.0.0.h +419 -0
- package/dist/node_modules/winston-transport/package.json +1 -1
- package/dist/server/IsolatedVm.js +75 -0
- package/dist/server/ScriptInstruction.d.ts +6 -0
- package/dist/server/ScriptInstruction.js +11 -1
- package/dist/server/Vm.js +42 -27
- package/package.json +3 -2
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
declare namespace IsolatedVM {
|
|
2
|
+
export type Transferable =
|
|
3
|
+
| null
|
|
4
|
+
| undefined
|
|
5
|
+
| string
|
|
6
|
+
| number
|
|
7
|
+
| boolean
|
|
8
|
+
| Isolate
|
|
9
|
+
| Context
|
|
10
|
+
| Script
|
|
11
|
+
| ExternalCopy<any>
|
|
12
|
+
| Callback<any>
|
|
13
|
+
| Copy<any>
|
|
14
|
+
| Reference<any>
|
|
15
|
+
| Dereference<any>
|
|
16
|
+
| Module
|
|
17
|
+
| ((...args: any[]) => any)
|
|
18
|
+
| typeof IsolatedVM;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This is the main reference to an isolate. Every handle to an isolate is transferable, which
|
|
22
|
+
* means you can give isolates references to each other. An isolate will remain valid as long as
|
|
23
|
+
* someone holds a handle to the isolate or anything created inside that isolate. Once an isolate
|
|
24
|
+
* is lost the garbage collector should eventually find it and clean up its memory. Since an
|
|
25
|
+
* isolate and all it contains can represent quite a large chunk of memory though you may want to
|
|
26
|
+
* explicitly call the `dispose()` method on isolates that you are finished with to get that memory
|
|
27
|
+
* back immediately.
|
|
28
|
+
*/
|
|
29
|
+
export class Isolate {
|
|
30
|
+
private __ivm_isolate: undefined;
|
|
31
|
+
constructor(options?: IsolateOptions);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The total CPU time spent in this isolate. CPU time is the amount of time the isolate has
|
|
35
|
+
* spent actively doing work on the CPU.
|
|
36
|
+
*
|
|
37
|
+
* Note that CPU time may vary drastically if there is contention for the CPU. This could occur
|
|
38
|
+
* if other processes are trying to do work, or if you have more than
|
|
39
|
+
* require('os').cpus().length isolates currently doing work in the same nodejs process.
|
|
40
|
+
*/
|
|
41
|
+
readonly cpuTime: bigint;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Flag that indicates whether this isolate has been disposed.
|
|
45
|
+
*/
|
|
46
|
+
readonly isDisposed: boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The total wall time spent in this isolate. Wall time is the amount of time the isolate has
|
|
50
|
+
* been running, including passive time spent waiting (think "wall" like a clock on the wall).
|
|
51
|
+
* For instance, if an isolate makes a call into another isolate, wall time will continue
|
|
52
|
+
* increasing while CPU time will remain the same.
|
|
53
|
+
*/
|
|
54
|
+
readonly wallTime: bigint;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the total count of active `Reference` instances that belong to this isolate. Note
|
|
58
|
+
* that in certain cases many `Reference` instances in JavaScript will point to the same
|
|
59
|
+
* underlying reference handle, in which case this number will only reflect the underlying
|
|
60
|
+
* reference handle. This happens when you transfer a `Reference` instance via some method which
|
|
61
|
+
* accepts transferable values. This will also include underlying reference handles created by
|
|
62
|
+
* isolated-vm like `Script` or `Context` objects.
|
|
63
|
+
*/
|
|
64
|
+
readonly referenceCount: number;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Isolate snapshots are a very useful feature if you intend to create several isolates running
|
|
68
|
+
* common libraries between them. A snapshot serializes the entire v8 heap including parsed code,
|
|
69
|
+
* global variables, and compiled code. Check out the examples section for tips on using this.
|
|
70
|
+
*
|
|
71
|
+
* **Please note that versions of nodejs 10.4.0 - 10.9.0 may crash while using the snapshot
|
|
72
|
+
* feature.**
|
|
73
|
+
*
|
|
74
|
+
* @param warmup_script - Optional script to "warmup" the snapshot by triggering code compilation
|
|
75
|
+
*/
|
|
76
|
+
static createSnapshot(scripts: SnapshotScriptInfo[], warmup_script?: string): ExternalCopy<ArrayBuffer>;
|
|
77
|
+
|
|
78
|
+
compileScript(code: string, scriptInfo?: ScriptInfo): Promise<Script>;
|
|
79
|
+
compileScriptSync(code: string, scriptInfo?: ScriptInfo): Script;
|
|
80
|
+
|
|
81
|
+
compileModule(code: string, options?: CompileModuleOptions): Promise<Module>;
|
|
82
|
+
compileModuleSync(code: string, options?: CompileModuleOptions): Module;
|
|
83
|
+
|
|
84
|
+
createContext(options?: ContextOptions): Promise<Context>;
|
|
85
|
+
createContextSync(options?: ContextOptions): Context;
|
|
86
|
+
|
|
87
|
+
createInspectorSession(): InspectorSession;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Destroys this isolate and invalidates all references obtained from it.
|
|
91
|
+
*/
|
|
92
|
+
dispose(): void;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Returns heap statistics from v8.
|
|
96
|
+
*
|
|
97
|
+
* The return value is almost identical to the nodejs function v8.getHeapStatistics().
|
|
98
|
+
*
|
|
99
|
+
* See: https://nodejs.org/dist/latest-v8.x/docs/api/v8.html#v8_v8_getheapstatistics.
|
|
100
|
+
*
|
|
101
|
+
* This function returns one additional property: "externally_allocated_size" which is the total
|
|
102
|
+
* amount of currently allocated memory which is not included in the v8 heap but counts against
|
|
103
|
+
* this isolate's "memoryLimit".
|
|
104
|
+
*
|
|
105
|
+
* ArrayBuffer instances over a certain size are externally allocated and will be counted here.
|
|
106
|
+
*/
|
|
107
|
+
getHeapStatistics(): Promise<HeapStatistics>;
|
|
108
|
+
getHeapStatisticsSync(): HeapStatistics;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Start profiling against the isolate with a specific title
|
|
112
|
+
*
|
|
113
|
+
* @param title the profile title
|
|
114
|
+
*/
|
|
115
|
+
startCpuProfiler(title: string): void;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Stop profiling against the isolate with a specific title
|
|
119
|
+
* that started via `startCpuProfiler`. It will return more
|
|
120
|
+
* than one cpu profiles because isolate can be run in different
|
|
121
|
+
* threads. The `ThreadCpuProfile` contains the `thread_id` that
|
|
122
|
+
* the isolate was running in.
|
|
123
|
+
*
|
|
124
|
+
* @param title
|
|
125
|
+
*/
|
|
126
|
+
stopCpuProfiler(title: string): Promise<ThreadCpuProfile[]>;
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export type IsolateOptions = {
|
|
131
|
+
/**
|
|
132
|
+
* Memory limit that this isolate may use, in MB. Note that this is more of a guideline
|
|
133
|
+
* instead of a strict limit. A determined attacker could use 2-3 times this limit before
|
|
134
|
+
* their script is terminated. Against non-hostile code this limit should be pretty close. The
|
|
135
|
+
* default is 128MB and the mimium is 8MB.
|
|
136
|
+
*/
|
|
137
|
+
memoryLimit?: number;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Enable v8 inspector support in this isolate. See `inspector-example.js` in this repository
|
|
141
|
+
* for an example of how to use this.
|
|
142
|
+
*/
|
|
143
|
+
inspector?: boolean;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* This is an optional snapshot created from `createSnapshot` which will be used to initialize
|
|
147
|
+
* the heap of this isolate.
|
|
148
|
+
*/
|
|
149
|
+
snapshot?: ExternalCopy<ArrayBuffer>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Callback to be invoked when a *very bad* error occurs. If this is invoked it means that v8
|
|
153
|
+
* has lost all control over the isolate, and all resources in use are totally unrecoverable. If
|
|
154
|
+
* you receive this error you should log the error, stop serving requests, finish outstanding
|
|
155
|
+
* work, and end the process by calling `process.abort()`.
|
|
156
|
+
*/
|
|
157
|
+
onCatastrophicError?: (message: string) => void;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export type ContextOptions = {
|
|
161
|
+
inspector?: boolean;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export type HeapStatistics = {
|
|
165
|
+
total_heap_size: number;
|
|
166
|
+
total_heap_size_executable: number;
|
|
167
|
+
total_physical_size: number;
|
|
168
|
+
total_available_size: number;
|
|
169
|
+
used_heap_size: number;
|
|
170
|
+
heap_size_limit: number;
|
|
171
|
+
malloced_memory: number;
|
|
172
|
+
peak_malloced_memory: number;
|
|
173
|
+
does_zap_garbage: number;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The total amount of currently allocated memory which is not included in the v8 heap but
|
|
177
|
+
* counts against this isolate's "memoryLimit".
|
|
178
|
+
*/
|
|
179
|
+
externally_allocated_size: number;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export type CompileModuleOptions = ScriptInfo & {
|
|
183
|
+
/**
|
|
184
|
+
* Callback which will be invoked the first time this module accesses `import.meta`. The `meta`
|
|
185
|
+
* object will be passed as the first argument. This option may only be used when invoking
|
|
186
|
+
* `compileModule` from within the same isolate.
|
|
187
|
+
*/
|
|
188
|
+
meta?: (meta: any) => void;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* A context is a sandboxed execution environment within an isolate. Each context contains its own
|
|
193
|
+
* built-in objects and global space.
|
|
194
|
+
*/
|
|
195
|
+
export class Context {
|
|
196
|
+
private __ivm_context: undefined;
|
|
197
|
+
private constructor();
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* `Reference` to this context's global object. Note that if you call `context.release()` the
|
|
201
|
+
* global reference will be released as well.
|
|
202
|
+
*/
|
|
203
|
+
readonly global: Reference<Record<number | string | symbol, any>>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Compiles and executes a script within a context. This will return the last value evaluated,
|
|
207
|
+
* as long as that value was transferable, otherwise `undefined` will be returned.
|
|
208
|
+
*/
|
|
209
|
+
eval<Options extends ContextEvalOptions>(
|
|
210
|
+
code: string, options?: Options
|
|
211
|
+
): Promise<ResultTypeSync<Options>>; // `ResultTypeSync` used intentionally
|
|
212
|
+
evalIgnored(code: string, options?: ContextEvalOptions): void
|
|
213
|
+
evalSync<Options extends ContextEvalOptions>(
|
|
214
|
+
code: string, options?: Options
|
|
215
|
+
): ResultTypeSync<Options>;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Compiles and runs code as if it were inside a function, similar to the seldom-used `new
|
|
219
|
+
* Function(code)` constructor. You can pass arguments to the function and they will be
|
|
220
|
+
* available as `$0`, `$1`, and so on. You can also use `return` from the code.
|
|
221
|
+
*/
|
|
222
|
+
evalClosure<Options extends ContextEvalClosureOptions>(
|
|
223
|
+
code: string, arguments?: ArgumentsTypeBidirectional<Options>, options?: Options
|
|
224
|
+
): Promise<ResultTypeBidirectionalSync<Options>>; // `ResultTypeBidirectionalSync` used intentionally
|
|
225
|
+
evalClosureIgnored<Options extends ContextEvalClosureOptions>(
|
|
226
|
+
code: string, arguments?: ArgumentsTypeBidirectional<Options>, options?: Options
|
|
227
|
+
): void
|
|
228
|
+
evalClosureSync<Options extends ContextEvalClosureOptions>(
|
|
229
|
+
code: string, arguments?: ArgumentsTypeBidirectional<Options>, options?: Options
|
|
230
|
+
): ResultTypeBidirectionalSync<Options>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Releases this reference to the context. You can call this to free up v8 resources
|
|
234
|
+
* immediately, or you can let the garbage collector handle it when it feels like it. Note that
|
|
235
|
+
* if there are other references to this context it will not be disposed. This only affects this
|
|
236
|
+
* reference to the context.
|
|
237
|
+
*/
|
|
238
|
+
release(): void;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export type ContextEvalOptions = RunOptions & ScriptOrigin & TransferOptions;
|
|
242
|
+
export type ContextEvalClosureOptions = RunOptions & ScriptOrigin & TransferOptionsBidirectional;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* A script is a compiled chunk of JavaScript which can be executed in any context within a single
|
|
246
|
+
* isolate.
|
|
247
|
+
*/
|
|
248
|
+
export class Script {
|
|
249
|
+
private __ivm_script: undefined;
|
|
250
|
+
private constructor();
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Releases the reference to this script, allowing the script data to be garbage collected.
|
|
254
|
+
* Functions and data created in the isolate by previous invocations to `script.run(...)` will
|
|
255
|
+
* still be alive in their respective contexts-- this only means that you can't invoke
|
|
256
|
+
* `script.run(...)` again with this reference.
|
|
257
|
+
*/
|
|
258
|
+
release(): void;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Runs a given script within a context. This will return the last value evaluated in a given
|
|
262
|
+
* script, as long as that value was transferable, otherwise `undefined` will be returned. For
|
|
263
|
+
* instance if your script was "let foo = 1; let bar = 2; bar = foo + bar" then the return value
|
|
264
|
+
* will be 3 because that is the last expression.
|
|
265
|
+
*/
|
|
266
|
+
run<Options extends ScriptRunOptions>(context: Context, options?: Options): ResultTypeAsync<Options>;
|
|
267
|
+
runIgnored(context: Context, options?: ScriptRunOptions): void;
|
|
268
|
+
runSync<Options extends ScriptRunOptions>(context: Context, options?: Options): ResultTypeSync<Options>;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export type ScriptRunOptions = RunOptions & ReleaseOptions & TransferOptions;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* A JavaScript module. Note that a Module can only run in the isolate which created it.
|
|
275
|
+
*/
|
|
276
|
+
export class Module {
|
|
277
|
+
private __ivm_module: undefined;
|
|
278
|
+
private constructor();
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* A read-only array of all dependency specifiers the module has.
|
|
282
|
+
*/
|
|
283
|
+
readonly dependencySpecifiers: string[];
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Returns a Reference containing all exported values.
|
|
287
|
+
*/
|
|
288
|
+
readonly namespace: Reference<any>;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Instantiate the module together with all its dependencies. Calling this more than once on a
|
|
292
|
+
* single module will have no effect.
|
|
293
|
+
* @param context The context the module should use.
|
|
294
|
+
* @param resolveCallback This callback is responsible for resolving all direct and indirect
|
|
295
|
+
* dependencies of this module. It accepts two parameters: specifier and referrer. It must
|
|
296
|
+
* return a Module instance or a promise which will be used to satisfy the dependency.
|
|
297
|
+
*/
|
|
298
|
+
instantiate(
|
|
299
|
+
context: Context,
|
|
300
|
+
resolveCallback: (
|
|
301
|
+
specifier: string,
|
|
302
|
+
referrer: Module
|
|
303
|
+
) => Module | Promise<Module>
|
|
304
|
+
): Promise<void>;
|
|
305
|
+
instantiateSync(
|
|
306
|
+
context: Context,
|
|
307
|
+
resolveCallback: (specifier: string, referrer: Module) => Module
|
|
308
|
+
): void;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Evaluate the module and return the last expression (same as script.run). If evaluate is
|
|
312
|
+
* called more than once on the same module the return value from the first invocation will be
|
|
313
|
+
* returned (or thrown).
|
|
314
|
+
* @param options Optional
|
|
315
|
+
*/
|
|
316
|
+
evaluate(options?: ScriptRunOptions): Promise<Transferable>;
|
|
317
|
+
evaluateSync(options?: ScriptRunOptions): Transferable;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Releases this module. This behaves the same as other `.release()` methods.
|
|
321
|
+
*/
|
|
322
|
+
release(): void;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* A instance of Reference is a pointer to a value stored in any isolate.
|
|
327
|
+
*/
|
|
328
|
+
export class Reference<T = any> {
|
|
329
|
+
private __ivm_reference: T;
|
|
330
|
+
constructor(value: T, options?: { unsafeInherit?: boolean });
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* This is the typeof the referenced value, and is available at any time
|
|
334
|
+
* from any isolate. Note that this differs from the real typeof operator in
|
|
335
|
+
* that null is "null", and Symbols are "object".
|
|
336
|
+
*/
|
|
337
|
+
readonly typeof: string;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Creates a copy of the referenced value and internalizes it into this isolate. This uses the
|
|
341
|
+
* same copy rules as ExternalCopy.
|
|
342
|
+
*/
|
|
343
|
+
copy(): Promise<T>;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Creates a copy of the referenced value and internalizes it into this isolate. This uses the
|
|
347
|
+
* same copy rules as ExternalCopy.
|
|
348
|
+
*
|
|
349
|
+
* @return JavaScript value of the reference.
|
|
350
|
+
*/
|
|
351
|
+
copySync(): T;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Will attempt to return the actual value or object pointed to by this reference. Note that in
|
|
355
|
+
* order to call this function the reference must be owned by the current isolate, otherwise an
|
|
356
|
+
* error will be thrown.
|
|
357
|
+
*/
|
|
358
|
+
deref(options?: ReleaseOptions): T;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Returns an object, which when passed to another isolate will cause that isolate to
|
|
362
|
+
* dereference the handle.
|
|
363
|
+
*/
|
|
364
|
+
derefInto(options?: ReleaseOptions): Dereference<T>;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Releases this reference. If you're passing around a lot of references between isolates it's
|
|
368
|
+
* wise to release the references when you are done. Otherwise you may run into issues with
|
|
369
|
+
* isolates running out of memory because other isolates haven't garbage collected recently.
|
|
370
|
+
* After calling this method all attempts to access the reference will throw an error.
|
|
371
|
+
*/
|
|
372
|
+
release(): void;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Delete a property from this reference, as if using `delete reference[property]`
|
|
376
|
+
*/
|
|
377
|
+
delete(property: keyof T): Promise<void>;
|
|
378
|
+
deleteIgnored(property: keyof T): void;
|
|
379
|
+
deleteSync(property: keyof T): void;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Will access a reference as if using reference[property] and return a reference to that value.
|
|
383
|
+
*
|
|
384
|
+
* If the object is a proxy, or if the property is a getter, this method will throw.
|
|
385
|
+
*/
|
|
386
|
+
get<Options extends TransferOptions, Key extends keyof T>(
|
|
387
|
+
property: Key, options?: Options): ResultTypeAsync<Options & FallbackReference, T[Key]>;
|
|
388
|
+
getSync<Options extends TransferOptions, Key extends keyof T>(
|
|
389
|
+
property: Key, options?: Options): ResultTypeSync<Options & FallbackReference, T[Key]>;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Will access a reference as if using reference[property] and return a reference to that value.
|
|
393
|
+
*/
|
|
394
|
+
set<Options extends TransferOptions, Key extends keyof T>(
|
|
395
|
+
property: Key, value: ArgumentType<Options, T[Key]>, options?: Options): Promise<void>;
|
|
396
|
+
setIgnored<Options extends TransferOptions, Key extends keyof T>(
|
|
397
|
+
property: Key, value: ArgumentType<Options, T[Key]>, options?: Options): void;
|
|
398
|
+
setSync<Options extends TransferOptions, Key extends keyof T>(
|
|
399
|
+
property: Key, value: ArgumentType<Options, T[Key]>, options?: Options): void;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Will attempt to invoke an object as if it were a function. If the return
|
|
403
|
+
* value is transferable it will be returned to the called of apply,
|
|
404
|
+
* otherwise an error will be thrown.
|
|
405
|
+
*/
|
|
406
|
+
apply<Options extends ReferenceApplyOptions>(
|
|
407
|
+
receiver?: ArgumentType<Options['arguments'], ApplyArgumentThis<T>>,
|
|
408
|
+
arguments?: ArgumentsTypeBidirectional<Options, ApplyArguments<T>>,
|
|
409
|
+
options?: Options
|
|
410
|
+
): ResultTypeBidirectionalAsync<Options & FallbackReference, ApplyResult<T>>;
|
|
411
|
+
applyIgnored<Options extends ReferenceApplyOptions>(
|
|
412
|
+
receiver?: ArgumentType<Options['arguments'], ApplyArgumentThis<T>>,
|
|
413
|
+
arguments?: ArgumentsTypeBidirectional<Options & FallbackReference, ApplyArguments<T>>,
|
|
414
|
+
options?: Options
|
|
415
|
+
): void;
|
|
416
|
+
applySync<Options extends ReferenceApplyOptions>(
|
|
417
|
+
receiver?: ArgumentType<Options['arguments'], ApplyArgumentThis<T>>,
|
|
418
|
+
arguments?: ArgumentsTypeBidirectional<Options, ApplyArguments<T>>,
|
|
419
|
+
options?: Options
|
|
420
|
+
): ResultTypeBidirectionalSync<Options & FallbackReference, ApplyResult<T>>;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* `applySyncPromise` is a special version of `applySync` which may only be invoked on functions
|
|
424
|
+
* belonging to the default isolate AND may only be invoked from a non-default thread. Functions
|
|
425
|
+
* invoked in this way may return a promise and the invoking isolate will wait for that promise
|
|
426
|
+
* to resolve before resuming execution. You can use this to implement functions like
|
|
427
|
+
* readFileSync in a way that doesn't block the default isolate. Note that the invoking isolate
|
|
428
|
+
* will not respond to any async functions until this promise is resolved, however synchronous
|
|
429
|
+
* functions will still function correctly. Misuse of this feature may result in deadlocked
|
|
430
|
+
* isolates, though the default isolate will never be at risk of a deadlock.
|
|
431
|
+
*/
|
|
432
|
+
applySyncPromise<Options extends ReferenceApplyOptions>(
|
|
433
|
+
receiver?: ArgumentType<Options['arguments'], ApplyArgumentThis<T>>,
|
|
434
|
+
arguments?: ArgumentsTypeBidirectional<Options, ApplyArguments<T>>,
|
|
435
|
+
options?: Options
|
|
436
|
+
): ResultTypeBidirectionalSync<Options & FallbackReference, ApplyResult<T>>;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Dummy type referencing a type dereferenced into a different Isolate.
|
|
441
|
+
*/
|
|
442
|
+
export class Dereference<T> {
|
|
443
|
+
private constructor();
|
|
444
|
+
private __ivm_deref: T;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export type ReferenceApplyOptions = RunOptions & TransferOptionsBidirectional;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Instances of this class represent some value that is stored outside of any v8
|
|
451
|
+
* isolate. This value can then be quickly copied into any isolate.
|
|
452
|
+
*/
|
|
453
|
+
export class ExternalCopy<T = any> {
|
|
454
|
+
private __ivm_external_copy: T;
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Primitive values can be copied exactly as they are. Date objects will be copied as as Dates.
|
|
458
|
+
* ArrayBuffers, TypedArrays, and DataViews will be copied in an efficient format.
|
|
459
|
+
* SharedArrayBuffers will simply copy a reference to the existing memory and when copied into
|
|
460
|
+
* another isolate the new SharedArrayBuffer will point to the same underlying data. After
|
|
461
|
+
* passing a SharedArrayBuffer to ExternalCopy for the first time isolated-vm will take over
|
|
462
|
+
* management of the underlying memory block, so a "copied" SharedArrayBuffer can outlive the
|
|
463
|
+
* isolate that created the memory originally.
|
|
464
|
+
*
|
|
465
|
+
* All other objects will be copied in seralized form using the [structured clone
|
|
466
|
+
* algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
|
|
467
|
+
*
|
|
468
|
+
* `ExternalCopy` can copy objects with deeply nested *transferable* objects.
|
|
469
|
+
*/
|
|
470
|
+
constructor(value: T, options?: ExternalCopyOptions);
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Static property which will return the total number of bytes that isolated-vm has allocated
|
|
474
|
+
* outside of v8 due to instances of `ExternalCopy`.
|
|
475
|
+
*/
|
|
476
|
+
static readonly totalExternalSize: number;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Internalizes the ExternalCopy data into this isolate.
|
|
480
|
+
*
|
|
481
|
+
* @return JavaScript value of the external copy.
|
|
482
|
+
*/
|
|
483
|
+
copy(options?: ExternalCopyCopyOptions): T;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Returns an object, which when passed to another isolate will cause that isolate to
|
|
487
|
+
* internalize a copy of this value.
|
|
488
|
+
*/
|
|
489
|
+
copyInto(options?: ExternalCopyCopyOptions): Copy<T>;
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Releases the reference to this copy. If there are other references to this copy elsewhere the
|
|
493
|
+
* copy will still remain in memory, but this handle will no longer be active. Disposing
|
|
494
|
+
* ExternalCopy instances isn't super important, v8 is a lot better at cleaning these up
|
|
495
|
+
* automatically because there's no inter-isolate dependencies.
|
|
496
|
+
*/
|
|
497
|
+
release(): void;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Dummy type referencing a type copied into a different Isolate.
|
|
502
|
+
*/
|
|
503
|
+
export class Copy<T> {
|
|
504
|
+
private constructor();
|
|
505
|
+
private __ivm_copy: T;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
export type ExternalCopyOptions = {
|
|
509
|
+
/**
|
|
510
|
+
* An array of `ArrayBuffer` instances to transfer ownership. This behaves in a similar way to
|
|
511
|
+
* [`postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage).
|
|
512
|
+
*/
|
|
513
|
+
transferList?: any[];
|
|
514
|
+
/**
|
|
515
|
+
* If true this will release ownership of the given resource from this isolate. This operation
|
|
516
|
+
* completes in constant time since it doesn't have to copy an arbitrarily large object. This
|
|
517
|
+
* only applies to ArrayBuffer and TypedArray instances.
|
|
518
|
+
*/
|
|
519
|
+
transferOut?: boolean;
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
export type ExternalCopyCopyOptions = ReleaseOptions & {
|
|
523
|
+
/**
|
|
524
|
+
* If true this will transfer the resource directly into this isolate, invalidating the
|
|
525
|
+
* ExternalCopy handle.
|
|
526
|
+
*/
|
|
527
|
+
transferIn?: boolean;
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Callbacks can be used to create cross-isolate references to simple functions. This can be
|
|
532
|
+
* easier and safer than dealing with the more flexible
|
|
533
|
+
* [`Reference`](#class-reference-transferable) class. Arguments passed to and returned from
|
|
534
|
+
* callbacks are always copied using the same method as
|
|
535
|
+
* [`ExternalCopy`](#class-externalcopy-transferable). When transferred to another isolate,
|
|
536
|
+
* instances of `Callback` will turn into a plain old function. Callbacks are created
|
|
537
|
+
* automatically when passing functions to most isolated-vm functions.
|
|
538
|
+
*/
|
|
539
|
+
export class Callback<T extends (...args: any[]) => any = any> {
|
|
540
|
+
private __ivm_callback: T;
|
|
541
|
+
|
|
542
|
+
constructor(value: T, options?: CallbackOptions);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export type CallbackOptions = {
|
|
546
|
+
/**
|
|
547
|
+
* Callback will be invoked asynchronously and will return a promise.
|
|
548
|
+
*/
|
|
549
|
+
async?: boolean;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Callback will be invoked asynchronously and will return a value (default).
|
|
553
|
+
*/
|
|
554
|
+
sync?: boolean;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Callback will be invoked asynchronously and will ignore the result (including exceptions).
|
|
558
|
+
*/
|
|
559
|
+
ignored?: boolean;
|
|
560
|
+
|
|
561
|
+
// The following ensures only 1 invocation option is given.
|
|
562
|
+
} & ({
|
|
563
|
+
async?: true;
|
|
564
|
+
sync?: never;
|
|
565
|
+
ignored?: never;
|
|
566
|
+
} | {
|
|
567
|
+
async?: never;
|
|
568
|
+
sync?: true;
|
|
569
|
+
ignored?: never;
|
|
570
|
+
} | {
|
|
571
|
+
async?: never;
|
|
572
|
+
sync?: never;
|
|
573
|
+
ignored?: true;
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* C++ native module for v8 representation.
|
|
578
|
+
*/
|
|
579
|
+
export class NativeModule {
|
|
580
|
+
private __ivm_native_module: undefined;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Instantiate a native module with the full path to the compiled library.
|
|
584
|
+
* For instance, filename would represent the path to a .node file
|
|
585
|
+
* compiled using node-gyp.
|
|
586
|
+
*
|
|
587
|
+
* @param filename Full path to compiled library.
|
|
588
|
+
*/
|
|
589
|
+
constructor(filename: string);
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Instantiates the module with a Context by running the `InitForContext`
|
|
593
|
+
* symbol, throws if that symbol is not present.
|
|
594
|
+
*
|
|
595
|
+
* Returned Reference<NativeModule> should be dereferenced into a context
|
|
596
|
+
*
|
|
597
|
+
* @param context Context to initialize the module with.
|
|
598
|
+
*/
|
|
599
|
+
create(context: Context): Promise<Reference<any>>;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Synchronous version of `create`
|
|
603
|
+
*
|
|
604
|
+
* @param context Context to initialize the module with.
|
|
605
|
+
*/
|
|
606
|
+
createSync(context: Context): Reference<any>;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export type ThreadCpuProfile = {
|
|
610
|
+
threadId: number;
|
|
611
|
+
profile: CpuProfile;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
export type CpuProfile = {
|
|
615
|
+
startTime: number;
|
|
616
|
+
endTime: number;
|
|
617
|
+
samples: number[];
|
|
618
|
+
timeDeltas: number[];
|
|
619
|
+
nodes: Array<{
|
|
620
|
+
id: number;
|
|
621
|
+
hitCount: number;
|
|
622
|
+
children: number[];
|
|
623
|
+
callFrame: {
|
|
624
|
+
functionName: string;
|
|
625
|
+
url: string;
|
|
626
|
+
scriptId: number;
|
|
627
|
+
lineNubmer: number;
|
|
628
|
+
columnNumber: number;
|
|
629
|
+
bailoutReason?: string;
|
|
630
|
+
};
|
|
631
|
+
}>;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export type InspectorSession = {
|
|
635
|
+
dispatchProtocolMessage(message: string): void;
|
|
636
|
+
dispose(): void;
|
|
637
|
+
onNotification: (message: string) => void;
|
|
638
|
+
onResponse: (callId: number, message: string) => void;
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Most functions which compile or run code can produce and consume cached data. You can produce
|
|
643
|
+
* cached data and use the data in later invocations to drastically speed up parsing of the same
|
|
644
|
+
* script. You can even save this data to disk and use it in a different process. You can set both
|
|
645
|
+
* `cachedData` and `produceCachedData`, in which case new cached data will only be produced if
|
|
646
|
+
* the data supplied was invalid.
|
|
647
|
+
*/
|
|
648
|
+
export type CachedDataOptions = {
|
|
649
|
+
/**
|
|
650
|
+
* This will consume cached compilation data from a previous call to this function. Please don't
|
|
651
|
+
* use `produceCachedData` and `cachedData` options at the same time. `cachedDataRejected` will
|
|
652
|
+
* be set to `true` if the supplied data was rejected by V8.
|
|
653
|
+
*/
|
|
654
|
+
cachedData?: ExternalCopy<ArrayBuffer>;
|
|
655
|
+
/**
|
|
656
|
+
* Produce V8 cache data. Similar to the [VM.Script](https://nodejs.org/api/vm.html) option of
|
|
657
|
+
* the same name. If this is true then the returned object will have `cachedData` set to an
|
|
658
|
+
* ExternalCopy handle. Note that this differs from the VM.Script option slightly in that
|
|
659
|
+
* `cachedDataProduced` is never set.
|
|
660
|
+
*/
|
|
661
|
+
produceCachedData?: boolean;
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
export type CachedDataResult = {
|
|
665
|
+
cachedData?: ExternalCopy<ArrayBuffer>;
|
|
666
|
+
producedCacheData?: boolean;
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
export type ReleaseOptions = {
|
|
670
|
+
/**
|
|
671
|
+
* If true release() will automatically be called on this instance.
|
|
672
|
+
*/
|
|
673
|
+
release?: boolean;
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
export type RunOptions = {
|
|
677
|
+
/**
|
|
678
|
+
* Maximum amount of time in milliseconds this script is allowed to run before execution is
|
|
679
|
+
* canceled. Default is no timeout.
|
|
680
|
+
*/
|
|
681
|
+
timeout?: number;
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* You may optionally specify information on compiled code's filename. This is used in various
|
|
686
|
+
* debugging contexts within v8, including stack traces and the inspector. It is recommended to
|
|
687
|
+
* use a valid URI scheme, for example: `{ filename: 'file:///test.js' }`, otherwise some devtools
|
|
688
|
+
* may malfunction.
|
|
689
|
+
*/
|
|
690
|
+
export type ScriptOrigin = {
|
|
691
|
+
/**
|
|
692
|
+
* Filename of this source code
|
|
693
|
+
*/
|
|
694
|
+
filename?: string;
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Column offset of this source code
|
|
698
|
+
*/
|
|
699
|
+
columnOffset?: number;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Line offset of this source code
|
|
703
|
+
*/
|
|
704
|
+
lineOffset?: number;
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
export type SnapshotScriptInfo = ScriptOrigin & {
|
|
708
|
+
/**
|
|
709
|
+
* Source code to set up this snapshot
|
|
710
|
+
*/
|
|
711
|
+
code: string;
|
|
712
|
+
};
|
|
713
|
+
export type ScriptInfo = CachedDataOptions & ScriptOrigin;
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Any function which moves data between isolates will accept these transfer options. By default
|
|
717
|
+
* only *[transferable]* values may pass between isolates. Without specifying one of these options
|
|
718
|
+
* the function may ignore the value, throw, or wrap it in a reference depending on the context.
|
|
719
|
+
*
|
|
720
|
+
* More advanced situations like transferring ownership of `ArrayBuffer` instances will require
|
|
721
|
+
* direct use of `ExternalCopy` or `Reference`.
|
|
722
|
+
*/
|
|
723
|
+
export type TransferOptions = {
|
|
724
|
+
/**
|
|
725
|
+
* Automatically proxy any returned promises between isolates. This can be used in combination
|
|
726
|
+
* with the other transfer options.
|
|
727
|
+
*/
|
|
728
|
+
promise?: boolean;
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Automatically deep copy value
|
|
732
|
+
*/
|
|
733
|
+
copy?: boolean;
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Automatically wrap value in `ExternalCopy` instance
|
|
737
|
+
*/
|
|
738
|
+
externalCopy?: boolean;
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Automatically wrap value in `Reference` instance
|
|
742
|
+
*/
|
|
743
|
+
reference?: boolean;
|
|
744
|
+
|
|
745
|
+
// The following ensures only 1 transfer option is given.
|
|
746
|
+
} & ({
|
|
747
|
+
copy?: true;
|
|
748
|
+
externalCopy?: never;
|
|
749
|
+
reference?: never;
|
|
750
|
+
} | {
|
|
751
|
+
copy?: never;
|
|
752
|
+
externalCopy?: true;
|
|
753
|
+
reference?: never;
|
|
754
|
+
} | {
|
|
755
|
+
copy?: never;
|
|
756
|
+
externalCopy?: never;
|
|
757
|
+
reference?: true;
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
export type TransferOptionsBidirectional = {
|
|
761
|
+
/**
|
|
762
|
+
* `TransferOptions` for the values going *into* this isolate.
|
|
763
|
+
*/
|
|
764
|
+
arguments?: TransferOptions;
|
|
765
|
+
/**
|
|
766
|
+
* `TransferOptions` for the values coming *out* of this isolate.
|
|
767
|
+
*/
|
|
768
|
+
result?: TransferOptions;
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
// Discriminating types for TransferOptions
|
|
772
|
+
type WithPromise = { promise: true };
|
|
773
|
+
type AsCopy = { copy: true };
|
|
774
|
+
type AsExternal = { externalCopy: true };
|
|
775
|
+
type AsReference = { reference: true };
|
|
776
|
+
type FallbackReference = { _reference: true };
|
|
777
|
+
type ApplyAsReference = { result: AsReference };
|
|
778
|
+
type WithTransfer = AsCopy | AsExternal | AsReference;
|
|
779
|
+
|
|
780
|
+
// Wraps a type in Promise<> if the options specify { promise: true }
|
|
781
|
+
type CheckPromise<Options, Result> = Options extends WithPromise ? Promise<Result> : Result;
|
|
782
|
+
|
|
783
|
+
// Type of a single argument for functions that accept TransferOptions
|
|
784
|
+
type ArgumentType<Options, Type> =
|
|
785
|
+
(Options extends WithTransfer ? Type | CheckPromise<Options, Type> :
|
|
786
|
+
Type extends Transferable ? Type | CheckPromise<Options, Type> :
|
|
787
|
+
Transferable | CheckPromise<Options, Transferable>) |
|
|
788
|
+
Copy<Type> | Dereference<Type>;
|
|
789
|
+
|
|
790
|
+
// Return type for functions that accept TransferOptions
|
|
791
|
+
type ResultTypeBase<Options, Result> =
|
|
792
|
+
Options extends AsCopy ? Result :
|
|
793
|
+
Options extends AsExternal ? ExternalCopy<Result> :
|
|
794
|
+
Options extends AsReference ? Reference<Result> :
|
|
795
|
+
Result extends Transferable ? Result :
|
|
796
|
+
Result extends void ? void :
|
|
797
|
+
Options extends FallbackReference ? Reference<Result> :
|
|
798
|
+
Transferable;
|
|
799
|
+
type ResultTypeAsync<Options extends TransferOptions, Result = any> = Promise<ResultTypeBase<Options, Result>>;
|
|
800
|
+
type ResultTypeSync<Options extends TransferOptions, Result = any> = CheckPromise<Options, ResultTypeBase<Options, Result>>;
|
|
801
|
+
|
|
802
|
+
// Arguments type for functions that accept TransferOptionsBidirectional
|
|
803
|
+
type ArgumentsTypeBidirectional<Options extends TransferOptionsBidirectional, Args extends any[] = any[]> = {
|
|
804
|
+
[Key in keyof Args]: ArgumentType<Options['arguments'] extends TransferOptions ? Options['arguments'] : {}, Args[Key]>
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
// Result type for functions that accept TransferOptionsBidirectional
|
|
808
|
+
type ResultTypeBidirectionalBase<Options extends TransferOptionsBidirectional, Result> =
|
|
809
|
+
ResultTypeBase<Options['result'] extends TransferOptions ? Options['result'] : {}, Result>;
|
|
810
|
+
type ResultTypeBidirectionalAsync<Options extends TransferOptionsBidirectional, Result = any> =
|
|
811
|
+
Promise<ResultTypeBidirectionalBase<Options, Result>>;
|
|
812
|
+
type ResultTypeBidirectionalSync<Options extends TransferOptionsBidirectional, Result = any> =
|
|
813
|
+
CheckPromise<Options['result'], ResultTypeBidirectionalBase<Options, Result>>;
|
|
814
|
+
|
|
815
|
+
// Types for `Reference.apply`
|
|
816
|
+
type ApplyArguments<Value> = Value extends (...args: infer Args) => unknown ? Args : any[];
|
|
817
|
+
type ApplyArgumentThis<Value> = Value extends (this: infer This, ...args: any) => unknown ? This : undefined | null;
|
|
818
|
+
type ApplyResult<Value> = Value extends (...args: any) => infer Result ? Result : unknown;
|
|
819
|
+
}
|
|
820
|
+
export = IsolatedVM;
|