Skip to content

Commit 9a554af

Browse files
committed
Fix up JS types
1 parent 25d1823 commit 9a554af

File tree

4 files changed

+43
-30
lines changed

4 files changed

+43
-30
lines changed

javascript/safari-driver/extension/server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ safaridriver.extension.Server.prototype.execute = function(
305305
if (!handler) {
306306
this.logMessage_('Unknown command: ' + command.getName(),
307307
goog.log.Logger.Level.SEVERE);
308-
return webdriver.promise.rejected(bot.response.createErrorResponse(
309-
Error('Unknown command: ' + command.getName())));
308+
return webdriver.promise.rejected(
309+
Error('Unknown command: ' + command.getName()));
310310
}
311311

312312
var description = this.session_.getId() + '::' + command.getName();

javascript/safari-driver/inject/page/page.js

+14-17
Original file line numberDiff line numberDiff line change
@@ -248,29 +248,26 @@ safaridriver.inject.page.onCommand_ = function(message, e) {
248248
}
249249

250250
var command = message.getCommand();
251-
252-
var response = new webdriver.promise.Deferred();
253-
// When the response is resolved, we want to wrap it up in a message and
254-
// send it back to the injected script. This does all that.
255-
response.then(function(value) {
256-
var encodedValue = safaridriver.inject.page.encoder.encode(value);
257-
// If the command result contains any DOM elements from another
258-
// document, the encoded value will contain promises that will resolve
259-
// once the owner documents have encoded the elements. Therefore, we
260-
// must wait for those to resolve.
261-
return webdriver.promise.fullyResolved(encodedValue);
262-
}).then(bot.response.createResponse, bot.response.createErrorResponse).
263-
then(function(response) {
251+
safaridriver.inject.CommandRegistry.getInstance()
252+
.execute(command, goog.global)
253+
// When the response is resolved, we want to wrap it up in a message and
254+
// send it back to the injected script. This does all that.
255+
.then(function(value) {
256+
var encodedValue = safaridriver.inject.page.encoder.encode(value);
257+
// If the command result contains any DOM elements from another
258+
// document, the encoded value will contain promises that will resolve
259+
// once the owner documents have encoded the elements. Therefore, we
260+
// must wait for those to resolve.
261+
return webdriver.promise.fullyResolved(encodedValue);
262+
})
263+
.then(bot.response.createResponse, bot.response.createErrorResponse)
264+
.then(function(response) {
264265
var responseMessage = new safaridriver.message.Response(
265266
command.getId(), response);
266267
goog.log.fine(safaridriver.inject.page.LOG_,
267268
'Sending ' + command.getName() + ' response: ' + responseMessage);
268269
responseMessage.send(window);
269270
});
270-
271-
safaridriver.inject.CommandRegistry.getInstance()
272-
.execute(command, goog.global)
273-
.then(response.fulfill, response.reject);
274271
};
275272

276273

javascript/safari-driver/inject/tab.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ safaridriver.inject.Tab.prototype.installPageScript_ = function(opt_dom) {
586586
var docEl = dom.getDocument().documentElement;
587587
goog.dom.appendChild(docEl, script);
588588

589-
this.installedPageScript_.thenFinally(function() {
589+
this.installedPageScript_.promise.thenFinally(function() {
590590
goog.dom.removeNode(script);
591591
});
592592
}, this));
@@ -622,7 +622,7 @@ safaridriver.inject.Tab.prototype.executeInPage = function(command) {
622622

623623
message.send(window);
624624

625-
return commandResponse.then(function(result) {
625+
return commandResponse.promise.then(function(result) {
626626
return bot.inject.wrapValue(result);
627627
});
628628
}, this));

javascript/webdriver/promise.js

+25-9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ goog.inherits(webdriver.promise.CancellationError, goog.debug.Error);
8484
* used to schedule callbacks on a promised value.
8585
*
8686
* @interface
87+
* @extends {IThenable.<T>}
8788
* @template T
8889
*/
8990
webdriver.promise.Thenable = function() {};
@@ -108,7 +109,7 @@ webdriver.promise.Thenable.prototype.isPending = function() {};
108109
* @param {?(function(T): (R|webdriver.promise.Promise.<R>))=} opt_callback The
109110
* function to call if this promise is successfully resolved. The function
110111
* should expect a single argument: the promise's resolved value.
111-
* @param {?(function(Error): (R|webdriver.promise.Promise.<R>))=} opt_errback
112+
* @param {?(function(*): (R|webdriver.promise.Promise.<R>))=} opt_errback
112113
* The function to call if this promise is rejected. The function should
113114
* expect a single argument: the rejection reason.
114115
* @return {!webdriver.promise.Promise.<R>} A new promise which will be
@@ -136,7 +137,7 @@ webdriver.promise.Thenable.prototype.then = function(
136137
* });
137138
* </code></pre>
138139
*
139-
* @param {function(Error): (R|webdriver.promise.Promise.<R>)} errback The
140+
* @param {function(*): (R|webdriver.promise.Promise.<R>)} errback The
140141
* function to call if this promise is rejected. The function should
141142
* expect a single argument: the rejection reason.
142143
* @return {!webdriver.promise.Promise.<R>} A new promise which will be
@@ -249,6 +250,12 @@ webdriver.promise.Thenable.isImplementation = function(object) {
249250
* fulfilled or rejected state, at which point the promise is considered
250251
* resolved.
251252
*
253+
* @param {function(
254+
* function((T|IThenable.<T>|Thenable)=),
255+
* function(*=))} resolver
256+
* Function that is invoked immediately to begin computation of this
257+
* promise's value. The function should accept a pair of callback functions,
258+
* one for fulfilling the promise and another for rejecting it.
252259
* @param {webdriver.promise.ControlFlow=} opt_flow The control flow
253260
* this instance was created under. Defaults to the currently active flow.
254261
* @constructor
@@ -531,14 +538,22 @@ webdriver.promise.Deferred = function(opt_flow) {
531538
}
532539
};
533540

534-
this.fulfill = function(value) {
535-
checkNotSelf(value);
536-
fulfill(value);
541+
/**
542+
* Resolves this deferred with the given value.
543+
* @param {(T|IThenable.<T>|Thenable)=} opt_value The fulfilled value.
544+
*/
545+
this.fulfill = function(opt_value) {
546+
checkNotSelf(opt_value);
547+
fulfill(opt_value);
537548
};
538549

539-
this.reject = function(reason) {
540-
checkNotSelf(reason);
541-
reject(reason);
550+
/**
551+
* Rejects this promise with the given reason.
552+
* @param {*=} opt_reason The rejection reason.
553+
*/
554+
this.reject = function(opt_reason) {
555+
checkNotSelf(opt_reason);
556+
reject(opt_reason);
542557
};
543558
};
544559
webdriver.promise.Thenable.addImplementation(webdriver.promise.Deferred);
@@ -1587,10 +1602,11 @@ webdriver.promise.ControlFlow.prototype.abortFrame_ = function(error) {
15871602
* returned promise will be rejected.
15881603
*
15891604
* @param {!Function} fn The function to execute.
1590-
* @param {function(*)} callback The function to call with a successful result.
1605+
* @param {function(T)} callback The function to call with a successful result.
15911606
* @param {function(*)} errback The function to call if there is an error.
15921607
* @param {boolean=} opt_activate Whether the active frame should be updated to
15931608
* the newly created frame so tasks are treated as sub-tasks.
1609+
* @template T
15941610
* @private
15951611
*/
15961612
webdriver.promise.ControlFlow.prototype.runInNewFrame_ = function(

0 commit comments

Comments
 (0)