-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[breaking change] Change return type of isTruthy and not #55267
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
Comments
Related issues: #55024 #55267 These operators were initially broken in 3.3 and were exposed as returning JSBoolean but implemented as returning bool. They were fixed to return bool in the public API, but we should prefer to have them return JS types as they're likely to be used in cases where implicit conversions are not useful. CoreLibraryReviewExempt: Fixing type mismatch in backend-specific library. Change-Id: I3b0e60550dcac78918f8399d11238dcfa34982cd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359180 Commit-Queue: Srujan Gaddam <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]>
LGTM 👍, this would bring all operators to have a consistent API: all other operators today return a JS type, this would make the cc @itsjustkevin - for the breaking change process In terms of timing, I'm open to either having this in 3.4 or 3.5, given the cutoff date, I'm fine waiting until 3.5. Usage is low enough that we don't expect much impact later either, but we may want to suggest a backward compatible way to write code if we don't release it in 3.4. For example: bool isReallyTruthy(JSAny a) {
Object o = a.isThruthy;
return o is bool ? o : (o as JSBoolean).toDart;
} |
SGTM. |
no objection; seems reasonable but i don't have enough context to fully evaluate. |
lgtm |
Breaking change approved |
Some more context here: #55238. This is the "reverse" of that change - move all operators to use JS types instead of returning Dart types.
Intended Change
dart:js_interop
'sisTruthy
andnot
should now return aJSBoolean
instead of abool
.dart:js_interop
exposesisTruthy
andnot
operators to be consistent withdart:js_util
API. They currently return abool
, as the result is always a boolean JS value.Justification
JS operator utility members should use JS types instead of their Dart equivalents for performance. They are likely to be used when the conversion is deemed costly (otherwise, users could just convert to the Dart value and use Dart operators) and they are likely to be composed on one other e.g.
b1.and(b2.or(b3))
. In the case of composition, this adds several additional unneeded conversions.Impact
Minimal. There are no usages in google3, in Flutter, in the SDK, or on GitHub.
Mitigation
Convert the resulting
JSBoolean
to aboolean
withtoDart
:cc @sigmundch
The text was updated successfully, but these errors were encountered: