mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

Jhugman math with transform using maps

Open josdejong opened this issue 4 years ago • 2 comments

Followup of #2264: changing mathWithTransform into a LazyMap

This is a work in progress.

  • [ ] Test whether the lazy loading actually works as in functions are loaded only when first used
  • [ ] Think through whether there are unforeseen edge cases
  • [ ] This is a breaking change in the API of rawFunction: there, math is now changed from Object into a Map

josdejong avatar Jul 07 '21 13:07 josdejong

Does there remain any motivation to change mathWithTransform from a plain object into a new LazyMap object with the Map interface? Or should this PR be closed?

gwhitney avatar Oct 28 '25 08:10 gwhitney

I think we should keep this PR open. I totally forgot about it 😅.

The main reason that we did change scope into a Map was for security and extensibility. I think the main reasons for this PR are similar:

  1. This PR changes mathWithTransform from being an object with has "lazy" getters into a Map interface. I think that is less "magic" and easier to grasp.
  2. At the places where we currently use mathWithTransform we need to use getSafeProperty for security reasons. When having a Map, this is not needed anymore so the attack surface becomes a bit smaller.
  3. A map interface is more flexible, it allows for different implementations and and composing maps (like the PartitionedMap implementation)

A downside is that it will be a breaking change: mathWithTransform changes from object to Map.

josdejong avatar Oct 29 '25 07:10 josdejong