Skip to content

[breaking change] Change return type of isTruthy and not #55267

@srujzs

Description

@srujzs

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's isTruthy and not should now return a JSBoolean instead of a bool.

dart:js_interop exposes isTruthy and not operators to be consistent with dart:js_util API. They currently return a bool, 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 a boolean with toDart:

bool b1 = true.toJS.not;
bool b2 = true.toJS.isTruthy;
bool b1 = true.toJS.not.toDart;
bool b2 = true.toJS.isTruthy.toDart;

cc @sigmundch

Metadata

Metadata

Assignees

Labels

area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.breaking-change-approvedbreaking-change-requestThis tracks requests for feedback on breaking changesweb-js-interopIssues that impact all js interop

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions