Skip to content

Commit e651fc1

Browse files
committed
(feat) release context after expression invocation, killme2008#392
1 parent 7145dbb commit e651fc1

File tree

1 file changed

+85
-30
lines changed

1 file changed

+85
-30
lines changed

src/main/java/com/googlecode/aviator/runtime/function/LambdaFunction.java

Lines changed: 85 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,82 +101,131 @@ public boolean isVariadic() {
101101

102102
@Override
103103
public AviatorObject call(final Map<String, Object> env) {
104-
if (this.isVariadic && !this.installed) {
105-
return variadicCall(env, true);
104+
try {
105+
if (this.isVariadic && !this.installed) {
106+
return variadicCall(env, true);
107+
}
108+
return AviatorRuntimeJavaType.valueOf(this.expression.executeDirectly(newEnv(env)));
109+
} finally {
110+
if (this.inheritEnv) {
111+
this.context = null;
112+
}
106113
}
107-
return AviatorRuntimeJavaType.valueOf(this.expression.executeDirectly(newEnv(env)));
108114
}
109115

110116
@Override
111117
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1) {
112-
if (this.isVariadic && !this.installed) {
113-
return variadicCall(env, true, arg1);
118+
try {
119+
if (this.isVariadic && !this.installed) {
120+
return variadicCall(env, true, arg1);
121+
}
122+
return AviatorRuntimeJavaType.valueOf(this.expression.executeDirectly(newEnv(env, arg1)));
123+
} finally {
124+
if (this.inheritEnv) {
125+
this.context = null;
126+
}
114127
}
115-
return AviatorRuntimeJavaType.valueOf(this.expression.executeDirectly(newEnv(env, arg1)));
116128
}
117129

118130
@Override
119131
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1,
120132
final AviatorObject arg2) {
121-
if (this.isVariadic && !this.installed) {
122-
return variadicCall(env, true, arg1, arg2);
133+
try {
134+
if (this.isVariadic && !this.installed) {
135+
return variadicCall(env, true, arg1, arg2);
136+
}
137+
return AviatorRuntimeJavaType
138+
.valueOf(this.expression.executeDirectly(newEnv(env, arg1, arg2)));
139+
} finally {
140+
if (this.inheritEnv) {
141+
this.context = null;
142+
}
123143
}
124-
return AviatorRuntimeJavaType.valueOf(this.expression.executeDirectly(newEnv(env, arg1, arg2)));
125144
}
126145

127146
@Override
128147
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1,
129148
final AviatorObject arg2, final AviatorObject arg3) {
130-
if (this.isVariadic && !this.installed) {
131-
return variadicCall(env, true, arg1, arg2, arg3);
149+
try {
150+
if (this.isVariadic && !this.installed) {
151+
return variadicCall(env, true, arg1, arg2, arg3);
152+
}
153+
return AviatorRuntimeJavaType
154+
.valueOf(this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3)));
155+
} finally {
156+
if (this.inheritEnv) {
157+
this.context = null;
158+
}
132159
}
133-
return AviatorRuntimeJavaType
134-
.valueOf(this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3)));
135160
}
136161

137162
@Override
138163
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1,
139164
final AviatorObject arg2, final AviatorObject arg3, final AviatorObject arg4) {
140-
if (this.isVariadic && !this.installed) {
141-
return variadicCall(env, true, arg1, arg2, arg3, arg4);
165+
try {
166+
if (this.isVariadic && !this.installed) {
167+
return variadicCall(env, true, arg1, arg2, arg3, arg4);
168+
}
169+
return AviatorRuntimeJavaType
170+
.valueOf(this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3, arg4)));
171+
} finally {
172+
if (this.inheritEnv) {
173+
this.context = null;
174+
}
142175
}
143-
return AviatorRuntimeJavaType
144-
.valueOf(this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3, arg4)));
145176
}
146177

147178
@Override
148179
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1,
149180
final AviatorObject arg2, final AviatorObject arg3, final AviatorObject arg4,
150181
final AviatorObject arg5) {
151-
if (this.isVariadic && !this.installed) {
152-
return variadicCall(env, true, arg1, arg2, arg3, arg4, arg5);
182+
try {
183+
if (this.isVariadic && !this.installed) {
184+
return variadicCall(env, true, arg1, arg2, arg3, arg4, arg5);
185+
}
186+
return AviatorRuntimeJavaType
187+
.valueOf(this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3, arg4, arg5)));
188+
} finally {
189+
if (this.inheritEnv) {
190+
this.context = null;
191+
}
153192
}
154-
return AviatorRuntimeJavaType
155-
.valueOf(this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3, arg4, arg5)));
156193
}
157194

158195

159196
@Override
160197
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1,
161198
final AviatorObject arg2, final AviatorObject arg3, final AviatorObject arg4,
162199
final AviatorObject arg5, final AviatorObject arg6) {
163-
if (this.isVariadic && !this.installed) {
164-
return variadicCall(env, true, arg1, arg2, arg3, arg4, arg5, arg6);
200+
try {
201+
if (this.isVariadic && !this.installed) {
202+
return variadicCall(env, true, arg1, arg2, arg3, arg4, arg5, arg6);
203+
}
204+
return AviatorRuntimeJavaType.valueOf(
205+
this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3, arg4, arg5, arg6)));
206+
} finally {
207+
if (this.inheritEnv) {
208+
this.context = null;
209+
}
165210
}
166-
return AviatorRuntimeJavaType
167-
.valueOf(this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3, arg4, arg5, arg6)));
168211
}
169212

170213

171214
@Override
172215
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1,
173216
final AviatorObject arg2, final AviatorObject arg3, final AviatorObject arg4,
174217
final AviatorObject arg5, final AviatorObject arg6, final AviatorObject arg7) {
175-
if (this.isVariadic && !this.installed) {
176-
return variadicCall(env, true, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
218+
try {
219+
if (this.isVariadic && !this.installed) {
220+
return variadicCall(env, true, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
221+
}
222+
return AviatorRuntimeJavaType.valueOf(
223+
this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7)));
224+
} finally {
225+
if (this.inheritEnv) {
226+
this.context = null;
227+
}
177228
}
178-
return AviatorRuntimeJavaType.valueOf(
179-
this.expression.executeDirectly(newEnv(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7)));
180229
}
181230

182231

@@ -223,7 +272,13 @@ public AviatorObject variadicCall(final Map<String, Object> env, final boolean p
223272

224273
@Override
225274
public AviatorObject variadicCall(final Map<String, Object> env, final AviatorObject... args) {
226-
return this.variadicCall(env, false, args);
275+
try {
276+
return this.variadicCall(env, false, args);
277+
} finally {
278+
if (this.inheritEnv) {
279+
this.context = null;
280+
}
281+
}
227282
}
228283

229284
}

0 commit comments

Comments
 (0)