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

Log all accesses to toStringTag #1674

Closed
wants to merge 1 commit into from

Conversation

garrettgu10
Copy link
Contributor

@garrettgu10 garrettgu10 commented Feb 15, 2024

One of the questions brought up in #1607 is whether or not the change would be breaking, so we wanted to get some visibility into how many workers actually use the toStringTag property on built-in objects (i.e. ResouceTypes). This would allow us to find out if a worker is getting or setting the property.

Open questions:

  • Not sure how to make the accessors simply set and get the actual property on the object, so I currently patch them through to a string property. I don't think this is best practice, and the ugly internal string property does show up when I console.log() the object.
  • Is this the right level/type of logging we want for this?

@garrettgu10 garrettgu10 requested review from a team as code owners February 15, 2024 18:57
@garrettgu10 garrettgu10 requested review from dom96 and jasnell February 15, 2024 18:57

static void setAndLogToStringTag(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info){
LOG_ERROR_PERIODICALLY("toStringTag has been set");
auto isolate = info.GetIsolate();
Copy link
Member

Choose a reason for hiding this comment

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

For this it would be simpler just to store the given value within a jsg::Value member field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally tried doing that, but I couldn't get access to the ResourceTypeBuilder instance from within this function, since I need to be able to give a pointer to it to SetAccessor. Any suggestions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I think we would have to use the object itself to store the property, since we would want two objets to have separate toStringTags even if they share a single ObjectTemplate.

@kentonv
Copy link
Member

kentonv commented Feb 15, 2024

What's the motivation for this? (This should be included in the PR and commit descriptions.)

@garrettgu10
Copy link
Contributor Author

What's the motivation for this? (This should be included in the PR and commit descriptions.)

My bad, I'll add it in.

One of the questions brought up in #1607 is whether or not the change would be breaking, so we wanted to get some visibility into how many workers actually use the toStringTag property on built-in objects (i.e. ResouceTypes). This would allow us to find out if a worker is getting or setting the property.

@garrettgu10 garrettgu10 requested a review from jasnell February 15, 2024 22:37
@kentonv
Copy link
Member

kentonv commented Feb 15, 2024

Ah, I see.

My opinion: I don't think we should worry about it. This is like worrying that adding a new method to an existing API could beak someone, because they might be checking for the existence of that method. It's extremely unlikely, and if we worry about stuff like that we'll never get anything done. So I'd say it's fine to proceed without this logging change and without a compat flag.

Honestly the more likely breakage is from people expecting that request.toString() returns [object Object] instead of [object Request], but I don't think this change would actually detect that. I still think this isn't likely, though.

@garrettgu10
Copy link
Contributor Author

I agree, especially since Node and Chromium already set the toStringTags correctly.

FYI, based on my testing, this change would actually detect what you mentioned.

@kentonv
Copy link
Member

kentonv commented Feb 15, 2024

FYI, based on my testing, this change would actually detect what you mentioned.

I think it will actually log any time anyone calls toString() on a JSG type at all? But people almost certainly do do that (probably by accident, but still), so this log line would be expected to show up immediately, but it doesn't actually tell us if changing the result would break anyone.

@jasnell
Copy link
Member

jasnell commented Feb 16, 2024

Yep, logging on the get here is not likely to tell us anything useful. Logging on the set would at least tell us if someone is trying to work around the lack of our APIs having a ToStringTag. In my original comment I in the other PR I had indicated that I believed the risk of breaking anyone here was really quite low. Logging like this is how we've made clear determinations in the past about whether a change is likely breaking but I think this is one case where we can likely base the decision off judgement.

@garrettgu10
Copy link
Contributor Author

Okie dokie, lemme close this and try to merge the other change in then. :-)

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