Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1343)

Unified Diff: Source/devtools/scripts/jsdoc-validator/tests/this.js

Issue 137553005: DevTools: [JsDocValidator] Refactor JsDoc annotation checkers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments from sergeyv Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/scripts/jsdoc-validator/tests/return.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/scripts/jsdoc-validator/tests/this.js
diff --git a/Source/devtools/scripts/jsdoc-validator/tests/this.js b/Source/devtools/scripts/jsdoc-validator/tests/this.js
new file mode 100644
index 0000000000000000000000000000000000000000..9d23f4acb88930c4a2cfd6a817bf671e50912cb0
--- /dev/null
+++ b/Source/devtools/scripts/jsdoc-validator/tests/this.js
@@ -0,0 +1,175 @@
+this.foo = this.foo + 1; // OK - outside of function.
+
+function f() {
+ this.foo = this.foo + 1; // OK - global |this|.
+}
+
+/**
+ * @constructor
+ */
+function TypeOne() {
+ this.foo = this.foo + 1; // OK - object field in ctor.
+
+ /**
+ * @this {TypeOne}
+ */
+ function callbackOne() {
+ this.foo = this.foo + 1; // OK - @this declared.
+
+ function badInnerCallback() {
+ this.foo = this.foo + 2; // ERROR - @this not declared.
+ }
+ }
+
+ function badCallbackInCtor() {
+ this.foo = this.foo + 1; // ERROR - @this not declared.
+ }
+}
+
+TypeOne.prototype = {
+ addListener: function(callback)
+ {
+ if (typeof callback !== "function")
+ throw "addListener: callback is not a function";
+ if (this._listeners.length === 0)
+ extensionServer.sendRequest({ command: commands.Subscribe, type: this._type });
+ this._listeners.push(callback);
+ extensionServer.registerHandler("notify-" + this._type, this._dispatch.bind(this));
+ },
+
+ funcOne: function() {
+ this.foo = this.foo + 1; // OK - in method.
+ },
+
+ funcTwo: function() {
+ /**
+ * @this {TypeOne}
+ */
+ function callback() {
+ this.foo = this.foo + 1; // OK - @this declared.
+ }
+ },
+
+ funcThree: function() {
+ function badCallbackInMethod() {
+ this.foo = this.foo + 1; // ERROR - @this not declared.
+ }
+ }
+}
+
+
+/**
+ * @constructor
+ */
+TypeTwo = function() {
+ this.bar = this.bar + 1; // OK - object field in ctor.
+
+ /**
+ * @this {TypeTwo}
+ */
+ function callbackOne() {
+ this.bar = this.bar + 1; // OK - @this declared.
+
+ function badInnerCallback() {
+ this.bar = this.bar + 2; // ERROR - @this not declared.
+ }
+ }
+
+ function badCallbackInCtor() {
+ this.bar = this.bar + 1; // ERROR - @this not declared.
+ }
+}
+
+TypeTwo.prototype = {
+ funcOne: function() {
+ this.bar = this.bar + 1; // OK - in method.
+ },
+
+ funcTwo: function() {
+ /**
+ * @this {TypeTwo}
+ */
+ function callback() {
+ this.bar = this.bar + 1; // OK - @this declared.
+ }
+ },
+
+ funcThree: function() {
+ function badCallbackInMethod() {
+ this.bar = this.bar + 1; // ERROR - @this not declared.
+ }
+ }
+}
+
+/**
+ * @return {!Object}
+ */
+function returnConstructedObject() {
+
+/**
+ * @constructor
+ */
+TypeThree = function() {
+ this.bar = this.bar + 1; // OK - object field in ctor.
+
+ /**
+ * @this {TypeThree}
+ */
+ function callbackOne() {
+ this.bar = this.bar + 1; // OK - @this declared.
+
+ function badInnerCallback() {
+ this.bar = this.bar + 2; // ERROR - @this not declared.
+ }
+ }
+
+ function badCallbackInCtor() {
+ this.bar = this.bar + 1; // ERROR - @this not declared.
+ }
+}
+
+TypeThree.prototype = {
+ funcOne: function() {
+ this.bar = this.bar + 1; // OK - in method.
+ },
+
+ funcTwo: function() {
+ /**
+ * @this {TypeThree}
+ */
+ function callback() {
+ this.bar = this.bar + 1; // OK - @this declared.
+ }
+ },
+
+ funcThree: function() {
+ function badCallbackInMethod() {
+ this.bar = this.bar + 1; // ERROR - @this not declared.
+ }
+ }
+}
+
+return new TypeThree();
+}
+
+var object = {
+ /**
+ * @this {MyType}
+ */
+ value: function()
+ {
+ this.foo = 1; // OK - @this annotated.
+ }
+};
+
+(function() {
+ var object = {
+ /**
+ * @this {MyType}
+ */
+ value: function()
+ {
+ this.foo = 1; // OK - @this annotated.
+ }
+ };
+})();
« no previous file with comments | « Source/devtools/scripts/jsdoc-validator/tests/return.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698