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

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

Issue 202813004: DevTools: [JsDocValidator] Make sure function receivers agree with @this annotations (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address misunderstood comments Created 6 years, 9 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/golden.dat ('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
index 9d23f4acb88930c4a2cfd6a817bf671e50912cb0..16af46a6d39a0951cf3dc87394fb6ea3ae6c9e4d 100644
--- a/Source/devtools/scripts/jsdoc-validator/tests/this.js
+++ b/Source/devtools/scripts/jsdoc-validator/tests/this.js
@@ -146,6 +146,13 @@ TypeThree.prototype = {
function badCallbackInMethod() {
this.bar = this.bar + 1; // ERROR - @this not declared.
}
+
+ /**
+ * @this {TypeOne}
+ */
+ function callbackNotReferencingThis() {
+ return 3; // ERROR - @this for a function not referencing |this|.
+ }
}
}
@@ -173,3 +180,55 @@ var object = {
}
};
})();
+
+/**
+ * @constructor
+ */
+var ReceiverTest = function() {}
+
+ReceiverTest.prototype = {
+ memberOne: function() {
+ var badMemberBinding1 = this.memberTwo.bind(null); // ERROR - Member not bound to |this| receiver.
+ var badMemberBinding2 = this.memberTwo.bind(bar); // ERROR - Member not bound to |this| receiver.
+ var goodMemberBinding = this.memberTwo.bind(this);
+
+ /** @this {ReceiverTest} */
+ function callbackWithThis()
+ {
+ this.memberTwo();
+ }
+
+ function callbackNoThis()
+ {
+ return 42;
+ }
+
+ callbackWithThis.call(this);
+ callbackWithThis.call(foo);
+ callbackNoThis();
+ callbackNoThis.call(null, 1);
+ callbackNoThis.apply(null, [2]);
+ callbackNoThis.bind(null, 1);
+ this.memberTwo(callbackWithThis.bind(this, 1));
+ this.memberTwo(callbackWithThis.bind(foo, 1));
+ this.memberTwo(callbackNoThis);
+ this.memberTwo(callbackNoThis.bind(null));
+
+ callbackWithThis(); // ERROR - No receiver.
+ callbackWithThis.call(); // ERROR - No receiver.
+ callbackWithThis.call(null); // ERROR - No receiver.
+ callbackWithThis.apply(); // ERROR - No receiver.
+ callbackWithThis.apply(null); // ERROR - No receiver.
+ callbackNoThis.call(this); // ERROR - Function has no @this annotation.
+ callbackNoThis.call(foo); // ERROR - Function has no @this annotation.
+ callbackNoThis.apply(this); // ERROR - Function has no @this annotation.
+ callbackNoThis.bind(this); // ERROR - Function has no @this annotation.
+
+ this.memberTwo(callbackWithThis); // ERROR - Used as argument with no bound receiver.
+ this.memberTwo(callbackWithThis.bind(null, 2)); // ERROR - Used as argument with no bound receiver (null means "no receiver").
+ this.memberTwo(callbackNoThis.bind(this)); // ERROR - Bound to a receiver but has no @this annotation.
+ this.memberTwo(callbackNoThis.bind(foo)); // ERROR - Bound to a receiver but has no @this annotation.
+ },
+
+ memberTwo: function(arg) {}
+}
« no previous file with comments | « Source/devtools/scripts/jsdoc-validator/tests/golden.dat ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698