mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:21:07 +00:00
[js_util] Add unsignedRightSift operator to js_util
Change-Id: Ibbf10bc5428e01e9f2bca24cf99489b186c7ba9a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278995 Commit-Queue: Riley Porter <rileyporter@google.com> Reviewed-by: Srujan Gaddam <srujzs@google.com>
This commit is contained in:
parent
3868b30e21
commit
329cb2088a
|
@ -449,6 +449,12 @@ bool delete<T>(Object o, Object property) {
|
|||
return JS<bool>('bool', 'delete #[#]', o, property);
|
||||
}
|
||||
|
||||
@patch
|
||||
@pragma('dart2js:tryInline')
|
||||
num unsignedRightShift(Object? leftOperand, Object? rightOperand) {
|
||||
return JS<num>('num', '# >>> #', leftOperand, rightOperand);
|
||||
}
|
||||
|
||||
@patch
|
||||
Future<T> promiseToFuture<T>(Object jsPromise) {
|
||||
final completer = Completer<T>();
|
||||
|
|
|
@ -118,6 +118,10 @@ external T and<T>(Object? first, Object? second);
|
|||
/// given object.
|
||||
external bool delete<T>(Object o, Object property);
|
||||
|
||||
/// Perform JavaScript unsigned right shift operator (`>>>`) on the given left
|
||||
/// operand by the amount specified by the given right operand.
|
||||
external num unsignedRightShift(Object? leftOperand, Object? rightOperand);
|
||||
|
||||
/// Exception for when the promise is rejected with a `null` or `undefined`
|
||||
/// value.
|
||||
///
|
||||
|
|
|
@ -135,4 +135,21 @@ main() {
|
|||
expect(js_util.delete(f, 'a'), isTrue);
|
||||
expect(js_util.getProperty(f, 'a'), equals(null));
|
||||
});
|
||||
|
||||
test('unsignedRightShift', () {
|
||||
expect(js_util.unsignedRightShift(9, 2), equals(2));
|
||||
expect(js_util.unsignedRightShift(-9, 2), equals(1073741821));
|
||||
|
||||
expect(js_util.unsignedRightShift(1, 'a'), equals(1));
|
||||
expect(js_util.unsignedRightShift(1, null), equals(1));
|
||||
expect(js_util.unsignedRightShift(1, undefinedObject), equals(1));
|
||||
expect(js_util.unsignedRightShift(1, false), equals(1));
|
||||
expect(js_util.unsignedRightShift(1, []), equals(1));
|
||||
|
||||
expect(js_util.unsignedRightShift('a', 1), equals(0));
|
||||
expect(js_util.unsignedRightShift(null, 1), equals(0));
|
||||
expect(js_util.unsignedRightShift(undefinedObject, 1), equals(0));
|
||||
expect(js_util.unsignedRightShift(false, 1), equals(0));
|
||||
expect(js_util.unsignedRightShift([], 1), equals(0));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -135,4 +135,21 @@ main() {
|
|||
expect(js_util.delete(f, 'a'), isTrue);
|
||||
expect(js_util.getProperty(f, 'a'), equals(null));
|
||||
});
|
||||
|
||||
test('unsignedRightShift', () {
|
||||
expect(js_util.unsignedRightShift(9, 2), equals(2));
|
||||
expect(js_util.unsignedRightShift(-9, 2), equals(1073741821));
|
||||
|
||||
expect(js_util.unsignedRightShift(1, 'a'), equals(1));
|
||||
expect(js_util.unsignedRightShift(1, null), equals(1));
|
||||
expect(js_util.unsignedRightShift(1, undefinedObject), equals(1));
|
||||
expect(js_util.unsignedRightShift(1, false), equals(1));
|
||||
expect(js_util.unsignedRightShift(1, []), equals(1));
|
||||
|
||||
expect(js_util.unsignedRightShift('a', 1), equals(0));
|
||||
expect(js_util.unsignedRightShift(null, 1), equals(0));
|
||||
expect(js_util.unsignedRightShift(undefinedObject, 1), equals(0));
|
||||
expect(js_util.unsignedRightShift(false, 1), equals(0));
|
||||
expect(js_util.unsignedRightShift([], 1), equals(0));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue