Skip to content

Commit 22cbc24

Browse files
committed
[js] Slight reversal on thenFinally deprecation in
9dd3fe4
1 parent 28db4a4 commit 22cbc24

File tree

5 files changed

+87
-31
lines changed

5 files changed

+87
-31
lines changed

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v2.53.2
2+
3+
* Deprecated `Promise#thenFinally()` - use `Promise#finally()`. The thenFinally
4+
shim added to the promise module in v2.53.0 will be removed in v3.0
5+
Sorry for the churn!
6+
17
## v2.53.1
28

39
* FIXED: for consistency with the other language bindings, `remote.FileDetector`

javascript/node/selenium-webdriver/firefox/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,7 @@ class Driver extends webdriver.WebDriver {
378378
command.kill();
379379
return command.result();
380380
});
381-
return promise.thenFinally(
382-
finishCommand,
383-
() => preparedProfile.then(io.rmDir));
381+
return finishCommand.finally(() => preparedProfile.then(io.rmDir));
384382
};
385383
}
386384

javascript/node/selenium-webdriver/lib/promise.js

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,44 @@ class Thenable {
923923
*/
924924
thenCatch(errback) {}
925925

926+
/**
927+
* Registers a listener to invoke when this promise is resolved, regardless
928+
* of whether the promise's value was successfully computed. This function
929+
* is synonymous with the {@code finally} clause in a synchronous API:
930+
*
931+
* // Synchronous API:
932+
* try {
933+
* doSynchronousWork();
934+
* } finally {
935+
* cleanUp();
936+
* }
937+
*
938+
* // Asynchronous promise API:
939+
* doAsynchronousWork().finally(cleanUp);
940+
*
941+
* __Note:__ similar to the {@code finally} clause, if the registered
942+
* callback returns a rejected promise or throws an error, it will silently
943+
* replace the rejection error (if any) from this promise:
944+
*
945+
* try {
946+
* throw Error('one');
947+
* } finally {
948+
* throw Error('two'); // Hides Error: one
949+
* }
950+
*
951+
* promise.rejected(Error('one'))
952+
* .finally(function() {
953+
* throw Error('two'); // Hides Error: one
954+
* });
955+
*
956+
* @param {function(): (R|IThenable<R>)} callback The function to call when
957+
* this promise is resolved.
958+
* @return {!ManagedPromise<R>} A promise that will be fulfilled
959+
* with the callback result.
960+
* @template R
961+
*/
962+
finally(callback) {}
963+
926964
/**
927965
* Registers a listener to invoke when this promise is resolved, regardless
928966
* of whether the promise's value was successfully computed. This function
@@ -957,14 +995,10 @@ class Thenable {
957995
* to call when this promise is resolved.
958996
* @return {!ManagedPromise<R>} A promise that will be fulfilled
959997
* with the callback result.
960-
* @deprecated thenFinally has been deprecated to help make WebDriver's
961-
* managed promises API compatible with native promises. The functionality
962-
* provided by this method is now offered for any promise implementation
963-
* using the {@link thenFinally} function in the promise module.
998+
* @deprecated Use {@link #finally()} instead.
964999
* @template R
9651000
*/
966-
thenFinally(callback) {}
967-
}
1001+
thenFinally(callback) {}}
9681002

9691003

