poe-code 14.0.63 → 14.0.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +48 -24
- package/dist/index.js.map +3 -3
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-js/dist/chunks/{chunk-KMTTD3BL.js → chunk-3EXDJDQM.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-RU2BCN4G.js → chunk-XO7B4P27.js} +48 -25
- package/packages/safe-js/dist/chunks/chunk-XO7B4P27.js.map +7 -0
- package/packages/safe-js/dist/cli.js +2 -2
- package/packages/safe-js/dist/core.js +1 -1
- package/packages/safe-js/dist/index.js +2 -2
- package/packages/safe-js/dist/interp/interpreter.js +4 -3
- package/packages/safe-js/dist/interp/methods/function.js +32 -15
- package/packages/safe-js/dist/interp/object-model.js +25 -11
- package/packages/safe-js/dist/chunks/chunk-RU2BCN4G.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-KMTTD3BL.js.map → chunk-3EXDJDQM.js.map} +0 -0
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
resolveFsConfig,
|
|
23
23
|
splitFrontmatter,
|
|
24
24
|
withBrokenPipeGuard
|
|
25
|
-
} from "./chunks/chunk-
|
|
25
|
+
} from "./chunks/chunk-3EXDJDQM.js";
|
|
26
26
|
import {
|
|
27
27
|
Budget,
|
|
28
28
|
SandboxError,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
replaceErrorStack,
|
|
35
35
|
restore,
|
|
36
36
|
run
|
|
37
|
-
} from "./chunks/chunk-
|
|
37
|
+
} from "./chunks/chunk-XO7B4P27.js";
|
|
38
38
|
import "./chunks/chunk-UXMKEUH3.js";
|
|
39
39
|
import "./chunks/chunk-5DYEOCT5.js";
|
|
40
40
|
import "./chunks/chunk-4YIDX44G.js";
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
runWithSpawnUsageAccumulator,
|
|
27
27
|
splitFrontmatter,
|
|
28
28
|
supportsSpawnMode
|
|
29
|
-
} from "./chunks/chunk-
|
|
29
|
+
} from "./chunks/chunk-3EXDJDQM.js";
|
|
30
30
|
import {
|
|
31
31
|
Budget,
|
|
32
32
|
FileSnapshotBackend,
|
|
@@ -50,7 +50,7 @@ import {
|
|
|
50
50
|
registerPendingHostCallPolicy,
|
|
51
51
|
restore,
|
|
52
52
|
run
|
|
53
|
-
} from "./chunks/chunk-
|
|
53
|
+
} from "./chunks/chunk-XO7B4P27.js";
|
|
54
54
|
import "./chunks/chunk-UXMKEUH3.js";
|
|
55
55
|
import "./chunks/chunk-5DYEOCT5.js";
|
|
56
56
|
import "./chunks/chunk-4YIDX44G.js";
|
|
@@ -14,7 +14,7 @@ import { CompileScope, RegexCompileGuard } from "./regex/compile-guard.js";
|
|
|
14
14
|
import { createCapturedException, createThrowCompletion, evaluateThrowStatement as evaluateThrowStatementResult, evaluateTryStatement as evaluateTryStatementResult, isCapturedException, isInterpreterError, surfaceThrownValue } from "./exceptions.js";
|
|
15
15
|
import { callArrayMethod, getArrayMember, isArrayMethodName } from "./methods/array.js";
|
|
16
16
|
import { getFunctionMember } from "./methods/function.js";
|
|
17
|
-
import { getBoxedPrototype, getGuestFunctionProperty, getSandboxPrototype, isDefaultBoxedMethod, isGuestClosure, materializeFunctionProperties, setSandboxPrototype } from "./object-model.js";
|
|
17
|
+
import { getBoxedPrototype, getGuestFunctionProperty, getSandboxPrototype, hasExplicitSandboxPrototype, isDefaultBoxedMethod, isGuestClosure, materializeFunctionProperties, setSandboxPrototype } from "./object-model.js";
|
|
18
18
|
import { getStringIndex } from "./methods/string.js";
|
|
19
19
|
import { assertSandboxDataDepth } from "../graph-depth.js";
|
|
20
20
|
import { callMapMethod, getMapMember, isMapMethodName } from "./methods/map.js";
|
|
@@ -2219,8 +2219,9 @@ function hasSandboxProperty(value, key, context) {
|
|
|
2219
2219
|
return hasHostObjectMember(current, key);
|
|
2220
2220
|
if (hasOwnSandboxProperty(current, key, false))
|
|
2221
2221
|
return true;
|
|
2222
|
-
if (
|
|
2223
|
-
|
|
2222
|
+
if (!(isGuestClosure(current) && hasExplicitSandboxPrototype(current)) &&
|
|
2223
|
+
(Array.isArray(current) || !isPlainSandboxObject(current) ||
|
|
2224
|
+
isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current))) {
|
|
2224
2225
|
return getPropertyValue(current, key, context) !== undefined;
|
|
2225
2226
|
}
|
|
2226
2227
|
current = getSandboxPrototype(current, context.budget);
|
|
@@ -1,23 +1,37 @@
|
|
|
1
1
|
import { createSandboxClosure, isSandboxClosure } from "../values.js";
|
|
2
|
-
import { getGuestFunctionProperty, isGuestClosure } from "../object-model.js";
|
|
2
|
+
import { getGuestFunctionProperty, getSandboxPrototype, hasExplicitSandboxPrototype, isGuestClosure, setSandboxPrototype } from "../object-model.js";
|
|
3
|
+
import { assertSandboxDataDepth } from "../../graph-depth.js";
|
|
3
4
|
import { functionString } from "../function-string.js";
|
|
4
5
|
import { runResources } from "../resources.js";
|
|
5
6
|
const functionMethodNames = new Set(["apply", "bind", "call", "toString"]);
|
|
6
7
|
export function getFunctionMember(target, property, options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
let current = target;
|
|
9
|
+
let depth = 0;
|
|
10
|
+
while (current !== null) {
|
|
11
|
+
if (isGuestClosure(current)) {
|
|
12
|
+
const value = getGuestFunctionProperty(current, String(property));
|
|
13
|
+
if (value !== undefined || Object.hasOwn(current.properties ?? {}, String(property)))
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
else if (isSandboxClosure(current)) {
|
|
17
|
+
if (current.properties !== undefined && Object.hasOwn(current.properties, String(property)))
|
|
18
|
+
return current.properties[String(property)];
|
|
19
|
+
if (property === "length")
|
|
20
|
+
return current.length;
|
|
21
|
+
}
|
|
22
|
+
else if (Object.hasOwn(current, String(property))) {
|
|
23
|
+
return current[String(property)];
|
|
24
|
+
}
|
|
25
|
+
if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current))
|
|
26
|
+
break;
|
|
27
|
+
current = getSandboxPrototype(current, options.budget);
|
|
28
|
+
if (current !== null) {
|
|
29
|
+
options.budget?.visitNode();
|
|
30
|
+
assertSandboxDataDepth(++depth);
|
|
31
|
+
}
|
|
20
32
|
}
|
|
33
|
+
if (current === null)
|
|
34
|
+
return undefined;
|
|
21
35
|
if (property === "toString" && runResources.getStore()?.functionSourceText === false)
|
|
22
36
|
return undefined;
|
|
23
37
|
if (!isFunctionMethodName(property)) {
|
|
@@ -44,7 +58,7 @@ function callFunctionMethod(target, methodName, args, options, stack) {
|
|
|
44
58
|
const thisValue = args[0];
|
|
45
59
|
if (methodName === "bind") {
|
|
46
60
|
const boundArgs = args.slice(1);
|
|
47
|
-
|
|
61
|
+
const bound = createSandboxClosure({
|
|
48
62
|
guest: true,
|
|
49
63
|
sandbox: true,
|
|
50
64
|
name: `bound ${target.name ?? ""}`,
|
|
@@ -58,6 +72,9 @@ function callFunctionMethod(target, methodName, args, options, stack) {
|
|
|
58
72
|
construct: (callArgs, context) => options.callClosure(target, [...boundArgs, ...callArgs], context?.stack ?? [], undefined, true)
|
|
59
73
|
})
|
|
60
74
|
});
|
|
75
|
+
if (hasExplicitSandboxPrototype(target))
|
|
76
|
+
setSandboxPrototype(bound, getSandboxPrototype(target, options.budget), options.budget);
|
|
77
|
+
return bound;
|
|
61
78
|
}
|
|
62
79
|
if (methodName === "call") {
|
|
63
80
|
return options.callClosure(target, args.slice(1), stack, thisValue);
|
|
@@ -91,17 +91,26 @@ function registerIntrinsicPrototype(budget, prototype, constructor) {
|
|
|
91
91
|
if (roots === undefined)
|
|
92
92
|
intrinsicPrototypeRoots.set(budget, roots = new Set());
|
|
93
93
|
roots.add(prototype);
|
|
94
|
-
const records = [prototype,
|
|
95
|
-
|
|
94
|
+
const records = [prototype, constructor].map(target => ({
|
|
95
|
+
target,
|
|
96
|
+
value: isGuestClosure(target) ? materializeFunctionProperties(target) : target,
|
|
97
|
+
prototype: getSandboxPrototype(target),
|
|
98
|
+
explicit: hasExplicitSandboxPrototype(target)
|
|
99
|
+
})).map(record => ({
|
|
100
|
+
...record, descriptors: new Map(Object.entries(Object.getOwnPropertyDescriptors(record.value)))
|
|
96
101
|
}));
|
|
97
102
|
const unchanged = (before, after) => before !== undefined && after !== undefined && Object.is(before.value, after.value) &&
|
|
98
103
|
before.writable === after.writable && before.configurable === after.configurable && before.enumerable === after.enumerable;
|
|
99
|
-
intrinsicConstructors.set(constructor, () => records.every(({ value, descriptors }) => {
|
|
104
|
+
intrinsicConstructors.set(constructor, () => records.every(({ target, value, descriptors, prototype: parent, explicit }) => {
|
|
100
105
|
const current = Object.getOwnPropertyDescriptors(value);
|
|
101
|
-
return
|
|
106
|
+
return getSandboxPrototype(target) === parent && hasExplicitSandboxPrototype(target) === explicit &&
|
|
107
|
+
Object.keys(current).length === descriptors.size &&
|
|
102
108
|
Object.keys(current).every(key => unchanged(descriptors.get(key), current[key]));
|
|
103
109
|
}));
|
|
104
|
-
budget.setRetainedValues(prototype, () => records.flatMap(({
|
|
110
|
+
budget.setRetainedValues(prototype, () => records.flatMap(({ target, value, descriptors, prototype: parent }) => [
|
|
111
|
+
...(getSandboxPrototype(target) === parent ? [] : [getSandboxPrototype(target)]),
|
|
112
|
+
...Object.entries(Object.getOwnPropertyDescriptors(value)).flatMap(([key, descriptor]) => unchanged(descriptors.get(key), descriptor) ? [] : [key, descriptor.value])
|
|
113
|
+
]));
|
|
105
114
|
}
|
|
106
115
|
export function releaseObjectPrototype(budget) {
|
|
107
116
|
for (const prototype of intrinsicPrototypeRoots.get(budget) ?? [])
|
|
@@ -118,7 +127,7 @@ export function getSandboxPrototype(value, budget) {
|
|
|
118
127
|
if (prototype !== undefined && prototype !== value)
|
|
119
128
|
return prototype;
|
|
120
129
|
}
|
|
121
|
-
return budget !== undefined && isPrototypeRecord(value)
|
|
130
|
+
return budget !== undefined && !isSandboxClosure(value) && isPrototypeRecord(value)
|
|
122
131
|
? intrinsicPrototypes.get(budget) ?? null
|
|
123
132
|
: null;
|
|
124
133
|
}
|
|
@@ -131,9 +140,12 @@ export function getSandboxDataProperty(value, key, budget) {
|
|
|
131
140
|
while (typeof current === "object" && current !== null) {
|
|
132
141
|
if (isGuestHostObject(current))
|
|
133
142
|
return getHostObjectMember(current, String(key));
|
|
134
|
-
if (isGuestClosure(current))
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
if (isGuestClosure(current)) {
|
|
144
|
+
const entry = getGuestFunctionProperty(current, String(key));
|
|
145
|
+
if (entry !== undefined || Object.hasOwn(current.properties ?? {}, String(key)))
|
|
146
|
+
return entry;
|
|
147
|
+
}
|
|
148
|
+
else if (isSandboxClosure(current)) {
|
|
137
149
|
const properties = current.properties;
|
|
138
150
|
return properties !== undefined && Object.hasOwn(properties, String(key))
|
|
139
151
|
? properties[String(key)]
|
|
@@ -145,7 +157,7 @@ export function getSandboxDataProperty(value, key, budget) {
|
|
|
145
157
|
isSandboxRegex(current) ||
|
|
146
158
|
isSandboxGenerator(current))
|
|
147
159
|
return undefined;
|
|
148
|
-
if (Object.hasOwn(current, String(key)))
|
|
160
|
+
if (!isSandboxClosure(current) && Object.hasOwn(current, String(key)))
|
|
149
161
|
return current[String(key)];
|
|
150
162
|
current = getSandboxPrototype(current, budget);
|
|
151
163
|
if (current !== null) {
|
|
@@ -160,7 +172,7 @@ export function setSandboxPrototype(value, prototype, budget) {
|
|
|
160
172
|
throw new TypeError("Object.prototype has an immutable null prototype.");
|
|
161
173
|
}
|
|
162
174
|
if (!isPrototypeRecord(value) || (prototype !== null && !isPrototypeRecord(prototype))) {
|
|
163
|
-
throw new TypeError("Prototype links require ordinary sandbox objects
|
|
175
|
+
throw new TypeError("Prototype links require ordinary sandbox objects or guest functions.");
|
|
164
176
|
}
|
|
165
177
|
if (prototypes.has(value) && getSandboxPrototype(value, budget) === prototype)
|
|
166
178
|
return;
|
|
@@ -177,6 +189,8 @@ export function setSandboxPrototype(value, prototype, budget) {
|
|
|
177
189
|
prototypes.set(value, prototype);
|
|
178
190
|
}
|
|
179
191
|
function isPrototypeRecord(value) {
|
|
192
|
+
if (isGuestClosure(value))
|
|
193
|
+
return true;
|
|
180
194
|
if (isGuestHostObject(value))
|
|
181
195
|
return false;
|
|
182
196
|
if (isSandboxClosure(value) ||
|