Skip to content

evalCode returns "[object Object]" for large objects when memory limit is set #241

Closed

Description

@justinbot

When a memory limit is set, objects with properties larger than a certain threshold (but still within the memory limit) will start to be output as the string "[object Object]".

The threshold where this starts happening appears to scale with memory limit, for example:

  • With memory limit 100_000
    • Property length 50_000 -> Works as expected
    • Property length 70_000 -> "[object Object]"
  • With memory limit 200_000
    • Property length 70_000 -> Works as expected
    • Property length 140_000 -> "[object Object]"

Can be reproduced with this example on quickjs-emscripten 0.31.0

import { getQuickJS } from "quickjs-emscripten";

async function main() {
  const QuickJS = await getQuickJS();
  const vm = QuickJS.newContext();

  // Set a memory limit
  vm.runtime.setMemoryLimit(100_000);

  const result = vm.evalCode('const test = { eg: "a".repeat(70_000) }; test;');
  if (result.error) {
    console.log("Execution failed:", JSON.stringify(vm.dump(result.error)));
    result.error.dispose();
  } else {
    console.log("Success:", JSON.stringify(vm.dump(result.value)));
    result.value.dispose();
  }

  vm.dispose();
}

main();

Activity

  1. justjake commented on Feb 16, 2026

    @justjake
    Owner

    vm.dump is respecting your memory limit. If you don't have enough memory to perform JSON conversion, then it will fall back to doing essentially String(value); it falls back to String(value) when it encounters any error converting to JSON.

    You can either expand/disable the memory limit around calls to vm.dump, or you can inspect the returned QuickJSHandle directly and use native iteration over its properties instead of serializing (so you use O(1) memory per call) the entire value at once (using another O(N) memory)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions