@jsii/kernel 1.62.0 → 1.63.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/lib/kernel.d.ts +2 -11
- package/lib/kernel.js +12 -42
- package/package.json +5 -5
package/lib/kernel.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export declare class Kernel {
|
|
|
13
13
|
private nextid;
|
|
14
14
|
private syncInProgress?;
|
|
15
15
|
private installDir?;
|
|
16
|
-
|
|
16
|
+
/** The internal require function, used instead of the global "require" so that webpack does not transform it... */
|
|
17
|
+
private require?;
|
|
17
18
|
/**
|
|
18
19
|
* Creates a jsii kernel object.
|
|
19
20
|
*
|
|
@@ -74,15 +75,5 @@ export declare class Kernel {
|
|
|
74
75
|
private _findPropertyTarget;
|
|
75
76
|
private _makecbid;
|
|
76
77
|
private _makeprid;
|
|
77
|
-
private _wrapSandboxCode;
|
|
78
|
-
/**
|
|
79
|
-
* Executes arbitrary code in a VM sandbox.
|
|
80
|
-
*
|
|
81
|
-
* @param code JavaScript code to be executed in the VM
|
|
82
|
-
* @param filename the file name to use for the executed code
|
|
83
|
-
*
|
|
84
|
-
* @returns the result of evaluating the code
|
|
85
|
-
*/
|
|
86
|
-
private _execute;
|
|
87
78
|
}
|
|
88
79
|
//# sourceMappingURL=kernel.d.ts.map
|
package/lib/kernel.js
CHANGED
|
@@ -5,10 +5,10 @@ const spec = require("@jsii/spec");
|
|
|
5
5
|
const spec_1 = require("@jsii/spec");
|
|
6
6
|
const cp = require("child_process");
|
|
7
7
|
const fs = require("fs-extra");
|
|
8
|
+
const module_1 = require("module");
|
|
8
9
|
const os = require("os");
|
|
9
10
|
const path = require("path");
|
|
10
11
|
const tar = require("tar");
|
|
11
|
-
const vm = require("vm");
|
|
12
12
|
const api = require("./api");
|
|
13
13
|
const api_1 = require("./api");
|
|
14
14
|
const objects_1 = require("./objects");
|
|
@@ -23,8 +23,6 @@ class Kernel {
|
|
|
23
23
|
* result (or throw an error).
|
|
24
24
|
*/
|
|
25
25
|
constructor(callbackHandler) {
|
|
26
|
-
// `setImmediate` is required for tests to pass (it is otherwise
|
|
27
|
-
// impossible to wait for in-VM promises to complete)
|
|
28
26
|
this.callbackHandler = callbackHandler;
|
|
29
27
|
/**
|
|
30
28
|
* Set to true for verbose debugging.
|
|
@@ -36,20 +34,6 @@ class Kernel {
|
|
|
36
34
|
this.waiting = new Map();
|
|
37
35
|
this.promises = new Map();
|
|
38
36
|
this.nextid = 20000; // incrementing counter for objid, cbid, promiseid
|
|
39
|
-
// `Buffer` is required when using simple-resource-bundler.
|
|
40
|
-
// HACK: when we webpack @jsii/runtime, all "require" statements get transpiled,
|
|
41
|
-
// so modules can be resolved within the pack. However, here we actually want to
|
|
42
|
-
// let loaded modules to use the native node "require" method.
|
|
43
|
-
// I wonder if webpack has some pragma that allows opting-out at certain points
|
|
44
|
-
// in the code.
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires
|
|
46
|
-
const moduleLoad = require('module').Module._load;
|
|
47
|
-
const nodeRequire = (p) => moduleLoad(p, module, false);
|
|
48
|
-
this.sandbox = vm.createContext({
|
|
49
|
-
Buffer,
|
|
50
|
-
setImmediate,
|
|
51
|
-
require: nodeRequire, // modules need to "require"
|
|
52
|
-
});
|
|
53
37
|
}
|
|
54
38
|
load(req) {
|
|
55
39
|
var _a, _b;
|
|
@@ -104,8 +88,8 @@ class Kernel {
|
|
|
104
88
|
catch (e) {
|
|
105
89
|
throw new Error(`Error for package tarball ${req.tarball}: ${e.message}`);
|
|
106
90
|
}
|
|
107
|
-
// load the module and capture
|
|
108
|
-
const closure = this.
|
|
91
|
+
// load the module and capture its closure
|
|
92
|
+
const closure = this.require(packageDir);
|
|
109
93
|
const assm = new Assembly(assmSpec, closure);
|
|
110
94
|
this._addAssembly(assm);
|
|
111
95
|
return {
|
|
@@ -164,7 +148,7 @@ class Kernel {
|
|
|
164
148
|
throw new Error(`property ${symbol} is not static`);
|
|
165
149
|
}
|
|
166
150
|
const prototype = this._findSymbol(fqn);
|
|
167
|
-
const value = this._ensureSync(`property ${property}`, () =>
|
|
151
|
+
const value = this._ensureSync(`property ${property}`, () => prototype[property]);
|
|
168
152
|
this._debug('value:', value);
|
|
169
153
|
const ret = this._fromSandbox(value, ti, `of static property ${symbol}`);
|
|
170
154
|
this._debug('ret', ret);
|
|
@@ -182,7 +166,7 @@ class Kernel {
|
|
|
182
166
|
throw new Error(`static property ${symbol} is readonly`);
|
|
183
167
|
}
|
|
184
168
|
const prototype = this._findSymbol(fqn);
|
|
185
|
-
this._ensureSync(`property ${property}`, () =>
|
|
169
|
+
this._ensureSync(`property ${property}`, () => (prototype[property] = this._toSandbox(value, ti, `assigned to static property ${symbol}`)));
|
|
186
170
|
return {};
|
|
187
171
|
}
|
|
188
172
|
get(req) {
|
|
@@ -198,7 +182,7 @@ class Kernel {
|
|
|
198
182
|
const propertyToGet = this._findPropertyTarget(instance, property);
|
|
199
183
|
// make the actual "get", and block any async calls that might be performed
|
|
200
184
|
// by jsii overrides.
|
|
201
|
-
const value = this._ensureSync(`property '${objref[api_1.TOKEN_REF]}.${propertyToGet}'`, () =>
|
|
185
|
+
const value = this._ensureSync(`property '${objref[api_1.TOKEN_REF]}.${propertyToGet}'`, () => instance[propertyToGet]);
|
|
202
186
|
this._debug('value:', value);
|
|
203
187
|
const ret = this._fromSandbox(value, ti, `of property ${fqn}.${property}`);
|
|
204
188
|
this._debug('ret:', ret);
|
|
@@ -213,7 +197,7 @@ class Kernel {
|
|
|
213
197
|
throw new Error(`Cannot set value of immutable property ${req.property} to ${req.value}`);
|
|
214
198
|
}
|
|
215
199
|
const propertyToSet = this._findPropertyTarget(instance, property);
|
|
216
|
-
this._ensureSync(`property '${objref[api_1.TOKEN_REF]}.${propertyToSet}'`, () =>
|
|
200
|
+
this._ensureSync(`property '${objref[api_1.TOKEN_REF]}.${propertyToSet}'`, () => (instance[propertyToSet] = this._toSandbox(value, propInfo, `assigned to property ${fqn}.${property}`)));
|
|
217
201
|
return {};
|
|
218
202
|
}
|
|
219
203
|
invoke(req) {
|
|
@@ -228,7 +212,7 @@ class Kernel {
|
|
|
228
212
|
}
|
|
229
213
|
const fqn = (0, objects_1.jsiiTypeFqn)(obj);
|
|
230
214
|
const ret = this._ensureSync(`method '${objref[api_1.TOKEN_REF]}.${method}'`, () => {
|
|
231
|
-
return
|
|
215
|
+
return fn.apply(obj, this._toSandboxValues(args, `method ${fqn ? `${fqn}#` : ''}${method}`, ti.parameters));
|
|
232
216
|
});
|
|
233
217
|
const result = this._fromSandbox(ret, (_b = ti.returns) !== null && _b !== void 0 ? _b : 'void', `returned by method ${fqn ? `${fqn}#` : ''}${method}`);
|
|
234
218
|
this._debug('invoke result', result);
|
|
@@ -250,7 +234,7 @@ class Kernel {
|
|
|
250
234
|
const prototype = this._findSymbol(fqn);
|
|
251
235
|
const fn = prototype[method];
|
|
252
236
|
const ret = this._ensureSync(`method '${fqn}.${method}'`, () => {
|
|
253
|
-
return
|
|
237
|
+
return fn.apply(prototype, this._toSandboxValues(args, `static method ${fqn}.${method}`, ti.parameters));
|
|
254
238
|
});
|
|
255
239
|
this._debug('method returned:', ret);
|
|
256
240
|
return {
|
|
@@ -271,7 +255,7 @@ class Kernel {
|
|
|
271
255
|
throw new Error(`Method ${method} is expected to be an async method`);
|
|
272
256
|
}
|
|
273
257
|
const fqn = (0, objects_1.jsiiTypeFqn)(obj);
|
|
274
|
-
const promise =
|
|
258
|
+
const promise = fn.apply(obj, this._toSandboxValues(args, `async method ${fqn ? `${fqn}#` : ''}${method}`, ti.parameters));
|
|
275
259
|
// since we are planning to resolve this promise in a different scope
|
|
276
260
|
// we need to handle rejections here [1]
|
|
277
261
|
// [1]: https://stackoverflow.com/questions/40920179/should-i-refrain-from-handling-promise-rejection-asynchronously/40921505
|
|
@@ -402,6 +386,7 @@ class Kernel {
|
|
|
402
386
|
_getPackageDir(pkgname) {
|
|
403
387
|
if (!this.installDir) {
|
|
404
388
|
this.installDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-kernel-'));
|
|
389
|
+
this.require = (0, module_1.createRequire)(this.installDir);
|
|
405
390
|
fs.mkdirpSync(path.join(this.installDir, 'node_modules'));
|
|
406
391
|
this._debug('creating jsii-kernel modules workdir:', this.installDir);
|
|
407
392
|
onExit.removeSync(this.installDir);
|
|
@@ -417,7 +402,7 @@ class Kernel {
|
|
|
417
402
|
const requestArgs = (_a = req.args) !== null && _a !== void 0 ? _a : [];
|
|
418
403
|
const ctorResult = this._findCtor(fqn, requestArgs);
|
|
419
404
|
const ctor = ctorResult.ctor;
|
|
420
|
-
const obj =
|
|
405
|
+
const obj = new ctor(...this._toSandboxValues(requestArgs, `new ${fqn}`, ctorResult.parameters));
|
|
421
406
|
const objref = this.objects.registerObject(obj, fqn, (_b = req.interfaces) !== null && _b !== void 0 ? _b : []);
|
|
422
407
|
// overrides: for each one of the override method names, installs a
|
|
423
408
|
// method on the newly created object which represents the remote "reverse proxy".
|
|
@@ -869,21 +854,6 @@ class Kernel {
|
|
|
869
854
|
_makeprid() {
|
|
870
855
|
return `jsii::promise::${this.nextid++}`;
|
|
871
856
|
}
|
|
872
|
-
_wrapSandboxCode(fn) {
|
|
873
|
-
return fn();
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* Executes arbitrary code in a VM sandbox.
|
|
877
|
-
*
|
|
878
|
-
* @param code JavaScript code to be executed in the VM
|
|
879
|
-
* @param filename the file name to use for the executed code
|
|
880
|
-
*
|
|
881
|
-
* @returns the result of evaluating the code
|
|
882
|
-
*/
|
|
883
|
-
_execute(code, filename) {
|
|
884
|
-
const script = new vm.Script(code, { filename });
|
|
885
|
-
return script.runInContext(this.sandbox, { displayErrors: true });
|
|
886
|
-
}
|
|
887
857
|
}
|
|
888
858
|
exports.Kernel = Kernel;
|
|
889
859
|
class Assembly {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsii/kernel",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.63.2",
|
|
4
4
|
"description": "kernel for jsii execution environment",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -31,17 +31,17 @@
|
|
|
31
31
|
"package": "package-js"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@jsii/spec": "^1.
|
|
34
|
+
"@jsii/spec": "^1.63.2",
|
|
35
35
|
"fs-extra": "^10.1.0",
|
|
36
36
|
"tar": "^6.1.11"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@scope/jsii-calc-base": "^1.
|
|
40
|
-
"@scope/jsii-calc-lib": "^1.
|
|
39
|
+
"@scope/jsii-calc-base": "^1.63.2",
|
|
40
|
+
"@scope/jsii-calc-lib": "^1.63.2",
|
|
41
41
|
"@types/fs-extra": "^9.0.13",
|
|
42
42
|
"@types/tar": "^6.1.1",
|
|
43
43
|
"jest-expect-message": "^1.0.2",
|
|
44
|
-
"jsii-build-tools": "^1.
|
|
44
|
+
"jsii-build-tools": "^1.63.2",
|
|
45
45
|
"jsii-calc": "^3.20.120"
|
|
46
46
|
}
|
|
47
47
|
}
|