@nyariv/sandboxjs 0.8.22 → 0.8.23
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/.github/workflows/npm-publish.yml +2 -2
- package/build/Sandbox.d.ts +5 -4
- package/build/Sandbox.js +1 -1
- package/build/executor.d.ts +46 -24
- package/build/executor.js +627 -624
- package/build/parser.d.ts +321 -52
- package/build/parser.js +217 -157
- package/dist/Sandbox.d.ts +5 -4
- package/dist/Sandbox.js +1 -1
- package/dist/Sandbox.js.map +1 -1
- package/dist/executor.d.ts +46 -24
- package/dist/node/Sandbox.d.ts +5 -4
- package/dist/node/Sandbox.js +842 -782
- package/dist/node/executor.d.ts +46 -24
- package/dist/node/parser.d.ts +321 -52
- package/dist/parser.d.ts +321 -52
- package/package.json +14 -14
- package/rollup.config.mjs +33 -0
- package/dist/Sandbox.min.js +0 -2
- package/dist/Sandbox.min.js.map +0 -1
package/dist/node/Sandbox.js
CHANGED
|
@@ -173,6 +173,9 @@ function unraw(raw) {
|
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
function createLisp(obj) {
|
|
177
|
+
return [obj.op, obj.a, obj.b];
|
|
178
|
+
}
|
|
176
179
|
let lispTypes = new Map();
|
|
177
180
|
class ParseError extends Error {
|
|
178
181
|
constructor(message, code) {
|
|
@@ -180,40 +183,6 @@ class ParseError extends Error {
|
|
|
180
183
|
this.code = code;
|
|
181
184
|
}
|
|
182
185
|
}
|
|
183
|
-
class Lisp {
|
|
184
|
-
constructor(obj) {
|
|
185
|
-
this.op = obj.op;
|
|
186
|
-
this.a = obj.a;
|
|
187
|
-
this.b = obj.b;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
class If {
|
|
191
|
-
constructor(t, f) {
|
|
192
|
-
this.t = t;
|
|
193
|
-
this.f = f;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
class KeyVal {
|
|
197
|
-
constructor(key, val) {
|
|
198
|
-
this.key = key;
|
|
199
|
-
this.val = val;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
class SpreadObject {
|
|
203
|
-
constructor(item) {
|
|
204
|
-
this.item = item;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
class SpreadArray {
|
|
208
|
-
constructor(item) {
|
|
209
|
-
this.item = item;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
const lispArrayKey = {};
|
|
213
|
-
function toLispArray(arr) {
|
|
214
|
-
arr.lisp = lispArrayKey;
|
|
215
|
-
return arr;
|
|
216
|
-
}
|
|
217
186
|
const inlineIfElse = /^:/;
|
|
218
187
|
const elseIf = /^else(?![\w\$])/;
|
|
219
188
|
const ifElse = /^if(?![\w\$])/;
|
|
@@ -336,7 +305,6 @@ let expectTypes = {
|
|
|
336
305
|
void: /^void(?![\w\$])\s*/,
|
|
337
306
|
await: /^await(?![\w\$])\s*/,
|
|
338
307
|
new: /^new(?![\w\$])\s*/,
|
|
339
|
-
throw: /^throw(?![\w\$])\s*/
|
|
340
308
|
},
|
|
341
309
|
next: [
|
|
342
310
|
'splitter',
|
|
@@ -350,6 +318,7 @@ let expectTypes = {
|
|
|
350
318
|
types: {
|
|
351
319
|
initialize: /^(var|let|const)\s+([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*(=)?/,
|
|
352
320
|
return: /^return(?![\w\$])/,
|
|
321
|
+
throw: /^throw(?![\w\$])\s*/
|
|
353
322
|
},
|
|
354
323
|
next: [
|
|
355
324
|
'modifier',
|
|
@@ -677,6 +646,16 @@ const closingsCreate = {
|
|
|
677
646
|
'arrayProp': /^\]/,
|
|
678
647
|
'call': /^\)/
|
|
679
648
|
};
|
|
649
|
+
const typesCreate = {
|
|
650
|
+
'createArray': 12 /* LispType.CreateArray */,
|
|
651
|
+
'createObject': 22 /* LispType.CreateObject */,
|
|
652
|
+
'group': 23 /* LispType.Group */,
|
|
653
|
+
'arrayProp': 19 /* LispType.ArrayProp */,
|
|
654
|
+
'call': 5 /* LispType.Call */,
|
|
655
|
+
'prop': 1 /* LispType.Prop */,
|
|
656
|
+
'?prop': 20 /* LispType.PropOptional */,
|
|
657
|
+
'?call': 21 /* LispType.CallOptional */,
|
|
658
|
+
};
|
|
680
659
|
setLispType(['createArray', 'createObject', 'group', 'arrayProp', 'call'], (constants, type, part, res, expect, ctx) => {
|
|
681
660
|
let extract = emptyString;
|
|
682
661
|
let arg = [];
|
|
@@ -689,7 +668,7 @@ setLispType(['createArray', 'createObject', 'group', 'arrayProp', 'call'], (cons
|
|
|
689
668
|
/^,/
|
|
690
669
|
]);
|
|
691
670
|
i += extract.length;
|
|
692
|
-
if (extract.length) {
|
|
671
|
+
if (extract.trim().length) {
|
|
693
672
|
arg.push(extract);
|
|
694
673
|
}
|
|
695
674
|
if (part.char(i) !== ',') {
|
|
@@ -710,13 +689,13 @@ setLispType(['createArray', 'createObject', 'group', 'arrayProp', 'call'], (cons
|
|
|
710
689
|
case 'call':
|
|
711
690
|
case 'createArray':
|
|
712
691
|
// @TODO: support 'empty' values
|
|
713
|
-
l =
|
|
692
|
+
l = arg.map((e) => lispify(constants, e, [...next, 'spreadArray']));
|
|
714
693
|
break;
|
|
715
694
|
case 'createObject':
|
|
716
|
-
l =
|
|
695
|
+
l = arg.map((str) => {
|
|
717
696
|
str = str.trimStart();
|
|
718
697
|
let value;
|
|
719
|
-
let key;
|
|
698
|
+
let key = '';
|
|
720
699
|
funcFound = expectTypes.expFunction.types.function.exec('function ' + str);
|
|
721
700
|
if (funcFound) {
|
|
722
701
|
key = funcFound[2].trimStart();
|
|
@@ -725,56 +704,111 @@ setLispType(['createArray', 'createObject', 'group', 'arrayProp', 'call'], (cons
|
|
|
725
704
|
else {
|
|
726
705
|
let extract = restOfExp(constants, str, [/^:/]);
|
|
727
706
|
key = lispify(constants, extract, [...next, 'spreadObject']);
|
|
728
|
-
if (key
|
|
729
|
-
key = key
|
|
707
|
+
if (key[0] === 1 /* LispType.Prop */) {
|
|
708
|
+
key = key[2];
|
|
730
709
|
}
|
|
731
|
-
if (extract.length === str.length)
|
|
732
|
-
return key;
|
|
733
710
|
value = lispify(constants, str.substring(extract.length + 1));
|
|
734
711
|
}
|
|
735
|
-
return
|
|
736
|
-
op:
|
|
712
|
+
return createLisp({
|
|
713
|
+
op: 6 /* LispType.KeyVal */,
|
|
737
714
|
a: key,
|
|
738
715
|
b: value
|
|
739
716
|
});
|
|
740
|
-
})
|
|
717
|
+
});
|
|
741
718
|
break;
|
|
742
719
|
}
|
|
743
|
-
|
|
744
|
-
ctx.lispTree = lispify(constants, part.substring(i + 1), expectTypes[expect].next,
|
|
745
|
-
op:
|
|
720
|
+
let lisptype = (type === 'arrayProp' ? (res[1] ? 20 /* LispType.PropOptional */ : 1 /* LispType.Prop */) : (type === 'call' ? (res[1] ? 21 /* LispType.CallOptional */ : 5 /* LispType.Call */) : typesCreate[type]));
|
|
721
|
+
ctx.lispTree = lispify(constants, part.substring(i + 1), expectTypes[expect].next, createLisp({
|
|
722
|
+
op: lisptype,
|
|
746
723
|
a: ctx.lispTree,
|
|
747
724
|
b: l,
|
|
748
725
|
}));
|
|
749
726
|
});
|
|
727
|
+
const modifierTypes = {
|
|
728
|
+
'inverse': 64 /* LispType.Inverse */,
|
|
729
|
+
'not': 24 /* LispType.Not */,
|
|
730
|
+
'positive': 59 /* LispType.Positive */,
|
|
731
|
+
'negative': 58 /* LispType.Negative */,
|
|
732
|
+
'typeof': 60 /* LispType.Typeof */,
|
|
733
|
+
'delete': 61 /* LispType.Delete */
|
|
734
|
+
};
|
|
750
735
|
setLispType(['inverse', 'not', 'negative', 'positive', 'typeof', 'delete'], (constants, type, part, res, expect, ctx) => {
|
|
751
736
|
let extract = restOfExp(constants, part.substring(res[0].length), [/^([^\s\.\?\w\$]|\?[^\.])/]);
|
|
752
|
-
ctx.lispTree = lispify(constants, part.substring(extract.length + res[0].length), restOfExp.next,
|
|
753
|
-
op: [
|
|
737
|
+
ctx.lispTree = lispify(constants, part.substring(extract.length + res[0].length), restOfExp.next, createLisp({
|
|
738
|
+
op: modifierTypes[type],
|
|
754
739
|
a: ctx.lispTree,
|
|
755
740
|
b: lispify(constants, extract, expectTypes[expect].next),
|
|
756
741
|
}));
|
|
757
742
|
});
|
|
743
|
+
const incrementTypes = {
|
|
744
|
+
'++$': 25 /* LispType.IncrementBefore */,
|
|
745
|
+
'--$': 27 /* LispType.DecrementBefore */,
|
|
746
|
+
'$++': 26 /* LispType.IncrementAfter */,
|
|
747
|
+
'$--': 28 /* LispType.DecrementAfter */
|
|
748
|
+
};
|
|
758
749
|
setLispType(['incrementerBefore'], (constants, type, part, res, expect, ctx) => {
|
|
759
750
|
let extract = restOfExp(constants, part.substring(2), [/^[^\s\.\w\$]/]);
|
|
760
|
-
ctx.lispTree = lispify(constants, part.substring(extract.length + 2), restOfExp.next,
|
|
761
|
-
op: res[0] + "$",
|
|
751
|
+
ctx.lispTree = lispify(constants, part.substring(extract.length + 2), restOfExp.next, createLisp({
|
|
752
|
+
op: incrementTypes[res[0] + "$"],
|
|
762
753
|
a: lispify(constants, extract, expectTypes[expect].next),
|
|
754
|
+
b: 0 /* LispType.None */
|
|
763
755
|
}));
|
|
764
756
|
});
|
|
765
757
|
setLispType(['incrementerAfter'], (constants, type, part, res, expect, ctx) => {
|
|
766
|
-
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next,
|
|
767
|
-
op: "$" + res[0],
|
|
758
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next, createLisp({
|
|
759
|
+
op: incrementTypes["$" + res[0]],
|
|
768
760
|
a: ctx.lispTree,
|
|
761
|
+
b: 0 /* LispType.None */
|
|
769
762
|
}));
|
|
770
763
|
});
|
|
764
|
+
const adderTypes = {
|
|
765
|
+
'&&': 29 /* LispType.And */,
|
|
766
|
+
'||': 30 /* LispType.Or */,
|
|
767
|
+
'instanceof': 62 /* LispType.Instanceof */,
|
|
768
|
+
'in': 63 /* LispType.In */,
|
|
769
|
+
'=': 9 /* LispType.Assign */,
|
|
770
|
+
'-=': 65 /* LispType.SubractEquals */,
|
|
771
|
+
'+=': 66 /* LispType.AddEquals */,
|
|
772
|
+
'/=': 67 /* LispType.DivideEquals */,
|
|
773
|
+
'**=': 68 /* LispType.PowerEquals */,
|
|
774
|
+
'*=': 69 /* LispType.MultiplyEquals */,
|
|
775
|
+
'%=': 70 /* LispType.ModulusEquals */,
|
|
776
|
+
'^=': 71 /* LispType.BitNegateEquals */,
|
|
777
|
+
'&=': 72 /* LispType.BitAndEquals */,
|
|
778
|
+
'|=': 73 /* LispType.BitOrEquals */,
|
|
779
|
+
'>>>=': 74 /* LispType.UnsignedShiftRightEquals */,
|
|
780
|
+
'<<=': 76 /* LispType.ShiftLeftEquals */,
|
|
781
|
+
'>>=': 75 /* LispType.ShiftRightEquals */,
|
|
782
|
+
};
|
|
771
783
|
setLispType(['assign', 'assignModify', 'boolOp'], (constants, type, part, res, expect, ctx) => {
|
|
772
|
-
ctx.lispTree =
|
|
773
|
-
op: res[0],
|
|
784
|
+
ctx.lispTree = createLisp({
|
|
785
|
+
op: adderTypes[res[0]],
|
|
774
786
|
a: ctx.lispTree,
|
|
775
787
|
b: lispify(constants, part.substring(res[0].length), expectTypes[expect].next)
|
|
776
788
|
});
|
|
777
789
|
});
|
|
790
|
+
const opTypes = {
|
|
791
|
+
'&': 77 /* LispType.BitAnd */,
|
|
792
|
+
'|': 78 /* LispType.BitOr */,
|
|
793
|
+
'^': 79 /* LispType.BitNegate */,
|
|
794
|
+
'<<': 80 /* LispType.BitShiftLeft */,
|
|
795
|
+
'>>': 81 /* LispType.BitShiftRight */,
|
|
796
|
+
'>>>': 82 /* LispType.BitUnsignedShiftRight */,
|
|
797
|
+
'<=': 54 /* LispType.SmallerEqualThan */,
|
|
798
|
+
'>=': 55 /* LispType.LargerEqualThan */,
|
|
799
|
+
'<': 56 /* LispType.SmallerThan */,
|
|
800
|
+
'>': 57 /* LispType.LargerThan */,
|
|
801
|
+
'!==': 31 /* LispType.StrictNotEqual */,
|
|
802
|
+
'!=': 53 /* LispType.NotEqual */,
|
|
803
|
+
'===': 32 /* LispType.StrictEqual */,
|
|
804
|
+
'==': 52 /* LispType.Equal */,
|
|
805
|
+
'+': 33 /* LispType.Plus */,
|
|
806
|
+
'-': 47 /* LispType.Minus */,
|
|
807
|
+
'/': 48 /* LispType.Divide */,
|
|
808
|
+
'**': 49 /* LispType.Power */,
|
|
809
|
+
'*': 50 /* LispType.Multiply */,
|
|
810
|
+
'%': 51 /* LispType.Modulus */,
|
|
811
|
+
};
|
|
778
812
|
setLispType(['opHigh', 'op', 'comparitor', 'bitwise'], (constants, type, part, res, expect, ctx) => {
|
|
779
813
|
const next = [
|
|
780
814
|
expectTypes.inlineIf.types.inlineIf,
|
|
@@ -792,8 +826,8 @@ setLispType(['opHigh', 'op', 'comparitor', 'bitwise'], (constants, type, part, r
|
|
|
792
826
|
next.push(expectTypes.splitter.types.boolOp);
|
|
793
827
|
}
|
|
794
828
|
let extract = restOfExp(constants, part.substring(res[0].length), next);
|
|
795
|
-
ctx.lispTree = lispify(constants, part.substring(extract.length + res[0].length), restOfExp.next,
|
|
796
|
-
op: res[0],
|
|
829
|
+
ctx.lispTree = lispify(constants, part.substring(extract.length + res[0].length), restOfExp.next, createLisp({
|
|
830
|
+
op: opTypes[res[0]],
|
|
797
831
|
a: ctx.lispTree,
|
|
798
832
|
b: lispify(constants, extract, expectTypes[expect].next),
|
|
799
833
|
}));
|
|
@@ -818,14 +852,17 @@ setLispType(['inlineIf'], (constants, type, part, res, expect, ctx) => {
|
|
|
818
852
|
}
|
|
819
853
|
}
|
|
820
854
|
extract.start = part.start + 1;
|
|
821
|
-
ctx.lispTree =
|
|
822
|
-
op:
|
|
855
|
+
ctx.lispTree = createLisp({
|
|
856
|
+
op: 15 /* LispType.InlineIf */,
|
|
823
857
|
a: ctx.lispTree,
|
|
824
|
-
b:
|
|
858
|
+
b: createLisp({
|
|
859
|
+
op: 16 /* LispType.InlineIfCase */,
|
|
860
|
+
a: lispifyExpr(constants, extract),
|
|
861
|
+
b: lispifyExpr(constants, part.substring(res[0].length + extract.length + 1))
|
|
862
|
+
})
|
|
825
863
|
});
|
|
826
864
|
});
|
|
827
865
|
function extractIfElse(constants, part) {
|
|
828
|
-
var _a;
|
|
829
866
|
let count = 0;
|
|
830
867
|
let found = part.substring(0, 0);
|
|
831
868
|
let foundElse = emptyString;
|
|
@@ -861,7 +898,7 @@ function extractIfElse(constants, part) {
|
|
|
861
898
|
break;
|
|
862
899
|
}
|
|
863
900
|
if (!count) {
|
|
864
|
-
let ie = extractIfElse(constants, part.substring(found.end - part.start + (
|
|
901
|
+
let ie = extractIfElse(constants, part.substring(found.end - part.start + (/^;?\s*else(?![\w\$])/.exec(f)?.[0].length)));
|
|
865
902
|
foundElse = ie.all;
|
|
866
903
|
break;
|
|
867
904
|
}
|
|
@@ -884,10 +921,14 @@ setLispType(['if'], (constants, type, part, res, expect, ctx) => {
|
|
|
884
921
|
trueBlock = trueBlock.slice(1, -1);
|
|
885
922
|
if (elseBlock.char(0) === "{")
|
|
886
923
|
elseBlock = elseBlock.slice(1, -1);
|
|
887
|
-
ctx.lispTree =
|
|
888
|
-
op:
|
|
924
|
+
ctx.lispTree = createLisp({
|
|
925
|
+
op: 13 /* LispType.If */,
|
|
889
926
|
a: lispifyExpr(constants, condition),
|
|
890
|
-
b:
|
|
927
|
+
b: createLisp({
|
|
928
|
+
op: 14 /* LispType.IfCase */,
|
|
929
|
+
a: lispifyBlock(trueBlock, constants),
|
|
930
|
+
b: lispifyBlock(elseBlock, constants)
|
|
931
|
+
})
|
|
891
932
|
});
|
|
892
933
|
});
|
|
893
934
|
setLispType(['switch'], (constants, type, part, res, expect, ctx) => {
|
|
@@ -934,16 +975,16 @@ setLispType(['switch'], (constants, type, part, res, expect, ctx) => {
|
|
|
934
975
|
}
|
|
935
976
|
}
|
|
936
977
|
statement = statement.substring(i);
|
|
937
|
-
cases.push(
|
|
938
|
-
op:
|
|
978
|
+
cases.push(createLisp({
|
|
979
|
+
op: 41 /* LispType.SwitchCase */,
|
|
939
980
|
a: caseFound[1] === "default" ? undefined : lispifyExpr(constants, cond),
|
|
940
|
-
b:
|
|
981
|
+
b: exprs
|
|
941
982
|
}));
|
|
942
983
|
}
|
|
943
|
-
ctx.lispTree =
|
|
944
|
-
op:
|
|
984
|
+
ctx.lispTree = createLisp({
|
|
985
|
+
op: 40 /* LispType.Switch */,
|
|
945
986
|
a: lispifyExpr(constants, test),
|
|
946
|
-
b:
|
|
987
|
+
b: cases
|
|
947
988
|
});
|
|
948
989
|
});
|
|
949
990
|
setLispType(['dot', 'prop'], (constants, type, part, res, expect, ctx) => {
|
|
@@ -963,51 +1004,52 @@ setLispType(['dot', 'prop'], (constants, type, part, res, expect, ctx) => {
|
|
|
963
1004
|
throw new SyntaxError('Hanging dot');
|
|
964
1005
|
}
|
|
965
1006
|
}
|
|
966
|
-
ctx.lispTree = lispify(constants, part.substring(index), expectTypes[expect].next,
|
|
967
|
-
op: op,
|
|
1007
|
+
ctx.lispTree = lispify(constants, part.substring(index), expectTypes[expect].next, createLisp({
|
|
1008
|
+
op: typesCreate[op],
|
|
968
1009
|
a: ctx.lispTree,
|
|
969
1010
|
b: prop
|
|
970
1011
|
}));
|
|
971
1012
|
});
|
|
972
1013
|
setLispType(['spreadArray', 'spreadObject'], (constants, type, part, res, expect, ctx) => {
|
|
973
|
-
ctx.lispTree =
|
|
974
|
-
op: type
|
|
1014
|
+
ctx.lispTree = createLisp({
|
|
1015
|
+
op: type === 'spreadArray' ? 18 /* LispType.SpreadArray */ : 17 /* LispType.SpreadObject */,
|
|
1016
|
+
a: 0 /* LispType.None */,
|
|
975
1017
|
b: lispify(constants, part.substring(res[0].length), expectTypes[expect].next)
|
|
976
1018
|
});
|
|
977
1019
|
});
|
|
978
1020
|
setLispType(['return', 'throw'], (constants, type, part, res, expect, ctx) => {
|
|
979
|
-
ctx.lispTree =
|
|
980
|
-
op: type
|
|
1021
|
+
ctx.lispTree = createLisp({
|
|
1022
|
+
op: type === 'return' ? 8 /* LispType.Return */ : 46 /* LispType.Throw */,
|
|
1023
|
+
a: 0 /* LispType.None */,
|
|
981
1024
|
b: lispifyExpr(constants, part.substring(res[0].length))
|
|
982
1025
|
});
|
|
983
1026
|
});
|
|
984
|
-
const primitives = {
|
|
985
|
-
"true": true,
|
|
986
|
-
"false": false,
|
|
987
|
-
"null": null,
|
|
988
|
-
Infinity,
|
|
989
|
-
NaN,
|
|
990
|
-
"und": undefined
|
|
991
|
-
};
|
|
992
1027
|
setLispType(['number', 'boolean', 'null', 'und', 'NaN', 'Infinity'], (constants, type, part, res, expect, ctx) => {
|
|
993
|
-
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next,
|
|
1028
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next, createLisp({
|
|
1029
|
+
op: type === "number" ? res[10] ? 83 /* LispType.BigInt */ : 7 /* LispType.Number */ : 35 /* LispType.GlobalSymbol */,
|
|
1030
|
+
a: 0 /* LispType.None */,
|
|
1031
|
+
b: res[10] ? res[1] : res[0]
|
|
1032
|
+
}));
|
|
994
1033
|
});
|
|
995
1034
|
setLispType(['string', 'literal', 'regex'], (constants, type, part, res, expect, ctx) => {
|
|
996
|
-
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next,
|
|
997
|
-
op: type
|
|
998
|
-
|
|
1035
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next, createLisp({
|
|
1036
|
+
op: type === 'string' ? 2 /* LispType.StringIndex */ : type === 'literal' ? 84 /* LispType.LiteralIndex */ : 85 /* LispType.RegexIndex */,
|
|
1037
|
+
a: 0 /* LispType.None */,
|
|
1038
|
+
b: res[1],
|
|
999
1039
|
}));
|
|
1000
1040
|
});
|
|
1001
1041
|
setLispType(['initialize'], (constants, type, part, res, expect, ctx) => {
|
|
1042
|
+
const lt = res[1] === 'var' ? 34 /* LispType.Var */ : res[1] === 'let' ? 3 /* LispType.Let */ : 4 /* LispType.Const */;
|
|
1002
1043
|
if (!res[3]) {
|
|
1003
|
-
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next,
|
|
1004
|
-
op:
|
|
1005
|
-
a: res[2]
|
|
1044
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next, createLisp({
|
|
1045
|
+
op: lt,
|
|
1046
|
+
a: res[2],
|
|
1047
|
+
b: 0 /* LispType.None */
|
|
1006
1048
|
}));
|
|
1007
1049
|
}
|
|
1008
1050
|
else {
|
|
1009
|
-
ctx.lispTree =
|
|
1010
|
-
op:
|
|
1051
|
+
ctx.lispTree = createLisp({
|
|
1052
|
+
op: lt,
|
|
1011
1053
|
a: res[2],
|
|
1012
1054
|
b: lispify(constants, part.substring(res[0].length), expectTypes[expect].next)
|
|
1013
1055
|
});
|
|
@@ -1017,7 +1059,7 @@ setLispType(['function', 'inlineFunction', 'arrowFunction', 'arrowFunctionSingle
|
|
|
1017
1059
|
const isArrow = type !== 'function' && type !== 'inlineFunction';
|
|
1018
1060
|
const isReturn = isArrow && !res[res.length - 1];
|
|
1019
1061
|
const argPos = isArrow ? 2 : 3;
|
|
1020
|
-
const isAsync =
|
|
1062
|
+
const isAsync = res[1] ? 88 /* LispType.True */ : 0 /* LispType.None */;
|
|
1021
1063
|
const args = res[argPos] ? res[argPos].replace(/\s+/g, "").split(/,/g) : [];
|
|
1022
1064
|
if (!isArrow) {
|
|
1023
1065
|
args.unshift((res[2] || "").trimStart());
|
|
@@ -1031,23 +1073,23 @@ setLispType(['function', 'inlineFunction', 'arrowFunction', 'arrowFunctionSingle
|
|
|
1031
1073
|
});
|
|
1032
1074
|
args.unshift(isAsync);
|
|
1033
1075
|
const f = restOfExp(constants, part.substring(res[0].length), !isReturn ? [/^}/] : [/^[,\)\}\]]/, semiColon]);
|
|
1034
|
-
const func = (isReturn ? 'return ' + f : f);
|
|
1035
|
-
ctx.lispTree = lispify(constants, part.substring(res[0].length + func.length + 1), expectTypes[expect].next,
|
|
1036
|
-
op: isArrow ? '
|
|
1037
|
-
a:
|
|
1076
|
+
const func = (isReturn ? 'return ' + f : f.toString());
|
|
1077
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length + func.length + 1), expectTypes[expect].next, createLisp({
|
|
1078
|
+
op: isArrow ? 11 /* LispType.ArrowFunction */ : type === 'function' ? 37 /* LispType.Function */ : 10 /* LispType.InlineFunction */,
|
|
1079
|
+
a: args,
|
|
1038
1080
|
b: constants.eager ? lispifyFunction(new CodeString(func), constants) : func
|
|
1039
1081
|
}));
|
|
1040
1082
|
});
|
|
1041
1083
|
const iteratorRegex = /^((let|var|const)\s+)?\s*([a-zA-Z\$_][a-zA-Z\d\$_]*)\s+(in|of)(?![\w\$])/;
|
|
1042
1084
|
setLispType(['for', 'do', 'while'], (constants, type, part, res, expect, ctx) => {
|
|
1043
1085
|
let i = 0;
|
|
1044
|
-
let startStep =
|
|
1045
|
-
let startInternal =
|
|
1086
|
+
let startStep = 88 /* LispType.True */;
|
|
1087
|
+
let startInternal = [];
|
|
1046
1088
|
let getIterator;
|
|
1047
|
-
let beforeStep =
|
|
1048
|
-
let checkFirst =
|
|
1089
|
+
let beforeStep = 0 /* LispType.None */;
|
|
1090
|
+
let checkFirst = 88 /* LispType.True */;
|
|
1049
1091
|
let condition;
|
|
1050
|
-
let step =
|
|
1092
|
+
let step = 88 /* LispType.True */;
|
|
1051
1093
|
let body;
|
|
1052
1094
|
switch (type) {
|
|
1053
1095
|
case 'while':
|
|
@@ -1073,20 +1115,20 @@ setLispType(['for', 'do', 'while'], (constants, type, part, res, expect, ctx) =>
|
|
|
1073
1115
|
if (args.length === 1 && (iterator = iteratorRegex.exec(args[0].toString()))) {
|
|
1074
1116
|
if (iterator[4] === 'of') {
|
|
1075
1117
|
getIterator = lispifyReturnExpr(constants, args[0].substring(iterator[0].length)),
|
|
1076
|
-
startInternal =
|
|
1118
|
+
startInternal = [
|
|
1077
1119
|
ofStart2,
|
|
1078
1120
|
ofStart3
|
|
1079
|
-
]
|
|
1121
|
+
];
|
|
1080
1122
|
condition = ofCondition;
|
|
1081
1123
|
step = ofStep;
|
|
1082
1124
|
beforeStep = lispify(constants, new CodeString((iterator[1] || 'let ') + iterator[3] + ' = $$next.value'), ['initialize']);
|
|
1083
1125
|
}
|
|
1084
1126
|
else {
|
|
1085
1127
|
getIterator = lispifyReturnExpr(constants, args[0].substring(iterator[0].length)),
|
|
1086
|
-
startInternal =
|
|
1128
|
+
startInternal = [
|
|
1087
1129
|
inStart2,
|
|
1088
1130
|
inStart3
|
|
1089
|
-
]
|
|
1131
|
+
];
|
|
1090
1132
|
step = inStep;
|
|
1091
1133
|
condition = inCondition;
|
|
1092
1134
|
beforeStep = lispify(constants, new CodeString((iterator[1] || 'let ') + iterator[3] + ' = $$keys[$$keyIndex]'), ['initialize']);
|
|
@@ -1105,26 +1147,31 @@ setLispType(['for', 'do', 'while'], (constants, type, part, res, expect, ctx) =>
|
|
|
1105
1147
|
body = body.slice(1, -1);
|
|
1106
1148
|
break;
|
|
1107
1149
|
case 'do':
|
|
1108
|
-
checkFirst =
|
|
1150
|
+
checkFirst = 0 /* LispType.None */;
|
|
1109
1151
|
const isBlock = !!res[3];
|
|
1110
1152
|
body = restOfExp(constants, part.substring(res[0].length), isBlock ? [/^\}/] : [semiColon]);
|
|
1111
1153
|
condition = lispifyReturnExpr(constants, restOfExp(constants, part.substring(part.toString().indexOf("(", res[0].length + body.length) + 1), [], "("));
|
|
1112
1154
|
break;
|
|
1113
1155
|
}
|
|
1114
|
-
const a =
|
|
1115
|
-
ctx.lispTree =
|
|
1116
|
-
op:
|
|
1156
|
+
const a = [checkFirst, startInternal, getIterator, startStep, step, condition, beforeStep];
|
|
1157
|
+
ctx.lispTree = createLisp({
|
|
1158
|
+
op: 38 /* LispType.Loop */,
|
|
1117
1159
|
a,
|
|
1118
1160
|
b: lispifyBlock(body, constants)
|
|
1119
1161
|
});
|
|
1120
1162
|
});
|
|
1121
1163
|
setLispType(['block'], (constants, type, part, res, expect, ctx) => {
|
|
1122
|
-
ctx.lispTree =
|
|
1164
|
+
ctx.lispTree = createLisp({
|
|
1165
|
+
op: 42 /* LispType.Block */,
|
|
1166
|
+
a: lispifyBlock(restOfExp(constants, part.substring(1), [], "{"), constants),
|
|
1167
|
+
b: 0 /* LispType.None */
|
|
1168
|
+
});
|
|
1123
1169
|
});
|
|
1124
1170
|
setLispType(['loopAction'], (constants, type, part, res, expect, ctx) => {
|
|
1125
|
-
ctx.lispTree =
|
|
1126
|
-
op:
|
|
1171
|
+
ctx.lispTree = createLisp({
|
|
1172
|
+
op: 86 /* LispType.LoopAction */,
|
|
1127
1173
|
a: res[1],
|
|
1174
|
+
b: 0 /* LispType.None */
|
|
1128
1175
|
});
|
|
1129
1176
|
});
|
|
1130
1177
|
const catchReg = /^\s*(catch\s*(\(\s*([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*\))?|finally)\s*\{/;
|
|
@@ -1132,7 +1179,7 @@ setLispType(['try'], (constants, type, part, res, expect, ctx) => {
|
|
|
1132
1179
|
const body = restOfExp(constants, part.substring(res[0].length), [], "{");
|
|
1133
1180
|
let catchRes = catchReg.exec(part.substring(res[0].length + body.length + 1).toString());
|
|
1134
1181
|
let finallyBody;
|
|
1135
|
-
let exception;
|
|
1182
|
+
let exception = "";
|
|
1136
1183
|
let catchBody;
|
|
1137
1184
|
let offset = 0;
|
|
1138
1185
|
if (catchRes[1].startsWith('catch')) {
|
|
@@ -1147,22 +1194,23 @@ setLispType(['try'], (constants, type, part, res, expect, ctx) => {
|
|
|
1147
1194
|
else {
|
|
1148
1195
|
finallyBody = restOfExp(constants, part.substring(res[0].length + body.length + 1 + catchRes[0].length), [], "{");
|
|
1149
1196
|
}
|
|
1150
|
-
const b =
|
|
1197
|
+
const b = [
|
|
1151
1198
|
exception,
|
|
1152
1199
|
lispifyBlock(insertSemicolons(constants, catchBody || emptyString), constants),
|
|
1153
1200
|
lispifyBlock(insertSemicolons(constants, finallyBody || emptyString), constants),
|
|
1154
|
-
]
|
|
1155
|
-
ctx.lispTree =
|
|
1156
|
-
op:
|
|
1201
|
+
];
|
|
1202
|
+
ctx.lispTree = createLisp({
|
|
1203
|
+
op: 39 /* LispType.Try */,
|
|
1157
1204
|
a: lispifyBlock(insertSemicolons(constants, body), constants),
|
|
1158
1205
|
b
|
|
1159
1206
|
});
|
|
1160
1207
|
});
|
|
1161
1208
|
setLispType(['void', 'await'], (constants, type, part, res, expect, ctx) => {
|
|
1162
1209
|
const extract = restOfExp(constants, part.substring(res[0].length), [/^([^\s\.\?\w\$]|\?[^\.])/]);
|
|
1163
|
-
ctx.lispTree = lispify(constants, part.substring(res[0].length + extract.length), expectTypes[expect].next,
|
|
1164
|
-
op: type
|
|
1210
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length + extract.length), expectTypes[expect].next, createLisp({
|
|
1211
|
+
op: type === 'void' ? 87 /* LispType.Void */ : 44 /* LispType.Await */,
|
|
1165
1212
|
a: lispify(constants, extract),
|
|
1213
|
+
b: 0 /* LispType.None */
|
|
1166
1214
|
}));
|
|
1167
1215
|
});
|
|
1168
1216
|
setLispType(['new'], (constants, type, part, res, expect, ctx) => {
|
|
@@ -1180,10 +1228,10 @@ setLispType(['new'], (constants, type, part, res, expect, ctx) => {
|
|
|
1180
1228
|
args.push(found.trim());
|
|
1181
1229
|
}
|
|
1182
1230
|
}
|
|
1183
|
-
ctx.lispTree = lispify(constants, part.substring(i), expectTypes.expEdge.next,
|
|
1184
|
-
op:
|
|
1231
|
+
ctx.lispTree = lispify(constants, part.substring(i), expectTypes.expEdge.next, createLisp({
|
|
1232
|
+
op: 45 /* LispType.New */,
|
|
1185
1233
|
a: lispify(constants, obj, expectTypes.initialize.next),
|
|
1186
|
-
b:
|
|
1234
|
+
b: args.map((arg) => lispify(constants, arg, expectTypes.initialize.next)),
|
|
1187
1235
|
}));
|
|
1188
1236
|
});
|
|
1189
1237
|
const ofStart2 = lispify(undefined, new CodeString('let $$iterator = $$obj[Symbol.iterator]()'), ['initialize']);
|
|
@@ -1196,6 +1244,7 @@ const inStep = lispify(undefined, new CodeString('$$keyIndex++'));
|
|
|
1196
1244
|
const inCondition = lispify(undefined, new CodeString('return $$keyIndex < $$keys.length'), ['initialize']);
|
|
1197
1245
|
var lastType;
|
|
1198
1246
|
function lispify(constants, part, expected, lispTree, topLevel = false) {
|
|
1247
|
+
lispTree = lispTree || [0 /* LispType.None */, 0 /* LispType.None */, 0 /* LispType.None */];
|
|
1199
1248
|
expected = expected || expectTypes.initialize.next;
|
|
1200
1249
|
if (part === undefined)
|
|
1201
1250
|
return lispTree;
|
|
@@ -1267,22 +1316,26 @@ function lispifyExpr(constants, str, expected) {
|
|
|
1267
1316
|
if (expected.includes('initialize')) {
|
|
1268
1317
|
let defined = expectTypes.initialize.types.initialize.exec(subExpressions[0].toString());
|
|
1269
1318
|
if (defined) {
|
|
1270
|
-
return
|
|
1319
|
+
return createLisp({
|
|
1320
|
+
op: 42 /* LispType.Block */,
|
|
1321
|
+
a: subExpressions.map((str, i) => lispify(constants, i ? new CodeString(defined[1] + ' ' + str) : str, ['initialize'], undefined, true)),
|
|
1322
|
+
b: 0 /* LispType.None */
|
|
1323
|
+
});
|
|
1271
1324
|
}
|
|
1272
1325
|
else if (expectTypes.initialize.types.return.exec(subExpressions[0].toString())) {
|
|
1273
1326
|
return lispify(constants, str, expected, undefined, true);
|
|
1274
1327
|
}
|
|
1275
1328
|
}
|
|
1276
|
-
const exprs =
|
|
1277
|
-
return
|
|
1329
|
+
const exprs = subExpressions.map((str, i) => lispify(constants, str, expected, undefined, true));
|
|
1330
|
+
return createLisp({ op: 43 /* LispType.Expression */, a: exprs, b: 0 /* LispType.None */ });
|
|
1278
1331
|
}
|
|
1279
1332
|
function lispifyReturnExpr(constants, str) {
|
|
1280
|
-
return
|
|
1333
|
+
return createLisp({ op: 8 /* LispType.Return */, a: 0 /* LispType.None */, b: lispifyExpr(constants, str) });
|
|
1281
1334
|
}
|
|
1282
1335
|
function lispifyBlock(str, constants, expression = false) {
|
|
1283
1336
|
str = insertSemicolons(constants, str);
|
|
1284
1337
|
if (!str.trim().length)
|
|
1285
|
-
return
|
|
1338
|
+
return [];
|
|
1286
1339
|
let parts = [];
|
|
1287
1340
|
let part;
|
|
1288
1341
|
let pos = 0;
|
|
@@ -1311,20 +1364,37 @@ function lispifyBlock(str, constants, expression = false) {
|
|
|
1311
1364
|
if (skipped) {
|
|
1312
1365
|
parts.push(str.substring(start, pos - (isInserted ? 0 : 1)));
|
|
1313
1366
|
}
|
|
1314
|
-
return
|
|
1367
|
+
return parts.map((str) => str.trimStart()).filter((str) => str.length).map((str, j) => {
|
|
1315
1368
|
return lispifyExpr(constants, str.trimStart(), startingExecpted);
|
|
1316
|
-
})
|
|
1369
|
+
});
|
|
1317
1370
|
}
|
|
1318
1371
|
function lispifyFunction(str, constants, expression = false) {
|
|
1319
1372
|
if (!str.trim().length)
|
|
1320
|
-
return
|
|
1373
|
+
return [];
|
|
1321
1374
|
const tree = lispifyBlock(str, constants, expression);
|
|
1322
|
-
let hoisted =
|
|
1375
|
+
let hoisted = [];
|
|
1323
1376
|
hoist(tree, hoisted);
|
|
1324
|
-
return
|
|
1377
|
+
return hoisted.concat(tree);
|
|
1378
|
+
}
|
|
1379
|
+
function isLisp(item) {
|
|
1380
|
+
return Array.isArray(item) && typeof item[0] === 'number' && item[0] !== 0 /* LispType.None */ && item[0] !== 88 /* LispType.True */;
|
|
1325
1381
|
}
|
|
1326
1382
|
function hoist(item, res) {
|
|
1327
|
-
if (
|
|
1383
|
+
if (isLisp(item)) {
|
|
1384
|
+
const [op, a, b] = item;
|
|
1385
|
+
if (op === 39 /* LispType.Try */ || op === 13 /* LispType.If */ || op === 38 /* LispType.Loop */ || op === 40 /* LispType.Switch */) {
|
|
1386
|
+
hoist(a, res);
|
|
1387
|
+
hoist(b, res);
|
|
1388
|
+
}
|
|
1389
|
+
else if (op === 34 /* LispType.Var */) {
|
|
1390
|
+
res.push(createLisp({ op: 34 /* LispType.Var */, a: a, b: 0 /* LispType.None */ }));
|
|
1391
|
+
}
|
|
1392
|
+
else if (op === 37 /* LispType.Function */ && a[1]) {
|
|
1393
|
+
res.push(item);
|
|
1394
|
+
return true;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
else if (Array.isArray(item)) {
|
|
1328
1398
|
const rep = [];
|
|
1329
1399
|
for (let it of item) {
|
|
1330
1400
|
if (!hoist(it, res)) {
|
|
@@ -1336,19 +1406,6 @@ function hoist(item, res) {
|
|
|
1336
1406
|
item.push(...rep);
|
|
1337
1407
|
}
|
|
1338
1408
|
}
|
|
1339
|
-
else if (item instanceof Lisp) {
|
|
1340
|
-
if (item.op === "try" || item.op === "if" || item.op === "loop" || item.op === "switch") {
|
|
1341
|
-
hoist(item.a, res);
|
|
1342
|
-
hoist(item.b, res);
|
|
1343
|
-
}
|
|
1344
|
-
else if (item.op === "var") {
|
|
1345
|
-
res.push(new Lisp({ op: 'var', a: item.a }));
|
|
1346
|
-
}
|
|
1347
|
-
else if (item.op === "function" && item.a[1]) {
|
|
1348
|
-
res.push(item);
|
|
1349
|
-
return true;
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
1409
|
return false;
|
|
1353
1410
|
}
|
|
1354
1411
|
const closingsNoInsertion = /^(\})\s*(catch|finally|else|while|instanceof)(?![\w\$])/;
|
|
@@ -1444,7 +1501,7 @@ function extractConstants(constants, str, currentEnclosure = "") {
|
|
|
1444
1501
|
let regexFound;
|
|
1445
1502
|
let comment = "";
|
|
1446
1503
|
let commentStart = -1;
|
|
1447
|
-
let currJs =
|
|
1504
|
+
let currJs = [];
|
|
1448
1505
|
let char = "";
|
|
1449
1506
|
const strRes = [];
|
|
1450
1507
|
const enclosures = [];
|
|
@@ -1477,11 +1534,13 @@ function extractConstants(constants, str, currentEnclosure = "") {
|
|
|
1477
1534
|
}
|
|
1478
1535
|
else if (quote === char) {
|
|
1479
1536
|
if (quote === '`') {
|
|
1480
|
-
|
|
1481
|
-
op:
|
|
1537
|
+
const li = createLisp({
|
|
1538
|
+
op: 36 /* LispType.Literal */,
|
|
1482
1539
|
a: unraw(extract.join("")),
|
|
1483
|
-
b:
|
|
1540
|
+
b: [],
|
|
1484
1541
|
});
|
|
1542
|
+
li.tempJsStrings = currJs;
|
|
1543
|
+
constants.literals.push(li);
|
|
1485
1544
|
strRes.push(`\``, constants.literals.length - 1, `\``);
|
|
1486
1545
|
}
|
|
1487
1546
|
else {
|
|
@@ -1497,7 +1556,7 @@ function extractConstants(constants, str, currentEnclosure = "") {
|
|
|
1497
1556
|
}
|
|
1498
1557
|
else {
|
|
1499
1558
|
if ((char === "'" || char === '"' || char === '`')) {
|
|
1500
|
-
currJs =
|
|
1559
|
+
currJs = [];
|
|
1501
1560
|
quote = char;
|
|
1502
1561
|
}
|
|
1503
1562
|
else if (closings[currentEnclosure] === char && !enclosures.length) {
|
|
@@ -1548,7 +1607,8 @@ function parse(code, eager = false, expression = false) {
|
|
|
1548
1607
|
const constants = { strings: [], literals: [], regexes: [], eager };
|
|
1549
1608
|
str = extractConstants(constants, str).str;
|
|
1550
1609
|
for (let l of constants.literals) {
|
|
1551
|
-
l
|
|
1610
|
+
l[2] = l.tempJsStrings.map((js) => lispifyExpr(constants, new CodeString(js)));
|
|
1611
|
+
delete l.tempJsStrings;
|
|
1552
1612
|
}
|
|
1553
1613
|
return { tree: lispifyFunction(new CodeString(str), constants, expression), constants };
|
|
1554
1614
|
}
|
|
@@ -1747,11 +1807,10 @@ function createFunction(argNames, parsed, ticks, context, scope, name) {
|
|
|
1747
1807
|
return func;
|
|
1748
1808
|
}
|
|
1749
1809
|
function createFunctionAsync(argNames, parsed, ticks, context, scope, name) {
|
|
1750
|
-
var _a;
|
|
1751
1810
|
if (context.ctx.options.forbidFunctionCreation) {
|
|
1752
1811
|
throw new SandboxError("Function creation is forbidden");
|
|
1753
1812
|
}
|
|
1754
|
-
if (!
|
|
1813
|
+
if (!context.ctx.prototypeWhitelist?.has(Promise.prototype)) {
|
|
1755
1814
|
throw new SandboxError("Async/await not permitted");
|
|
1756
1815
|
}
|
|
1757
1816
|
let func;
|
|
@@ -1794,7 +1853,6 @@ function sandboxedSetInterval(func) {
|
|
|
1794
1853
|
};
|
|
1795
1854
|
}
|
|
1796
1855
|
function assignCheck(obj, context, op = 'assign') {
|
|
1797
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1798
1856
|
if (obj.context === undefined) {
|
|
1799
1857
|
throw new ReferenceError(`Cannot ${op} value to undefined.`);
|
|
1800
1858
|
}
|
|
@@ -1812,21 +1870,21 @@ function assignCheck(obj, context, op = 'assign') {
|
|
|
1812
1870
|
}
|
|
1813
1871
|
if (op === "delete") {
|
|
1814
1872
|
if (obj.context.hasOwnProperty(obj.prop)) {
|
|
1815
|
-
|
|
1816
|
-
|
|
1873
|
+
context.changeSubscriptions.get(obj.context)?.forEach((cb) => cb({ type: "delete", prop: obj.prop }));
|
|
1874
|
+
context.changeSubscriptionsGlobal.get(obj.context)?.forEach((cb) => cb({ type: "delete", prop: obj.prop }));
|
|
1817
1875
|
}
|
|
1818
1876
|
}
|
|
1819
1877
|
else if (obj.context.hasOwnProperty(obj.prop)) {
|
|
1820
|
-
|
|
1878
|
+
context.setSubscriptions.get(obj.context)?.get(obj.prop)?.forEach((cb) => cb({
|
|
1821
1879
|
type: "replace"
|
|
1822
1880
|
}));
|
|
1823
|
-
|
|
1881
|
+
context.setSubscriptionsGlobal.get(obj.context)?.get(obj.prop)?.forEach((cb) => cb({
|
|
1824
1882
|
type: "replace"
|
|
1825
1883
|
}));
|
|
1826
1884
|
}
|
|
1827
1885
|
else {
|
|
1828
|
-
|
|
1829
|
-
|
|
1886
|
+
context.changeSubscriptions.get(obj.context)?.forEach((cb) => cb({ type: "create", prop: obj.prop }));
|
|
1887
|
+
context.changeSubscriptionsGlobal.get(obj.context)?.forEach((cb) => cb({ type: "create", prop: obj.prop }));
|
|
1830
1888
|
}
|
|
1831
1889
|
}
|
|
1832
1890
|
const arrayChange = new Set([
|
|
@@ -1839,542 +1897,507 @@ const arrayChange = new Set([
|
|
|
1839
1897
|
[].sort,
|
|
1840
1898
|
[].copyWithin
|
|
1841
1899
|
]);
|
|
1900
|
+
class KeyVal {
|
|
1901
|
+
constructor(key, val) {
|
|
1902
|
+
this.key = key;
|
|
1903
|
+
this.val = val;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
class SpreadObject {
|
|
1907
|
+
constructor(item) {
|
|
1908
|
+
this.item = item;
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
class SpreadArray {
|
|
1912
|
+
constructor(item) {
|
|
1913
|
+
this.item = item;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
class If {
|
|
1917
|
+
constructor(t, f) {
|
|
1918
|
+
this.t = t;
|
|
1919
|
+
this.f = f;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1842
1922
|
const literalRegex = /(\$\$)*(\$)?\${(\d+)}/g;
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
if (prop.context && prop.context[b] === globalThis) {
|
|
1862
|
-
done(undefined, context.ctx.globalScope.get('this'));
|
|
1923
|
+
const ops = new Map();
|
|
1924
|
+
function addOps(type, cb) {
|
|
1925
|
+
ops.set(type, cb);
|
|
1926
|
+
}
|
|
1927
|
+
addOps(1 /* LispType.Prop */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
1928
|
+
if (a === null) {
|
|
1929
|
+
throw new TypeError(`Cannot get property ${b} of null`);
|
|
1930
|
+
}
|
|
1931
|
+
const type = typeof a;
|
|
1932
|
+
if (type === 'undefined' && obj === undefined) {
|
|
1933
|
+
let prop = scope.get(b);
|
|
1934
|
+
if (prop.context === context.ctx.sandboxGlobal) {
|
|
1935
|
+
if (context.ctx.options.audit) {
|
|
1936
|
+
context.ctx.auditReport.globalsAccess.add(b);
|
|
1937
|
+
}
|
|
1938
|
+
const rep = context.ctx.globalsWhitelist.has(context.ctx.sandboxGlobal[b]) ? context.evals.get(context.ctx.sandboxGlobal[b]) : undefined;
|
|
1939
|
+
if (rep) {
|
|
1940
|
+
done(undefined, rep);
|
|
1863
1941
|
return;
|
|
1864
1942
|
}
|
|
1865
|
-
|
|
1943
|
+
}
|
|
1944
|
+
if (prop.context && prop.context[b] === globalThis) {
|
|
1945
|
+
done(undefined, context.ctx.globalScope.get('this'));
|
|
1866
1946
|
return;
|
|
1867
1947
|
}
|
|
1868
|
-
|
|
1869
|
-
|
|
1948
|
+
done(undefined, prop);
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1951
|
+
else if (a === undefined) {
|
|
1952
|
+
throw new SandboxError("Cannot get property '" + b + "' of undefined");
|
|
1953
|
+
}
|
|
1954
|
+
if (type !== 'object') {
|
|
1955
|
+
if (type === 'number') {
|
|
1956
|
+
a = new Number(a);
|
|
1870
1957
|
}
|
|
1871
|
-
if (type
|
|
1872
|
-
|
|
1873
|
-
a = new Number(a);
|
|
1874
|
-
}
|
|
1875
|
-
else if (type === 'string') {
|
|
1876
|
-
a = new String(a);
|
|
1877
|
-
}
|
|
1878
|
-
else if (type === 'boolean') {
|
|
1879
|
-
a = new Boolean(a);
|
|
1880
|
-
}
|
|
1958
|
+
else if (type === 'string') {
|
|
1959
|
+
a = new String(a);
|
|
1881
1960
|
}
|
|
1882
|
-
else if (
|
|
1883
|
-
|
|
1884
|
-
return;
|
|
1961
|
+
else if (type === 'boolean') {
|
|
1962
|
+
a = new Boolean(a);
|
|
1885
1963
|
}
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1964
|
+
}
|
|
1965
|
+
else if (typeof a.hasOwnProperty === 'undefined') {
|
|
1966
|
+
done(undefined, new Prop(undefined, b));
|
|
1967
|
+
return;
|
|
1968
|
+
}
|
|
1969
|
+
const isFunction = type === 'function';
|
|
1970
|
+
let prototypeAccess = isFunction || !(a.hasOwnProperty(b) || typeof b === 'number');
|
|
1971
|
+
if (context.ctx.options.audit && prototypeAccess) {
|
|
1972
|
+
if (typeof b === 'string') {
|
|
1973
|
+
let prot = Object.getPrototypeOf(a);
|
|
1974
|
+
do {
|
|
1975
|
+
if (prot.hasOwnProperty(b)) {
|
|
1976
|
+
if (!context.ctx.auditReport.prototypeAccess[prot.constructor.name]) {
|
|
1977
|
+
context.ctx.auditReport.prototypeAccess[prot.constructor.name] = new Set();
|
|
1897
1978
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1979
|
+
context.ctx.auditReport.prototypeAccess[prot.constructor.name].add(b);
|
|
1980
|
+
}
|
|
1981
|
+
} while (prot = Object.getPrototypeOf(prot));
|
|
1900
1982
|
}
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
if (whitelist && (!whitelist.size || whitelist.has(b))) ;
|
|
1911
|
-
else {
|
|
1912
|
-
throw new SandboxError(`Static method or property access not permitted: ${a.name}.${b}`);
|
|
1913
|
-
}
|
|
1983
|
+
}
|
|
1984
|
+
if (prototypeAccess) {
|
|
1985
|
+
if (isFunction) {
|
|
1986
|
+
if (!['name', 'length', 'constructor'].includes(b) && a.hasOwnProperty(b)) {
|
|
1987
|
+
const whitelist = context.ctx.prototypeWhitelist.get(a.prototype);
|
|
1988
|
+
const replace = context.ctx.options.prototypeReplacements.get(a);
|
|
1989
|
+
if (replace) {
|
|
1990
|
+
done(undefined, new Prop(replace(a, true), b));
|
|
1991
|
+
return;
|
|
1914
1992
|
}
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
while (prot = Object.getPrototypeOf(prot)) {
|
|
1919
|
-
if (prot.hasOwnProperty(b)) {
|
|
1920
|
-
const whitelist = context.ctx.prototypeWhitelist.get(prot);
|
|
1921
|
-
const replace = context.ctx.options.prototypeReplacements.get(prot.constuctor);
|
|
1922
|
-
if (replace) {
|
|
1923
|
-
done(undefined, new Prop(replace(a, false), b));
|
|
1924
|
-
return;
|
|
1925
|
-
}
|
|
1926
|
-
if (whitelist && (!whitelist.size || whitelist.has(b))) {
|
|
1927
|
-
break;
|
|
1928
|
-
}
|
|
1929
|
-
throw new SandboxError(`Method or property access not permitted: ${prot.constructor.name}.${b}`);
|
|
1930
|
-
}
|
|
1993
|
+
if (whitelist && (!whitelist.size || whitelist.has(b))) ;
|
|
1994
|
+
else {
|
|
1995
|
+
throw new SandboxError(`Static method or property access not permitted: ${a.name}.${b}`);
|
|
1931
1996
|
}
|
|
1932
1997
|
}
|
|
1933
1998
|
}
|
|
1934
|
-
if (
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
let g = obj.isGlobal || (isFunction && !sandboxedFunctions.has(a)) || context.ctx.globalsWhitelist.has(a);
|
|
1943
|
-
done(undefined, new Prop(a, b, false, g));
|
|
1944
|
-
},
|
|
1945
|
-
'call': (exec, done, ticks, a, b, obj, context, scope) => {
|
|
1946
|
-
if (context.ctx.options.forbidFunctionCalls)
|
|
1947
|
-
throw new SandboxError("Function invocations are not allowed");
|
|
1948
|
-
if (typeof a !== 'function') {
|
|
1949
|
-
throw new TypeError(`${obj.prop} is not a function`);
|
|
1950
|
-
}
|
|
1951
|
-
const args = b.map((item) => {
|
|
1952
|
-
if (item instanceof SpreadArray) {
|
|
1953
|
-
return [...item.item];
|
|
1954
|
-
}
|
|
1955
|
-
else {
|
|
1956
|
-
return [item];
|
|
1957
|
-
}
|
|
1958
|
-
}).flat();
|
|
1959
|
-
execMany(ticks, exec, toLispArray(args), (err, vals) => {
|
|
1960
|
-
var _a, _b;
|
|
1961
|
-
if (err) {
|
|
1962
|
-
done(err);
|
|
1963
|
-
return;
|
|
1964
|
-
}
|
|
1965
|
-
if (typeof obj === 'function') {
|
|
1966
|
-
done(undefined, obj(...vals));
|
|
1967
|
-
return;
|
|
1968
|
-
}
|
|
1969
|
-
if (obj.context[obj.prop] === JSON.stringify && context.getSubscriptions.size) {
|
|
1970
|
-
const cache = new Set();
|
|
1971
|
-
const recurse = (x) => {
|
|
1972
|
-
if (!x || !(typeof x === 'object') || cache.has(x))
|
|
1999
|
+
else if (b !== 'constructor') {
|
|
2000
|
+
let prot = a;
|
|
2001
|
+
while (prot = Object.getPrototypeOf(prot)) {
|
|
2002
|
+
if (prot.hasOwnProperty(b)) {
|
|
2003
|
+
const whitelist = context.ctx.prototypeWhitelist.get(prot);
|
|
2004
|
+
const replace = context.ctx.options.prototypeReplacements.get(prot.constuctor);
|
|
2005
|
+
if (replace) {
|
|
2006
|
+
done(undefined, new Prop(replace(a, false), b));
|
|
1973
2007
|
return;
|
|
1974
|
-
cache.add(x);
|
|
1975
|
-
for (let y in x) {
|
|
1976
|
-
context.getSubscriptions.forEach((cb) => cb(x, y));
|
|
1977
|
-
recurse(x[y]);
|
|
1978
2008
|
}
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
let change;
|
|
1984
|
-
let changed = false;
|
|
1985
|
-
if (obj.prop === "push") {
|
|
1986
|
-
change = {
|
|
1987
|
-
type: "push",
|
|
1988
|
-
added: vals
|
|
1989
|
-
};
|
|
1990
|
-
changed = !!vals.length;
|
|
1991
|
-
}
|
|
1992
|
-
else if (obj.prop === "pop") {
|
|
1993
|
-
change = {
|
|
1994
|
-
type: "pop",
|
|
1995
|
-
removed: obj.context.slice(-1)
|
|
1996
|
-
};
|
|
1997
|
-
changed = !!change.removed.length;
|
|
1998
|
-
}
|
|
1999
|
-
else if (obj.prop === "shift") {
|
|
2000
|
-
change = {
|
|
2001
|
-
type: "shift",
|
|
2002
|
-
removed: obj.context.slice(0, 1)
|
|
2003
|
-
};
|
|
2004
|
-
changed = !!change.removed.length;
|
|
2005
|
-
}
|
|
2006
|
-
else if (obj.prop === "unshift") {
|
|
2007
|
-
change = {
|
|
2008
|
-
type: "unshift",
|
|
2009
|
-
added: vals
|
|
2010
|
-
};
|
|
2011
|
-
changed = !!vals.length;
|
|
2012
|
-
}
|
|
2013
|
-
else if (obj.prop === "splice") {
|
|
2014
|
-
change = {
|
|
2015
|
-
type: "splice",
|
|
2016
|
-
startIndex: vals[0],
|
|
2017
|
-
deleteCount: vals[1] === undefined ? obj.context.length : vals[1],
|
|
2018
|
-
added: vals.slice(2),
|
|
2019
|
-
removed: obj.context.slice(vals[0], vals[1] === undefined ? undefined : vals[0] + vals[1])
|
|
2020
|
-
};
|
|
2021
|
-
changed = !!change.added.length || !!change.removed.length;
|
|
2022
|
-
}
|
|
2023
|
-
else if (obj.prop === "reverse" || obj.prop === "sort") {
|
|
2024
|
-
change = { type: obj.prop };
|
|
2025
|
-
changed = !!obj.context.length;
|
|
2026
|
-
}
|
|
2027
|
-
else if (obj.prop === "copyWithin") {
|
|
2028
|
-
let len = vals[2] === undefined ? obj.context.length - vals[1] : Math.min(obj.context.length, vals[2] - vals[1]);
|
|
2029
|
-
change = {
|
|
2030
|
-
type: "copyWithin",
|
|
2031
|
-
startIndex: vals[0],
|
|
2032
|
-
endIndex: vals[0] + len,
|
|
2033
|
-
added: obj.context.slice(vals[1], vals[1] + len),
|
|
2034
|
-
removed: obj.context.slice(vals[0], vals[0] + len)
|
|
2035
|
-
};
|
|
2036
|
-
changed = !!change.added.length || !!change.removed.length;
|
|
2037
|
-
}
|
|
2038
|
-
if (changed) {
|
|
2039
|
-
(_a = context.changeSubscriptions.get(obj.context)) === null || _a === void 0 ? void 0 : _a.forEach((cb) => cb(change));
|
|
2040
|
-
(_b = context.changeSubscriptionsGlobal.get(obj.context)) === null || _b === void 0 ? void 0 : _b.forEach((cb) => cb(change));
|
|
2009
|
+
if (whitelist && (!whitelist.size || whitelist.has(b))) {
|
|
2010
|
+
break;
|
|
2011
|
+
}
|
|
2012
|
+
throw new SandboxError(`Method or property access not permitted: ${prot.constructor.name}.${b}`);
|
|
2041
2013
|
}
|
|
2042
2014
|
}
|
|
2043
|
-
obj.get(context);
|
|
2044
|
-
done(undefined, obj.context[obj.prop](...vals));
|
|
2045
|
-
}, scope, context);
|
|
2046
|
-
},
|
|
2047
|
-
'createObject': (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2048
|
-
let res = {};
|
|
2049
|
-
for (let item of b) {
|
|
2050
|
-
if (item instanceof SpreadObject) {
|
|
2051
|
-
res = { ...res, ...item.item };
|
|
2052
|
-
}
|
|
2053
|
-
else {
|
|
2054
|
-
res[item.key] = item.val;
|
|
2055
|
-
}
|
|
2056
2015
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2016
|
+
}
|
|
2017
|
+
if (context.evals.has(a[b])) {
|
|
2018
|
+
done(undefined, context.evals.get(a[b]));
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
if (a[b] === globalThis) {
|
|
2022
|
+
done(undefined, context.ctx.globalScope.get('this'));
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
let g = obj.isGlobal || (isFunction && !sandboxedFunctions.has(a)) || context.ctx.globalsWhitelist.has(a);
|
|
2026
|
+
done(undefined, new Prop(a, b, false, g));
|
|
2027
|
+
});
|
|
2028
|
+
addOps(5 /* LispType.Call */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2029
|
+
if (context.ctx.options.forbidFunctionCalls)
|
|
2030
|
+
throw new SandboxError("Function invocations are not allowed");
|
|
2031
|
+
if (typeof a !== 'function') {
|
|
2032
|
+
throw new TypeError(`${typeof obj.prop === 'symbol' ? 'Symbol' : obj.prop} is not a function`);
|
|
2033
|
+
}
|
|
2034
|
+
const vals = b.map((item) => {
|
|
2035
|
+
if (item instanceof SpreadArray) {
|
|
2036
|
+
return [...item.item];
|
|
2077
2037
|
}
|
|
2078
2038
|
else {
|
|
2079
|
-
|
|
2080
|
-
}
|
|
2081
|
-
},
|
|
2082
|
-
'literal': (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2083
|
-
let name = context.constants.literals[b].a;
|
|
2084
|
-
let found = toLispArray([]);
|
|
2085
|
-
let f;
|
|
2086
|
-
let resnums = [];
|
|
2087
|
-
while (f = literalRegex.exec(name)) {
|
|
2088
|
-
if (!f[2]) {
|
|
2089
|
-
found.push(context.constants.literals[b].b[parseInt(f[3], 10)]);
|
|
2090
|
-
resnums.push(f[3]);
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
execMany(ticks, exec, found, (err, processed) => {
|
|
2094
|
-
const reses = {};
|
|
2095
|
-
if (err) {
|
|
2096
|
-
done(err);
|
|
2097
|
-
return;
|
|
2098
|
-
}
|
|
2099
|
-
for (let i in resnums) {
|
|
2100
|
-
const num = resnums[i];
|
|
2101
|
-
reses[num] = processed[i];
|
|
2102
|
-
}
|
|
2103
|
-
done(undefined, name.replace(/(\\\\)*(\\)?\${(\d+)}/g, (match, $$, $, num) => {
|
|
2104
|
-
if ($)
|
|
2105
|
-
return match;
|
|
2106
|
-
let res = reses[num];
|
|
2107
|
-
return ($$ ? $$ : '') + `${valueOrProp(res, context)}`;
|
|
2108
|
-
}));
|
|
2109
|
-
}, scope, context);
|
|
2110
|
-
},
|
|
2111
|
-
'spreadArray': (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2112
|
-
exec(ticks, b, scope, context, (err, res) => {
|
|
2113
|
-
if (err) {
|
|
2114
|
-
done(err);
|
|
2115
|
-
return;
|
|
2116
|
-
}
|
|
2117
|
-
done(undefined, new SpreadArray(res));
|
|
2118
|
-
});
|
|
2119
|
-
},
|
|
2120
|
-
'spreadObject': (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2121
|
-
exec(ticks, b, scope, context, (err, res) => {
|
|
2122
|
-
if (err) {
|
|
2123
|
-
done(err);
|
|
2124
|
-
return;
|
|
2125
|
-
}
|
|
2126
|
-
done(undefined, new SpreadObject(res));
|
|
2127
|
-
});
|
|
2128
|
-
},
|
|
2129
|
-
'!': (exec, done, ticks, a, b) => done(undefined, !b),
|
|
2130
|
-
'~': (exec, done, ticks, a, b) => done(undefined, ~b),
|
|
2131
|
-
'++$': (exec, done, ticks, a, b, obj, context) => {
|
|
2132
|
-
assignCheck(obj, context);
|
|
2133
|
-
done(undefined, ++obj.context[obj.prop]);
|
|
2134
|
-
},
|
|
2135
|
-
'$++': (exec, done, ticks, a, b, obj, context) => {
|
|
2136
|
-
assignCheck(obj, context);
|
|
2137
|
-
done(undefined, obj.context[obj.prop]++);
|
|
2138
|
-
},
|
|
2139
|
-
'--$': (exec, done, ticks, a, b, obj, context) => {
|
|
2140
|
-
assignCheck(obj, context);
|
|
2141
|
-
done(undefined, --obj.context[obj.prop]);
|
|
2142
|
-
},
|
|
2143
|
-
'$--': (exec, done, ticks, a, b, obj, context) => {
|
|
2144
|
-
assignCheck(obj, context);
|
|
2145
|
-
done(undefined, obj.context[obj.prop]--);
|
|
2146
|
-
},
|
|
2147
|
-
'=': (exec, done, ticks, a, b, obj, context) => {
|
|
2148
|
-
assignCheck(obj, context);
|
|
2149
|
-
done(undefined, obj.context[obj.prop] = b);
|
|
2150
|
-
},
|
|
2151
|
-
'+=': (exec, done, ticks, a, b, obj, context) => {
|
|
2152
|
-
assignCheck(obj, context);
|
|
2153
|
-
done(undefined, obj.context[obj.prop] += b);
|
|
2154
|
-
},
|
|
2155
|
-
'-=': (exec, done, ticks, a, b, obj, context) => {
|
|
2156
|
-
assignCheck(obj, context);
|
|
2157
|
-
done(undefined, obj.context[obj.prop] -= b);
|
|
2158
|
-
},
|
|
2159
|
-
'/=': (exec, done, ticks, a, b, obj, context) => {
|
|
2160
|
-
assignCheck(obj, context);
|
|
2161
|
-
done(undefined, obj.context[obj.prop] /= b);
|
|
2162
|
-
},
|
|
2163
|
-
'*=': (exec, done, ticks, a, b, obj, context) => {
|
|
2164
|
-
assignCheck(obj, context);
|
|
2165
|
-
done(undefined, obj.context[obj.prop] *= b);
|
|
2166
|
-
},
|
|
2167
|
-
'**=': (exec, done, ticks, a, b, obj, context) => {
|
|
2168
|
-
assignCheck(obj, context);
|
|
2169
|
-
done(undefined, obj.context[obj.prop] **= b);
|
|
2170
|
-
},
|
|
2171
|
-
'%=': (exec, done, ticks, a, b, obj, context) => {
|
|
2172
|
-
assignCheck(obj, context);
|
|
2173
|
-
done(undefined, obj.context[obj.prop] %= b);
|
|
2174
|
-
},
|
|
2175
|
-
'^=': (exec, done, ticks, a, b, obj, context) => {
|
|
2176
|
-
assignCheck(obj, context);
|
|
2177
|
-
done(undefined, obj.context[obj.prop] ^= b);
|
|
2178
|
-
},
|
|
2179
|
-
'&=': (exec, done, ticks, a, b, obj, context) => {
|
|
2180
|
-
assignCheck(obj, context);
|
|
2181
|
-
done(undefined, obj.context[obj.prop] &= b);
|
|
2182
|
-
},
|
|
2183
|
-
'|=': (exec, done, ticks, a, b, obj, context) => {
|
|
2184
|
-
assignCheck(obj, context);
|
|
2185
|
-
done(undefined, obj.context[obj.prop] |= b);
|
|
2186
|
-
},
|
|
2187
|
-
'<<=': (exec, done, ticks, a, b, obj, context) => {
|
|
2188
|
-
assignCheck(obj, context);
|
|
2189
|
-
done(undefined, obj.context[obj.prop] <<= b);
|
|
2190
|
-
},
|
|
2191
|
-
'>>=': (exec, done, ticks, a, b, obj, context) => {
|
|
2192
|
-
assignCheck(obj, context);
|
|
2193
|
-
done(undefined, obj.context[obj.prop] >>= b);
|
|
2194
|
-
},
|
|
2195
|
-
'>>>=': (exec, done, ticks, a, b, obj, context) => {
|
|
2196
|
-
assignCheck(obj, context);
|
|
2197
|
-
done(undefined, obj.context[obj.prop] >>= b);
|
|
2198
|
-
},
|
|
2199
|
-
'?': (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2200
|
-
if (!(b instanceof If)) {
|
|
2201
|
-
throw new SyntaxError('Invalid inline if');
|
|
2202
|
-
}
|
|
2203
|
-
exec(ticks, a, scope, context, (err, res) => {
|
|
2204
|
-
if (err) {
|
|
2205
|
-
done(err);
|
|
2206
|
-
}
|
|
2207
|
-
else {
|
|
2208
|
-
exec(ticks, valueOrProp(res, context) ? b.t : b.f, scope, context, done);
|
|
2209
|
-
}
|
|
2210
|
-
});
|
|
2211
|
-
},
|
|
2212
|
-
'>': (exec, done, ticks, a, b) => done(undefined, a > b),
|
|
2213
|
-
'<': (exec, done, ticks, a, b) => done(undefined, a < b),
|
|
2214
|
-
'>=': (exec, done, ticks, a, b) => done(undefined, a >= b),
|
|
2215
|
-
'<=': (exec, done, ticks, a, b) => done(undefined, a <= b),
|
|
2216
|
-
'==': (exec, done, ticks, a, b) => done(undefined, a == b),
|
|
2217
|
-
'===': (exec, done, ticks, a, b) => done(undefined, a === b),
|
|
2218
|
-
'!=': (exec, done, ticks, a, b) => done(undefined, a != b),
|
|
2219
|
-
'!==': (exec, done, ticks, a, b) => done(undefined, a !== b),
|
|
2220
|
-
'&&': (exec, done, ticks, a, b) => done(undefined, a && b),
|
|
2221
|
-
'||': (exec, done, ticks, a, b) => done(undefined, a || b),
|
|
2222
|
-
'&': (exec, done, ticks, a, b) => done(undefined, a & b),
|
|
2223
|
-
'|': (exec, done, ticks, a, b) => done(undefined, a | b),
|
|
2224
|
-
':': (exec, done, ticks, a, b) => done(undefined, new If(a, b)),
|
|
2225
|
-
'+': (exec, done, ticks, a, b) => done(undefined, a + b),
|
|
2226
|
-
'-': (exec, done, ticks, a, b) => done(undefined, a - b),
|
|
2227
|
-
'$+': (exec, done, ticks, a, b) => done(undefined, +b),
|
|
2228
|
-
'$-': (exec, done, ticks, a, b) => done(undefined, -b),
|
|
2229
|
-
'/': (exec, done, ticks, a, b) => done(undefined, a / b),
|
|
2230
|
-
'^': (exec, done, ticks, a, b) => done(undefined, a ^ b),
|
|
2231
|
-
'*': (exec, done, ticks, a, b) => done(undefined, a * b),
|
|
2232
|
-
'%': (exec, done, ticks, a, b) => done(undefined, a % b),
|
|
2233
|
-
'<<': (exec, done, ticks, a, b) => done(undefined, a << b),
|
|
2234
|
-
'>>': (exec, done, ticks, a, b) => done(undefined, a >> b),
|
|
2235
|
-
'>>>': (exec, done, ticks, a, b) => done(undefined, a >>> b),
|
|
2236
|
-
'typeof': (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2237
|
-
exec(ticks, b, scope, context, (e, prop) => {
|
|
2238
|
-
done(undefined, typeof valueOrProp(prop, context));
|
|
2239
|
-
});
|
|
2240
|
-
},
|
|
2241
|
-
'instanceof': (exec, done, ticks, a, b) => done(undefined, a instanceof b),
|
|
2242
|
-
'in': (exec, done, ticks, a, b) => done(undefined, a in b),
|
|
2243
|
-
'delete': (exec, done, ticks, a, b, obj, context, scope, bobj) => {
|
|
2244
|
-
if (bobj.context === undefined) {
|
|
2245
|
-
done(undefined, true);
|
|
2246
|
-
return;
|
|
2247
|
-
}
|
|
2248
|
-
assignCheck(bobj, context, 'delete');
|
|
2249
|
-
if (bobj.isVariable) {
|
|
2250
|
-
done(undefined, false);
|
|
2251
|
-
return;
|
|
2039
|
+
return [item];
|
|
2252
2040
|
}
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
done(undefined, scope.declare(a, VarType.var, res));
|
|
2263
|
-
});
|
|
2264
|
-
},
|
|
2265
|
-
'let': (exec, done, ticks, a, b, obj, context, scope, bobj) => {
|
|
2266
|
-
exec(ticks, b, scope, context, (err, res) => {
|
|
2267
|
-
if (err) {
|
|
2268
|
-
done(err);
|
|
2269
|
-
return;
|
|
2270
|
-
}
|
|
2271
|
-
done(undefined, scope.declare(a, VarType.let, res, bobj && bobj.isGlobal));
|
|
2272
|
-
});
|
|
2273
|
-
},
|
|
2274
|
-
'const': (exec, done, ticks, a, b, obj, context, scope, bobj) => {
|
|
2275
|
-
exec(ticks, b, scope, context, (err, res) => {
|
|
2276
|
-
if (err) {
|
|
2277
|
-
done(err);
|
|
2041
|
+
}).flat().map((item) => valueOrProp(item, context));
|
|
2042
|
+
if (typeof obj === 'function') {
|
|
2043
|
+
done(undefined, obj(...vals));
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
if (obj.context[obj.prop] === JSON.stringify && context.getSubscriptions.size) {
|
|
2047
|
+
const cache = new Set();
|
|
2048
|
+
const recurse = (x) => {
|
|
2049
|
+
if (!x || !(typeof x === 'object') || cache.has(x))
|
|
2278
2050
|
return;
|
|
2051
|
+
cache.add(x);
|
|
2052
|
+
for (let y in x) {
|
|
2053
|
+
context.getSubscriptions.forEach((cb) => cb(x, y));
|
|
2054
|
+
recurse(x[y]);
|
|
2279
2055
|
}
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2056
|
+
};
|
|
2057
|
+
recurse(vals[0]);
|
|
2058
|
+
}
|
|
2059
|
+
if (obj.context instanceof Array && arrayChange.has(obj.context[obj.prop]) && (context.changeSubscriptions.get(obj.context) || context.changeSubscriptionsGlobal.get(obj.context))) {
|
|
2060
|
+
let change;
|
|
2061
|
+
let changed = false;
|
|
2062
|
+
if (obj.prop === "push") {
|
|
2063
|
+
change = {
|
|
2064
|
+
type: "push",
|
|
2065
|
+
added: vals
|
|
2066
|
+
};
|
|
2067
|
+
changed = !!vals.length;
|
|
2068
|
+
}
|
|
2069
|
+
else if (obj.prop === "pop") {
|
|
2070
|
+
change = {
|
|
2071
|
+
type: "pop",
|
|
2072
|
+
removed: obj.context.slice(-1)
|
|
2073
|
+
};
|
|
2074
|
+
changed = !!change.removed.length;
|
|
2075
|
+
}
|
|
2076
|
+
else if (obj.prop === "shift") {
|
|
2077
|
+
change = {
|
|
2078
|
+
type: "shift",
|
|
2079
|
+
removed: obj.context.slice(0, 1)
|
|
2080
|
+
};
|
|
2081
|
+
changed = !!change.removed.length;
|
|
2082
|
+
}
|
|
2083
|
+
else if (obj.prop === "unshift") {
|
|
2084
|
+
change = {
|
|
2085
|
+
type: "unshift",
|
|
2086
|
+
added: vals
|
|
2087
|
+
};
|
|
2088
|
+
changed = !!vals.length;
|
|
2089
|
+
}
|
|
2090
|
+
else if (obj.prop === "splice") {
|
|
2091
|
+
change = {
|
|
2092
|
+
type: "splice",
|
|
2093
|
+
startIndex: vals[0],
|
|
2094
|
+
deleteCount: vals[1] === undefined ? obj.context.length : vals[1],
|
|
2095
|
+
added: vals.slice(2),
|
|
2096
|
+
removed: obj.context.slice(vals[0], vals[1] === undefined ? undefined : vals[0] + vals[1])
|
|
2097
|
+
};
|
|
2098
|
+
changed = !!change.added.length || !!change.removed.length;
|
|
2099
|
+
}
|
|
2100
|
+
else if (obj.prop === "reverse" || obj.prop === "sort") {
|
|
2101
|
+
change = { type: obj.prop };
|
|
2102
|
+
changed = !!obj.context.length;
|
|
2103
|
+
}
|
|
2104
|
+
else if (obj.prop === "copyWithin") {
|
|
2105
|
+
let len = vals[2] === undefined ? obj.context.length - vals[1] : Math.min(obj.context.length, vals[2] - vals[1]);
|
|
2106
|
+
change = {
|
|
2107
|
+
type: "copyWithin",
|
|
2108
|
+
startIndex: vals[0],
|
|
2109
|
+
endIndex: vals[0] + len,
|
|
2110
|
+
added: obj.context.slice(vals[1], vals[1] + len),
|
|
2111
|
+
removed: obj.context.slice(vals[0], vals[0] + len)
|
|
2112
|
+
};
|
|
2113
|
+
changed = !!change.added.length || !!change.removed.length;
|
|
2114
|
+
}
|
|
2115
|
+
if (changed) {
|
|
2116
|
+
context.changeSubscriptions.get(obj.context)?.forEach((cb) => cb(change));
|
|
2117
|
+
context.changeSubscriptionsGlobal.get(obj.context)?.forEach((cb) => cb(change));
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
obj.get(context);
|
|
2121
|
+
done(undefined, obj.context[obj.prop](...vals));
|
|
2122
|
+
});
|
|
2123
|
+
addOps(22 /* LispType.CreateObject */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2124
|
+
let res = {};
|
|
2125
|
+
for (let item of b) {
|
|
2126
|
+
if (item.key instanceof SpreadObject) {
|
|
2127
|
+
res = { ...res, ...item.key.item };
|
|
2304
2128
|
}
|
|
2305
2129
|
else {
|
|
2306
|
-
|
|
2307
|
-
}
|
|
2308
|
-
if (name) {
|
|
2309
|
-
scope.declare(name, VarType.var, func);
|
|
2130
|
+
res[item.key] = item.val;
|
|
2310
2131
|
}
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
if (name) {
|
|
2320
|
-
scope = new Scope(scope, {});
|
|
2321
|
-
}
|
|
2322
|
-
let func;
|
|
2323
|
-
if (isAsync) {
|
|
2324
|
-
func = createFunctionAsync(a, b, ticks, context, scope, name);
|
|
2132
|
+
}
|
|
2133
|
+
done(undefined, res);
|
|
2134
|
+
});
|
|
2135
|
+
addOps(6 /* LispType.KeyVal */, (exec, done, ticks, a, b) => done(undefined, new KeyVal(a, b)));
|
|
2136
|
+
addOps(12 /* LispType.CreateArray */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2137
|
+
const items = b.map((item) => {
|
|
2138
|
+
if (item instanceof SpreadArray) {
|
|
2139
|
+
return [...item.item];
|
|
2325
2140
|
}
|
|
2326
2141
|
else {
|
|
2327
|
-
|
|
2142
|
+
return [item];
|
|
2328
2143
|
}
|
|
2329
|
-
|
|
2330
|
-
|
|
2144
|
+
}).flat().map((item) => valueOrProp(item, context));
|
|
2145
|
+
done(undefined, items);
|
|
2146
|
+
});
|
|
2147
|
+
addOps(23 /* LispType.Group */, (exec, done, ticks, a, b) => done(undefined, b));
|
|
2148
|
+
addOps(35 /* LispType.GlobalSymbol */, (exec, done, ticks, a, b) => {
|
|
2149
|
+
switch (b) {
|
|
2150
|
+
case 'true': return done(undefined, true);
|
|
2151
|
+
case 'false': return done(undefined, false);
|
|
2152
|
+
case 'null': return done(undefined, null);
|
|
2153
|
+
case 'undefined': return done(undefined, undefined);
|
|
2154
|
+
case 'NaN': return done(undefined, NaN);
|
|
2155
|
+
case 'Infinity': return done(undefined, Infinity);
|
|
2156
|
+
}
|
|
2157
|
+
done(new Error('Unknown symbol: ' + b));
|
|
2158
|
+
});
|
|
2159
|
+
addOps(7 /* LispType.Number */, (exec, done, ticks, a, b) => done(undefined, Number(b)));
|
|
2160
|
+
addOps(83 /* LispType.BigInt */, (exec, done, ticks, a, b) => done(undefined, BigInt(b)));
|
|
2161
|
+
addOps(2 /* LispType.StringIndex */, (exec, done, ticks, a, b, obj, context) => done(undefined, context.constants.strings[parseInt(b)]));
|
|
2162
|
+
addOps(85 /* LispType.RegexIndex */, (exec, done, ticks, a, b, obj, context) => {
|
|
2163
|
+
const reg = context.constants.regexes[parseInt(b)];
|
|
2164
|
+
if (!context.ctx.globalsWhitelist.has(RegExp)) {
|
|
2165
|
+
throw new SandboxError("Regex not permitted");
|
|
2166
|
+
}
|
|
2167
|
+
else {
|
|
2168
|
+
done(undefined, new RegExp(reg.regex, reg.flags));
|
|
2169
|
+
}
|
|
2170
|
+
});
|
|
2171
|
+
addOps(84 /* LispType.LiteralIndex */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2172
|
+
let item = context.constants.literals[parseInt(b)];
|
|
2173
|
+
const [, name, js] = item;
|
|
2174
|
+
let found = [];
|
|
2175
|
+
let f;
|
|
2176
|
+
let resnums = [];
|
|
2177
|
+
while (f = literalRegex.exec(name)) {
|
|
2178
|
+
if (!f[2]) {
|
|
2179
|
+
found.push(js[parseInt(f[3], 10)]);
|
|
2180
|
+
resnums.push(f[3]);
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
exec(ticks, found, scope, context, (err, processed) => {
|
|
2184
|
+
const reses = {};
|
|
2185
|
+
if (err) {
|
|
2186
|
+
done(err);
|
|
2187
|
+
return;
|
|
2331
2188
|
}
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
const [checkFirst, startInternal, getIterator, startStep, step, condition, beforeStep] = a;
|
|
2336
|
-
let loop = true;
|
|
2337
|
-
const loopScope = new Scope(scope, {});
|
|
2338
|
-
let internalVars = {
|
|
2339
|
-
'$$obj': undefined
|
|
2340
|
-
};
|
|
2341
|
-
const interalScope = new Scope(loopScope, internalVars);
|
|
2342
|
-
if (exec === execAsync) {
|
|
2343
|
-
(async () => {
|
|
2344
|
-
let ad;
|
|
2345
|
-
ad = asyncDone((d) => exec(ticks, startStep, loopScope, context, d));
|
|
2346
|
-
internalVars['$$obj'] = (ad = asyncDone((d) => exec(ticks, getIterator, loopScope, context, d))).isInstant === true ? ad.instant : (await ad.p).result;
|
|
2347
|
-
ad = asyncDone((d) => exec(ticks, startInternal, interalScope, context, d));
|
|
2348
|
-
if (checkFirst)
|
|
2349
|
-
loop = (ad = asyncDone((d) => exec(ticks, condition, interalScope, context, d))).isInstant === true ? ad.instant : (await ad.p).result;
|
|
2350
|
-
while (loop) {
|
|
2351
|
-
let innerLoopVars = {};
|
|
2352
|
-
ad = asyncDone((d) => exec(ticks, beforeStep, new Scope(interalScope, innerLoopVars), context, d));
|
|
2353
|
-
ad.isInstant === true ? ad.instant : (await ad.p).result;
|
|
2354
|
-
let res = await executeTreeAsync(ticks, context, b, [new Scope(loopScope, innerLoopVars)], "loop");
|
|
2355
|
-
if (res instanceof ExecReturn && res.returned) {
|
|
2356
|
-
done(undefined, res);
|
|
2357
|
-
return;
|
|
2358
|
-
}
|
|
2359
|
-
if (res instanceof ExecReturn && res.breakLoop) {
|
|
2360
|
-
break;
|
|
2361
|
-
}
|
|
2362
|
-
ad = asyncDone((d) => exec(ticks, step, interalScope, context, d));
|
|
2363
|
-
loop = (ad = asyncDone((d) => exec(ticks, condition, interalScope, context, d))).isInstant === true ? ad.instant : (await ad.p).result;
|
|
2364
|
-
}
|
|
2365
|
-
done();
|
|
2366
|
-
})().catch(done);
|
|
2189
|
+
for (let i in resnums) {
|
|
2190
|
+
const num = resnums[i];
|
|
2191
|
+
reses[num] = processed[i];
|
|
2367
2192
|
}
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2193
|
+
done(undefined, name.replace(/(\\\\)*(\\)?\${(\d+)}/g, (match, $$, $, num) => {
|
|
2194
|
+
if ($)
|
|
2195
|
+
return match;
|
|
2196
|
+
let res = reses[num];
|
|
2197
|
+
return ($$ ? $$ : '') + `${valueOrProp(res, context)}`;
|
|
2198
|
+
}));
|
|
2199
|
+
});
|
|
2200
|
+
});
|
|
2201
|
+
addOps(18 /* LispType.SpreadArray */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2202
|
+
done(undefined, new SpreadArray(b));
|
|
2203
|
+
});
|
|
2204
|
+
addOps(17 /* LispType.SpreadObject */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2205
|
+
done(undefined, new SpreadObject(b));
|
|
2206
|
+
});
|
|
2207
|
+
addOps(24 /* LispType.Not */, (exec, done, ticks, a, b) => done(undefined, !b));
|
|
2208
|
+
addOps(64 /* LispType.Inverse */, (exec, done, ticks, a, b) => done(undefined, ~b));
|
|
2209
|
+
addOps(25 /* LispType.IncrementBefore */, (exec, done, ticks, a, b, obj, context) => {
|
|
2210
|
+
assignCheck(obj, context);
|
|
2211
|
+
done(undefined, ++obj.context[obj.prop]);
|
|
2212
|
+
});
|
|
2213
|
+
addOps(26 /* LispType.IncrementAfter */, (exec, done, ticks, a, b, obj, context) => {
|
|
2214
|
+
assignCheck(obj, context);
|
|
2215
|
+
done(undefined, obj.context[obj.prop]++);
|
|
2216
|
+
});
|
|
2217
|
+
addOps(27 /* LispType.DecrementBefore */, (exec, done, ticks, a, b, obj, context) => {
|
|
2218
|
+
assignCheck(obj, context);
|
|
2219
|
+
done(undefined, --obj.context[obj.prop]);
|
|
2220
|
+
});
|
|
2221
|
+
addOps(28 /* LispType.DecrementAfter */, (exec, done, ticks, a, b, obj, context) => {
|
|
2222
|
+
assignCheck(obj, context);
|
|
2223
|
+
done(undefined, obj.context[obj.prop]--);
|
|
2224
|
+
});
|
|
2225
|
+
addOps(9 /* LispType.Assign */, (exec, done, ticks, a, b, obj, context) => {
|
|
2226
|
+
assignCheck(obj, context);
|
|
2227
|
+
done(undefined, obj.context[obj.prop] = b);
|
|
2228
|
+
});
|
|
2229
|
+
addOps(66 /* LispType.AddEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2230
|
+
assignCheck(obj, context);
|
|
2231
|
+
done(undefined, obj.context[obj.prop] += b);
|
|
2232
|
+
});
|
|
2233
|
+
addOps(65 /* LispType.SubractEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2234
|
+
assignCheck(obj, context);
|
|
2235
|
+
done(undefined, obj.context[obj.prop] -= b);
|
|
2236
|
+
});
|
|
2237
|
+
addOps(67 /* LispType.DivideEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2238
|
+
assignCheck(obj, context);
|
|
2239
|
+
done(undefined, obj.context[obj.prop] /= b);
|
|
2240
|
+
});
|
|
2241
|
+
addOps(69 /* LispType.MultiplyEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2242
|
+
assignCheck(obj, context);
|
|
2243
|
+
done(undefined, obj.context[obj.prop] *= b);
|
|
2244
|
+
});
|
|
2245
|
+
addOps(68 /* LispType.PowerEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2246
|
+
assignCheck(obj, context);
|
|
2247
|
+
done(undefined, obj.context[obj.prop] **= b);
|
|
2248
|
+
});
|
|
2249
|
+
addOps(70 /* LispType.ModulusEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2250
|
+
assignCheck(obj, context);
|
|
2251
|
+
done(undefined, obj.context[obj.prop] %= b);
|
|
2252
|
+
});
|
|
2253
|
+
addOps(71 /* LispType.BitNegateEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2254
|
+
assignCheck(obj, context);
|
|
2255
|
+
done(undefined, obj.context[obj.prop] ^= b);
|
|
2256
|
+
});
|
|
2257
|
+
addOps(72 /* LispType.BitAndEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2258
|
+
assignCheck(obj, context);
|
|
2259
|
+
done(undefined, obj.context[obj.prop] &= b);
|
|
2260
|
+
});
|
|
2261
|
+
addOps(73 /* LispType.BitOrEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2262
|
+
assignCheck(obj, context);
|
|
2263
|
+
done(undefined, obj.context[obj.prop] |= b);
|
|
2264
|
+
});
|
|
2265
|
+
addOps(76 /* LispType.ShiftLeftEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2266
|
+
assignCheck(obj, context);
|
|
2267
|
+
done(undefined, obj.context[obj.prop] <<= b);
|
|
2268
|
+
});
|
|
2269
|
+
addOps(75 /* LispType.ShiftRightEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2270
|
+
assignCheck(obj, context);
|
|
2271
|
+
done(undefined, obj.context[obj.prop] >>= b);
|
|
2272
|
+
});
|
|
2273
|
+
addOps(74 /* LispType.UnsignedShiftRightEquals */, (exec, done, ticks, a, b, obj, context) => {
|
|
2274
|
+
assignCheck(obj, context);
|
|
2275
|
+
done(undefined, obj.context[obj.prop] >>= b);
|
|
2276
|
+
});
|
|
2277
|
+
addOps(57 /* LispType.LargerThan */, (exec, done, ticks, a, b) => done(undefined, a > b));
|
|
2278
|
+
addOps(56 /* LispType.SmallerThan */, (exec, done, ticks, a, b) => done(undefined, a < b));
|
|
2279
|
+
addOps(55 /* LispType.LargerEqualThan */, (exec, done, ticks, a, b) => done(undefined, a >= b));
|
|
2280
|
+
addOps(54 /* LispType.SmallerEqualThan */, (exec, done, ticks, a, b) => done(undefined, a <= b));
|
|
2281
|
+
addOps(52 /* LispType.Equal */, (exec, done, ticks, a, b) => done(undefined, a == b));
|
|
2282
|
+
addOps(32 /* LispType.StrictEqual */, (exec, done, ticks, a, b) => done(undefined, a === b));
|
|
2283
|
+
addOps(53 /* LispType.NotEqual */, (exec, done, ticks, a, b) => done(undefined, a != b));
|
|
2284
|
+
addOps(31 /* LispType.StrictNotEqual */, (exec, done, ticks, a, b) => done(undefined, a !== b));
|
|
2285
|
+
addOps(29 /* LispType.And */, (exec, done, ticks, a, b) => done(undefined, a && b));
|
|
2286
|
+
addOps(30 /* LispType.Or */, (exec, done, ticks, a, b) => done(undefined, a || b));
|
|
2287
|
+
addOps(77 /* LispType.BitAnd */, (exec, done, ticks, a, b) => done(undefined, a & b));
|
|
2288
|
+
addOps(78 /* LispType.BitOr */, (exec, done, ticks, a, b) => done(undefined, a | b));
|
|
2289
|
+
addOps(33 /* LispType.Plus */, (exec, done, ticks, a, b) => done(undefined, a + b));
|
|
2290
|
+
addOps(47 /* LispType.Minus */, (exec, done, ticks, a, b) => done(undefined, a - b));
|
|
2291
|
+
addOps(59 /* LispType.Positive */, (exec, done, ticks, a, b) => done(undefined, +b));
|
|
2292
|
+
addOps(58 /* LispType.Negative */, (exec, done, ticks, a, b) => done(undefined, -b));
|
|
2293
|
+
addOps(48 /* LispType.Divide */, (exec, done, ticks, a, b) => done(undefined, a / b));
|
|
2294
|
+
addOps(79 /* LispType.BitNegate */, (exec, done, ticks, a, b) => done(undefined, a ^ b));
|
|
2295
|
+
addOps(50 /* LispType.Multiply */, (exec, done, ticks, a, b) => done(undefined, a * b));
|
|
2296
|
+
addOps(51 /* LispType.Modulus */, (exec, done, ticks, a, b) => done(undefined, a % b));
|
|
2297
|
+
addOps(80 /* LispType.BitShiftLeft */, (exec, done, ticks, a, b) => done(undefined, a << b));
|
|
2298
|
+
addOps(81 /* LispType.BitShiftRight */, (exec, done, ticks, a, b) => done(undefined, a >> b));
|
|
2299
|
+
addOps(82 /* LispType.BitUnsignedShiftRight */, (exec, done, ticks, a, b) => done(undefined, a >>> b));
|
|
2300
|
+
addOps(60 /* LispType.Typeof */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2301
|
+
exec(ticks, b, scope, context, (e, prop) => {
|
|
2302
|
+
done(undefined, typeof valueOrProp(prop, context));
|
|
2303
|
+
});
|
|
2304
|
+
});
|
|
2305
|
+
addOps(62 /* LispType.Instanceof */, (exec, done, ticks, a, b) => done(undefined, a instanceof b));
|
|
2306
|
+
addOps(63 /* LispType.In */, (exec, done, ticks, a, b) => done(undefined, a in b));
|
|
2307
|
+
addOps(61 /* LispType.Delete */, (exec, done, ticks, a, b, obj, context, scope, bobj) => {
|
|
2308
|
+
if (bobj.context === undefined) {
|
|
2309
|
+
done(undefined, true);
|
|
2310
|
+
return;
|
|
2311
|
+
}
|
|
2312
|
+
assignCheck(bobj, context, 'delete');
|
|
2313
|
+
if (bobj.isVariable) {
|
|
2314
|
+
done(undefined, false);
|
|
2315
|
+
return;
|
|
2316
|
+
}
|
|
2317
|
+
done(undefined, delete bobj.context[bobj.prop]);
|
|
2318
|
+
});
|
|
2319
|
+
addOps(8 /* LispType.Return */, (exec, done, ticks, a, b, obj, context) => done(undefined, b));
|
|
2320
|
+
addOps(34 /* LispType.Var */, (exec, done, ticks, a, b, obj, context, scope, bobj) => {
|
|
2321
|
+
done(undefined, scope.declare(a, VarType.var, b));
|
|
2322
|
+
});
|
|
2323
|
+
addOps(3 /* LispType.Let */, (exec, done, ticks, a, b, obj, context, scope, bobj) => {
|
|
2324
|
+
done(undefined, scope.declare(a, VarType.let, b, bobj && bobj.isGlobal));
|
|
2325
|
+
});
|
|
2326
|
+
addOps(4 /* LispType.Const */, (exec, done, ticks, a, b, obj, context, scope, bobj) => {
|
|
2327
|
+
done(undefined, scope.declare(a, VarType.const, b));
|
|
2328
|
+
});
|
|
2329
|
+
addOps(11 /* LispType.ArrowFunction */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2330
|
+
a = [...a];
|
|
2331
|
+
if (typeof obj[2] === "string" || obj[2] instanceof CodeString) {
|
|
2332
|
+
obj[2] = b = lispifyFunction(new CodeString(obj[2]), context.constants);
|
|
2333
|
+
}
|
|
2334
|
+
if (a.shift()) {
|
|
2335
|
+
done(undefined, createFunctionAsync(a, b, ticks, context, scope));
|
|
2336
|
+
}
|
|
2337
|
+
else {
|
|
2338
|
+
done(undefined, createFunction(a, b, ticks, context, scope));
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
addOps(37 /* LispType.Function */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2342
|
+
if (typeof obj[2] === "string" || obj[2] instanceof CodeString) {
|
|
2343
|
+
obj[2] = b = lispifyFunction(new CodeString(obj[2]), context.constants);
|
|
2344
|
+
}
|
|
2345
|
+
let isAsync = a.shift();
|
|
2346
|
+
let name = a.shift();
|
|
2347
|
+
let func;
|
|
2348
|
+
if (isAsync === 88 /* LispType.True */) {
|
|
2349
|
+
func = createFunctionAsync(a, b, ticks, context, scope, name);
|
|
2350
|
+
}
|
|
2351
|
+
else {
|
|
2352
|
+
func = createFunction(a, b, ticks, context, scope, name);
|
|
2353
|
+
}
|
|
2354
|
+
if (name) {
|
|
2355
|
+
scope.declare(name, VarType.var, func);
|
|
2356
|
+
}
|
|
2357
|
+
done(undefined, func);
|
|
2358
|
+
});
|
|
2359
|
+
addOps(10 /* LispType.InlineFunction */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2360
|
+
if (typeof obj[2] === "string" || obj[2] instanceof CodeString) {
|
|
2361
|
+
obj[2] = b = lispifyFunction(new CodeString(obj[2]), context.constants);
|
|
2362
|
+
}
|
|
2363
|
+
let isAsync = a.shift();
|
|
2364
|
+
let name = a.shift();
|
|
2365
|
+
if (name) {
|
|
2366
|
+
scope = new Scope(scope, {});
|
|
2367
|
+
}
|
|
2368
|
+
let func;
|
|
2369
|
+
if (isAsync === 88 /* LispType.True */) {
|
|
2370
|
+
func = createFunctionAsync(a, b, ticks, context, scope, name);
|
|
2371
|
+
}
|
|
2372
|
+
else {
|
|
2373
|
+
func = createFunction(a, b, ticks, context, scope, name);
|
|
2374
|
+
}
|
|
2375
|
+
if (name) {
|
|
2376
|
+
scope.declare(name, VarType.let, func);
|
|
2377
|
+
}
|
|
2378
|
+
done(undefined, func);
|
|
2379
|
+
});
|
|
2380
|
+
addOps(38 /* LispType.Loop */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2381
|
+
const [checkFirst, startInternal, getIterator, startStep, step, condition, beforeStep] = a;
|
|
2382
|
+
let loop = true;
|
|
2383
|
+
const loopScope = new Scope(scope, {});
|
|
2384
|
+
let internalVars = {
|
|
2385
|
+
'$$obj': undefined
|
|
2386
|
+
};
|
|
2387
|
+
const interalScope = new Scope(loopScope, internalVars);
|
|
2388
|
+
if (exec === execAsync) {
|
|
2389
|
+
(async () => {
|
|
2390
|
+
let ad;
|
|
2391
|
+
ad = asyncDone((d) => exec(ticks, startStep, loopScope, context, d));
|
|
2392
|
+
internalVars['$$obj'] = (ad = asyncDone((d) => exec(ticks, getIterator, loopScope, context, d))).isInstant === true ? ad.instant : (await ad.p).result;
|
|
2393
|
+
ad = asyncDone((d) => exec(ticks, startInternal, interalScope, context, d));
|
|
2372
2394
|
if (checkFirst)
|
|
2373
|
-
loop = (
|
|
2395
|
+
loop = (ad = asyncDone((d) => exec(ticks, condition, interalScope, context, d))).isInstant === true ? ad.instant : (await ad.p).result;
|
|
2374
2396
|
while (loop) {
|
|
2375
2397
|
let innerLoopVars = {};
|
|
2376
|
-
|
|
2377
|
-
|
|
2398
|
+
ad = asyncDone((d) => exec(ticks, beforeStep, new Scope(interalScope, innerLoopVars), context, d));
|
|
2399
|
+
ad.isInstant === true ? ad.instant : (await ad.p).result;
|
|
2400
|
+
let res = await executeTreeAsync(ticks, context, b, [new Scope(loopScope, innerLoopVars)], "loop");
|
|
2378
2401
|
if (res instanceof ExecReturn && res.returned) {
|
|
2379
2402
|
done(undefined, res);
|
|
2380
2403
|
return;
|
|
@@ -2382,116 +2405,128 @@ let ops2 = {
|
|
|
2382
2405
|
if (res instanceof ExecReturn && res.breakLoop) {
|
|
2383
2406
|
break;
|
|
2384
2407
|
}
|
|
2385
|
-
|
|
2386
|
-
loop = (
|
|
2408
|
+
ad = asyncDone((d) => exec(ticks, step, interalScope, context, d));
|
|
2409
|
+
loop = (ad = asyncDone((d) => exec(ticks, condition, interalScope, context, d))).isInstant === true ? ad.instant : (await ad.p).result;
|
|
2387
2410
|
}
|
|
2388
2411
|
done();
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
done(err);
|
|
2412
|
+
})().catch(done);
|
|
2413
|
+
}
|
|
2414
|
+
else {
|
|
2415
|
+
syncDone((d) => exec(ticks, startStep, loopScope, context, d));
|
|
2416
|
+
internalVars['$$obj'] = syncDone((d) => exec(ticks, getIterator, loopScope, context, d)).result;
|
|
2417
|
+
syncDone((d) => exec(ticks, startInternal, interalScope, context, d));
|
|
2418
|
+
if (checkFirst)
|
|
2419
|
+
loop = (syncDone((d) => exec(ticks, condition, interalScope, context, d))).result;
|
|
2420
|
+
while (loop) {
|
|
2421
|
+
let innerLoopVars = {};
|
|
2422
|
+
syncDone((d) => exec(ticks, beforeStep, new Scope(interalScope, innerLoopVars), context, d));
|
|
2423
|
+
let res = executeTree(ticks, context, b, [new Scope(loopScope, innerLoopVars)], "loop");
|
|
2424
|
+
if (res instanceof ExecReturn && res.returned) {
|
|
2425
|
+
done(undefined, res);
|
|
2404
2426
|
return;
|
|
2405
2427
|
}
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
},
|
|
2409
|
-
'switch': (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2410
|
-
exec(ticks, a, scope, context, (err, toTest) => {
|
|
2411
|
-
if (err) {
|
|
2412
|
-
done(err);
|
|
2413
|
-
return;
|
|
2428
|
+
if (res instanceof ExecReturn && res.breakLoop) {
|
|
2429
|
+
break;
|
|
2414
2430
|
}
|
|
2415
|
-
|
|
2416
|
-
|
|
2431
|
+
syncDone((d) => exec(ticks, step, interalScope, context, d));
|
|
2432
|
+
loop = (syncDone((d) => exec(ticks, condition, interalScope, context, d))).result;
|
|
2433
|
+
}
|
|
2434
|
+
done();
|
|
2435
|
+
}
|
|
2436
|
+
});
|
|
2437
|
+
addOps(86 /* LispType.LoopAction */, (exec, done, ticks, a, b, obj, context, scope, bobj, inLoopOrSwitch) => {
|
|
2438
|
+
if ((inLoopOrSwitch === "switch" && a === "continue") || !inLoopOrSwitch) {
|
|
2439
|
+
throw new SandboxError("Illegal " + a + " statement");
|
|
2440
|
+
}
|
|
2441
|
+
done(undefined, new ExecReturn(context.ctx.auditReport, undefined, false, a === "break", a === "continue"));
|
|
2442
|
+
});
|
|
2443
|
+
addOps(13 /* LispType.If */, (exec, done, ticks, a, b, obj, context, scope, bobj, inLoopOrSwitch) => {
|
|
2444
|
+
exec(ticks, valueOrProp(a, context) ? b.t : b.f, scope, context, done);
|
|
2445
|
+
});
|
|
2446
|
+
addOps(15 /* LispType.InlineIf */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2447
|
+
exec(ticks, valueOrProp(a, context) ? b.t : b.f, scope, context, done);
|
|
2448
|
+
});
|
|
2449
|
+
addOps(16 /* LispType.InlineIfCase */, (exec, done, ticks, a, b) => done(undefined, new If(a, b)));
|
|
2450
|
+
addOps(14 /* LispType.IfCase */, (exec, done, ticks, a, b) => done(undefined, new If(a, b)));
|
|
2451
|
+
addOps(40 /* LispType.Switch */, (exec, done, ticks, a, b, obj, context, scope) => {
|
|
2452
|
+
exec(ticks, a, scope, context, (err, toTest) => {
|
|
2453
|
+
if (err) {
|
|
2454
|
+
done(err);
|
|
2455
|
+
return;
|
|
2456
|
+
}
|
|
2457
|
+
toTest = valueOrProp(toTest, context);
|
|
2458
|
+
if (exec === execSync) {
|
|
2459
|
+
let res;
|
|
2460
|
+
let isTrue = false;
|
|
2461
|
+
for (let caseItem of b) {
|
|
2462
|
+
if (isTrue || (isTrue = !caseItem[1] || toTest === valueOrProp((syncDone((d) => exec(ticks, caseItem[1], scope, context, d))).result, context))) {
|
|
2463
|
+
if (!caseItem[2])
|
|
2464
|
+
continue;
|
|
2465
|
+
res = executeTree(ticks, context, caseItem[2], [scope], "switch");
|
|
2466
|
+
if (res.breakLoop)
|
|
2467
|
+
break;
|
|
2468
|
+
if (res.returned) {
|
|
2469
|
+
done(undefined, res);
|
|
2470
|
+
return;
|
|
2471
|
+
}
|
|
2472
|
+
if (!caseItem[1]) { // default case
|
|
2473
|
+
break;
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
done();
|
|
2478
|
+
}
|
|
2479
|
+
else {
|
|
2480
|
+
(async () => {
|
|
2417
2481
|
let res;
|
|
2418
2482
|
let isTrue = false;
|
|
2419
2483
|
for (let caseItem of b) {
|
|
2420
|
-
|
|
2421
|
-
|
|
2484
|
+
let ad;
|
|
2485
|
+
if (isTrue || (isTrue = !caseItem[1] || toTest === valueOrProp((ad = asyncDone((d) => exec(ticks, caseItem[1], scope, context, d))).isInstant === true ? ad.instant : (await ad.p).result, context))) {
|
|
2486
|
+
if (!caseItem[2])
|
|
2422
2487
|
continue;
|
|
2423
|
-
res =
|
|
2488
|
+
res = await executeTreeAsync(ticks, context, caseItem[2], [scope], "switch");
|
|
2424
2489
|
if (res.breakLoop)
|
|
2425
2490
|
break;
|
|
2426
2491
|
if (res.returned) {
|
|
2427
2492
|
done(undefined, res);
|
|
2428
2493
|
return;
|
|
2429
2494
|
}
|
|
2430
|
-
if (!caseItem
|
|
2495
|
+
if (!caseItem[1]) { // default case
|
|
2431
2496
|
break;
|
|
2432
2497
|
}
|
|
2433
2498
|
}
|
|
2434
2499
|
}
|
|
2435
2500
|
done();
|
|
2501
|
+
})().catch(done);
|
|
2502
|
+
}
|
|
2503
|
+
});
|
|
2504
|
+
});
|
|
2505
|
+
addOps(39 /* LispType.Try */, (exec, done, ticks, a, b, obj, context, scope, bobj, inLoopOrSwitch) => {
|
|
2506
|
+
const [exception, catchBody, finallyBody] = b;
|
|
2507
|
+
executeTreeWithDone(exec, (err, res) => {
|
|
2508
|
+
executeTreeWithDone(exec, (e) => {
|
|
2509
|
+
if (e)
|
|
2510
|
+
done(e);
|
|
2511
|
+
else if (err) {
|
|
2512
|
+
executeTreeWithDone(exec, done, ticks, context, catchBody, [new Scope(scope)], inLoopOrSwitch);
|
|
2436
2513
|
}
|
|
2437
2514
|
else {
|
|
2438
|
-
(
|
|
2439
|
-
let res;
|
|
2440
|
-
let isTrue = false;
|
|
2441
|
-
for (let caseItem of b) {
|
|
2442
|
-
let ad;
|
|
2443
|
-
if (isTrue || (isTrue = !caseItem.a || toTest === valueOrProp((ad = asyncDone((d) => exec(ticks, caseItem.a, scope, context, d))).isInstant === true ? ad.instant : (await ad.p).result, context))) {
|
|
2444
|
-
if (!caseItem.b)
|
|
2445
|
-
continue;
|
|
2446
|
-
res = await executeTreeAsync(ticks, context, caseItem.b, [scope], "switch");
|
|
2447
|
-
if (res.breakLoop)
|
|
2448
|
-
break;
|
|
2449
|
-
if (res.returned) {
|
|
2450
|
-
done(undefined, res);
|
|
2451
|
-
return;
|
|
2452
|
-
}
|
|
2453
|
-
if (!caseItem.a) { // default case
|
|
2454
|
-
break;
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
done();
|
|
2459
|
-
})().catch(done);
|
|
2515
|
+
done(undefined, res);
|
|
2460
2516
|
}
|
|
2461
|
-
});
|
|
2462
|
-
},
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
}
|
|
2475
|
-
else {
|
|
2476
|
-
done(undefined, res);
|
|
2477
|
-
}
|
|
2478
|
-
}, ticks, context, finallyBody, [new Scope(scope, {})]);
|
|
2479
|
-
}, ticks, context, a, [new Scope(scope)], inLoopOrSwitch);
|
|
2480
|
-
},
|
|
2481
|
-
'void': (exec, done, ticks, a) => { done(); },
|
|
2482
|
-
'new': (exec, done, ticks, a, b, obj, context) => {
|
|
2483
|
-
if (!context.ctx.globalsWhitelist.has(a) && !sandboxedFunctions.has(a)) {
|
|
2484
|
-
throw new SandboxError(`Object construction not allowed: ${a.constructor.name}`);
|
|
2485
|
-
}
|
|
2486
|
-
done(undefined, new a(...b));
|
|
2487
|
-
},
|
|
2488
|
-
'throw': (exec, done, ticks, a, b) => { done(b); },
|
|
2489
|
-
'multi': (exec, done, ticks, a) => done(undefined, a.pop())
|
|
2490
|
-
};
|
|
2491
|
-
let ops = new Map();
|
|
2492
|
-
for (let op in ops2) {
|
|
2493
|
-
ops.set(op, ops2[op]);
|
|
2494
|
-
}
|
|
2517
|
+
}, ticks, context, finallyBody, [new Scope(scope, {})]);
|
|
2518
|
+
}, ticks, context, a, [new Scope(scope)], inLoopOrSwitch);
|
|
2519
|
+
});
|
|
2520
|
+
addOps(87 /* LispType.Void */, (exec, done, ticks, a) => { done(); });
|
|
2521
|
+
addOps(45 /* LispType.New */, (exec, done, ticks, a, b, obj, context) => {
|
|
2522
|
+
if (!context.ctx.globalsWhitelist.has(a) && !sandboxedFunctions.has(a)) {
|
|
2523
|
+
throw new SandboxError(`Object construction not allowed: ${a.constructor.name}`);
|
|
2524
|
+
}
|
|
2525
|
+
done(undefined, new a(...b));
|
|
2526
|
+
});
|
|
2527
|
+
addOps(46 /* LispType.Throw */, (exec, done, ticks, a, b) => { done(b); });
|
|
2528
|
+
addOps(43 /* LispType.Expression */, (exec, done, ticks, a) => done(undefined, a.pop()));
|
|
2529
|
+
addOps(0 /* LispType.None */, (exec, done, ticks, a) => done());
|
|
2495
2530
|
function valueOrProp(a, context) {
|
|
2496
2531
|
if (a instanceof Prop)
|
|
2497
2532
|
return a.get(context);
|
|
@@ -2522,6 +2557,10 @@ function _execManySync(ticks, tree, done, scope, context, inLoopOrSwitch) {
|
|
|
2522
2557
|
done(undefined, res);
|
|
2523
2558
|
return;
|
|
2524
2559
|
}
|
|
2560
|
+
if (isLisp(tree[i]) && tree[i][0] === 8 /* LispType.Return */) {
|
|
2561
|
+
done(undefined, new ExecReturn(context.ctx.auditReport, res, true));
|
|
2562
|
+
return;
|
|
2563
|
+
}
|
|
2525
2564
|
ret.push(res);
|
|
2526
2565
|
}
|
|
2527
2566
|
done(undefined, ret);
|
|
@@ -2542,6 +2581,10 @@ async function _execManyAsync(ticks, tree, done, scope, context, inLoopOrSwitch)
|
|
|
2542
2581
|
done(undefined, res);
|
|
2543
2582
|
return;
|
|
2544
2583
|
}
|
|
2584
|
+
if (isLisp(tree[i]) && tree[i][0] === 8 /* LispType.Return */) {
|
|
2585
|
+
done(undefined, new ExecReturn(context.ctx.auditReport, res, true));
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2545
2588
|
ret.push(res);
|
|
2546
2589
|
}
|
|
2547
2590
|
done(undefined, ret);
|
|
@@ -2586,11 +2629,12 @@ async function execAsync(ticks, tree, scope, context, doneOriginal, inLoopOrSwit
|
|
|
2586
2629
|
};
|
|
2587
2630
|
});
|
|
2588
2631
|
if (_execNoneRecurse(ticks, tree, scope, context, done, true, inLoopOrSwitch)) ;
|
|
2589
|
-
else if (tree
|
|
2632
|
+
else if (isLisp(tree)) {
|
|
2633
|
+
let op = tree[0];
|
|
2590
2634
|
let obj;
|
|
2591
2635
|
try {
|
|
2592
2636
|
let ad;
|
|
2593
|
-
obj = (ad = asyncDone((d) => execAsync(ticks, tree
|
|
2637
|
+
obj = (ad = asyncDone((d) => execAsync(ticks, tree[1], scope, context, d, inLoopOrSwitch))).isInstant === true ? ad.instant : (await ad.p).result;
|
|
2594
2638
|
}
|
|
2595
2639
|
catch (e) {
|
|
2596
2640
|
done(e);
|
|
@@ -2604,16 +2648,15 @@ async function execAsync(ticks, tree, scope, context, doneOriginal, inLoopOrSwit
|
|
|
2604
2648
|
done(e);
|
|
2605
2649
|
return;
|
|
2606
2650
|
}
|
|
2607
|
-
|
|
2608
|
-
if (op === '?prop' || op === '?call') {
|
|
2651
|
+
if (op === 20 /* LispType.PropOptional */ || op === 21 /* LispType.CallOptional */) {
|
|
2609
2652
|
if (a === undefined || a === null) {
|
|
2610
2653
|
done(undefined, optional);
|
|
2611
2654
|
return;
|
|
2612
2655
|
}
|
|
2613
|
-
op = op.
|
|
2656
|
+
op = op === 20 /* LispType.PropOptional */ ? 1 /* LispType.Prop */ : 5 /* LispType.Call */;
|
|
2614
2657
|
}
|
|
2615
2658
|
if (a === optional) {
|
|
2616
|
-
if (op ===
|
|
2659
|
+
if (op === 1 /* LispType.Prop */ || op === 5 /* LispType.Call */) {
|
|
2617
2660
|
done(undefined, a);
|
|
2618
2661
|
return;
|
|
2619
2662
|
}
|
|
@@ -2624,7 +2667,7 @@ async function execAsync(ticks, tree, scope, context, doneOriginal, inLoopOrSwit
|
|
|
2624
2667
|
let bobj;
|
|
2625
2668
|
try {
|
|
2626
2669
|
let ad;
|
|
2627
|
-
bobj = (ad = asyncDone((d) => execAsync(ticks, tree
|
|
2670
|
+
bobj = (ad = asyncDone((d) => execAsync(ticks, tree[2], scope, context, d, inLoopOrSwitch))).isInstant === true ? ad.instant : (await ad.p).result;
|
|
2628
2671
|
}
|
|
2629
2672
|
catch (e) {
|
|
2630
2673
|
done(e);
|
|
@@ -2657,10 +2700,11 @@ async function execAsync(ticks, tree, scope, context, doneOriginal, inLoopOrSwit
|
|
|
2657
2700
|
}
|
|
2658
2701
|
function execSync(ticks, tree, scope, context, done, inLoopOrSwitch) {
|
|
2659
2702
|
if (_execNoneRecurse(ticks, tree, scope, context, done, false, inLoopOrSwitch)) ;
|
|
2660
|
-
else if (tree
|
|
2703
|
+
else if (isLisp(tree)) {
|
|
2704
|
+
let op = tree[0];
|
|
2661
2705
|
let obj;
|
|
2662
2706
|
try {
|
|
2663
|
-
obj = syncDone((d) => execSync(ticks, tree
|
|
2707
|
+
obj = syncDone((d) => execSync(ticks, tree[1], scope, context, d, inLoopOrSwitch)).result;
|
|
2664
2708
|
}
|
|
2665
2709
|
catch (e) {
|
|
2666
2710
|
done(e);
|
|
@@ -2674,16 +2718,15 @@ function execSync(ticks, tree, scope, context, done, inLoopOrSwitch) {
|
|
|
2674
2718
|
done(e);
|
|
2675
2719
|
return;
|
|
2676
2720
|
}
|
|
2677
|
-
|
|
2678
|
-
if (op === '?prop' || op === '?call') {
|
|
2721
|
+
if (op === 20 /* LispType.PropOptional */ || op === 21 /* LispType.CallOptional */) {
|
|
2679
2722
|
if (a === undefined || a === null) {
|
|
2680
2723
|
done(undefined, optional);
|
|
2681
2724
|
return;
|
|
2682
2725
|
}
|
|
2683
|
-
op = op.
|
|
2726
|
+
op = op === 20 /* LispType.PropOptional */ ? 1 /* LispType.Prop */ : 5 /* LispType.Call */;
|
|
2684
2727
|
}
|
|
2685
2728
|
if (a === optional) {
|
|
2686
|
-
if (op ===
|
|
2729
|
+
if (op === 1 /* LispType.Prop */ || op === 5 /* LispType.Call */) {
|
|
2687
2730
|
done(undefined, a);
|
|
2688
2731
|
return;
|
|
2689
2732
|
}
|
|
@@ -2693,7 +2736,7 @@ function execSync(ticks, tree, scope, context, done, inLoopOrSwitch) {
|
|
|
2693
2736
|
}
|
|
2694
2737
|
let bobj;
|
|
2695
2738
|
try {
|
|
2696
|
-
bobj = syncDone((d) => execSync(ticks, tree
|
|
2739
|
+
bobj = syncDone((d) => execSync(ticks, tree[2], scope, context, d, inLoopOrSwitch)).result;
|
|
2697
2740
|
}
|
|
2698
2741
|
catch (e) {
|
|
2699
2742
|
done(e);
|
|
@@ -2723,9 +2766,18 @@ function execSync(ticks, tree, scope, context, done, inLoopOrSwitch) {
|
|
|
2723
2766
|
}
|
|
2724
2767
|
}
|
|
2725
2768
|
}
|
|
2726
|
-
const unexecTypes = new Set([
|
|
2769
|
+
const unexecTypes = new Set([
|
|
2770
|
+
11 /* LispType.ArrowFunction */,
|
|
2771
|
+
37 /* LispType.Function */,
|
|
2772
|
+
10 /* LispType.InlineFunction */,
|
|
2773
|
+
38 /* LispType.Loop */,
|
|
2774
|
+
39 /* LispType.Try */,
|
|
2775
|
+
40 /* LispType.Switch */,
|
|
2776
|
+
14 /* LispType.IfCase */,
|
|
2777
|
+
16 /* LispType.InlineIfCase */,
|
|
2778
|
+
60 /* LispType.Typeof */
|
|
2779
|
+
]);
|
|
2727
2780
|
function _execNoneRecurse(ticks, tree, scope, context, done, isAsync, inLoopOrSwitch) {
|
|
2728
|
-
var _a;
|
|
2729
2781
|
const exec = isAsync ? execAsync : execSync;
|
|
2730
2782
|
if (context.ctx.options.executionQuota <= ticks.ticks) {
|
|
2731
2783
|
if (typeof context.ctx.options.onExecutionQuotaReached === 'function' && context.ctx.options.onExecutionQuotaReached(ticks, scope, context, tree)) ;
|
|
@@ -2747,18 +2799,26 @@ function _execNoneRecurse(ticks, tree, scope, context, done, isAsync, inLoopOrSw
|
|
|
2747
2799
|
else if (tree === optional) {
|
|
2748
2800
|
done();
|
|
2749
2801
|
}
|
|
2750
|
-
else if (Array.isArray(tree) && tree
|
|
2751
|
-
|
|
2802
|
+
else if (Array.isArray(tree) && !isLisp(tree)) {
|
|
2803
|
+
if (tree[0] === 0 /* LispType.None */) {
|
|
2804
|
+
done();
|
|
2805
|
+
}
|
|
2806
|
+
else {
|
|
2807
|
+
execMany(ticks, exec, tree, done, scope, context, inLoopOrSwitch);
|
|
2808
|
+
}
|
|
2752
2809
|
}
|
|
2753
|
-
else if (!(tree
|
|
2810
|
+
else if (!isLisp(tree)) {
|
|
2754
2811
|
done(undefined, tree);
|
|
2755
2812
|
}
|
|
2756
|
-
else if (tree
|
|
2813
|
+
else if (tree[0] === 42 /* LispType.Block */) {
|
|
2814
|
+
execMany(ticks, exec, tree[1], done, scope, context, inLoopOrSwitch);
|
|
2815
|
+
}
|
|
2816
|
+
else if (tree[0] === 44 /* LispType.Await */) {
|
|
2757
2817
|
if (!isAsync) {
|
|
2758
2818
|
done(new SandboxError("Illegal use of 'await', must be inside async function"));
|
|
2759
2819
|
}
|
|
2760
|
-
else if (
|
|
2761
|
-
execAsync(ticks, tree
|
|
2820
|
+
else if (context.ctx.prototypeWhitelist?.has(Promise.prototype)) {
|
|
2821
|
+
execAsync(ticks, tree[1], scope, context, async (e, r) => {
|
|
2762
2822
|
if (e)
|
|
2763
2823
|
done(e);
|
|
2764
2824
|
else
|
|
@@ -2774,9 +2834,9 @@ function _execNoneRecurse(ticks, tree, scope, context, done, isAsync, inLoopOrSw
|
|
|
2774
2834
|
done(new SandboxError('Async/await is not permitted'));
|
|
2775
2835
|
}
|
|
2776
2836
|
}
|
|
2777
|
-
else if (unexecTypes.has(tree
|
|
2837
|
+
else if (unexecTypes.has(tree[0])) {
|
|
2778
2838
|
try {
|
|
2779
|
-
ops.get(tree
|
|
2839
|
+
ops.get(tree[0])(exec, done, ticks, tree[1], tree[2], tree, context, scope, undefined, inLoopOrSwitch);
|
|
2780
2840
|
}
|
|
2781
2841
|
catch (err) {
|
|
2782
2842
|
done(err);
|
|
@@ -2852,7 +2912,7 @@ function _executeWithDoneSync(done, ticks, context, executionTree, scope, inLoop
|
|
|
2852
2912
|
done(undefined, res);
|
|
2853
2913
|
return;
|
|
2854
2914
|
}
|
|
2855
|
-
if (current
|
|
2915
|
+
if (isLisp(current) && current[0] === 8 /* LispType.Return */) {
|
|
2856
2916
|
done(undefined, new ExecReturn(context.ctx.auditReport, res, true));
|
|
2857
2917
|
return;
|
|
2858
2918
|
}
|
|
@@ -2884,7 +2944,7 @@ async function _executeWithDoneAsync(done, ticks, context, executionTree, scope,
|
|
|
2884
2944
|
done(undefined, res);
|
|
2885
2945
|
return;
|
|
2886
2946
|
}
|
|
2887
|
-
if (current
|
|
2947
|
+
if (isLisp(current) && current[0] === 8 /* LispType.Return */) {
|
|
2888
2948
|
done(undefined, new ExecReturn(context.ctx.auditReport, res, true));
|
|
2889
2949
|
return;
|
|
2890
2950
|
}
|
|
@@ -2930,7 +2990,7 @@ function subscribeSet(obj, name, callback, context) {
|
|
|
2930
2990
|
return {
|
|
2931
2991
|
unsubscribe: () => {
|
|
2932
2992
|
callbacks.delete(callback);
|
|
2933
|
-
changeCbs
|
|
2993
|
+
changeCbs?.delete(callback);
|
|
2934
2994
|
}
|
|
2935
2995
|
};
|
|
2936
2996
|
}
|
|
@@ -3152,7 +3212,7 @@ exports.LocalScope = LocalScope;
|
|
|
3152
3212
|
exports.SandboxGlobal = SandboxGlobal;
|
|
3153
3213
|
exports.assignCheck = assignCheck;
|
|
3154
3214
|
exports.asyncDone = asyncDone;
|
|
3155
|
-
exports
|
|
3215
|
+
exports.default = Sandbox;
|
|
3156
3216
|
exports.execAsync = execAsync;
|
|
3157
3217
|
exports.execMany = execMany;
|
|
3158
3218
|
exports.execSync = execSync;
|