(value: unknown, seen: WeakSet<object>)
| 258 | } |
| 259 | |
| 260 | function assertValue(value: unknown, seen: WeakSet<object>): void { |
| 261 | if (value === null || typeof value === "boolean" || typeof value === "string") return; |
| 262 | if (typeof value === "number" && Number.isFinite(value)) return; |
| 263 | if (typeof value !== "object") { |
| 264 | throw new Error("Workspace code inputs and results must be JSON-compatible values."); |
| 265 | } |
| 266 | if (seen.has(value)) throw new Error("Workspace code inputs and results cannot contain cycles."); |
| 267 | seen.add(value); |
| 268 | if (Array.isArray(value)) { |
| 269 | for (const item of value) assertValue(item, seen); |
| 270 | seen.delete(value); |
| 271 | return; |
| 272 | } |
| 273 | const prototype = Object.getPrototypeOf(value); |
| 274 | if (prototype !== Object.prototype && prototype !== null) { |
| 275 | throw new Error("Workspace code inputs and results must use plain objects."); |
| 276 | } |
| 277 | for (const item of Object.values(value)) assertValue(item, seen); |
| 278 | seen.delete(value); |
| 279 | } |
no test coverage detected