Alternate design to implementing & testing jsnums#1839
Alternate design to implementing & testing jsnums#1839
Conversation
…stead of take them as explicit arguments everywhere
…er jsnums changes)
…dules obtain the correct jsnums library that now closes over an appropriate errbacks parameter
…hadowed the one we're trying to use.
…n array of values as second argument
|
Makes me a bit nervous that we have to make sure we account for every client of js-numbers here, because it is no longer exporting a bunch of functions it used to. Is there a way to do this that is backwards-compatible? Like, maybe all the existing functions are also exported, with an errbacks argument, and they call Sketch: |
|
Properties this has:
|
|
I don't think that will quite work, because Do we have any library authors who write native JS libraries for Pyret that we're not aware of? Because if not, then as of this PR (and the counterpart for CPO), the only mentions of and |
|
Re: “it's not hard to find all the uses”. What about pyret-embed? What about pyret-npm? What about the Thinking more about the design options here. |
|
A few ideas that would make me more comfortable:
|
|
To be clear this PR is a vast improvement in ergonomics. I just really, really don't want to have some 5-alarm fire because we broke an interface that we didn't know something relies on (could be something we wrote and forgot about! could be a huge pain of a built file sitting in someone's |
|
Fair points.
I'm not sure I completely understand your latest suggestion, yet. Will think about it more... |
In case this is a useful data point: Neither Brown's nor NEU's autograder repos use pyret-lang's js-numbers.js as a JS library. |
Expose every non-class top-level Numbers function at the module level, each wrapped with a parameterize-style save/setErrbacks/restore so callers can optionally supply their own errbacks as a trailing argument without having to instantiate their own library. Co-Authored-By: Ben Lerner <benjamin.lerner@gmail.com> Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
@blerner I think this is good to merge. Thanks for going through my roundabout complaints, I'm happy with where this landed now. I think that the way this is set up now, the only case this will be backwards incompatible for on expected behavior is if some code was:
If they were doing all of that, they will get the default errbacks that throw raw JS errors instead of their custom errbacks. In all other ways this is backwards-compatible if you were using the library correctly. This does change the expected use of the library a bit (which is generally all internal anyway), to use the instantiated API on runtime configured with the “right” Pyret errbacks. But it shouldn't suddenly break for someone using it the “old” way. The only other backwards incompatibilities should only apply to uses that were incorrectly not providing errbacks anyway, so it's hard to blame us for changing their error behavior. |
Alternate design to #1818, where instead of manually placing
errbacksparameters everywhere throughout the code, and where even a single missederrbacksargument could be a brittle and hard-to-find failure later, this one changes js-numbers to only expose a module-creating function that closes over theerrbacksparameter, and exports the createdjsnumsinstance as a field onruntime-- so that modules that previously imported jsnums directly can now access it off their respective runtimes.I've pulled in the tests from #1818, and they all pass, and I think I've pulled in any substantive changes to runtime.js as well.