mirror of
https://github.com/dart-lang/sdk
synced 2024-09-30 04:48:37 +00:00
[dart:js_interop] Make not and isTruthy return JSBoolean
Since these operators can't be written by users, prefer to keep them as JS types. Closes https://github.com/dart-lang/sdk/issues/55267 Change-Id: Ifb9b581fb82e057ba14c669a5a3934f9c502d06f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359181 Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com> Commit-Queue: Srujan Gaddam <srujzs@google.com>
This commit is contained in:
parent
0b761229cc
commit
1550539558
|
@ -55,8 +55,11 @@
|
|||
|
||||
- **Breaking Change** [#55508][]: `importModule` now accepts a `JSAny` instead
|
||||
of a `String` to support other JS values as well, like `TrustedScriptURL`s.
|
||||
- **Breaking Change** [#55267][]: `isTruthy` and `not` now return `JSBoolean`
|
||||
instead of `bool` to be consistent with the other operators.
|
||||
|
||||
[#55508]: https://github.com/dart-lang/sdk/issues/55508
|
||||
[#55267]: https://github.com/dart-lang/sdk/issues/55267
|
||||
|
||||
### Tools
|
||||
|
||||
|
|
|
@ -467,11 +467,11 @@ extension JSAnyOperatorExtension on JSAny? {
|
|||
|
||||
@patch
|
||||
@pragma('dart2js:prefer-inline')
|
||||
bool get not => js_util.not(this);
|
||||
JSBoolean get not => js_util.not(this);
|
||||
|
||||
@patch
|
||||
@pragma('dart2js:prefer-inline')
|
||||
bool get isTruthy => js_util.isTruthy(this);
|
||||
JSBoolean get isTruthy => JSBoolean._(js_util.isTruthy(this));
|
||||
}
|
||||
|
||||
@patch
|
||||
|
|
|
@ -545,14 +545,12 @@ extension JSAnyOperatorExtension on JSAny? {
|
|||
'(o, a) => o || a', this.toExternRef, any.toExternRef)) as JSAny?;
|
||||
|
||||
@patch
|
||||
bool get not => JSBoolean._(
|
||||
JSValue(js_helper.JS<WasmExternRef?>('(o) => !o', this.toExternRef)))
|
||||
.toDart;
|
||||
JSBoolean get not => JSBoolean._(
|
||||
JSValue(js_helper.JS<WasmExternRef?>('(o) => !o', this.toExternRef)));
|
||||
|
||||
@patch
|
||||
bool get isTruthy => JSBoolean._(
|
||||
JSValue(js_helper.JS<WasmExternRef?>('(o) => !!o', this.toExternRef)))
|
||||
.toDart;
|
||||
JSBoolean get isTruthy => JSBoolean._(
|
||||
JSValue(js_helper.JS<WasmExternRef?>('(o) => !!o', this.toExternRef)));
|
||||
}
|
||||
|
||||
@patch
|
||||
|
|
|
@ -1143,12 +1143,10 @@ extension JSAnyOperatorExtension on JSAny? {
|
|||
external JSAny? or(JSAny? any);
|
||||
|
||||
/// The result of <code>!`this`</code> in JavaScript.
|
||||
// TODO(srujzs): Change this to JSBoolean to be consistent.
|
||||
external bool get not;
|
||||
external JSBoolean get not;
|
||||
|
||||
/// The result of <code>!!`this`</code> in JavaScript.
|
||||
// TODO(srujzs): Change this to JSBoolean to be consistent.
|
||||
external bool get isTruthy;
|
||||
external JSBoolean get isTruthy;
|
||||
}
|
||||
|
||||
/// The global scope that is used to find user-declared interop members.
|
||||
|
|
|
@ -82,8 +82,8 @@ void dartJsInteropOperatorsTest() {
|
|||
Expect.isTrue(t.strictNotEquals(1.toJS).toDart);
|
||||
Expect.isFalse((t.and(f) as JSBoolean).toDart);
|
||||
Expect.isTrue((t.or(f) as JSBoolean).toDart);
|
||||
Expect.isFalse(t.not);
|
||||
Expect.isTrue(t.isTruthy);
|
||||
Expect.isFalse(t.not.toDart);
|
||||
Expect.isTrue(t.isTruthy.toDart);
|
||||
Expect.isFalse(i10.lessThan(i10).toDart);
|
||||
Expect.isTrue(i10.lessThanOrEqualTo(i10).toDart);
|
||||
Expect.isFalse(i10.greaterThan(i10).toDart);
|
||||
|
@ -103,8 +103,8 @@ void dartJsInteropOperatorsTest() {
|
|||
Expect.isFalse(null.strictNotEquals(null).toDart);
|
||||
expect(null.and(null), null);
|
||||
expect(null.or(null), null);
|
||||
Expect.isTrue(null.not);
|
||||
Expect.isFalse(null.isTruthy);
|
||||
Expect.isTrue(null.not.toDart);
|
||||
Expect.isFalse(null.isTruthy.toDart);
|
||||
Expect.isFalse(null.lessThan(null).toDart);
|
||||
Expect.isTrue(null.lessThanOrEqualTo(null).toDart);
|
||||
Expect.isFalse(null.greaterThan(null).toDart);
|
||||
|
@ -128,8 +128,8 @@ void dartJsInteropOperatorsTest() {
|
|||
Expect.isTrue(b1.strictNotEquals(t).toDart);
|
||||
expect(b10.and(b1), b1);
|
||||
expect(b10.or(b1), b10);
|
||||
Expect.isFalse(b10.not);
|
||||
Expect.isTrue(b10.isTruthy);
|
||||
Expect.isFalse(b10.not.toDart);
|
||||
Expect.isTrue(b10.isTruthy.toDart);
|
||||
Expect.isFalse(b10.lessThan(b10).toDart);
|
||||
Expect.isTrue(b10.lessThanOrEqualTo(b10).toDart);
|
||||
Expect.isFalse(b10.greaterThan(b10).toDart);
|
||||
|
|
Loading…
Reference in a new issue