poe-code 13.0.1 → 13.0.2
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/README.md +26 -5
- package/dist/index.js +91 -5
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-js/dist/chunks/{chunk-EL23VF23.js → chunk-JP474LP7.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-DALBPQDZ.js → chunk-RIQRHKCB.js} +82 -4
- package/packages/safe-js/dist/chunks/{chunk-DALBPQDZ.js.map → chunk-RIQRHKCB.js.map} +4 -4
- 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/globals/object-array.js +2 -7
- package/packages/safe-js/dist/interp/interpreter.js +1 -0
- package/packages/safe-js/dist/interp/string-coercion.d.ts +3 -0
- package/packages/safe-js/dist/interp/string-coercion.js +89 -0
- package/packages/safe-js/dist/interp/values.d.ts +1 -0
- /package/packages/safe-js/dist/chunks/{chunk-EL23VF23.js.map → chunk-JP474LP7.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-JP474LP7.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-RIQRHKCB.js";
|
|
38
38
|
import "./chunks/chunk-ZRX5HT5L.js";
|
|
39
39
|
import "./chunks/chunk-WVN5MMDR.js";
|
|
40
40
|
import "./chunks/chunk-4YIDX44G.js";
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
runWithSpawnUsageAccumulator,
|
|
30
30
|
splitFrontmatter,
|
|
31
31
|
supportsSpawnMode
|
|
32
|
-
} from "./chunks/chunk-
|
|
32
|
+
} from "./chunks/chunk-JP474LP7.js";
|
|
33
33
|
import {
|
|
34
34
|
Budget,
|
|
35
35
|
FileSnapshotBackend,
|
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
registerPendingHostCallPolicy,
|
|
52
52
|
restore,
|
|
53
53
|
run
|
|
54
|
-
} from "./chunks/chunk-
|
|
54
|
+
} from "./chunks/chunk-RIQRHKCB.js";
|
|
55
55
|
import "./chunks/chunk-ZRX5HT5L.js";
|
|
56
56
|
import "./chunks/chunk-WVN5MMDR.js";
|
|
57
57
|
import "./chunks/chunk-4YIDX44G.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { sandboxErrorTypes } from "../../error/shape.js";
|
|
2
1
|
import { isFloat32Array } from "../float32.js";
|
|
3
2
|
import { setFloat32Member } from "./float32array.js";
|
|
4
3
|
import { getSandboxIterator } from "../iteration.js";
|
|
4
|
+
import { sandboxString } from "../string-coercion.js";
|
|
5
5
|
import { allocateProducedSandboxValue, createSandboxClosure, deepCopyToSandbox, isSandboxClosure, isSandboxMap, isSandboxPromise, isSandboxRegex, isSandboxSet } from "../values.js";
|
|
6
6
|
export function createObjectArrayGlobals(options) {
|
|
7
7
|
return {
|
|
@@ -91,12 +91,7 @@ export function createObjectArrayGlobals(options) {
|
|
|
91
91
|
}),
|
|
92
92
|
String: createSandboxClosure({
|
|
93
93
|
sandbox: true,
|
|
94
|
-
call: (
|
|
95
|
-
value !== null &&
|
|
96
|
-
sandboxErrorTypes.has(value) &&
|
|
97
|
-
!Object.hasOwn(value, "toString")
|
|
98
|
-
? Error.prototype.toString.call(value)
|
|
99
|
-
: String(value)),
|
|
94
|
+
call: (args, context) => sandboxString(args.length === 0 ? "" : args[0], options.budget, context),
|
|
100
95
|
name: "String",
|
|
101
96
|
properties: {
|
|
102
97
|
raw: createSandboxClosure({
|
|
@@ -2333,6 +2333,7 @@ async function invokeSandboxClosure(callee, args, context, stack, span, thisValu
|
|
|
2333
2333
|
{
|
|
2334
2334
|
stack,
|
|
2335
2335
|
thisValue,
|
|
2336
|
+
invokeClosure: (closure, argumentsList, receiver) => invokeSandboxClosure(closure, argumentsList, context, stack, span, receiver),
|
|
2336
2337
|
...(span === undefined ? {} : { span })
|
|
2337
2338
|
}
|
|
2338
2339
|
]);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { sandboxErrorTypes } from "../error/shape.js";
|
|
2
|
+
import { float32Storage, isFloat32Array } from "./float32.js";
|
|
3
|
+
import { isSandboxClosure, isSandboxPromise } from "./values.js";
|
|
4
|
+
export function sandboxString(value, budget, context, joining = new Set()) {
|
|
5
|
+
if (value === null || typeof value !== "object") {
|
|
6
|
+
if (typeof value === "function")
|
|
7
|
+
throw new TypeError("Expected a sandbox value.");
|
|
8
|
+
return budget.allocateString(String(value));
|
|
9
|
+
}
|
|
10
|
+
return stringifyObject(value, budget, context, joining);
|
|
11
|
+
}
|
|
12
|
+
async function stringifyObject(value, budget, context, joining) {
|
|
13
|
+
const leaveCall = budget.enterCall();
|
|
14
|
+
try {
|
|
15
|
+
budget.visitNode();
|
|
16
|
+
for (const name of ["toString", "valueOf"]) {
|
|
17
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
18
|
+
let result;
|
|
19
|
+
if (descriptor === undefined) {
|
|
20
|
+
if (name === "valueOf")
|
|
21
|
+
continue;
|
|
22
|
+
result = await defaultToString(value, budget, context, joining);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const hook = ownDataValue(value, name);
|
|
26
|
+
if (!isSandboxClosure(hook))
|
|
27
|
+
continue;
|
|
28
|
+
if (context?.invokeClosure === undefined) {
|
|
29
|
+
throw new TypeError("String hooks require a sandbox call context.");
|
|
30
|
+
}
|
|
31
|
+
result = await context.invokeClosure(hook, [], value);
|
|
32
|
+
}
|
|
33
|
+
if (result === null || typeof result !== "object") {
|
|
34
|
+
return sandboxString(result, budget, context, joining);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
throw new TypeError("Cannot convert object to primitive value");
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
leaveCall();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function defaultToString(value, budget, context, joining) {
|
|
44
|
+
if (Array.isArray(value) || isFloat32Array(value)) {
|
|
45
|
+
if (Object.hasOwn(value, "join")) {
|
|
46
|
+
const join = ownDataValue(value, "join");
|
|
47
|
+
if (!isSandboxClosure(join))
|
|
48
|
+
return isFloat32Array(value) ? "[object Float32Array]" : "[object Array]";
|
|
49
|
+
if (context?.invokeClosure === undefined) {
|
|
50
|
+
throw new TypeError("String hooks require a sandbox call context.");
|
|
51
|
+
}
|
|
52
|
+
return context.invokeClosure(join, [], value);
|
|
53
|
+
}
|
|
54
|
+
if (joining.has(value))
|
|
55
|
+
return "";
|
|
56
|
+
joining.add(value);
|
|
57
|
+
try {
|
|
58
|
+
const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
|
|
59
|
+
let text = "";
|
|
60
|
+
for (let index = 0; index < length; index++) {
|
|
61
|
+
budget.visitNode();
|
|
62
|
+
const element = ownDataValue(value, String(index));
|
|
63
|
+
const part = element === null || element === undefined
|
|
64
|
+
? ""
|
|
65
|
+
: await sandboxString(element, budget, context, joining);
|
|
66
|
+
text = budget.allocateString(text + (index === 0 ? "" : ",") + part);
|
|
67
|
+
}
|
|
68
|
+
return text;
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
joining.delete(value);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (sandboxErrorTypes.has(value)) {
|
|
75
|
+
const nameValue = ownDataValue(value, "name");
|
|
76
|
+
const name = nameValue === undefined ? "Error" : await sandboxString(nameValue, budget, context, joining);
|
|
77
|
+
const messageValue = ownDataValue(value, "message");
|
|
78
|
+
const message = messageValue === undefined ? "" : await sandboxString(messageValue, budget, context, joining);
|
|
79
|
+
return name === "" ? message : message === "" ? name : `${name}: ${message}`;
|
|
80
|
+
}
|
|
81
|
+
return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
|
|
82
|
+
}
|
|
83
|
+
function ownDataValue(value, name) {
|
|
84
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
85
|
+
if (descriptor !== undefined && !Object.hasOwn(descriptor, "value")) {
|
|
86
|
+
throw new TypeError("String conversion requires sandbox data properties.");
|
|
87
|
+
}
|
|
88
|
+
return descriptor?.value;
|
|
89
|
+
}
|
|
@@ -49,6 +49,7 @@ export type SandboxCallContext = {
|
|
|
49
49
|
};
|
|
50
50
|
readonly stack: readonly string[];
|
|
51
51
|
readonly thisValue: SandboxValue;
|
|
52
|
+
readonly invokeClosure?: (closure: SandboxClosure, args: readonly SandboxValue[], thisValue: SandboxValue) => Promise<SandboxValue>;
|
|
52
53
|
};
|
|
53
54
|
export type SandboxClosure = {
|
|
54
55
|
readonly async?: true;
|
|
File without changes
|