@jsii/kernel 1.85.0 → 1.86.1

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.js CHANGED
@@ -1,8 +1,19 @@
1
1
  "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _Kernel_instances, _Kernel_assemblies, _Kernel_objects, _Kernel_cbs, _Kernel_waiting, _Kernel_promises, _Kernel_serializerHost, _Kernel_nextid, _Kernel_syncInProgress, _Kernel_installDir, _Kernel_require, _Kernel_load, _Kernel_addAssembly, _Kernel_findCtor, _Kernel_getPackageDir, _Kernel_create, _Kernel_getSuperPropertyName, _Kernel_applyPropertyOverride, _Kernel_defineOverridenProperty, _Kernel_applyMethodOverride, _Kernel_defineOverridenMethod, _Kernel_findInvokeTarget, _Kernel_validateMethodArguments, _Kernel_assemblyFor, _Kernel_findSymbol, _Kernel_typeInfoForFqn, _Kernel_isVisibleType, _Kernel_typeInfoForMethod, _Kernel_tryTypeInfoForMethod, _Kernel_tryTypeInfoForProperty, _Kernel_typeInfoForProperty, _Kernel_toSandbox, _Kernel_fromSandbox, _Kernel_toSandboxValues, _Kernel_fromSandboxValues, _Kernel_boxUnboxParameters, _Kernel_debug, _Kernel_debugTime, _Kernel_ensureSync, _Kernel_findPropertyTarget, _Kernel_getBinScriptCommand, _Kernel_makecbid, _Kernel_makeprid;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.Kernel = exports.RuntimeError = exports.JsiiFault = void 0;
4
16
  const spec = require("@jsii/spec");
5
- const spec_1 = require("@jsii/spec");
6
17
  const cp = require("child_process");
7
18
  const fs = require("fs-extra");
8
19
  const module_1 = require("module");
@@ -38,6 +49,7 @@ class Kernel {
38
49
  */
39
50
  constructor(callbackHandler) {
40
51
  this.callbackHandler = callbackHandler;
52
+ _Kernel_instances.add(this);
41
53
  /**
42
54
  * Set to true for verbose debugging.
43
55
  */
@@ -46,81 +58,37 @@ class Kernel {
46
58
  * Set to true for timing data to be emitted.
47
59
  */
48
60
  this.debugTimingEnabled = false;
49
- this.assemblies = new Map();
50
- this.objects = new objects_1.ObjectTable(this._typeInfoForFqn.bind(this));
51
- this.cbs = new Map();
52
- this.waiting = new Map();
53
- this.promises = new Map();
54
- this.nextid = 20000; // incrementing counter for objid, cbid, promiseid
61
+ /**
62
+ * Set to true to validate assemblies upon loading (slow).
63
+ */
64
+ this.validateAssemblies = false;
65
+ _Kernel_assemblies.set(this, new Map());
66
+ _Kernel_objects.set(this, new objects_1.ObjectTable(__classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForFqn).bind(this)));
67
+ _Kernel_cbs.set(this, new Map());
68
+ _Kernel_waiting.set(this, new Map());
69
+ _Kernel_promises.set(this, new Map());
70
+ _Kernel_serializerHost.set(this, void 0);
71
+ _Kernel_nextid.set(this, 20000); // incrementing counter for objid, cbid, promiseid
72
+ _Kernel_syncInProgress.set(this, void 0); // forbids async calls (begin) while processing sync calls (get/set/invoke)
73
+ _Kernel_installDir.set(this, void 0);
74
+ /** The internal require function, used instead of the global "require" so that webpack does not transform it... */
75
+ _Kernel_require.set(this, void 0);
76
+ __classPrivateFieldSet(this, _Kernel_serializerHost, {
77
+ objects: __classPrivateFieldGet(this, _Kernel_objects, "f"),
78
+ debug: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).bind(this),
79
+ isVisibleType: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_isVisibleType).bind(this),
80
+ findSymbol: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findSymbol).bind(this),
81
+ lookupType: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForFqn).bind(this),
82
+ }, "f");
55
83
  }
56
84
  load(req) {
57
- return this._debugTime(() => this._load(req), `load(${JSON.stringify(req, null, 2)})`);
58
- }
59
- _load(req) {
60
- var _a, _b, _c;
61
- this._debug('load', req);
62
- if ('assembly' in req) {
63
- throw new JsiiFault('`assembly` field is deprecated for "load", use `name`, `version` and `tarball` instead');
64
- }
65
- const pkgname = req.name;
66
- const pkgver = req.version;
67
- // check if we already have such a module
68
- const packageDir = this._getPackageDir(pkgname);
69
- if (fs.pathExistsSync(packageDir)) {
70
- // module exists, verify version
71
- const epkg = fs.readJsonSync(path.join(packageDir, 'package.json'));
72
- if (epkg.version !== pkgver) {
73
- throw new JsiiFault(`Multiple versions ${pkgver} and ${epkg.version} of the ` +
74
- `package '${pkgname}' cannot be loaded together since this is unsupported by ` +
75
- 'some runtime environments');
76
- }
77
- // same version, no-op
78
- this._debug('look up already-loaded assembly', pkgname);
79
- const assm = this.assemblies.get(pkgname);
80
- return {
81
- assembly: assm.metadata.name,
82
- types: Object.keys((_a = assm.metadata.types) !== null && _a !== void 0 ? _a : {}).length,
83
- };
84
- }
85
- // Force umask to have npm-install-like permissions
86
- const originalUmask = process.umask(0o022);
87
- try {
88
- // untar the archive to its final location
89
- const { cache } = this._debugTime(() => tar.extract(req.tarball, packageDir, {
90
- strict: true,
91
- strip: 1,
92
- unlink: true,
93
- }, req.name, req.version), `tar.extract(${req.tarball}) => ${packageDir}`);
94
- if (cache != null) {
95
- this._debug(`Package cache enabled, extraction resulted in a cache ${cache}`);
96
- }
97
- }
98
- finally {
99
- // Reset umask to the initial value
100
- process.umask(originalUmask);
101
- }
102
- // read .jsii metadata from the root of the package
103
- let assmSpec;
104
- try {
105
- assmSpec = this._debugTime(() => (0, spec_1.loadAssemblyFromPath)(packageDir), `loadAssemblyFromPath(${packageDir})`);
106
- }
107
- catch (e) {
108
- throw new JsiiFault(`Error for package tarball ${req.tarball}: ${e.message}`);
109
- }
110
- // load the module and capture its closure
111
- const closure = this._debugTime(() => this.require(packageDir), `require(${packageDir})`);
112
- const assm = new Assembly(assmSpec, closure);
113
- this._debugTime(() => this._addAssembly(assm), `registerAssembly({ name: ${assm.metadata.name}, types: ${Object.keys((_b = assm.metadata.types) !== null && _b !== void 0 ? _b : {}).length} })`);
114
- return {
115
- assembly: assmSpec.name,
116
- types: Object.keys((_c = assmSpec.types) !== null && _c !== void 0 ? _c : {}).length,
117
- };
85
+ return __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debugTime).call(this, () => __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_load).call(this, req), `load(${JSON.stringify(req, null, 2)})`);
118
86
  }
119
87
  getBinScriptCommand(req) {
120
- return this._getBinScriptCommand(req);
88
+ return __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_getBinScriptCommand).call(this, req);
121
89
  }
122
90
  invokeBinScript(req) {
123
- const { command, args, env } = this._getBinScriptCommand(req);
91
+ const { command, args, env } = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_getBinScriptCommand).call(this, req);
124
92
  const result = cp.spawnSync(command, args, {
125
93
  encoding: 'utf-8',
126
94
  env,
@@ -134,99 +102,99 @@ class Kernel {
134
102
  };
135
103
  }
136
104
  create(req) {
137
- return this._create(req);
105
+ return __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_create).call(this, req);
138
106
  }
139
107
  del(req) {
140
108
  const { objref } = req;
141
- this._debug('del', objref);
142
- this.objects.deleteObject(objref);
109
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'del', objref);
110
+ __classPrivateFieldGet(this, _Kernel_objects, "f").deleteObject(objref);
143
111
  return {};
144
112
  }
145
113
  sget(req) {
146
114
  const { fqn, property } = req;
147
115
  const symbol = `${fqn}.${property}`;
148
- this._debug('sget', symbol);
149
- const ti = this._typeInfoForProperty(property, fqn);
116
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'sget', symbol);
117
+ const ti = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForProperty).call(this, property, fqn);
150
118
  if (!ti.static) {
151
119
  throw new JsiiFault(`property ${symbol} is not static`);
152
120
  }
153
- const prototype = this._findSymbol(fqn);
154
- const value = this._ensureSync(`property ${property}`, () => prototype[property]);
155
- this._debug('value:', value);
156
- const ret = this._fromSandbox(value, ti, `of static property ${symbol}`);
157
- this._debug('ret', ret);
121
+ const prototype = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findSymbol).call(this, fqn);
122
+ const value = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_ensureSync).call(this, `property ${property}`, () => prototype[property]);
123
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'value:', value);
124
+ const ret = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_fromSandbox).call(this, value, ti, `of static property ${symbol}`);
125
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'ret', ret);
158
126
  return { value: ret };
159
127
  }
160
128
  sset(req) {
161
129
  const { fqn, property, value } = req;
162
130
  const symbol = `${fqn}.${property}`;
163
- this._debug('sset', symbol);
164
- const ti = this._typeInfoForProperty(property, fqn);
131
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'sset', symbol);
132
+ const ti = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForProperty).call(this, property, fqn);
165
133
  if (!ti.static) {
166
134
  throw new JsiiFault(`property ${symbol} is not static`);
167
135
  }
168
136
  if (ti.immutable) {
169
137
  throw new JsiiFault(`static property ${symbol} is readonly`);
170
138
  }
171
- const prototype = this._findSymbol(fqn);
172
- this._ensureSync(`property ${property}`, () => (prototype[property] = this._toSandbox(value, ti, `assigned to static property ${symbol}`)));
139
+ const prototype = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findSymbol).call(this, fqn);
140
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_ensureSync).call(this, `property ${property}`, () => (prototype[property] = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandbox).call(this, value, ti, `assigned to static property ${symbol}`)));
173
141
  return {};
174
142
  }
175
143
  get(req) {
176
144
  const { objref, property } = req;
177
- this._debug('get', objref, property);
178
- const { instance, fqn, interfaces } = this.objects.findObject(objref);
179
- const ti = this._typeInfoForProperty(property, fqn, interfaces);
145
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'get', objref, property);
146
+ const { instance, fqn, interfaces } = __classPrivateFieldGet(this, _Kernel_objects, "f").findObject(objref);
147
+ const ti = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForProperty).call(this, property, fqn, interfaces);
180
148
  // if the property is overridden by the native code and "get" is called on the object, it
181
149
  // means that the native code is trying to access the "super" property. in order to enable
182
150
  // that, we actually keep a copy of the original property descriptor when we override,
183
151
  // so `findPropertyTarget` will return either the original property name ("property") or
184
152
  // the "super" property name (somehing like "$jsii$super$<property>$").
185
- const propertyToGet = this._findPropertyTarget(instance, property);
153
+ const propertyToGet = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findPropertyTarget).call(this, instance, property);
186
154
  // make the actual "get", and block any async calls that might be performed
187
155
  // by jsii overrides.
188
- const value = this._ensureSync(`property '${objref[api_1.TOKEN_REF]}.${propertyToGet}'`, () => instance[propertyToGet]);
189
- this._debug('value:', value);
190
- const ret = this._fromSandbox(value, ti, `of property ${fqn}.${property}`);
191
- this._debug('ret:', ret);
156
+ const value = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_ensureSync).call(this, `property '${objref[api_1.TOKEN_REF]}.${propertyToGet}'`, () => instance[propertyToGet]);
157
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'value:', value);
158
+ const ret = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_fromSandbox).call(this, value, ti, `of property ${fqn}.${property}`);
159
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'ret:', ret);
192
160
  return { value: ret };
193
161
  }
194
162
  set(req) {
195
163
  const { objref, property, value } = req;
196
- this._debug('set', objref, property, value);
197
- const { instance, fqn, interfaces } = this.objects.findObject(objref);
198
- const propInfo = this._typeInfoForProperty(req.property, fqn, interfaces);
164
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'set', objref, property, value);
165
+ const { instance, fqn, interfaces } = __classPrivateFieldGet(this, _Kernel_objects, "f").findObject(objref);
166
+ const propInfo = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForProperty).call(this, req.property, fqn, interfaces);
199
167
  if (propInfo.immutable) {
200
168
  throw new JsiiFault(`Cannot set value of immutable property ${req.property} to ${req.value}`);
201
169
  }
202
- const propertyToSet = this._findPropertyTarget(instance, property);
203
- this._ensureSync(`property '${objref[api_1.TOKEN_REF]}.${propertyToSet}'`, () => (instance[propertyToSet] = this._toSandbox(value, propInfo, `assigned to property ${fqn}.${property}`)));
170
+ const propertyToSet = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findPropertyTarget).call(this, instance, property);
171
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_ensureSync).call(this, `property '${objref[api_1.TOKEN_REF]}.${propertyToSet}'`, () => (instance[propertyToSet] = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandbox).call(this, value, propInfo, `assigned to property ${fqn}.${property}`)));
204
172
  return {};
205
173
  }
206
174
  invoke(req) {
207
175
  var _a, _b;
208
176
  const { objref, method } = req;
209
177
  const args = (_a = req.args) !== null && _a !== void 0 ? _a : [];
210
- this._debug('invoke', objref, method, args);
211
- const { ti, obj, fn } = this._findInvokeTarget(objref, method, args);
178
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'invoke', objref, method, args);
179
+ const { ti, obj, fn } = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findInvokeTarget).call(this, objref, method, args);
212
180
  // verify this is not an async method
213
181
  if (ti.async) {
214
182
  throw new JsiiFault(`${method} is an async method, use "begin" instead`);
215
183
  }
216
- const fqn = (0, objects_1.jsiiTypeFqn)(obj);
217
- const ret = this._ensureSync(`method '${objref[api_1.TOKEN_REF]}.${method}'`, () => {
218
- return fn.apply(obj, this._toSandboxValues(args, `method ${fqn ? `${fqn}#` : ''}${method}`, ti.parameters));
184
+ const fqn = (0, objects_1.jsiiTypeFqn)(obj, __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_isVisibleType).bind(this));
185
+ const ret = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_ensureSync).call(this, `method '${objref[api_1.TOKEN_REF]}.${method}'`, () => {
186
+ return fn.apply(obj, __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandboxValues).call(this, args, `method ${fqn ? `${fqn}#` : ''}${method}`, ti.parameters));
219
187
  });
220
- const result = this._fromSandbox(ret, (_b = ti.returns) !== null && _b !== void 0 ? _b : 'void', `returned by method ${fqn ? `${fqn}#` : ''}${method}`);
221
- this._debug('invoke result', result);
188
+ const result = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_fromSandbox).call(this, ret, (_b = ti.returns) !== null && _b !== void 0 ? _b : 'void', `returned by method ${fqn ? `${fqn}#` : ''}${method}`);
189
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'invoke result', result);
222
190
  return { result };
223
191
  }
224
192
  sinvoke(req) {
225
193
  var _a, _b;
226
194
  const { fqn, method } = req;
227
195
  const args = (_a = req.args) !== null && _a !== void 0 ? _a : [];
228
- this._debug('sinvoke', fqn, method, args);
229
- const ti = this._typeInfoForMethod(method, fqn);
196
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'sinvoke', fqn, method, args);
197
+ const ti = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForMethod).call(this, method, fqn);
230
198
  if (!ti.static) {
231
199
  throw new JsiiFault(`${fqn}.${method} is not a static method`);
232
200
  }
@@ -234,37 +202,37 @@ class Kernel {
234
202
  if (ti.async) {
235
203
  throw new JsiiFault(`${method} is an async method, use "begin" instead`);
236
204
  }
237
- const prototype = this._findSymbol(fqn);
205
+ const prototype = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findSymbol).call(this, fqn);
238
206
  const fn = prototype[method];
239
- const ret = this._ensureSync(`method '${fqn}.${method}'`, () => {
240
- return fn.apply(prototype, this._toSandboxValues(args, `static method ${fqn}.${method}`, ti.parameters));
207
+ const ret = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_ensureSync).call(this, `method '${fqn}.${method}'`, () => {
208
+ return fn.apply(prototype, __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandboxValues).call(this, args, `static method ${fqn}.${method}`, ti.parameters));
241
209
  });
242
- this._debug('method returned:', ret);
210
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'method returned:', ret);
243
211
  return {
244
- result: this._fromSandbox(ret, (_b = ti.returns) !== null && _b !== void 0 ? _b : 'void', `returned by static method ${fqn}.${method}`),
212
+ result: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_fromSandbox).call(this, ret, (_b = ti.returns) !== null && _b !== void 0 ? _b : 'void', `returned by static method ${fqn}.${method}`),
245
213
  };
246
214
  }
247
215
  begin(req) {
248
216
  var _a;
249
217
  const { objref, method } = req;
250
218
  const args = (_a = req.args) !== null && _a !== void 0 ? _a : [];
251
- this._debug('begin', objref, method, args);
252
- if (this.syncInProgress) {
253
- throw new JsiiFault(`Cannot invoke async method '${req.objref[api_1.TOKEN_REF]}.${req.method}' while sync ${this.syncInProgress} is being processed`);
219
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'begin', objref, method, args);
220
+ if (__classPrivateFieldGet(this, _Kernel_syncInProgress, "f")) {
221
+ throw new JsiiFault(`Cannot invoke async method '${req.objref[api_1.TOKEN_REF]}.${req.method}' while sync ${__classPrivateFieldGet(this, _Kernel_syncInProgress, "f")} is being processed`);
254
222
  }
255
- const { ti, obj, fn } = this._findInvokeTarget(objref, method, args);
223
+ const { ti, obj, fn } = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findInvokeTarget).call(this, objref, method, args);
256
224
  // verify this is indeed an async method
257
225
  if (!ti.async) {
258
226
  throw new JsiiFault(`Method ${method} is expected to be an async method`);
259
227
  }
