From 54a9797bd5b13cb6474b6dbcdc3a769862cac42a Mon Sep 17 00:00:00 2001 From: Erwin Mombay Date: Wed, 27 Jul 2016 14:26:26 -0700 Subject: [PATCH 1/2] more xhr type fixes --- src/log.js | 1 + src/service/xhr-impl.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/log.js b/src/log.js index d4ca7e615c24..dfbe4e119923 100644 --- a/src/log.js +++ b/src/log.js @@ -219,6 +219,7 @@ export class Log { * @param {...*} var_args Arguments substituted into %s in the message. * @return {T} The value of shouldBeTrueish. * @template T + * @throws {Error} */ /*eslint "google-camelcase/google-camelcase": 0*/ assert(shouldBeTrueish, opt_message, var_args) { diff --git a/src/service/xhr-impl.js b/src/service/xhr-impl.js index dd5b5e459138..d2a15d9cd46b 100644 --- a/src/service/xhr-impl.js +++ b/src/service/xhr-impl.js @@ -95,7 +95,7 @@ export class Xhr { if (opt_init && opt_init.responseType == 'document') { return fetchPolyfill(input, opt_init); } - return (this.win.fetch || fetchPolyfill).apply(null, arguments); + return fetchPolyfill(input, opt_init); } /** From e49b11c2a8dd75cf04a99c9400c69b42964284e5 Mon Sep 17 00:00:00 2001 From: Erwin Mombay Date: Wed, 27 Jul 2016 16:52:07 -0700 Subject: [PATCH 2/2] v-services type fixes --- src/log.js | 1 - src/observable.js | 6 +++--- src/service/viewer-impl.js | 25 +++++++++++++++++-------- src/service/viewport-impl.js | 6 +++--- src/service/vsync-impl.js | 2 +- src/service/xhr-impl.js | 2 +- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/log.js b/src/log.js index dfbe4e119923..d4ca7e615c24 100644 --- a/src/log.js +++ b/src/log.js @@ -219,7 +219,6 @@ export class Log { * @param {...*} var_args Arguments substituted into %s in the message. * @return {T} The value of shouldBeTrueish. * @template T - * @throws {Error} */ /*eslint "google-camelcase/google-camelcase": 0*/ assert(shouldBeTrueish, opt_message, var_args) { diff --git a/src/observable.js b/src/observable.js index f0621d221dc9..3ad72313b95a 100644 --- a/src/observable.js +++ b/src/observable.js @@ -53,13 +53,13 @@ export class Observable { /** * Fires an event. All observers are called. - * @param {TYPE} event + * @param {TYPE=} opt_event */ - fire(event) { + fire(opt_event) { const handlers = this.handlers_; for (let i = 0; i < handlers.length; i++) { const handler = handlers[i]; - handler(event); + handler(opt_event); } } diff --git a/src/service/viewer-impl.js b/src/service/viewer-impl.js index 6af394a33c26..3fb64475e145 100644 --- a/src/service/viewer-impl.js +++ b/src/service/viewer-impl.js @@ -125,7 +125,7 @@ export class Viewer { /** @private {number} */ this.prerenderSize_ = 1; - /** @private {string} */ + /** @private {!ViewportType} */ this.viewportType_ = ViewportType.NATURAL; /** @private {number} */ @@ -188,7 +188,7 @@ export class Viewer { this.isRuntimeOn_ = !parseInt(this.params_['off'], 10); dev().fine(TAG_, '- runtimeOn:', this.isRuntimeOn_); - this.overtakeHistory_ = parseInt(this.params_['history'], 10) || + this.overtakeHistory_ = !!(parseInt(this.params_['history'], 10)) || this.overtakeHistory_; dev().fine(TAG_, '- history:', this.overtakeHistory_); @@ -237,6 +237,9 @@ export class Viewer { // Wait for document to become visible. this.docState_.onVisibilityChanged(this.recheckVisibilityState_.bind(this)); + /** @private {function()|undefined} */ + this.messagingReadyResolver_ = undefined; + /** * This promise will resolve when communications channel has been * established or timeout in 20 seconds. The timeout is needed to avoid @@ -248,10 +251,10 @@ export class Viewer { timerFor(this.win).timeoutPromise( 20000, new Promise(resolve => { - /** @private @const {function()|undefined} */ this.messagingReadyResolver_ = resolve; })).catch(reason => { - throw getChannelError(reason); + throw getChannelError(/** @type {!Error|string|undefined} */ ( + reason)); }) : null; /** @@ -265,7 +268,8 @@ export class Viewer { this.messagingReadyPromise_ .catch(reason => { // Don't fail promise, but still report. - reportError(getChannelError(reason)); + reportError(getChannelError( + /** @type {!Error|string|undefined} */ (reason))); }) : null; // Trusted viewer and referrer. @@ -283,10 +287,12 @@ export class Viewer { this.isTrustedViewerOrigin_(this.win.location.ancestorOrigins[0])); trustedViewerPromise = Promise.resolve(trustedViewerResolved); } else { + + /** @private {!function(boolean)|undefined} */ + this.trustedViewerResolver_ = undefined; // Wait for comms channel to confirm the origin. trustedViewerResolved = undefined; trustedViewerPromise = new Promise(resolve => { - /** @const @private {!function(boolean)|undefined} */ this.trustedViewerResolver_ = resolve; }); } @@ -294,6 +300,9 @@ export class Viewer { /** @const @private {!Promise} */ this.isTrustedViewer_ = trustedViewerPromise; + /** @private {!function(string)|undefined} */ + this.viewerOriginResolver_ = undefined; + /** @const @private {!Promise} */ this.viewerOrigin_ = new Promise(resolve => { if (!this.isEmbedded()) { @@ -884,7 +893,7 @@ export class Viewer { /** * Requests AMP document to receive a message from Viewer. * @param {string} eventType - * @param {*} data + * @param {!JSONType} data * @param {boolean} unusedAwaitResponse * @return {(!Promise<*>|undefined)} * @export @@ -1081,7 +1090,7 @@ function parseParams_(str, allParams) { /** * Creates an error for the case where a channel cannot be established. - * @param {!Error=} opt_reason + * @param {!Error|string=} opt_reason * @return {!Error} */ function getChannelError(opt_reason) { diff --git a/src/service/viewport-impl.js b/src/service/viewport-impl.js index 8a2c163bbb75..2954f7b11354 100644 --- a/src/service/viewport-impl.js +++ b/src/service/viewport-impl.js @@ -500,8 +500,8 @@ export class Viewport { return null; } if (this.viewportMeta_ === undefined) { - this.viewportMeta_ = this.win_.document.querySelector( - 'meta[name=viewport]'); + this.viewportMeta_ = /** @type {?HTMLMetaElement} */ ( + this.win_.document.querySelector('meta[name=viewport]')); if (this.viewportMeta_) { this.originalViewportMetaString_ = this.viewportMeta_.content; } @@ -1253,7 +1253,7 @@ export function updateViewportMetaString(currentValue, updateParams) { if (params[k] !== updateParams[k]) { changed = true; if (updateParams[k] !== undefined) { - params[k] = updateParams[k]; + params[k] = /** @type {string} */ (updateParams[k]); } else { delete params[k]; } diff --git a/src/service/vsync-impl.js b/src/service/vsync-impl.js index 140698b03b75..3fef0c7a8be8 100644 --- a/src/service/vsync-impl.js +++ b/src/service/vsync-impl.js @@ -125,7 +125,7 @@ export class Vsync { * will be undefined. * * @param {!VsyncTaskSpecDef} task - * @param {VsyncStateDef=} opt_state + * @param {!VsyncStateDef=} opt_state */ run(task, opt_state) { this.tasks_.push(task); diff --git a/src/service/xhr-impl.js b/src/service/xhr-impl.js index d2a15d9cd46b..dd5b5e459138 100644 --- a/src/service/xhr-impl.js +++ b/src/service/xhr-impl.js @@ -95,7 +95,7 @@ export class Xhr { if (opt_init && opt_init.responseType == 'document') { return fetchPolyfill(input, opt_init); } - return fetchPolyfill(input, opt_init); + return (this.win.fetch || fetchPolyfill).apply(null, arguments); } /**