@@ -60,24 +60,28 @@ define(function (require, exports, module) {
6060 * @param {!string } message The deprecation message to be displayed.
6161 * @param {boolean= } oncePerCaller If true, displays the message once for each unique call location.
6262 * If false (the default), only displays the message once no matter where it's called from.
63+ * Note that setting this to true can cause a slight performance hit (because it has to generate
64+ * a stack trace), so don't set this for functions that you expect to be called from performance-
65+ * sensitive code (e.g. tight loops).
6366 */
64- function deprecationWarning ( message , oncePerCall ) {
67+ function deprecationWarning ( message , oncePerCaller ) {
68+ // If oncePerCaller isn't set, then only show the message once no matter who calls it.
69+ if ( ! message || ( ! oncePerCaller && displayedWarnings [ message ] ) ) {
70+ return ;
71+ }
72+
73+ // Don't show the warning again if we've already gotten it from the current caller.
6574 // The true caller location is the fourth line in the stack trace:
6675 // * 0 is the word "Error"
6776 // * 1 is this function
6877 // * 2 is the caller of this function (the one throwing the deprecation warning)
6978 // * 3 is the actual caller of the deprecated function.
7079 var stack = new Error ( ) . stack ,
7180 callerLocation = stack . split ( "\n" ) [ 3 ] ;
72-
73- // If we have displayed this message before, then don't
74- // show it again.
75- if ( ! message ||
76- ( ! oncePerCall && displayedWarnings [ message ] ) ||
77- ( oncePerCall && displayedWarnings [ message ] && displayedWarnings [ message ] [ callerLocation ] ) ) {
81+ if ( oncePerCaller && displayedWarnings [ message ] && displayedWarnings [ message ] [ callerLocation ] ) {
7882 return ;
7983 }
80-
84+
8185 console . warn ( message + "\n" + _trimStack ( stack ) ) ;
8286 if ( ! displayedWarnings [ message ] ) {
8387 displayedWarnings [ message ] = { } ;
0 commit comments