greybel-interpreter 4.8.2 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/run-next.d.ts +1 -0
- package/dist/utils/run-next.js +46 -0
- package/dist/vm.js +3 -3
- package/package.json +1 -1
- package/dist/utils/set-immediate.d.ts +0 -1
- package/dist/utils/set-immediate.js +0 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const runNext: any;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runNext = void 0;
|
|
4
|
+
class RunNextHelper {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.stack = [];
|
|
7
|
+
this.sleep = 0;
|
|
8
|
+
this.timer = null;
|
|
9
|
+
}
|
|
10
|
+
shouldSleep() {
|
|
11
|
+
if (this.stack.length > 0)
|
|
12
|
+
return this.sleep = 0;
|
|
13
|
+
if (this.sleep++ <= RunNextHelper.SLEEP_LIMIT)
|
|
14
|
+
return;
|
|
15
|
+
clearInterval(this.timer);
|
|
16
|
+
this.timer = null;
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
tick() {
|
|
20
|
+
const current = this.stack;
|
|
21
|
+
this.stack = [];
|
|
22
|
+
for (let i = 0; i < current.length; i++) {
|
|
23
|
+
try {
|
|
24
|
+
current[i]();
|
|
25
|
+
}
|
|
26
|
+
catch (err) { }
|
|
27
|
+
}
|
|
28
|
+
this.shouldSleep();
|
|
29
|
+
}
|
|
30
|
+
;
|
|
31
|
+
start() {
|
|
32
|
+
if (this.timer !== null)
|
|
33
|
+
return;
|
|
34
|
+
this.sleep = 0;
|
|
35
|
+
this.timer = setInterval(() => this.tick(), 0);
|
|
36
|
+
}
|
|
37
|
+
;
|
|
38
|
+
add(callback) {
|
|
39
|
+
this.stack.push(callback);
|
|
40
|
+
this.start();
|
|
41
|
+
}
|
|
42
|
+
;
|
|
43
|
+
}
|
|
44
|
+
RunNextHelper.SLEEP_LIMIT = 1000;
|
|
45
|
+
const helper = new RunNextHelper();
|
|
46
|
+
exports.runNext = helper.add.bind(helper);
|
package/dist/vm.js
CHANGED
|
@@ -25,7 +25,7 @@ const evaluation_1 = require("./vm/evaluation");
|
|
|
25
25
|
const number_1 = require("./types/number");
|
|
26
26
|
const map_1 = require("./types/map");
|
|
27
27
|
const list_1 = require("./types/list");
|
|
28
|
-
const
|
|
28
|
+
const run_next_1 = require("./utils/run-next");
|
|
29
29
|
const string_1 = require("./types/string");
|
|
30
30
|
const events_1 = __importDefault(require("events"));
|
|
31
31
|
const object_value_1 = require("./utils/object-value");
|
|
@@ -65,7 +65,7 @@ class Debugger {
|
|
|
65
65
|
resolve();
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
|
-
(0,
|
|
68
|
+
(0, run_next_1.runNext)(check);
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
check();
|
|
@@ -699,7 +699,7 @@ class VM {
|
|
|
699
699
|
}
|
|
700
700
|
if (this.actionCount++ === this.maxActionsPerLoop) {
|
|
701
701
|
this.actionCount = 0;
|
|
702
|
-
(0,
|
|
702
|
+
(0, run_next_1.runNext)(() => {
|
|
703
703
|
this.resume(done);
|
|
704
704
|
});
|
|
705
705
|
return;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setImmediate = void 0;
|
|
4
|
-
function setImmediateProvider() {
|
|
5
|
-
var _a, _b;
|
|
6
|
-
const ctx = globalThis;
|
|
7
|
-
return ((_b = (_a = ctx.setImmediate) !== null && _a !== void 0 ? _a : ctx.requestAnimationFrame) !== null && _b !== void 0 ? _b : function (callback, ...args) {
|
|
8
|
-
return setTimeout(() => callback(...args), 0);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
exports.setImmediate = setImmediateProvider();
|