(e, log)
| 13277 | } |
| 13278 | |
| 13279 | function helpForMisusedAtTopLevelCode(e, log) { |
| 13280 | if (!log) { |
| 13281 | log = console.log.bind(console); |
| 13282 | } |
| 13283 | |
| 13284 | if (!misusedAtTopLevelCode) { |
| 13285 | defineMisusedAtTopLevelCode(); |
| 13286 | } |
| 13287 | |
| 13288 | // If we find that we're logging lots of false positives, we can |
| 13289 | // uncomment the following code to avoid displaying anything if the |
| 13290 | // user's code isn't likely to be using p5's global mode. (Note that |
| 13291 | // setup/draw are more likely to be defined due to JS function hoisting.) |
| 13292 | // |
| 13293 | //if (!('setup' in window || 'draw' in window)) { |
| 13294 | // return; |
| 13295 | //} |
| 13296 | |
| 13297 | misusedAtTopLevelCode.some(function(symbol) { |
| 13298 | // Note that while just checking for the occurrence of the |
| 13299 | // symbol name in the error message could result in false positives, |
| 13300 | // a more rigorous test is difficult because different browsers |
| 13301 | // log different messages, and the format of those messages may |
| 13302 | // change over time. |
| 13303 | // |
| 13304 | // For example, if the user uses 'PI' in their code, it may result |
| 13305 | // in any one of the following messages: |
| 13306 | // |
| 13307 | // * 'PI' is undefined (Microsoft Edge) |
| 13308 | // * ReferenceError: PI is undefined (Firefox) |
| 13309 | // * Uncaught ReferenceError: PI is not defined (Chrome) |
| 13310 | |
| 13311 | if (e.message && e.message.match('\\W?'+symbol.name+'\\W') !== null) { |
| 13312 | log('%cDid you just try to use p5.js\'s ' + symbol.name + |
| 13313 | (symbol.type === 'function' ? '() ' : ' ') + symbol.type + |
| 13314 | '? If so, you may want to ' + |
| 13315 | 'move it into your sketch\'s setup() function.\n\n' + |
| 13316 | 'For more details, see: ' + FAQ_URL, |
| 13317 | 'color: #B40033' /* Dark magenta */); |
| 13318 | return true; |
| 13319 | } |
| 13320 | }); |
| 13321 | } |
| 13322 | |
| 13323 | // Exposing this primarily for unit testing. |
| 13324 | p5.prototype._helpForMisusedAtTopLevelCode = helpForMisusedAtTopLevelCode; |
nothing calls this directly
no test coverage detected