Skip to content

Commit

Permalink
[js] Slight reversal on thenFinally deprecation in
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyba committed Jun 28, 2016
1 parent 28db4a4 commit 22cbc24
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 31 deletions.
6 changes: 6 additions & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v2.53.2

* Deprecated `Promise#thenFinally()` - use `Promise#finally()`. The thenFinally
shim added to the promise module in v2.53.0 will be removed in v3.0
Sorry for the churn!

## v2.53.1

* FIXED: for consistency with the other language bindings, `remote.FileDetector`
Expand Down
4 changes: 1 addition & 3 deletions javascript/node/selenium-webdriver/firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,7 @@ class Driver extends webdriver.WebDriver {
command.kill();
return command.result();
});
return promise.thenFinally(
finishCommand,
() => preparedProfile.then(io.rmDir));
return finishCommand.finally(() => preparedProfile.then(io.rmDir));
};
}

Expand Down
73 changes: 59 additions & 14 deletions javascript/node/selenium-webdriver/lib/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,44 @@ class Thenable {
*/
thenCatch(errback) {}

/**
* Registers a listener to invoke when this promise is resolved, regardless
* of whether the promise's value was successfully computed. This function
* is synonymous with the {@code finally} clause in a synchronous API:
*
* // Synchronous API:
* try {
* doSynchronousWork();
* } finally {
* cleanUp();
* }
*
* // Asynchronous promise API:
* doAsynchronousWork().finally(cleanUp);
*
* __Note:__ similar to the {@code finally} clause, if the registered
* callback returns a rejected promise or throws an error, it will silently
* replace the rejection error (if any) from this promise:
*
* try {
* throw Error('one');
* } finally {
* throw Error('two'); // Hides Error: one
* }
*
* promise.rejected(Error('one'))
* .finally(function() {
* throw Error('two'); // Hides Error: one
* });
*
* @param {function(): (R|IThenable<R>)} callback The function to call when
* this promise is resolved.
* @return {!ManagedPromise<R>} A promise that will be fulfilled
* with the callback result.
* @template R
*/
finally(callback) {}

/**
* Registers a listener to invoke when this promise is resolved, regardless
* of whether the promise's value was successfully computed. This function
Expand Down Expand Up @@ -957,14 +995,10 @@ class Thenable {
* to call when this promise is resolved.
* @return {!ManagedPromise<R>} A promise that will be fulfilled
* with the callback result.
* @deprecated thenFinally has been deprecated to help make WebDriver's
* managed promises API compatible with native promises. The functionality
* provided by this method is now offered for any promise implementation
* using the {@link thenFinally} function in the promise module.
* @deprecated Use {@link #finally()} instead.
* @template R
*/
thenFinally(callback) {}
}
thenFinally(callback) {}}


/**
Expand Down Expand Up @@ -1252,14 +1286,8 @@ class ManagedPromise {
return this.catch(errback);
}

/**
* @override
* @deprecated thenFinally has been deprecated to help make WebDriver's
* managed promises API compatible with native promises. The functionality
* provided by this method is now offered for any promise implementation
* using the {@link thenFinally} function in the promise module.
*/
thenFinally(callback) {
/** @override */
finally(callback) {
var error;
var mustThrow = false;
return this.then(function() {
Expand All @@ -1275,6 +1303,14 @@ class ManagedPromise {
});
}

/**
* @override
* @deprecated Use {@link #finally()} instead.
*/
thenFinally(callback) {
return this.finally(callback);
}

/**
* Registers a new callback with this promise
* @param {(function(T): (R|IThenable<R>)|null|undefined)} callback The
Expand Down Expand Up @@ -1448,6 +1484,14 @@ class Deferred {
thenFinally(opt_cb) {
return this.promise.thenFinally(opt_cb);
}

/**
* @override
* @deprecated Use {@code finally} from the promise property directly.
*/
finally(opt_cb) {
return this.promise.finally(opt_cb);
}
}
Thenable.addImplementation(Deferred);

Expand Down Expand Up @@ -1490,6 +1534,7 @@ Thenable.addImplementation(Deferred);
* promise will inherit the value of the original input if the callback
* does not throw or return a rejected promise.
* @template PROMISE_TYPE
* @deprecated
*/
function thenFinally(promise, callback) {
if (!isPromise(promise)) {
Expand Down
33 changes: 20 additions & 13 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ class WebDriver {
var result = this.schedule(
new command.Command(command.Name.QUIT),
'WebDriver.quit()');
// Delete our session ID when the quit command finishes; this will allow us to
// throw an error when attemnpting to use a driver post-quit.
return promise.thenFinally(result, () => delete this.session_);
// Delete our session ID when the quit command finishes; this will allow us
// to throw an error when attemnpting to use a driver post-quit.
return result.finally(() => delete this.session_);
}

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

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

/** @override */
this.thenFinally = (cb) => promise.thenFinally(el, cb);
this.finally = el.finally.bind(el);

/** @override */
this.thenFinally = el.finally.bind(el);

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

/** @override */
this.thenFinally = (cb) => promise.thenFinally(alert, cb);
this.finally = alert.finally.bind(alert);

/** @override */
this.thenFinally = alert.finally.bind(alert);

/**
* Defer returning text until the promised alert has been resolved.
Expand Down
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/safari.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class CommandExecutor {
}));
}
var self = this;
return promise.thenFinally(promise.all(tasks), function() {
return promise.all(tasks).finally(function() {
self.server_ = null;
self.socket_ = null;
self.safari_ = null;
Expand Down

0 comments on commit 22cbc24

Please sign in to comment.