ajax333221 / isepic-chess

♞ JavaScript chess utility library.
MIT License
16 stars 3 forks source link

fenGet() referenced values #36

Closed ajax333221 closed 1 year ago

ajax333221 commented 2 years ago

We should kill all the references before returning the values to prevent unwanted behavior.

Currently, the board properties that are Object type (objects and arrays) that might be affected are:

The temporal board where they come gets deleted and it is not clear what happens next to these pass-by-reference values.

ajax333221 commented 1 year ago

the function _cloneBoardObjs() kills all references, maybe we can reuse this function.

ajax333221 commented 1 year ago

_cloneBoardObjs() was renamed to _cloneBoardToObj(), it now returns the object it is being copied to and makes a test to make sure the board it is being copied from is actually a board. It now also copies all values (including the static ones that were previously being ignored to increase performance).

There was something tricky with w, b and squares because when doing the overwrite, some perparations had to be done that were not there.

so the references are getting unreferenced by running this line inside fenGet():

board = _cloneBoardToObj({ boardName: 'fake_board_fenGet' }, board);