Skip to content

Convert console.count() and console.time() labels to strings - #8843

Merged
littledivy merged 2 commits into
mainfrom
littledivy/2026-11-23-wpt-console-labels
Nov 26, 2026
Merged

littledivy merged 2 commits into
mainfrom
littledivy/2026-11-23-wpt-console-labels

Conversation

@littledivy

@littledivy littledivy commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

console.count(), countReset(), time(), timeLog() and timeEnd() are V8's builtins. They hand the label to the inspector's console delegate and never look at it otherwise. Without an inspector, an object label's toString() is never called, and a label whose conversion throws, such as a Symbol, is silently accepted. With an inspector, the delegate converts the label but drops the error. The Console spec converts the label to a string first and rethrows, which accounts for the 10 expected failures in WPT's console-label-conversion.any.js.

In this patch setupContext wraps those five methods. The wrapper converts any label other than undefined with ToString(), rethrows what that throws, and then calls the builtin with the string and the other arguments unchanged. The builtin is kept as the wrapper's function data, and the wrapper is registered as an external reference so it survives the startup snapshot.

There is no compat flag. What a Worker can see: toString() is now called on object labels, and console.count(Symbol()), or any label whose toString() throws, now throws instead of doing nothing. Browsers and Node.js already behave this way, so portable code expects it.

console-label-conversion-test covers each of the five methods with an object label, a throwing toString(), a Symbol, no label and extra arguments. It fails without the fix, and so does //src/wpt:console@, which has no expected failures left for this file.

@littledivy
littledivy requested review from a team as code owners November 24, 2026 03:08

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 2944ba2a.

This review, of 5a708a80

✅ Approved — I found no issues: the label conversion is correct, sits behind a new compatibility flag, survives the startup snapshot, and is tested with the flag on and off.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

The wrapper leaves conversion errors pending and returns, forwards the other arguments unchanged, and keeps the builtin as the function's data. It is installed after the existing guard in setupContext and registered as an external reference. The flag ordinal and names match the tests and the WPT config.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The flag's doc comment describes the current behaviour with and without the flag.


Reviewed commit: 5a708a80

@littledivy
littledivy force-pushed the littledivy/2026-11-23-wpt-console-labels branch from 5a708a8 to 2944ba2 Compare November 24, 2026 03:22

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 169acfae.

This review, of 2944ba2a

✅ Approved — No issues found. The label conversion is correct, sits behind a new compatibility flag, survives the startup snapshot and is tested with the flag on and off; the only change since the last review is a comment fix.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns. When ToString throws, the wrapper makes no further V8 calls that take a context, so the exception keeps propagating.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

The ConsoleMethod comment now matches the code.

  • The label wrapper leaves conversion errors pending and returns.
  • It forwards this and the other arguments unchanged.
  • It keeps the builtin as the function's data.
  • It is registered as an external reference and installed only after the existing guard.

The flag names match the tests and the WPT config.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The flag's doc comment describes the current behaviour with and without the flag.


Reviewed commit: 2944ba2a

@littledivy
littledivy force-pushed the littledivy/2026-11-23-wpt-console-labels branch from 2944ba2 to 169acfa Compare November 25, 2026 15:00

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 24cb3660.

This review, of 169acfae

✅ Approved — No issues found. The label conversion sits behind a new compatibility flag, survives the startup snapshot and is tested with the flag on and off. The only change since the last review is a doc comment fix.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns. When ToString throws, the wrapper makes no further V8 calls that take a context, so the exception keeps propagating.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

No issues found. Checked at this commit:

  • Compat flag: consoleLabelConversion @211 takes the next free ordinal.
  • Wrapper: consoleLabelDecorator converts the label with ToString. If that throws, it returns right away without making further V8 calls, so the exception keeps propagating. It forwards this and the other arguments unchanged and keeps the builtin as its function data.
  • Snapshot and install order: the wrapper is registered as an external reference, so it survives the startup snapshot, and it is installed only after the existing guard in setupContext.
  • Tests: they cover all five methods with the flag on and off. The WPT config turns the flag on and drops the expected failures.

⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The flag's doc comment describes how the methods behave with and without the flag.


Reviewed commit: 169acfae

@jasnell

jasnell commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

I'd be shocked if this actually broke anything in production. Probably ok to change without the compat flag, to be honest, but don't feel strongly either way.

console.count(), countReset(), time(), timeLog() and timeEnd() are V8's
builtins. They pass the label to the inspector's console delegate and
never look at it otherwise, so without an inspector an object label's
toString() is never called, and a label whose conversion throws, such as
a Symbol, is silently accepted. With an inspector the delegate converts
the label but drops the error. The Console spec converts the label to a
string first and rethrows.

In this patch setupContext wraps those five methods. The wrapper
converts a label that isn't undefined with ToString(), rethrowing what
it throws, then calls the builtin with the string and the other
arguments unchanged.

There is no compat flag. What a Worker can see: toString() is now called
on object labels, and console.count(Symbol()) or a label whose
toString() throws now throws instead of doing nothing. Browsers and
Node.js already behave this way, so portable code expects it.
console-label-conversion-test runs count, countReset, time, timeLog and
timeEnd with an object label, a throwing toString(), a Symbol, no label
and extra arguments. It fails without the previous commit.

The 10 expected failures in WPT's console-label-conversion.any.js are
removed.
@littledivy
littledivy force-pushed the littledivy/2026-11-23-wpt-console-labels branch from 169acfa to 24cb366 Compare November 26, 2026 08:32

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — No issues found. The wrapper rethrows conversion errors correctly, survives the startup snapshot and is tested on all five methods, and the commit message records the decision to ship without a compat flag.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns. When ToString throws, the wrapper makes no further V8 calls that take a context.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

Checked at this commit:

  • Wrapper: If ToString throws, consoleLabelDecorator returns right away without making further V8 calls, so the exception keeps propagating. A missing or undefined label reaches the builtin unchanged, as do this and the other arguments.
  • Snapshot and install order: &consoleLabelDecorator is registered as an external reference. The wrapper is installed after the existing early-return guard in setupContext, and SetName keeps each method's name intact.
  • Compatibility: The change has no compat flag. The commit message of 8c0d8ab explicitly accepts that risk and describes what Worker code can observe, which is what the backward-compatibility rules ask for.
  • Tests: They cover all five methods with an object label, a throwing toString(), a Symbol, no label and extra arguments. The WPT expected failures for console-label-conversion.any.js are removed.

⚡ Performance: ✅ LGTM

Each call to one of the five label methods costs one ToString and one extra call. These methods are not hot paths, and the wrappers are installed once per context.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 24cb3660

@littledivy

Copy link
Copy Markdown
Member Author

Removed the compat flag.

@littledivy
littledivy merged commit 59b512f into main Nov 26, 2026
25 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-23-wpt-console-labels branch November 26, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants