SqueakJS icon indicating copy to clipboard operation
SqueakJS copied to clipboard

Improve isAssociation() in vm.primitives.js

Open ccrraaiigg opened this issue 4 years ago • 3 comments

We have a Global in the special objects array, so we can be rather more specific in isAssociation(). This bit me when marshaling a complex object for use with the JS bridge.

ccrraaiigg avatar Mar 30 '21 05:03 ccrraaiigg

Alternatively, we could iterate through the array and make sure every entry is a 2-pointer object and the first of these 2 is a bytes object (ByteSymbol / ByteString).

codefrau avatar Mar 31 '21 01:03 codefrau

Hm, I still would have been bitten. Perhaps we could check both the old and new special objects array cases, and answer true if either of them is a match?

ccrraaiigg avatar Mar 31 '21 21:03 ccrraaiigg

Okay. We could try to find (and maybe cache) LookupKey class by following the superclass chain from the Processor global to the class that has only 1 instance variable:

(Smalltalk specialObjectsArray at: 4) class withAllSuperclasses collect: [:c | c -> c instSize] 

Global->2 Binding->1 LookupKey->1 Magnitude->0 Object->0 ProtoObject->0

Association->2 LookupKey->1 Magnitude->0 Object->0 

So maybe something like

  1. LookupKey = starting at schedAssoc.sqClass, go up superclass chain until we find a class satisfying cls.pointers[0].classInstSize() === 0
  2. Object in question is an Association if its superclass is LookupKey and it has 2 inst vars.

codefrau avatar Mar 31 '21 23:03 codefrau