Skip to content

[p5.js 2.0 Bug Report]: Internal calls to p5 functions are checked by FES #7817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 17 tasks
davepagurek opened this issue May 15, 2025 · 0 comments
Open
1 of 17 tasks

Comments

@davepagurek
Copy link
Contributor

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.0.2

Web browser and version

Firefox

Operating system

MacOS

Steps to reproduce this

In this sketch https://editor.p5js.org/davepagurek/sketches/Ty-01oHgN, in the console, you'll see the FES message: "p5.js says: Expected at most 1 argument, but received more in createVector()."

This specific error is due to #7741 and has since been fixed in 2.0.2, but you'll notice the error is about createVector, but the sketch's code does not actually directly call createVector. It is coming from inside of worldToScreen here:

worldPosition = this.createVector(...arguments);

This scenario could be improved for two reasons:

  • If we internally use a non-documented parameter pattern, users will be seeing a warning for code they didn't write and can't change. This seems pretty confusing for them.
  • If we internally use a valid parameter pattern, we are spending extra time checking parameters that should already be correct since it's an internal usage. (If it's incorrect, FES is probably not the right spot to surface the issue anyway.)

My recommendation here is to not run FES parameter checking on internal function calls.

Implementation notes

For synchronous function calls, we can keep track of how deeply nested a function call is by modifying the FES wrapper here:

this[f] = function(...args) {
this.validate(f, args);
return copy.call(this, ...args);
};

...to be something more like this, which keeps track of a nesting level, and only checks params at the first level:

this[f] = function(...args) {
  this.level = (this.level || 0) + 1;
  if (this.level === 1) {
    this.validate(f, args);
  }
  const result = copy.call(this, ...args);
  this.level--;
  return result;
};

This doesn't quite solve the issue for asynchronous functions, since multiple can be running at once, with the runtime jumping back and forth between their execution contexts. Maybe only doing this for synchronous contexts is good enough for now? I'm open to ideas for other implementations that also handle the async case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Work
Development

No branches or pull requests

2 participants