Skip to content

Commit e3a7450

Browse files
committed
Emit double as return value instead of num
Closes dart-lang#57 In cases where the return type is known to be a double value, prefer double over num so users don't try and downcast the type, which won't work consistently on all compilers. In order to do this, _typeReference is amended to take an extra option 'returnType' which determines if the `_RawType` is used in a return type context.
1 parent f6f778b commit e3a7450

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+508
-499
lines changed

lib/src/dom/battery_status.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension type BatteryManager._(JSObject _) implements EventTarget, JSObject {
5050
/// > **Note:** Even if the time returned is precise to the second,
5151
/// > browsers round them to a higher interval
5252
/// > (typically to the closest 15 minutes) for privacy reasons.
53-
external num get chargingTime;
53+
external double get chargingTime;
5454

5555
/// The **`dischargingTime`** read-only property of the [BatteryManager]
5656
/// interface indicates the amount of time, in seconds, that remains until the
@@ -63,7 +63,7 @@ extension type BatteryManager._(JSObject _) implements EventTarget, JSObject {
6363
/// > **Note:** Even if the time returned is precise to the second, browsers
6464
/// > round them to a higher
6565
/// > interval (typically to the closest 15 minutes) for privacy reasons.
66-
external num get dischargingTime;
66+
external double get dischargingTime;
6767

6868
/// The **`level`** read-only property of the [BatteryManager] interface
6969
/// indicates the current battery charge level as a value between `0.0` and
@@ -74,7 +74,7 @@ extension type BatteryManager._(JSObject _) implements EventTarget, JSObject {
7474
/// report the battery status information.
7575
/// When its value changes, the [BatteryManager.levelchange_event] event is
7676
/// fired.
77-
external num get level;
77+
external double get level;
7878
external EventHandler get onchargingchange;
7979
external set onchargingchange(EventHandler value);
8080
external EventHandler get onchargingtimechange;

lib/src/dom/cookie_store.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ extension type CookieInit._(JSObject _) implements JSObject {
9494
external set name(String value);
9595
external String get value;
9696
external set value(String value);
97-
external DOMHighResTimeStamp? get expires;
97+
external double? get expires;
9898
external set expires(DOMHighResTimeStamp? value);
9999
external String? get domain;
100100
external set domain(String? value);
@@ -142,7 +142,7 @@ extension type CookieListItem._(JSObject _) implements JSObject {
142142
external set domain(String? value);
143143
external String get path;
144144
external set path(String value);
145-
external DOMHighResTimeStamp? get expires;
145+
external double? get expires;
146146
external set expires(DOMHighResTimeStamp? value);
147147
external bool get secure;
148148
external set secure(bool value);

lib/src/dom/css_animations.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension type AnimationEvent._(JSObject _) implements Event, JSObject {
4343
/// `elapsedTime` is `0.0` unless there was a negative value for
4444
/// , in which case the event will be fired with
4545
/// `elapsedTime` containing `(-1 * delay)`.
46-
external num get elapsedTime;
46+
external double get elapsedTime;
4747

4848
/// The **`AnimationEvent.pseudoElement`** read-only property is a
4949
/// string, starting with `'::'`, containing the name of the
@@ -65,7 +65,7 @@ extension type AnimationEventInit._(JSObject _) implements EventInit, JSObject {
6565

6666
external String get animationName;
6767
external set animationName(String value);
68-
external num get elapsedTime;
68+
external double get elapsedTime;
6969
external set elapsedTime(num value);
7070
external String get pseudoElement;
7171
external set pseudoElement(String value);

lib/src/dom/css_paint_api.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ extension type PaintRenderingContext2D._(JSObject _) implements JSObject {
116116
]);
117117
external void setLineDash(JSArray<JSNumber> segments);
118118
external JSArray<JSNumber> getLineDash();
119-
external num get globalAlpha;
119+
external double get globalAlpha;
120120
external set globalAlpha(num value);
121121
external String get globalCompositeOperation;
122122
external set globalCompositeOperation(String value);
@@ -128,26 +128,26 @@ extension type PaintRenderingContext2D._(JSObject _) implements JSObject {
128128
external set strokeStyle(JSAny value);
129129
external JSAny get fillStyle;
130130
external set fillStyle(JSAny value);
131-
external num get shadowOffsetX;
131+
external double get shadowOffsetX;
132132
external set shadowOffsetX(num value);
133-
external num get shadowOffsetY;
133+
external double get shadowOffsetY;
134134
external set shadowOffsetY(num value);
135-
external num get shadowBlur;
135+
external double get shadowBlur;
136136
external set shadowBlur(num value);
137137
external String get shadowColor;
138138
external set shadowColor(String value);
139-
external num get lineWidth;
139+
external double get lineWidth;
140140
external set lineWidth(num value);
141141
external CanvasLineCap get lineCap;
142142
external set lineCap(CanvasLineCap value);
143143
external CanvasLineJoin get lineJoin;
144144
external set lineJoin(CanvasLineJoin value);
145-
external num get miterLimit;
145+
external double get miterLimit;
146146
external set miterLimit(num value);
147-
external num get lineDashOffset;
147+
external double get lineDashOffset;
148148
external set lineDashOffset(num value);
149149
}
150150
extension type PaintSize._(JSObject _) implements JSObject {
151-
external num get width;
152-
external num get height;
151+
external double get width;
152+
external double get height;
153153
}

lib/src/dom/css_transitions.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension type TransitionEvent._(JSObject _) implements Event, JSObject {
3939
/// seconds,
4040
/// when this event fired. This value is not affected by the
4141
/// property.
42-
external num get elapsedTime;
42+
external double get elapsedTime;
4343

4444
/// The **`TransitionEvent.pseudoElement`** read-only property is a
4545
/// string, starting with `'::'`, containing the name of the
@@ -63,7 +63,7 @@ extension type TransitionEventInit._(JSObject _)
6363

6464
external String get propertyName;
6565
external set propertyName(String value);
66-
external num get elapsedTime;
66+
external double get elapsedTime;
6767
external set elapsedTime(num value);
6868
external String get pseudoElement;
6969
external set pseudoElement(String value);

lib/src/dom/css_typed_om.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ extension type CSSUnitValue._(JSObject _) implements CSSNumericValue, JSObject {
302302

303303
/// The **`CSSUnitValue.value`** property of the
304304
/// [CSSUnitValue] interface returns a double indicating the number of units.
305-
external num get value;
305+
external double get value;
306306
external set value(num value);
307307

308308
/// The **`CSSUnitValue.unit`** read-only property

lib/src/dom/cssom_view.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ extension type ScrollToOptions._(JSObject _)
3333
num top,
3434
});
3535

36-
external num get left;
36+
external double get left;
3737
external set left(num value);
38-
external num get top;
38+
external double get top;
3939
external set top(num value);
4040
}
4141

@@ -248,41 +248,41 @@ extension type VisualViewport._(JSObject _) implements EventTarget, JSObject {
248248
/// returns the offset of the left edge of the visual viewport from the left
249249
/// edge of the layout viewport in CSS pixels, or `0` if current document is
250250
/// not fully active.
251-
external num get offsetLeft;
251+
external double get offsetLeft;
252252

253253
/// The **`offsetTop`** read-only property of the [VisualViewport] interface
254254
/// returns the offset of the top edge of the visual viewport from the top
255255
/// edge of the layout viewport in CSS pixels, or `0` if current document is
256256
/// not fully active.
257-
external num get offsetTop;
257+
external double get offsetTop;
258258

259259
/// The **`pageLeft`** read-only property of the [VisualViewport] interface
260260
/// returns the x coordinate of the left edge of the visual viewport relative
261261
/// to the initial containing block origin, in CSS pixels, or `0` if current
262262
/// document is not fully active.
263-
external num get pageLeft;
263+
external double get pageLeft;
264264

265265
/// The **`pageTop`** read-only property of the [VisualViewport] interface
266266
/// returns the y coordinate of the top edge of the visual viewport relative
267267
/// to the initial containing block origin, in CSS pixels, or `0` if current
268268
/// document is not fully active.
269-
external num get pageTop;
269+
external double get pageTop;
270270

271271
/// The **`width`** read-only property of the [VisualViewport] interface
272272
/// returns the width of the visual viewport, in CSS pixels, or `0` if current
273273
/// document is not fully active.
274-
external num get width;
274+
external double get width;
275275

276276
/// The **`height`** read-only property of the [VisualViewport] interface
277277
/// returns the height of the visual viewport, in CSS pixels, or `0` if
278278
/// current document is not fully active.
279-
external num get height;
279+
external double get height;
280280

281281
/// The **`scale`** read-only property of the [VisualViewport] interface
282282
/// returns the pinch-zoom scaling factor applied to the visual viewport, or
283283
/// `0` if current document is not fully active, or `1` if there is no output
284284
/// device.
285-
external num get scale;
285+
external double get scale;
286286
external EventHandler get onresize;
287287
external set onresize(EventHandler value);
288288
external EventHandler get onscroll;

lib/src/dom/dom.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import 'cssom.dart';
1919
import 'cssom_view.dart';
2020
import 'fullscreen.dart';
2121
import 'geometry.dart';
22-
import 'hr_time.dart';
2322
import 'html.dart';
2423
import 'selection_api.dart';
2524
import 'svg.dart';
@@ -286,7 +285,7 @@ extension type Event._(JSObject _) implements JSObject {
286285

287286
/// The **`timeStamp`** read-only property of the [Event] interface returns
288287
/// the time (in milliseconds) at which the event was created.
289-
external DOMHighResTimeStamp get timeStamp;
288+
external double get timeStamp;
290289
}
291290
extension type EventInit._(JSObject _) implements JSObject {
292291
external factory EventInit({
@@ -3406,7 +3405,7 @@ extension type Element._(JSObject _) implements Node, JSObject {
34063405
///
34073406
/// > **Warning:** On systems using display scaling, `scrollTop` may give you
34083407
/// > a decimal value.
3409-
external num get scrollTop;
3408+
external double get scrollTop;
34103409
external set scrollTop(num value);
34113410

34123411
/// The **`Element.scrollLeft`** property gets or sets the number
@@ -3432,7 +3431,7 @@ extension type Element._(JSObject _) implements Node, JSObject {
34323431
/// > **Warning:** On systems using display scaling, `scrollLeft` may give you
34333432
/// > a decimal
34343433
/// > value.
3435-
external num get scrollLeft;
3434+
external double get scrollLeft;
34363435
external set scrollLeft(num value);
34373436

34383437
/// The **`Element.scrollWidth`** read-only property is a
@@ -5253,7 +5252,7 @@ extension type XPathResult._(JSObject _) implements JSObject {
52535252
/// The read-only **`numberValue`** property of the
52545253
/// [XPathResult] interface returns the numeric value of a result with
52555254
/// [XPathResult.resultType] being `NUMBER_TYPE`.
5256-
external num get numberValue;
5255+
external double get numberValue;
52575256

52585257
/// The read-only **`stringValue`** property of the
52595258
/// [XPathResult] interface returns the string value of a result with

lib/src/dom/encrypted_media.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ extension type MediaKeySession._(JSObject _) implements EventTarget, JSObject {
171171
/// measured in milliseconds since January 1, 1970, UTC. This value may change
172172
/// during a
173173
/// session lifetime, such as when an action triggers the start of a window.
174-
external num get expiration;
174+
external double get expiration;
175175

176176
/// The `MediaKeySession.closed` read-only property returns a
177177
/// `Promise` signaling when a [MediaKeySession] closes. This

lib/src/dom/event_timing.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ library;
1414
import 'dart:js_interop';
1515

1616
import 'dom.dart';
17-
import 'hr_time.dart';
1817
import 'performance_timeline.dart';
1918

2019
/// The `PerformanceEventTiming` interface of the Event Timing API provides
@@ -34,14 +33,14 @@ extension type PerformanceEventTiming._(JSObject _)
3433
/// The read-only **`processingStart`** property returns the time at which
3534
/// event dispatch started. This is when event handlers are about to be
3635
/// executed.
37-
external DOMHighResTimeStamp get processingStart;
36+
external double get processingStart;
3837

3938
/// The read-only **`processingEnd`** property returns the time the last event
4039
/// handler finished executing.
4140
///
4241
/// It's equal to [PerformanceEventTiming.processingStart] when there are no
4342
/// such event handlers.
44-
external DOMHighResTimeStamp get processingEnd;
43+
external double get processingEnd;
4544

4645
/// The read-only **`cancelable`** property returns the associated event's
4746
/// [`cancelable`](https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable)

lib/src/dom/gamepad.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ library;
1414
import 'dart:js_interop';
1515

1616
import 'dom.dart';
17-
import 'hr_time.dart';
1817

1918
typedef GamepadMappingType = String;
2019

@@ -84,7 +83,7 @@ extension type Gamepad._(JSObject _) implements JSObject {
8483
/// newer values will always be greater than or equal to older values.
8584
///
8685
/// > **Note:** This property is not currently supported anywhere.
87-
external DOMHighResTimeStamp get timestamp;
86+
external double get timestamp;
8887

8988
/// The **`Gamepad.mapping`** property of the
9089
/// [Gamepad] interface returns a string indicating whether the browser has
@@ -166,7 +165,7 @@ extension type GamepadButton._(JSObject _) implements JSObject {
166165
/// The values are normalized to the range `0.0``1.0`, with
167166
/// `0.0` representing a button that is not pressed, and 1.0 representing a
168167
/// button that is fully pressed.
169-
external num get value;
168+
external double get value;
170169
}
171170

172171
/// The **`GamepadHapticActuator`** interface of the

lib/src/dom/generic_sensor.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ library;
1414
import 'dart:js_interop';
1515

1616
import 'dom.dart';
17-
import 'hr_time.dart';
1817
import 'html.dart';
1918
import 'webidl.dart';
2019

@@ -73,7 +72,7 @@ extension type Sensor._(JSObject _) implements EventTarget, JSObject {
7372
///
7473
/// Because [Sensor] is a base class, `timestamp` may only be read
7574
/// from one of its derived classes.
76-
external DOMHighResTimeStamp? get timestamp;
75+
external double? get timestamp;
7776
external EventHandler get onreading;
7877
external set onreading(EventHandler value);
7978
external EventHandler get onactivate;
@@ -84,7 +83,7 @@ extension type Sensor._(JSObject _) implements EventTarget, JSObject {
8483
extension type SensorOptions._(JSObject _) implements JSObject {
8584
external factory SensorOptions({num frequency});
8685

87-
external num get frequency;
86+
external double get frequency;
8887
external set frequency(num value);
8988
}
9089

lib/src/dom/geolocation.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ extension type GeolocationCoordinates._(JSObject _) implements JSObject {
113113
/// interface is a strictly positive `double` representing the accuracy, with
114114
/// a 95% confidence level, of the [GeolocationCoordinates.latitude] and
115115
/// [GeolocationCoordinates.longitude] properties expressed in meters.
116-
external num get accuracy;
116+
external double get accuracy;
117117

118118
/// The **`latitude`** read-only property of the [GeolocationCoordinates]
119119
/// interface is a `double` representing the latitude of the position in
120120
/// decimal degrees.
121-
external num get latitude;
121+
external double get latitude;
122122

123123
/// The **`longitude`** read-only property of the [GeolocationCoordinates]
124124
/// interface is a number which represents the longitude of a geographical
@@ -127,22 +127,22 @@ extension type GeolocationCoordinates._(JSObject _) implements JSObject {
127127
/// measurement, the `GeolocationCoordinates` object is part of the
128128
/// [GeolocationPosition] interface, which is the object type returned by
129129
/// Geolocation API functions that obtain and return a geographical position.
130-
external num get longitude;
130+
external double get longitude;
131131

132132
/// The **`altitude`** read-only property of the [GeolocationCoordinates]
133133
/// interface is a `double` representing the altitude of the position in
134134
/// meters above the
135135
/// [WGS84](https://gis-lab.info/docs/nima-tr8350.2-wgs84fin.pdf) ellipsoid
136136
/// (which defines the nominal sea level surface). This value is `null` if the
137137
/// implementation cannot provide this data.
138-
external num? get altitude;
138+
external double? get altitude;
139139

140140
/// The **`altitudeAccuracy`** read-only property of the
141141
/// [GeolocationCoordinates] interface is a strictly positive `double`
142142
/// representing the accuracy, with a 95% confidence level, of the `altitude`
143143
/// expressed in meters. This value is `null` if the implementation doesn't
144144
/// support measuring altitude.
145-
external num? get altitudeAccuracy;
145+
external double? get altitudeAccuracy;
146146

147147
/// The **`heading`** read-only property of the [GeolocationCoordinates]
148148
/// interface is a `double` representing the direction in which the device is
@@ -152,13 +152,13 @@ extension type GeolocationCoordinates._(JSObject _) implements JSObject {
152152
/// degrees and west is `270` degrees). If [GeolocationCoordinates.speed] is
153153
/// `0`, `heading` is `NaN`. If the device is not able to provide heading
154154
/// information, this value is `null`.
155-
external num? get heading;
155+
external double? get heading;
156156

157157
/// The **`speed`** read-only property of the [GeolocationCoordinates]
158158
/// interface is a `double` representing the velocity of the device in meters
159159
/// per second. This value is `null` if the implementation is not able to
160160
/// measure it.
161-
external num? get speed;
161+
external double? get speed;
162162
}
163163

164164
/// The **`GeolocationPositionError`** interface represents the reason of an

0 commit comments

Comments
 (0)