`{ ..."ab" }` is `{}`; a throw in a `for await` body does not wait for the iterator's return()

Open
#611 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, javascript
Domain
backend, compilers

Research direction

Start by reading the object spread path and JS_CopyDataProperties, then trace how the source is converted before its properties are copied. For the for await case, follow AsyncIteratorClose and its handling of throw completions. Use the two reproductions in the issue to check both behaviors; done means string properties are copied and iterator cleanup finishes before the catch runs.

Written by the indexing model from the issue text.

Description

1. Object spread of a string primitive copies nothing.

console.log(JSON.stringify({ ..."ab" }));                  // {"0":"a","1":"b"}
console.log(JSON.stringify({ ...new String("ab") }));      // {"0":"a","1":"b"}

./qjs t.js prints {} for the first line; the second is correct, and so are Object.assign({}, "ab") and const {...r} = "ab". JS_CopyDataProperties returns early when the source is not an object, and the object-literal spread path doesn't convert the source with ToObject first.

2. A throw in a for await body doesn't await return().

const log = [];
async function* g() { try { yield 1; } finally { log.push("finally"); } }
(async () => {
  try { for await (const v of g()) throw "t"; } catch (e) { log.push("catch"); }
  console.log(log.join(" "));   // expected: finally catch
})();

Actual: catch (the finally runs later). With break instead of throw master is correct; the 2026-06-04 release gets both wrong. AsyncIteratorClose awaits the result of return() even when the completion is a throw.

Versions: master e5ac135 (2026-11-09) and release 2026-06-04, Linux x86-64.

Credit: https://ucsbplse.github.io/

Dominant language
C
Stars
11.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bellard/quickjs

All issues in bellard/quickjs

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.