@mirascript/mirascript 0.1.92 → 0.1.93
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/chunk-7JTZW66P.js +1075 -0
- package/dist/chunk-7JTZW66P.js.map +6 -0
- package/dist/{chunk-Y7S6AHE7.js → chunk-F3FHURMG.js} +55 -939
- package/dist/chunk-F3FHURMG.js.map +6 -0
- package/dist/{chunk-HHKY7Y7L.js → chunk-GTNLLZL4.js} +4 -82
- package/dist/chunk-GTNLLZL4.js.map +6 -0
- package/dist/chunk-H2OHULLB.js +89 -0
- package/dist/chunk-H2OHULLB.js.map +6 -0
- package/dist/compiler/worker.js +2 -1
- package/dist/compiler/worker.js.map +1 -1
- package/dist/experimental-context.d.ts +93 -0
- package/dist/experimental-context.d.ts.map +1 -0
- package/dist/experimental-context.js +90 -0
- package/dist/experimental-context.js.map +6 -0
- package/dist/helpers/convert/string.d.ts +0 -2
- package/dist/helpers/convert/string.d.ts.map +1 -1
- package/dist/helpers/error.d.ts.map +1 -1
- package/dist/helpers/serialize/display.d.ts +29 -0
- package/dist/helpers/serialize/display.d.ts.map +1 -0
- package/dist/helpers/serialize/index.d.ts +5 -0
- package/dist/helpers/serialize/index.d.ts.map +1 -0
- package/dist/helpers/serialize/interface.d.ts +33 -0
- package/dist/helpers/serialize/interface.d.ts.map +1 -0
- package/dist/helpers/serialize/serialize.d.ts +39 -0
- package/dist/helpers/serialize/serialize.d.ts.map +1 -0
- package/dist/helpers/serialize/simple.d.ts +9 -0
- package/dist/helpers/serialize/simple.d.ts.map +1 -0
- package/dist/helpers/serialize/string.d.ts +6 -0
- package/dist/helpers/serialize/string.d.ts.map +1 -0
- package/dist/helpers/utils.d.ts +4 -0
- package/dist/helpers/utils.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/dist/subtle.d.ts +1 -1
- package/dist/subtle.d.ts.map +1 -1
- package/dist/subtle.js +9 -6
- package/dist/subtle.js.map +1 -1
- package/dist/vm/effects/run.d.ts +7 -0
- package/dist/vm/effects/run.d.ts.map +1 -0
- package/dist/vm/effects/state.d.ts +62 -0
- package/dist/vm/effects/state.d.ts.map +1 -0
- package/dist/vm/effects/wrap.d.ts +4 -0
- package/dist/vm/effects/wrap.d.ts.map +1 -0
- package/dist/vm/lib/global/bit.d.ts +7 -7
- package/dist/vm/lib/global/bit.d.ts.map +1 -1
- package/dist/vm/lib/global/debug.d.ts +1 -1
- package/dist/vm/lib/global/debug.d.ts.map +1 -1
- package/dist/vm/lib/global/json.d.ts +2 -2
- package/dist/vm/lib/global/json.d.ts.map +1 -1
- package/dist/vm/lib/global/math/index.d.ts +2 -2
- package/dist/vm/lib/global/math/index.d.ts.map +1 -1
- package/dist/vm/lib/global/math/tgamma.d.ts +2 -2
- package/dist/vm/lib/global/math/tgamma.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/all-any.d.ts +2 -2
- package/dist/vm/lib/global/sequence/all-any.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/entries.d.ts +3 -3
- package/dist/vm/lib/global/sequence/entries.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/find.d.ts +1 -1
- package/dist/vm/lib/global/sequence/flatten.d.ts +1 -1
- package/dist/vm/lib/global/sequence/flatten.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/fold.d.ts +1 -1
- package/dist/vm/lib/global/sequence/fold.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/group.d.ts +1 -1
- package/dist/vm/lib/global/sequence/group.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/len.d.ts +1 -1
- package/dist/vm/lib/global/sequence/len.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/map-filter.d.ts +3 -3
- package/dist/vm/lib/global/sequence/map-filter.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/new.d.ts +2 -2
- package/dist/vm/lib/global/sequence/new.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/repeat.d.ts +1 -1
- package/dist/vm/lib/global/sequence/repeat.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/reverse.d.ts +1 -1
- package/dist/vm/lib/global/sequence/reverse.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/sort.d.ts +2 -2
- package/dist/vm/lib/global/sequence/sort.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/unique.d.ts +2 -2
- package/dist/vm/lib/global/sequence/unique.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/with.d.ts +1 -1
- package/dist/vm/lib/global/sequence/with.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/zip.d.ts +1 -1
- package/dist/vm/lib/global/sequence/zip.d.ts.map +1 -1
- package/dist/vm/lib/global/string/case.d.ts +2 -2
- package/dist/vm/lib/global/string/case.d.ts.map +1 -1
- package/dist/vm/lib/global/string/index.d.ts +4 -4
- package/dist/vm/lib/global/string/index.d.ts.map +1 -1
- package/dist/vm/lib/global/string/search.d.ts +3 -3
- package/dist/vm/lib/global/string/search.d.ts.map +1 -1
- package/dist/vm/lib/global/string/trim.d.ts +3 -3
- package/dist/vm/lib/global/string/trim.d.ts.map +1 -1
- package/dist/vm/lib/global/time.d.ts +3 -3
- package/dist/vm/lib/global/time.d.ts.map +1 -1
- package/dist/vm/lib/global/to-primitive.d.ts +3 -3
- package/dist/vm/lib/global/to-primitive.d.ts.map +1 -1
- package/dist/vm/lib/mod/matrix/bin-ops.d.ts +6 -6
- package/dist/vm/lib/mod/matrix/bin-ops.d.ts.map +1 -1
- package/dist/vm/lib/mod/matrix/fill.d.ts +4 -4
- package/dist/vm/lib/mod/matrix/fill.d.ts.map +1 -1
- package/dist/vm/lib/mod/matrix/invert.d.ts +1 -1
- package/dist/vm/lib/mod/matrix/invert.d.ts.map +1 -1
- package/dist/vm/lib/mod/matrix/size.d.ts +1 -1
- package/dist/vm/lib/mod/matrix/size.d.ts.map +1 -1
- package/dist/vm/lib/mod/matrix/transpose.d.ts +1 -1
- package/dist/vm/lib/mod/matrix/transpose.d.ts.map +1 -1
- package/dist/vm/types/function.d.ts +4 -2
- package/dist/vm/types/function.d.ts.map +1 -1
- package/package.json +8 -4
- package/src/experimental-context.ts +121 -0
- package/src/helpers/convert/boolean.ts +1 -1
- package/src/helpers/convert/number.ts +1 -1
- package/src/helpers/convert/string.ts +6 -11
- package/src/helpers/error.ts +2 -0
- package/src/helpers/serialize/display.ts +60 -0
- package/src/helpers/serialize/index.ts +4 -0
- package/src/helpers/serialize/interface.ts +33 -0
- package/src/helpers/serialize/serialize.ts +200 -0
- package/src/helpers/serialize/simple.ts +25 -0
- package/src/helpers/serialize/string.ts +91 -0
- package/src/helpers/utils.ts +11 -2
- package/src/index.ts +1 -1
- package/src/subtle.ts +2 -2
- package/src/vm/effects/run.ts +80 -0
- package/src/vm/effects/state.ts +108 -0
- package/src/vm/effects/wrap.ts +71 -0
- package/src/vm/lib/global/debug.ts +6 -3
- package/src/vm/lib/global/math/index.ts +9 -5
- package/src/vm/lib/global/sequence/zip.ts +1 -1
- package/src/vm/lib/global/time.ts +5 -2
- package/src/vm/lib/helpers.ts +1 -1
- package/src/vm/operations/call.ts +1 -1
- package/src/vm/operations/compound.ts +1 -1
- package/src/vm/operations/iterable.ts +1 -1
- package/src/vm/operations/slice.ts +1 -1
- package/src/vm/operations/spread.ts +1 -1
- package/src/vm/types/function.ts +7 -5
- package/dist/chunk-HHKY7Y7L.js.map +0 -6
- package/dist/chunk-Y7S6AHE7.js.map +0 -6
- package/dist/helpers/serialize.d.ts +0 -63
- package/dist/helpers/serialize.d.ts.map +0 -1
- package/src/helpers/serialize.ts +0 -397
|
@@ -1,21 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
$AssertInit,
|
|
3
|
+
$Call,
|
|
4
|
+
$VArgs,
|
|
5
|
+
VM_ARRAY_MAX_LENGTH,
|
|
6
|
+
VM_FUNCTION_ANONYMOUS_NAME,
|
|
7
|
+
VM_SCRIPT_NAME,
|
|
8
|
+
VmError,
|
|
9
|
+
VmFunction,
|
|
10
|
+
VmWrapper,
|
|
11
|
+
constants_exports,
|
|
12
|
+
display,
|
|
13
|
+
getVmType,
|
|
14
|
+
isVmArray,
|
|
15
|
+
isVmCallable,
|
|
16
|
+
isVmConst,
|
|
17
|
+
isVmExtern,
|
|
18
|
+
isVmFunction,
|
|
19
|
+
isVmModule,
|
|
20
|
+
isVmPrimitive,
|
|
21
|
+
isVmRecord,
|
|
22
|
+
isVmWrapper,
|
|
23
|
+
kVmContext,
|
|
24
|
+
kVmModule,
|
|
25
|
+
kVmScript,
|
|
26
|
+
rethrowControl,
|
|
27
|
+
toString,
|
|
28
|
+
wrapEffect,
|
|
29
|
+
wrapToVmConst,
|
|
30
|
+
wrapToVmValue
|
|
31
|
+
} from "./chunk-7JTZW66P.js";
|
|
1
32
|
import {
|
|
2
33
|
DiagnosticCode,
|
|
34
|
+
emit,
|
|
35
|
+
formatDiagnostics,
|
|
36
|
+
generateBytecode,
|
|
37
|
+
parseDiagnostics
|
|
38
|
+
} from "./chunk-GTNLLZL4.js";
|
|
39
|
+
import {
|
|
3
40
|
NegativeInfinity,
|
|
4
41
|
NotNumber,
|
|
5
42
|
PositiveInfinity,
|
|
6
43
|
__export,
|
|
7
|
-
__reExport,
|
|
8
|
-
apply,
|
|
9
44
|
create,
|
|
10
45
|
defineProperty,
|
|
11
|
-
emit,
|
|
12
46
|
entries,
|
|
13
|
-
formatDiagnostics,
|
|
14
47
|
freeze,
|
|
15
48
|
fromEntries,
|
|
16
|
-
generateBytecode,
|
|
17
|
-
getOwnPropertyNames,
|
|
18
|
-
getPrototypeOf,
|
|
19
49
|
getRecord,
|
|
20
50
|
hasOwn,
|
|
21
51
|
hasOwnEnumerable,
|
|
@@ -26,10 +56,9 @@ import {
|
|
|
26
56
|
isSafeInteger,
|
|
27
57
|
keys,
|
|
28
58
|
keysLength,
|
|
29
|
-
parseDiagnostics,
|
|
30
59
|
setRecord,
|
|
31
60
|
values
|
|
32
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-H2OHULLB.js";
|
|
33
62
|
|
|
34
63
|
// src/compiler/load-module.ts
|
|
35
64
|
import { loadModule } from "@mirascript/bindings";
|
|
@@ -38,515 +67,6 @@ try {
|
|
|
38
67
|
} catch (error) {
|
|
39
68
|
}
|
|
40
69
|
|
|
41
|
-
// src/helpers/constants.ts
|
|
42
|
-
var constants_exports = {};
|
|
43
|
-
__export(constants_exports, {
|
|
44
|
-
VM_ARRAY_MAX_LENGTH: () => VM_ARRAY_MAX_LENGTH,
|
|
45
|
-
VM_FUNCTION_ANONYMOUS_NAME: () => VM_FUNCTION_ANONYMOUS_NAME,
|
|
46
|
-
VM_SCRIPT_NAME: () => VM_SCRIPT_NAME,
|
|
47
|
-
kVmContext: () => kVmContext,
|
|
48
|
-
kVmExtern: () => kVmExtern,
|
|
49
|
-
kVmFunction: () => kVmFunction,
|
|
50
|
-
kVmFunctionProxy: () => kVmFunctionProxy,
|
|
51
|
-
kVmModule: () => kVmModule,
|
|
52
|
-
kVmScript: () => kVmScript,
|
|
53
|
-
kVmWrapper: () => kVmWrapper
|
|
54
|
-
});
|
|
55
|
-
__reExport(constants_exports, constants_star);
|
|
56
|
-
import * as constants_star from "@mirascript/constants";
|
|
57
|
-
var VM_ARRAY_MAX_LENGTH = 16777216;
|
|
58
|
-
var kVmScript = /* @__PURE__ */ Symbol.for("mirascript.vm.script");
|
|
59
|
-
var kVmFunction = /* @__PURE__ */ Symbol.for("mirascript.vm.function");
|
|
60
|
-
var kVmFunctionProxy = /* @__PURE__ */ Symbol.for("mirascript.vm.function.proxy");
|
|
61
|
-
var kVmContext = /* @__PURE__ */ Symbol.for("mirascript.vm.context");
|
|
62
|
-
var kVmExtern = /* @__PURE__ */ Symbol.for("mirascript.vm.extern");
|
|
63
|
-
var kVmModule = /* @__PURE__ */ Symbol.for("mirascript.vm.module");
|
|
64
|
-
var kVmWrapper = /* @__PURE__ */ Symbol.for("mirascript.vm.wrapper");
|
|
65
|
-
var VM_SCRIPT_NAME = `<script_root>`;
|
|
66
|
-
var VM_FUNCTION_ANONYMOUS_NAME = `<anonymous>`;
|
|
67
|
-
|
|
68
|
-
// src/helpers/types/basic.ts
|
|
69
|
-
function isVmScript(value) {
|
|
70
|
-
return typeof value === "function" && kVmScript in value;
|
|
71
|
-
}
|
|
72
|
-
function isVmContext(context) {
|
|
73
|
-
return context != null && typeof context == "object" && kVmContext in context;
|
|
74
|
-
}
|
|
75
|
-
function isVmFunction(value) {
|
|
76
|
-
return typeof value == "function" && kVmFunction in value;
|
|
77
|
-
}
|
|
78
|
-
function getVmFunctionInfo(value) {
|
|
79
|
-
if (typeof value != "function") return void 0;
|
|
80
|
-
return value[kVmFunction];
|
|
81
|
-
}
|
|
82
|
-
function isVmWrapper(value) {
|
|
83
|
-
return value != null && typeof value == "object" && kVmWrapper in value;
|
|
84
|
-
}
|
|
85
|
-
function isVmModule(value) {
|
|
86
|
-
return value != null && typeof value == "object" && kVmModule in value;
|
|
87
|
-
}
|
|
88
|
-
function isVmExtern(value) {
|
|
89
|
-
return value != null && typeof value == "object" && kVmExtern in value;
|
|
90
|
-
}
|
|
91
|
-
function isVmCallable(value) {
|
|
92
|
-
return isVmFunction(value) || isVmExtern(value) && typeof value.value == "function";
|
|
93
|
-
}
|
|
94
|
-
function isVmPrimitive(value) {
|
|
95
|
-
if (value === null || typeof value == "number" || typeof value == "string" || typeof value == "boolean") {
|
|
96
|
-
value;
|
|
97
|
-
value;
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
function isVmArray(value) {
|
|
103
|
-
if (!isArray(value)) return false;
|
|
104
|
-
value;
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
function isVmRecord(value) {
|
|
108
|
-
if (value == null || typeof value != "object") return false;
|
|
109
|
-
if (isVmWrapper(value) || isVmArray(value)) return false;
|
|
110
|
-
value;
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// src/helpers/types/proto.ts
|
|
115
|
-
function isPlainArray(value) {
|
|
116
|
-
const proto = getPrototypeOf(value);
|
|
117
|
-
return isArray(proto) && hasOwn(proto, "push");
|
|
118
|
-
}
|
|
119
|
-
function isPlainObject(value) {
|
|
120
|
-
const proto1 = getPrototypeOf(value);
|
|
121
|
-
if (proto1 == null) return true;
|
|
122
|
-
const proto2 = getPrototypeOf(proto1);
|
|
123
|
-
if (proto2 != null) return false;
|
|
124
|
-
return hasOwn(proto1, "hasOwnProperty");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// src/helpers/types/const.ts
|
|
128
|
-
var MAX_DEPTH = 16;
|
|
129
|
-
function isVmArrayDeep(value, depth) {
|
|
130
|
-
if (!isPlainArray(value)) return false;
|
|
131
|
-
if (depth <= 0) return true;
|
|
132
|
-
const inner_depth = depth - 1;
|
|
133
|
-
return value.every((item) => isVmConstInner(item, inner_depth));
|
|
134
|
-
}
|
|
135
|
-
function isVmRecordDeep(value, depth) {
|
|
136
|
-
if (!isPlainObject(value)) return false;
|
|
137
|
-
if (depth <= 0) return true;
|
|
138
|
-
const inner_depth = depth - 1;
|
|
139
|
-
return values(value).every((value2) => isVmConstInner(value2, inner_depth));
|
|
140
|
-
}
|
|
141
|
-
function isVmConstInner(value, depth) {
|
|
142
|
-
if (value == null) return true;
|
|
143
|
-
if (typeof value == "string" || typeof value == "number" || typeof value == "boolean") return true;
|
|
144
|
-
if (typeof value == "object") {
|
|
145
|
-
if (isVmWrapper(value)) return false;
|
|
146
|
-
if (isArray(value)) {
|
|
147
|
-
return isVmArrayDeep(value, depth);
|
|
148
|
-
} else {
|
|
149
|
-
return isVmRecordDeep(value, depth);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
function isVmConst(value, checkDeep = false) {
|
|
155
|
-
if (value === void 0) return false;
|
|
156
|
-
return isVmConstInner(value, checkDeep ? MAX_DEPTH : 0);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// src/helpers/types/get-type.ts
|
|
160
|
-
function getVmType(value) {
|
|
161
|
-
if (value === void 0) return "uninitialized";
|
|
162
|
-
if (value === null) return "nil";
|
|
163
|
-
if (isVmWrapper(value)) return value.type;
|
|
164
|
-
if (isVmArray(value)) return "array";
|
|
165
|
-
if (typeof value == "object") return "record";
|
|
166
|
-
return typeof value;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// src/helpers/types/array-like.ts
|
|
170
|
-
function isVmArrayLikeRecordByEntries(entries3) {
|
|
171
|
-
const { length } = entries3;
|
|
172
|
-
if (length === 0) return true;
|
|
173
|
-
if (length > VM_ARRAY_MAX_LENGTH) return false;
|
|
174
|
-
const firstKey = entries3[0][0];
|
|
175
|
-
if (firstKey !== "0") return false;
|
|
176
|
-
const lastKey = entries3[length - 1][0];
|
|
177
|
-
if (lastKey !== String(length - 1)) return false;
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
function isVmArrayLikeRecordByKeys(keys4) {
|
|
181
|
-
const { length } = keys4;
|
|
182
|
-
if (length === 0) return true;
|
|
183
|
-
if (length > VM_ARRAY_MAX_LENGTH) return false;
|
|
184
|
-
const firstKey = keys4[0];
|
|
185
|
-
if (firstKey !== "0") return false;
|
|
186
|
-
const lastKey = keys4[length - 1];
|
|
187
|
-
if (lastKey !== String(length - 1)) return false;
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
function isVmArrayLikeRecord(value) {
|
|
191
|
-
return isVmArrayLikeRecordByKeys(keys(value));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// src/helpers/types/composed.ts
|
|
195
|
-
function isVmImmutable(value, checkDeep = false) {
|
|
196
|
-
return isVmModule(value) || isVmFunction(value) || isVmConst(value, checkDeep);
|
|
197
|
-
}
|
|
198
|
-
function isVmValue(value, checkDeep = false) {
|
|
199
|
-
return isVmWrapper(value) || isVmFunction(value) || isVmConst(value, checkDeep);
|
|
200
|
-
}
|
|
201
|
-
function isVmAny(value, checkDeep) {
|
|
202
|
-
if (value == null) return true;
|
|
203
|
-
return isVmValue(value, checkDeep);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// src/helpers/error.ts
|
|
207
|
-
var VmError = class _VmError extends Error {
|
|
208
|
-
constructor(message, recovered) {
|
|
209
|
-
super(message);
|
|
210
|
-
this.recovered = recovered;
|
|
211
|
-
this.name = "VmError";
|
|
212
|
-
}
|
|
213
|
-
/** 从其他错误构造 */
|
|
214
|
-
static from(prefix, error, recovered) {
|
|
215
|
-
if (prefix) {
|
|
216
|
-
if (prefix.endsWith(":")) {
|
|
217
|
-
prefix += " ";
|
|
218
|
-
} else if (!prefix.endsWith(": ")) {
|
|
219
|
-
prefix += ": ";
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
let vmError;
|
|
223
|
-
if (error instanceof Error) {
|
|
224
|
-
vmError = new _VmError(`${prefix}${error.message}`, recovered);
|
|
225
|
-
vmError.stack = error.stack;
|
|
226
|
-
} else {
|
|
227
|
-
vmError = new _VmError(`${prefix}${String(error)}`, recovered);
|
|
228
|
-
}
|
|
229
|
-
vmError.cause = error;
|
|
230
|
-
return vmError;
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
// src/helpers/serialize.ts
|
|
235
|
-
import { REG_IDENTIFIER_FULL, REG_ORDINAL_FULL } from "@mirascript/constants";
|
|
236
|
-
|
|
237
|
-
// src/helpers/convert/string.ts
|
|
238
|
-
function numberToString(value, minusZero) {
|
|
239
|
-
if (isNaN(value)) return "nan";
|
|
240
|
-
if (value === Infinity) return "inf";
|
|
241
|
-
if (value === -Infinity) return "-inf";
|
|
242
|
-
if (minusZero && value === 0 && 1 / value < 0) return "-0";
|
|
243
|
-
return String(value);
|
|
244
|
-
}
|
|
245
|
-
function innerToString(value, useBraces) {
|
|
246
|
-
if (value == null) return "nil";
|
|
247
|
-
if (typeof value == "number") return numberToString(value, false);
|
|
248
|
-
if (typeof value == "string" || typeof value == "boolean") return String(value);
|
|
249
|
-
if (typeof value == "function") return displayFunction(value);
|
|
250
|
-
if (isVmWrapper(value)) return value.toString(useBraces);
|
|
251
|
-
if (isVmArray(value)) {
|
|
252
|
-
const strings = [];
|
|
253
|
-
for (const item of value) {
|
|
254
|
-
strings.push(innerToString(item, true));
|
|
255
|
-
}
|
|
256
|
-
const results = strings.join(", ");
|
|
257
|
-
if (!useBraces) return results;
|
|
258
|
-
return `[${results}]`;
|
|
259
|
-
} else {
|
|
260
|
-
const entries3 = keys(value).map((key) => `${key}: ${innerToString(value[key], true)}`).join(", ");
|
|
261
|
-
if (!useBraces) return entries3;
|
|
262
|
-
return `(${entries3})`;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
function toString(value, fallback) {
|
|
266
|
-
if (typeof value == "string") return value;
|
|
267
|
-
if (value == null) return "";
|
|
268
|
-
try {
|
|
269
|
-
return innerToString(value, false);
|
|
270
|
-
} catch (ex) {
|
|
271
|
-
if (fallback === void 0) {
|
|
272
|
-
const e2 = new VmError(`Failed to convert value to string: ${display(value)}`, "");
|
|
273
|
-
e2.cause = ex;
|
|
274
|
-
throw e2;
|
|
275
|
-
}
|
|
276
|
-
return fallback;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// src/helpers/serialize.ts
|
|
281
|
-
function serializeNil() {
|
|
282
|
-
return "nil";
|
|
283
|
-
}
|
|
284
|
-
function serializeBoolean(value) {
|
|
285
|
-
return value ? "true" : "false";
|
|
286
|
-
}
|
|
287
|
-
function serializeNumber(value) {
|
|
288
|
-
return numberToString(value, true);
|
|
289
|
-
}
|
|
290
|
-
function serializeStringEscaped(escaped, options) {
|
|
291
|
-
return options.serializeStringEscape("\\" + escaped, options);
|
|
292
|
-
}
|
|
293
|
-
function serializeStringContent(value, options) {
|
|
294
|
-
return options.serializeStringContent(value, options);
|
|
295
|
-
}
|
|
296
|
-
var STRING_QUOTE = `'`;
|
|
297
|
-
var STRING_REG = new RegExp(String.raw`[${STRING_QUOTE}\\\$\p{C}\u2028\u2029]`, "gu");
|
|
298
|
-
var STRING_MARK = /^[\p{M}]$/u;
|
|
299
|
-
function serializeSpecialChar(char, options) {
|
|
300
|
-
if (char === STRING_QUOTE) {
|
|
301
|
-
return serializeStringEscaped(STRING_QUOTE, options);
|
|
302
|
-
} else if (char === "\0") {
|
|
303
|
-
return serializeStringEscaped(`0`, options);
|
|
304
|
-
} else if (char === "\n") {
|
|
305
|
-
return serializeStringEscaped(`n`, options);
|
|
306
|
-
} else if (char === "\r") {
|
|
307
|
-
return serializeStringEscaped(`r`, options);
|
|
308
|
-
} else if (char === " ") {
|
|
309
|
-
return serializeStringEscaped(`t`, options);
|
|
310
|
-
} else if (char === "\b") {
|
|
311
|
-
return serializeStringEscaped(`b`, options);
|
|
312
|
-
} else if (char === "\f") {
|
|
313
|
-
return serializeStringEscaped(`f`, options);
|
|
314
|
-
} else if (char === "\v") {
|
|
315
|
-
return serializeStringEscaped(`v`, options);
|
|
316
|
-
} else if (char === "\\") {
|
|
317
|
-
return serializeStringEscaped(`\\`, options);
|
|
318
|
-
} else if (char === "$") {
|
|
319
|
-
return serializeStringEscaped(`$`, options);
|
|
320
|
-
} else {
|
|
321
|
-
const code = char.codePointAt(0);
|
|
322
|
-
if (code <= 127) {
|
|
323
|
-
return serializeStringEscaped(`x${code.toString(16).padStart(2, "0")}`, options);
|
|
324
|
-
} else if (code >= 55296 && code <= 57343) {
|
|
325
|
-
return serializeStringContent("�", options);
|
|
326
|
-
} else {
|
|
327
|
-
return serializeStringEscaped(`u{${code.toString(16)}}`, options);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
function serializeStringImpl(value, options) {
|
|
332
|
-
const oq = options.serializeStringQuote(STRING_QUOTE, true, options);
|
|
333
|
-
const cq = options.serializeStringQuote(STRING_QUOTE, false, options);
|
|
334
|
-
if (value.length === 0) {
|
|
335
|
-
return oq + cq;
|
|
336
|
-
}
|
|
337
|
-
let ret = oq;
|
|
338
|
-
let lastIndex = 0;
|
|
339
|
-
while (value.length > lastIndex) {
|
|
340
|
-
const cp2 = value.codePointAt(lastIndex);
|
|
341
|
-
const ch = String.fromCodePoint(cp2);
|
|
342
|
-
if (!STRING_MARK.test(ch)) break;
|
|
343
|
-
ret += serializeStringEscaped(`u{${cp2.toString(16)}}`, options);
|
|
344
|
-
lastIndex += ch.length;
|
|
345
|
-
}
|
|
346
|
-
STRING_REG.lastIndex = lastIndex;
|
|
347
|
-
let match;
|
|
348
|
-
while ((match = STRING_REG.exec(value)) !== null) {
|
|
349
|
-
ret += serializeStringContent(value.slice(lastIndex, match.index), options);
|
|
350
|
-
lastIndex = STRING_REG.lastIndex;
|
|
351
|
-
ret += serializeSpecialChar(match[0], options);
|
|
352
|
-
}
|
|
353
|
-
ret += serializeStringContent(value.slice(lastIndex), options);
|
|
354
|
-
ret += cq;
|
|
355
|
-
return ret;
|
|
356
|
-
}
|
|
357
|
-
function serializeString(value, options) {
|
|
358
|
-
return serializeStringImpl(value, getSerializeOptions(options));
|
|
359
|
-
}
|
|
360
|
-
function serializeRecordKeyDefault(key) {
|
|
361
|
-
if (REG_ORDINAL_FULL.test(key) || REG_IDENTIFIER_FULL.test(key)) {
|
|
362
|
-
return key;
|
|
363
|
-
}
|
|
364
|
-
return serializeStringImpl(key, DEFAULT_OPTIONS);
|
|
365
|
-
}
|
|
366
|
-
function serializeRecordKeyOpt(value, options) {
|
|
367
|
-
if (isDefaultOptions(options)) {
|
|
368
|
-
return serializeRecordKeyDefault(value);
|
|
369
|
-
}
|
|
370
|
-
if (REG_ORDINAL_FULL.test(value)) {
|
|
371
|
-
return options.serializePropName(Number(value), options);
|
|
372
|
-
}
|
|
373
|
-
if (REG_IDENTIFIER_FULL.test(value)) {
|
|
374
|
-
return options.serializePropName(value, options);
|
|
375
|
-
}
|
|
376
|
-
return options.serializeString(value, options);
|
|
377
|
-
}
|
|
378
|
-
function serializeRecordKey(key, options) {
|
|
379
|
-
if (isDefaultOptions(options)) {
|
|
380
|
-
return serializeRecordKeyDefault(key);
|
|
381
|
-
}
|
|
382
|
-
return serializeRecordKeyOpt(key, getSerializeOptions(options));
|
|
383
|
-
}
|
|
384
|
-
function serializeArray(value, depth, options) {
|
|
385
|
-
if (depth > options.maxDepth) return `[]`;
|
|
386
|
-
if (value.length === 0) return "[]";
|
|
387
|
-
let result = "[";
|
|
388
|
-
for (let i = 0; i < value.length; i++) {
|
|
389
|
-
if (i > 0) result += ", ";
|
|
390
|
-
result += serializeImpl(value[i], depth, options);
|
|
391
|
-
}
|
|
392
|
-
result += "]";
|
|
393
|
-
return result;
|
|
394
|
-
}
|
|
395
|
-
var { valueOf } = Object.prototype;
|
|
396
|
-
function customValueOf(value) {
|
|
397
|
-
const thisValueOf = value.valueOf;
|
|
398
|
-
if (typeof thisValueOf !== "function" || thisValueOf === valueOf) {
|
|
399
|
-
return void 0;
|
|
400
|
-
}
|
|
401
|
-
const customValue = thisValueOf.call(value);
|
|
402
|
-
if (customValue === value) return void 0;
|
|
403
|
-
return customValue;
|
|
404
|
-
}
|
|
405
|
-
function serializeRecord(value, depth, options) {
|
|
406
|
-
const customValue = customValueOf(value);
|
|
407
|
-
if (customValue !== void 0) {
|
|
408
|
-
return serializeImpl(customValue, depth - 1, options);
|
|
409
|
-
}
|
|
410
|
-
if (depth > options.maxDepth) return `()`;
|
|
411
|
-
const e2 = entries(value);
|
|
412
|
-
if (e2.length === 0) return "()";
|
|
413
|
-
if (e2.length === 1) {
|
|
414
|
-
const [k, v] = e2[0];
|
|
415
|
-
if (k === "0") {
|
|
416
|
-
return `(${serializeImpl(v, depth, options)},)`;
|
|
417
|
-
}
|
|
418
|
-
return `(${serializeRecordKeyOpt(k, options)}: ${serializeImpl(v, depth, options)})`;
|
|
419
|
-
}
|
|
420
|
-
const omitKey = isVmArrayLikeRecordByEntries(e2);
|
|
421
|
-
let result = "(";
|
|
422
|
-
for (const [key, val] of e2) {
|
|
423
|
-
if (result.length > 1) result += ", ";
|
|
424
|
-
if (omitKey) {
|
|
425
|
-
result += serializeImpl(val, depth, options);
|
|
426
|
-
} else {
|
|
427
|
-
result += `${serializeRecordKeyOpt(key, options)}: ${serializeImpl(val, depth, options)}`;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
result += ")";
|
|
431
|
-
return result;
|
|
432
|
-
}
|
|
433
|
-
function serializeImpl(value, depth, options) {
|
|
434
|
-
if (value == null) {
|
|
435
|
-
return options.serializeNil(options);
|
|
436
|
-
}
|
|
437
|
-
if (typeof value == "boolean") {
|
|
438
|
-
return options.serializeBoolean(value, options);
|
|
439
|
-
}
|
|
440
|
-
if (typeof value == "number") {
|
|
441
|
-
return options.serializeNumber(value, options);
|
|
442
|
-
}
|
|
443
|
-
if (typeof value == "string") {
|
|
444
|
-
return options.serializeString(value, options);
|
|
445
|
-
}
|
|
446
|
-
if (isVmFunction(value)) {
|
|
447
|
-
return options.serializeFunction(value, options);
|
|
448
|
-
}
|
|
449
|
-
if (isVmModule(value)) {
|
|
450
|
-
return options.serializeModule(value, depth + 1, options);
|
|
451
|
-
}
|
|
452
|
-
if (isVmExtern(value)) {
|
|
453
|
-
return options.serializeExtern(value, depth + 1, options);
|
|
454
|
-
}
|
|
455
|
-
if (isVmArray(value)) {
|
|
456
|
-
return options.serializeArray(value, depth + 1, options);
|
|
457
|
-
}
|
|
458
|
-
if (isVmRecord(value)) {
|
|
459
|
-
return options.serializeRecord(value, depth + 1, options);
|
|
460
|
-
}
|
|
461
|
-
value;
|
|
462
|
-
return options.serializeNil(options);
|
|
463
|
-
}
|
|
464
|
-
function serialize(value, options) {
|
|
465
|
-
return serializeImpl(value, 0, getSerializeOptions(options));
|
|
466
|
-
}
|
|
467
|
-
function displayFunction(value) {
|
|
468
|
-
try {
|
|
469
|
-
const name = getVmFunctionInfo(value)?.fullName;
|
|
470
|
-
return name ? `<function ${name}>` : `<function>`;
|
|
471
|
-
} catch {
|
|
472
|
-
return `<function>`;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
function displayModule(value) {
|
|
476
|
-
try {
|
|
477
|
-
return value.toString(true);
|
|
478
|
-
} catch {
|
|
479
|
-
return `<module>`;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
function displayExtern(value) {
|
|
483
|
-
try {
|
|
484
|
-
const tag = `<extern ${value.tag}>`;
|
|
485
|
-
const rep = value.toString(true);
|
|
486
|
-
if (rep === tag || rep.length > 50) {
|
|
487
|
-
return tag;
|
|
488
|
-
}
|
|
489
|
-
return `${tag} ${rep}`;
|
|
490
|
-
} catch {
|
|
491
|
-
return `<extern>`;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function display(value, options) {
|
|
495
|
-
const opt = mergeOptions(DISPLAY_OPTIONS, options);
|
|
496
|
-
return serializeImpl(value, 0, opt);
|
|
497
|
-
}
|
|
498
|
-
function isDefaultOptions(options) {
|
|
499
|
-
return options == null || options === DEFAULT_OPTIONS;
|
|
500
|
-
}
|
|
501
|
-
function mergeOptions(base, options) {
|
|
502
|
-
if (options == null) return base;
|
|
503
|
-
let opt = null;
|
|
504
|
-
for (const key in options) {
|
|
505
|
-
if (!hasOwn(options, key) || !hasOwn(base, key)) continue;
|
|
506
|
-
const el = options[key];
|
|
507
|
-
if (el == null) continue;
|
|
508
|
-
opt ??= { ...base };
|
|
509
|
-
opt[key] = el;
|
|
510
|
-
}
|
|
511
|
-
return opt ? Object.freeze(opt) : base;
|
|
512
|
-
}
|
|
513
|
-
function getSerializeOptions(options) {
|
|
514
|
-
if (isDefaultOptions(options)) return DEFAULT_OPTIONS;
|
|
515
|
-
return mergeOptions(DEFAULT_OPTIONS, options);
|
|
516
|
-
}
|
|
517
|
-
var DEFAULT_OPTIONS = Object.freeze({
|
|
518
|
-
maxDepth: 128,
|
|
519
|
-
serializeNil,
|
|
520
|
-
serializeBoolean,
|
|
521
|
-
serializeNumber,
|
|
522
|
-
serializeString: serializeStringImpl,
|
|
523
|
-
serializeStringQuote: (value) => value,
|
|
524
|
-
serializeStringEscape: (value) => value,
|
|
525
|
-
serializeStringContent: (value) => value,
|
|
526
|
-
serializeArray,
|
|
527
|
-
serializeRecord,
|
|
528
|
-
serializePropName: String,
|
|
529
|
-
serializeFunction: serializeNil,
|
|
530
|
-
serializeModule: serializeNil,
|
|
531
|
-
serializeExtern: serializeNil
|
|
532
|
-
});
|
|
533
|
-
var DISPLAY_OPTIONS = Object.freeze({
|
|
534
|
-
maxDepth: 3,
|
|
535
|
-
serializeNil,
|
|
536
|
-
serializeBoolean,
|
|
537
|
-
serializeNumber,
|
|
538
|
-
serializeString: serializeStringImpl,
|
|
539
|
-
serializeStringQuote: (value) => value,
|
|
540
|
-
serializeStringEscape: (value) => value,
|
|
541
|
-
serializeStringContent: (value) => value,
|
|
542
|
-
serializeArray,
|
|
543
|
-
serializeRecord,
|
|
544
|
-
serializePropName: String,
|
|
545
|
-
serializeFunction: displayFunction,
|
|
546
|
-
serializeModule: displayModule,
|
|
547
|
-
serializeExtern: displayExtern
|
|
548
|
-
});
|
|
549
|
-
|
|
550
70
|
// src/helpers/convert/index.ts
|
|
551
71
|
var convert_exports = {};
|
|
552
72
|
__export(convert_exports, {
|
|
@@ -637,381 +157,6 @@ function toBoolean(value, fallback) {
|
|
|
637
157
|
return fallback;
|
|
638
158
|
}
|
|
639
159
|
|
|
640
|
-
// src/vm/types/wrapper.ts
|
|
641
|
-
var VmWrapper = class {
|
|
642
|
-
constructor(value) {
|
|
643
|
-
this.value = value;
|
|
644
|
-
}
|
|
645
|
-
/** 描述键对应的值 */
|
|
646
|
-
describe(key) {
|
|
647
|
-
return void 0;
|
|
648
|
-
}
|
|
649
|
-
/** 转为字符串 */
|
|
650
|
-
toString(useBraces) {
|
|
651
|
-
const { type, tag } = this;
|
|
652
|
-
if (!tag) return `<${type}>`;
|
|
653
|
-
return `<${type} ${tag}>`;
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
Object.defineProperty(VmWrapper.prototype, kVmWrapper, { value: true });
|
|
657
|
-
|
|
658
|
-
// src/vm/operations/common.ts
|
|
659
|
-
var $AssertInit = (value) => {
|
|
660
|
-
if (value === void 0) throw new VmError(`Uninitialized value`, null);
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
// src/vm/operations/call.ts
|
|
664
|
-
function $Call(func, args) {
|
|
665
|
-
const argsLen = args.length;
|
|
666
|
-
for (let i = 0; i < argsLen; i++) {
|
|
667
|
-
$AssertInit(args[i]);
|
|
668
|
-
}
|
|
669
|
-
if (typeof func == "function") {
|
|
670
|
-
return func(...args) ?? null;
|
|
671
|
-
}
|
|
672
|
-
if (isVmExtern(func)) {
|
|
673
|
-
return func.call(args) ?? null;
|
|
674
|
-
}
|
|
675
|
-
throw new VmError(`Value is not callable: ${display(func)}`, null);
|
|
676
|
-
}
|
|
677
|
-
function $VArgs(varags) {
|
|
678
|
-
for (let i = 0, l = varags.length; i < l; i++) {
|
|
679
|
-
const el = varags[i];
|
|
680
|
-
if (!isVmConst(el)) {
|
|
681
|
-
varags[i] = null;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
return varags;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
// src/vm/types/boundary.ts
|
|
688
|
-
function toVmFunctionProxy(fn) {
|
|
689
|
-
const cached = fn[kVmFunctionProxy];
|
|
690
|
-
if (cached != null) return cached;
|
|
691
|
-
const proxy = (...args) => {
|
|
692
|
-
const ret = $Call(
|
|
693
|
-
fn,
|
|
694
|
-
// 作为函数参数传入的值一定丢失了它的 this
|
|
695
|
-
args.map((v) => wrapToVmValue(v, null, null))
|
|
696
|
-
);
|
|
697
|
-
return unwrapFromVmValue(ret, true);
|
|
698
|
-
};
|
|
699
|
-
defineProperty(fn, kVmFunctionProxy, { value: proxy });
|
|
700
|
-
defineProperty(proxy, kVmFunctionProxy, { value: fn });
|
|
701
|
-
defineProperty(proxy, "name", {
|
|
702
|
-
value: fn.name,
|
|
703
|
-
configurable: true
|
|
704
|
-
});
|
|
705
|
-
return proxy;
|
|
706
|
-
}
|
|
707
|
-
function fromVmFunctionProxy(fn) {
|
|
708
|
-
if (isVmFunction(fn)) return fn;
|
|
709
|
-
const original = fn[kVmFunctionProxy];
|
|
710
|
-
if (original && isVmFunction(original)) return original;
|
|
711
|
-
return null;
|
|
712
|
-
}
|
|
713
|
-
function wrapToVmConst(value, assumeVmValue = null) {
|
|
714
|
-
if (value == null) return null;
|
|
715
|
-
switch (typeof value) {
|
|
716
|
-
case "function":
|
|
717
|
-
return null;
|
|
718
|
-
case "object": {
|
|
719
|
-
if (isVmWrapper(value)) return null;
|
|
720
|
-
if (value instanceof Date) return value.valueOf();
|
|
721
|
-
if (assumeVmValue?.(value)) return value;
|
|
722
|
-
return null;
|
|
723
|
-
}
|
|
724
|
-
case "string":
|
|
725
|
-
case "number":
|
|
726
|
-
case "boolean":
|
|
727
|
-
return value;
|
|
728
|
-
case "bigint":
|
|
729
|
-
return Number(value);
|
|
730
|
-
case "symbol":
|
|
731
|
-
case "undefined":
|
|
732
|
-
default:
|
|
733
|
-
return null;
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
function wrapToVmValue(value, thisArg = null, assumeVmValue = null) {
|
|
737
|
-
if (value == null) return null;
|
|
738
|
-
if (typeof value == "function") {
|
|
739
|
-
const unwrapped = fromVmFunctionProxy(value);
|
|
740
|
-
if (unwrapped != null) return unwrapped;
|
|
741
|
-
return new VmExtern(value, thisArg);
|
|
742
|
-
}
|
|
743
|
-
const constValue = wrapToVmConst(value, assumeVmValue);
|
|
744
|
-
if (constValue != null) return constValue;
|
|
745
|
-
if (typeof value == "object") {
|
|
746
|
-
if (isVmWrapper(value)) return value;
|
|
747
|
-
return new VmExtern(value);
|
|
748
|
-
}
|
|
749
|
-
return null;
|
|
750
|
-
}
|
|
751
|
-
function bindThis(fn, thisArg) {
|
|
752
|
-
if (thisArg == null) return fn;
|
|
753
|
-
return new Proxy(fn, {
|
|
754
|
-
apply(target, _thisArg, args) {
|
|
755
|
-
return apply(target, thisArg, args);
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
function unwrapFromVmValue(value, bindThisArg = true) {
|
|
760
|
-
if (isVmFunction(value)) {
|
|
761
|
-
return toVmFunctionProxy(value);
|
|
762
|
-
}
|
|
763
|
-
if (value == null || typeof value != "object") return value;
|
|
764
|
-
if (!isVmExtern(value)) return value;
|
|
765
|
-
if (value.thisArg == null || typeof value.value != "function") {
|
|
766
|
-
return value.value;
|
|
767
|
-
}
|
|
768
|
-
const f = value;
|
|
769
|
-
return bindThisArg ? bindThis(f.value, f.thisArg) : f.value;
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
// src/vm/types/extern/tag.ts
|
|
773
|
-
var ObjectPrototype = Object.prototype;
|
|
774
|
-
function getJsObjectTag(value) {
|
|
775
|
-
return ObjectPrototype.toString.call(value).slice(8, -1);
|
|
776
|
-
}
|
|
777
|
-
function classNameOf(kls) {
|
|
778
|
-
const { displayName } = kls;
|
|
779
|
-
if (typeof displayName === "string" && displayName.trim()) {
|
|
780
|
-
return displayName.trim();
|
|
781
|
-
}
|
|
782
|
-
const { name } = kls;
|
|
783
|
-
if (typeof name == "string" && name.length > 2) {
|
|
784
|
-
return name;
|
|
785
|
-
}
|
|
786
|
-
return null;
|
|
787
|
-
}
|
|
788
|
-
function getTag(value) {
|
|
789
|
-
const tag = getJsObjectTag(value);
|
|
790
|
-
if (tag === "Function") {
|
|
791
|
-
if ("prototype" in value && typeof value.prototype == "object") {
|
|
792
|
-
const className = classNameOf(value);
|
|
793
|
-
if (!className) return `class`;
|
|
794
|
-
return `class ${className}`;
|
|
795
|
-
}
|
|
796
|
-
return `function`;
|
|
797
|
-
}
|
|
798
|
-
if (tag === "AsyncFunction") {
|
|
799
|
-
return `async function`;
|
|
800
|
-
}
|
|
801
|
-
if (tag === "GeneratorFunction") {
|
|
802
|
-
return `function*`;
|
|
803
|
-
}
|
|
804
|
-
if (tag === "AsyncGeneratorFunction") {
|
|
805
|
-
return `async function*`;
|
|
806
|
-
}
|
|
807
|
-
if (tag === "Object") {
|
|
808
|
-
const proto = getPrototypeOf(value);
|
|
809
|
-
if (proto === ObjectPrototype) {
|
|
810
|
-
return "Object";
|
|
811
|
-
}
|
|
812
|
-
if (proto == null) {
|
|
813
|
-
return "Object: null prototype";
|
|
814
|
-
}
|
|
815
|
-
if (typeof proto.constructor === "function") {
|
|
816
|
-
return classNameOf(proto.constructor) ?? "Object";
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
return tag;
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
// src/vm/types/extern/utils.ts
|
|
823
|
-
function isArrayLike(value) {
|
|
824
|
-
return isArray(value) || ArrayBuffer.isView(value) && "length" in value;
|
|
825
|
-
}
|
|
826
|
-
function getKeys(value, includeNonEnumerable) {
|
|
827
|
-
if (!includeNonEnumerable) {
|
|
828
|
-
const keys5 = [];
|
|
829
|
-
for (const key in value) {
|
|
830
|
-
keys5.push(key);
|
|
831
|
-
}
|
|
832
|
-
return keys5;
|
|
833
|
-
}
|
|
834
|
-
const keys4 = /* @__PURE__ */ new Set();
|
|
835
|
-
let e2 = value;
|
|
836
|
-
while (e2 != null && (typeof e2 == "object" || typeof e2 == "function")) {
|
|
837
|
-
for (const key of getOwnPropertyNames(e2)) {
|
|
838
|
-
keys4.add(key);
|
|
839
|
-
}
|
|
840
|
-
e2 = getPrototypeOf(e2);
|
|
841
|
-
}
|
|
842
|
-
return Array.from(keys4);
|
|
843
|
-
}
|
|
844
|
-
var ObjectToString = Object.prototype.toString;
|
|
845
|
-
var FunctionToString = Function.prototype.toString;
|
|
846
|
-
var ArrayToString = Array.prototype.toString;
|
|
847
|
-
var TypedArrayToString = Uint8Array.prototype.toString;
|
|
848
|
-
function hasCustomToString(value) {
|
|
849
|
-
const { toString: toString2 } = value;
|
|
850
|
-
if (typeof toString2 != "function") return false;
|
|
851
|
-
if (toString2 === ObjectToString || toString2 === FunctionToString || toString2 === ArrayToString || toString2 === TypedArrayToString)
|
|
852
|
-
return false;
|
|
853
|
-
return true;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// src/vm/types/extern/access.ts
|
|
857
|
-
var pFunction = Function.prototype;
|
|
858
|
-
var pArray = Array.prototype;
|
|
859
|
-
var pObject = Object.prototype;
|
|
860
|
-
function canAccessProperty(value, key, read) {
|
|
861
|
-
if (key.startsWith("_")) return false;
|
|
862
|
-
if (typeof value == "function" && (key === "prototype" || key === "arguments" || key === "caller")) return false;
|
|
863
|
-
if (hasOwn(value, key)) return true;
|
|
864
|
-
if (!read) return true;
|
|
865
|
-
if (!(key in value)) return false;
|
|
866
|
-
if (key === "constructor") return false;
|
|
867
|
-
const prop = value[key];
|
|
868
|
-
if (key in pFunction && prop === pFunction[key]) return false;
|
|
869
|
-
if (key in pArray && prop === pArray[key]) return false;
|
|
870
|
-
if (key in pObject && prop === pObject[key]) return false;
|
|
871
|
-
return true;
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
// src/vm/types/extern/index.ts
|
|
875
|
-
var ArrayMap = Array.prototype.map;
|
|
876
|
-
var VmExtern = class extends VmWrapper {
|
|
877
|
-
constructor(value, thisArg = null) {
|
|
878
|
-
super(value);
|
|
879
|
-
this.thisArg = thisArg;
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
* Check if the object has a property
|
|
883
|
-
* This method will be used in {@link get}, {@link set}, {@link has}, and {@link keys} methods
|
|
884
|
-
*/
|
|
885
|
-
access(key, read) {
|
|
886
|
-
return canAccessProperty(this.value, key, read);
|
|
887
|
-
}
|
|
888
|
-
/** 决定是否对属性进行包装 */
|
|
889
|
-
assumeVmValue(value, key) {
|
|
890
|
-
return false;
|
|
891
|
-
}
|
|
892
|
-
/** @inheritdoc */
|
|
893
|
-
has(key) {
|
|
894
|
-
return this.access(key, true);
|
|
895
|
-
}
|
|
896
|
-
/** @inheritdoc */
|
|
897
|
-
get(key) {
|
|
898
|
-
if (!(key in this.value)) return void 0;
|
|
899
|
-
if (!this.access(key, true)) return void 0;
|
|
900
|
-
const prop = this.value[key];
|
|
901
|
-
return wrapToVmValue(prop, this.value, (v) => this.assumeVmValue(v, key));
|
|
902
|
-
}
|
|
903
|
-
/** Set a property on the object */
|
|
904
|
-
set(key, value) {
|
|
905
|
-
if (!this.access(key, false)) return false;
|
|
906
|
-
const prop = unwrapFromVmValue(value, true);
|
|
907
|
-
this.value[key] = prop;
|
|
908
|
-
return true;
|
|
909
|
-
}
|
|
910
|
-
/** Call extern value */
|
|
911
|
-
call(args) {
|
|
912
|
-
const { value } = this;
|
|
913
|
-
if (typeof value != "function") {
|
|
914
|
-
throw VmError.from(`Not a callable extern`, null, null);
|
|
915
|
-
}
|
|
916
|
-
const caller = this.thisArg;
|
|
917
|
-
const unwrappedArgs = args.map((arg) => unwrapFromVmValue(arg, true));
|
|
918
|
-
let ret;
|
|
919
|
-
try {
|
|
920
|
-
ret = apply(value, caller, unwrappedArgs);
|
|
921
|
-
} catch (ex) {
|
|
922
|
-
throw VmError.from(`Callable extern`, ex, null);
|
|
923
|
-
}
|
|
924
|
-
return wrapToVmValue(ret, null, (obj) => this.assumeVmValue(obj, void 0));
|
|
925
|
-
}
|
|
926
|
-
/** @inheritdoc */
|
|
927
|
-
keys(includeNonEnumerable = false) {
|
|
928
|
-
const keys4 = getKeys(this.value, includeNonEnumerable);
|
|
929
|
-
return keys4.filter((key) => this.access(key, true));
|
|
930
|
-
}
|
|
931
|
-
/** @inheritdoc */
|
|
932
|
-
same(other) {
|
|
933
|
-
if (!isVmExtern(other)) return false;
|
|
934
|
-
return this.value === other.value && this.thisArg === other.thisArg;
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
* Should this extern be treated as array-like?
|
|
938
|
-
*
|
|
939
|
-
* By default, this method returns true if the wrapped value is an Array or a TypedArray.
|
|
940
|
-
*/
|
|
941
|
-
isArrayLike() {
|
|
942
|
-
return isArrayLike(this.value);
|
|
943
|
-
}
|
|
944
|
-
/** @inheritdoc */
|
|
945
|
-
toString(useBraces) {
|
|
946
|
-
if (hasCustomToString(this.value)) {
|
|
947
|
-
return String(this.value);
|
|
948
|
-
}
|
|
949
|
-
if (this.isArrayLike()) {
|
|
950
|
-
const mapped = ArrayMap.call(this.value, (item) => {
|
|
951
|
-
if (item === void 0) return "";
|
|
952
|
-
return innerToString(wrapToVmValue(item ?? null, null, null), true);
|
|
953
|
-
});
|
|
954
|
-
const str = mapped.join(", ");
|
|
955
|
-
if (useBraces) return `[${str}]`;
|
|
956
|
-
return str;
|
|
957
|
-
}
|
|
958
|
-
return super.toString(useBraces);
|
|
959
|
-
}
|
|
960
|
-
/** @inheritdoc */
|
|
961
|
-
get type() {
|
|
962
|
-
return "extern";
|
|
963
|
-
}
|
|
964
|
-
/** @inheritdoc */
|
|
965
|
-
get tag() {
|
|
966
|
-
const tag = getTag(this.value);
|
|
967
|
-
if (this.isArrayLike()) {
|
|
968
|
-
return `${tag}(${this.value.length})`;
|
|
969
|
-
}
|
|
970
|
-
return tag;
|
|
971
|
-
}
|
|
972
|
-
};
|
|
973
|
-
Object.defineProperty(VmExtern.prototype, kVmExtern, { value: true });
|
|
974
|
-
|
|
975
|
-
// src/vm/types/function.ts
|
|
976
|
-
var nameIfNotAnonymous = ({ name }, fallback) => {
|
|
977
|
-
if (!name) return fallback;
|
|
978
|
-
if (name === VM_FUNCTION_ANONYMOUS_NAME) return fallback;
|
|
979
|
-
return name;
|
|
980
|
-
};
|
|
981
|
-
function VmFunction(fn, option = {}) {
|
|
982
|
-
if (typeof fn != "function") {
|
|
983
|
-
throw new TypeError("Invalid function");
|
|
984
|
-
}
|
|
985
|
-
const exists = fromVmFunctionProxy(fn);
|
|
986
|
-
if (exists) return exists;
|
|
987
|
-
let opt;
|
|
988
|
-
if (isVmFunction(option)) {
|
|
989
|
-
opt = { ...option[kVmFunction], name: nameIfNotAnonymous(option, null) };
|
|
990
|
-
} else if (typeof option == "function") {
|
|
991
|
-
opt = {
|
|
992
|
-
...option,
|
|
993
|
-
isLib: true,
|
|
994
|
-
name: nameIfNotAnonymous(option, null)
|
|
995
|
-
};
|
|
996
|
-
} else {
|
|
997
|
-
opt = option;
|
|
998
|
-
}
|
|
999
|
-
const info = {
|
|
1000
|
-
__proto__: null,
|
|
1001
|
-
fullName: opt.fullName ?? nameIfNotAnonymous(fn, ""),
|
|
1002
|
-
isLib: opt.isLib ?? false,
|
|
1003
|
-
summary: opt.summary || void 0,
|
|
1004
|
-
params: opt.params,
|
|
1005
|
-
returns: opt.returns ?? void 0,
|
|
1006
|
-
examples: opt.examples?.length ? opt.examples : void 0,
|
|
1007
|
-
deprecated: opt.deprecated ?? void 0
|
|
1008
|
-
};
|
|
1009
|
-
const name = opt.name ?? fn.name;
|
|
1010
|
-
defineProperty(fn, "name", { value: name, configurable: true });
|
|
1011
|
-
defineProperty(fn, kVmFunction, { value: freeze(info) });
|
|
1012
|
-
return fn;
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
160
|
// src/vm/types/context.ts
|
|
1016
161
|
var VM_SHARED_CONTEXT = create(null);
|
|
1017
162
|
var VM_SHARED_CONTEXT_DESCRIPTIONS = create(null);
|
|
@@ -1216,7 +361,7 @@ var { now } = Date;
|
|
|
1216
361
|
var TIME_ORIGIN = now() - 1e3 * 3600 * 12;
|
|
1217
362
|
var timestamp = () => now() - TIME_ORIGIN | 0;
|
|
1218
363
|
var CP_DEFAULT_INTERVAL = 100;
|
|
1219
|
-
var
|
|
364
|
+
var MAX_DEPTH = 128;
|
|
1220
365
|
var CP_UNSET = -1;
|
|
1221
366
|
var CP_DEFAULT_TIMEOUT = 100;
|
|
1222
367
|
var cpTimeout = CP_DEFAULT_TIMEOUT | 0;
|
|
@@ -1241,7 +386,7 @@ var CpEnter = () => {
|
|
|
1241
386
|
cp = CP_UNSET | 0;
|
|
1242
387
|
cpCounter = 0;
|
|
1243
388
|
cpDepth = 1;
|
|
1244
|
-
} else if ((cpDepth | 0) >
|
|
389
|
+
} else if ((cpDepth | 0) > MAX_DEPTH) {
|
|
1245
390
|
throw new RangeError("Maximum call depth exceeded");
|
|
1246
391
|
} else {
|
|
1247
392
|
Cp();
|
|
@@ -2620,11 +1765,14 @@ var pow3 = VmLib((x, y) => _pow(expectNumber(0, x), expectNumber(1, y)), {
|
|
|
2620
1765
|
},
|
|
2621
1766
|
returns: { type: "number" }
|
|
2622
1767
|
});
|
|
2623
|
-
var random = VmLib(
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
}
|
|
1768
|
+
var random = VmLib(
|
|
1769
|
+
wrapEffect("memo", () => _random()),
|
|
1770
|
+
{
|
|
1771
|
+
summary: "返回 [0, 1) 之间的伪随机数",
|
|
1772
|
+
params: {},
|
|
1773
|
+
returns: { type: "number" }
|
|
1774
|
+
}
|
|
1775
|
+
);
|
|
2628
1776
|
|
|
2629
1777
|
// src/vm/lib/global/bit.ts
|
|
2630
1778
|
var b_and = VmLib(
|
|
@@ -3495,7 +2643,8 @@ function serializeValue(options, arg, format2) {
|
|
|
3495
2643
|
}
|
|
3496
2644
|
try {
|
|
3497
2645
|
return serializer.call(options, arg, format2);
|
|
3498
|
-
} catch {
|
|
2646
|
+
} catch (error) {
|
|
2647
|
+
rethrowControl(error);
|
|
3499
2648
|
return defaultSerializer(arg, format2);
|
|
3500
2649
|
}
|
|
3501
2650
|
}
|
|
@@ -3606,10 +2755,10 @@ var createPrintOptions = (consoleMethod) => {
|
|
|
3606
2755
|
logger: consoleMethod
|
|
3607
2756
|
};
|
|
3608
2757
|
};
|
|
3609
|
-
|
|
2758
|
+
var doPrint = wrapEffect("once", (opt, args) => {
|
|
3610
2759
|
const formatResult = opt.parser(args);
|
|
3611
2760
|
void Promise.resolve(opt.formatter(formatResult)).then((printed) => opt.logger(...printed));
|
|
3612
|
-
}
|
|
2761
|
+
});
|
|
3613
2762
|
var debug_print = VmLib(
|
|
3614
2763
|
(...args) => {
|
|
3615
2764
|
doPrint(debug_print, args);
|
|
@@ -3925,6 +3074,7 @@ var join = VmLib(
|
|
|
3925
3074
|
);
|
|
3926
3075
|
|
|
3927
3076
|
// src/vm/lib/global/time.ts
|
|
3077
|
+
var now2 = wrapEffect("memo", () => Date.now());
|
|
3928
3078
|
var fromNumber = (datetime, fallback) => {
|
|
3929
3079
|
const n = new Date(datetime).getTime();
|
|
3930
3080
|
if (isFinite(n)) return n;
|
|
@@ -3933,7 +3083,7 @@ var fromNumber = (datetime, fallback) => {
|
|
|
3933
3083
|
};
|
|
3934
3084
|
var getTimestamp = (datetime, fallback) => {
|
|
3935
3085
|
if (datetime == null) {
|
|
3936
|
-
return
|
|
3086
|
+
return now2();
|
|
3937
3087
|
}
|
|
3938
3088
|
if (typeof datetime == "number") {
|
|
3939
3089
|
return fromNumber(datetime, fallback);
|
|
@@ -4603,41 +3753,7 @@ for (const [name, value] of entries(mod_exports)) {
|
|
|
4603
3753
|
var lib = Object.freeze(Object.assign(create(null), global_exports, mod_exports));
|
|
4604
3754
|
|
|
4605
3755
|
export {
|
|
4606
|
-
constants_exports,
|
|
4607
|
-
isVmScript,
|
|
4608
|
-
isVmContext,
|
|
4609
|
-
isVmFunction,
|
|
4610
|
-
getVmFunctionInfo,
|
|
4611
|
-
isVmWrapper,
|
|
4612
|
-
isVmModule,
|
|
4613
|
-
isVmExtern,
|
|
4614
|
-
isVmCallable,
|
|
4615
|
-
isVmPrimitive,
|
|
4616
|
-
isVmArray,
|
|
4617
|
-
isVmRecord,
|
|
4618
|
-
isVmConst,
|
|
4619
|
-
getVmType,
|
|
4620
|
-
isVmArrayLikeRecordByEntries,
|
|
4621
|
-
isVmArrayLikeRecordByKeys,
|
|
4622
|
-
isVmArrayLikeRecord,
|
|
4623
|
-
isVmImmutable,
|
|
4624
|
-
isVmValue,
|
|
4625
|
-
isVmAny,
|
|
4626
|
-
VmError,
|
|
4627
|
-
serializeNil,
|
|
4628
|
-
serializeBoolean,
|
|
4629
|
-
serializeNumber,
|
|
4630
|
-
serializeString,
|
|
4631
|
-
serializeRecordKey,
|
|
4632
|
-
serializeArray,
|
|
4633
|
-
serializeRecord,
|
|
4634
|
-
serialize,
|
|
4635
|
-
display,
|
|
4636
3756
|
convert_exports,
|
|
4637
|
-
VmExtern,
|
|
4638
|
-
wrapToVmValue,
|
|
4639
|
-
unwrapFromVmValue,
|
|
4640
|
-
VmFunction,
|
|
4641
3757
|
defineVmContextValue,
|
|
4642
3758
|
DefaultVmContext,
|
|
4643
3759
|
createVmContext,
|
|
@@ -4653,4 +3769,4 @@ export {
|
|
|
4653
3769
|
compileVerbose,
|
|
4654
3770
|
lib
|
|
4655
3771
|
};
|
|
4656
|
-
//# sourceMappingURL=chunk-
|
|
3772
|
+
//# sourceMappingURL=chunk-F3FHURMG.js.map
|