Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toStringTag value on JSG resource types #1607

Merged

Conversation

garrettgu10
Copy link
Contributor

@garrettgu10 garrettgu10 commented Feb 1, 2024

This PR ensures that Object.prototype.toString() returns the correct values for built-in objects (i.e. ResourceTypes).

This means that for instance new Headers().toString() will output [object Headers] instead of [object Object].

@garrettgu10 garrettgu10 requested review from a team as code owners February 1, 2024 23:25
src/workerd/jsg/resource.h Outdated Show resolved Hide resolved
src/workerd/jsg/resource.h Outdated Show resolved Hide resolved
src/workerd/jsg/jsg.h Outdated Show resolved Hide resolved
@dom96
Copy link
Collaborator

dom96 commented Feb 8, 2024

what's the difference between getMemoryName and getName?

@jasnell
Copy link
Member

jasnell commented Feb 8, 2024

what's the difference bretween getMemoryName and getName

jsgGetMemoryName(...) is used while generating the heap snapshot. While for jsg::Object instances its value is currently the same name as the class, it does not need to be and could change in the future. We should not rely on its value for stable user-facing API.

src/workerd/jsg/resource.h Outdated Show resolved Hide resolved
@garrettgu10 garrettgu10 changed the title [do not merge] Add toStringTag value on JSG resource types Add toStringTag value on JSG resource types Feb 16, 2024
@garrettgu10 garrettgu10 requested a review from jasnell February 16, 2024 21:20
@garrettgu10 garrettgu10 merged commit 9c8e3fa into cloudflare:main Feb 20, 2024
11 checks passed
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