x-runtime-lib 0.8.76 → 0.8.78

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.
@@ -1,3 +1,5 @@
1
1
  import { QuickJSContext, QuickJSHandle } from 'quickjs-emscripten';
2
+ import { Sandbox } from '../sandbox';
3
+ export declare function isVmAvail(sandbox: Sandbox): boolean;
2
4
  export declare function hostToVm(vm: QuickJSContext, value: any): QuickJSHandle;
3
5
  export declare function vmToHost(vm: QuickJSContext, value: QuickJSHandle): any;
@@ -1 +1 @@
1
- export declare const timer = "\nlet __timers__ = {}\nlet __currTimerId__ = 0\n\nfunction __createTimerV1__(interval, loop, count, immediate, callback) {\n if (!loop && count <= 0) {\n return\n }\n __currTimerId__ = __currTimerId__ + 1\n const timer = {}\n timer.id = __currTimerId__\n timer.interval = interval\n timer.loop = loop\n timer.count = count\n timer.immediate = immediate\n timer.callback = callback\n __timers__[timer.id] = timer\n if (timer.immediate) {\n __timeoutCallbackV1__(timer.id)\n } else {\n __timeoutV1__(timer.id, timer.interval)\n }\n}\n\nfunction __timeoutCallbackV1__(timerId) {\n const timer = __timers__[timerId]\n if (timer) {\n timer.callback()\n // \u4FEE\u6539\u8BA1\u6570\n if (!timer.loop) {\n timer.count = timer.count - 1\n }\n // \u89E6\u53D1\u8D85\u65F6\n if (timer.loop || timer.count > 0) {\n __timeoutV1__(timer.id, timer.interval)\n }\n // \u56DE\u6536\n if (!timer.loop && timer.count <= 0) {\n delete __timers__[timer.id]\n }\n }\n}\n";
1
+ export declare const timer = "\nlet __timers__ = {}\nlet __currTimerId__ = 0\n\nfunction __createTimerV1__(interval, loop, count, immediate, callback) {\n if (!loop && count <= 0) {\n return\n }\n __currTimerId__ = __currTimerId__ + 1\n const timer = {}\n timer.id = __currTimerId__\n timer.interval = interval\n timer.loop = loop\n timer.count = count\n timer.immediate = immediate\n timer.callback = callback\n __timers__[timer.id] = timer\n if (timer.immediate) {\n __timeoutCallbackV1__(timer.id)\n } else {\n __timeoutV1__(timer.id, timer.interval)\n }\n}\n\nfunction __timeoutCallback__(timerId) {\n const timer = __timers__[timerId]\n if (timer) {\n timer.callback()\n // \u4FEE\u6539\u8BA1\u6570\n if (!timer.loop) {\n timer.count = timer.count - 1\n }\n // \u89E6\u53D1\u8D85\u65F6\n if (timer.loop || timer.count > 0) {\n __timeoutV1__(timer.id, timer.interval)\n }\n // \u56DE\u6536\n if (!timer.loop && timer.count <= 0) {\n delete __timers__[timer.id]\n }\n }\n}\n";
@@ -1,5 +1,6 @@
1
1
  import { QuickJSContext, QuickJSRuntime } from 'quickjs-emscripten';
2
2
  import { Data, Env, Mode, SandboxKind } from '@/types';
3
+ import { PromiseManager } from './promiseManager';
3
4
  export type PropertyKeys = string[] | string;
4
5
  export declare function dotPropertyKeys(propertyKeys: PropertyKeys): string;
5
6
  interface Hooks {
@@ -27,6 +28,7 @@ export declare class Sandbox {
27
28
  private addChild;
28
29
  private removeChild;
29
30
  vm: QuickJSContext | undefined;
31
+ promiseManager: PromiseManager | undefined;
30
32
  createVm(runtime: QuickJSRuntime, code: string): Promise<void>;
31
33
  destroyVm(): void;
32
34
  callFunction(funcName: string, ...ps: any): void;
@@ -0,0 +1,15 @@
1
+ import { QuickJSContext, QuickJSDeferredPromise } from 'quickjs-emscripten';
2
+ export declare class PromiseManager {
3
+ vm: QuickJSContext;
4
+ promiseId: number;
5
+ promises: {
6
+ [key: string]: QuickJSDeferredPromise;
7
+ };
8
+ constructor(vm: QuickJSContext);
9
+ dispose(): void;
10
+ acquire(): {
11
+ id: number;
12
+ promise: QuickJSDeferredPromise;
13
+ };
14
+ release(id: number): void;
15
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "x-runtime-lib",
3
3
  "private": false,
4
- "version": "0.8.76",
4
+ "version": "0.8.78",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",