Permalink
Browse files

Cleanup of JavaScript casts.

The JSCompiler is going to start validate where @type annotations are
allowed and this requires being stricter about casts.  Casts
should be in the form of "/** @type {TypeName} */ (expr)".

R=brenneman
DELTA=35  (0 added, 0 deleted, 35 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=5766


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2268 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
1 parent 7413087 commit 9076e3b7f0f37aab22ae9f98d68c79ee5af8df9e johnlenz@google.com committed Nov 2, 2012
@@ -60,21 +60,21 @@ goog.db.Transaction = function(tx) {
// TODO(user): remove these casts once the externs file is updated to
// correctly reflect that IDBTransaction extends EventTarget
this.eventHandler_.listen(
- (/** @type {EventTarget} */ this.tx_),
+ /** @type {EventTarget} */ (this.tx_),
'complete',
goog.bind(
this.dispatchEvent,
this,
goog.db.Transaction.EventTypes.COMPLETE));
this.eventHandler_.listen(
- (/** @type {EventTarget} */ this.tx_),
+ /** @type {EventTarget} */ (this.tx_),
'abort',
goog.bind(
this.dispatchEvent,
this,
goog.db.Transaction.EventTypes.ABORT));
this.eventHandler_.listen(
- (/** @type {EventTarget} */ this.tx_),
+ /** @type {EventTarget} */ (this.tx_),
'error',
this.dispatchError_);
};
@@ -346,7 +346,7 @@ goog.debug.Trace_.prototype.reset = function(defaultThreshold) {
this.defaultThreshold_ = defaultThreshold;
for (var i = 0; i < this.events_.length; i++) {
- var id = (/** @type {Object} */ this.eventPool_).id;
+ var id = /** @type {Object} */ (this.eventPool_).id;
if (id) {
this.idPool_.releaseObject(id);
}
View
@@ -1232,7 +1232,7 @@ goog.dom.getParentElement = function(element) {
return element.parentElement;
}
var parent = element.parentNode;
- return goog.dom.isElement(parent) ? (/** @type {!Element} */ parent) : null;
+ return goog.dom.isElement(parent) ? /** @type {!Element} */ (parent) : null;
};
@@ -60,8 +60,8 @@ goog.events.MouseWheelHandler = function(element) {
this.element_ = element;
var rtlElement = goog.dom.isElement(this.element_) ?
- (/** @type {Element} */ this.element_) :
- (this.element_ ? (/** @type {Document} */ this.element_).body : null);
+ /** @type {Element} */ (this.element_) :
+ (this.element_ ? /** @type {Document} */ (this.element_).body : null);
/**
* True if the element exists and is RTL, false otherwise.
@@ -144,7 +144,7 @@ goog.gears.Worker.prototype.getId = function() {
*/
goog.gears.Worker.isCommandLike = function(obj) {
return goog.isArray(obj) && obj.length == 2 &&
- goog.isNumber((/** @type {Array} */ obj)[0]);
+ goog.isNumber(/** @type {Array} */ (obj)[0]);
};
@@ -246,7 +246,7 @@ goog.History = function(opt_invisible, opt_blankPageUrl, opt_input,
* @type {HTMLInputElement}
* @private
*/
- this.hiddenInput_ = (/** @type {HTMLInputElement} */ input);
+ this.hiddenInput_ = /** @type {HTMLInputElement} */ (input);
/**
* The window whose location contains the history token fragment. This is
@@ -324,7 +324,7 @@ goog.History = function(opt_invisible, opt_blankPageUrl, opt_input,
* @type {HTMLIFrameElement}
* @private
*/
- this.iframe_ = (/** @type {HTMLIFrameElement} */ iframe);
+ this.iframe_ = /** @type {HTMLIFrameElement} */ (iframe);
/**
* Whether the hidden iframe has had a document written to it yet in this
@@ -188,10 +188,10 @@ goog.json.Serializer.prototype.serialize = function(object) {
goog.json.Serializer.prototype.serialize_ = function(object, sb) {
switch (typeof object) {
case 'string':
- this.serializeString_((/** @type {string} */ object), sb);
+ this.serializeString_(/** @type {string} */ (object), sb);
break;
case 'number':
- this.serializeNumber_((/** @type {number} */ object), sb);
+ this.serializeNumber_(/** @type {number} */ (object), sb);
break;
case 'boolean':
sb.push(object);
@@ -205,13 +205,13 @@ goog.json.Serializer.prototype.serialize_ = function(object, sb) {
break;
}
if (goog.isArray(object)) {
- this.serializeArray((/** @type {!Array} */ object), sb);
+ this.serializeArray(/** @type {!Array} */ (object), sb);
break;
}
// should we allow new String, new Number and new Boolean to be treated
// as string, number and boolean? Most implementations do not and the
// need is not very big
- this.serializeObject_((/** @type {Object} */ object), sb);
+ this.serializeObject_(/** @type {Object} */ (object), sb);
break;
case 'function':
// Skip functions.
@@ -186,8 +186,8 @@ goog.messaging.RespondingChannel.prototype.callbackServiceHandler_ = function(
var result = message['data'];
if (signature in this.sigCallbackMap_) {
- var callback = /** @type {function(Object)} */ this.sigCallbackMap_[
- signature];
+ var callback = /** @type {function(Object)} */ (this.sigCallbackMap_[
+ signature]);
callback(result);
delete this.sigCallbackMap_[signature];
} else {
@@ -418,7 +418,7 @@ goog.net.WebSocket.prototype.onMessage_ = function(event) {
* @private
*/
goog.net.WebSocket.prototype.onError_ = function(event) {
- var data = /** @type {string} */ event.data;
+ var data = /** @type {string} */ (event.data);
this.logger_.severe('An error occurred: ' + data);
this.dispatchEvent(new goog.net.WebSocket.ErrorEvent(data));
};
@@ -123,8 +123,8 @@ goog.net.XmlHttp.factory_;
*/
goog.net.XmlHttp.setFactory = function(factory, optionsFactory) {
goog.net.XmlHttp.setGlobalFactory(new goog.net.WrapperXmlHttpFactory(
- (/** @type {function() : !(XMLHttpRequest|GearsHttpRequest)} */ factory),
- (/** @type {function() : !Object}*/ optionsFactory)));
+ /** @type {function() : !(XMLHttpRequest|GearsHttpRequest)} */ (factory),
+ /** @type {function() : !Object}*/ (optionsFactory)));
};
@@ -644,7 +644,7 @@ goog.proto2.Message.prototype.array$Values = function(tag) {
var field = this.getFieldByTag_(tag);
var value = this.getValueForField_(field);
goog.proto2.Util.assert(value == null || goog.isArray(value));
- return (/** @type {Array} */value) || [];
+ return /** @type {Array} */ (value) || [];
};
@@ -195,7 +195,7 @@ goog.proto2.TextFormatSerializer.prototype.printFieldValue_ =
case goog.proto2.FieldDescriptor.FieldType.GROUP:
case goog.proto2.FieldDescriptor.FieldType.MESSAGE:
this.serializeMessage_(
- (/** @type {goog.proto2.Message} */value), printer);
+ /** @type {goog.proto2.Message} */ (value), printer);
break;
}
};
@@ -486,7 +486,7 @@ goog.proto2.TextFormatSerializer.Tokenizer_.prototype.nextInternal_ =
// Advance the index by the length of the token.
if (next) {
this.current_ =
- (/** @type {goog.proto2.TextFormatSerializer.Tokenizer_.Token} */next);
+ /** @type {goog.proto2.TextFormatSerializer.Tokenizer_.Token} */ (next);
this.index_ += next.value.length;
this.currentData_ = this.currentData_.substring(next.value.length);
}
@@ -150,7 +150,7 @@ goog.structs.clear = function(col) {
if (typeof col.clear == 'function') {
col.clear();
} else if (goog.isArrayLike(col)) {
- goog.array.clear((/** @type {goog.array.ArrayLike} */ col));
+ goog.array.clear(/** @type {goog.array.ArrayLike} */ (col));
} else {
goog.object.clear(col);
}
@@ -133,7 +133,7 @@ goog.testing.PerformanceTable.prototype.round_ = function(num) {
*/
goog.testing.PerformanceTable.prototype.run = function(fn, opt_desc) {
this.runTask(
- new goog.testing.PerformanceTimer.Task((/** @type {function()} */ fn)),
+ new goog.testing.PerformanceTimer.Task(/** @type {function()} */ (fn)),
opt_desc);
};
@@ -140,7 +140,7 @@ goog.testing.PerformanceTimer.prototype.isDiscardOutliers = function() {
*/
goog.testing.PerformanceTimer.prototype.run = function(testFn) {
return this.runTask(new goog.testing.PerformanceTimer.Task(
- (/** @type {goog.testing.PerformanceTimer.TestFunction} */ testFn)));
+ /** @type {goog.testing.PerformanceTimer.TestFunction} */ (testFn)));
};
@@ -77,7 +77,7 @@ goog.ui.DimensionPickerRenderer.prototype.getUnderlyingDiv_ = function(
*/
goog.ui.DimensionPickerRenderer.prototype.getHighlightDiv_ = function(
element) {
- return /** @type {Element} */ element.firstChild.lastChild;
+ return /** @type {Element} */ (element.firstChild.lastChild);
};
@@ -101,7 +101,7 @@ goog.ui.DimensionPickerRenderer.prototype.getStatusDiv_ = function(
*/
goog.ui.DimensionPickerRenderer.prototype.getMouseCatcher_ = function(
element) {
- return /** @type {Element} */ element.firstChild.firstChild;
+ return /** @type {Element} */ (element.firstChild.firstChild);
};
@@ -114,7 +114,7 @@ goog.ui.emoji.EmojiPaletteRenderer.prototype.updateAnimatedPaletteItem =
// now being updated. See createPaletteItem for the structure of the palette
// items we're modifying.
- var inner = (/** @type {Element} */ item.firstChild);
+ var inner = /** @type {Element} */ (item.firstChild);
// The first case is a palette item with a CSS class representing the sprite,
// and an animated emoji.
@@ -78,7 +78,7 @@ goog.ui.emoji.ProgressiveEmojiPaletteRenderer.prototype.
var el = item.firstChild;
while (el) {
if ('IMG' == el.tagName) {
- img = (/** @type {Element} */ el);
+ img = /** @type {Element} */ (el);
break;
}
el = el.firstChild;
@@ -139,16 +139,16 @@ goog.ui.SplitBehavior.CSS_CLASS = goog.getCssName('goog-split-behavior');
goog.ui.SplitBehavior.DefaultHandlers = {
NONE: goog.nullFunction,
CAPTION: function(targetControl, e) {
- var item = (/** @type {goog.ui.MenuItem} */e.target);
+ var item = /** @type {goog.ui.MenuItem} */ (e.target);
var value = (/** @type {string} */((item && item.getValue()) || ''));
- var button = (/** @type {goog.ui.Button} */targetControl);
+ var button = /** @type {goog.ui.Button} */ (targetControl);
button.setCaption && button.setCaption(value);
button.setValue && button.setValue(value);
},
VALUE: function(targetControl, e) {
- var item = (/** @type {goog.ui.MenuItem} */e.target);
+ var item = /** @type {goog.ui.MenuItem} */ (e.target);
var value = (/** @type {string} */(item && item.getValue()) || '');
- var button = (/** @type {goog.ui.Button} */targetControl);
+ var button = /** @type {goog.ui.Button} */ (targetControl);
button.setValue && button.setValue(value);
}
};
@@ -943,7 +943,7 @@ goog.vec.Matrix4.multVec4 = function(mat, vec, resultVec) {
*/
goog.vec.Matrix4.multVec3ToArray = function(mat, vec, resultVec) {
goog.vec.Matrix4.multVec3(
- mat, vec, (/** @type {goog.vec.ArrayType} */ resultVec));
+ mat, vec, /** @type {goog.vec.ArrayType} */ (resultVec));
return resultVec;
};
@@ -962,7 +962,7 @@ goog.vec.Matrix4.multVec3ToArray = function(mat, vec, resultVec) {
*/
goog.vec.Matrix4.multVec4ToArray = function(mat, vec, resultVec) {
goog.vec.Matrix4.multVec4(
- mat, vec, (/** @type {goog.vec.ArrayType} */ resultVec));
+ mat, vec, /** @type {goog.vec.ArrayType} */ (resultVec));
return resultVec;
};

0 comments on commit 9076e3b

Please sign in to comment.