codefrau / SqueakJS

A Squeak Smalltalk VM in Javascript
https://squeak.js.org
MIT License
364 stars 75 forks source link

Fix globals reference to allow underlying Dictionary to change #147

Closed ErikOnBike closed 11 months ago

ErikOnBike commented 11 months ago

In my tiny image a lot of code is (i.e. classes are) installed dynamically. The Smalltalk globals Dictionary needs to grow to accommodate these extra classes. The interpreter kept a reference to the globals by using the (pointers to the) Array elements which are part of the SystemDictionary. When a Dictionary needs to grow it will however replace this internal Array with a bigger one. The globals kept referencing the old elements (collection). This fix replaces the globals reference with a getGlobals() getter function which dynamically references the globals (but without having to do the whole search for the actual Dictionary which is needed for the different Smalltalk variants).

codefrau commented 11 months ago

Curious about how you ran into this? The globals "magic" is only supposed to happen during debugging, not during regular execution.

ErikOnBike commented 11 months ago

@codefrau my plugins need to access some standard classes like Dictionary and also some internal classes. I like to use the same access method to retrieve those classes. Therefore I use this global magic at start of the plugin. It worked up till recently, because the order of loading changed a bit. More classes were created before the plugin got loaded and therefore I hit this issue. Thx for merging it. Have a nice day!