Skip to content

Commit 55fec53

Browse files
refactor
1 parent b477de8 commit 55fec53

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

geolocation/success.https.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<script src="/resources/testharnessreport.js"></script>
55
<script src="/resources/testdriver.js?feature=bidi"></script>
66
<script src="/resources/testdriver-vendor.js"></script>
7-
<script src="support.js"></script>
87

98
<script>
109
promise_setup(async () => {
@@ -28,7 +27,14 @@
2827
coordinates: {latitude, longitude, accuracy}
2928
});
3029

31-
const position = await getCurrentGeolocation();
30+
const positionPromise = new Promise(
31+
(resolve, reject) =>
32+
window.navigator.geolocation.getCurrentPosition(
33+
position => resolve(position.coords.toJSON()),
34+
error => reject(error),
35+
{timeout: 200}
36+
))
37+
const position = await positionPromise;
3238

3339
assert_equals(position.latitude, latitude);
3440
assert_equals(position.longitude, longitude);

geolocation/support.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,3 @@ var errorToString = function(err) {
2828
}
2929
return '[code: ' + codeString + ' (' + err.code + '), message: ' + (err.message ? err.message : '(empty)') + ']';
3030
};
31-
32-
/**
33-
* Returns the current geolocation or throws error.
34-
*
35-
* @param {number} timeout - Timeout in milliseconds, default is 200ms.
36-
*/
37-
function getCurrentGeolocation(timeout = 200) {
38-
return new Promise(
39-
(resolve, reject) => window.navigator.geolocation.getCurrentPosition(
40-
position => resolve(position.coords.toJSON()),
41-
error => reject(error),
42-
// Fail fast if geolocation is not available.
43-
{timeout}
44-
))
45-
}

0 commit comments

Comments
 (0)