Skip to content

Commit e445c58

Browse files
committed
ProgressEvent: properties loaded and total are numeric
1 parent 93635fa commit e445c58

3 files changed

Lines changed: 43 additions & 36 deletions

File tree

src/changes/changes.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
<body>
1010
<release version="5.0.0" date="April 01, 2026" description="jdk17, Bugfixes">
11+
<action type="update" dev="rbri">
12+
ProgressEvent: properties loaded and total are numeric.
13+
</action>
14+
<action type="fix" dev="rbri">
15+
Intl: getCanonicalLocales() processes arguments as array-likes in sync with the spec.
16+
</action>
1117
<action type="add" dev="Lai Quang Duong">
1218
FileReader: fire ProgressEvent and add missing event handlers
1319
</action>

src/main/java/org/htmlunit/javascript/host/event/ProgressEvent.java

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
public class ProgressEvent extends Event {
3333

3434
private boolean lengthComputable_;
35-
private Object loaded_ = Long.valueOf(0L);
36-
private long total_;
35+
private double loaded_;
36+
private double total_;
3737

3838
/**
3939
* Default constructor.
@@ -60,36 +60,10 @@ public void jsConstructor(final String type, final ScriptableObject details) {
6060
}
6161

6262
final Object loaded = details.get("loaded");
63-
if (loaded instanceof Long) {
64-
loaded_ = loaded;
65-
}
66-
else if (loaded instanceof Double double1) {
67-
loaded_ = double1.longValue();
68-
}
69-
else {
70-
try {
71-
loaded_ = Long.parseLong(loaded.toString());
72-
}
73-
catch (final NumberFormatException ignored) {
74-
// ignore
75-
}
76-
}
63+
loaded_ = JavaScriptEngine.toNumber(loaded);
7764

7865
final Object total = details.get("total");
79-
if (total instanceof Long long1) {
80-
total_ = long1;
81-
}
82-
else if (total instanceof Double double1) {
83-
total_ = double1.longValue();
84-
}
85-
else {
86-
try {
87-
total_ = Long.parseLong(details.get("total").toString());
88-
}
89-
catch (final NumberFormatException ignored) {
90-
// ignore
91-
}
92-
}
66+
total_ = JavaScriptEngine.toNumber(total);
9367
}
9468
}
9569

@@ -99,7 +73,7 @@ else if (total instanceof Double double1) {
9973
* @param type the event type
10074
*/
10175
public ProgressEvent(final EventTarget target, final String type) {
102-
super(target, type);
76+
this(target, type, false, 0d, 0d);
10377
}
10478

10579
/**
@@ -111,7 +85,7 @@ public ProgressEvent(final EventTarget target, final String type) {
11185
* @param total the total number of bytes
11286
*/
11387
public ProgressEvent(final EventTarget target, final String type,
114-
final boolean lengthComputable, final long loaded, final long total) {
88+
final boolean lengthComputable, final double loaded, final double total) {
11589
super(target, type);
11690
lengthComputable_ = lengthComputable;
11791
loaded_ = loaded;
@@ -141,7 +115,7 @@ public void setLengthComputable(final boolean lengthComputable) {
141115
* @return the loaded property from the event.
142116
*/
143117
@JsxGetter
144-
public Object getLoaded() {
118+
public double getLoaded() {
145119
return loaded_;
146120
}
147121

@@ -150,7 +124,7 @@ public Object getLoaded() {
150124
*
151125
* @param loaded the loaded information for this event
152126
*/
153-
public void setLoaded(final Object loaded) {
127+
public void setLoaded(final double loaded) {
154128
loaded_ = loaded;
155129
}
156130

@@ -159,7 +133,7 @@ public void setLoaded(final Object loaded) {
159133
* @return the total property from the event.
160134
*/
161135
@JsxGetter
162-
public long getTotal() {
136+
public double getTotal() {
163137
return total_;
164138
}
165139

@@ -168,7 +142,7 @@ public long getTotal() {
168142
*
169143
* @param total the total information for this event
170144
*/
171-
public void setTotal(final long total) {
145+
public void setTotal(final double total) {
172146
total_ = total;
173147
}
174148
}

src/test/java/org/htmlunit/javascript/host/event/ProgressEventTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,33 @@ public void create_ctorWithDetails() throws Exception {
9090
loadPageVerifyTitle2(html);
9191
}
9292

93+
/**
94+
* @throws Exception if the test fails
95+
*/
96+
@Test
97+
@Alerts({"[object ProgressEvent]", "test", "true", "false", "false", "true", "2.34", "66.6"})
98+
public void create_ctorWithDetailsDouble() throws Exception {
99+
final String html = DOCTYPE_HTML
100+
+ "<html><head><script>\n"
101+
+ LOG_TITLE_FUNCTION
102+
+ " function test() {\n"
103+
+ " try {\n"
104+
+ " var event = new ProgressEvent('test', {\n"
105+
+ " 'bubbles': true,\n"
106+
+ " 'lengthComputable': true,\n"
107+
+ " 'loaded': 2.34,\n"
108+
+ " 'total': 66.6\n"
109+
+ " });\n"
110+
+ " dump(event);\n"
111+
+ " } catch(e) { logEx(e) }\n"
112+
+ " }\n"
113+
+ DUMP_EVENT_FUNCTION
114+
+ "</script></head><body onload='test()'>\n"
115+
+ "</body></html>";
116+
117+
loadPageVerifyTitle2(html);
118+
}
119+
93120
/**
94121
* @throws Exception if the test fails
95122
*/

0 commit comments

Comments
 (0)