260
- const fqn = (0, objects_1.jsiiTypeFqn)(obj);
261
- const promise = fn.apply(obj, this._toSandboxValues(args, `async method ${fqn ? `${fqn}#` : ''}${method}`, ti.parameters));
228
+ const fqn = (0, objects_1.jsiiTypeFqn)(obj, __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_isVisibleType).bind(this));
229
+ const promise = fn.apply(obj, __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandboxValues).call(this, args, `async method ${fqn ? `${fqn}#` : ''}${method}`, ti.parameters));
262
230
  // since we are planning to resolve this promise in a different scope
263
231
  // we need to handle rejections here [1]
264
232
  // [1]: https://stackoverflow.com/questions/40920179/should-i-refrain-from-handling-promise-rejection-asynchronously/40921505
265
233
  promise.catch((_) => undefined);
266
- const prid = this._makeprid();
267
- this.promises.set(prid, {
234
+ const prid = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_makeprid).call(this);
235
+ __classPrivateFieldGet(this, _Kernel_promises, "f").set(prid, {
268
236
  promise,
269
237
  method: ti,
270
238
  });
@@ -273,8 +241,8 @@ class Kernel {
273
241
  async end(req) {
274
242
  var _a;
275
243
  const { promiseid } = req;
276
- this._debug('end', promiseid);
277
- const storedPromise = this.promises.get(promiseid);
244
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'end', promiseid);
245
+ const storedPromise = __classPrivateFieldGet(this, _Kernel_promises, "f").get(promiseid);
278
246
  if (storedPromise == null) {
279
247
  throw new JsiiFault(`Cannot find promise with ID: ${promiseid}`);
280
248
  }
@@ -282,10 +250,10 @@ class Kernel {
282
250
  let result;
283
251
  try {
284
252
  result = await promise;
285
- this._debug('promise result:', result);
253
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'promise result:', result);
286
254
  }
287
255
  catch (e) {
288
- this._debug('promise error:', e);
256
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'promise error:', e);
289
257
  if (e.name === "@jsii/kernel.Fault" /* JsiiErrorType.JSII_FAULT */) {
290
258
  if (e instanceof JsiiFault) {
291
259
  throw e;
@@ -300,14 +268,14 @@ class Kernel {
300
268
  throw new RuntimeError(e);
301
269
  }
302
270
  return {
303
- result: this._fromSandbox(result, (_a = method.returns) !== null && _a !== void 0 ? _a : 'void', `returned by async method ${method.name}`),
271
+ result: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_fromSandbox).call(this, result, (_a = method.returns) !== null && _a !== void 0 ? _a : 'void', `returned by async method ${method.name}`),
304
272
  };
305
273
  }
306
274
  callbacks(_req) {
307
- this._debug('callbacks');
308
- const ret = Array.from(this.cbs.entries()).map(([cbid, cb]) => {
309
- this.waiting.set(cbid, cb); // move to waiting
310
- this.cbs.delete(cbid); // remove from created
275
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'callbacks');
276
+ const ret = Array.from(__classPrivateFieldGet(this, _Kernel_cbs, "f").entries()).map(([cbid, cb]) => {
277
+ __classPrivateFieldGet(this, _Kernel_waiting, "f").set(cbid, cb); // move to waiting
278
+ __classPrivateFieldGet(this, _Kernel_cbs, "f").delete(cbid); // remove from created
311
279
  const callback = {
312
280
  cbid,
313
281
  cookie: cb.override.cookie,
@@ -324,23 +292,25 @@ class Kernel {
324
292
  complete(req) {
325
293
  var _a;
326
294
  const { cbid, err, result, name } = req;
327
- this._debug('complete', cbid, err, result);
328
- const cb = this.waiting.get(cbid);
295
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'complete', cbid, err, result);
296
+ const cb = __classPrivateFieldGet(this, _Kernel_waiting, "f").get(cbid);
329
297
  if (!cb) {
330
298
  throw new JsiiFault(`Callback ${cbid} not found`);
331
299
  }
332
300
  if (err) {
333
- this._debug('completed with error:', err);
301
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'completed with error:', err);
334
302
  cb.fail(name === "@jsii/kernel.Fault" /* JsiiErrorType.JSII_FAULT */
335
303
  ? new JsiiFault(err)
336
304
  : new RuntimeError(err));
337
305
  }
338
306
  else {
339
- const sandoxResult = this._toSandbox(result, (_a = cb.expectedReturnType) !== null && _a !== void 0 ? _a : 'void', `returned by callback ${cb.toString()}`);
340
- this._debug('completed with result:', sandoxResult);
307
+ const sandoxResult = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandbox).call(this, result, (_a = cb.expectedReturnType) !== null && _a !== void 0 ? _a : 'void',
308
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
309
+ `returned by callback ${cb.toString()}`);
310
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'completed with result:', sandoxResult);
341
311
  cb.succeed(sandoxResult);
342
312
  }
343
- this.waiting.delete(cbid);
313
+ __classPrivateFieldGet(this, _Kernel_waiting, "f").delete(cbid);
344
314
  return { cbid };
345
315
  }
346
316
  /**
@@ -349,8 +319,8 @@ class Kernel {
349
319
  */
350
320
  naming(req) {
351
321
  const assemblyName = req.assembly;
352
- this._debug('naming', assemblyName);
353
- const assembly = this._assemblyFor(assemblyName);
322
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'naming', assemblyName);
323
+ const assembly = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_assemblyFor).call(this, assemblyName);
354
324
  const targets = assembly.metadata.targets;
355
325
  if (!targets) {
356
326
  throw new JsiiFault(`Unexpected - "targets" for ${assemblyName} is missing!`);
@@ -359,575 +329,612 @@ class Kernel {
359
329
  }
360
330
  stats(_req) {
361
331
  return {
362
- objectCount: this.objects.count,
332
+ objectCount: __classPrivateFieldGet(this, _Kernel_objects, "f").count,
363
333
  };
364
334
  }
365
- _addAssembly(assm) {
366
- var _a;
367
- this.assemblies.set(assm.metadata.name, assm);
368
- // add the __jsii__.fqn property on every constructor. this allows
369
- // traversing between the javascript and jsii worlds given any object.
370
- for (const fqn of Object.keys((_a = assm.metadata.types) !== null && _a !== void 0 ? _a : {})) {
371
- const typedef = assm.metadata.types[fqn];
372
- switch (typedef.kind) {
373
- case spec.TypeKind.Interface:
374
- continue; // interfaces don't really exist
375
- case spec.TypeKind.Class:
376
- case spec.TypeKind.Enum:
377
- const constructor = this._findSymbol(fqn);
378
- (0, objects_1.tagJsiiConstructor)(constructor, fqn);
379
- }
380
- }
335
+ }
336
+ exports.Kernel = Kernel;
337
+ _Kernel_assemblies = new WeakMap(), _Kernel_objects = new WeakMap(), _Kernel_cbs = new WeakMap(), _Kernel_waiting = new WeakMap(), _Kernel_promises = new WeakMap(), _Kernel_serializerHost = new WeakMap(), _Kernel_nextid = new WeakMap(), _Kernel_syncInProgress = new WeakMap(), _Kernel_installDir = new WeakMap(), _Kernel_require = new WeakMap(), _Kernel_instances = new WeakSet(), _Kernel_load = function _Kernel_load(req) {
338
+ var _a, _b, _c;
339
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'load', req);
340
+ if ('assembly' in req) {
341
+ throw new JsiiFault('`assembly` field is deprecated for "load", use `name`, `version` and `tarball` instead');
342
+ }
343
+ const pkgname = req.name;
344
+ const pkgver = req.version;
345
+ // check if we already have such a module
346
+ const packageDir = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_getPackageDir).call(this, pkgname);
347
+ if (fs.pathExistsSync(packageDir)) {
348
+ // module exists, verify version
349
+ const epkg = fs.readJsonSync(path.join(packageDir, 'package.json'));
350
+ if (epkg.version !== pkgver) {
351
+ throw new JsiiFault(`Multiple versions ${pkgver} and ${epkg.version} of the ` +
352
+ `package '${pkgname}' cannot be loaded together since this is unsupported by ` +
353
+ 'some runtime environments');
354
+ }
355
+ // same version, no-op
356
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'look up already-loaded assembly', pkgname);
357
+ const assm = __classPrivateFieldGet(this, _Kernel_assemblies, "f").get(pkgname);
358
+ return {
359
+ assembly: assm.metadata.name,
360
+ types: Object.keys((_a = assm.metadata.types) !== null && _a !== void 0 ? _a : {}).length,
361
+ };
381
362
  }
382
- // find the javascript constructor function for a jsii FQN.
383
- _findCtor(fqn, args) {
384
- if (fqn === wire.EMPTY_OBJECT_FQN) {
385
- return { ctor: Object };
386
- }
387
- const typeinfo = this._typeInfoForFqn(fqn);
388
- switch (typeinfo.kind) {
389
- case spec.TypeKind.Class:
390
- const classType = typeinfo;
391
- this._validateMethodArguments(classType.initializer, args);
392
- return {
393
- ctor: this._findSymbol(fqn),
394
- parameters: classType.initializer && classType.initializer.parameters,
395
- };
363
+ // Force umask to have npm-install-like permissions
364
+ const originalUmask = process.umask(0o022);
365
+ try {
366
+ // untar the archive to its final location
367
+ const { cache } = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debugTime).call(this, () => tar.extract(req.tarball, packageDir, {
368
+ strict: true,
369
+ strip: 1,
370
+ unlink: true,
371
+ }, req.name, req.version), `tar.extract(${req.tarball}) => ${packageDir}`);
372
+ if (cache != null) {
373
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, `Package cache enabled, extraction resulted in a cache ${cache}`);
374
+ }
375
+ }
376
+ finally {
377
+ // Reset umask to the initial value
378
+ process.umask(originalUmask);
379
+ }
380
+ // read .jsii metadata from the root of the package
381
+ let assmSpec;
382
+ try {
383
+ assmSpec = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debugTime).call(this, () => spec.loadAssemblyFromPath(packageDir, this.validateAssemblies), `loadAssemblyFromPath(${packageDir})`);
384
+ }
385
+ catch (e) {
386
+ throw new JsiiFault(`Error for package tarball ${req.tarball}: ${e.message}`);
387
+ }
388
+ // We do a `require.resolve` call, as otherwise, requiring with a directory will cause any `exports` from
389
+ // `package.json` to be ignored, preventing injection of a "lazy index" entry point.
390
+ const entryPoint = __classPrivateFieldGet(this, _Kernel_require, "f").resolve(assmSpec.name, {
391
+ paths: [__classPrivateFieldGet(this, _Kernel_installDir, "f")],
392
+ });
393
+ // load the module and capture its closure
394
+ const closure = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debugTime).call(this, () => __classPrivateFieldGet(this, _Kernel_require, "f")(entryPoint), `require(${entryPoint})`);
395
+ const assm = new Assembly(assmSpec, closure);
396
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debugTime).call(this, () => __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_addAssembly).call(this, assm), `registerAssembly({ name: ${assm.metadata.name}, types: ${Object.keys((_b = assm.metadata.types) !== null && _b !== void 0 ? _b : {}).length} })`);
397
+ return {
398
+ assembly: assmSpec.name,
399
+ types: Object.keys((_c = assmSpec.types) !== null && _c !== void 0 ? _c : {}).length,
400
+ };
401
+ }, _Kernel_addAssembly = function _Kernel_addAssembly(assm) {
402
+ var _a;
403
+ __classPrivateFieldGet(this, _Kernel_assemblies, "f").set(assm.metadata.name, assm);
404
+ // We can use jsii runtime type information from jsii 1.19.0 onwards... Note that a version of
405
+ // 0.0.0 means we are assessing against a development tree, which is newer...
406
+ const jsiiVersion = assm.metadata.jsiiVersion.split(' ', 1)[0];
407
+ const [jsiiMajor, jsiiMinor, _jsiiPatch, ..._rest] = jsiiVersion
408
+ .split('.')
409
+ .map((str) => parseInt(str, 10));
410
+ if (jsiiVersion === '0.0.0' ||
411
+ jsiiMajor > 1 ||
412
+ (jsiiMajor === 1 && jsiiMinor >= 19)) {
413
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'Using compiler-woven runtime type information!');
414
+ return;
415
+ }
416
+ // add the __jsii__.fqn property on every constructor. this allows
417
+ // traversing between the javascript and jsii worlds given any object.
418
+ for (const fqn of Object.keys((_a = assm.metadata.types) !== null && _a !== void 0 ? _a : {})) {
419
+ const typedef = assm.metadata.types[fqn];
420
+ switch (typedef.kind) {
396
421
  case spec.TypeKind.Interface:
397
- throw new JsiiFault(`Cannot create an object with an FQN of an interface: ${fqn}`);
398
- default:
399
- throw new JsiiFault(`Unexpected FQN kind: ${fqn}`);
422
+ continue; // interfaces don't really exist
423
+ case spec.TypeKind.Class:
424
+ case spec.TypeKind.Enum:
425
+ const constructor = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findSymbol).call(this, fqn);
426
+ (0, objects_1.tagJsiiConstructor)(constructor, fqn);
400
427
  }
401
428
  }
402
- _getPackageDir(pkgname) {
403
- if (!this.installDir) {
404
- this.installDir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-kernel-'));
405
- this.require = (0, module_1.createRequire)(this.installDir);
406
- fs.mkdirpSync(path.join(this.installDir, 'node_modules'));
407
- this._debug('creating jsii-kernel modules workdir:', this.installDir);
408
- onExit.removeSync(this.installDir);
409
- }
410
- return path.join(this.installDir, 'node_modules', pkgname);
429
+ }, _Kernel_findCtor = function _Kernel_findCtor(fqn, args) {
430
+ if (fqn === wire.EMPTY_OBJECT_FQN) {
431
+ return { ctor: Object };
411
432
  }
412
- // prefixed with _ to allow calling this method internally without
413
- // getting it recorded for testing.
414
- _create(req) {
415
- var _a, _b;
416
- this._debug('create', req);
417
- const { fqn, interfaces, overrides } = req;
418
- const requestArgs = (_a = req.args) !== null && _a !== void 0 ? _a : [];
419
- const ctorResult = this._findCtor(fqn, requestArgs);
420
- const ctor = ctorResult.ctor;
421
- const obj = new ctor(...this._toSandboxValues(requestArgs, `new ${fqn}`, ctorResult.parameters));
422
- const objref = this.objects.registerObject(obj, fqn, (_b = req.interfaces) !== null && _b !== void 0 ? _b : []);
423
- // overrides: for each one of the override method names, installs a
424
- // method on the newly created object which represents the remote "reverse proxy".
425
- if (overrides) {
426
- this._debug('overrides', overrides);
427
- const overrideTypeErrorMessage = 'Override can either be "method" or "property"';
428
- const methods = new Set();
429
- const properties = new Set();
430
- for (const override of overrides) {
431
- if (api.isMethodOverride(override)) {
432
- if (api.isPropertyOverride(override)) {
433
- throw new JsiiFault(overrideTypeErrorMessage);
434
- }
435
- if (methods.has(override.method)) {
436
- throw new JsiiFault(`Duplicate override for method '${override.method}'`);
437
- }
438
- methods.add(override.method);
439
- this._applyMethodOverride(obj, objref, fqn, interfaces, override);
433
+ const typeinfo = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForFqn).call(this, fqn);
434
+ switch (typeinfo.kind) {
435
+ case spec.TypeKind.Class:
436
+ const classType = typeinfo;
437
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_validateMethodArguments).call(this, classType.initializer, args);
438
+ return {
439
+ ctor: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findSymbol).call(this, fqn),
440
+ parameters: classType.initializer && classType.initializer.parameters,
441
+ };
442
+ case spec.TypeKind.Interface:
443
+ throw new JsiiFault(`Cannot create an object with an FQN of an interface: ${fqn}`);
444
+ default:
445
+ throw new JsiiFault(`Unexpected FQN kind: ${fqn}`);
446
+ }
447
+ }, _Kernel_getPackageDir = function _Kernel_getPackageDir(pkgname) {
448
+ if (!__classPrivateFieldGet(this, _Kernel_installDir, "f")) {
449
+ __classPrivateFieldSet(this, _Kernel_installDir, fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-kernel-')), "f");
450
+ __classPrivateFieldSet(this, _Kernel_require, (0, module_1.createRequire)(__classPrivateFieldGet(this, _Kernel_installDir, "f")), "f");
451
+ fs.mkdirpSync(path.join(__classPrivateFieldGet(this, _Kernel_installDir, "f"), 'node_modules'));
452
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'creating jsii-kernel modules workdir:', __classPrivateFieldGet(this, _Kernel_installDir, "f"));
453
+ onExit.removeSync(__classPrivateFieldGet(this, _Kernel_installDir, "f"));
454
+ }
455
+ return path.join(__classPrivateFieldGet(this, _Kernel_installDir, "f"), 'node_modules', pkgname);
456
+ }, _Kernel_create = function _Kernel_create(req) {
457
+ var _a, _b;
458
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'create', req);
459
+ const { fqn, interfaces, overrides } = req;
460
+ const requestArgs = (_a = req.args) !== null && _a !== void 0 ? _a : [];
461
+ const ctorResult = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_findCtor).call(this, fqn, requestArgs);
462
+ const ctor = ctorResult.ctor;
463
+ const obj = new ctor(...__classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandboxValues).call(this, requestArgs, `new ${fqn}`, ctorResult.parameters));
464
+ const objref = __classPrivateFieldGet(this, _Kernel_objects, "f").registerObject(obj, fqn, (_b = req.interfaces) !== null && _b !== void 0 ? _b : []);
465
+ // overrides: for each one of the override method names, installs a
466
+ // method on the newly created object which represents the remote "reverse proxy".
467
+ if (overrides) {
468
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'overrides', overrides);
469
+ const overrideTypeErrorMessage = 'Override can either be "method" or "property"';
470
+ const methods = new Set();
471
+ const properties = new Set();
472
+ for (const override of overrides) {
473
+ if (api.isMethodOverride(override)) {
474
+ if (api.isPropertyOverride(override)) {
475
+ throw new JsiiFault(overrideTypeErrorMessage);
440
476
  }
441
- else if (api.isPropertyOverride(override)) {
442
- if (api.isMethodOverride(override)) {
443
- throw new JsiiFault(overrideTypeErrorMessage);
444
- }
445
- if (properties.has(override.property)) {
446
- throw new JsiiFault(`Duplicate override for property '${override.property}'`);
447
- }
448
- properties.add(override.property);
449
- this._applyPropertyOverride(obj, objref, fqn, interfaces, override);
477
+ if (methods.has(override.method)) {
478
+ throw new JsiiFault(`Duplicate override for method '${override.method}'`);
450
479
  }
451
- else {
480
+ methods.add(override.method);
481
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_applyMethodOverride).call(this, obj, objref, fqn, interfaces, override);
482
+ }
483
+ else if (api.isPropertyOverride(override)) {
484
+ if (api.isMethodOverride(override)) {
452
485
  throw new JsiiFault(overrideTypeErrorMessage);
453
486
  }
487
+ if (properties.has(override.property)) {
488
+ throw new JsiiFault(`Duplicate override for property '${override.property}'`);
489
+ }
490
+ properties.add(override.property);
491
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_applyPropertyOverride).call(this, obj, objref, fqn, interfaces, override);
492
+ }
493
+ else {
494
+ throw new JsiiFault(overrideTypeErrorMessage);
454
495
  }
455
496
  }
456
- return objref;
457
- }
458
- _getSuperPropertyName(name) {
459
- return `$jsii$super$${name}$`;
460
- }
461
- _applyPropertyOverride(obj, objref, typeFqn, interfaces, override) {
462
- // error if we can find a method with this name
463
- if (this._tryTypeInfoForMethod(override.property, typeFqn, interfaces)) {
464
- throw new JsiiFault(`Trying to override method '${override.property}' as a property`);
465
- }
466
- let propInfo = this._tryTypeInfoForProperty(override.property, typeFqn, interfaces);
467
- // if this is a private property (i.e. doesn't have `propInfo` the object has a key)
468
- if (!propInfo && override.property in obj) {
469
- this._debug(`Skipping override of private property ${override.property}`);
470
- return;
471
- }
472
- if (!propInfo) {
473
- // We've overriding a property on an object we have NO type information on (probably
474
- // because it's an anonymous object).
475
- // Pretend it's 'prop: any';
476
- //
477
- // FIXME: We could do better type checking during the conversion if JSII clients
478
- // would tell us the intended interface type.
479
- propInfo = {
480
- name: override.property,
481
- type: spec.CANONICAL_ANY,
482
- };
483
- }
484
- this._defineOverridenProperty(obj, objref, override, propInfo);
485
497
  }
486
- _defineOverridenProperty(obj, objref, override, propInfo) {
487
- var _a;
488
- const propertyName = override.property;
489
- this._debug('apply override', propertyName);
490
- // save the old property under $jsii$super$<prop>$ so that property overrides
491
- // can still access it via `super.<prop>`.
492
- const prev = (_a = getPropertyDescriptor(obj, propertyName)) !== null && _a !== void 0 ? _a : {
493
- value: obj[propertyName],
494
- writable: true,
495
- enumerable: true,
496
- configurable: true,
498
+ return objref;
499
+ }, _Kernel_getSuperPropertyName = function _Kernel_getSuperPropertyName(name) {
500
+ return `$jsii$super$${name}$`;
501
+ }, _Kernel_applyPropertyOverride = function _Kernel_applyPropertyOverride(obj, objref, typeFqn, interfaces, override) {
502
+ // error if we can find a method with this name
503
+ if (__classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_tryTypeInfoForMethod).call(this, override.property, typeFqn, interfaces)) {
504
+ throw new JsiiFault(`Trying to override method '${override.property}' as a property`);
505
+ }
506
+ let propInfo = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_tryTypeInfoForProperty).call(this, override.property, typeFqn, interfaces);
507
+ // if this is a private property (i.e. doesn't have `propInfo` the object has a key)
508
+ if (!propInfo && override.property in obj) {
509
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, `Skipping override of private property ${override.property}`);
510
+ return;
511
+ }
512
+ if (!propInfo) {
513
+ // We've overriding a property on an object we have NO type information on (probably
514
+ // because it's an anonymous object).
515
+ // Pretend it's 'prop: any';
516
+ //
517
+ // FIXME: We could do better type checking during the conversion if JSII clients
518
+ // would tell us the intended interface type.
519
+ propInfo = {
520
+ name: override.property,
521
+ type: spec.CANONICAL_ANY,
497
522
  };
498
- const prevEnumerable = prev.enumerable;
499
- prev.enumerable = false;
500
- Object.defineProperty(obj, this._getSuperPropertyName(propertyName), prev);
501
- // we add callbacks for both 'get' and 'set', even if the property
502
- // is readonly. this is fine because if you try to set() a readonly
503
- // property, it will fail.
504
- Object.defineProperty(obj, propertyName, {
505
- enumerable: prevEnumerable,
506
- configurable: prev.configurable,
507
- get: () => {
508
- this._debug('virtual get', objref, propertyName, {
509
- cookie: override.cookie,
510
- });
511
- const result = this.callbackHandler({
512
- cookie: override.cookie,
513
- cbid: this._makecbid(),
514
- get: { objref, property: propertyName },
523
+ }
524
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_defineOverridenProperty).call(this, obj, objref, override, propInfo);
525
+ }, _Kernel_defineOverridenProperty = function _Kernel_defineOverridenProperty(obj, objref, override, propInfo) {
526
+ var _a;
527
+ const propertyName = override.property;
528
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'apply override', propertyName);
529
+ // save the old property under $jsii$super$<prop>$ so that property overrides
530
+ // can still access it via `super.<prop>`.
531
+ const prev = (_a = getPropertyDescriptor(obj, propertyName)) !== null && _a !== void 0 ? _a : {
532
+ value: obj[propertyName],
533
+ writable: true,
534
+ enumerable: true,
535
+ configurable: true,
536
+ };
537
+ const prevEnumerable = prev.enumerable;
538
+ prev.enumerable = false;
539
+ Object.defineProperty(obj, __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_getSuperPropertyName).call(this, propertyName), prev);
540
+ // we add callbacks for both 'get' and 'set', even if the property
541
+ // is readonly. this is fine because if you try to set() a readonly
542
+ // property, it will fail.
543
+ Object.defineProperty(obj, propertyName, {
544
+ enumerable: prevEnumerable,
545
+ configurable: prev.configurable,
546
+ get: () => {
547
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'virtual get', objref, propertyName, {
548
+ cookie: override.cookie,
549
+ });
550
+ const result = this.callbackHandler({
551
+ cookie: override.cookie,
552
+ cbid: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_makecbid).call(this),
553
+ get: { objref, property: propertyName },
554
+ });
555
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'callback returned', result);
556
+ return __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandbox).call(this, result, propInfo, `returned by callback property ${propertyName}`);
557
+ },
558
+ set: (value) => {
559
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'virtual set', objref, propertyName, {
560
+ cookie: override.cookie,
561
+ });
562
+ this.callbackHandler({
563
+ cookie: override.cookie,
564
+ cbid: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_makecbid).call(this),
565
+ set: {
566
+ objref,
567
+ property: propertyName,
568
+ value: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_fromSandbox).call(this, value, propInfo, `assigned to callback property ${propertyName}`),
569
+ },
570
+ });
571
+ },
572
+ });
573
+ function getPropertyDescriptor(obj, propertyName) {
574
+ const direct = Object.getOwnPropertyDescriptor(obj, propertyName);
575
+ if (direct != null) {
576
+ return direct;
577
+ }
578
+ const proto = Object.getPrototypeOf(obj);
579
+ if (proto == null && proto !== Object.prototype) {
580
+ // We reached Object or the prototype chain root, all hope is lost!
581
+ return undefined;
582
+ }
583
+ return getPropertyDescriptor(proto, propertyName);
584
+ }
585
+ }, _Kernel_applyMethodOverride = function _Kernel_applyMethodOverride(obj, objref, typeFqn, interfaces, override) {
586
+ // error if we can find a property with this name
587
+ if (__classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_tryTypeInfoForProperty).call(this, override.method, typeFqn, interfaces)) {
588
+ throw new JsiiFault(`Trying to override property '${override.method}' as a method`);
589
+ }
590
+ let methodInfo = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_tryTypeInfoForMethod).call(this, override.method, typeFqn, interfaces);
591
+ // If this is a private method (doesn't have methodInfo, key resolves on the object), we
592
+ // are going to skip the override.
593
+ if (!methodInfo && obj[override.method]) {
594
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, `Skipping override of private method ${override.method}`);
595
+ return;
596
+ }
597
+ if (!methodInfo) {
598
+ // We've overriding a method on an object we have NO type information on (probably
599
+ // because it's an anonymous object).
600
+ // Pretend it's an (...args: any[]) => any
601
+ methodInfo = {
602
+ name: override.method,
603
+ returns: { type: spec.CANONICAL_ANY },
604
+ parameters: [
605
+ {
606
+ name: 'args',
607
+ type: spec.CANONICAL_ANY,
608
+ variadic: true,
609
+ },
610
+ ],
611
+ variadic: true,
612
+ };
613
+ }
614
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_defineOverridenMethod).call(this, obj, objref, override, methodInfo);
615
+ }, _Kernel_defineOverridenMethod = function _Kernel_defineOverridenMethod(obj, objref, override, methodInfo) {
616
+ const methodName = override.method;
617
+ const fqn = (0, objects_1.jsiiTypeFqn)(obj, __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_isVisibleType).bind(this));
618
+ const methodContext = `${methodInfo.async ? 'async ' : ''}method${fqn ? `${fqn}#` : methodName}`;
619
+ if (methodInfo.async) {
620
+ // async method override
621
+ Object.defineProperty(obj, methodName, {
622
+ enumerable: false,
623
+ configurable: false,
624
+ writable: false,
625
+ value: (...methodArgs) => {
626
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'invoke async method override', override);
627
+ const args = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandboxValues).call(this, methodArgs, methodContext, methodInfo.parameters);
628
+ return new Promise((succeed, fail) => {
629
+ var _a;
630
+ const cbid = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_makecbid).call(this);
631
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'adding callback to queue', cbid);
632
+ __classPrivateFieldGet(this, _Kernel_cbs, "f").set(cbid, {
633
+ objref,
634
+ override,
635
+ args,
636
+ expectedReturnType: (_a = methodInfo.returns) !== null && _a !== void 0 ? _a : 'void',
637
+ succeed,
638
+ fail,
639
+ });
515
640
  });
516
- this._debug('callback returned', result);
517
- return this._toSandbox(result, propInfo, `returned by callback property ${propertyName}`);
518
641
  },
519
- set: (value) => {
520
- this._debug('virtual set', objref, propertyName, {
521
- cookie: override.cookie,
522
- });
523
- this.callbackHandler({
642
+ });
643
+ }
644
+ else {
645
+ // sync method override (method info is not required)
646
+ Object.defineProperty(obj, methodName, {
647
+ enumerable: false,
648
+ configurable: false,
649
+ writable: false,
650
+ value: (...methodArgs) => {
651
+ var _a;
652
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'invoke sync method override', override, 'args', methodArgs);
653
+ // We should be validating the actual arguments according to the
654
+ // declared parameters here, but let's just assume the JSII runtime on the
655
+ // other end has done its work.
656
+ const result = this.callbackHandler({
524
657
  cookie: override.cookie,
525
- cbid: this._makecbid(),
526
- set: {
658
+ cbid: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_makecbid).call(this),
659
+ invoke: {
527
660
  objref,
528
- property: propertyName,
529
- value: this._fromSandbox(value, propInfo, `assigned to callback property ${propertyName}`),
661
+ method: methodName,
662
+ args: __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_fromSandboxValues).call(this, methodArgs, methodContext, methodInfo.parameters),
530
663
  },
531
664
  });
665
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_debug).call(this, 'Result', result);
666
+ return __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandbox).call(this, result, (_a = methodInfo.returns) !== null && _a !== void 0 ? _a : 'void', `returned by callback method ${methodName}`);
532
667
  },
533
668
  });
534
- function getPropertyDescriptor(obj, propertyName) {
535
- const direct = Object.getOwnPropertyDescriptor(obj, propertyName);
536
- if (direct != null) {
537
- return direct;
538
- }
539
- const proto = Object.getPrototypeOf(obj);
540
- if (proto == null && proto !== Object.prototype) {
541
- // We reached Object or the prototype chain root, all hope is lost!
542
- return undefined;
543
- }
544
- return getPropertyDescriptor(proto, propertyName);
545
- }
546
- }
547
- _applyMethodOverride(obj, objref, typeFqn, interfaces, override) {
548
- // error if we can find a property with this name
549
- if (this._tryTypeInfoForProperty(override.method, typeFqn, interfaces)) {
550
- throw new JsiiFault(`Trying to override property '${override.method}' as a method`);
551
- }
552
- let methodInfo = this._tryTypeInfoForMethod(override.method, typeFqn, interfaces);
553
- // If this is a private method (doesn't have methodInfo, key resolves on the object), we
554
- // are going to skip the override.
555
- if (!methodInfo && obj[override.method]) {
556
- this._debug(`Skipping override of private method ${override.method}`);
557
- return;
558
- }
559
- if (!methodInfo) {
560
- // We've overriding a method on an object we have NO type information on (probably
561
- // because it's an anonymous object).
562
- // Pretend it's an (...args: any[]) => any
563
- methodInfo = {
564
- name: override.method,
565
- returns: { type: spec.CANONICAL_ANY },
566
- parameters: [
567
- {
568
- name: 'args',
569
- type: spec.CANONICAL_ANY,
570
- variadic: true,
571
- },
572
- ],
573
- variadic: true,
574
- };
575
- }
576
- this._defineOverridenMethod(obj, objref, override, methodInfo);
577
- }
578
- _defineOverridenMethod(obj, objref, override, methodInfo) {
579
- const methodName = override.method;
580
- const fqn = (0, objects_1.jsiiTypeFqn)(obj);
581
- const methodContext = `${methodInfo.async ? 'async ' : ''}method${fqn ? `${fqn}#` : methodName}`;
582
- if (methodInfo.async) {
583
- // async method override
584
- Object.defineProperty(obj, methodName, {
585
- enumerable: false,
586
- configurable: false,
587
- writable: false,
588
- value: (...methodArgs) => {
589
- this._debug('invoke async method override', override);
590
- const args = this._toSandboxValues(methodArgs, methodContext, methodInfo.parameters);
591
- return new Promise((succeed, fail) => {
592
- var _a;
593
- const cbid = this._makecbid();
594
- this._debug('adding callback to queue', cbid);
595
- this.cbs.set(cbid, {
596
- objref,
597
- override,
598
- args,
599
- expectedReturnType: (_a = methodInfo.returns) !== null && _a !== void 0 ? _a : 'void',
600
- succeed,
601
- fail,
602
- });
603
- });
604
- },
605
- });
606
- }
607
- else {
608
- // sync method override (method info is not required)
609
- Object.defineProperty(obj, methodName, {
610
- enumerable: false,
611
- configurable: false,
612
- writable: false,
613
- value: (...methodArgs) => {
614
- var _a;
615
- this._debug('invoke sync method override', override, 'args', methodArgs);
616
- // We should be validating the actual arguments according to the
617
- // declared parameters here, but let's just assume the JSII runtime on the
618
- // other end has done its work.
619
- const result = this.callbackHandler({
620
- cookie: override.cookie,
621
- cbid: this._makecbid(),
622
- invoke: {
623
- objref,
624
- method: methodName,
625
- args: this._fromSandboxValues(methodArgs, methodContext, methodInfo.parameters),
626
- },
627
- });
628
- this._debug('Result', result);
629
- return this._toSandbox(result, (_a = methodInfo.returns) !== null && _a !== void 0 ? _a : 'void', `returned by callback method ${methodName}`);
630
- },
631
- });
632
- }
633
669
  }
634
- _findInvokeTarget(objref, methodName, args) {
635
- const { instance, fqn, interfaces } = this.objects.findObject(objref);
636
- const ti = this._typeInfoForMethod(methodName, fqn, interfaces);
637
- this._validateMethodArguments(ti, args);
638
- // always first look up the method in the prototype. this practically bypasses
639
- // any methods overridden by derived classes (which are by definition native
640
- // methods). this serves to allow native call to invoke "super.method()" when
641
- // overriding the method.
642
- // if we didn't find the method on the prototype, it could be a literal object
643
- // that implements an interface, so we look if we have the method on the object
644
- // itself. if we do, we invoke it.
645
- let fn = instance.constructor.prototype[methodName];
670
+ }, _Kernel_findInvokeTarget = function _Kernel_findInvokeTarget(objref, methodName, args) {
671
+ const { instance, fqn, interfaces } = __classPrivateFieldGet(this, _Kernel_objects, "f").findObject(objref);
672
+ const ti = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForMethod).call(this, methodName, fqn, interfaces);
673
+ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_validateMethodArguments).call(this, ti, args);
674
+ // always first look up the method in the prototype. this practically bypasses
675
+ // any methods overridden by derived classes (which are by definition native
676
+ // methods). this serves to allow native call to invoke "super.method()" when
677
+ // overriding the method.
678
+ // if we didn't find the method on the prototype, it could be a literal object
679
+ // that implements an interface, so we look if we have the method on the object
680
+ // itself. if we do, we invoke it.
681
+ let fn = instance.constructor.prototype[methodName];
682
+ if (!fn) {
683
+ fn = instance[methodName];
646
684
  if (!fn) {
647
- fn = instance[methodName];
648
- if (!fn) {
649
- throw new JsiiFault(`Cannot find ${methodName} on object`);
650
- }
651
- }
652
- return { ti, obj: instance, fn };
653
- }
654
- _validateMethodArguments(method, args) {
655
- var _a;
656
- const params = (_a = method === null || method === void 0 ? void 0 : method.parameters) !== null && _a !== void 0 ? _a : [];
657
- // error if args > params
658
- if (args.length > params.length && !(method && method.variadic)) {
659
- throw new JsiiFault(`Too many arguments (method accepts ${params.length} parameters, got ${args.length} arguments)`);
660
- }
661
- for (let i = 0; i < params.length; ++i) {
662
- const param = params[i];
663
- const arg = args[i];
664
- if (param.variadic) {
665
- if (params.length <= i) {
666
- return;
667
- } // No vararg was provided
668
- for (let j = i; j < params.length; j++) {
669
- if (!param.optional && params[j] === undefined) {
670
- throw new JsiiFault(`Unexpected 'undefined' value at index ${j - i} of variadic argument '${param.name}' of type '${spec.describeTypeReference(param.type)}'`);
671
- }
685
+ throw new JsiiFault(`Cannot find ${methodName} on object`);
686
+ }
687
+ }
688
+ return { ti, obj: instance, fn };
689
+ }, _Kernel_validateMethodArguments = function _Kernel_validateMethodArguments(method, args) {
690
+ var _a;
691
+ const params = (_a = method === null || method === void 0 ? void 0 : method.parameters) !== null && _a !== void 0 ? _a : [];
692
+ // error if args > params
693
+ if (args.length > params.length && !(method && method.variadic)) {
694
+ throw new JsiiFault(`Too many arguments (method accepts ${params.length} parameters, got ${args.length} arguments)`);
695
+ }
696
+ for (let i = 0; i < params.length; ++i) {
697
+ const param = params[i];
698
+ const arg = args[i];
699
+ if (param.variadic) {
700
+ if (params.length <= i) {
701
+ return;
702
+ } // No vararg was provided
703
+ for (let j = i; j < params.length; j++) {
704
+ if (!param.optional && params[j] === undefined) {
705
+ throw new JsiiFault(`Unexpected 'undefined' value at index ${j - i} of variadic argument '${param.name}' of type '${spec.describeTypeReference(param.type)}'`);
672
706
  }
673
707
  }
674
- else if (!param.optional && arg === undefined) {
675
- throw new JsiiFault(`Not enough arguments. Missing argument for the required parameter '${param.name}' of type '${spec.describeTypeReference(param.type)}'`);
676
- }
677
708
  }
678
- }
679
- _assemblyFor(assemblyName) {
680
- const assembly = this.assemblies.get(assemblyName);
681
- if (!assembly) {
682
- throw new JsiiFault(`Could not find assembly: ${assemblyName}`);
683
- }
684
- return assembly;
685
- }
686
- _findSymbol(fqn) {
687
- const [assemblyName, ...parts] = fqn.split('.');
688
- const assembly = this._assemblyFor(assemblyName);
689
- let curr = assembly.closure;
690
- while (parts.length > 0) {
691
- const name = parts.shift();
692
- if (!name) {
693
- break;
694
- }
695
- curr = curr[name];
696
- }
697
- if (!curr) {
698
- throw new JsiiFault(`Could not find symbol ${fqn}`);
709
+ else if (!param.optional && arg === undefined) {
710
+ throw new JsiiFault(`Not enough arguments. Missing argument for the required parameter '${param.name}' of type '${spec.describeTypeReference(param.type)}'`);
711
+ }
712
+ }
713
+ }, _Kernel_assemblyFor = function _Kernel_assemblyFor(assemblyName) {
714
+ const assembly = __classPrivateFieldGet(this, _Kernel_assemblies, "f").get(assemblyName);
715
+ if (!assembly) {
716
+ throw new JsiiFault(`Could not find assembly: ${assemblyName}`);
717
+ }
718
+ return assembly;
719
+ }, _Kernel_findSymbol = function _Kernel_findSymbol(fqn) {
720
+ const [assemblyName, ...parts] = fqn.split('.');
721
+ const assembly = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_assemblyFor).call(this, assemblyName);
722
+ let curr = assembly.closure;
723
+ while (parts.length > 0) {
724
+ const name = parts.shift();
725
+ if (!name) {
726
+ break;
727
+ }
728
+ curr = curr[name];
729
+ }
730
+ if (!curr) {
731
+ throw new JsiiFault(`Could not find symbol ${fqn}`);
732
+ }
733
+ return curr;
734
+ }, _Kernel_typeInfoForFqn = function _Kernel_typeInfoForFqn(fqn) {
735
+ var _a;
736
+ const components = fqn.split('.');
737
+ const moduleName = components[0];
738
+ const assembly = __classPrivateFieldGet(this, _Kernel_assemblies, "f").get(moduleName);
739
+ if (!assembly) {
740
+ throw new JsiiFault(`Module '${moduleName}' not found`);
741
+ }
742
+ const types = (_a = assembly.metadata.types) !== null && _a !== void 0 ? _a : {};
743
+ const fqnInfo = types[fqn];
744
+ if (!fqnInfo) {
745
+ throw new JsiiFault(`Type '${fqn}' not found`);
746
+ }
747
+ return fqnInfo;
748
+ }, _Kernel_isVisibleType = function _Kernel_isVisibleType(fqn) {
749
+ try {
750
+ /* ignored */ __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForFqn).call(this, fqn);
751
+ return true;
752
+ }
753
+ catch (e) {
754
+ if (e instanceof JsiiFault) {
755
+ return false;
756
+ }
757
+ throw e;
758
+ }
759
+ }, _Kernel_typeInfoForMethod = function _Kernel_typeInfoForMethod(methodName, fqn, interfaces) {
760
+ const ti = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_tryTypeInfoForMethod).call(this, methodName, fqn, interfaces);
761
+ if (!ti) {
762
+ const addendum = interfaces && interfaces.length > 0
763
+ ? ` or interface(s) ${interfaces.join(', ')}`
764
+ : '';
765
+ throw new JsiiFault(`Class ${fqn}${addendum} doesn't have a method '${methodName}'`);
766
+ }
767
+ return ti;
768
+ }, _Kernel_tryTypeInfoForMethod = function _Kernel_tryTypeInfoForMethod(methodName, classFqn, interfaces = []) {
769
+ var _a, _b;
770
+ for (const fqn of [classFqn, ...interfaces]) {
771
+ if (fqn === wire.EMPTY_OBJECT_FQN) {
772
+ continue;
699
773
  }
700
- return curr;
701
- }
702
- _typeInfoForFqn(fqn) {
703
- var _a;
704
- const components = fqn.split('.');
705
- const moduleName = components[0];
706
- const assembly = this.assemblies.get(moduleName);
707
- if (!assembly) {
708
- throw new JsiiFault(`Module '${moduleName}' not found`);
709
- }
710
- const types = (_a = assembly.metadata.types) !== null && _a !== void 0 ? _a : {};
711
- const fqnInfo = types[fqn];
712
- if (!fqnInfo) {
713
- throw new JsiiFault(`Type '${fqn}' not found`);
714
- }
715
- return fqnInfo;
716
- }
717
- _typeInfoForMethod(methodName, fqn, interfaces) {
718
- const ti = this._tryTypeInfoForMethod(methodName, fqn, interfaces);
719
- if (!ti) {
720
- const addendum = interfaces && interfaces.length > 0
721
- ? ` or interface(s) ${interfaces.join(', ')}`
722
- : '';
723
- throw new JsiiFault(`Class ${fqn}${addendum} doesn't have a method '${methodName}'`);
724
- }
725
- return ti;
726
- }
727
- _tryTypeInfoForMethod(methodName, classFqn, interfaces = []) {
728
- var _a, _b;
729
- for (const fqn of [classFqn, ...interfaces]) {
730
- if (fqn === wire.EMPTY_OBJECT_FQN) {
731
- continue;
732
- }
733
- const typeinfo = this._typeInfoForFqn(fqn);
734
- const methods = (_a = typeinfo.methods) !== null && _a !== void 0 ? _a : [];
735
- for (const m of methods) {
736
- if (m.name === methodName) {
737
- return m;
738
- }
739
- }
740
- // recursion to parent type (if exists)
741
- const bases = [
742
- typeinfo.base,
743
- ...((_b = typeinfo.interfaces) !== null && _b !== void 0 ? _b : []),
744
- ];
745
- for (const base of bases) {
746
- if (!base) {
747
- continue;
748
- }
749
- const found = this._tryTypeInfoForMethod(methodName, base);
750
- if (found) {
751
- return found;
752
- }
774
+ const typeinfo = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForFqn).call(this, fqn);
775
+ const methods = (_a = typeinfo.methods) !== null && _a !== void 0 ? _a : [];
776
+ for (const m of methods) {
777
+ if (m.name === methodName) {
778
+ return m;
753
779
  }
754
780
  }
755
- return undefined;
756
- }
757
- _tryTypeInfoForProperty(property, classFqn, interfaces = []) {
758
- var _a;
759
- for (const fqn of [classFqn, ...interfaces]) {
760
- if (fqn === wire.EMPTY_OBJECT_FQN) {
781
+ // recursion to parent type (if exists)
782
+ const bases = [
783
+ typeinfo.base,
784
+ ...((_b = typeinfo.interfaces) !== null && _b !== void 0 ? _b : []),
785
+ ];
786
+ for (const base of bases) {
787
+ if (!base) {
761
788
  continue;
762
789
  }
763
- const typeInfo = this._typeInfoForFqn(fqn);
764
- let properties;
765
- let bases;
766
- if (spec.isClassType(typeInfo)) {
767
- const classTypeInfo = typeInfo;
768
- properties = classTypeInfo.properties;
769
- bases = classTypeInfo.base ? [classTypeInfo.base] : [];
770
- }
771
- else if (spec.isInterfaceType(typeInfo)) {
772
- const interfaceTypeInfo = typeInfo;
773
- properties = interfaceTypeInfo.properties;
774
- bases = (_a = interfaceTypeInfo.interfaces) !== null && _a !== void 0 ? _a : [];
775
- }
776
- else {
777
- throw new JsiiFault(`Type of kind ${typeInfo.kind} does not have properties`);
778
- }
779
- for (const p of properties !== null && properties !== void 0 ? properties : []) {
780
- if (p.name === property) {
781
- return p;
782
- }
783
- }
784
- // recurse to parent type (if exists)
785
- for (const baseFqn of bases) {
786
- const ret = this._tryTypeInfoForProperty(property, baseFqn);
787
- if (ret) {
788
- return ret;
789
- }
790
+ const found = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_tryTypeInfoForMethod).call(this, methodName, base);
791
+ if (found) {
792
+ return found;
790
793
  }
791
794
  }
792
- return undefined;
793
- }
794
- _typeInfoForProperty(property, fqn, interfaces) {
795
- const typeInfo = this._tryTypeInfoForProperty(property, fqn, interfaces);
796
- if (!typeInfo) {
797
- const addendum = interfaces && interfaces.length > 0
798
- ? ` or interface(s) ${interfaces.join(', ')}`
799
- : '';
800
- throw new JsiiFault(`Type ${fqn}${addendum} doesn't have a property '${property}'`);
801
- }
802
- return typeInfo;
803
- }
804
- _toSandbox(v, expectedType, context) {
805
- return wire.process({
806
- objects: this.objects,
807
- debug: this._debug.bind(this),
808
- findSymbol: this._findSymbol.bind(this),
809
- lookupType: this._typeInfoForFqn.bind(this),
810
- }, 'deserialize', v, expectedType, context);
811
795
  }
812
- _fromSandbox(v, targetType, context) {
813
- return wire.process({
814
- objects: this.objects,
815
- debug: this._debug.bind(this),
816
- findSymbol: this._findSymbol.bind(this),
817
- lookupType: this._typeInfoForFqn.bind(this),
818
- }, 'serialize', v, targetType, context);
819
- }
820
- _toSandboxValues(xs, methodContext, parameters) {
821
- return this._boxUnboxParameters(xs, methodContext, parameters, this._toSandbox.bind(this));
822
- }
823
- _fromSandboxValues(xs, methodContext, parameters) {
824
- return this._boxUnboxParameters(xs, methodContext, parameters, this._fromSandbox.bind(this));
825
- }
826
- _boxUnboxParameters(xs, methodContext, parameters = [], boxUnbox) {
827
- const parametersCopy = [...parameters];
828
- const variadic = parametersCopy.length > 0 &&
829
- !!parametersCopy[parametersCopy.length - 1].variadic;
830
- // Repeat the last (variadic) type to match the number of actual arguments
831
- while (variadic && parametersCopy.length < xs.length) {
832
- parametersCopy.push(parametersCopy[parametersCopy.length - 1]);
833
- }
834
- if (xs.length > parametersCopy.length) {
835
- throw new JsiiFault(`Argument list (${JSON.stringify(xs)}) not same size as expected argument list (length ${parametersCopy.length})`);
796
+ return undefined;
797
+ }, _Kernel_tryTypeInfoForProperty = function _Kernel_tryTypeInfoForProperty(property, classFqn, interfaces = []) {
798
+ var _a;
799
+ for (const fqn of [classFqn, ...interfaces]) {
800
+ if (fqn === wire.EMPTY_OBJECT_FQN) {
801
+ continue;
836
802
  }
837
- return xs.map((x, i) => boxUnbox(x, parametersCopy[i], `passed to parameter ${parametersCopy[i].name} of ${methodContext}`));
838
- }
839
- _debug(...args) {
840
- if (this.traceEnabled) {
841
- console.error('[@jsii/kernel]', ...args);
803
+ const typeInfo = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_typeInfoForFqn).call(this, fqn);
804
+ let properties;
805
+ let bases;
806
+ if (spec.isClassType(typeInfo)) {
807
+ const classTypeInfo = typeInfo;
808
+ properties = classTypeInfo.properties;
809
+ bases = classTypeInfo.base ? [classTypeInfo.base] : [];
842
810
  }
843
- }
844
- _debugTime(cb, label) {
845
- const fullLabel = `[@jsii/kernel:timing] ${label}`;
846
- if (this.debugTimingEnabled) {
847
- console.time(fullLabel);
811
+ else if (spec.isInterfaceType(typeInfo)) {
812
+ const interfaceTypeInfo = typeInfo;
813
+ properties = interfaceTypeInfo.properties;
814
+ bases = (_a = interfaceTypeInfo.interfaces) !== null && _a !== void 0 ? _a : [];
848
815
  }
849
- try {
850
- return cb();
816
+ else {
817
+ throw new JsiiFault(`Type of kind ${typeInfo.kind} does not have properties`);
851
818
  }
852
- finally {
853
- if (this.debugTimingEnabled) {
854
- console.timeEnd(fullLabel);
819
+ for (const p of properties !== null && properties !== void 0 ? properties : []) {
820
+ if (p.name === property) {
821
+ return p;
855
822
  }
856
823
  }
857
- }
858
- /**
859
- * Ensures that `fn` is called and defends against beginning to invoke
860
- * async methods until fn finishes (successfully or not).
861
- */
862
- _ensureSync(desc, fn) {
863
- this.syncInProgress = desc;
864
- try {
865
- return fn();
866
- }
867
- catch (e) {
868
- if (e.name === "@jsii/kernel.Fault" /* JsiiErrorType.JSII_FAULT */) {
869
- if (e instanceof JsiiFault) {
870
- throw e;
871
- }
872
- throw new JsiiFault(e);
873
- }
874
- // This error can be thrown by the kernel directly, or it can be
875
- // thrown from user code. If the error comes from the kernel, then its name field will be populated;
876
- // if the error comes from user code, the name field will not be populated.
877
- if (e instanceof RuntimeError) {
878
- throw e;
824
+ // recurse to parent type (if exists)
825
+ for (const baseFqn of bases) {
826
+ const ret = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_tryTypeInfoForProperty).call(this, property, baseFqn);
827
+ if (ret) {
828
+ return ret;
879
829
  }
880
- throw new RuntimeError(e);
881
- }
882
- finally {
883
- delete this.syncInProgress;
884
830
  }
885
831
  }
886
- _findPropertyTarget(obj, property) {
887
- const superProp = this._getSuperPropertyName(property);
888
- if (superProp in obj) {
889
- return superProp;
832
+ return undefined;
833
+ }, _Kernel_typeInfoForProperty = function _Kernel_typeInfoForProperty(property, fqn, interfaces) {
834
+ const typeInfo = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_tryTypeInfoForProperty).call(this, property, fqn, interfaces);
835
+ if (!typeInfo) {
836
+ const addendum = interfaces && interfaces.length > 0
837
+ ? ` or interface(s) ${interfaces.join(', ')}`
838
+ : '';
839
+ throw new JsiiFault(`Type ${fqn}${addendum} doesn't have a property '${property}'`);
840
+ }
841
+ return typeInfo;
842
+ }, _Kernel_toSandbox = function _Kernel_toSandbox(v, expectedType, context) {
843
+ return wire.process(__classPrivateFieldGet(this, _Kernel_serializerHost, "f"), 'deserialize', v, expectedType, context);
844
+ }, _Kernel_fromSandbox = function _Kernel_fromSandbox(v, targetType, context) {
845
+ return wire.process(__classPrivateFieldGet(this, _Kernel_serializerHost, "f"), 'serialize', v, targetType, context);
846
+ }, _Kernel_toSandboxValues = function _Kernel_toSandboxValues(xs, methodContext, parameters) {
847
+ return __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_boxUnboxParameters).call(this, xs, methodContext, parameters, __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_toSandbox).bind(this));
848
+ }, _Kernel_fromSandboxValues = function _Kernel_fromSandboxValues(xs, methodContext, parameters) {
849
+ return __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_boxUnboxParameters).call(this, xs, methodContext, parameters, __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_fromSandbox).bind(this));
850
+ }, _Kernel_boxUnboxParameters = function _Kernel_boxUnboxParameters(xs, methodContext, parameters = [], boxUnbox) {
851
+ const parametersCopy = [...parameters];
852
+ const variadic = parametersCopy.length > 0 &&
853
+ !!parametersCopy[parametersCopy.length - 1].variadic;
854
+ // Repeat the last (variadic) type to match the number of actual arguments
855
+ while (variadic && parametersCopy.length < xs.length) {
856
+ parametersCopy.push(parametersCopy[parametersCopy.length - 1]);
857
+ }
858
+ if (xs.length > parametersCopy.length) {
859
+ throw new JsiiFault(`Argument list (${JSON.stringify(xs)}) not same size as expected argument list (length ${parametersCopy.length})`);
860
+ }
861
+ return xs.map((x, i) => boxUnbox(x, parametersCopy[i], `passed to parameter ${parametersCopy[i].name} of ${methodContext}`));
862
+ }, _Kernel_debug = function _Kernel_debug(...args) {
863
+ if (this.traceEnabled) {
864
+ console.error('[@jsii/kernel]', ...args);
865
+ }
866
+ }, _Kernel_debugTime = function _Kernel_debugTime(cb, label) {
867
+ const fullLabel = `[@jsii/kernel:timing] ${label}`;
868
+ if (this.debugTimingEnabled) {
869
+ console.time(fullLabel);
870
+ }
871
+ try {
872
+ return cb();
873
+ }
874
+ finally {
875
+ if (this.debugTimingEnabled) {
876
+ console.timeEnd(fullLabel);
890
877
  }
891
- return property;
892
878
  }
893
- /**
894
- * Shared (non-public implementation) to as not to break API recording.
895
- */
896
- _getBinScriptCommand(req) {
897
- var _a, _b;
898
- const packageDir = this._getPackageDir(req.assembly);
899
- if (fs.pathExistsSync(packageDir)) {
900
- // module exists, verify version
901
- const epkg = fs.readJsonSync(path.join(packageDir, 'package.json'));
902
- const scriptPath = (_a = epkg.bin) === null || _a === void 0 ? void 0 : _a[req.script];
903
- if (!epkg.bin) {
904
- throw new JsiiFault(`Script with name ${req.script} was not defined.`);
879
+ }, _Kernel_ensureSync = function _Kernel_ensureSync(desc, fn) {
880
+ __classPrivateFieldSet(this, _Kernel_syncInProgress, desc, "f");
881
+ try {
882
+ return fn();
883
+ }
884
+ catch (e) {
885
+ if (e.name === "@jsii/kernel.Fault" /* JsiiErrorType.JSII_FAULT */) {
886
+ if (e instanceof JsiiFault) {
887
+ throw e;
905
888
  }
906
- return {
907
- command: path.join(packageDir, scriptPath),
908
- args: (_b = req.args) !== null && _b !== void 0 ? _b : [],
909
- env: {
910
- ...process.env,
911
- // Make sure the current NODE_OPTIONS are honored if we shell out to node
912
- NODE_OPTIONS: process.execArgv.join(' '),
913
- // Make sure "this" node is ahead of $PATH just in case
914
- PATH: `${path.dirname(process.execPath)}:${process.env.PATH}`,
915
- },
916
- };
889
+ throw new JsiiFault(e);
890
+ }
891
+ // This error can be thrown by the kernel directly, or it can be
892
+ // thrown from user code. If the error comes from the kernel, then its name field will be populated;
893
+ // if the error comes from user code, the name field will not be populated.
894
+ if (e instanceof RuntimeError) {
895
+ throw e;
896
+ }
897
+ throw new RuntimeError(e);
898
+ }
899
+ finally {
900
+ __classPrivateFieldSet(this, _Kernel_syncInProgress, undefined, "f");
901
+ }
902
+ }, _Kernel_findPropertyTarget = function _Kernel_findPropertyTarget(obj, property) {
903
+ const superProp = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_getSuperPropertyName).call(this, property);
904
+ if (superProp in obj) {
905
+ return superProp;
906
+ }
907
+ return property;
908
+ }, _Kernel_getBinScriptCommand = function _Kernel_getBinScriptCommand(req) {
909
+ var _a, _b;
910
+ const packageDir = __classPrivateFieldGet(this, _Kernel_instances, "m", _Kernel_getPackageDir).call(this, req.assembly);
911
+ if (fs.pathExistsSync(packageDir)) {
912
+ // module exists, verify version
913
+ const epkg = fs.readJsonSync(path.join(packageDir, 'package.json'));
914
+ const scriptPath = (_a = epkg.bin) === null || _a === void 0 ? void 0 : _a[req.script];
915
+ if (!epkg.bin) {
916
+ throw new JsiiFault(`Script with name ${req.script} was not defined.`);
917
917
  }
918
- throw new JsiiFault(`Package with name ${req.assembly} was not loaded.`);
919
- }
920
- //
921
- // type information
922
- //
923
- _makecbid() {
924
- return `jsii::callback::${this.nextid++}`;
925
- }
926
- _makeprid() {
927
- return `jsii::promise::${this.nextid++}`;
918
+ return {
919
+ command: path.join(packageDir, scriptPath),
920
+ args: (_b = req.args) !== null && _b !== void 0 ? _b : [],
921
+ env: {
922
+ ...process.env,
923
+ // Make sure the current NODE_OPTIONS are honored if we shell out to node
924
+ NODE_OPTIONS: process.execArgv.join(' '),
925
+ // Make sure "this" node is ahead of $PATH just in case
926
+ PATH: `${path.dirname(process.execPath)}:${process.env.PATH}`,
927
+ },
928
+ };
928
929
  }
929
- }
930
- exports.Kernel = Kernel;
930
+ throw new JsiiFault(`Package with name ${req.assembly} was not loaded.`);
931
+ }, _Kernel_makecbid = function _Kernel_makecbid() {
932
+ var _a, _b;
933
+ return `jsii::callback::${__classPrivateFieldSet(this, _Kernel_nextid, (_b = __classPrivateFieldGet(this, _Kernel_nextid, "f"), _a = _b++, _b), "f"), _a}`;
934
+ }, _Kernel_makeprid = function _Kernel_makeprid() {
935
+ var _a, _b;
936
+ return `jsii::promise::${__classPrivateFieldSet(this, _Kernel_nextid, (_b = __classPrivateFieldGet(this, _Kernel_nextid, "f"), _a = _b++, _b), "f"), _a}`;
937
+ };
931
938
  class Assembly {
932
939
  constructor(metadata, closure) {
933
940
  this.metadata = metadata;