Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change implementation by trap bytecode methods with patched literals #17

Merged
merged 12 commits into from
Oct 23, 2023
8 changes: 5 additions & 3 deletions src/BaselineOfMethodProxies/BaselineOfMethodProxies.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ BaselineOfMethodProxies >> baseline: spec [

<baseline>
spec for: #common do: [
spec package: #MethodProxies;
spec
package: #MethodProxies;
package: #'MethodProxies-Tests'
with: [ spec requires: #( #MethodProxies ) ];
with: [ spec requires: #( #MethodProxies #MethodProxiesExamples ) ];
package: #MethodProxiesExamples
with: [ spec requires: #( #MethodProxies ) ];
package: #'MethodProxiesExamples-Tests'
with: [ spec requires: #( #MethodProxiesExamples ) ].
with: [
spec requires: #( #'MethodProxies-Tests' ) ].

spec
group: 'Core' with: #( #MethodProxies );
Expand Down
55 changes: 55 additions & 0 deletions src/MethodProxies-Tests/MpAbstractMethodProxyTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Class {
#name : #MpAbstractMethodProxyTest,
#superclass : #TestCase,
#instVars : [
'trackedWrappers'
],
#category : #'MethodProxies-Tests'
}

{ #category : #testing }
MpAbstractMethodProxyTest class >> isAbstract [

^ self == MpAbstractMethodProxyTest
]

{ #category : #'tests - dead representation' }
MpAbstractMethodProxyTest >> installMethodProxy: aMethodProxy [

trackedWrappers add: aMethodProxy.
aMethodProxy install.

]

{ #category : #initialization }
MpAbstractMethodProxyTest >> setUp [

super setUp.
trackedWrappers := OrderedCollection new
]

{ #category : #initialization }
MpAbstractMethodProxyTest >> tearDown [

| stillInstalled |

"Uninstall proxies using a fixed point approach.
This is to cover a problem of proxies wrapping proxies for now"
[
stillInstalled := trackedWrappers select: [ :e | e isInstalled ].
stillInstalled isEmpty ] whileFalse: [
stillInstalled do: [ :each |
[
each uninstall.
trackedWrappers remove: each ]
on: Error
do: [ :e | "continue" ] ] ].

"Give me the guarantee that we did not leave proxies installed in the system"
(MpMethodProxy allInstances anySatisfy: [ :e | e isInstalled ])
ifTrue: [
self error:
'Proxies still installed after test: ' , testSelector asString ].

super tearDown
]
26 changes: 26 additions & 0 deletions src/MethodProxies-Tests/MpAfterResultHandler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Class {
#name : #MpAfterResultHandler,
#superclass : #MpHandler,
#instVars : [
'count'
],
#category : #'MethodProxies-Tests'
}

{ #category : #evaluating }
MpAfterResultHandler >> afterExecutionWithReceiver: anObject arguments: anArrayOfObjects returnValue: aReturnValue [

^ 'trapped [', aReturnValue asString, ']'
]

{ #category : #accessing }
MpAfterResultHandler >> count [
^ count
]

{ #category : #evaluating }
MpAfterResultHandler >> initialize [

super initialize.
count := 0
]
2 changes: 1 addition & 1 deletion src/MethodProxies-Tests/MpClassA.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ MpClassA >> methodLastingOneSecond [

{ #category : #debugging }
MpClassA >> methodOne [

^ 101

]

{ #category : #debugging }
Expand Down
Loading
Loading