@objectstack/runtime 12.5.0 → 12.6.0

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/dist/index.js CHANGED
@@ -243,8 +243,20 @@ function installApiMethod(vm, parent, method, objectName, ctx, caps, required, o
243
243
  vm.setProp(parent, method, fn);
244
244
  fn.dispose();
245
245
  }
246
+ function safeJsonStringify(v) {
247
+ const seen = /* @__PURE__ */ new WeakSet();
248
+ const json = JSON.stringify(v ?? null, function(_key, value) {
249
+ if (typeof value === "bigint") return value.toString();
250
+ if (typeof value === "object" && value !== null) {
251
+ if (seen.has(value)) return void 0;
252
+ seen.add(value);
253
+ }
254
+ return value;
255
+ });
256
+ return json ?? "null";
257
+ }
246
258
  function jsonToHandle(vm, v) {
247
- const json = JSON.stringify(v ?? null);
259
+ const json = safeJsonStringify(v);
248
260
  const r = vm.evalCode(`(${json})`);
249
261
  if (r.error) {
250
262
  const msg = vm.dump(r.error);
@@ -254,7 +266,7 @@ function jsonToHandle(vm, v) {
254
266
  return r.value;
255
267
  }
256
268
  function setGlobalJson(vm, name, v) {
257
- const json = JSON.stringify(v ?? null);
269
+ const json = safeJsonStringify(v);
258
270
  const result = vm.evalCode(`(${json})`);
259
271
  if (result.error) {
260
272
  result.error.dispose();
@@ -264,7 +276,7 @@ function setGlobalJson(vm, name, v) {
264
276
  result.value.dispose();
265
277
  }
266
278
  function setObjectJson(vm, parent, key, v) {
267
- const json = JSON.stringify(v ?? null);
279
+ const json = safeJsonStringify(v);
268
280
  const result = vm.evalCode(`(${json})`);
269
281
  if (result.error) {
270
282
  result.error.dispose();