MCPcopy
hub / github.com/processing/p5.js / checkForUserDefinedFunctions

Function checkForUserDefinedFunctions

src/core/friendly_errors/fes_core.js:325–363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323 * "global mode" and to a p5 instance in "instance mode"
324 */
325 const checkForUserDefinedFunctions = context => {
326 if (p5.disableFriendlyErrors) return;
327
328 // if using instance mode, this function would be called with the current
329 // instance as context
330 const instanceMode = context instanceof p5;
331 context = instanceMode ? context : window;
332 const fnNames = entryPoints;
333
334 if (context.preload && !p5.isPreloadSupported()) {
335 p5._error(context, translator('fes.preloadDisabled'));
336 }
337
338 const fxns = {};
339 // lowercasename -> actualName mapping
340 fnNames.forEach(symbol => {
341 fxns[symbol.toLowerCase()] = symbol;
342 });
343
344 for (const prop of Object.keys(context)) {
345 const lowercase = prop.toLowerCase();
346
347 // check if the lowercase property name has an entry in fxns, if the
348 // actual name with correct capitalization doesnt exist in context,
349 // and if the user-defined symbol is of the type function
350 if (
351 fxns.hasOwnProperty(lowercase) &&
352 !context[fxns[lowercase]] &&
353 typeof context[prop] === 'function'
354 ) {
355 const msg = translator('fes.checkUserDefinedFns', {
356 name: prop,
357 actualName: fxns[lowercase]
358 });
359
360 p5._friendlyError(msg, fxns[lowercase]);
361 }
362 }
363 };
364
365 /**
366 * Compares the symbol caught in the ReferenceError to everything in

Callers

nothing calls this directly

Calls 2

translatorFunction · 0.90
_friendlyErrorMethod · 0.45

Tested by

no test coverage detected