@poe-platform/safe-js 0.1.391 → 0.1.393

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-2H5CQNFL.js";
25
+ } from "./chunks/chunk-CTMJJJQL.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-MT4D4J5E.js";
37
+ } from "./chunks/chunk-UDQ7HBDC.js";
38
38
  import "./chunks/chunk-4YIDX44G.js";
39
39
 
40
40
  // packages/safe-js/src/cli.ts
@@ -5,7 +5,7 @@ import {
5
5
  defineExtension,
6
6
  lint,
7
7
  run
8
- } from "./chunks/chunk-MT4D4J5E.js";
8
+ } from "./chunks/chunk-UDQ7HBDC.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-2H5CQNFL.js";
29
+ } from "./chunks/chunk-CTMJJJQL.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-MT4D4J5E.js";
53
+ } from "./chunks/chunk-UDQ7HBDC.js";
54
54
  import "./chunks/chunk-4YIDX44G.js";
55
55
 
56
56
  // packages/safe-js/src/parse.ts
@@ -29,6 +29,7 @@ export type GeneratorExpressionState<T = SandboxValue, S = Scope, I = SandboxIte
29
29
  current: T;
30
30
  referenceObject?: T;
31
31
  referenceKey?: T;
32
+ privateName?: string;
32
33
  } | {
33
34
  kind: "array-pattern";
34
35
  phase: "reference" | "binding";
@@ -38,6 +39,7 @@ export type GeneratorExpressionState<T = SandboxValue, S = Scope, I = SandboxIte
38
39
  iterator: I;
39
40
  referenceObject?: T;
40
41
  referenceKey?: T;
42
+ privateName?: string;
41
43
  } | {
42
44
  kind: "for-of-array";
43
45
  phase: "left" | "body";
@@ -83,6 +85,7 @@ export type GeneratorExpressionState<T = SandboxValue, S = Scope, I = SandboxIte
83
85
  current: T;
84
86
  key?: T;
85
87
  superReceiver?: T;
88
+ privateName?: string;
86
89
  } | {
87
90
  kind: "template";
88
91
  prefix: string;
@@ -8,6 +8,7 @@ type Pattern = VariableDeclarator["id"] | AssignmentPattern | MemberExpression |
8
8
  export type AssignmentReference = {
9
9
  object: SandboxValue;
10
10
  key: PropertyKey;
11
+ privateName?: string;
11
12
  };
12
13
  export type PatternTarget = {
13
14
  kind: VariableDeclarationKind;
@@ -31,6 +32,7 @@ export type PatternContext = {
31
32
  toPropertyKey(value: SandboxValue): string | symbol | Promise<string | symbol>;
32
33
  getProperty(value: SandboxValue, key: PropertyKey): SandboxValue | Promise<SandboxValue>;
33
34
  setProperty(target: SandboxValue, key: PropertyKey, value: SandboxValue): void | Promise<void>;
35
+ setPrivateProperty?(target: SandboxValue, name: string, value: SandboxValue): void | Promise<void>;
34
36
  };
35
37
  export type BindPatternResult = {
36
38
  ok: true;
@@ -0,0 +1,18 @@
1
+ import type { SandboxClosure, SandboxValue } from "./values.js";
2
+ export type PrivateName = {
3
+ readonly description: string;
4
+ };
5
+ export type PrivateElement = {
6
+ kind: "field";
7
+ value: SandboxValue;
8
+ } | {
9
+ kind: "method";
10
+ value: SandboxClosure;
11
+ } | {
12
+ kind: "accessor";
13
+ get?: SandboxClosure;
14
+ set?: SandboxClosure;
15
+ };
16
+ export declare const privateElements: WeakMap<object, Map<PrivateName, PrivateElement>>;
17
+ export declare function findPrivateElement(receiver: SandboxValue, name: PrivateName): PrivateElement | undefined;
18
+ export declare function addPrivateElement(receiver: SandboxValue, name: PrivateName, element: PrivateElement): void;
@@ -1,4 +1,5 @@
1
1
  import type { VariableDeclarationKind } from "../parse.js";
2
+ import type { PrivateName } from "./private-state.js";
2
3
  import type { InterpreterSnapshot, InterpreterValue } from "./interpreter.js";
3
4
  type ScopeLookupResult = {
4
5
  found: true;
@@ -12,6 +13,7 @@ type ScopeOptions = {
12
13
  chargeData?: boolean;
13
14
  };
14
15
  export type ScopeFrame = {
16
+ privateNames?: Array<[string, PrivateName]>;
15
17
  parent?: Scope;
16
18
  importMeta?: InterpreterValue;
17
19
  functionBoundary: boolean;
@@ -32,8 +34,11 @@ export declare class Scope {
32
34
  private readonly parent?;
33
35
  private importMeta?;
34
36
  private readonly options;
37
+ privateNames?: Map<string, PrivateName>;
35
38
  constructor(bindings?: Record<string, InterpreterValue>, parent?: Scope | undefined, importMeta?: InterpreterValue, options?: ScopeOptions, restoredBindings?: Record<string, InterpreterValue>);
36
39
  child(bindings?: Record<string, InterpreterValue>, options?: ScopeOptions): Scope;
40
+ declarePrivateName(description: string): PrivateName;
41
+ resolvePrivateName(description: string): PrivateName;
37
42
  consumeRestoredBinding(name: string): {
38
43
  found: true;
39
44
  value: InterpreterValue;
@@ -4,4 +4,4 @@ export type FunctionSource = {
4
4
  readonly start: number;
5
5
  readonly end: number;
6
6
  };
7
- export declare const functionSources: WeakMap<FunctionNode | ClassNode, FunctionSource>;
7
+ export declare const functionSources: WeakMap<ClassNode | FunctionNode, FunctionSource>;
@@ -19,6 +19,10 @@ export type Identifier = BaseNode & {
19
19
  type: "Identifier";
20
20
  name: string;
21
21
  };
22
+ export type PrivateIdentifier = BaseNode & {
23
+ type: "PrivateIdentifier";
24
+ name: string;
25
+ };
22
26
  export type ThisExpression = BaseNode & {
23
27
  type: "ThisExpression";
24
28
  };
@@ -397,7 +401,7 @@ export type ArrowFunctionExpression = BaseNode & {
397
401
  params: Array<AssignmentPattern | ArrayPattern | Identifier | ObjectPattern | RestElement>;
398
402
  };
399
403
  export type FunctionNode = ArrowFunctionExpression | FunctionDeclaration | FunctionExpression;
400
- export type Expression = ArrowFunctionExpression | AssignmentExpression | ArrayExpression | AwaitExpression | BinaryExpression | BooleanLiteral | CallExpression | ConditionalExpression | ClassExpression | FunctionExpression | Identifier | LogicalExpression | MemberExpression | MetaProperty | NewExpression | NewTargetExpression | NullLiteral | NumericLiteral | BigIntLiteral | ObjectExpression | RegexLiteral | SequenceExpression | StringLiteral | SuperExpression | TaggedTemplateExpression | TemplateLiteral | ThisExpression | UnaryExpression | UpdateExpression | UndefinedLiteral | YieldExpression;
404
+ export type Expression = ArrowFunctionExpression | AssignmentExpression | ArrayExpression | AwaitExpression | BinaryExpression | BooleanLiteral | CallExpression | ConditionalExpression | ClassExpression | FunctionExpression | Identifier | PrivateIdentifier | LogicalExpression | MemberExpression | MetaProperty | NewExpression | NewTargetExpression | NullLiteral | NumericLiteral | BigIntLiteral | ObjectExpression | RegexLiteral | SequenceExpression | StringLiteral | SuperExpression | TaggedTemplateExpression | TemplateLiteral | ThisExpression | UnaryExpression | UpdateExpression | UndefinedLiteral | YieldExpression;
401
405
  export type ParseResult = Expression | Statement;
402
406
  export declare function parse(source: string, filename?: string, owner?: CompileOwner): ParseResult;
403
407
  export declare function parseModule(source: string, filename?: string, owner?: CompileOwner): Module;
@@ -4,7 +4,7 @@ export type Position = {
4
4
  column: number;
5
5
  offset: number;
6
6
  };
7
- export type TokenType = "identifier" | "keyword" | "numeric" | "regex" | "string" | "template" | "punctuator" | "eof";
7
+ export type TokenType = "identifier" | "private-identifier" | "keyword" | "numeric" | "regex" | "string" | "template" | "punctuator" | "eof";
8
8
  export type Token = {
9
9
  type: TokenType;
10
10
  value: string;
@@ -1,4 +1,4 @@
1
- import type { GuestObjectState } from "./guest-heap.js";
1
+ import { type GuestObjectState } from "./guest-heap.js";
2
2
  import type { Budget } from "../interp/budget.js";
3
3
  export type ArrayBufferData<TReference> = {
4
4
  kind: "arraybuffer";
@@ -1,4 +1,4 @@
1
- import type { GuestObjectState } from "./guest-heap.js";
1
+ import { type GuestObjectState } from "./guest-heap.js";
2
2
  import type { Budget } from "../interp/budget.js";
3
3
  export type DataViewData<T> = {
4
4
  kind: "dataview";
@@ -3,6 +3,7 @@ import { type CollectionIterationMethod } from "../interp/collection-iterator.js
3
3
  import { type IteratorHelperState } from "../interp/iterator-helper.js";
4
4
  import { type ScopeFrame } from "../interp/scope.js";
5
5
  import { type PropertyDescriptorData } from "./property-descriptors.js";
6
+ import { type PrivateName, type PrivateElement } from "../interp/private-state.js";
6
7
  import type { CompletionResult } from "../interp/exceptions.js";
7
8
  import type { GeneratorExpressionState } from "../interp/generator-expression-state.js";
8
9
  import { type IteratorSnapshot } from "../interp/iteration.js";
@@ -14,8 +15,37 @@ export type GeneratorFinallyCompletion<T> = Omit<CompletionResult, "value" | "no
14
15
  export type GuestObjectState<T> = {
15
16
  properties: PropertyDescriptorData<T>;
16
17
  prototype?: T;
18
+ privateElements?: PrivateElementData<T>[];
17
19
  };
20
+ export type PrivateElementData<T> = {
21
+ name: T;
22
+ } & ({
23
+ kind: "field" | "method";
24
+ value: T;
25
+ } | {
26
+ kind: "accessor";
27
+ get: T;
28
+ set: T;
29
+ });
18
30
  export type GuestHeapNode<T> = {
31
+ kind: "guest-regex";
32
+ source: string;
33
+ flags: string;
34
+ state: GuestObjectState<T>;
35
+ } | {
36
+ kind: "guest-promise";
37
+ status: "fulfilled" | "rejected";
38
+ value: T;
39
+ state: GuestObjectState<T>;
40
+ } | {
41
+ kind: "guest-boxed";
42
+ value: T;
43
+ state: GuestObjectState<T>;
44
+ } | {
45
+ kind: "guest-date";
46
+ value: T;
47
+ state: GuestObjectState<T>;
48
+ } | {
19
49
  kind: "iterator-helper";
20
50
  method: IteratorHelperState["method"];
21
51
  status: "start" | "yield" | "done";
@@ -82,18 +112,22 @@ export type GuestHeapNode<T> = {
82
112
  fields: Array<{
83
113
  index: number;
84
114
  key: T;
115
+ privateName?: T;
85
116
  }>;
117
+ privateMethods?: PrivateElementData<T>[];
86
118
  state: GuestObjectState<T>;
87
119
  } | {
88
120
  kind: "map";
89
121
  entries: Array<[T, T]>;
90
122
  propertyState?: PropertyDescriptorData<T>;
91
123
  prototype?: T;
124
+ privateElements?: PrivateElementData<T>[];
92
125
  } | {
93
126
  kind: "set";
94
127
  values: T[];
95
128
  propertyState?: PropertyDescriptorData<T>;
96
129
  prototype?: T;
130
+ privateElements?: PrivateElementData<T>[];
97
131
  } | {
98
132
  kind: "raw-json";
99
133
  text: string;
@@ -147,6 +181,7 @@ export type GuestHeapNode<T> = {
147
181
  importMeta: T;
148
182
  functionBoundary: boolean;
149
183
  chargeData: boolean;
184
+ privateNames?: Array<[string, T]>;
150
185
  bindings: Array<[string, number]>;
151
186
  cells: Array<{
152
187
  kind: ScopeFrame["cells"][number]["kind"];
@@ -159,3 +194,4 @@ export type GuestHeapNode<T> = {
159
194
  restoredBindings?: Array<[string, T]>;
160
195
  };
161
196
  export declare function captureGuestHeapNode<T>(value: object, encode: (value: unknown) => T): GuestHeapNode<T> | undefined;
197
+ export declare function capturePrivateElements<T>(elements: Map<PrivateName, PrivateElement>, encode: (value: unknown) => T): PrivateElementData<T>[];
@@ -1,5 +1,5 @@
1
1
  import { numericTypedArrayConstructors, type NumericTypedArray } from "../interp/typed-array.js";
2
- import type { GuestObjectState } from "./guest-heap.js";
2
+ import { type GuestObjectState } from "./guest-heap.js";
3
3
  import type { Budget } from "../interp/budget.js";
4
4
  export declare function captureTypedArrayState<T>(value: NumericTypedArray, encode: (value: unknown) => T): GuestObjectState<T>;
5
5
  export declare function restoreTypedArrayProperties<T>(value: NumericTypedArray, state: GuestObjectState<T>, decode: (value: T) => unknown): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-js",
3
- "version": "0.1.391",
3
+ "version": "0.1.393",
4
4
  "description": "Budgeted JavaScript interpreter with explicit host capabilities and resumable execution",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@poe-platform/safe-fs": "0.1.391",
61
+ "@poe-platform/safe-fs": "0.1.393",
62
62
  "@petamoriken/float16": "^3.9.3",
63
63
  "yaml": "^2.8.2",
64
64
  "jose": "^6.1.3",