[squeak-dev] Request for feedback: mirrors

Frank Shearar frank.shearar at gmail.com
Tue May 22 10:09:27 UTC 2012


On 22 May 2012 08:07, Colin Putney <colin at wiresong.com> wrote:
> Hi all,
>
> I've just uploaded a package to the Inbox for review by the community:
>
> http://source.squeak.org/inbox/Mirrors-cwp.2.mcz
>
> It's a simple first step at creating a mirror API for Squeak. I've only
> implemented ObjectMirror and ObjectVmMirror, which provide high- and
> low-level reflection on an object. This implementation has a twist, however:
> it sends no messages to the object it's reflecting. That allows us to
> reflect on network proxies, ORM stubs, mock objects and the like without
> triggering any state changes.
>
> As a proof of the concept, I've implemented a rudimentary non-invasive
> MirrorInspector. The main thing that's missing is non-invasive printing,
> which would take a bit of work to implement, but isn't necessary for a demo.
> To see it in action do try the following in a workspace.
>
> WARNING: Read the comments carefully, and don't do this in an image you care
> about!
>
> "This creates a very dangerous object"
> Object subclass: #Nuke
> instanceVariableNames: 'one two three'
> classVariableNames: ''
> poolDictionaries: ''
> category: 'Test'.
> class := Smalltalk at: #Nuke.
> class superclass: nil.
> inst := class basicNew.
>
> "This is harmless"
> MirrorInspector inspect: inst.
>
> "This will crash your image"
> inst yourself.
>
> The implementation uses primitive 188 to directly execute CompiledMethods
> with the reflected object as the receiver, thus giving us access to the
> object's state without sending it a message.
>
> So, what do you think?

MessageShunt can't load because it has a nil superclass, causing an
MNU for #allowsSubInstVars in ClassBuilder >>
#validateInstVars:from:forSuper: because the last arg - newSuper - is
nil.

frank

> Colin


More information about the Squeak-dev mailing list