-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
src: remove ToLocalChecked() from UnionBytes
#60164
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
Conversation
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #60164 +/- ##
========================================
Coverage 88.53% 88.54%
========================================
Files 703 704 +1
Lines 207997 208094 +97
Branches 40015 40024 +9
========================================
+ Hits 184150 184251 +101
+ Misses 15864 15858 -6
- Partials 7983 7985 +2
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnionBytes is used for built-in strings (like built-in module sources). It is intended that if a UnionBytes failed to create the external string, the process should crash as soon as possible.
| } else { | ||
| return String::NewExternalTwoByte(isolate, two_byte_resource_) | ||
| .ToLocalChecked(); | ||
| return String::NewExternalTwoByte(isolate, two_byte_resource_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change kind of only brings us halfway towards the right semantics, because the comment in this snippet also applies here:
Lines 347 to 357 in 1527825
| if (str.size() >= static_cast<size_t>(v8::String::kMaxLength)) [[unlikely]] { | |
| // V8 only has a TODO comment about adding an exception when the maximum | |
| // string size is exceeded. | |
| ThrowErrStringTooLong(isolate); | |
| return v8::MaybeLocal<v8::Value>(); | |
| } | |
| return v8::String::NewFromUtf8( | |
| isolate, str.data(), v8::NewStringType::kNormal, str.size()) | |
| .FromMaybe(v8::Local<v8::String>()); | |
| } |
| if (out->Set(context, key, value).IsNothing()) { | ||
| return; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion, but if we add support for UnionBytes in ToV8Value(), this entirely loop could be replaced by a ToV8Value() call
| if (!config_.ToString(isolate).ToLocal(&config_str)) { | ||
| return {}; | ||
| } | ||
| return config_str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not do this – this is dangerous and strictly worse than the previous code, because a return type of Local<String> (as opposed to MaybeLocal<String>) typically means that the value won't be empty, so the caller might assume that it's always safe to dereference the handle.
|
Thanks for the review and guidance! I approached this too narrowly without fully understanding the overall design. I’ll close this PR. |
This PR removes
ToLocalChecked()usage fromUnionBytesto avoid unexpected crashes.UnionBytes::ToStringChecked()->UnionBytes::ToString().ToLocalChecked()usage.MaybeLocal.MaybeLocal.