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

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: Limit the thread count by the number of validated files 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
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..b735b70625e52df53c53cdebbf31ed2262d1cb49
--- /dev/null
+++ b/Source/devtools/scripts/jsdoc-validator/tests/this.js
@@ -0,0 +1,153 @@
+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();
+}

Powered by Google App Engine
This is Rietveld 408576698