console.log("%s=%d", "x", 5) prints "%s=%d x 5" instead of "x=5": Console Formatter (format specifiers) not implemented

Aperta
#358 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, wasm
Ambito
api, backend

Direzione di ricerca

Read builtins/web/console.cpp, especially console_out and the existing to-source logic, then compare its behavior with the Console Standard Formatter steps cited in the issue. Implement the described formatting for the listed specifiers and run the console tests covering formatted arguments. Done means the reproduction prints the expected formatted output, including consuming the %c argument.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

console.log and friends never apply the Console Standard's Formatter, so %s, %d/%i, %f, %o/%O and %c
are printed literally and the arguments are appended after them. Browsers and node substitute them.

Environment

  • StarlingMonkey v0.4.0 release starling.wasm, wasmtime 50.0.1 (wasmtime run -S http --dir . starling.wasm --legacy-script repro.js).
  • builtins/web/console.cpp is unchanged on main (54b3329b).
  • Checked on 2026-11-03. Reference: node v26.13.0.

Reproduction

console.log("%s=%d", "x", 5);
console.log("%i|%f", 3.9, "2.5");
console.log("%o and %O", { a: 1 }, [1]);
console.log("%c styled", "color: red");
StarlingMonkey expected (node)
line 1 Log: %s=%d x 5 x=5
line 2 Log: %i|%f 3.9 2.5 3|2.5
line 3 Log: %o and %O { a: 1 } [1] { a: 1 } and [ 1 ]
line 4 Log: %c styled color: red styled (the %c argument is consumed)

Spec

Console Standard, Logger, step 5: "Otherwise, perform Printer(logLevel,
Formatter(args))". Formatter replaces the first specifier in the first
argument with the converted next argument and recurses:

  • %s: %String%(arg)
  • %d / %i: %parseInt%(arg, 10) (NaN for a Symbol)
  • %f: %parseFloat%(arg) (NaN for a Symbol)
  • %o / %O: the argument with object formatting
  • %c: CSS in browsers; runtimes without styling consume the argument and print nothing for it

Printer is implementation-defined, but Formatter is not.

Cause

In builtins/web/console.cpp, console_out converts every argument with the existing to-source logic and joins
them with spaces. Formatter is never applied. (Comments near console.assert/console.trace already mention "a
string without any formatting specifiers".)

Suggested fix

When the first argument is a string and more arguments follow, walk it once, replace each specifier with the
converted next argument (reusing the existing to-source code for %o/%O, dropping the argument for %c), then
append the remaining arguments as today. ComponentizeJS only replaces the final print hook, so it gets the fix
automatically.

Lingua principale
C
Stelle
297
Fork
64
Merge medio
1g 17h
PR unite (30g)
16

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bytecodealliance/StarlingMonkey

Tutte le issue di bytecodealliance/StarlingMonkey

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.