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.
@@ -22,7 +22,7 @@ import {
22
22
  resolveFsConfig,
23
23
  splitFrontmatter,
24
24
  withBrokenPipeGuard
25
- } from "./chunks/chunk-KMTTD3BL.js";
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-RU2BCN4G.js";
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";
@@ -5,7 +5,7 @@ import {
5
5
  defineExtension,
6
6
  lint,
7
7
  run
8
- } from "./chunks/chunk-RU2BCN4G.js";
8
+ } from "./chunks/chunk-XO7B4P27.js";
9
9
  import "./chunks/chunk-4YIDX44G.js";
10
10
  export {
11
11
  Budget,
@@ -26,7 +26,7 @@ import {
26
26
  runWithSpawnUsageAccumulator,
27
27
  splitFrontmatter,
28
28
  supportsSpawnMode
29
- } from "./chunks/chunk-KMTTD3BL.js";
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-RU2BCN4G.js";
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 (Array.isArray(current) || !isPlainSandboxObject(current) ||
2223
- isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current)) {
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
- if (isGuestClosure(target)) {
8
- const value = getGuestFunctionProperty(target, String(property));
9
- if (value !== undefined || Object.hasOwn(target.properties ?? {}, String(property)))
10
- return value;
11
- if (!isFunctionMethodName(property))
12
- return undefined;
13
- }
14
- const properties = target.properties;
15
- if (properties !== undefined && Object.hasOwn(properties, String(property))) {
16
- return properties[String(property)];
17
- }
18
- if (property === "length") {
19
- return target.length;
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
- return createSandboxClosure({
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, materializeFunctionProperties(constructor)].map(value => ({
95
- value, descriptors: new Map(Object.entries(Object.getOwnPropertyDescriptors(value)))
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 Object.keys(current).length === descriptors.size &&
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(({ value, descriptors }) => Object.entries(Object.getOwnPropertyDescriptors(value)).flatMap(([key, descriptor]) => unchanged(descriptors.get(key), descriptor) ? [] : [key, descriptor.value])));
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
- return getGuestFunctionProperty(current, String(key));
136
- if (isSandboxClosure(current)) {
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; callable and exotic prototype chains are not supported.");
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) ||