-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[DevTools] Replace constructor.name
checks with constructor
checks
#26567
[DevTools] Replace constructor.name
checks with constructor
checks
#26567
Conversation
constructor.name
checks with instanceof
constructor.name
checks with constructor
checks
@mondaychen, this PR is probably micro-optimization, but at least it provides some confidence in the checks. These checks could have been possible, too, but they didn't pass the existing tests:
|
This seems fine to me. |
This code was from 2019 (#17579); I don't remember exactly why it was written that way. This is what we were doing before that didn't work in some cases: } else if (data instanceof ArrayBuffer) {
return 'array_buffer'; I think checking the Looking at how this library does it, for example, seems to support that the check isn't so simple: I would vote not to change this without good reason. What's the actual motivation here? |
Thank you, @bvaughn, for reviewing this! Interestingly, using the is-array-buffer module that you mentioned throws the same error as using
It seems that the is-array-buffer module works similarly as
Whereas both
Your old question about a better way motivated me to search for one. It seems that the solution that you came up with (the |
I appreciate your following up with the extra info!
My concern is still about cross-realm/iframe issues. I think I remember seeing something about that, which is maybe why I used |
It seems that you really thought this through back then, because:
Well, this was an interesting exercise. Thank you so much for your time! |
No problem! Thanks for the speedy responses. |
Summary
There is a question in the code of
utils.js
asking for a better way to check for anArrayBuffer
:Replacing the current check (
data.constructor && data.constructor.name === 'ArrayBuffer'
) withdata.constructor && data.constructor === ArrayBuffer
is arguably a better and more efficient way.How did you test this change?
In addition to running the existing tests, I compared the speeds of the checks:
This resulted in significant speed differences: