X Tutup
Skip to content

Commit 43c99eb

Browse files
author
Johan Brichau
committed
Fix GRDynamicVariable>>use:during: in GemStone to correctly implement expected semantics (see method comments for details)
1 parent 6e1d99d commit 43c99eb

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
accessing
22
use: anObject during: aBlock
3-
| p oldValue result |
4-
"We cannot just do a super call to value:during: because the GS implementation does not return a result value and also does not produce an error when the dynamic var was not found."
3+
| p hasOldValue oldValue result |
4+
"Implementation cannot send a supercall to value:during: because:
5+
- this method needs to return the value
6+
- the defaultValue may not be invoked here to support throwing errors as defaultValue
7+
- nil may not remain installed as the default value once the block has finished running"
58
p := Processor activeProcess.
9+
hasOldValue := p environment includesKey: self.
610
oldValue := p environmentAt: self.
711
[
812
p environmentAt: self put: anObject.
913
result := aBlock value ]
10-
ensure: [ p environmentAt: self put: oldValue ].
14+
ensure: [
15+
hasOldValue
16+
ifFalse: [ p environment removeKey: self ]
17+
ifTrue: [ p environmentAt: self put: oldValue ] ].
1118
^ result

repository/Grease-GemStone-Core.package/GRDynamicVariable.class/methodProperties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"class" : {
33
"default" : "JohanBrichau 07/23/2017 09:48",
44
"defaultValue" : "JohanBrichau 07/23/2017 09:47",
5-
"use:during:" : "JohanBrichau 09/07/2017 05:38" },
5+
"use:during:" : "JB 09/08/2017 00:34" },
66
"instance" : {
77
} }

0 commit comments

Comments
 (0)
X Tutup