9701004
/**
@@ -1252,14 +1286,8 @@ class ManagedPromise {
12521286
return this.catch(errback);
12531287
}
12541288

1255-
/**
1256-
* @override
1257-
* @deprecated thenFinally has been deprecated to help make WebDriver's
1258-
* managed promises API compatible with native promises. The functionality
1259-
* provided by this method is now offered for any promise implementation
1260-
* using the {@link thenFinally} function in the promise module.
1261-
*/
1262-
thenFinally(callback) {
1289+
/** @override */
1290+
finally(callback) {
12631291
var error;
12641292
var mustThrow = false;
12651293
return this.then(function() {
@@ -1275,6 +1303,14 @@ class ManagedPromise {
12751303
});
12761304
}
12771305

1306+
/**
1307+
* @override
1308+
* @deprecated Use {@link #finally()} instead.
1309+
*/
1310+
thenFinally(callback) {
1311+
return this.finally(callback);
1312+
}
1313+
12781314
/**
12791315
* Registers a new callback with this promise
12801316
* @param {(function(T): (R|IThenable<R>)|null|undefined)} callback The
@@ -1448,6 +1484,14 @@ class Deferred {
14481484
thenFinally(opt_cb) {
14491485
return this.promise.thenFinally(opt_cb);
14501486
}
1487+
1488+
/**
1489+
* @override
1490+
* @deprecated Use {@code finally} from the promise property directly.
1491+
*/
1492+
finally(opt_cb) {
1493+
return this.promise.finally(opt_cb);
1494+
}
14511495
}
14521496
Thenable.addImplementation(Deferred);
14531497

@@ -1490,6 +1534,7 @@ Thenable.addImplementation(Deferred);
14901534
* promise will inherit the value of the original input if the callback
14911535
* does not throw or return a rejected promise.
14921536
* @template PROMISE_TYPE
1537+
* @deprecated
14931538
*/
14941539
function thenFinally(promise, callback) {
14951540
if (!isPromise(promise)) {

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ class WebDriver {
445445
var result = this.schedule(
446446
new command.Command(command.Name.QUIT),
447447
'WebDriver.quit()');
448-
// Delete our session ID when the quit command finishes; this will allow us to
449-
// throw an error when attemnpting to use a driver post-quit.
450-
return promise.thenFinally(result, () => delete this.session_);
448+
// Delete our session ID when the quit command finishes; this will allow us
449+
// to throw an error when attemnpting to use a driver post-quit.
450+
return result.finally(() => delete this.session_);
451451
}
452452

453453
/**
@@ -1961,8 +1961,8 @@ class WebElement {
19611961
* Schedules a command to query for the computed style of the element
19621962
* represented by this instance. If the element inherits the named style from
19631963
* its parent, the parent will be queried for its value. Where possible, color
1964-
* values will be converted to their hex representation (e.g. #00ff00 instead of
1965-
* rgb(0, 255, 0)).
1964+
* values will be converted to their hex representation (e.g. #00ff00 instead
1965+
* of rgb(0, 255, 0)).
19661966
*
19671967
* _Warning:_ the value returned will be as the browser interprets it, so
19681968
* it may be tricky to form a proper assertion.
@@ -1983,10 +1983,10 @@ class WebElement {
19831983
/**
19841984
* Schedules a command to query for the value of the given attribute of the
19851985
* element. Will return the current value, even if it has been modified after
1986-
* the page has been loaded. More exactly, this method will return the value of
1987-
* the given attribute, unless that attribute is not present, in which case the
1988-
* value of the property with the same name is returned. If neither value is
1989-
* set, null is returned (for example, the "value" property of a textarea
1986+
* the page has been loaded. More exactly, this method will return the value
1987+
* of the given attribute, unless that attribute is not present, in which case
1988+
* the value of the property with the same name is returned. If neither value
1989+
* is set, null is returned (for example, the "value" property of a textarea
19901990
* element). The "style" attribute is converted as best can be to a
19911991
* text representation with a trailing semi-colon. The following are deemed to
19921992
* be "boolean" attributes and will return either "true" or null:
@@ -2017,8 +2017,9 @@ class WebElement {
20172017
}
20182018

20192019
/**
2020-
* Get the visible (i.e. not hidden by CSS) innerText of this element, including
2021-
* sub-elements, without any leading or trailing whitespace.
2020+
* Get the visible (i.e. not hidden by CSS) innerText of this element,
2021+
* including sub-elements, without any leading or trailing whitespace.
2022+
*
20222023
* @return {!promise.Promise<string>} A promise that will be
20232024
* resolved with the element's visible text.
20242025
*/
@@ -2203,7 +2204,10 @@ class WebElementPromise extends WebElement {
22032204
this.thenCatch = el.catch.bind(el);
22042205

22052206
/** @override */
2206-
this.thenFinally = (cb) => promise.thenFinally(el, cb);
2207+
this.finally = el.finally.bind(el);
2208+
2209+
/** @override */
2210+
this.thenFinally = el.finally.bind(el);
22072211

22082212
/**
22092213
* Defers returning the element ID until the wrapped WebElement has been
@@ -2357,7 +2361,10 @@ class AlertPromise extends Alert {
23572361
this.thenCatch = alert.catch.bind(alert);
23582362

23592363
/** @override */
2360-
this.thenFinally = (cb) => promise.thenFinally(alert, cb);
2364+
this.finally = alert.finally.bind(alert);
2365+
2366+
/** @override */
2367+
this.thenFinally = alert.finally.bind(alert);
23612368

23622369
/**
23632370
* Defer returning text until the promised alert has been resolved.

javascript/node/selenium-webdriver/safari.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class CommandExecutor {
414414
}));
415415
}
416416
var self = this;
417-
return promise.thenFinally(promise.all(tasks), function() {
417+
return promise.all(tasks).finally(function() {
418418
self.server_ = null;
419419
self.socket_ = null;
420420
self.safari_ = null;

0 commit comments

Comments
 (0)