JavaContext.st
branchdevelopment
changeset 2650 5f8857840a1e
parent 2532 64a784c73d1e
child 2711 a00302fe5083
child 2726 6971720de5a4
--- a/JavaContext.st	Fri Aug 09 02:13:58 2013 +0100
+++ b/JavaContext.st	Fri Aug 09 02:35:21 2013 +0100
@@ -358,6 +358,54 @@
     "Modified: / 17-11-2011 / 19:13:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 !
 
+methodFromClass
+    "Return the up-to-date method. Actyally, it fetches the method
+     from receiver's class"
+
+    |c sender sendersSelector m|
+
+    "mhmh - maybe I am a context for an unbound method (as generated by doIt);
+     look in the sender's context. Consider this a kludge.
+     Future versions of ST/X's message lookup may store the method in
+     the context.
+    "
+    sender := self sender.
+    sender notNil ifTrue:[
+        sendersSelector := sender selector.
+        sendersSelector notNil ifTrue:[
+            (sendersSelector startsWith:'valueWithReceiver:') ifTrue:[
+                m := sender receiver.
+                m isMethod ifTrue:[
+                    method := m.
+                    ^ m
+                ]
+            ]
+        ]
+    ].
+
+    c := self searchClass.
+    "
+     the below cannot happen in normal circumstances
+     (added to avoid recursive errors in case of a broken sender chain)
+    "
+    c isBehavior ifFalse:[
+        'Context [error]: non class in searchClass' errorPrintCR.
+        '      selector: ' errorPrint. selector errorPrint.
+        ' receiver: ' errorPrint. receiver errorPrintCR.
+        ^ nil
+    ].
+
+    c := c whichClassIncludesSelector:selector.
+    c notNil ifTrue:[
+        method := c compiledMethodAt:selector.
+        ^ method
+    ].
+
+    ^ nil
+
+    "Created: / 09-08-2013 / 02:25:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 programmingLanguage
 
     ^JavaLanguage instance
@@ -416,9 +464,9 @@
     "Update the bytecode before restarting so
      bytecode interpreter can execute new code, if any"
 
-     | m |
+    | m |
 
-    m := self method.
+    m := self methodFromClass.
     m notNil ifTrue:[
          byteCode := m byteCode.
          constPool := m constantPool.
@@ -426,6 +474,7 @@
     ^super restart.
 
     "Created: / 19-04-2013 / 13:33:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 09-08-2013 / 02:33:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 return