@poe-platform/safe-js 0.1.17 → 0.1.19
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 +17 -1
- package/dist/safe-js/chunks/{chunk-Z3D76J4U.js → chunk-B7H4ZL65.js} +17065 -16803
- package/dist/safe-js/chunks/chunk-B7H4ZL65.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-ZYYMVUYU.js → chunk-GMDOPMVZ.js} +2 -2
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/dist/safe-js/interp/interpreter.d.ts +7 -1
- package/dist/safe-js/interp/patterns.d.ts +24 -0
- package/dist/safe-js/interp/values.d.ts +2 -0
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-Z3D76J4U.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-ZYYMVUYU.js.map → chunk-GMDOPMVZ.js.map} +0 -0
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ console.log(result.returnValue);
|
|
|
32
32
|
## Supported features
|
|
33
33
|
|
|
34
34
|
- **JavaScript control flow:** functions and closures, async/await, loops, destructuring, spread, templates, exceptions, and synchronous generators.
|
|
35
|
+
- **Guest function objects:** own properties on functions and arrows; ordinary constructors with shared prototypes, inherited methods and `instanceof`. `Object.create`, `getPrototypeOf`, `setPrototypeOf`, own-property inspection, and data descriptors work on ordinary sandbox records.
|
|
35
36
|
- **Data processing:** arrays, objects, strings, numbers, JSON, Math, Map, Set, Float32Array, promises, and a bounded regular-expression subset. These are selected APIs, not complete ECMAScript implementations.
|
|
36
37
|
- **Explicit capabilities:** named, default, and namespace imports resolve against host-supplied modules. Optional helpers cover agents, MCP tools, files, environment reads, time, logging, and metrics.
|
|
37
38
|
- **Execution controls:** step, call-depth, string, array, and retained-data budgets; an absolute deadline; host cancellation; console and telemetry sinks.
|
|
@@ -40,6 +41,19 @@ console.log(result.returnValue);
|
|
|
40
41
|
|
|
41
42
|
Scripts have no ambient `process`, `require`, `fetch`, or filesystem access. Host functions still execute with the host's privileges. Register only the capabilities the script needs; this is not OS or process isolation.
|
|
42
43
|
|
|
44
|
+
```js
|
|
45
|
+
const result = await run(`
|
|
46
|
+
function Counter(value) { this.value = value; }
|
|
47
|
+
Counter.label = "counter";
|
|
48
|
+
Counter.prototype.read = function () { return this.value; };
|
|
49
|
+
const counter = new Counter(7);
|
|
50
|
+
return [Counter.label, counter.read(), counter instanceof Counter];
|
|
51
|
+
`, { budget: new Budget({ maxSteps: 10_000 }) });
|
|
52
|
+
// result.returnValue: ["counter", 7, true]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Properties stay inside the interpreter, not on native host functions. Arrows and object methods remain nonconstructible. Prototype links between callable or exotic objects (such as arrays) and accessor descriptors are unsupported; native `Function.prototype` is never exposed.
|
|
56
|
+
|
|
43
57
|
## Add a host capability
|
|
44
58
|
|
|
45
59
|
Expose a small module rather than an entire application client:
|
|
@@ -162,6 +176,8 @@ Factories return exports to register in `modules`; calling a factory alone does
|
|
|
162
176
|
<details>
|
|
163
177
|
<summary>Checkpoints and recovery</summary>
|
|
164
178
|
|
|
179
|
+
Guest functions with materialized own-property state, prototype-linked objects, and custom data descriptors are not portable checkpoint data. Dump, restore, and replay serialization reject these values instead of silently discarding their state. Data-copy boundaries also reject prototype-linked objects and custom descriptors; pass a plain projection such as `{ value: counter.value }` to host operations. Bridged callbacks retain their function identity and properties while the run is alive.
|
|
180
|
+
|
|
165
181
|
- `dump(resultOrRunningPromise, { mode?, onFailure? })` returns checkpoint JSON. `mode` is `capture` or `replay`; `onFailure` is `throw` or `checkpoint`.
|
|
166
182
|
- `restore(snapshot, { source })` validates state for compatible source; pass it as `run`'s `snapshot` option. It does not run the program.
|
|
167
183
|
- `new FileSnapshotBackend(path, { writeMaxAttempts?, writeRetryDelayMs? })` defaults to 3 write attempts and a 100 ms retry delay.
|
|
@@ -199,7 +215,7 @@ For embedding, `runCli(argv, options?)` comes from `@poe-platform/safe-js/cli`.
|
|
|
199
215
|
|
|
200
216
|
## Meaningful limitations
|
|
201
217
|
|
|
202
|
-
- **Not a full JavaScript engine.** No user-defined classes
|
|
218
|
+
- **Not a full JavaScript engine.** No user-defined classes, async generators, dynamic imports, or automatic multi-file/npm resolution. No browser build, DOM, general Node API, `eval`, or `Function` constructor. Ordinary guest constructor prototypes are supported, but native and exotic prototype chains are not. Built-in coverage is selective; lint success is not a runtime compatibility guarantee.
|
|
203
219
|
- **Some familiar syntax differs.** Binary `in` is unsupported; use `Object.hasOwn(object, key)` for own-property checks. Regex supports `g`, `i`, `m`, and `s`, but not lookaround, backreferences, named groups, Unicode property escapes, or other flags. Compilation and matching have fixed limits in addition to configured budgets.
|
|
204
220
|
- **Budgets are not hard resource isolation.** Limits govern interpreter work, not arbitrary host functions or total process memory. Deadlines are checked cooperatively; cancellation cannot forcibly stop a blocking host call or undo its effects. Add host-operation timeouts and external isolation where required.
|
|
205
221
|
- **Recovery is not exactly-once delivery.** Replay can repeat work and consumes budget again. Pending side effects need external reconciliation; opaque host handles and native iterator frames are not portable checkpoint state. Keep compatible source for ordinary restore or explicitly migrate. Checkpoints can contain input data and host results: store them as sensitive data.
|